[ruby-oci8-commit] [338] trunk/ruby-oci8: * ext/oci8/oci8.h, ext/oci8/oci8lib.c, ext/oci8/ ocinumber.c,

nobody at rubyforge.org nobody at rubyforge.org
Tue Apr 14 07:58:26 EDT 2009


Revision: 338
Author:   kubo
Date:     2009-04-14 07:58:26 -0400 (Tue, 14 Apr 2009)

Log Message:
-----------
* ext/oci8/oci8.h, ext/oci8/oci8lib.c, ext/oci8/ocinumber.c,
  ext/oci8/metadata.c, ext/oci8/object.c: pass an OCIError to
    OraNumber functions if it can. (This is the first step to
    delay OCIEnv initialization.)

Modified Paths:
--------------
    trunk/ruby-oci8/ChangeLog
    trunk/ruby-oci8/ext/oci8/metadata.c
    trunk/ruby-oci8/ext/oci8/object.c
    trunk/ruby-oci8/ext/oci8/oci8.h
    trunk/ruby-oci8/ext/oci8/oci8lib.c
    trunk/ruby-oci8/ext/oci8/ocinumber.c

Modified: trunk/ruby-oci8/ChangeLog
===================================================================
--- trunk/ruby-oci8/ChangeLog	2009-04-14 11:07:01 UTC (rev 337)
+++ trunk/ruby-oci8/ChangeLog	2009-04-14 11:58:26 UTC (rev 338)
@@ -1,4 +1,10 @@
 2009-04-14  KUBO Takehiro  <kubo at jiubao.org>
+	* ext/oci8/oci8.h, ext/oci8/oci8lib.c, ext/oci8/ocinumber.c,
+	  ext/oci8/metadata.c, ext/oci8/object.c: pass an OCIError to
+	    OraNumber functions if it can. (This is the first step to
+	    delay OCIEnv initialization.)
+
+2009-04-14  KUBO Takehiro  <kubo at jiubao.org>
 	* ext/oci8/oraconf.rb: Gets ORACLE_HOME from the Windows regitry
 	    by enumerating subkeys of \\HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE.
 

Modified: trunk/ruby-oci8/ext/oci8/metadata.c
===================================================================
--- trunk/ruby-oci8/ext/oci8/metadata.c	2009-04-14 11:07:01 UTC (rev 337)
+++ trunk/ruby-oci8/ext/oci8/metadata.c	2009-04-14 11:58:26 UTC (rev 338)
@@ -2,7 +2,7 @@
 /*
  * metadata.c
  *
- * Copyright (C) 2006-2007 KUBO Takehiro <kubo at jiubao.org>
+ * Copyright (C) 2006-2009 KUBO Takehiro <kubo at jiubao.org>
  *
  * implement private methods of classes in OCI8::Metadata module.
  *
@@ -210,7 +210,7 @@
     memset(&on, 0, sizeof(on));
     on.OCINumberPart[0] = size;
     memcpy(&on.OCINumberPart[1], value, size);
-    return oci8_make_integer(&on);
+    return oci8_make_integer(&on, oci8_errhp);
 }
 
 static VALUE metadata_get_param(VALUE self, VALUE idx)

Modified: trunk/ruby-oci8/ext/oci8/object.c
===================================================================
--- trunk/ruby-oci8/ext/oci8/object.c	2009-04-14 11:07:01 UTC (rev 337)
+++ trunk/ruby-oci8/ext/oci8/object.c	2009-04-14 11:58:26 UTC (rev 338)
@@ -1,5 +1,10 @@
 /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
 /*
+ * Copyright (C) 2002-2009 KUBO Takehiro <kubo at jiubao.org>
+ */
+
+/*
+ *
  * Document-class: OCI8::TDO
  *
  * OCI8::TDO is the class for Type Descriptor Object, which describe
@@ -157,11 +162,11 @@
         return rb_str_new(TO_CHARPTR(OCIRawPtr(oci8_envhp, *(OCIRaw **)data)),
                           OCIRawSize(oci8_envhp, *(OCIRaw **)data));
     case ATTR_OCINUMBER:
-        return oci8_make_ocinumber((OCINumber *)data);
+        return oci8_make_ocinumber((OCINumber *)data, oci8_errhp);
     case ATTR_FLOAT:
-        return oci8_make_float((OCINumber *)data);
+        return oci8_make_float((OCINumber *)data, oci8_errhp);
     case ATTR_INTEGER:
-        return oci8_make_integer((OCINumber *)data);
+        return oci8_make_integer((OCINumber *)data, oci8_errhp);
     case ATTR_BINARY_DOUBLE:
         return rb_float_new(*(double*)data);
     case ATTR_BINARY_FLOAT:
@@ -431,10 +436,10 @@
         break;
     case ATTR_OCINUMBER:
     case ATTR_FLOAT:
-        oci8_set_ocinumber((OCINumber*)data, val);
+        oci8_set_ocinumber((OCINumber*)data, val, oci8_errhp);
         break;
     case ATTR_INTEGER:
-        oci8_set_integer((OCINumber*)data, val);
+        oci8_set_integer((OCINumber*)data, val, oci8_errhp);
         break;
     case ATTR_BINARY_DOUBLE:
         *(double*)data = NUM2DBL(val);

Modified: trunk/ruby-oci8/ext/oci8/oci8.h
===================================================================
--- trunk/ruby-oci8/ext/oci8/oci8.h	2009-04-14 11:07:01 UTC (rev 337)
+++ trunk/ruby-oci8/ext/oci8/oci8.h	2009-04-14 11:58:26 UTC (rev 338)
@@ -1,9 +1,9 @@
 /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
 /*
-  oci8.h - part of ruby-oci8
-
-  Copyright (C) 2002-2009 KUBO Takehiro <kubo at jiubao.org>
-*/
+ * oci8.h - part of ruby-oci8
+ *
+ * Copyright (C) 2002-2009 KUBO Takehiro <kubo at jiubao.org>
+ */
 #ifndef _RUBY_OCI_H_
 #define _RUBY_OCI_H_ 1
 
@@ -434,13 +434,13 @@
 void Init_ora_date(void);
 
 /* ocinumber.c */
-void Init_oci_number(VALUE mOCI);
+void Init_oci_number(VALUE mOCI, OCIError *errhp);
 OCINumber *oci8_get_ocinumber(VALUE num);
-VALUE oci8_make_ocinumber(OCINumber *s);
-VALUE oci8_make_integer(OCINumber *s);
-VALUE oci8_make_float(OCINumber *s);
-OCINumber *oci8_set_ocinumber(OCINumber *result, VALUE self);
-OCINumber *oci8_set_integer(OCINumber *result, VALUE self);
+VALUE oci8_make_ocinumber(OCINumber *s, OCIError *errhp);
+VALUE oci8_make_integer(OCINumber *s, OCIError *errhp);
+VALUE oci8_make_float(OCINumber *s, OCIError *errhp);
+OCINumber *oci8_set_ocinumber(OCINumber *result, VALUE self, OCIError *errhp);
+OCINumber *oci8_set_integer(OCINumber *result, VALUE self, OCIError *errhp);
 
 /* ocidatetim.c */
 void Init_oci_datetime(void);

Modified: trunk/ruby-oci8/ext/oci8/oci8lib.c
===================================================================
--- trunk/ruby-oci8/ext/oci8/oci8lib.c	2009-04-14 11:07:01 UTC (rev 337)
+++ trunk/ruby-oci8/ext/oci8/oci8lib.c	2009-04-14 11:58:26 UTC (rev 338)
@@ -1,6 +1,6 @@
 /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
 /*
- * Copyright (C) 2002-2008 KUBO Takehiro <kubo at jiubao.org>
+ * Copyright (C) 2002-2009 KUBO Takehiro <kubo at jiubao.org>
  */
 
 #include "oci8.h"
@@ -155,7 +155,7 @@
     Init_oci8_lob(cOCI8);
 
     Init_ora_date();
-    Init_oci_number(cOCI8);
+    Init_oci_number(cOCI8, oci8_errhp);
     Init_oci_datetime();
     Init_oci_object(cOCI8);
     Init_oci_xmldb();

Modified: trunk/ruby-oci8/ext/oci8/ocinumber.c
===================================================================
--- trunk/ruby-oci8/ext/oci8/ocinumber.c	2009-04-14 11:07:01 UTC (rev 337)
+++ trunk/ruby-oci8/ext/oci8/ocinumber.c	2009-04-14 11:58:26 UTC (rev 338)
@@ -2,11 +2,8 @@
 /*
  *  ocinumber.c
  *
- * $Author$
- * $Date$
+ * Copyright (C) 2005-2009 KUBO Takehiro <kubo at jiubao.org>
  *
- * Copyright (C) 2005-2008 KUBO Takehiro <kubo at jiubao.org>
- *
  */
 #include "oci8.h"
 #include <orl.h>
@@ -61,40 +58,40 @@
 }
 
 /* construct an ruby object(OCI::Number) from C structure (OCINumber). */
-VALUE oci8_make_ocinumber(OCINumber *s)
+VALUE oci8_make_ocinumber(OCINumber *s, OCIError *errhp)
 {
     VALUE obj;
     OCINumber *d;
 
     obj = Data_Make_Struct(cOCINumber, OCINumber, NULL, xfree, d);
-    oci_lc(OCINumberAssign(oci8_errhp, s, d));
+    oci_lc(OCINumberAssign(errhp, s, d));
     return obj;
 }
 
-VALUE oci8_make_integer(OCINumber *s)
+VALUE oci8_make_integer(OCINumber *s, OCIError *errhp)
 {
     signed long sl;
     char buf[512];
     ub4 buf_size = sizeof(buf);
 
-    if (OCINumberToInt(oci8_errhp, s, sizeof(sl), OCI_NUMBER_SIGNED, &sl) == OCI_SUCCESS) {
+    if (OCINumberToInt(errhp, s, sizeof(sl), OCI_NUMBER_SIGNED, &sl) == OCI_SUCCESS) {
         return LONG2NUM(sl);
     }
-    oci_lc(OCINumberToText(oci8_errhp, s, NUMBER_FORMAT2, NUMBER_FORMAT2_LEN,
+    oci_lc(OCINumberToText(errhp, s, NUMBER_FORMAT2, NUMBER_FORMAT2_LEN,
                            NULL, 0, &buf_size, TO_ORATEXT(buf)));
     return rb_cstr2inum(buf, 10);
 }
 
-VALUE oci8_make_float(OCINumber *s)
+VALUE oci8_make_float(OCINumber *s, OCIError *errhp)
 {
     double dbl;
 
-    oci_lc(OCINumberToReal(oci8_errhp, s, sizeof(double), &dbl));
+    oci_lc(OCINumberToReal(errhp, s, sizeof(double), &dbl));
     return rb_float_new(dbl);
 }
 
 /* fill C structure (OCINumber) from a string. */
-static void set_oci_number_from_str(OCINumber *result, VALUE str, VALUE fmt, VALUE nls_params)
+static void set_oci_number_from_str(OCINumber *result, VALUE str, VALUE fmt, VALUE nls_params, OCIError *errhp)
 {
     oratext *fmt_ptr;
     oratext *nls_params_ptr;
@@ -135,7 +132,7 @@
         nls_params_ptr = RSTRING_ORATEXT(nls_params);
         nls_params_len = RSTRING_LEN(nls_params);
     }
-    oci_lc(OCINumberFromText(oci8_errhp,
+    oci_lc(OCINumberFromText(errhp,
                              RSTRING_ORATEXT(str), RSTRING_LEN(str),
                              fmt_ptr, fmt_len, nls_params_ptr, nls_params_len,
                              result));
@@ -143,7 +140,7 @@
 
 /* fill C structure (OCINumber) from a numeric object. */
 /* 1 - success, 0 - error */
-static int set_oci_number_from_num(OCINumber *result, VALUE num, int force)
+static int set_oci_number_from_num(OCINumber *result, VALUE num, int force, OCIError *errhp)
 {
     signed long sl;
     double dbl;
@@ -154,45 +151,46 @@
     case T_FIXNUM:
         /* set from long. */
         sl = NUM2LONG(num);
-        oci_lc(OCINumberFromInt(oci8_errhp, &sl, sizeof(sl), OCI_NUMBER_SIGNED, result));
+        oci_lc(OCINumberFromInt(errhp, &sl, sizeof(sl), OCI_NUMBER_SIGNED, result));
         return 1;
     case T_FLOAT:
         /* set from double. */
         dbl = NUM2DBL(num);
-        oci_lc(OCINumberFromReal(oci8_errhp, &dbl, sizeof(dbl), result));
+        oci_lc(OCINumberFromReal(errhp, &dbl, sizeof(dbl), result));
         return 1;
     case T_BIGNUM:
         /* change via string. */
         num = rb_big2str(num, 10);
-        set_oci_number_from_str(result, num, Qnil, Qnil);
+        set_oci_number_from_str(result, num, Qnil, Qnil, errhp);
         return 1;
     }
     if (RTEST(rb_obj_is_instance_of(num, cOCINumber))) {
         /* OCI::Number */
-        oci_lc(OCINumberAssign(oci8_errhp, DATA_PTR(num), result));
+        oci_lc(OCINumberAssign(errhp, DATA_PTR(num), result));
         return 1;
     }
     if (force) {
         /* change via string as a last resort. */
         /* TODO: if error, raise TypeError instead of OCI::Error */
-        set_oci_number_from_str(result, num, Qnil, Qnil);
+        set_oci_number_from_str(result, num, Qnil, Qnil, errhp);
         return 1;
     }
     return 0;
 }
 
-OCINumber *oci8_set_ocinumber(OCINumber *result, VALUE self)
+OCINumber *oci8_set_ocinumber(OCINumber *result, VALUE self, OCIError *errhp)
 {
-    set_oci_number_from_num(result, self, 1);
+    set_oci_number_from_num(result, self, 1, errhp);
     return result;
 }
-#define TO_OCINUM(on, val) oci8_set_ocinumber((on), (val))
+#define TO_OCINUM oci8_set_ocinumber
 
-OCINumber *oci8_set_integer(OCINumber *result, VALUE self)
+OCINumber *oci8_set_integer(OCINumber *result, VALUE self, OCIError *errhp)
 {
     OCINumber work;
-    set_oci_number_from_num(&work, self, 1);
-    oci_lc(OCINumberTrunc(oci8_errhp, &work, 0, result));
+
+    set_oci_number_from_num(&work, self, 1, errhp);
+    oci_lc(OCINumberTrunc(errhp, &work, 0, result));
     return result;
 }
 
@@ -205,30 +203,31 @@
  */
 static VALUE omath_atan2(VALUE self, VALUE Ycoordinate, VALUE Xcoordinate)
 {
+    OCIError *errhp = oci8_errhp;
     OCINumber nY;
     OCINumber nX;
     OCINumber rv;
     boolean is_zero;
     sword sign;
 
-    set_oci_number_from_num(&nX, Xcoordinate, 1);
-    set_oci_number_from_num(&nY, Ycoordinate, 1);
+    set_oci_number_from_num(&nX, Xcoordinate, 1, errhp);
+    set_oci_number_from_num(&nY, Ycoordinate, 1, errhp);
     /* check zero */
-    oci_lc(OCINumberIsZero(oci8_errhp, &nX, &is_zero));
+    oci_lc(OCINumberIsZero(errhp, &nX, &is_zero));
     if (is_zero) {
-        oci_lc(OCINumberSign(oci8_errhp, &nY, &sign));
+        oci_lc(OCINumberSign(errhp, &nY, &sign));
         switch (sign) {
         case 0:
             return INT2FIX(0); /* atan2(0, 0) => 0 or ERROR? */
         case 1:
-            return oci8_make_ocinumber(&const_PI2); /* atan2(positive, 0) => PI/2 */
+            return oci8_make_ocinumber(&const_PI2, errhp); /* atan2(positive, 0) => PI/2 */
         case -1:
-            return oci8_make_ocinumber(&const_mPI2); /* atan2(negative, 0) => -PI/2 */
+            return oci8_make_ocinumber(&const_mPI2, errhp); /* atan2(negative, 0) => -PI/2 */
         }
     }
     /* atan2 */
-    oci_lc(OCINumberArcTan2(oci8_errhp, &nY, &nX, &rv));
-    return oci8_make_ocinumber(&rv);
+    oci_lc(OCINumberArcTan2(errhp, &nY, &nX, &rv));
+    return oci8_make_ocinumber(&rv, errhp);
 }
 
 /*
@@ -240,11 +239,12 @@
  */
 static VALUE omath_cos(VALUE obj, VALUE radian)
 {
+    OCIError *errhp = oci8_errhp;
     OCINumber r;
     OCINumber rv;
 
-    oci_lc(OCINumberCos(oci8_errhp, TO_OCINUM(&r, radian), &rv));
-    return oci8_make_ocinumber(&rv);
+    oci_lc(OCINumberCos(errhp, TO_OCINUM(&r, radian, errhp), &rv));
+    return oci8_make_ocinumber(&rv, errhp);
 }
 
 /*
@@ -256,11 +256,12 @@
  */
 static VALUE omath_sin(VALUE obj, VALUE radian)
 {
+    OCIError *errhp = oci8_errhp;
     OCINumber r;
     OCINumber rv;
 
-    oci_lc(OCINumberSin(oci8_errhp, TO_OCINUM(&r, radian), &rv));
-    return oci8_make_ocinumber(&rv);
+    oci_lc(OCINumberSin(errhp, TO_OCINUM(&r, radian, errhp), &rv));
+    return oci8_make_ocinumber(&rv, errhp);
 }
 
 /*
@@ -271,11 +272,12 @@
  */
 static VALUE omath_tan(VALUE obj, VALUE radian)
 {
+    OCIError *errhp = oci8_errhp;
     OCINumber r;
     OCINumber rv;
 
-    oci_lc(OCINumberTan(oci8_errhp, TO_OCINUM(&r, radian), &rv));
-    return oci8_make_ocinumber(&rv);
+    oci_lc(OCINumberTan(errhp, TO_OCINUM(&r, radian, errhp), &rv));
+    return oci8_make_ocinumber(&rv, errhp);
 }
 
 /*
@@ -286,22 +288,23 @@
  */
 static VALUE omath_acos(VALUE obj, VALUE num)
 {
+    OCIError *errhp = oci8_errhp;
     OCINumber n;
     OCINumber r;
     sword sign;
 
-    set_oci_number_from_num(&n, num, 1);
+    set_oci_number_from_num(&n, num, 1, errhp);
     /* check upper bound */
-    oci_lc(OCINumberCmp(oci8_errhp, &n, &const_p1, &sign));
+    oci_lc(OCINumberCmp(errhp, &n, &const_p1, &sign));
     if (sign > 0)
         rb_raise(rb_eRangeError, "out of range for acos");
     /* check lower bound */
-    oci_lc(OCINumberCmp(oci8_errhp, &n, &const_m1, &sign));
+    oci_lc(OCINumberCmp(errhp, &n, &const_m1, &sign));
     if (sign < 0)
         rb_raise(rb_eRangeError, "out of range for acos");
     /* acos */
-    oci_lc(OCINumberArcCos(oci8_errhp, &n, &r));
-    return oci8_make_ocinumber(&r);
+    oci_lc(OCINumberArcCos(errhp, &n, &r));
+    return oci8_make_ocinumber(&r, errhp);
 }
 
 /*
@@ -312,22 +315,23 @@
  */
 static VALUE omath_asin(VALUE obj, VALUE num)
 {
+    OCIError *errhp = oci8_errhp;
     OCINumber n;
     OCINumber r;
     sword sign;
 
-    set_oci_number_from_num(&n, num, 1);
+    set_oci_number_from_num(&n, num, 1, errhp);
     /* check upper bound */
-    oci_lc(OCINumberCmp(oci8_errhp, &n, &const_p1, &sign));
+    oci_lc(OCINumberCmp(errhp, &n, &const_p1, &sign));
     if (sign > 0)
         rb_raise(rb_eRangeError, "out of range for asin");
     /* check lower bound */
-    oci_lc(OCINumberCmp(oci8_errhp, &n, &const_m1, &sign));
+    oci_lc(OCINumberCmp(errhp, &n, &const_m1, &sign));
     if (sign < 0)
         rb_raise(rb_eRangeError, "out of range for asin");
     /* asin */
-    oci_lc(OCINumberArcSin(oci8_errhp, &n, &r));
-    return oci8_make_ocinumber(&r);
+    oci_lc(OCINumberArcSin(errhp, &n, &r));
+    return oci8_make_ocinumber(&r, errhp);
 }
 
 /*
@@ -338,11 +342,12 @@
  */
 static VALUE omath_atan(VALUE obj, VALUE num)
 {
+    OCIError *errhp = oci8_errhp;
     OCINumber n;
     OCINumber r;
 
-    oci_lc(OCINumberArcTan(oci8_errhp, TO_OCINUM(&n, num), &r));
-    return oci8_make_ocinumber(&r);
+    oci_lc(OCINumberArcTan(errhp, TO_OCINUM(&n, num, errhp), &r));
+    return oci8_make_ocinumber(&r, errhp);
 }
 
 /*
@@ -353,11 +358,12 @@
  */
 static VALUE omath_cosh(VALUE obj, VALUE num)
 {
+    OCIError *errhp = oci8_errhp;
     OCINumber n;
     OCINumber r;
 
-    oci_lc(OCINumberHypCos(oci8_errhp, TO_OCINUM(&n, num), &r));
-    return oci8_make_ocinumber(&r);
+    oci_lc(OCINumberHypCos(errhp, TO_OCINUM(&n, num, errhp), &r));
+    return oci8_make_ocinumber(&r, errhp);
 }
 
 /*
@@ -369,11 +375,12 @@
  */
 static VALUE omath_sinh(VALUE obj, VALUE num)
 {
+    OCIError *errhp = oci8_errhp;
     OCINumber n;
     OCINumber r;
 
-    oci_lc(OCINumberHypSin(oci8_errhp, TO_OCINUM(&n, num), &r));
-    return oci8_make_ocinumber(&r);
+    oci_lc(OCINumberHypSin(errhp, TO_OCINUM(&n, num, errhp), &r));
+    return oci8_make_ocinumber(&r, errhp);
 }
 
 /*
@@ -385,11 +392,12 @@
  */
 static VALUE omath_tanh(VALUE obj, VALUE num)
 {
+    OCIError *errhp = oci8_errhp;
     OCINumber n;
     OCINumber r;
 
-    oci_lc(OCINumberHypTan(oci8_errhp, TO_OCINUM(&n, num), &r));
-    return oci8_make_ocinumber(&r);
+    oci_lc(OCINumberHypTan(errhp, TO_OCINUM(&n, num, errhp), &r));
+    return oci8_make_ocinumber(&r, errhp);
 }
 
 /*
@@ -400,11 +408,12 @@
  */
 static VALUE omath_exp(VALUE obj, VALUE num)
 {
+    OCIError *errhp = oci8_errhp;
     OCINumber n;
     OCINumber r;
 
-    oci_lc(OCINumberExp(oci8_errhp, TO_OCINUM(&n, num), &r));
-    return oci8_make_ocinumber(&r);
+    oci_lc(OCINumberExp(errhp, TO_OCINUM(&n, num, errhp), &r));
+    return oci8_make_ocinumber(&r, errhp);
 }
 
 /*
@@ -417,6 +426,7 @@
  */
 static VALUE omath_log(int argc, VALUE *argv, VALUE obj)
 {
+    OCIError *errhp = oci8_errhp;
     VALUE num, base;
     OCINumber n;
     OCINumber b;
@@ -424,23 +434,23 @@
     sword sign;
 
     rb_scan_args(argc, argv, "11", &num, &base);
-    set_oci_number_from_num(&n, num, 1);
-    oci_lc(OCINumberSign(oci8_errhp, &n, &sign));
+    set_oci_number_from_num(&n, num, 1, errhp);
+    oci_lc(OCINumberSign(errhp, &n, &sign));
     if (sign <= 0)
         rb_raise(rb_eRangeError, "nonpositive value for log");
     if (NIL_P(base)) {
-        oci_lc(OCINumberLn(oci8_errhp, &n, &r));
+        oci_lc(OCINumberLn(errhp, &n, &r));
     } else {
-        set_oci_number_from_num(&b, base, 1);
-        oci_lc(OCINumberSign(oci8_errhp, &b, &sign));
+        set_oci_number_from_num(&b, base, 1, errhp);
+        oci_lc(OCINumberSign(errhp, &b, &sign));
         if (sign <= 0)
             rb_raise(rb_eRangeError, "nonpositive value for the base of log");
-        oci_lc(OCINumberCmp(oci8_errhp, &b, &const_p1, &sign));
+        oci_lc(OCINumberCmp(errhp, &b, &const_p1, &sign));
         if (sign == 0)
             rb_raise(rb_eRangeError, "base 1 for log");
-        oci_lc(OCINumberLog(oci8_errhp, &b, &n, &r));
+        oci_lc(OCINumberLog(errhp, &b, &n, &r));
     }
-    return oci8_make_ocinumber(&r);
+    return oci8_make_ocinumber(&r, errhp);
 }
 
 /*
@@ -451,16 +461,17 @@
  */
 static VALUE omath_log10(VALUE obj, VALUE num)
 {
+    OCIError *errhp = oci8_errhp;
     OCINumber n;
     OCINumber r;
     sword sign;
 
-    set_oci_number_from_num(&n, num, 1);
-    oci_lc(OCINumberSign(oci8_errhp, &n, &sign));
+    set_oci_number_from_num(&n, num, 1, errhp);
+    oci_lc(OCINumberSign(errhp, &n, &sign));
     if (sign <= 0)
         rb_raise(rb_eRangeError, "nonpositive value for log10");
-    oci_lc(OCINumberLog(oci8_errhp, &const_p10, &n, &r));
-    return oci8_make_ocinumber(&r);
+    oci_lc(OCINumberLog(errhp, &const_p10, &n, &r));
+    return oci8_make_ocinumber(&r, errhp);
 }
 
 /*
@@ -471,33 +482,35 @@
  */
 static VALUE omath_sqrt(VALUE obj, VALUE num)
 {
+    OCIError *errhp = oci8_errhp;
     OCINumber n;
     OCINumber r;
     sword sign;
 
-    set_oci_number_from_num(&n, num, 1);
+    set_oci_number_from_num(&n, num, 1, errhp);
     /* check whether num is negative */
-    oci_lc(OCINumberSign(oci8_errhp, &n, &sign));
+    oci_lc(OCINumberSign(errhp, &n, &sign));
     if (sign < 0) {
         errno = EDOM;
         rb_sys_fail("sqrt");
     }
-    oci_lc(OCINumberSqrt(oci8_errhp, &n, &r));
-    return oci8_make_ocinumber(&r);
+    oci_lc(OCINumberSqrt(errhp, &n, &r));
+    return oci8_make_ocinumber(&r, errhp);
 }
 
 static VALUE onum_initialize(int argc, VALUE *argv, VALUE self)
 {
+    OCIError *errhp = oci8_errhp;
     VALUE val;
     VALUE fmt;
     VALUE nls_params;
 
     if (rb_scan_args(argc, argv, "03", &val /* 0 */, &fmt /* nil */, &nls_params /* nil */) == 0) {
-        OCINumberSetZero(oci8_errhp, _NUMBER(self));
+        OCINumberSetZero(errhp, _NUMBER(self));
     } else if (RTEST(rb_obj_is_kind_of(val, rb_cNumeric))) {
-        set_oci_number_from_num(_NUMBER(self), val, 1);
+        set_oci_number_from_num(_NUMBER(self), val, 1, errhp);
     } else {
-        set_oci_number_from_str(_NUMBER(self), val, fmt, nls_params);
+        set_oci_number_from_str(_NUMBER(self), val, fmt, nls_params, errhp);
     }
     return Qnil;
 }
@@ -514,11 +527,12 @@
 
 static VALUE onum_coerce(VALUE self, VALUE other)
 {
+    OCIError *errhp = oci8_errhp;
     OCINumber n;
 
     if (RTEST(rb_obj_is_kind_of(other, rb_cNumeric)))
-        if (set_oci_number_from_num(&n, other, 0))
-            return rb_assoc_new(oci8_make_ocinumber(&n), self);
+        if (set_oci_number_from_num(&n, other, 0, errhp))
+            return rb_assoc_new(oci8_make_ocinumber(&n, errhp), self);
     rb_raise(rb_eTypeError, "Can't coerce %s to %s",
              rb_class2name(CLASS_OF(other)), rb_class2name(cOCINumber));
 }
@@ -531,10 +545,11 @@
  */
 static VALUE onum_neg(VALUE self)
 {
+    OCIError *errhp = oci8_errhp;
     OCINumber r;
 
-    oci_lc(OCINumberNeg(oci8_errhp, _NUMBER(self), &r));
-    return oci8_make_ocinumber(&r);
+    oci_lc(OCINumberNeg(errhp, _NUMBER(self), &r));
+    return oci8_make_ocinumber(&r, errhp);
 }
 
 /*
@@ -546,15 +561,16 @@
  */
 static VALUE onum_add(VALUE lhs, VALUE rhs)
 {
+    OCIError *errhp = oci8_errhp;
     OCINumber n;
     OCINumber r;
 
     /* change to OCINumber */
-    if (!set_oci_number_from_num(&n, rhs, 0))
+    if (!set_oci_number_from_num(&n, rhs, 0, errhp))
         return rb_num_coerce_bin(lhs, rhs, '+');
     /* add */
-    oci_lc(OCINumberAdd(oci8_errhp, _NUMBER(lhs), &n, &r));
-    return oci8_make_ocinumber(&r);
+    oci_lc(OCINumberAdd(errhp, _NUMBER(lhs), &n, &r));
+    return oci8_make_ocinumber(&r, errhp);
 }
 
 /*
@@ -566,15 +582,16 @@
  */
 static VALUE onum_sub(VALUE lhs, VALUE rhs)
 {
+    OCIError *errhp = oci8_errhp;
     OCINumber n;
     OCINumber r;
 
     /* change to OCINumber */
-    if (!set_oci_number_from_num(&n, rhs, 0))
+    if (!set_oci_number_from_num(&n, rhs, 0, errhp))
         return rb_num_coerce_bin(lhs, rhs, '-');
     /* subtracting */
-    oci_lc(OCINumberSub(oci8_errhp, _NUMBER(lhs), &n, &r));
-    return oci8_make_ocinumber(&r);
+    oci_lc(OCINumberSub(errhp, _NUMBER(lhs), &n, &r));
+    return oci8_make_ocinumber(&r, errhp);
 }
 
 /*
@@ -586,15 +603,16 @@
  */
 static VALUE onum_mul(VALUE lhs, VALUE rhs)
 {
+    OCIError *errhp = oci8_errhp;
     OCINumber n;
     OCINumber r;
 
     /* change to OCINumber */
-    if (!set_oci_number_from_num(&n, rhs, 0))
+    if (!set_oci_number_from_num(&n, rhs, 0, errhp))
         return rb_num_coerce_bin(lhs, rhs, '*');
     /* multiply */
-    oci_lc(OCINumberMul(oci8_errhp, _NUMBER(lhs), &n, &r));
-    return oci8_make_ocinumber(&r);
+    oci_lc(OCINumberMul(errhp, _NUMBER(lhs), &n, &r));
+    return oci8_make_ocinumber(&r, errhp);
 }
 
 /*
@@ -606,20 +624,21 @@
  */
 static VALUE onum_div(VALUE lhs, VALUE rhs)
 {
+    OCIError *errhp = oci8_errhp;
     OCINumber n;
     OCINumber r;
     boolean is_zero;
 
     /* change to OCINumber */
-    if (!set_oci_number_from_num(&n, rhs, 0))
+    if (!set_oci_number_from_num(&n, rhs, 0, errhp))
         return rb_num_coerce_bin(lhs, rhs, '/');
     /* check whether argument is not zero. */
-    oci_lc(OCINumberIsZero(oci8_errhp, &n, &is_zero));
+    oci_lc(OCINumberIsZero(errhp, &n, &is_zero));
     if (is_zero)
         rb_num_zerodiv();
     /* division */
-    oci_lc(OCINumberDiv(oci8_errhp, _NUMBER(lhs), &n, &r));
-    return oci8_make_ocinumber(&r);
+    oci_lc(OCINumberDiv(errhp, _NUMBER(lhs), &n, &r));
+    return oci8_make_ocinumber(&r, errhp);
 }
 
 /*
@@ -630,20 +649,21 @@
  */
 static VALUE onum_mod(VALUE lhs, VALUE rhs)
 {
+    OCIError *errhp = oci8_errhp;
     OCINumber n;
     OCINumber r;
     boolean is_zero;
 
     /* change to OCINumber */
-    if (!set_oci_number_from_num(&n, rhs, 0))
+    if (!set_oci_number_from_num(&n, rhs, 0, errhp))
         return rb_num_coerce_bin(lhs, rhs, '%');
     /* check whether argument is not zero. */
-    oci_lc(OCINumberIsZero(oci8_errhp, &n, &is_zero));
+    oci_lc(OCINumberIsZero(errhp, &n, &is_zero));
     if (is_zero)
         rb_num_zerodiv();
     /* modulo */
-    oci_lc(OCINumberMod(oci8_errhp, _NUMBER(lhs), &n, &r));
-    return oci8_make_ocinumber(&r);
+    oci_lc(OCINumberMod(errhp, _NUMBER(lhs), &n, &r));
+    return oci8_make_ocinumber(&r, errhp);
 }
 
 /*
@@ -654,18 +674,19 @@
  */
 static VALUE onum_power(VALUE lhs, VALUE rhs)
 {
+    OCIError *errhp = oci8_errhp;
     OCINumber n;
     OCINumber r;
 
     if (FIXNUM_P(rhs)) {
-        oci_lc(OCINumberIntPower(oci8_errhp, _NUMBER(lhs), FIX2INT(rhs), &r));
+        oci_lc(OCINumberIntPower(errhp, _NUMBER(lhs), FIX2INT(rhs), &r));
     } else {
         /* change to OCINumber */
-        if (!set_oci_number_from_num(&n, rhs, 0))
+        if (!set_oci_number_from_num(&n, rhs, 0, errhp))
             return rb_num_coerce_bin(lhs, rhs, id_power);
-        oci_lc(OCINumberPower(oci8_errhp, _NUMBER(lhs), &n, &r));
+        oci_lc(OCINumberPower(errhp, _NUMBER(lhs), &n, &r));
     }
-    return oci8_make_ocinumber(&r);
+    return oci8_make_ocinumber(&r, errhp);
 }
 
 /*
@@ -678,14 +699,15 @@
  */
 static VALUE onum_cmp(VALUE lhs, VALUE rhs)
 {
+    OCIError *errhp = oci8_errhp;
     OCINumber n;
     sword r;
 
     /* change to OCINumber */
-    if (!set_oci_number_from_num(&n, rhs, 0))
+    if (!set_oci_number_from_num(&n, rhs, 0, errhp))
         return rb_num_coerce_cmp(lhs, rhs, id_cmp);
     /* compare */
-    oci_lc(OCINumberCmp(oci8_errhp, _NUMBER(lhs), &n, &r));
+    oci_lc(OCINumberCmp(errhp, _NUMBER(lhs), &n, &r));
     if (r > 0) {
         return INT2FIX(1);
     } else if (r == 0) {
@@ -703,10 +725,11 @@
  */
 static VALUE onum_floor(VALUE self)
 {
+    OCIError *errhp = oci8_errhp;
     OCINumber r;
 
-    oci_lc(OCINumberFloor(oci8_errhp, _NUMBER(self), &r));
-    return oci8_make_integer(&r);
+    oci_lc(OCINumberFloor(errhp, _NUMBER(self), &r));
+    return oci8_make_integer(&r, errhp);
 }
 
 /*
@@ -718,10 +741,11 @@
  */
 static VALUE onum_ceil(VALUE self)
 {
+    OCIError *errhp = oci8_errhp;
     OCINumber r;
 
-    oci_lc(OCINumberCeil(oci8_errhp, _NUMBER(self), &r));
-    return oci8_make_integer(&r);
+    oci_lc(OCINumberCeil(errhp, _NUMBER(self), &r));
+    return oci8_make_integer(&r, errhp);
 }
 
 /*
@@ -738,15 +762,16 @@
  */
 static VALUE onum_round(int argc, VALUE *argv, VALUE self)
 {
+    OCIError *errhp = oci8_errhp;
     VALUE decplace;
     OCINumber r;
 
     rb_scan_args(argc, argv, "01", &decplace /* 0 */);
-    oci_lc(OCINumberRound(oci8_errhp, _NUMBER(self), NIL_P(decplace) ? 0 : NUM2INT(decplace), &r));
+    oci_lc(OCINumberRound(errhp, _NUMBER(self), NIL_P(decplace) ? 0 : NUM2INT(decplace), &r));
     if (argc == 0) {
-        return oci8_make_integer(&r);
+        return oci8_make_integer(&r, errhp);
     } else {
-        return oci8_make_ocinumber(&r);
+        return oci8_make_ocinumber(&r, errhp);
     }
 }
 
@@ -760,12 +785,13 @@
  */
 static VALUE onum_trunc(int argc, VALUE *argv, VALUE self)
 {
+    OCIError *errhp = oci8_errhp;
     VALUE decplace;
     OCINumber r;
 
     rb_scan_args(argc, argv, "01", &decplace /* 0 */);
-    oci_lc(OCINumberTrunc(oci8_errhp, _NUMBER(self), NIL_P(decplace) ? 0 : NUM2INT(decplace), &r));
-    return oci8_make_ocinumber(&r);
+    oci_lc(OCINumberTrunc(errhp, _NUMBER(self), NIL_P(decplace) ? 0 : NUM2INT(decplace), &r));
+    return oci8_make_ocinumber(&r, errhp);
 }
 
 /*
@@ -781,10 +807,11 @@
  */
 static VALUE onum_round_prec(VALUE self, VALUE ndigs)
 {
+    OCIError *errhp = oci8_errhp;
     OCINumber r;
 
-    oci_lc(OCINumberPrec(oci8_errhp, _NUMBER(self), NUM2INT(ndigs), &r));
-    return oci8_make_ocinumber(&r);
+    oci_lc(OCINumberPrec(errhp, _NUMBER(self), NUM2INT(ndigs), &r));
+    return oci8_make_ocinumber(&r, errhp);
 }
 
 /*
@@ -797,6 +824,7 @@
  */
 static VALUE onum_to_char(int argc, VALUE *argv, VALUE self)
 {
+    OCIError *errhp = oci8_errhp;
     VALUE fmt;
     VALUE nls_params;
     char buf[512];
@@ -813,13 +841,13 @@
         sword sign;
         boolean is_int;
 
-        oci_lc(OCINumberIsInt(oci8_errhp, _NUMBER(self), &is_int));
+        oci_lc(OCINumberIsInt(errhp, _NUMBER(self), &is_int));
         if (is_int) {
             fmt_ptr = NUMBER_FORMAT_INT;
             fmt_len = NUMBER_FORMAT_INT_LEN;
         } else {
-            oci_lc(OCINumberAbs(oci8_errhp, _NUMBER(self), &absval));
-            oci_lc(OCINumberCmp(oci8_errhp, &absval, &const_shreshold, &sign));
+            oci_lc(OCINumberAbs(errhp, _NUMBER(self), &absval));
+            oci_lc(OCINumberCmp(errhp, &absval, &const_shreshold, &sign));
             if (sign >= 0) {
                 fmt_ptr = NUMBER_FORMAT2;
                 fmt_len = NUMBER_FORMAT2_LEN;
@@ -841,18 +869,18 @@
         nls_params_ptr = RSTRING_ORATEXT(nls_params);
         nls_params_len = RSTRING_LEN(nls_params);
     }
-    rv = OCINumberToText(oci8_errhp, _NUMBER(self),
+    rv = OCINumberToText(errhp, _NUMBER(self),
                          fmt_ptr, fmt_len, nls_params_ptr, nls_params_len,
                          &buf_size, TO_ORATEXT(buf));
     if (rv == OCI_ERROR) {
         sb4 errcode;
-        OCIErrorGet(oci8_errhp, 1, NULL, &errcode, NULL, 0, OCI_HTYPE_ERROR);
+        OCIErrorGet(errhp, 1, NULL, &errcode, NULL, 0, OCI_HTYPE_ERROR);
         if (errcode == 22065) {
             /* OCI-22065: number to text translation for the given format causes overflow */
             if (NIL_P(fmt)) /* implicit conversion */
                 return rb_usascii_str_new_cstr("overflow");
         }
-        oci8_raise(oci8_errhp, rv, NULL);
+        oci8_raise(errhp, rv, NULL);
     }
     return rb_usascii_str_new(buf, buf_size);
 }
@@ -876,10 +904,11 @@
  */
 static VALUE onum_to_i(VALUE self)
 {
+    OCIError *errhp = oci8_errhp;
     OCINumber num;
 
-    oci_lc(OCINumberTrunc(oci8_errhp, _NUMBER(self), 0, &num));
-    return oci8_make_integer(&num);
+    oci_lc(OCINumberTrunc(errhp, _NUMBER(self), 0, &num));
+    return oci8_make_integer(&num, errhp);
 }
 
 /*
@@ -891,9 +920,10 @@
  */
 static VALUE onum_to_f(VALUE self)
 {
+    OCIError *errhp = oci8_errhp;
     double dbl;
 
-    oci_lc(OCINumberToReal(oci8_errhp, _NUMBER(self), sizeof(dbl), &dbl));
+    oci_lc(OCINumberToReal(errhp, _NUMBER(self), sizeof(dbl), &dbl));
     return rb_float_new(dbl);
 }
 
@@ -916,9 +946,10 @@
  */
 static VALUE onum_zero_p(VALUE self)
 {
+    OCIError *errhp = oci8_errhp;
     boolean result;
 
-    oci_lc(OCINumberIsZero(oci8_errhp, _NUMBER(self), &result));
+    oci_lc(OCINumberIsZero(errhp, _NUMBER(self), &result));
     return result ? Qtrue : Qfalse;
 }
 
@@ -931,10 +962,11 @@
  */
 static VALUE onum_abs(VALUE self)
 {
+    OCIError *errhp = oci8_errhp;
     OCINumber result;
 
-    oci_lc(OCINumberAbs(oci8_errhp, _NUMBER(self), &result));
-    return oci8_make_ocinumber(&result);
+    oci_lc(OCINumberAbs(errhp, _NUMBER(self), &result));
+    return oci8_make_ocinumber(&result, errhp);
 }
 
 /*
@@ -946,10 +978,11 @@
  */
 static VALUE onum_shift(VALUE self, VALUE exp)
 {
+    OCIError *errhp = oci8_errhp;
     OCINumber result;
 
-    oci_lc(OCINumberShift(oci8_errhp, _NUMBER(self), NUM2INT(exp), &result));
-    return oci8_make_ocinumber(&result);
+    oci_lc(OCINumberShift(errhp, _NUMBER(self), NUM2INT(exp), &result));
+    return oci8_make_ocinumber(&result, errhp);
 }
 
 static VALUE onum_hash(VALUE self)
@@ -1018,7 +1051,7 @@
     }
     memset(&num, 0, sizeof(num));
     memcpy(&num, c, size);
-    return oci8_make_ocinumber(&num);
+    return oci8_make_ocinumber(&num, oci8_errhp);
 }
 
 /*
@@ -1026,25 +1059,26 @@
  */
 static VALUE bind_ocinumber_get(oci8_bind_t *obind, void *data, void *null_struct)
 {
-    return oci8_make_ocinumber((OCINumber*)data);
+    return oci8_make_ocinumber((OCINumber*)data, oci8_errhp);
 }
 
 static VALUE bind_integer_get(oci8_bind_t *obind, void *data, void *null_struct)
 {
-    return oci8_make_integer((OCINumber*)data);
+    return oci8_make_integer((OCINumber*)data, oci8_errhp);
 }
 
 static void bind_ocinumber_set(oci8_bind_t *obind, void *data, void **null_structp, VALUE val)
 {
-    set_oci_number_from_num((OCINumber*)data, val, 1);
+    set_oci_number_from_num((OCINumber*)data, val, 1, oci8_errhp);
 }
 
 static void bind_integer_set(oci8_bind_t *obind, void *data, void **null_structp, VALUE val)
 {
+    OCIError *errhp = oci8_errhp;
     OCINumber num;
 
-    set_oci_number_from_num(&num, val, 1);
-    oci_lc(OCINumberTrunc(oci8_errhp, &num, 0, (OCINumber*)data));
+    set_oci_number_from_num(&num, val, 1, errhp);
+    oci_lc(OCINumberTrunc(errhp, &num, 0, (OCINumber*)data));
 }
 
 static void bind_ocinumber_init(oci8_bind_t *obind, VALUE svc, VALUE val, VALUE length)
@@ -1055,10 +1089,11 @@
 
 static void bind_ocinumber_init_elem(oci8_bind_t *obind, VALUE svc)
 {
+    OCIError *errhp = oci8_errhp;
     ub4 idx = 0;
 
     do {
-        OCINumberSetZero(oci8_errhp, (OCINumber*)obind->valuep + idx);
+        OCINumberSetZero(errhp, (OCINumber*)obind->valuep + idx);
     } while (++idx < obind->maxar_sz);
 }
 
@@ -1095,7 +1130,7 @@
 };
 
 void
-Init_oci_number(VALUE cOCI8)
+Init_oci_number(VALUE cOCI8, OCIError *errhp)
 {
     VALUE mMath;
     OCINumber num1, num2;
@@ -1111,27 +1146,27 @@
     /* constants for internal use. */
     /* set const_p1 */
     sl = 1;
-    OCINumberFromInt(oci8_errhp, &sl, sizeof(sl), OCI_NUMBER_SIGNED, &const_p1);
+    OCINumberFromInt(errhp, &sl, sizeof(sl), OCI_NUMBER_SIGNED, &const_p1);
     /* set const_p10 */
     sl = 10;
-    OCINumberFromInt(oci8_errhp, &sl, sizeof(sl), OCI_NUMBER_SIGNED, &const_p10);
+    OCINumberFromInt(errhp, &sl, sizeof(sl), OCI_NUMBER_SIGNED, &const_p10);
     /* set const_m1 */
     sl = -1;
-    OCINumberFromInt(oci8_errhp, &sl, sizeof(sl), OCI_NUMBER_SIGNED, &const_m1);
+    OCINumberFromInt(errhp, &sl, sizeof(sl), OCI_NUMBER_SIGNED, &const_m1);
     /* set const_PI2 */
     sl = 2;
-    OCINumberSetPi(oci8_errhp, &num1);
-    OCINumberFromInt(oci8_errhp, &sl, sizeof(sl), OCI_NUMBER_SIGNED, &num2);
-    OCINumberDiv(oci8_errhp, &num1 /* PI */, &num2 /* 2 */, &const_PI2);
+    OCINumberSetPi(errhp, &num1);
+    OCINumberFromInt(errhp, &sl, sizeof(sl), OCI_NUMBER_SIGNED, &num2);
+    OCINumberDiv(errhp, &num1 /* PI */, &num2 /* 2 */, &const_PI2);
     /* set const_mPI2 */
-    OCINumberNeg(oci8_errhp, &const_PI2 /* PI/2 */, &const_mPI2);
+    OCINumberNeg(errhp, &const_PI2 /* PI/2 */, &const_mPI2);
     /* set const_shreshold */
-    OCINumberFromText(oci8_errhp, SHRESHOLD_VAL, SHRESHOLD_VAL_LEN, SHRESHOLD_FMT, SHRESHOLD_FMT_LEN,
+    OCINumberFromText(errhp, SHRESHOLD_VAL, SHRESHOLD_VAL_LEN, SHRESHOLD_FMT, SHRESHOLD_FMT_LEN,
                       NULL, 0, &const_shreshold);
 
     /* PI */
-    OCINumberSetPi(oci8_errhp, &num1);
-    obj_PI = oci8_make_ocinumber(&num1);
+    OCINumberSetPi(errhp, &num1);
+    obj_PI = oci8_make_ocinumber(&num1, errhp);
 
     /* The ratio of the circumference of a circle to its diameter. */
     rb_define_const(mMath, "PI", obj_PI);




More information about the ruby-oci8-commit mailing list