diff options
Diffstat (limited to 'rb/src/IceRuby/Util.cpp')
-rw-r--r-- | rb/src/IceRuby/Util.cpp | 300 |
1 files changed, 150 insertions, 150 deletions
diff --git a/rb/src/IceRuby/Util.cpp b/rb/src/IceRuby/Util.cpp index 272bb95516b..b02d2efcaba 100644 --- a/rb/src/IceRuby/Util.cpp +++ b/rb/src/IceRuby/Util.cpp @@ -83,19 +83,19 @@ IceRuby::getInteger(VALUE val) { if(!FIXNUM_P(val) && TYPE(val) != T_BIGNUM) { - val = callRuby(rb_Integer, val); + val = callRuby(rb_Integer, val); } if(FIXNUM_P(val)) { - return FIX2LONG(val); + return FIX2LONG(val); } else if(TYPE(val) == T_BIGNUM) { - Ice::Long l = getLong(val); - if(l >= static_cast<Ice::Long>(INT_MIN) && l <= static_cast<Ice::Long>(INT_MAX)) - { - return static_cast<long>(l); - } + Ice::Long l = getLong(val); + if(l >= static_cast<Ice::Long>(INT_MIN) && l <= static_cast<Ice::Long>(INT_MAX)) + { + return static_cast<long>(l); + } } throw RubyException(rb_eTypeError, "unable to convert value to an integer"); } @@ -114,37 +114,37 @@ IceRuby::getLong(VALUE val) volatile VALUE v = callRuby(rb_Integer, val); if(NIL_P(v)) { - throw RubyException(rb_eTypeError, "unable to convert value to a long"); + throw RubyException(rb_eTypeError, "unable to convert value to a long"); } if(FIXNUM_P(v)) { - return FIX2LONG(v); + return FIX2LONG(v); } else { - assert(TYPE(v) == T_BIGNUM); - long len = RBIGNUM(v)->len; - if(len > SIZEOF_LONG_LONG/SIZEOF_BDIGITS) - { - throw RubyException(rb_eRangeError, "bignum too big to convert into long"); - } - BDIGIT *ds = BDIGITS(v); - BDIGIT_DBL num = 0; - while(len--) - { - num = BIGUP(num); - num += ds[len]; - } - Ice::Long l = static_cast<Ice::Long>(num); - if(l < 0 && (RBIGNUM(v)->sign || l != LLONG_MIN)) - { - throw RubyException(rb_eRangeError, "bignum too big to convert into long"); - } - if (!RBIGNUM(v)->sign) - { - return -l; - } - return l; + assert(TYPE(v) == T_BIGNUM); + long len = RBIGNUM(v)->len; + if(len > SIZEOF_LONG_LONG/SIZEOF_BDIGITS) + { + throw RubyException(rb_eRangeError, "bignum too big to convert into long"); + } + BDIGIT *ds = BDIGITS(v); + BDIGIT_DBL num = 0; + while(len--) + { + num = BIGUP(num); + num += ds[len]; + } + Ice::Long l = static_cast<Ice::Long>(num); + if(l < 0 && (RBIGNUM(v)->sign || l != LLONG_MIN)) + { + throw RubyException(rb_eRangeError, "bignum too big to convert into long"); + } + if (!RBIGNUM(v)->sign) + { + return -l; + } + return l; } } @@ -154,12 +154,12 @@ IceRuby::arrayToStringSeq(VALUE val, vector<string>& seq) volatile VALUE arr = callRuby(rb_check_array_type, val); if(NIL_P(arr)) { - return false; + return false; } for(long i = 0; i < RARRAY(arr)->len; ++i) { - string s = getString(RARRAY(arr)->ptr[i]); - seq.push_back(getString(RARRAY(arr)->ptr[i])); + string s = getString(RARRAY(arr)->ptr[i]); + seq.push_back(getString(RARRAY(arr)->ptr[i])); } return true; } @@ -171,7 +171,7 @@ IceRuby::stringSeqToArray(const vector<string>& seq) long i = 0; for(vector<string>::const_iterator p = seq.begin(); p != seq.end(); ++p, ++i) { - RARRAY(result)->ptr[i] = createString(*p); + RARRAY(result)->ptr[i] = createString(*p); } RARRAY(result)->len = static_cast<long>(seq.size()); return result; @@ -188,9 +188,9 @@ struct HashToContextIterator : public IceRuby::HashIterator virtual void element(VALUE key, VALUE value) { - string kstr = IceRuby::getString(key); - string vstr = IceRuby::getString(value); - ctx[kstr] = vstr; + string kstr = IceRuby::getString(key); + string vstr = IceRuby::getString(value); + ctx[kstr] = vstr; } Ice::Context& ctx; @@ -203,11 +203,11 @@ IceRuby::hashToContext(VALUE val, Ice::Context& ctx) { if(TYPE(val) != T_HASH) { - val = callRuby(rb_convert_type, val, T_HASH, "Hash", "to_hash"); - if(NIL_P(val)) - { - return false; - } + val = callRuby(rb_convert_type, val, T_HASH, "Hash", "to_hash"); + if(NIL_P(val)) + { + return false; + } } HashToContextIterator iter(ctx); hashIterate(val, iter); @@ -220,9 +220,9 @@ IceRuby::contextToHash(const Ice::Context& ctx) volatile VALUE result = callRuby(rb_hash_new); for(Ice::Context::const_iterator p = ctx.begin(); p != ctx.end(); ++p) { - volatile VALUE key = callRuby(rb_str_new, p->first.c_str(), static_cast<long>(p->first.size())); - volatile VALUE value = callRuby(rb_str_new, p->second.c_str(), static_cast<long>(p->second.size())); - callRuby(rb_hash_aset, result, key, value); + volatile VALUE key = callRuby(rb_str_new, p->first.c_str(), static_cast<long>(p->first.size())); + volatile VALUE value = callRuby(rb_str_new, p->second.c_str(), static_cast<long>(p->second.size())); + callRuby(rb_hash_aset, result, key, value); } return result; } @@ -239,8 +239,8 @@ IceRuby_Util_hash_foreach_callback(VALUE val, VALUE arg) // ICE_RUBY_TRY { - IceRuby::HashIterator* iter = reinterpret_cast<IceRuby::HashIterator*>(arg); - iter->element(key, value); + IceRuby::HashIterator* iter = reinterpret_cast<IceRuby::HashIterator*>(arg); + iter->element(key, value); } ICE_RUBY_CATCH return val; @@ -256,8 +256,8 @@ IceRuby::hashIterate(VALUE h, HashIterator& iter) { assert(TYPE(h) == T_HASH); callRuby(rb_iterate, rb_each, h, - reinterpret_cast<ICE_RUBY_HASH_FOREACH_CALLBACK>(IceRuby_Util_hash_foreach_callback), - reinterpret_cast<VALUE>(&iter)); + reinterpret_cast<ICE_RUBY_HASH_FOREACH_CALLBACK>(IceRuby_Util_hash_foreach_callback), + reinterpret_cast<VALUE>(&iter)); } Ice::Identity @@ -268,7 +268,7 @@ IceRuby::getIdentity(VALUE v) if(callRuby(rb_obj_is_kind_of, v, cls) == Qfalse) { - throw RubyException(rb_eTypeError, "value is not an Ice::Identity"); + throw RubyException(rb_eTypeError, "value is not an Ice::Identity"); } volatile VALUE name = callRuby(rb_iv_get, v, "@name"); @@ -276,19 +276,19 @@ IceRuby::getIdentity(VALUE v) if(!NIL_P(category) && !isString(category)) { - throw RubyException(rb_eTypeError, "identity category must be a string"); + throw RubyException(rb_eTypeError, "identity category must be a string"); } if(NIL_P(name) || !isString(name)) { - throw RubyException(rb_eTypeError, "identity name must be a string"); + throw RubyException(rb_eTypeError, "identity name must be a string"); } Ice::Identity result; result.name = getString(name); if(!NIL_P(category)) { - result.category = getString(category); + result.category = getString(category); } return result; } @@ -314,7 +314,7 @@ IceRuby::callProtected(RubyFunction func, VALUE arg) volatile VALUE result = rb_protect(func, arg, &error); if(error) { - throw RubyException(); + throw RubyException(); } return result; } @@ -327,166 +327,166 @@ setExceptionMembers(const Ice::LocalException& ex, VALUE p) // try { - ex.ice_throw(); + ex.ice_throw(); } catch(const Ice::InitializationException& e) { - volatile VALUE v = createString(e.reason); - callRuby(rb_iv_set, p, "@reason", v); + volatile VALUE v = createString(e.reason); + callRuby(rb_iv_set, p, "@reason", v); } catch(const Ice::PluginInitializationException& e) { - volatile VALUE v = createString(e.reason); - callRuby(rb_iv_set, p, "@reason", v); + volatile VALUE v = createString(e.reason); + callRuby(rb_iv_set, p, "@reason", v); } catch(const Ice::AlreadyRegisteredException& e) { - volatile VALUE v; - v = createString(e.kindOfObject); - callRuby(rb_iv_set, p, "@kindOfObject", v); - v = createString(e.id); - callRuby(rb_iv_set, p, "@id", v); + volatile VALUE v; + v = createString(e.kindOfObject); + callRuby(rb_iv_set, p, "@kindOfObject", v); + v = createString(e.id); + callRuby(rb_iv_set, p, "@id", v); } catch(const Ice::NotRegisteredException& e) { - volatile VALUE v; - v = createString(e.kindOfObject); - callRuby(rb_iv_set, p, "@kindOfObject", v); - v = createString(e.id); - callRuby(rb_iv_set, p, "@id", v); + volatile VALUE v; + v = createString(e.kindOfObject); + callRuby(rb_iv_set, p, "@kindOfObject", v); + v = createString(e.id); + callRuby(rb_iv_set, p, "@id", v); } catch(const Ice::TwowayOnlyException& e) { - volatile VALUE v = createString(e.operation); - callRuby(rb_iv_set, p, "@operation", v); + volatile VALUE v = createString(e.operation); + callRuby(rb_iv_set, p, "@operation", v); } catch(const Ice::UnknownException& e) { - volatile VALUE v = createString(e.unknown); - callRuby(rb_iv_set, p, "@unknown", v); + volatile VALUE v = createString(e.unknown); + callRuby(rb_iv_set, p, "@unknown", v); } catch(const Ice::ObjectAdapterDeactivatedException& e) { - volatile VALUE v = createString(e.name); - callRuby(rb_iv_set, p, "@name", v); + volatile VALUE v = createString(e.name); + callRuby(rb_iv_set, p, "@name", v); } catch(const Ice::ObjectAdapterIdInUseException& e) { - volatile VALUE v = createString(e.id); - callRuby(rb_iv_set, p, "@id", v); + volatile VALUE v = createString(e.id); + callRuby(rb_iv_set, p, "@id", v); } catch(const Ice::NoEndpointException& e) { - volatile VALUE v = createString(e.proxy); - callRuby(rb_iv_set, p, "@proxy", v); + volatile VALUE v = createString(e.proxy); + callRuby(rb_iv_set, p, "@proxy", v); } catch(const Ice::EndpointParseException& e) { - volatile VALUE v = createString(e.str); - callRuby(rb_iv_set, p, "@str", v); + volatile VALUE v = createString(e.str); + callRuby(rb_iv_set, p, "@str", v); } catch(const Ice::IdentityParseException& e) { - volatile VALUE v = createString(e.str); - callRuby(rb_iv_set, p, "@str", v); + volatile VALUE v = createString(e.str); + callRuby(rb_iv_set, p, "@str", v); } catch(const Ice::ProxyParseException& e) { - volatile VALUE v = createString(e.str); - callRuby(rb_iv_set, p, "@str", v); + volatile VALUE v = createString(e.str); + callRuby(rb_iv_set, p, "@str", v); } catch(const Ice::IllegalIdentityException& e) { - volatile VALUE v = IceRuby::createIdentity(e.id); - callRuby(rb_iv_set, p, "@id", v); + volatile VALUE v = IceRuby::createIdentity(e.id); + callRuby(rb_iv_set, p, "@id", v); } catch(const Ice::RequestFailedException& e) { - volatile VALUE v; - v = IceRuby::createIdentity(e.id); - callRuby(rb_iv_set, p, "@id", v); - v = createString(e.facet); - callRuby(rb_iv_set, p, "@facet", v); - v = createString(e.operation); - callRuby(rb_iv_set, p, "@operation", v); + volatile VALUE v; + v = IceRuby::createIdentity(e.id); + callRuby(rb_iv_set, p, "@id", v); + v = createString(e.facet); + callRuby(rb_iv_set, p, "@facet", v); + v = createString(e.operation); + callRuby(rb_iv_set, p, "@operation", v); } catch(const Ice::FileException& e) { - volatile VALUE v = INT2FIX(e.error); - callRuby(rb_iv_set, p, "@error", v); - v = createString(e.path); - callRuby(rb_iv_set, p, "@path", v); + volatile VALUE v = INT2FIX(e.error); + callRuby(rb_iv_set, p, "@error", v); + v = createString(e.path); + callRuby(rb_iv_set, p, "@path", v); } catch(const Ice::SyscallException& e) // This must appear after all subclasses of SyscallException. { - volatile VALUE v = INT2FIX(e.error); - callRuby(rb_iv_set, p, "@error", v); + volatile VALUE v = INT2FIX(e.error); + callRuby(rb_iv_set, p, "@error", v); } catch(const Ice::DNSException& e) { - volatile VALUE v; - v = INT2FIX(e.error); - callRuby(rb_iv_set, p, "@error", v); - v = createString(e.host); - callRuby(rb_iv_set, p, "@host", v); + volatile VALUE v; + v = INT2FIX(e.error); + callRuby(rb_iv_set, p, "@error", v); + v = createString(e.host); + callRuby(rb_iv_set, p, "@host", v); } catch(const Ice::UnsupportedProtocolException& e) { - callRuby(rb_iv_set, p, "@badMajor", INT2FIX(e.badMajor)); - callRuby(rb_iv_set, p, "@badMinor", INT2FIX(e.badMinor)); - callRuby(rb_iv_set, p, "@major", INT2FIX(e.major)); - callRuby(rb_iv_set, p, "@minor", INT2FIX(e.minor)); + callRuby(rb_iv_set, p, "@badMajor", INT2FIX(e.badMajor)); + callRuby(rb_iv_set, p, "@badMinor", INT2FIX(e.badMinor)); + callRuby(rb_iv_set, p, "@major", INT2FIX(e.major)); + callRuby(rb_iv_set, p, "@minor", INT2FIX(e.minor)); } catch(const Ice::UnsupportedEncodingException& e) { - callRuby(rb_iv_set, p, "@badMajor", INT2FIX(e.badMajor)); - callRuby(rb_iv_set, p, "@badMinor", INT2FIX(e.badMinor)); - callRuby(rb_iv_set, p, "@major", INT2FIX(e.major)); - callRuby(rb_iv_set, p, "@minor", INT2FIX(e.minor)); + callRuby(rb_iv_set, p, "@badMajor", INT2FIX(e.badMajor)); + callRuby(rb_iv_set, p, "@badMinor", INT2FIX(e.badMinor)); + callRuby(rb_iv_set, p, "@major", INT2FIX(e.major)); + callRuby(rb_iv_set, p, "@minor", INT2FIX(e.minor)); } catch(const Ice::NoObjectFactoryException& e) { - volatile VALUE v; - v = createString(e.reason); - callRuby(rb_iv_set, p, "@reason", v); - v = createString(e.type); - callRuby(rb_iv_set, p, "@type", v); + volatile VALUE v; + v = createString(e.reason); + callRuby(rb_iv_set, p, "@reason", v); + v = createString(e.type); + callRuby(rb_iv_set, p, "@type", v); } catch(const Ice::UnexpectedObjectException& e) { - volatile VALUE v; - v = createString(e.reason); - callRuby(rb_iv_set, p, "@reason", v); - v = createString(e.type); - callRuby(rb_iv_set, p, "@type", v); - v = createString(e.expectedType); - callRuby(rb_iv_set, p, "@expectedType", v); + volatile VALUE v; + v = createString(e.reason); + callRuby(rb_iv_set, p, "@reason", v); + v = createString(e.type); + callRuby(rb_iv_set, p, "@type", v); + v = createString(e.expectedType); + callRuby(rb_iv_set, p, "@expectedType", v); } catch(const Ice::ProtocolException& e) // This must appear after all subclasses of ProtocolException. { - volatile VALUE v = createString(e.reason); - callRuby(rb_iv_set, p, "@reason", v); + volatile VALUE v = createString(e.reason); + callRuby(rb_iv_set, p, "@reason", v); } catch(const Ice::FeatureNotSupportedException& e) { - volatile VALUE v = createString(e.unsupportedFeature); - callRuby(rb_iv_set, p, "@unsupportedFeature", v); + volatile VALUE v = createString(e.unsupportedFeature); + callRuby(rb_iv_set, p, "@unsupportedFeature", v); } catch(const Ice::NotSetException& e) { - volatile VALUE v = createString(e.key); - callRuby(rb_iv_set, p, "@key", v); + volatile VALUE v = createString(e.key); + callRuby(rb_iv_set, p, "@key", v); } catch(const Ice::SecurityException& e) { - volatile VALUE v = createString(e.reason); - callRuby(rb_iv_set, p, "@reason", v); + volatile VALUE v = createString(e.reason); + callRuby(rb_iv_set, p, "@reason", v); } catch(const Ice::LocalException&) { - // - // Nothing to do. - // + // + // Nothing to do. + // } } @@ -500,23 +500,23 @@ IceRuby::convertLocalException(const Ice::LocalException& ex) // try { - string name = ex.ice_name(); - volatile VALUE cls = callRuby(rb_path2class, name.c_str()); - if(NIL_P(cls)) - { - throw RubyException(rb_eRuntimeError, "exception class `%s' not found", name.c_str()); - } - volatile VALUE result = callRuby(rb_class_new_instance, 0, reinterpret_cast<VALUE*>(0), cls); - setExceptionMembers(ex, result); - return result; + string name = ex.ice_name(); + volatile VALUE cls = callRuby(rb_path2class, name.c_str()); + if(NIL_P(cls)) + { + throw RubyException(rb_eRuntimeError, "exception class `%s' not found", name.c_str()); + } + volatile VALUE result = callRuby(rb_class_new_instance, 0, reinterpret_cast<VALUE*>(0), cls); + setExceptionMembers(ex, result); + return result; } catch(const RubyException& e) { - return e.ex; + return e.ex; } catch(...) { - string msg = "failure occurred while converting exception " + ex.ice_name(); - return rb_exc_new2(rb_eRuntimeError, msg.c_str()); + string msg = "failure occurred while converting exception " + ex.ice_name(); + return rb_exc_new2(rb_eRuntimeError, msg.c_str()); } } |