diff --git a/cext/src/class.cpp b/cext/src/class.cpp index 17de150404d..787a41f4203 100644 --- a/cext/src/class.cpp +++ b/cext/src/class.cpp @@ -63,7 +63,8 @@ rb_class_new_instance(int argc, VALUE* argv, VALUE klass) extern "C" VALUE rb_class_of(VALUE obj) { - return callMethodA(obj, "class", 0, NULL); + JLocalEnv env; + return (VALUE) env->CallStaticObjectMethod(JRuby_class, JRuby_getMetaClass, valueToObject(env, obj)); } extern "C" VALUE diff --git a/cext/src/invoke.cpp b/cext/src/invoke.cpp index d2f38c8d4ef..03c91a24c6f 100644 --- a/cext/src/invoke.cpp +++ b/cext/src/invoke.cpp @@ -92,7 +92,7 @@ Java_org_jruby_cext_Native_callInit(JNIEnv* env, jobject self, jobject jThreadCo { jobject runtime = env->CallObjectMethod(jThreadContext, jruby::ThreadContext_getRuntime_method); if (!env->IsSameObject(runtime, jruby::runtime)) { - jruby::throwExceptionByName(env, jruby::RuntimeException, "invalid ruby runtime"); + jruby::throwExceptionByName(env, jruby::RuntimeException, "C extension initialized against invalid ruby runtime"); return 0; } diff --git a/cext/src/jruby-cext.cpp b/cext/src/jruby-cext.cpp index bf011fe4f06..dc8bb383587 100644 --- a/cext/src/jruby-cext.cpp +++ b/cext/src/jruby-cext.cpp @@ -84,8 +84,12 @@ namespace jruby { jmethodID JRuby_nativeBlockingRegion; jmethodID JRuby_newThread; jmethodID JRuby_newProc; + jmethodID JRuby_sysFail; + jmethodID JRuby_threadSleep; + jmethodID JRuby_getMetaClass; jmethodID ThreadContext_getRuntime_method; + jmethodID Ruby_defineModule_method; jmethodID Ruby_getNil_method; jmethodID Ruby_getTrue_method; @@ -94,44 +98,62 @@ namespace jruby { jmethodID Ruby_getModule_method; jmethodID Ruby_newSymbol_method; jmethodID Ruby_newFixnum_method; + jmethodID Ruby_defineClass_method; + jmethodID Ruby_defineClassUnder_method; + jmethodID Ruby_getClassFromPath_method; + jmethodID Ruby_defineReadonlyVariable_method; + jmethodID RaiseException_constructor; + jmethodID RubyData_newRubyData_method; + jmethodID RubyObject_getNativeTypeIndex_method; + jmethodID RubyBignum_big2dbl_method; jmethodID RubyBignum_big2long_method; jmethodID RubyBignum_big2ulong_method; + jmethodID RubyNumeric_num2long_method; jmethodID RubyNumeric_num2chr_method; jmethodID RubyNumeric_num2dbl_method; jmethodID RubyNumeric_int2fix_method; + jmethodID RubyString_newStringNoCopy; jmethodID RubyString_view; + jmethodID RubyString_resize_method; + jmethodID RubySymbol_getSymbolLong; + jmethodID RubyStruct_newInstance; + jmethodID IRubyObject_callMethod; jmethodID IRubyObject_asJavaString_method; jmethodID IRubyObject_respondsTo_method; + jmethodID Handle_nativeHandle; + jmethodID Ruby_getCurrentContext_method; + jmethodID GC_trigger; + jmethodID RubyArray_toJavaArray_method; + jmethodID RubyClass_newClass_method; - jmethodID Ruby_defineClass_method; - jmethodID Ruby_defineClassUnder_method; jmethodID RubyClass_setAllocator_method; - jmethodID Ruby_getClassFromPath_method; - jmethodID ObjectAllocator_allocate_method; jmethodID RubyClass_getAllocator_method; + + jmethodID RubyModule_undef_method; + + jmethodID ObjectAllocator_allocate_method; + jmethodID RubyBasicObject_getInstanceVariable_method; jmethodID RubyBasicObject_setInstanceVariable_method; jmethodID RubyBasicObject_hasInstanceVariable_method; - jmethodID Ruby_defineReadonlyVariable_method; - jmethodID JRuby_sysFail; - jmethodID RubyString_resize_method; + jmethodID RubyArray_newArray; jmethodID RubyArray_clear_method; jmethodID RubyArray_append_method; - jmethodID JRuby_threadSleep; + jfieldID Handle_address_field; jfieldID RubyString_value_field; jfieldID RubyFloat_value_field; @@ -325,6 +347,7 @@ loadIds(JNIEnv* env) "(Lorg/jruby/Ruby;Lorg/jruby/RubyArray;)Lorg/jruby/runtime/builtin/IRubyObject;"); JRuby_blockGiven = getStaticMethodID(env, JRuby_class, "blockGiven", "(Lorg/jruby/Ruby;)I"); JRuby_getBlockProc = getStaticMethodID(env, JRuby_class, "getBlockProc", "(Lorg/jruby/Ruby;)Lorg/jruby/RubyProc;"); + JRuby_getMetaClass = getStaticMethodID(env, JRuby_class, "getMetaClass", "(Lorg/jruby/runtime/builtin/IRubyObject;)J"); RubyArray_toJavaArray_method = getMethodID(env, RubyArray_class, "toJavaArray", "()[Lorg/jruby/runtime/builtin/IRubyObject;"); RubyClass_newClass_method = getStaticMethodID(env, RubyClass_class, "newClass", @@ -335,6 +358,8 @@ loadIds(JNIEnv* env) "(Ljava/lang/String;Lorg/jruby/RubyClass;Lorg/jruby/runtime/ObjectAllocator;Lorg/jruby/RubyModule;)Lorg/jruby/RubyClass;"); RubyClass_setAllocator_method = getMethodID(env, RubyClass_class, "setAllocator", "(Lorg/jruby/runtime/ObjectAllocator;)V"); + RubyModule_undef_method = getMethodID(env, RubyModule_class, "undef", + "(Lorg/jruby/runtime/ThreadContext;Ljava/lang/String;)V"); Ruby_getClassFromPath_method = getMethodID(env, Ruby_class, "getClassFromPath", "(Ljava/lang/String;)Lorg/jruby/RubyModule;"); ObjectAllocator_allocate_method = getMethodID(env, ObjectAllocator_class, "allocate", diff --git a/cext/src/jruby.h b/cext/src/jruby.h index 2762e29dfdb..5bd2d7f6dbf 100644 --- a/cext/src/jruby.h +++ b/cext/src/jruby.h @@ -124,11 +124,14 @@ namespace jruby { extern jmethodID JRuby_nativeBlockingRegion; extern jmethodID JRuby_newThread; extern jmethodID JRuby_newProc; + extern jmethodID JRuby_getMetaClass; + extern jmethodID RubyArray_toJavaArray_method; extern jmethodID RubyClass_newClass_method; extern jmethodID Ruby_defineClass_method; extern jmethodID Ruby_defineClassUnder_method; extern jmethodID RubyClass_setAllocator_method; + extern jmethodID RubyModule_undef_method; extern jmethodID Ruby_getClassFromPath_method; extern jmethodID ObjectAllocator_allocate_method; extern jmethodID RubyClass_getAllocator_method; diff --git a/cext/src/module.cpp b/cext/src/module.cpp index ec48517c824..4653441e37c 100644 --- a/cext/src/module.cpp +++ b/cext/src/module.cpp @@ -157,11 +157,9 @@ rb_undef_method(VALUE klass, const char* method) { JLocalEnv env; - jmethodID undef = getMethodID(env, RubyModule_class, "undef", - "(Lorg/jruby/runtime/ThreadContext;Ljava/lang/String;)V"); jobject ctxt = env->CallObjectMethod(getRuntime(), Ruby_getCurrentContext_method); checkExceptions(env); - env->CallObjectMethod(valueToObject(env, klass), undef, ctxt, env->NewStringUTF(method)); + env->CallObjectMethod(valueToObject(env, klass), RubyModule_undef_method, ctxt, env->NewStringUTF(method)); checkExceptions(env); } diff --git a/lib/native/Darwin/libjffi-1.0.jnilib b/lib/native/Darwin/libjffi-1.0.jnilib new file mode 100644 index 00000000000..96706f23c77 Binary files /dev/null and b/lib/native/Darwin/libjffi-1.0.jnilib differ diff --git a/lib/native/Darwin/libjruby-cext.jnilib b/lib/native/Darwin/libjruby-cext.jnilib index 0a729391ea9..560cb0f1760 100755 Binary files a/lib/native/Darwin/libjruby-cext.jnilib and b/lib/native/Darwin/libjruby-cext.jnilib differ diff --git a/src/org/jruby/cext/JRuby.java b/src/org/jruby/cext/JRuby.java index a5b76cb19bc..1529bc2d817 100644 --- a/src/org/jruby/cext/JRuby.java +++ b/src/org/jruby/cext/JRuby.java @@ -276,6 +276,11 @@ public static void threadSleep(Ruby runtime, int interval) { // Thread wakeup, do nothing } } + + public static long getMetaClass(IRubyObject object) { + RubyClass metaClass = object.getMetaClass(); + return Handle.nativeHandle(metaClass); + } public static final class NativeFunctionTask implements BlockingTask {