/** @note Shares code with rb_define_module_under, change there too. --rue */ VALUE rb_define_class_under(VALUE parent_handle, const char* name, VALUE superclass_handle) { NativeMethodEnvironment* env = NativeMethodEnvironment::get(); Module* parent = c_as<Module>(env->get_object(parent_handle)); Class* superclass = c_as<Class>(env->get_object(superclass_handle)); Symbol* constant = env->state()->symbol(name); bool created = false; Class* cls = rubinius::Helpers::open_class(env->state(), env->current_call_frame(), parent, superclass, constant, &created); return env->get_handle_global(cls); }
VALUE capi_get_constant(CApiConstant type) { static CApiConstantHandleMap map; CApiConstantHandleMap::iterator entry = map.find(type); if(entry == map.end()) { NativeMethodEnvironment* env = NativeMethodEnvironment::get(); Object* obj = env->state()->globals.object.get()->get_const(env->state(), capi_get_constant_name(type).c_str()); Handle handle = env->get_handle_global(obj); map[type] = handle; return handle; } else { return entry->second; } }
/** * This looks like a complicated scheme but there is a reason for * doing it this way. In MRI, rb_cObject, etc. are all global data. * We need to avoid global data to better support embedding and * other features like MVM. @see capi_get_constant(). */ std::string& capi_get_constant_name(int type) { static CApiConstantNameMap map; if(map.empty()) { map.resize(cCApiMaxConstant + 1); map[cCApiArray] = "Array"; map[cCApiBignum] = "Bignum"; map[cCApiClass] = "Class"; map[cCApiComparable] = "Comparable"; map[cCApiData] = "Data"; map[cCApiEnumerable] = "Enumerable"; map[cCApiFalse] = "FalseClass"; map[cCApiFixnum] = "Fixnum"; map[cCApiFloat] = "Float"; map[cCApiHash] = "Hash"; map[cCApiInteger] = "Integer"; map[cCApiIO] = "IO"; map[cCApiKernel] = "Kernel"; map[cCApiModule] = "Module"; map[cCApiNil] = "NilClass"; map[cCApiObject] = "Object"; map[cCApiRegexp] = "Regexp"; map[cCApiString] = "String"; map[cCApiSymbol] = "Symbol"; map[cCApiThread] = "Thread"; map[cCApiTime] = "Time"; map[cCApiTrue] = "TrueClass"; map[cCApiArgumentError] = "ArgumentError"; map[cCApiEOFError] = "EOFError"; map[cCApiErrno] = "Errno"; map[cCApiException] = "Exception"; map[cCApiFatal] = "Fatal"; map[cCApiFloatDomainError] = "FloatDomainError"; map[cCApiIndexError] = "IndexError"; map[cCApiInterrupt] = "Interrupt"; map[cCApiIOError] = "IOError"; map[cCApiLoadError] = "LoadError"; map[cCApiLocalJumpError] = "LocalJumpError"; map[cCApiNameError] = "NameError"; map[cCApiNoMemoryError] = "NoMemoryError"; map[cCApiNoMethodError] = "NoMethodError"; map[cCApiNotImplementedError] = "NotImplementedError"; map[cCApiRangeError] = "RangeError"; map[cCApiRegexpError] = "RegexpError"; map[cCApiRuntimeError] = "RuntimeError"; map[cCApiScriptError] = "ScriptError"; map[cCApiSecurityError] = "SecurityError"; map[cCApiSignalException] = "SignalException"; map[cCApiStandardError] = "StandardError"; map[cCApiSyntaxError] = "SyntaxError"; map[cCApiSystemCallError] = "SystemCallError"; map[cCApiSystemExit] = "SystemExit"; map[cCApiSystemStackError] = "SystemStackError"; map[cCApiTypeError] = "TypeError"; map[cCApiThreadError] = "ThreadError"; map[cCApiZeroDivisionError] = "ZeroDivisionError"; } if(type < 0 || type >= cCApiMaxConstant) { NativeMethodEnvironment* env = NativeMethodEnvironment::get(); rb_raise(env->get_handle_global(env->state()->globals.exception.get()), "C-API: invalid constant index"); } return map[type]; }
VALUE rb_class_of(VALUE object_handle) { NativeMethodEnvironment* env = NativeMethodEnvironment::get(); Class* class_object = env->get_object(object_handle)->class_object(env->state()); return env->get_handle_global(class_object); }