[ruby-oci8-commit] [538] trunk/ruby-oci8: fix to pass compilation and tests for ruby 1. 8 and rubinius 2.0 testing.

nobody at rubyforge.org nobody at rubyforge.org
Sat Nov 10 11:56:49 UTC 2012


Revision: 538
Author:   kubo
Date:     2012-11-10 11:56:48 +0000 (Sat, 10 Nov 2012)
Log Message:
-----------
fix to pass compilation and tests for ruby 1.8 and rubinius 2.0 testing.

Modified Paths:
--------------
    trunk/ruby-oci8/ChangeLog
    trunk/ruby-oci8/ext/oci8/oci8lib.c
    trunk/ruby-oci8/ext/oci8/ocinumber.c
    trunk/ruby-oci8/lib/oci8/datetime.rb
    trunk/ruby-oci8/test/config.rb
    trunk/ruby-oci8/test/test_oci8.rb

Modified: trunk/ruby-oci8/ChangeLog
===================================================================
--- trunk/ruby-oci8/ChangeLog	2012-10-28 05:52:44 UTC (rev 537)
+++ trunk/ruby-oci8/ChangeLog	2012-11-10 11:56:48 UTC (rev 538)
@@ -1,3 +1,12 @@
+2012-11-10  KUBO Takehiro  <kubo at jiubao.org>
+	* ext/oci8/oci8lib.c: fix compilation errors when ruby version is 1.8.x.
+	* ext/oci8/ocinumber.c: Don't use rb_Rational() when rbx-2.0.testing
+	    runs with ruby 1.8 mode.
+	* lib/oci8/datetime.rb: fix #<NoMethodError: undefined method `timezone' for Time:Class>
+	    when ruby is less than 1.9.2 and an object type's time attribute
+	    is accessed.
+	* test/config.rb, test/test_oci8.rb: for ruby 1.8.x.
+
 2012-10-28  KUBO Takehiro  <kubo at jiubao.org>
 	* ext/oci8/extconf.rb: Use rb_thread_call_without_gvl only when
 	    ruby/thread.h exists. rb_thread_call_without_gvl is an internal

Modified: trunk/ruby-oci8/ext/oci8/oci8lib.c
===================================================================
--- trunk/ruby-oci8/ext/oci8/oci8lib.c	2012-10-28 05:52:44 UTC (rev 537)
+++ trunk/ruby-oci8/ext/oci8/oci8lib.c	2012-11-10 11:56:48 UTC (rev 538)
@@ -294,14 +294,14 @@
 /* ruby 1.8 */
 typedef struct {
     oci8_svcctx_t *svcctx;
-    rb_blocking_function_t *func;
+    void *(*func)(void *);
     void *data;
 } blocking_region_arg_t;
 
 static VALUE blocking_function_execute(blocking_region_arg_t *arg)
 {
     oci8_svcctx_t *svcctx = arg->svcctx;
-    rb_blocking_function_t *func = arg->func;
+    void *(*func)(void *) = arg->func;
     void *data = arg->data;
     struct timeval tv;
     sword rv;
@@ -309,7 +309,7 @@
     tv.tv_sec = 0;
     tv.tv_usec = 10000;
     svcctx->executing_thread = rb_thread_current();
-    while ((rv = func(data)) == OCI_STILL_EXECUTING) {
+    while ((rv = (sword)(VALUE)func(data)) == OCI_STILL_EXECUTING) {
         rb_thread_wait_for(tv);
         if (tv.tv_usec < 500000)
             tv.tv_usec <<= 1;

Modified: trunk/ruby-oci8/ext/oci8/ocinumber.c
===================================================================
--- trunk/ruby-oci8/ext/oci8/ocinumber.c	2012-10-28 05:52:44 UTC (rev 537)
+++ trunk/ruby-oci8/ext/oci8/ocinumber.c	2012-11-10 11:56:48 UTC (rev 538)
@@ -32,7 +32,7 @@
 static ID id_Rational;
 static ID id_BigDecimal;
 
-#ifndef T_RATIONAL
+#ifndef rb_Rational2
 static VALUE cRational;
 #endif
 static VALUE cBigDecimal;
@@ -51,7 +51,7 @@
 #endif
 #define RBOCI8_T_ORANUMBER (T_MASK + 1)
 #define RBOCI8_T_BIGDECIMAL (T_MASK + 2)
-#ifdef T_RATIONAL
+#ifdef rb_Rational2
 #define RBOCI8_T_RATIONAL T_RATIONAL
 #else
 #define RBOCI8_T_RATIONAL (T_MASK + 3)
@@ -63,7 +63,7 @@
     VALUE klass;
 
     switch (type) {
-#ifndef T_RATIONAL
+#ifndef rb_Rational2
     case T_OBJECT:
         klass = CLASS_OF(obj);
         if (cRational != 0) {
@@ -1435,7 +1435,7 @@
     } else {
         y = rb_funcall(INT2FIX(10), rb_intern("**"), 1, INT2FIX(nshift));
     }
-#ifdef T_RATIONAL
+#ifdef rb_Rational2
     return rb_Rational(x, y);
 #else
     if (!cRational) {

Modified: trunk/ruby-oci8/lib/oci8/datetime.rb
===================================================================
--- trunk/ruby-oci8/lib/oci8/datetime.rb	2012-10-28 05:52:44 UTC (rev 537)
+++ trunk/ruby-oci8/lib/oci8/datetime.rb	2012-11-10 11:56:48 UTC (rev 538)
@@ -204,7 +204,7 @@
           usec = (nsec == 0) ? 0 : nsec.to_r / 1000
           begin
             if timezone
-              return ::Time.send(:timezone, year, month, day, hour, minute, sec, usec)
+              return ::Time.send(timezone, year, month, day, hour, minute, sec, usec)
             else
               if tz_hour == 0 and tz_min == 0
                 tm = ::Time.utc(year, month, day, hour, minute, sec, usec)

Modified: trunk/ruby-oci8/test/config.rb
===================================================================
--- trunk/ruby-oci8/test/config.rb	2012-10-28 05:52:44 UTC (rev 537)
+++ trunk/ruby-oci8/test/config.rb	2012-11-10 11:56:48 UTC (rev 538)
@@ -88,7 +88,24 @@
                else
                  Time.local(year, month, day, hour, minute, sec).utc_offset
                end
-  DateTime.civil(year, month, day, hour, minute, sec + subsec, utc_offset.to_r / 86400)
+  begin
+    DateTime.civil(year, month, day, hour, minute, sec + subsec, utc_offset.to_r / 86400)
+  rescue ArgumentError
+    raise $! if $!.to_s != 'invalid date'
+    # for ruby 1.8.6.
+    # convert to a DateTime via a String as a workaround.
+    if utc_offset >= 0
+      sign = ?+
+    else
+      sign = ?-
+      utc_offset = - utc_offset;
+    end
+    tz_min = utc_offset / 60
+    tz_hour, tz_min = tz_min.divmod 60
+    time_str = format("%04d-%02d-%02dT%02d:%02d:%02d.%09d%c%02d:%02d",
+                      year, month, day, hour, minute, sec, (subsec * 1000_000_000).to_i, sign, tz_hour, tz_min)
+    ::DateTime.parse(time_str)
+  end
 end
 
 module Test

Modified: trunk/ruby-oci8/test/test_oci8.rb
===================================================================
--- trunk/ruby-oci8/test/test_oci8.rb	2012-10-28 05:52:44 UTC (rev 537)
+++ trunk/ruby-oci8/test/test_oci8.rb	2012-11-10 11:56:48 UTC (rev 538)
@@ -465,17 +465,17 @@
 
   def test_environment_handle
     # OCI_ATTR_HEAPALLOC
-    assert_operator(OCI8.class_variable_get(:@@environment_handle).send(:attr_get_ub4, 30), :>,  0)
+    assert_operator(OCI8.send(:class_variable_get, :@@environment_handle).send(:attr_get_ub4, 30), :>,  0)
     # OCI_ATTR_OBJECT
-    assert(OCI8.class_variable_get(:@@environment_handle).send(:attr_get_boolean, 2))
+    assert(OCI8.send(:class_variable_get, :@@environment_handle).send(:attr_get_boolean, 2))
     # OCI_ATTR_SHARED_HEAPALLOC
-    assert_equal(0, OCI8.class_variable_get(:@@environment_handle).send(:attr_get_ub4, 84))
+    assert_equal(0, OCI8.send(:class_variable_get, :@@environment_handle).send(:attr_get_ub4, 84))
   end
 
   def test_process_handle
     # OCI_ATTR_MEMPOOL_APPNAME
-    assert_equal('', OCI8.class_variable_get(:@@process_handle).send(:attr_get_string, 90))
+    assert_equal('', OCI8.send(:class_variable_get, :@@process_handle).send(:attr_get_string, 90))
     # OCI_ATTR_MEMPOOL_SIZE
-    assert_equal(0, OCI8.class_variable_get(:@@process_handle).send(:attr_get_ub4, 88))
+    assert_equal(0, OCI8.send(:class_variable_get, :@@process_handle).send(:attr_get_ub4, 88))
   end
 end # TestOCI8



More information about the ruby-oci8-commit mailing list