Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/cext/src/float.cpp b/cext/src/float.cpp
- index be1d3e1..ea3ced7 100644
- --- a/cext/src/float.cpp
- +++ b/cext/src/float.cpp
- @@ -147,7 +147,19 @@ jruby_float_value(VALUE v)
- extern "C" VALUE
- rb_Float(VALUE obj)
- {
- - return likely(TYPE(obj) == T_FLOAT) ? obj : callMethodA(obj, "to_f", 0, NULL);
- + if (likely(TYPE(obj) == T_FLOAT)) {
- + return obj;
- + } else {
- + JLocalEnv env;
- + Handle* h = Handle::valueOf(obj);
- + jvalue params[1];
- + params[0].l = h->obj;
- +
- + jobject rubyFloat = env->CallStaticObjectMethodA(JRuby_class, JRuby_convertToFloat, params);
- + RubyFloat* f = new RubyFloat(0);
- + f->obj = env->NewGlobalRef(rubyFloat);
- + return (VALUE)f;
- + }
- }
- extern "C" double
- diff --git a/cext/src/jruby-cext.cpp b/cext/src/jruby-cext.cpp
- index c26dfce..005698a 100644
- --- a/cext/src/jruby-cext.cpp
- +++ b/cext/src/jruby-cext.cpp
- @@ -75,6 +75,7 @@ namespace jruby {
- jmethodID JRuby_getRString;
- jmethodID JRuby_getRArray;
- jmethodID JRuby_newFloat;
- + jmethodID JRuby_convertToFloat;
- jmethodID JRuby_yield;
- jmethodID JRuby_blockGiven;
- jmethodID JRuby_getBlockProc;
- @@ -362,6 +363,9 @@ loadIds(JNIEnv* env)
- JRuby_newProc = getStaticMethodID(env, JRuby_class, "newProc",
- "(Lorg/jruby/Ruby;J)Lorg/jruby/runtime/builtin/IRubyObject;");
- + JRuby_convertToFloat = getStaticMethodID(env, JRuby_class, "convertToFloat",
- + "(Lorg/jruby/runtime/builting/IRubyObject;)Lorg/jruby/RubyFloat;");
- +
- RubyString_value_field = getFieldID(env, RubyString_class, "value", "Lorg/jruby/util/ByteList;");
- RubyFloat_value_field = getFieldID(env, RubyFloat_class, "value", "D");
- ByteList_bytes_field = getFieldID(env, ByteList_class, "bytes", "[B");
- diff --git a/cext/src/jruby.h b/cext/src/jruby.h
- index c9b5ffb..92b4d0e 100644
- --- a/cext/src/jruby.h
- +++ b/cext/src/jruby.h
- @@ -109,6 +109,7 @@ namespace jruby {
- extern jmethodID JRuby_clearErrorInfo;
- extern jmethodID JRuby_newString;
- extern jmethodID JRuby_newFloat;
- + extern jmethodID JRuby_convertToFloat;
- extern jmethodID JRuby_ll2inum;
- extern jmethodID JRuby_ull2inum;
- extern jmethodID JRuby_int2big;
- diff --git a/src/org/jruby/cext/JRuby.java b/src/org/jruby/cext/JRuby.java
- index 6bdfb77..8cba67f 100644
- --- a/src/org/jruby/cext/JRuby.java
- +++ b/src/org/jruby/cext/JRuby.java
- @@ -303,4 +303,8 @@ public class JRuby {
- GIL.acquire(lockCount);
- return task.retval;
- }
- +
- + public static RubyFloat convertToFloat(IRubyObject object) {
- + return object.convertToFloat();
- + }
- }
Add Comment
Please, Sign In to add comment