Guest User

Untitled

a guest
Jun 19th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. diff --git a/cext/src/float.cpp b/cext/src/float.cpp
  2. index be1d3e1..ea3ced7 100644
  3. --- a/cext/src/float.cpp
  4. +++ b/cext/src/float.cpp
  5. @@ -147,7 +147,19 @@ jruby_float_value(VALUE v)
  6. extern "C" VALUE
  7. rb_Float(VALUE obj)
  8. {
  9. - return likely(TYPE(obj) == T_FLOAT) ? obj : callMethodA(obj, "to_f", 0, NULL);
  10. + if (likely(TYPE(obj) == T_FLOAT)) {
  11. + return obj;
  12. + } else {
  13. + JLocalEnv env;
  14. + Handle* h = Handle::valueOf(obj);
  15. + jvalue params[1];
  16. + params[0].l = h->obj;
  17. +
  18. + jobject rubyFloat = env->CallStaticObjectMethodA(JRuby_class, JRuby_convertToFloat, params);
  19. + RubyFloat* f = new RubyFloat(0);
  20. + f->obj = env->NewGlobalRef(rubyFloat);
  21. + return (VALUE)f;
  22. + }
  23. }
  24.  
  25. extern "C" double
  26. diff --git a/cext/src/jruby-cext.cpp b/cext/src/jruby-cext.cpp
  27. index c26dfce..005698a 100644
  28. --- a/cext/src/jruby-cext.cpp
  29. +++ b/cext/src/jruby-cext.cpp
  30. @@ -75,6 +75,7 @@ namespace jruby {
  31. jmethodID JRuby_getRString;
  32. jmethodID JRuby_getRArray;
  33. jmethodID JRuby_newFloat;
  34. + jmethodID JRuby_convertToFloat;
  35. jmethodID JRuby_yield;
  36. jmethodID JRuby_blockGiven;
  37. jmethodID JRuby_getBlockProc;
  38. @@ -362,6 +363,9 @@ loadIds(JNIEnv* env)
  39. JRuby_newProc = getStaticMethodID(env, JRuby_class, "newProc",
  40. "(Lorg/jruby/Ruby;J)Lorg/jruby/runtime/builtin/IRubyObject;");
  41.  
  42. + JRuby_convertToFloat = getStaticMethodID(env, JRuby_class, "convertToFloat",
  43. + "(Lorg/jruby/runtime/builting/IRubyObject;)Lorg/jruby/RubyFloat;");
  44. +
  45. RubyString_value_field = getFieldID(env, RubyString_class, "value", "Lorg/jruby/util/ByteList;");
  46. RubyFloat_value_field = getFieldID(env, RubyFloat_class, "value", "D");
  47. ByteList_bytes_field = getFieldID(env, ByteList_class, "bytes", "[B");
  48. diff --git a/cext/src/jruby.h b/cext/src/jruby.h
  49. index c9b5ffb..92b4d0e 100644
  50. --- a/cext/src/jruby.h
  51. +++ b/cext/src/jruby.h
  52. @@ -109,6 +109,7 @@ namespace jruby {
  53. extern jmethodID JRuby_clearErrorInfo;
  54. extern jmethodID JRuby_newString;
  55. extern jmethodID JRuby_newFloat;
  56. + extern jmethodID JRuby_convertToFloat;
  57. extern jmethodID JRuby_ll2inum;
  58. extern jmethodID JRuby_ull2inum;
  59. extern jmethodID JRuby_int2big;
  60. diff --git a/src/org/jruby/cext/JRuby.java b/src/org/jruby/cext/JRuby.java
  61. index 6bdfb77..8cba67f 100644
  62. --- a/src/org/jruby/cext/JRuby.java
  63. +++ b/src/org/jruby/cext/JRuby.java
  64. @@ -303,4 +303,8 @@ public class JRuby {
  65. GIL.acquire(lockCount);
  66. return task.retval;
  67. }
  68. +
  69. + public static RubyFloat convertToFloat(IRubyObject object) {
  70. + return object.convertToFloat();
  71. + }
  72. }
Add Comment
Please, Sign In to add comment