Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardnormier committed Jul 22, 2024
1 parent 290b9b5 commit 7610856
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 70 deletions.
4 changes: 0 additions & 4 deletions ruby/ruby/Ice/Proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ def ice_staticId()
def checkedCast(proxy, facetOrContext=nil, context=nil)
ice_checkedCast(proxy, self::ICE_ID, facetOrContext, context)
end

def uncheckedCast(proxy, facet=nil)
ice_uncheckedCast(proxy, facet)
end
end

def self.included(base)
Expand Down
103 changes: 37 additions & 66 deletions ruby/src/IceRuby/Proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,19 +189,19 @@ IceRuby_ObjectPrx_ice_getIdentity(VALUE self)
extern "C" VALUE
IceRuby_ObjectPrx_ice_identity(VALUE self, VALUE args)
{
VALUE cls = Qnil;
long len = RARRAY_LEN(args);
if (len > 2 || len == 0)
{
rb_raise(rb_eArgError, "wrong number of arguments");
}
if (len == 2)
{
cls = rb_ary_entry(args, 1);
}

ICE_RUBY_TRY
{
VALUE cls = Qnil;
long len = RARRAY_LEN(args);
if (len > 2 || len == 0)
{
throw RubyException(rb_eArgError, "ice_identity requires one or two arguments");
}
if (len == 2)
{
cls = rb_ary_entry(args, 1);
}

Ice::ObjectPrx p = getProxy(self);
Ice::Identity ident = getIdentity(rb_ary_entry(args, 0));
return createProxy(p->ice_identity(ident), cls);
Expand Down Expand Up @@ -256,19 +256,19 @@ IceRuby_ObjectPrx_ice_getFacet(VALUE self)
extern "C" VALUE
IceRuby_ObjectPrx_ice_facet(VALUE self, VALUE args)
{
VALUE cls = Qnil;
long len = RARRAY_LEN(args);
if (len > 2 || len == 0)
{
rb_raise(rb_eArgError, "wrong number of arguments");
}
if (len == 2)
{
cls = rb_ary_entry(args, 1);
}

ICE_RUBY_TRY
{
VALUE cls = Qnil;
long len = RARRAY_LEN(args);
if (len > 2 || len == 0)
{
throw RubyException(rb_eArgError, "ice_facet requires one or two arguments");
}
if (len == 2)
{
cls = rb_ary_entry(args, 1);
}

Ice::ObjectPrx p = getProxy(self);
string f = getString(rb_ary_entry(args, 0));
return createProxy(p->ice_facet(f), cls);
Expand Down Expand Up @@ -1032,47 +1032,6 @@ IceRuby_ObjectPrx_checkedCast(int argc, VALUE* args, VALUE /*self*/)
return Qnil;
}

extern "C" VALUE
IceRuby_ObjectPrx_uncheckedCast(int argc, VALUE* args, VALUE /*self*/)
{
ICE_RUBY_TRY
{
if (argc < 1 || argc > 2)
{
throw RubyException(rb_eArgError, "uncheckedCast requires a proxy argument and an optional facet");
}

if (NIL_P(args[0]))
{
return Qnil;
}

if (!checkProxy(args[0]))
{
throw RubyException(rb_eArgError, "uncheckedCast requires a proxy argument");
}

volatile VALUE facet = Qnil;
if (argc == 2)
{
facet = args[1];
}

Ice::ObjectPrx p = getProxy(args[0]);

if (!NIL_P(facet))
{
return createProxy(p->ice_facet(getString(facet)));
}
else
{
return createProxy(p);
}
}
ICE_RUBY_CATCH
return Qnil;
}

extern "C" VALUE
IceRuby_ObjectPrx_ice_checkedCast(VALUE self, VALUE obj, VALUE id, VALUE facetOrContext, VALUE ctx)
{
Expand Down Expand Up @@ -1126,10 +1085,23 @@ IceRuby_ObjectPrx_ice_checkedCast(VALUE self, VALUE obj, VALUE id, VALUE facetOr
}

extern "C" VALUE
IceRuby_ObjectPrx_ice_uncheckedCast(VALUE self, VALUE obj, VALUE facet)
IceRuby_ObjectPrx_uncheckedCast(VALUE self, VALUE args)
{
ICE_RUBY_TRY
{
VALUE facet = Qnil;
long len = RARRAY_LEN(args);
if (len > 2 || len == 0)
{
throw RubyException(rb_eArgError, "uncheckedCast requires one or two arguments");
}

VALUE obj = rb_ary_entry(args, 0);
if (len == 2)
{
facet = rb_ary_entry(args, 1);
}

if (NIL_P(obj))
{
return Qnil;
Expand Down Expand Up @@ -1264,9 +1236,8 @@ IceRuby::initProxy(VALUE iceModule)
// Static methods.
//
rb_define_singleton_method(_proxyClass, "checkedCast", CAST_METHOD(IceRuby_ObjectPrx_checkedCast), -1);
rb_define_singleton_method(_proxyClass, "uncheckedCast", CAST_METHOD(IceRuby_ObjectPrx_uncheckedCast), -1);
rb_define_singleton_method(_proxyClass, "uncheckedCast", CAST_METHOD(IceRuby_ObjectPrx_uncheckedCast), -2);
rb_define_singleton_method(_proxyClass, "ice_checkedCast", CAST_METHOD(IceRuby_ObjectPrx_ice_checkedCast), 4);
rb_define_singleton_method(_proxyClass, "ice_uncheckedCast", CAST_METHOD(IceRuby_ObjectPrx_ice_uncheckedCast), 2);
rb_define_singleton_method(_proxyClass, "ice_staticId", CAST_METHOD(IceRuby_ObjectPrx_ice_staticId), 0);
rb_define_singleton_method(_proxyClass, "new", CAST_METHOD(IceRuby_ObjectPrx_new), 2);
}
Expand Down

0 comments on commit 7610856

Please sign in to comment.