Skip to content

Commit

Permalink
Add support for Ruby 3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
externl committed Jan 6, 2025
1 parent e99d2e5 commit ea98f33
Show file tree
Hide file tree
Showing 9 changed files with 194 additions and 71 deletions.
29 changes: 20 additions & 9 deletions ruby/src/IceRuby/Communicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ using CommunicatorMap = map<Ice::CommunicatorPtr, VALUE>;
static CommunicatorMap _communicatorMap;

extern "C" void
IceRuby_Communicator_mark(Ice::CommunicatorPtr* p)
IceRuby_Communicator_mark(void* p)
{
assert(p);
auto communicator = static_cast<Ice::CommunicatorPtr*>(p);
try
{
auto vfm = dynamic_pointer_cast<ValueFactoryManager>((*p)->getValueFactoryManager());
auto vfm = dynamic_pointer_cast<ValueFactoryManager>((*communicator)->getValueFactoryManager());
assert(vfm);
vfm->markSelf();
}
Expand All @@ -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<Ice::CommunicatorPtr*>(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
Expand Down Expand Up @@ -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);
Expand Down
55 changes: 40 additions & 15 deletions ruby/src/IceRuby/Connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Ice::ConnectionPtr*>(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
Expand Down Expand Up @@ -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<Ice::ConnectionInfoPtr*>(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)
{
Expand All @@ -214,7 +234,8 @@ IceRuby::createConnectionInfo(const Ice::ConnectionInfoPtr& p)
VALUE info;
if (dynamic_pointer_cast<Ice::WSConnectionInfo>(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<Ice::WSConnectionInfo>(p);
volatile VALUE result = callRuby(rb_hash_new);
Expand All @@ -228,15 +249,17 @@ IceRuby::createConnectionInfo(const Ice::ConnectionInfoPtr& p)
}
else if (dynamic_pointer_cast<Ice::TCPConnectionInfo>(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<Ice::TCPConnectionInfo>(p);
rb_ivar_set(info, rb_intern("@rcvSize"), INT2FIX(tcp->rcvSize));
rb_ivar_set(info, rb_intern("@sndSize"), INT2FIX(tcp->sndSize));
}
else if (dynamic_pointer_cast<Ice::UDPConnectionInfo>(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<Ice::UDPConnectionInfo>(p);
rb_ivar_set(info, rb_intern("@mcastAddress"), createString(udp->mcastAddress));
Expand All @@ -246,7 +269,8 @@ IceRuby::createConnectionInfo(const Ice::ConnectionInfoPtr& p)
}
else if (dynamic_pointer_cast<Ice::SSL::ConnectionInfo>(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<Ice::SSL::ConnectionInfo>(p);
string encoded;
Expand All @@ -258,11 +282,12 @@ IceRuby::createConnectionInfo(const Ice::ConnectionInfoPtr& p)
}
else if (dynamic_pointer_cast<Ice::IPConnectionInfo>(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<Ice::IPConnectionInfo>(p))
Expand Down
50 changes: 36 additions & 14 deletions ruby/src/IceRuby/Endpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Ice::EndpointPtr*>(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
Expand Down Expand Up @@ -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<Ice::EndpointInfoPtr*>(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)
{
Expand All @@ -122,26 +144,26 @@ IceRuby::createEndpointInfo(const Ice::EndpointInfoPtr& p)
VALUE info;
if (dynamic_pointer_cast<Ice::WSEndpointInfo>(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<Ice::WSEndpointInfo>(p);
rb_ivar_set(info, rb_intern("@resource"), createString(ws->resource));
}
else if (dynamic_pointer_cast<Ice::TCPEndpointInfo>(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<Ice::UDPEndpointInfo>(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<Ice::UDPEndpointInfo>(p);
rb_ivar_set(info, rb_intern("@mcastInterface"), createString(udp->mcastInterface));
rb_ivar_set(info, rb_intern("@mcastTtl"), INT2FIX(udp->mcastTtl));
}
else if (dynamic_pointer_cast<Ice::OpaqueEndpointInfo>(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<Ice::OpaqueEndpointInfo>(p);
auto b = opaque->rawBytes;
Expand All @@ -151,15 +173,15 @@ IceRuby::createEndpointInfo(const Ice::EndpointInfoPtr& p)
}
else if (dynamic_pointer_cast<Ice::SSL::EndpointInfo>(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<Ice::IPEndpointInfo>(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<Ice::IPEndpointInfo>(p))
Expand Down
19 changes: 15 additions & 4 deletions ruby/src/IceRuby/ImplicitContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Ice::ImplicitContextPtr*>(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)
{
Expand Down Expand Up @@ -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));
}
19 changes: 15 additions & 4 deletions ruby/src/IceRuby/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Ice::LoggerPtr*>(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
Expand Down
18 changes: 15 additions & 3 deletions ruby/src/IceRuby/Operation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,23 @@ namespace IceRuby
}

extern "C" void
IceRuby_Operation_free(OperationPtr* p)
IceRuby_Operation_free(void* p)
{
delete p;
delete static_cast<OperationPtr*>(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*/,
Expand All @@ -90,7 +102,7 @@ IceRuby_defineOperation(
ICE_RUBY_TRY
{
OperationIPtr op = make_shared<OperationI>(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;
Expand Down
Loading

0 comments on commit ea98f33

Please sign in to comment.