From ea98f3388b0fdc2046a507bb842d66782e611a4b Mon Sep 17 00:00:00 2001 From: Joe George Date: Mon, 6 Jan 2025 15:30:34 -0500 Subject: [PATCH] Add support for Ruby 3.4 --- ruby/src/IceRuby/Communicator.cpp | 29 +++++++++---- ruby/src/IceRuby/Connection.cpp | 55 +++++++++++++++++------- ruby/src/IceRuby/Endpoint.cpp | 50 +++++++++++++++------ ruby/src/IceRuby/ImplicitContext.cpp | 19 ++++++-- ruby/src/IceRuby/Logger.cpp | 19 ++++++-- ruby/src/IceRuby/Operation.cpp | 18 ++++++-- ruby/src/IceRuby/Properties.cpp | 19 ++++++-- ruby/src/IceRuby/Proxy.cpp | 28 ++++++++---- ruby/src/IceRuby/ValueFactoryManager.cpp | 28 ++++++++---- 9 files changed, 194 insertions(+), 71 deletions(-) diff --git a/ruby/src/IceRuby/Communicator.cpp b/ruby/src/IceRuby/Communicator.cpp index 00d188fae23..0e43f721e3c 100644 --- a/ruby/src/IceRuby/Communicator.cpp +++ b/ruby/src/IceRuby/Communicator.cpp @@ -25,12 +25,12 @@ using CommunicatorMap = map; static CommunicatorMap _communicatorMap; extern "C" void -IceRuby_Communicator_mark(Ice::CommunicatorPtr* p) +IceRuby_Communicator_mark(void* p) { - assert(p); + auto communicator = static_cast(p); try { - auto vfm = dynamic_pointer_cast((*p)->getValueFactoryManager()); + auto vfm = dynamic_pointer_cast((*communicator)->getValueFactoryManager()); assert(vfm); vfm->markSelf(); } @@ -41,12 +41,24 @@ IceRuby_Communicator_mark(Ice::CommunicatorPtr* p) } extern "C" void -IceRuby_Communicator_free(Ice::CommunicatorPtr* p) +IceRuby_Communicator_free(void* p) { - assert(p); - delete p; + auto communicator = static_cast(p); + delete communicator; } +static const rb_data_type_t IceRuby_CommunicatorType = { + .wrap_struct_name = "Ice::Communicator", + .function = + { + .dmark = IceRuby_Communicator_mark, + .dfree = IceRuby_Communicator_free, + .dsize = nullptr, + }, + .data = nullptr, + .flags = RUBY_TYPED_FREE_IMMEDIATELY, +}; + namespace { class CommunicatorDestroyer @@ -260,10 +272,9 @@ IceRuby_initialize(int argc, VALUE* argv, VALUE /*self*/) } delete[] av; - VALUE result = Data_Wrap_Struct( + VALUE result = TypedData_Wrap_Struct( _communicatorClass, - IceRuby_Communicator_mark, - IceRuby_Communicator_free, + &IceRuby_CommunicatorType, new Ice::CommunicatorPtr(communicator)); CommunicatorMap::iterator p = _communicatorMap.find(communicator); diff --git a/ruby/src/IceRuby/Connection.cpp b/ruby/src/IceRuby/Connection.cpp index 251827f67fe..6e42f3fd828 100644 --- a/ruby/src/IceRuby/Connection.cpp +++ b/ruby/src/IceRuby/Connection.cpp @@ -21,19 +21,28 @@ static VALUE _udpConnectionInfoClass; static VALUE _wsConnectionInfoClass; static VALUE _sslConnectionInfoClass; -// Connection - extern "C" void -IceRuby_Connection_free(Ice::ConnectionPtr* p) +IceRuby_Connection_free(void* p) { - assert(p); - delete p; + delete static_cast(p); } +static const rb_data_type_t IceRuby_ConnectionType = { + .wrap_struct_name = "Ice::Connection", + .function = + { + .dmark = nullptr, + .dfree = IceRuby_Connection_free, + .dsize = nullptr, + }, + .data = nullptr, + .flags = RUBY_TYPED_FREE_IMMEDIATELY, +}; + VALUE IceRuby::createConnection(const Ice::ConnectionPtr& p) { - return Data_Wrap_Struct(_connectionClass, 0, IceRuby_Connection_free, new Ice::ConnectionPtr(p)); + return TypedData_Wrap_Struct(_connectionClass, &IceRuby_ConnectionType, new Ice::ConnectionPtr(p)); } extern "C" VALUE @@ -197,12 +206,23 @@ IceRuby_Connection_equals(VALUE self, VALUE other) // ConnectionInfo extern "C" void -IceRuby_ConnectionInfo_free(Ice::ConnectionInfoPtr* p) +IceRuby_ConnectionInfo_free(void* p) { - assert(p); - delete p; + delete static_cast(p); } +static const rb_data_type_t IceRuby_ConnectionInfoType = { + .wrap_struct_name = "Ice::ConnectionInfo", + .function = + { + .dmark = nullptr, + .dfree = IceRuby_ConnectionInfo_free, + .dsize = nullptr, + }, + .data = nullptr, + .flags = RUBY_TYPED_FREE_IMMEDIATELY, +}; + VALUE IceRuby::createConnectionInfo(const Ice::ConnectionInfoPtr& p) { @@ -214,7 +234,8 @@ IceRuby::createConnectionInfo(const Ice::ConnectionInfoPtr& p) VALUE info; if (dynamic_pointer_cast(p)) { - info = Data_Wrap_Struct(_wsConnectionInfoClass, 0, IceRuby_ConnectionInfo_free, new Ice::ConnectionInfoPtr(p)); + info = + TypedData_Wrap_Struct(_wsConnectionInfoClass, &IceRuby_ConnectionInfoType, new Ice::ConnectionInfoPtr(p)); Ice::WSConnectionInfoPtr ws = dynamic_pointer_cast(p); volatile VALUE result = callRuby(rb_hash_new); @@ -228,7 +249,8 @@ IceRuby::createConnectionInfo(const Ice::ConnectionInfoPtr& p) } else if (dynamic_pointer_cast(p)) { - info = Data_Wrap_Struct(_tcpConnectionInfoClass, 0, IceRuby_ConnectionInfo_free, new Ice::ConnectionInfoPtr(p)); + info = + TypedData_Wrap_Struct(_tcpConnectionInfoClass, &IceRuby_ConnectionInfoType, new Ice::ConnectionInfoPtr(p)); Ice::TCPConnectionInfoPtr tcp = dynamic_pointer_cast(p); rb_ivar_set(info, rb_intern("@rcvSize"), INT2FIX(tcp->rcvSize)); @@ -236,7 +258,8 @@ IceRuby::createConnectionInfo(const Ice::ConnectionInfoPtr& p) } else if (dynamic_pointer_cast(p)) { - info = Data_Wrap_Struct(_udpConnectionInfoClass, 0, IceRuby_ConnectionInfo_free, new Ice::ConnectionInfoPtr(p)); + info = + TypedData_Wrap_Struct(_udpConnectionInfoClass, &IceRuby_ConnectionInfoType, new Ice::ConnectionInfoPtr(p)); Ice::UDPConnectionInfoPtr udp = dynamic_pointer_cast(p); rb_ivar_set(info, rb_intern("@mcastAddress"), createString(udp->mcastAddress)); @@ -246,7 +269,8 @@ IceRuby::createConnectionInfo(const Ice::ConnectionInfoPtr& p) } else if (dynamic_pointer_cast(p)) { - info = Data_Wrap_Struct(_sslConnectionInfoClass, 0, IceRuby_ConnectionInfo_free, new Ice::ConnectionInfoPtr(p)); + info = + TypedData_Wrap_Struct(_sslConnectionInfoClass, &IceRuby_ConnectionInfoType, new Ice::ConnectionInfoPtr(p)); Ice::SSL::ConnectionInfoPtr ssl = dynamic_pointer_cast(p); string encoded; @@ -258,11 +282,12 @@ IceRuby::createConnectionInfo(const Ice::ConnectionInfoPtr& p) } else if (dynamic_pointer_cast(p)) { - info = Data_Wrap_Struct(_ipConnectionInfoClass, 0, IceRuby_ConnectionInfo_free, new Ice::ConnectionInfoPtr(p)); + info = + TypedData_Wrap_Struct(_ipConnectionInfoClass, &IceRuby_ConnectionInfoType, new Ice::ConnectionInfoPtr(p)); } else { - info = Data_Wrap_Struct(_connectionInfoClass, 0, IceRuby_ConnectionInfo_free, new Ice::ConnectionInfoPtr(p)); + info = TypedData_Wrap_Struct(_connectionInfoClass, &IceRuby_ConnectionInfoType, new Ice::ConnectionInfoPtr(p)); } if (dynamic_pointer_cast(p)) diff --git a/ruby/src/IceRuby/Endpoint.cpp b/ruby/src/IceRuby/Endpoint.cpp index 51737ce5702..71745238002 100644 --- a/ruby/src/IceRuby/Endpoint.cpp +++ b/ruby/src/IceRuby/Endpoint.cpp @@ -22,16 +22,27 @@ static VALUE _sslEndpointInfoClass; // Endpoint extern "C" void -IceRuby_Endpoint_free(Ice::EndpointPtr* p) +IceRuby_Endpoint_free(void* p) { - assert(p); - delete p; + delete static_cast(p); } +static const rb_data_type_t IceRuby_EndpointType = { + .wrap_struct_name = "Ice::Endpoint", + .function = + { + .dmark = nullptr, + .dfree = IceRuby_Endpoint_free, + .dsize = nullptr, + }, + .data = nullptr, + .flags = RUBY_TYPED_FREE_IMMEDIATELY, +}; + VALUE IceRuby::createEndpoint(const Ice::EndpointPtr& p) { - return Data_Wrap_Struct(_endpointClass, 0, IceRuby_Endpoint_free, new Ice::EndpointPtr(p)); + return TypedData_Wrap_Struct(_endpointClass, &IceRuby_EndpointType, new Ice::EndpointPtr(p)); } extern "C" VALUE @@ -105,12 +116,23 @@ IceRuby_Endpoint_equals(VALUE self, VALUE other) // EndpointInfo extern "C" void -IceRuby_EndpointInfo_free(Ice::EndpointPtr* p) +IceRuby_EndpointInfo_free(void* p) { - assert(p); - delete p; + delete static_cast(p); } +static const rb_data_type_t IceRuby_EndpointInfoType = { + .wrap_struct_name = "Ice::EndpointInfo", + .function = + { + .dmark = nullptr, + .dfree = IceRuby_EndpointInfo_free, + .dsize = nullptr, + }, + .data = nullptr, + .flags = RUBY_TYPED_FREE_IMMEDIATELY, +}; + VALUE IceRuby::createEndpointInfo(const Ice::EndpointInfoPtr& p) { @@ -122,18 +144,18 @@ IceRuby::createEndpointInfo(const Ice::EndpointInfoPtr& p) VALUE info; if (dynamic_pointer_cast(p)) { - info = Data_Wrap_Struct(_wsEndpointInfoClass, 0, IceRuby_EndpointInfo_free, new Ice::EndpointInfoPtr(p)); + info = TypedData_Wrap_Struct(_wsEndpointInfoClass, &IceRuby_EndpointInfoType, new Ice::EndpointInfoPtr(p)); Ice::WSEndpointInfoPtr ws = dynamic_pointer_cast(p); rb_ivar_set(info, rb_intern("@resource"), createString(ws->resource)); } else if (dynamic_pointer_cast(p)) { - info = Data_Wrap_Struct(_tcpEndpointInfoClass, 0, IceRuby_EndpointInfo_free, new Ice::EndpointInfoPtr(p)); + info = TypedData_Wrap_Struct(_tcpEndpointInfoClass, &IceRuby_EndpointInfoType, new Ice::EndpointInfoPtr(p)); } else if (dynamic_pointer_cast(p)) { - info = Data_Wrap_Struct(_udpEndpointInfoClass, 0, IceRuby_EndpointInfo_free, new Ice::EndpointInfoPtr(p)); + info = TypedData_Wrap_Struct(_udpEndpointInfoClass, &IceRuby_EndpointInfoType, new Ice::EndpointInfoPtr(p)); Ice::UDPEndpointInfoPtr udp = dynamic_pointer_cast(p); rb_ivar_set(info, rb_intern("@mcastInterface"), createString(udp->mcastInterface)); @@ -141,7 +163,7 @@ IceRuby::createEndpointInfo(const Ice::EndpointInfoPtr& p) } else if (dynamic_pointer_cast(p)) { - info = Data_Wrap_Struct(_opaqueEndpointInfoClass, 0, IceRuby_EndpointInfo_free, new Ice::EndpointInfoPtr(p)); + info = TypedData_Wrap_Struct(_opaqueEndpointInfoClass, &IceRuby_EndpointInfoType, new Ice::EndpointInfoPtr(p)); Ice::OpaqueEndpointInfoPtr opaque = dynamic_pointer_cast(p); auto b = opaque->rawBytes; @@ -151,15 +173,15 @@ IceRuby::createEndpointInfo(const Ice::EndpointInfoPtr& p) } else if (dynamic_pointer_cast(p)) { - info = Data_Wrap_Struct(_sslEndpointInfoClass, 0, IceRuby_EndpointInfo_free, new Ice::EndpointInfoPtr(p)); + info = TypedData_Wrap_Struct(_sslEndpointInfoClass, &IceRuby_EndpointInfoType, new Ice::EndpointInfoPtr(p)); } else if (dynamic_pointer_cast(p)) { - info = Data_Wrap_Struct(_ipEndpointInfoClass, 0, IceRuby_EndpointInfo_free, new Ice::EndpointInfoPtr(p)); + info = TypedData_Wrap_Struct(_ipEndpointInfoClass, &IceRuby_EndpointInfoType, new Ice::EndpointInfoPtr(p)); } else { - info = Data_Wrap_Struct(_endpointInfoClass, 0, IceRuby_EndpointInfo_free, new Ice::EndpointInfoPtr(p)); + info = TypedData_Wrap_Struct(_endpointInfoClass, &IceRuby_EndpointInfoType, new Ice::EndpointInfoPtr(p)); } if (dynamic_pointer_cast(p)) diff --git a/ruby/src/IceRuby/ImplicitContext.cpp b/ruby/src/IceRuby/ImplicitContext.cpp index d8d7dd8f4cd..91de683905b 100644 --- a/ruby/src/IceRuby/ImplicitContext.cpp +++ b/ruby/src/IceRuby/ImplicitContext.cpp @@ -13,12 +13,23 @@ using namespace IceRuby; static VALUE _implicitContextClass; extern "C" void -IceRuby_ImplicitContext_free(Ice::ImplicitContextPtr* p) +IceRuby_ImplicitContext_free(void* p) { - assert(p); - delete p; + delete static_cast(p); } +static const rb_data_type_t IceRuby_ImplicitContextType = { + .wrap_struct_name = "Ice::ImplicitContext", + .function = + { + .dmark = nullptr, + .dfree = IceRuby_ImplicitContext_free, + .dsize = nullptr, + }, + .data = nullptr, + .flags = RUBY_TYPED_FREE_IMMEDIATELY, +}; + extern "C" VALUE IceRuby_ImplicitContext_getContext(VALUE self) { @@ -133,5 +144,5 @@ IceRuby::getImplicitContext(VALUE v) VALUE IceRuby::createImplicitContext(const Ice::ImplicitContextPtr& p) { - return Data_Wrap_Struct(_implicitContextClass, 0, IceRuby_ImplicitContext_free, new Ice::ImplicitContextPtr(p)); + return TypedData_Wrap_Struct(_implicitContextClass, &IceRuby_ImplicitContextType, new Ice::ImplicitContextPtr(p)); } diff --git a/ruby/src/IceRuby/Logger.cpp b/ruby/src/IceRuby/Logger.cpp index 857df1f1fbf..639d4422b3a 100644 --- a/ruby/src/IceRuby/Logger.cpp +++ b/ruby/src/IceRuby/Logger.cpp @@ -12,16 +12,27 @@ using namespace IceRuby; static VALUE _loggerClass; extern "C" void -IceRuby_Logger_free(Ice::LoggerPtr* p) +IceRuby_Logger_free(void* p) { - assert(p); - delete p; + delete static_cast(p); } +static const rb_data_type_t IceRuby_LoggerType = { + .wrap_struct_name = "Ice::Logger", + .function = + { + .dmark = nullptr, + .dfree = IceRuby_Logger_free, + .dsize = nullptr, + }, + .data = nullptr, + .flags = RUBY_TYPED_FREE_IMMEDIATELY, +}; + VALUE IceRuby::createLogger(const Ice::LoggerPtr& p) { - return Data_Wrap_Struct(_loggerClass, 0, IceRuby_Logger_free, new Ice::LoggerPtr(p)); + return TypedData_Wrap_Struct(_loggerClass, &IceRuby_LoggerType, new Ice::LoggerPtr(p)); } extern "C" VALUE diff --git a/ruby/src/IceRuby/Operation.cpp b/ruby/src/IceRuby/Operation.cpp index 0b20a4cdb13..a9a1054653d 100644 --- a/ruby/src/IceRuby/Operation.cpp +++ b/ruby/src/IceRuby/Operation.cpp @@ -71,11 +71,23 @@ namespace IceRuby } extern "C" void -IceRuby_Operation_free(OperationPtr* p) +IceRuby_Operation_free(void* p) { - delete p; + delete static_cast(p); } +static const rb_data_type_t IceRuby_OperationType = { + .wrap_struct_name = "Ice::Operation", + .function = + { + .dmark = nullptr, + .dfree = IceRuby_Operation_free, + .dsize = nullptr, + }, + .data = nullptr, + .flags = RUBY_TYPED_FREE_IMMEDIATELY, +}; + extern "C" VALUE IceRuby_defineOperation( VALUE /*self*/, @@ -90,7 +102,7 @@ IceRuby_defineOperation( ICE_RUBY_TRY { OperationIPtr op = make_shared(name, mode, format, inParams, outParams, returnType, exceptions); - return Data_Wrap_Struct(_operationClass, 0, IceRuby_Operation_free, new OperationPtr(op)); + return TypedData_Wrap_Struct(_operationClass, &IceRuby_OperationType, new OperationPtr(op)); } ICE_RUBY_CATCH return Qnil; diff --git a/ruby/src/IceRuby/Properties.cpp b/ruby/src/IceRuby/Properties.cpp index c472f2367cb..b31bcfc3fb0 100644 --- a/ruby/src/IceRuby/Properties.cpp +++ b/ruby/src/IceRuby/Properties.cpp @@ -13,12 +13,23 @@ using namespace IceRuby; static VALUE _propertiesClass; extern "C" void -IceRuby_Properties_free(Ice::PropertiesPtr* p) +IceRuby_Properties_free(void* p) { - assert(p); - delete p; + delete static_cast(p); } +static const rb_data_type_t IceRuby_PropertiesType = { + .wrap_struct_name = "Ice::Properties", + .function = + { + .dmark = nullptr, + .dfree = IceRuby_Properties_free, + .dsize = nullptr, + }, + .data = nullptr, + .flags = RUBY_TYPED_FREE_IMMEDIATELY, +}; + extern "C" VALUE IceRuby_createProperties(int argc, VALUE* argv, VALUE /*self*/) { @@ -411,5 +422,5 @@ IceRuby::getProperties(VALUE v) VALUE IceRuby::createProperties(const Ice::PropertiesPtr& p) { - return Data_Wrap_Struct(_propertiesClass, 0, IceRuby_Properties_free, new Ice::PropertiesPtr(p)); + return TypedData_Wrap_Struct(_propertiesClass, &IceRuby_PropertiesType, new Ice::PropertiesPtr(p)); } diff --git a/ruby/src/IceRuby/Proxy.cpp b/ruby/src/IceRuby/Proxy.cpp index cf64b259330..722f5d01e99 100644 --- a/ruby/src/IceRuby/Proxy.cpp +++ b/ruby/src/IceRuby/Proxy.cpp @@ -22,22 +22,33 @@ static VALUE _proxyClass; // ObjectPrx extern "C" void -IceRuby_ObjectPrx_mark(Ice::ObjectPrx* p) +IceRuby_ObjectPrx_mark(void* p) { // We need to mark the communicator associated with this proxy. - assert(p); - volatile VALUE communicator = lookupCommunicator((*p)->ice_getCommunicator()); + auto proxy = static_cast(p); + volatile VALUE communicator = lookupCommunicator((*proxy)->ice_getCommunicator()); assert(!NIL_P(communicator)); rb_gc_mark(communicator); } extern "C" void -IceRuby_ObjectPrx_free(Ice::ObjectPrx* p) +IceRuby_ObjectPrx_free(void* p) { - assert(p); - delete p; + delete static_cast(p); } +static const rb_data_type_t IceRuby_ObjectPrxType = { + .wrap_struct_name = "Ice::ObjectPrx", + .function = + { + .dmark = IceRuby_ObjectPrx_mark, + .dfree = IceRuby_ObjectPrx_free, + .dsize = nullptr, + }, + .data = nullptr, + .flags = RUBY_TYPED_FREE_IMMEDIATELY, +}; + // If a context was provided set it to ::Ice::noExplicitContext. static void checkArgs(const char* name, int numArgs, int argc, VALUE* argv, Ice::Context& ctx) @@ -1246,10 +1257,9 @@ VALUE IceRuby::createProxy(Ice::ObjectPrx p, VALUE cls) { // If cls is nil then the proxy has the base type Ice::ObjectPrx. - return Data_Wrap_Struct( + return TypedData_Wrap_Struct( NIL_P(cls) ? _proxyClass : cls, - IceRuby_ObjectPrx_mark, - IceRuby_ObjectPrx_free, + &IceRuby_ObjectPrxType, new Ice::ObjectPrx(std::move(p))); } diff --git a/ruby/src/IceRuby/ValueFactoryManager.cpp b/ruby/src/IceRuby/ValueFactoryManager.cpp index 09beb30b65e..1db4c1c4fbd 100644 --- a/ruby/src/IceRuby/ValueFactoryManager.cpp +++ b/ruby/src/IceRuby/ValueFactoryManager.cpp @@ -35,19 +35,30 @@ namespace } extern "C" void -IceRuby_ValueFactoryManager_mark(ValueFactoryManagerPtr* p) +IceRuby_ValueFactoryManager_mark(void* p) { - assert(p); - (*p)->mark(); + auto manager = static_cast(p); + (*manager)->mark(); } extern "C" void -IceRuby_ValueFactoryManager_free(ValueFactoryManagerPtr* p) +IceRuby_ValueFactoryManager_free(void* p) { - assert(p); - delete p; + delete static_cast(p); } +static const rb_data_type_t IceRuby_ValueFactoryManagerType = { + .wrap_struct_name = "Ice::ValueFactoryManager", + .function = + { + .dmark = nullptr, + .dfree = IceRuby_ValueFactoryManager_free, + .dsize = nullptr, + }, + .data = nullptr, + .flags = RUBY_TYPED_FREE_IMMEDIATELY, +}; + /* static */ ValueFactoryManagerPtr IceRuby::ValueFactoryManager::ValueFactoryManager::create() { @@ -57,10 +68,9 @@ IceRuby::ValueFactoryManager::ValueFactoryManager::create() // // Create a Ruby wrapper around this object. Note that this is a cyclic reference. // - vfm->_self = Data_Wrap_Struct( + vfm->_self = TypedData_Wrap_Struct( _valueFactoryManagerClass, - IceRuby_ValueFactoryManager_mark, - IceRuby_ValueFactoryManager_free, + &IceRuby_ValueFactoryManagerType, new ValueFactoryManagerPtr(vfm)); return vfm;