[ruby-oci8-commit] [305] trunk/ruby-oci8: * ext/oci8/encoding.c, ext/oci8/error.c, ext/oci8/ ocinumber.c,

nobody at rubyforge.org nobody at rubyforge.org
Sat Jan 3 11:58:02 EST 2009


Revision: 305
Author:   kubo
Date:     2009-01-03 11:58:01 -0500 (Sat, 03 Jan 2009)

Log Message:
-----------
* ext/oci8/encoding.c, ext/oci8/error.c, ext/oci8/ocinumber.c,
  ext/oci8/oradate.c: use rb_usascii_str_new() or
    rb_usascii_str_new_cstr() when its encoding is always
    us-ascii.
* ext/oci8/extconf.rb: add type checking for rb_encoding
    for ruby 1.9.
* ext/oci8/oci8.h: use rb_str_new(), rb_str_new2() and
    rb_tainted_str_new() if rb_usascii_str_new(),
    rb_usascii_str_new_cstr() and rb_external_str_new_with_enc()
    are not usable.
* ext/oci8/oci8lib.c: use ORAVERNUM macro.

Modified Paths:
--------------
    trunk/ruby-oci8/ChangeLog
    trunk/ruby-oci8/ext/oci8/encoding.c
    trunk/ruby-oci8/ext/oci8/error.c
    trunk/ruby-oci8/ext/oci8/extconf.rb
    trunk/ruby-oci8/ext/oci8/oci8.h
    trunk/ruby-oci8/ext/oci8/oci8lib.c
    trunk/ruby-oci8/ext/oci8/ocinumber.c
    trunk/ruby-oci8/ext/oci8/oradate.c

Modified: trunk/ruby-oci8/ChangeLog
===================================================================
--- trunk/ruby-oci8/ChangeLog	2009-01-03 08:36:03 UTC (rev 304)
+++ trunk/ruby-oci8/ChangeLog	2009-01-03 16:58:01 UTC (rev 305)
@@ -1,4 +1,17 @@
 2009-01-03  KUBO Takehiro  <kubo at jiubao.org>
+	* ext/oci8/encoding.c, ext/oci8/error.c, ext/oci8/ocinumber.c,
+	  ext/oci8/oradate.c: use rb_usascii_str_new() or
+	    rb_usascii_str_new_cstr() when its encoding is always
+	    us-ascii.
+	* ext/oci8/extconf.rb: add type checking for rb_encoding
+	    for ruby 1.9.
+	* ext/oci8/oci8.h: use rb_str_new(), rb_str_new2() and
+	    rb_tainted_str_new() if rb_usascii_str_new(),
+	    rb_usascii_str_new_cstr() and rb_external_str_new_with_enc()
+	    are not usable.
+	* ext/oci8/oci8lib.c: use ORAVERNUM macro.
+
+2009-01-03  KUBO Takehiro  <kubo at jiubao.org>
 	* custom-rdoc.rb: fix for rdoc bundled with ruby 1.9.
 	* ext/oci8/apiwrap.yml, ext/oci8/oci8lib.c: set the value of
 	    OCI8.oracle_client_version by OCIClientVersion() if

Modified: trunk/ruby-oci8/ext/oci8/encoding.c
===================================================================
--- trunk/ruby-oci8/ext/oci8/encoding.c	2009-01-03 08:36:03 UTC (rev 304)
+++ trunk/ruby-oci8/ext/oci8/encoding.c	2009-01-03 16:58:01 UTC (rev 305)
@@ -46,7 +46,7 @@
         if (rv != OCI_SUCCESS) {
             return Qnil;
         }
-        name = rb_str_new2(buf);
+        name = rb_usascii_str_new_cstr(buf);
     } else {
         /* Oracle 9iR1 or lower */
         oci8_exec_sql_var_t bind_vars[2];
@@ -72,7 +72,7 @@
         if (buflen == 0) {
             return Qnil;
         }
-        name = rb_str_new(buf, buflen);
+        name = rb_usascii_str_new(buf, buflen);
     }
     OBJ_FREEZE(name);
     rb_hash_aset(csid2name, csid, name);

Modified: trunk/ruby-oci8/ext/oci8/error.c
===================================================================
--- trunk/ruby-oci8/ext/oci8/error.c	2009-01-03 08:36:03 UTC (rev 304)
+++ trunk/ruby-oci8/ext/oci8/error.c	2009-01-03 16:58:01 UTC (rev 305)
@@ -74,7 +74,7 @@
         if (RARRAY_LEN(vmessages) > 0) {
             msg = RARRAY_PTR(vmessages)[0];
         } else {
-            msg = rb_str_new2("ERROR");
+            msg = rb_usascii_str_new_cstr("ERROR");
         }
         if (status == OCI_ERROR) {
             exc = eOCIError;
@@ -103,28 +103,28 @@
         break;
     case OCI_NO_DATA:
         exc = eOCINoData;
-        msg = rb_str_new2("No Data");
+        msg = rb_usascii_str_new_cstr("No Data");
         break;
     case OCI_INVALID_HANDLE:
         exc = eOCIInvalidHandle;
-        msg = rb_str_new2("Invalid Handle");
+        msg = rb_usascii_str_new_cstr("Invalid Handle");
         break;
     case OCI_NEED_DATA:
         exc = eOCINeedData;
-        msg = rb_str_new2("Need Data");
+        msg = rb_usascii_str_new_cstr("Need Data");
         break;
     case OCI_STILL_EXECUTING:
         exc = eOCIStillExecuting;
-        msg = rb_str_new2("Still Executing");
+        msg = rb_usascii_str_new_cstr("Still Executing");
         break;
     case OCI_CONTINUE:
         exc = eOCIContinue;
-        msg = rb_str_new2("Continue");
+        msg = rb_usascii_str_new_cstr("Continue");
         break;
     default:
         sprintf(errmsg, "Unknown error (%d)", status);
         exc = rb_eStandardError;
-        msg = rb_str_new2(errmsg);
+        msg = rb_usascii_str_new_cstr(errmsg);
     }
     exc = rb_funcall(exc, oci8_id_new, 1, msg);
     if (!NIL_P(vcodes)) {
@@ -159,7 +159,7 @@
     if (TYPE(backtrace) == T_ARRAY) {
         snprintf(errmsg, sizeof(errmsg), "%s:%d:in oci8lib.so", file, line);
         errmsg[sizeof(errmsg) - 1] = '\0';
-        rb_ary_unshift(backtrace, rb_str_new2(errmsg));
+        rb_ary_unshift(backtrace, rb_usascii_str_new_cstr(errmsg));
         rb_funcall(exc, oci8_id_set_backtrace, 1, backtrace);
     }
     rb_exc_raise(exc);
@@ -294,7 +294,7 @@
 
 void oci8_do_raise_init_error(const char *file, int line)
 {
-    VALUE msg = rb_str_new2("OCI Library Initialization Error");
+    VALUE msg = rb_usascii_str_new_cstr("OCI Library Initialization Error");
     VALUE exc = rb_funcall(eOCIError, oci8_id_new, 1, msg);
 
     rb_ivar_set(exc, oci8_id_code, rb_ary_new3(1, INT2FIX(-1)));

Modified: trunk/ruby-oci8/ext/oci8/extconf.rb
===================================================================
--- trunk/ruby-oci8/ext/oci8/extconf.rb	2009-01-03 08:36:03 UTC (rev 304)
+++ trunk/ruby-oci8/ext/oci8/extconf.rb	2009-01-03 16:58:01 UTC (rev 305)
@@ -93,6 +93,7 @@
 have_header("util.h")
 # ruby 1.9 headers
 have_header("ruby/util.h")
+have_type('rb_encoding', ['ruby/ruby.h', 'ruby/encoding.h'])
 
 # $! in C API
 have_var("ruby_errinfo", "ruby.h") # ruby 1.8

Modified: trunk/ruby-oci8/ext/oci8/oci8.h
===================================================================
--- trunk/ruby-oci8/ext/oci8/oci8.h	2009-01-03 08:36:03 UTC (rev 304)
+++ trunk/ruby-oci8/ext/oci8/oci8.h	2009-01-03 16:58:01 UTC (rev 305)
@@ -89,6 +89,12 @@
 typedef VALUE rb_blocking_function_t(void *);
 #endif
 
+#ifndef HAVE_TYPE_RB_ENCODING
+#define rb_external_str_new_with_enc(ptr, len, enc) rb_tainted_str_new((ptr), (len))
+#define rb_usascii_str_new(ptr, len) rb_str_new((ptr), (len))
+#define rb_usascii_str_new_cstr(ptr) rb_str_new2(ptr)
+#endif
+
 /* macros depends on the compiler.
  *  LIKELY(x)      hint for the compiler that 'x' is 1(TRUE) in many cases.
  *  UNLIKELY(x)    hint for the compiler that 'x' is 0(FALSE) in many cases.

Modified: trunk/ruby-oci8/ext/oci8/oci8lib.c
===================================================================
--- trunk/ruby-oci8/ext/oci8/oci8lib.c	2009-01-03 08:36:03 UTC (rev 304)
+++ trunk/ruby-oci8/ext/oci8/oci8lib.c	2009-01-03 16:58:01 UTC (rev 305)
@@ -114,7 +114,7 @@
     if (have_OCIClientVersion) {
         sword major, minor, update, patch, port_update;
         OCIClientVersion(&major, &minor, &update, &patch, &port_update);
-        oracle_client_version = (major << 24) | (minor << 20) | (update << 12) | (patch << 8) | port_update;
+        oracle_client_version = ORAVERNUM(major, minor, update, patch, port_update);
     }
 #endif
 

Modified: trunk/ruby-oci8/ext/oci8/ocinumber.c
===================================================================
--- trunk/ruby-oci8/ext/oci8/ocinumber.c	2009-01-03 08:36:03 UTC (rev 304)
+++ trunk/ruby-oci8/ext/oci8/ocinumber.c	2009-01-03 16:58:01 UTC (rev 305)
@@ -850,7 +850,7 @@
         if (errcode == 22065) {
             /* OCI-22065: number to text translation for the given format causes overflow */
             if (NIL_P(fmt)) /* implicit conversion */
-                return rb_str_new2("overflow");
+                return rb_usascii_str_new_cstr("overflow");
         }
         oci8_raise(oci8_errhp, rv, NULL);
     }
@@ -978,7 +978,7 @@
 
     snprintf(str, len, "#<%s:%s>", name, RSTRING_PTR(s));
     str[len - 1] = '\0';
-    return rb_str_new2(str);
+    return rb_usascii_str_new_cstr(str);
 }
 
 /*

Modified: trunk/ruby-oci8/ext/oci8/oradate.c
===================================================================
--- trunk/ruby-oci8/ext/oci8/oradate.c	2009-01-03 08:36:03 UTC (rev 304)
+++ trunk/ruby-oci8/ext/oci8/oradate.c	2009-01-03 16:58:01 UTC (rev 305)
@@ -200,7 +200,7 @@
     Data_Get_Struct(self, ora_date_t, od);
     sprintf(buf, "%04d/%02d/%02d %02d:%02d:%02d", Get_year(od), Get_month(od),
             Get_day(od), Get_hour(od), Get_minute(od), Get_second(od));
-    return rb_str_new2(buf);
+    return rb_usascii_str_new_cstr(buf);
 }
 
 /*
@@ -495,7 +495,7 @@
 {
     ora_date_t *od;
     Data_Get_Struct(self, ora_date_t, od);
-    return rb_str_new((const char*)od, sizeof(ora_date_t));
+    return rb_str_new((const char*)od, sizeof(ora_date_t)); /* ASCII-8BIT */
 }
 
 /*




More information about the ruby-oci8-commit mailing list