From 776ec521480d9523732b96c55af4addfdd007e61 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Thu, 12 Dec 2024 23:29:14 +0900 Subject: [PATCH] [ruby/win32ole] Deprecate old constants in toplevel https://github.com/ruby/win32ole/commit/eaa1507262 --- ext/win32ole/extconf.rb | 1 + ext/win32ole/win32ole.h | 4 ++++ ext/win32ole/win32ole_error.c | 2 ++ ext/win32ole/win32ole_event.c | 1 + ext/win32ole/win32ole_method.c | 1 + ext/win32ole/win32ole_param.c | 1 + ext/win32ole/win32ole_record.c | 1 + ext/win32ole/win32ole_type.c | 1 + ext/win32ole/win32ole_typelib.c | 1 + ext/win32ole/win32ole_variable.c | 1 + ext/win32ole/win32ole_variant.c | 1 + test/win32ole/test_win32ole.rb | 5 ----- test/win32ole/test_win32ole_event.rb | 4 ---- test/win32ole/test_win32ole_method.rb | 4 ---- test/win32ole/test_win32ole_param.rb | 4 ---- test/win32ole/test_win32ole_record.rb | 3 --- test/win32ole/test_win32ole_type.rb | 4 ---- test/win32ole/test_win32ole_typelib.rb | 4 ---- test/win32ole/test_win32ole_variable.rb | 4 ---- test/win32ole/test_win32ole_variant.rb | 4 ---- test/win32ole/test_win32ole_variant_m.rb | 4 ---- 21 files changed, 15 insertions(+), 40 deletions(-) diff --git a/ext/win32ole/extconf.rb b/ext/win32ole/extconf.rb index d2044663a92569..45bcd4de3d6811 100644 --- a/ext/win32ole/extconf.rb +++ b/ext/win32ole/extconf.rb @@ -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 diff --git a/ext/win32ole/win32ole.h b/ext/win32ole/win32ole.h index cd627ef7652905..07ef11070c583c 100644 --- a/ext/win32ole/win32ole.h +++ b/ext/win32ole/win32ole.h @@ -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) {\ diff --git a/ext/win32ole/win32ole_error.c b/ext/win32ole/win32ole_error.c index 6cb080d0e6bb9a..208120d2a7d80f 100644 --- a/ext/win32ole/win32ole_error.c +++ b/ext/win32ole/win32ole_error.c @@ -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 * @@ -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"); } diff --git a/ext/win32ole/win32ole_event.c b/ext/win32ole/win32ole_event.c index a422e937f5f26e..242a3288fb2392 100644 --- a/ext/win32ole/win32ole_event.c +++ b/ext/win32ole/win32ole_event.c @@ -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); diff --git a/ext/win32ole/win32ole_method.c b/ext/win32ole/win32ole_method.c index 0b6696c59f8c0c..fa4e8cf71d546d 100644 --- a/ext/win32ole/win32ole_method.c +++ b/ext/win32ole/win32ole_method.c @@ -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); diff --git a/ext/win32ole/win32ole_param.c b/ext/win32ole/win32ole_param.c index 2370c76b3cf111..8ab6181f3e8ddc 100644 --- a/ext/win32ole/win32ole_param.c +++ b/ext/win32ole/win32ole_param.c @@ -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); diff --git a/ext/win32ole/win32ole_record.c b/ext/win32ole/win32ole_record.c index 954f559f5e9816..493ad8119b9174 100644 --- a/ext/win32ole/win32ole_record.c +++ b/ext/win32ole/win32ole_record.c @@ -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); diff --git a/ext/win32ole/win32ole_type.c b/ext/win32ole/win32ole_type.c index cfcaa9080ebbc6..0f449482d4c337 100644 --- a/ext/win32ole/win32ole_type.c +++ b/ext/win32ole/win32ole_type.c @@ -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); diff --git a/ext/win32ole/win32ole_typelib.c b/ext/win32ole/win32ole_typelib.c index 4be6d118153d8b..0c76c60e377754 100644 --- a/ext/win32ole/win32ole_typelib.c +++ b/ext/win32ole/win32ole_typelib.c @@ -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); diff --git a/ext/win32ole/win32ole_variable.c b/ext/win32ole/win32ole_variable.c index 094cb5ceab51eb..35b4ac3f520bf5 100644 --- a/ext/win32ole/win32ole_variable.c +++ b/ext/win32ole/win32ole_variable.c @@ -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); diff --git a/ext/win32ole/win32ole_variant.c b/ext/win32ole/win32ole_variant.c index a65eed471062a5..8ec4d0842ce05b 100644 --- a/ext/win32ole/win32ole_variant.c +++ b/ext/win32ole/win32ole_variant.c @@ -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); diff --git a/test/win32ole/test_win32ole.rb b/test/win32ole/test_win32ole.rb index e6347e89b456ec..b0c147b3116c15 100644 --- a/test/win32ole/test_win32ole.rb +++ b/test/win32ole/test_win32ole.rb @@ -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) diff --git a/test/win32ole/test_win32ole_event.rb b/test/win32ole/test_win32ole_event.rb index d52f8cf9b3ba74..da3ee8567e8ebb 100644 --- a/test/win32ole/test_win32ole_event.rb +++ b/test/win32ole/test_win32ole_event.rb @@ -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") diff --git a/test/win32ole/test_win32ole_method.rb b/test/win32ole/test_win32ole_method.rb index c84c4027ff3f00..4b3e255fdc99fe 100644 --- a/test/win32ole/test_win32ole_method.rb +++ b/test/win32ole/test_win32ole_method.rb @@ -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) { diff --git a/test/win32ole/test_win32ole_param.rb b/test/win32ole/test_win32ole_param.rb index 13ca9d0cfbea5f..551da537fc7165 100644 --- a/test/win32ole/test_win32ole_param.rb +++ b/test/win32ole/test_win32ole_param.rb @@ -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") diff --git a/test/win32ole/test_win32ole_record.rb b/test/win32ole/test_win32ole_record.rb index 49205ce53da91c..2fae16788d7d3d 100644 --- a/test/win32ole/test_win32ole_record.rb +++ b/test/win32ole/test_win32ole_record.rb @@ -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? diff --git a/test/win32ole/test_win32ole_type.rb b/test/win32ole/test_win32ole_type.rb index 9abcd68c9bb5e0..df1ba6556c64ad 100644 --- a/test/win32ole/test_win32ole_type.rb +++ b/test/win32ole/test_win32ole_type.rb @@ -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) diff --git a/test/win32ole/test_win32ole_typelib.rb b/test/win32ole/test_win32ole_typelib.rb index 31d6122756be53..f743ad68f90e31 100644 --- a/test/win32ole/test_win32ole_typelib.rb +++ b/test/win32ole/test_win32ole_typelib.rb @@ -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) diff --git a/test/win32ole/test_win32ole_variable.rb b/test/win32ole/test_win32ole_variable.rb index 646cf68915e3b0..74a6cbd890ad95 100644 --- a/test/win32ole/test_win32ole_variable.rb +++ b/test/win32ole/test_win32ole_variable.rb @@ -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 diff --git a/test/win32ole/test_win32ole_variant.rb b/test/win32ole/test_win32ole_variant.rb index 13b9a229a5076e..1837a1e1d630f2 100644 --- a/test/win32ole/test_win32ole_variant.rb +++ b/test/win32ole/test_win32ole_variant.rb @@ -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) diff --git a/test/win32ole/test_win32ole_variant_m.rb b/test/win32ole/test_win32ole_variant_m.rb index 3c2884644c5892..f176d1a51e237f 100644 --- a/test/win32ole/test_win32ole_variant_m.rb +++ b/test/win32ole/test_win32ole_variant_m.rb @@ -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)