Skip to content

Commit

Permalink
ICE-7023 - Ruby 2.3 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
spruiell committed Mar 16, 2016
1 parent f94e41a commit 2470db9
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 48 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG-3.6.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ These are the changes since Ice 3.6.1.
- Fixed a bug where unmarshaling Ice objects was really slow when using
compact type IDs.

## Ruby Changes

- Added compatibility with Ruby 2.3.

# Changes in Ice 3.6.1

These are the changes since Ice 3.6.0.
Expand Down
11 changes: 11 additions & 0 deletions ruby/src/IceRuby/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,15 @@ typedef VALUE(*ICE_RUBY_ENTRY_POINT)(...);
# define RFLOAT_VALUE(v) RFLOAT(v)->value
#endif

//
// The RARRAY_AREF and RARRAY_ASET macros were added in Ruby 2.1.
//
#ifndef RARRAY_AREF
# define RARRAY_AREF(a, i) (RARRAY_PTR(a)[i])
#endif

#ifndef RARRAY_ASET
# define RARRAY_ASET(a, i, v) RARRAY_PTR(a)[i] = v
#endif

#endif
22 changes: 11 additions & 11 deletions ruby/src/IceRuby/Operation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ IceRuby::ParamInfo::unmarshaled(VALUE val, VALUE target, void* closure)
#else
long i = reinterpret_cast<long>(closure);
#endif
RARRAY_PTR(target)[i] = val;
RARRAY_ASET(target, i, val);
}

//
Expand Down Expand Up @@ -278,7 +278,7 @@ IceRuby::OperationI::OperationI(VALUE name, VALUE mode, VALUE sendMode, VALUE am
//
for(long i = 0; i < RARRAY_LEN(exceptions); ++i)
{
_exceptions.push_back(getException(RARRAY_PTR(exceptions)[i]));
_exceptions.push_back(getException(RARRAY_AREF(exceptions, i)));
}
}

Expand Down Expand Up @@ -350,7 +350,7 @@ IceRuby::OperationI::invoke(const Ice::ObjectPrx& proxy, VALUE args, VALUE hctx)
}
else
{
return RARRAY_PTR(results)[0];
return RARRAY_AREF(results, 0);
}
}
}
Expand Down Expand Up @@ -378,7 +378,7 @@ IceRuby::OperationI::convertParams(VALUE v, ParamInfoList& params, int posOffset

for(long i = 0; i < RARRAY_LEN(v); ++i)
{
ParamInfoPtr param = convertParam(RARRAY_PTR(v)[i], i + posOffset);
ParamInfoPtr param = convertParam(RARRAY_AREF(v, i), i + posOffset);
params.push_back(param);
if(!param->optional && !usesClasses)
{
Expand All @@ -392,9 +392,9 @@ IceRuby::OperationI::convertParam(VALUE v, int pos)
{
assert(TYPE(v) == T_ARRAY);
ParamInfoPtr param = new ParamInfo;
param->type = getType(RARRAY_PTR(v)[0]);
param->optional = static_cast<bool>(RTEST(RARRAY_PTR(v)[1]));
param->tag = static_cast<int>(getInteger(RARRAY_PTR(v)[2]));
param->type = getType(RARRAY_AREF(v, 0));
param->optional = static_cast<bool>(RTEST(RARRAY_AREF(v, 1)));
param->tag = static_cast<int>(getInteger(RARRAY_AREF(v, 2)));
param->pos = pos;
return param;
}
Expand Down Expand Up @@ -432,7 +432,7 @@ IceRuby::OperationI::prepareRequest(const Ice::ObjectPrx& proxy, VALUE args, Ice
for(p = _inParams.begin(); p != _inParams.end(); ++p)
{
ParamInfoPtr info = *p;
volatile VALUE arg = RARRAY_PTR(args)[info->pos];
volatile VALUE arg = RARRAY_AREF(args, info->pos);
if((!info->optional || arg != Unset) && !info->type->validate(arg))
{
string opName = fixIdent(_name, IdentNormal);
Expand All @@ -449,7 +449,7 @@ IceRuby::OperationI::prepareRequest(const Ice::ObjectPrx& proxy, VALUE args, Ice
ParamInfoPtr info = *p;
if(!info->optional)
{
volatile VALUE arg = RARRAY_PTR(args)[info->pos];
volatile VALUE arg = RARRAY_AREF(args, info->pos);
info->type->marshal(arg, os, &objectMap, false);
}
}
Expand All @@ -460,7 +460,7 @@ IceRuby::OperationI::prepareRequest(const Ice::ObjectPrx& proxy, VALUE args, Ice
for(p = _optionalInParams.begin(); p != _optionalInParams.end(); ++p)
{
ParamInfoPtr info = *p;
volatile VALUE arg = RARRAY_PTR(args)[info->pos];
volatile VALUE arg = RARRAY_AREF(args, info->pos);
if(arg != Unset && os->writeOptional(info->tag, info->type->optionalFormat()))
{
info->type->marshal(arg, os, &objectMap, true);
Expand Down Expand Up @@ -543,7 +543,7 @@ IceRuby::OperationI::unmarshalResults(const vector<Ice::Byte>& bytes, const Ice:
}
else
{
RARRAY_PTR(results)[info->pos] = Unset;
RARRAY_ASET(results, info->pos, Unset);
}
}

Expand Down
8 changes: 4 additions & 4 deletions ruby/src/IceRuby/Proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ IceRuby_ObjectPrx_ice_ids(int argc, VALUE* argv, VALUE self)
long i = 0;
for(vector<string>::iterator q = ids.begin(); q != ids.end(); ++q, ++i)
{
RARRAY_PTR(result)[i] = createString(*q);
RARRAY_ASET(result, i, createString(*q));
}

return result;
Expand Down Expand Up @@ -352,7 +352,7 @@ IceRuby_ObjectPrx_ice_getEndpoints(VALUE self)
long i = 0;
for(Ice::EndpointSeq::iterator q = seq.begin(); q != seq.end(); ++q, ++i)
{
RARRAY_PTR(result)[i] = createEndpoint(*q);
RARRAY_ASET(result, i, createEndpoint(*q));
}
return result;
}
Expand Down Expand Up @@ -383,11 +383,11 @@ IceRuby_ObjectPrx_ice_endpoints(VALUE self, VALUE seq)
}
for(long i = 0; i < RARRAY_LEN(arr); ++i)
{
if(!checkEndpoint(RARRAY_PTR(arr)[i]))
if(!checkEndpoint(RARRAY_AREF(arr, i)))
{
throw RubyException(rb_eTypeError, "array element is not an Ice::Endpoint");
}
Ice::EndpointPtr* e = reinterpret_cast<Ice::EndpointPtr*>(DATA_PTR(RARRAY_PTR(arr)[i]));
Ice::EndpointPtr* e = reinterpret_cast<Ice::EndpointPtr*>(DATA_PTR(RARRAY_AREF(arr, i)));
assert(e);
endpoints.push_back(*e);
}
Expand Down
60 changes: 31 additions & 29 deletions ruby/src/IceRuby/Types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,8 @@ IceRuby::StreamUtil::setSlicedDataMember(VALUE obj, const Ice::SlicedDataPtr& sl
{
volatile VALUE slice = callRuby(rb_class_new_instance, 0, static_cast<VALUE*>(0), _sliceInfoType);

RARRAY_PTR(slices)[i++] = slice;
RARRAY_ASET(slices, i, slice);
i++;

//
// typeId
Expand Down Expand Up @@ -295,7 +296,8 @@ IceRuby::StreamUtil::setSlicedDataMember(VALUE obj, const Ice::SlicedDataPtr& sl
assert(r);
VALUE o = r->getObject();
assert(o != Qnil); // Should be non-nil.
RARRAY_PTR(objects)[j++] = o;
RARRAY_ASET(objects, j, o);
j++;
}

//
Expand Down Expand Up @@ -338,7 +340,7 @@ IceRuby::StreamUtil::getSlicedDataMember(VALUE obj, ObjectMap* objectMap)
long sz = RARRAY_LEN(sl);
for(long i = 0; i < sz; ++i)
{
volatile VALUE s = RARRAY_PTR(sl)[i];
volatile VALUE s = RARRAY_AREF(sl, i);

Ice::SliceInfoPtr info = new Ice::SliceInfo;

Expand All @@ -364,7 +366,7 @@ IceRuby::StreamUtil::getSlicedDataMember(VALUE obj, ObjectMap* objectMap)
long osz = RARRAY_LEN(objects);
for(long j = 0; j < osz; ++j)
{
VALUE o = RARRAY_PTR(objects)[j];
VALUE o = RARRAY_AREF(objects, j);

Ice::ObjectPtr writer;

Expand Down Expand Up @@ -876,21 +878,21 @@ convertDataMembers(VALUE members, DataMemberList& reqMembers, DataMemberList& op
assert(!NIL_P(arr));
for(long i = 0; i < RARRAY_LEN(arr); ++i)
{
volatile VALUE m = callRuby(rb_check_array_type, RARRAY_PTR(arr)[i]);
volatile VALUE m = callRuby(rb_check_array_type, RARRAY_AREF(arr, i));
assert(!NIL_P(m));
assert(RARRAY_LEN(m) == allowOptional ? 4 : 2);

DataMemberPtr member = new DataMember;

member->name = getString(RARRAY_PTR(m)[0]);
member->type = getType(RARRAY_PTR(m)[1]);
member->name = getString(RARRAY_AREF(m, 0));
member->type = getType(RARRAY_AREF(m, 1));
string s = "@" + member->name;
member->rubyID = rb_intern(s.c_str());

if(allowOptional)
{
member->optional = RTEST(RARRAY_PTR(m)[2]);
member->tag = static_cast<int>(getInteger(RARRAY_PTR(m)[3]));
member->optional = RTEST(RARRAY_AREF(m, 2));
member->tag = static_cast<int>(getInteger(RARRAY_AREF(m, 3)));
}
else
{
Expand Down Expand Up @@ -1238,12 +1240,12 @@ IceRuby::SequenceInfo::marshal(VALUE p, Ice::OutputStream* os, ObjectMap* object
os->writeSize(static_cast<Ice::Int>(sz));
for(long i = 0; i < sz; ++i)
{
if(!elementType->validate(RARRAY_PTR(arr)[i]))
if(!elementType->validate(RARRAY_AREF(arr, i)))
{
throw RubyException(rb_eTypeError, "invalid value for element %ld of `%s'", i,
const_cast<char*>(id.c_str()));
}
elementType->marshal(RARRAY_PTR(arr)[i], os, objectMap, false);
elementType->marshal(RARRAY_AREF(arr, i), os, objectMap, false);
}
}

Expand Down Expand Up @@ -1296,7 +1298,7 @@ IceRuby::SequenceInfo::unmarshaled(VALUE val, VALUE target, void* closure)
#else
long i = reinterpret_cast<long>(closure);
#endif
RARRAY_PTR(target)[i] = val;
RARRAY_ASET(target, i, val);
}

void
Expand Down Expand Up @@ -1336,7 +1338,7 @@ IceRuby::SequenceInfo::print(VALUE value, IceUtilInternal::Output& out, PrintObj
for(long i = 0; i < sz; ++i)
{
out << nl << '[' << i << "] = ";
elementType->print(RARRAY_PTR(arr)[i], out, history);
elementType->print(RARRAY_AREF(arr, i), out, history);
}
out.eb();
}
Expand Down Expand Up @@ -1393,7 +1395,7 @@ IceRuby::SequenceInfo::marshalPrimitiveSequence(const PrimitiveInfoPtr& pi, VALU
Ice::BoolSeq seq(sz);
for(long i = 0; i < sz; ++i)
{
seq[i] = RTEST(RARRAY_PTR(arr)[i]);
seq[i] = RTEST(RARRAY_AREF(arr, i));
}
os->write(seq);
break;
Expand All @@ -1419,7 +1421,7 @@ IceRuby::SequenceInfo::marshalPrimitiveSequence(const PrimitiveInfoPtr& pi, VALU
Ice::ByteSeq seq(sz);
for(long i = 0; i < sz; ++i)
{
long val = getInteger(RARRAY_PTR(arr)[i]);
long val = getInteger(RARRAY_AREF(arr, i));
if(val < 0 || val > 255)
{
throw RubyException(rb_eTypeError, "invalid value for element %ld of sequence<byte>", i);
Expand All @@ -1436,7 +1438,7 @@ IceRuby::SequenceInfo::marshalPrimitiveSequence(const PrimitiveInfoPtr& pi, VALU
Ice::ShortSeq seq(sz);
for(long i = 0; i < sz; ++i)
{
long val = getInteger(RARRAY_PTR(arr)[i]);
long val = getInteger(RARRAY_AREF(arr, i));
if(val < SHRT_MIN || val > SHRT_MAX)
{
throw RubyException(rb_eTypeError, "invalid value for element %ld of sequence<short>", i);
Expand All @@ -1452,7 +1454,7 @@ IceRuby::SequenceInfo::marshalPrimitiveSequence(const PrimitiveInfoPtr& pi, VALU
Ice::IntSeq seq(sz);
for(long i = 0; i < sz; ++i)
{
long val = getInteger(RARRAY_PTR(arr)[i]);
long val = getInteger(RARRAY_AREF(arr, i));
if(val < INT_MIN || val > INT_MAX)
{
throw RubyException(rb_eTypeError, "invalid value for element %ld of sequence<int>", i);
Expand All @@ -1468,7 +1470,7 @@ IceRuby::SequenceInfo::marshalPrimitiveSequence(const PrimitiveInfoPtr& pi, VALU
Ice::LongSeq seq(sz);
for(long i = 0; i < sz; ++i)
{
seq[i] = getLong(RARRAY_PTR(arr)[i]);
seq[i] = getLong(RARRAY_AREF(arr, i));
}
os->write(&seq[0], &seq[0] + seq.size());
break;
Expand All @@ -1479,7 +1481,7 @@ IceRuby::SequenceInfo::marshalPrimitiveSequence(const PrimitiveInfoPtr& pi, VALU
Ice::FloatSeq seq(sz);
for(long i = 0; i < sz; ++i)
{
volatile VALUE v = callRuby(rb_Float, RARRAY_PTR(arr)[i]);
volatile VALUE v = callRuby(rb_Float, RARRAY_AREF(arr, i));
if(NIL_P(v))
{
throw RubyException(rb_eTypeError, "unable to convert array element %ld to a float", i);
Expand All @@ -1496,7 +1498,7 @@ IceRuby::SequenceInfo::marshalPrimitiveSequence(const PrimitiveInfoPtr& pi, VALU
Ice::DoubleSeq seq(sz);
for(long i = 0; i < sz; ++i)
{
volatile VALUE v = callRuby(rb_Float, RARRAY_PTR(arr)[i]);
volatile VALUE v = callRuby(rb_Float, RARRAY_AREF(arr, i));
if(NIL_P(v))
{
throw RubyException(rb_eTypeError, "unable to convert array element %ld to a double", i);
Expand All @@ -1513,7 +1515,7 @@ IceRuby::SequenceInfo::marshalPrimitiveSequence(const PrimitiveInfoPtr& pi, VALU
Ice::StringSeq seq(sz);
for(long i = 0; i < sz; ++i)
{
seq[i] = getString(RARRAY_PTR(arr)[i]);
seq[i] = getString(RARRAY_AREF(arr, i));
}
os->write(&seq[0], &seq[0] + seq.size());
break;
Expand Down Expand Up @@ -1541,7 +1543,7 @@ IceRuby::SequenceInfo::unmarshalPrimitiveSequence(const PrimitiveInfoPtr& pi, Ic
{
for(long i = 0; i < sz; ++i)
{
RARRAY_PTR(result)[i] = p.first[i] ? Qtrue : Qfalse;
RARRAY_ASET(result, i, p.first[i] ? Qtrue : Qfalse);
}
}
break;
Expand All @@ -1565,7 +1567,7 @@ IceRuby::SequenceInfo::unmarshalPrimitiveSequence(const PrimitiveInfoPtr& pi, Ic
{
for(long i = 0; i < sz; ++i)
{
RARRAY_PTR(result)[i] = INT2FIX(p.first[i]);
RARRAY_ASET(result, i, INT2FIX(p.first[i]));
}
}
break;
Expand All @@ -1582,7 +1584,7 @@ IceRuby::SequenceInfo::unmarshalPrimitiveSequence(const PrimitiveInfoPtr& pi, Ic
{
for(long i = 0; i < sz; ++i)
{
RARRAY_PTR(result)[i] = INT2FIX(p.first[i]);
RARRAY_ASET(result, i, INT2FIX(p.first[i]));
}
}
break;
Expand All @@ -1599,7 +1601,7 @@ IceRuby::SequenceInfo::unmarshalPrimitiveSequence(const PrimitiveInfoPtr& pi, Ic
{
for(long i = 0; i < sz; ++i)
{
RARRAY_PTR(result)[i] = callRuby(rb_ll2inum, p.first[i]);
RARRAY_ASET(result, i, callRuby(rb_ll2inum, p.first[i]));
}
}
break;
Expand All @@ -1616,7 +1618,7 @@ IceRuby::SequenceInfo::unmarshalPrimitiveSequence(const PrimitiveInfoPtr& pi, Ic
{
for(long i = 0; i < sz; ++i)
{
RARRAY_PTR(result)[i] = callRuby(rb_float_new, p.first[i]);
RARRAY_ASET(result, i, callRuby(rb_float_new, p.first[i]));
}
}
break;
Expand All @@ -1633,7 +1635,7 @@ IceRuby::SequenceInfo::unmarshalPrimitiveSequence(const PrimitiveInfoPtr& pi, Ic
{
for(long i = 0; i < sz; ++i)
{
RARRAY_PTR(result)[i] = callRuby(rb_float_new, p.first[i]);
RARRAY_ASET(result, i, callRuby(rb_float_new, p.first[i]));
}
}
break;
Expand All @@ -1649,7 +1651,7 @@ IceRuby::SequenceInfo::unmarshalPrimitiveSequence(const PrimitiveInfoPtr& pi, Ic
{
for(long i = 0; i < sz; ++i)
{
RARRAY_PTR(result)[i] = createString(seq[i]);
RARRAY_ASET(result, i, createString(seq[i]));
}
}
break;
Expand Down Expand Up @@ -1977,7 +1979,7 @@ IceRuby::ClassInfo::define(VALUE t, VALUE compact, VALUE abstr, VALUE pres, VALU
assert(!NIL_P(arr));
for(n = 0; n < RARRAY_LEN(arr); ++n)
{
ClassInfoPtr iface = ClassInfoPtr::dynamicCast(getType(RARRAY_PTR(arr)[n]));
ClassInfoPtr iface = ClassInfoPtr::dynamicCast(getType(RARRAY_AREF(arr, n)));
assert(iface);
const_cast<ClassInfoList&>(interfaces).push_back(iface);
}
Expand Down
Loading

0 comments on commit 2470db9

Please sign in to comment.