Skip to content

Commit

Permalink
[ruby/win32ole] Deprecate old constants in toplevel
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu authored and matzbot committed Dec 12, 2024
1 parent 20b62ac commit 776ec52
Show file tree
Hide file tree
Showing 21 changed files with 15 additions and 40 deletions.
1 change: 1 addition & 0 deletions ext/win32ole/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def create_win32ole_makefile
spec or 'no'
end
$defs << "-DRB_THREAD_SPECIFIC=#{spec}" if spec
have_func(%[rb_deprecate_constant(Qnil, "")])
create_makefile("win32ole")
end
end
Expand Down
4 changes: 4 additions & 0 deletions ext/win32ole/win32ole.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@
#define NUM2UI8 RB_NUM2UINT
#endif

#ifndef HAVE_RB_DEPRECATE_CONSTANT
# define rb_deprecate_constant(mod, name) (void)0
#endif

#define OLE_ADDREF(X) (X) ? ((X)->lpVtbl->AddRef(X)) : 0
#define OLE_RELEASE(X) (X) ? ((X)->lpVtbl->Release(X)) : 0
#define OLE_FREE(x) {\
Expand Down
2 changes: 2 additions & 0 deletions ext/win32ole/win32ole_error.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ Init_win32ole_error(void)
eWIN32OLERuntimeError = rb_define_class_under(cWIN32OLE, "RuntimeError", rb_eRuntimeError);
/* Alias of WIN32OLE::RuntimeError, for the backward compatibility */
rb_define_const(rb_cObject, "WIN32OLE" "RuntimeError", eWIN32OLERuntimeError);
rb_deprecate_constant(rb_cObject, "WIN32OLE" "RuntimeError");
/*
* Document-class: WIN32OLE::QueryInterfaceError
*
Expand All @@ -93,4 +94,5 @@ Init_win32ole_error(void)
eWIN32OLEQueryInterfaceError = rb_define_class_under(cWIN32OLE, "QueryInterfaceError", eWIN32OLERuntimeError);
/* Alias of WIN32OLE::QueryInterfaceError, for the backward compatibility */
rb_define_const(rb_cObject, "WIN32OLE" "QueryInterfaceError", eWIN32OLEQueryInterfaceError);
rb_deprecate_constant(rb_cObject, "WIN32OLE" "QueryInterfaceError");
}
1 change: 1 addition & 0 deletions ext/win32ole/win32ole_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -1267,6 +1267,7 @@ Init_win32ole_event(void)
cWIN32OLE_EVENT = rb_define_class_under(cWIN32OLE, "Event", rb_cObject);
/* Alias of WIN32OLE::Event, for the backward compatibility */
rb_define_const(rb_cObject, "WIN32OLE" "_EVENT", cWIN32OLE_EVENT);
rb_deprecate_constant(rb_cObject, "WIN32OLE" "_EVENT");
rb_define_singleton_method(cWIN32OLE_EVENT, "message_loop", fev_s_msg_loop, 0);
rb_define_alloc_func(cWIN32OLE_EVENT, fev_s_allocate);
rb_define_method(cWIN32OLE_EVENT, "initialize", fev_initialize, -1);
Expand Down
1 change: 1 addition & 0 deletions ext/win32ole/win32ole_method.c
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,7 @@ void Init_win32ole_method(void)
cWIN32OLE_METHOD = rb_define_class_under(cWIN32OLE, "Method", rb_cObject);
/* Alias of WIN32OLE::Method, for the backward compatibility */
rb_define_const(rb_cObject, "WIN32OLE" "_METHOD", cWIN32OLE_METHOD);
rb_deprecate_constant(rb_cObject, "WIN32OLE" "_METHOD");
rb_define_alloc_func(cWIN32OLE_METHOD, folemethod_s_allocate);
rb_define_method(cWIN32OLE_METHOD, "initialize", folemethod_initialize, 2);
rb_define_method(cWIN32OLE_METHOD, "name", folemethod_name, 0);
Expand Down
1 change: 1 addition & 0 deletions ext/win32ole/win32ole_param.c
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ Init_win32ole_param(void)
cWIN32OLE_PARAM = rb_define_class_under(cWIN32OLE, "Param", rb_cObject);
/* Alias of WIN32OLE::Param, for the backward compatibility */
rb_define_const(rb_cObject, "WIN32OLE" "_PARAM", cWIN32OLE_PARAM);
rb_deprecate_constant(rb_cObject, "WIN32OLE" "_PARAM");
rb_define_alloc_func(cWIN32OLE_PARAM, foleparam_s_allocate);
rb_define_method(cWIN32OLE_PARAM, "initialize", foleparam_initialize, 2);
rb_define_method(cWIN32OLE_PARAM, "name", foleparam_name, 0);
Expand Down
1 change: 1 addition & 0 deletions ext/win32ole/win32ole_record.c
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,7 @@ Init_win32ole_record(void)
cWIN32OLE_RECORD = rb_define_class_under(cWIN32OLE, "Record", rb_cObject);
/* Alias of WIN32OLE::Record, for the backward compatibility */
rb_define_const(rb_cObject, "WIN32OLE" "_RECORD", cWIN32OLE_RECORD);
rb_deprecate_constant(rb_cObject, "WIN32OLE" "_RECORD");
rb_define_alloc_func(cWIN32OLE_RECORD, folerecord_s_allocate);
rb_define_method(cWIN32OLE_RECORD, "initialize", folerecord_initialize, 2);
rb_define_method(cWIN32OLE_RECORD, "to_h", folerecord_to_h, 0);
Expand Down
1 change: 1 addition & 0 deletions ext/win32ole/win32ole_type.c
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,7 @@ void Init_win32ole_type(void)
cWIN32OLE_TYPE = rb_define_class_under(cWIN32OLE, "Type", rb_cObject);
/* Alias of WIN32OLE::Type, for the backward compatibility */
rb_define_const(rb_cObject, "WIN32OLE" "_TYPE", cWIN32OLE_TYPE);
rb_deprecate_constant(rb_cObject, "WIN32OLE" "_TYPE");
rb_define_singleton_method(cWIN32OLE_TYPE, "ole_classes", foletype_s_ole_classes, 1);
rb_define_singleton_method(cWIN32OLE_TYPE, "typelibs", foletype_s_typelibs, 0);
rb_define_singleton_method(cWIN32OLE_TYPE, "progids", foletype_s_progids, 0);
Expand Down
1 change: 1 addition & 0 deletions ext/win32ole/win32ole_typelib.c
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,7 @@ Init_win32ole_typelib(void)
cWIN32OLE_TYPELIB = rb_define_class_under(cWIN32OLE, "TypeLib", rb_cObject);
/* Alias of WIN32OLE::TypeLib, for the backward compatibility */
rb_define_const(rb_cObject, "WIN32OLE" "_TYPELIB", cWIN32OLE_TYPELIB);
rb_deprecate_constant(rb_cObject, "WIN32OLE" "_TYPELIB");
rb_define_singleton_method(cWIN32OLE_TYPELIB, "typelibs", foletypelib_s_typelibs, 0);
rb_define_alloc_func(cWIN32OLE_TYPELIB, foletypelib_s_allocate);
rb_define_method(cWIN32OLE_TYPELIB, "initialize", foletypelib_initialize, -2);
Expand Down
1 change: 1 addition & 0 deletions ext/win32ole/win32ole_variable.c
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ void Init_win32ole_variable(void)
cWIN32OLE_VARIABLE = rb_define_class_under(cWIN32OLE, "Variable", rb_cObject);
/* Alias of WIN32OLE::Variable, for the backward compatibility */
rb_define_const(rb_cObject, "WIN32OLE" "_VARIABLE", cWIN32OLE_VARIABLE);
rb_deprecate_constant(rb_cObject, "WIN32OLE" "_VARIABLE");
rb_undef_alloc_func(cWIN32OLE_VARIABLE);
rb_define_method(cWIN32OLE_VARIABLE, "name", folevariable_name, 0);
rb_define_method(cWIN32OLE_VARIABLE, "ole_type", folevariable_ole_type, 0);
Expand Down
1 change: 1 addition & 0 deletions ext/win32ole/win32ole_variant.c
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,7 @@ Init_win32ole_variant(void)
cWIN32OLE_VARIANT = rb_define_class_under(cWIN32OLE, "Variant", rb_cObject);
/* Alias of WIN32OLE::Variant, for the backward compatibility */
rb_define_const(rb_cObject, "WIN32OLE" "_VARIANT", cWIN32OLE_VARIANT);
rb_deprecate_constant(rb_cObject, "WIN32OLE" "_VARIANT");
rb_define_alloc_func(cWIN32OLE_VARIANT, folevariant_s_allocate);
rb_define_singleton_method(cWIN32OLE_VARIANT, "array", folevariant_s_array, 2);
rb_define_method(cWIN32OLE_VARIANT, "initialize", folevariant_initialize, -2);
Expand Down
5 changes: 0 additions & 5 deletions test/win32ole/test_win32ole.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,6 @@ def test_s_new
assert_instance_of(WIN32OLE, @dict2)
end

def test_toplevel_constants_backward_compatibility
assert_equal(WIN32OLE::RuntimeError, ::WIN32OLERuntimeError)
assert_equal(WIN32OLE::QueryInterfaceError, ::WIN32OLEQueryInterfaceError)
end

def test_s_new_exc
assert_raise(TypeError) {
WIN32OLE.new(1)
Expand Down
4 changes: 0 additions & 4 deletions test/win32ole/test_win32ole_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@

if defined?(WIN32OLE::Event)
class TestWIN32OLE_EVENT < Test::Unit::TestCase
def test_toplevel_constants_backward_compatibility
assert_equal(WIN32OLE::Event, ::WIN32OLE_EVENT)
end

def test_s_new_exception
assert_raise(TypeError) {
WIN32OLE::Event.new("A")
Expand Down
4 changes: 0 additions & 4 deletions test/win32ole/test_win32ole_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ def setup
@m_file_name = WIN32OLE::Method.new(ole_type, "name")
end

def test_toplevel_constants_backward_compatibility
assert_equal(WIN32OLE::Method, ::WIN32OLE_METHOD)
end

def test_initialize
ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "Shell")
assert_raise(TypeError) {
Expand Down
4 changes: 0 additions & 4 deletions test/win32ole/test_win32ole_param.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ def setup
@param_key = m_add.params[0]
end

def test_constants_backward_compatibility
assert_equal(WIN32OLE::Param, ::WIN32OLE_PARAM)
end

def test_s_new
assert_raise(ArgumentError) {
WIN32OLE::Param.new("hoge")
Expand Down
3 changes: 0 additions & 3 deletions test/win32ole/test_win32ole_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@

if defined?(WIN32OLE::Record)
class TestWIN32OLE_RECORD < Test::Unit::TestCase
def test_toplevel_constants_backward_compatibility
assert_equal(WIN32OLE::Record, ::WIN32OLE_RECORD)
end
end

def rbcomtest_exist?
Expand Down
4 changes: 0 additions & 4 deletions test/win32ole/test_win32ole_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@

if defined?(WIN32OLE::Type)
class TestWIN32OLE_TYPE < Test::Unit::TestCase
def test_toplevel_constants_backward_compatibility
assert_equal(WIN32OLE::Type, ::WIN32OLE_TYPE)
end

def test_s_progids
progids = WIN32OLE::Type.progids
assert_instance_of(Array, progids)
Expand Down
4 changes: 0 additions & 4 deletions test/win32ole/test_win32ole_typelib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@

if defined?(WIN32OLE::TypeLib)
class TestWIN32OLE_TYPELIB < Test::Unit::TestCase
def test_toplevel_constants_backward_compatibility
assert_equal(WIN32OLE::TypeLib, ::WIN32OLE_TYPELIB)
end

def test_s_typelibs
tlibs = WIN32OLE::TypeLib.typelibs
assert_instance_of(Array, tlibs)
Expand Down
4 changes: 0 additions & 4 deletions test/win32ole/test_win32ole_variable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ def setup
@var2 = variables.find {|v| v.name == 'UILevel'}
end

def test_toplevel_constants_backward_compatibility
assert_equal(WIN32OLE::Variable, ::WIN32OLE_VARIABLE)
end

def test_initialize
assert_raise(TypeError) {WIN32OLE::Variable.new}
end
Expand Down
4 changes: 0 additions & 4 deletions test/win32ole/test_win32ole_variant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ def teardown
WIN32OLE.locale = @orglocale
end

def test_toplevel_constants_backward_compatibility
assert_equal(WIN32OLE::Variant, ::WIN32OLE_VARIANT)
end

def test_s_new
obj = WIN32OLE::Variant.new('foo')
assert_instance_of(WIN32OLE::Variant, obj)
Expand Down
4 changes: 0 additions & 4 deletions test/win32ole/test_win32ole_variant_m.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
class TestWin32OLE_VARIANT_MODULE < Test::Unit::TestCase
include WIN32OLE::VARIANT

def test_toplevel_constants_backward_compatibility
assert_equal(WIN32OLE::VariantType, WIN32OLE::VARIANT)
end

def test_variant
assert_equal(0, VT_EMPTY)
assert_equal(1, VT_NULL)
Expand Down

0 comments on commit 776ec52

Please sign in to comment.