[ruby-oci8-commit] [391] trunk/ruby-oci8: * lib/oci8/encoding-init.rb: fix for zero-length NLS_LANG.

nobody at rubyforge.org nobody at rubyforge.org
Sun May 2 09:15:25 EDT 2010


Revision: 391
Author:   kubo
Date:     2010-05-02 09:15:25 -0400 (Sun, 02 May 2010)

Log Message:
-----------
* lib/oci8/encoding-init.rb: fix for zero-length NLS_LANG.
    fix AL32UTF8's nls_ratio.
* ext/oci8/stmt.c: fix SEGV when an exception is raised in
    post_bind_hook().

Modified Paths:
--------------
    trunk/ruby-oci8/ChangeLog
    trunk/ruby-oci8/ext/oci8/stmt.c
    trunk/ruby-oci8/lib/oci8/encoding-init.rb

Modified: trunk/ruby-oci8/ChangeLog
===================================================================
--- trunk/ruby-oci8/ChangeLog	2010-04-27 14:31:26 UTC (rev 390)
+++ trunk/ruby-oci8/ChangeLog	2010-05-02 13:15:25 UTC (rev 391)
@@ -1,3 +1,9 @@
+2010-05-02  KUBO Takehiro  <kubo at jiubao.org>
+	* lib/oci8/encoding-init.rb: fix for zero-length NLS_LANG.
+	    fix AL32UTF8's nls_ratio.
+	* ext/oci8/stmt.c: fix SEGV when an exception is raised in
+	    post_bind_hook().
+
 2010-04-27  KUBO Takehiro  <kubo at jiubao.org>
 	* ext/oci8/lob.c, ext/oci8/object.c, ext/oci8/oci8.h,
 	  ext/oci8/stmt.c: refactor code to prepare character length

Modified: trunk/ruby-oci8/ext/oci8/stmt.c
===================================================================
--- trunk/ruby-oci8/ext/oci8/stmt.c	2010-04-27 14:31:26 UTC (rev 390)
+++ trunk/ruby-oci8/ext/oci8/stmt.c	2010-05-02 13:15:25 UTC (rev 391)
@@ -3,7 +3,7 @@
  * stmt.c - part of ruby-oci8
  *         implement the methods of OCIStmt.
  *
- * Copyright (C) 2002-2007 KUBO Takehiro <kubo at jiubao.org>
+ * Copyright (C) 2002-2010 KUBO Takehiro <kubo at jiubao.org>
  *
  */
 #include "oci8.h"
@@ -117,21 +117,23 @@
         oci8_raise(oci8_errhp, status, stmt->base.hp.ptr);
     }
     obind->base.type = OCI_HTYPE_DEFINE;
+    /* link to the parent as soon as possible to preserve deallocation order. */
+    oci8_unlink_from_parent((oci8_base_t*)obind);
+    oci8_link_to_parent((oci8_base_t*)obind, (oci8_base_t*)stmt);
+
     if (NIL_P(obind->tdo) && obind->maxar_sz > 0) {
         oci_lc(OCIDefineArrayOfStruct(obind->base.hp.dfn, oci8_errhp, obind->alloc_sz, sizeof(sb2), 0, 0));
     }
+    if (bind_class->post_bind_hook != NULL) {
+        bind_class->post_bind_hook(obind);
+    }
     if (position - 1 < RARRAY_LEN(stmt->defns)) {
         VALUE old_value = RARRAY_PTR(stmt->defns)[position - 1];
         if (!NIL_P(old_value)) {
             oci8_base_free((oci8_base_t*)oci8_get_bind(old_value));
         }
     }
-    if (bind_class->post_bind_hook != NULL) {
-        bind_class->post_bind_hook(obind);
-    }
     rb_ary_store(stmt->defns, position - 1, obind->base.self);
-    oci8_unlink_from_parent((oci8_base_t*)obind);
-    oci8_link_to_parent((oci8_base_t*)obind, (oci8_base_t*)stmt);
     return obind->base.self;
 }
 
@@ -192,6 +194,10 @@
         oci8_raise(oci8_errhp, status, stmt->base.hp.stmt);
     }
     obind->base.type = OCI_HTYPE_BIND;
+    /* link to the parent as soon as possible to preserve deallocation order. */
+    oci8_unlink_from_parent((oci8_base_t*)obind);
+    oci8_link_to_parent((oci8_base_t*)obind, (oci8_base_t*)stmt);
+
     if (NIL_P(obind->tdo) && obind->maxar_sz > 0) {
         oci_lc(OCIBindArrayOfStruct(obind->base.hp.bnd, oci8_errhp, obind->alloc_sz, sizeof(sb2), 0, 0));
     }
@@ -203,8 +209,6 @@
         oci8_base_free((oci8_base_t*)oci8_get_bind(old_value));
     }
     rb_hash_aset(stmt->binds, vplaceholder, obind->base.self);
-    oci8_unlink_from_parent((oci8_base_t*)obind);
-    oci8_link_to_parent((oci8_base_t*)obind, (oci8_base_t*)stmt);
     return obind->base.self;
 }
 

Modified: trunk/ruby-oci8/lib/oci8/encoding-init.rb
===================================================================
--- trunk/ruby-oci8/lib/oci8/encoding-init.rb	2010-04-27 14:31:26 UTC (rev 390)
+++ trunk/ruby-oci8/lib/oci8/encoding-init.rb	2010-05-02 13:15:25 UTC (rev 391)
@@ -5,6 +5,10 @@
 # get the environment variable NLS_LANG.
 nls_lang = ENV['NLS_LANG']
 
+if nls_lang.is_a? String and nls_lang.length == 0
+  nls_lang = nil
+end
+
 # if NLS_LANG is not set, get it from the Windows registry.
 if nls_lang.nil? and defined? OCI8::Win32Util
   dll_path = OCI8::Win32Util.dll_path.upcase
@@ -37,7 +41,7 @@
   OCI8.nls_ratio = 3
 when 'AL16UTF16'
   OCI8.nls_ratio = 4
-when /^\w+(\d+)/
+when /^[[:alpha:]]+(\d+)/
   # convert maximum number of bits per one chracter to NLS ratio.
   #   charset name  max bits  max bytes
   #   ------------  --------  ---------




More information about the ruby-oci8-commit mailing list