[ruby-oci8-commit] [548] trunk/ruby-oci8: delete an internal method OCI8.nls_ratio= when the ruby is 1.9 or greater.

nobody at rubyforge.org nobody at rubyforge.org
Thu Jan 3 01:39:00 UTC 2013


Revision: 548
Author:   kubo
Date:     2013-01-03 01:38:58 +0000 (Thu, 03 Jan 2013)
Log Message:
-----------
delete an internal method OCI8.nls_ratio= when the ruby is 1.9 or greater.
nls_ratio is set by OCI8.encoding=.

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

Modified: trunk/ruby-oci8/ChangeLog
===================================================================
--- trunk/ruby-oci8/ChangeLog	2012-12-23 11:47:16 UTC (rev 547)
+++ trunk/ruby-oci8/ChangeLog	2013-01-03 01:38:58 UTC (rev 548)
@@ -1,3 +1,8 @@
+2013-01-03  KUBO Takehiro  <kubo at jiubao.org>
+	* ext/oci8/encoding.c, lib/oci8/encoding-init.rb: delete an internal method
+	    OCI8.nls_ratio= when the ruby is 1.9 or greater. nls_ratio is set by
+	    OCI8.encoding=.
+
 2012-12-23  KUBO Takehiro  <kubo at jiubao.org>
 	* ext/oci8/lob.c, ext/oci8/oci8.h, ext/oci8/oci8lib.c, test/test_clob.rb:
 	    fix SEGV when a temporary LOB is freed when OCILobRead returns OCI_NEED_DATA.

Modified: trunk/ruby-oci8/ext/oci8/encoding.c
===================================================================
--- trunk/ruby-oci8/ext/oci8/encoding.c	2012-12-23 11:47:16 UTC (rev 547)
+++ trunk/ruby-oci8/ext/oci8/encoding.c	2013-01-03 01:38:58 UTC (rev 548)
@@ -185,12 +185,14 @@
  *
  * @return [Fixnum]  NLS ratio
  * @since 2.1.0
+ * @private
  */
 static VALUE oci8_get_nls_ratio(VALUE klass)
 {
     return INT2NUM(oci8_nls_ratio);
 }
 
+#ifndef HAVE_TYPE_RB_ENCODING
 /*
  * call-seq:
  *   OCI8.nls_ratio = integer
@@ -201,6 +203,8 @@
  *
  * @param [Fixnum] integer  NLS ratio
  * @since 2.1.0
+ * @private
+ * @note ruby 1.8 only
  */
 static VALUE oci8_set_nls_ratio(VALUE klass, VALUE val)
 {
@@ -211,6 +215,7 @@
     oci8_nls_ratio = v;
     return val;
 }
+#endif
 
 #ifdef HAVE_TYPE_RB_ENCODING
 
@@ -243,6 +248,7 @@
  *
  * @return [Encoding]
  * @since 2.0.0 and ruby 1.9
+ * @private
  */
 static VALUE oci8_get_encoding(VALUE klass)
 {
@@ -259,13 +265,16 @@
  *
  * @param [Encoding]  enc
  * @since 2.0.0 and ruby 1.9
+ * @private
  */
 static VALUE oci8_set_encoding(VALUE klass, VALUE encoding)
 {
     if (NIL_P(encoding)) {
         oci8_encoding = NULL;
+        oci8_nls_ratio = 1;
     } else {
         oci8_encoding = rb_to_encoding(encoding);
+        oci8_nls_ratio = rb_enc_mbmaxlen(oci8_encoding);
     }
     return encoding;
 }
@@ -287,7 +296,9 @@
     rb_define_method(cOCI8, "charset_name2id", oci8_charset_name2id, 1);
     rb_define_method(cOCI8, "charset_id2name", oci8_charset_id2name, 1);
     rb_define_singleton_method(cOCI8, "nls_ratio", oci8_get_nls_ratio, 0);
+#ifndef HAVE_TYPE_RB_ENCODING
     rb_define_singleton_method(cOCI8, "nls_ratio=", oci8_set_nls_ratio, 1);
+#endif
 #ifdef HAVE_TYPE_RB_ENCODING
     rb_define_singleton_method(cOCI8, "encoding", oci8_get_encoding, 0);
     rb_define_singleton_method(cOCI8, "encoding=", oci8_set_encoding, 1);

Modified: trunk/ruby-oci8/lib/oci8/encoding-init.rb
===================================================================
--- trunk/ruby-oci8/lib/oci8/encoding-init.rb	2012-12-23 11:47:16 UTC (rev 547)
+++ trunk/ruby-oci8/lib/oci8/encoding-init.rb	2013-01-03 01:38:58 UTC (rev 548)
@@ -39,26 +39,6 @@
     @@client_charset_name = 'US7ASCII'
   end
 
-  # NLS ratio, maximum number of bytes per one chracter
-  case @@client_charset_name
-  when 'UTF8'
-    OCI8.nls_ratio = 3
-  when 'AL16UTF16'
-    OCI8.nls_ratio = 4
-  when /^[[:alpha:]]+(\d+)/
-    # convert maximum number of bits per one chracter to NLS ratio.
-    #   charset name  max bits  max bytes
-    #   ------------  --------  ---------
-    #   US7ASCII          7         1
-    #   WE8ISO8859P1      8         1
-    #   JA16SJIS         16         2
-    #   AL32UTF8         32         4
-    #   ...
-    OCI8.nls_ratio = (($1.to_i + 7) >> 3)
-  else
-    raise "Unknown NLS character set name format: #{@@client_charset_name}"
-  end
-
   # Ruby encoding name for ruby 1.9.
   if OCI8.respond_to? :encoding
     if defined? DEFAULT_OCI8_ENCODING
@@ -75,5 +55,25 @@
       end
     end
     OCI8.encoding = enc
+  else
+    # NLS ratio, maximum number of bytes per one chracter
+    case @@client_charset_name
+    when 'UTF8'
+      OCI8.nls_ratio = 3
+    when 'AL16UTF16'
+      OCI8.nls_ratio = 4
+    when /^[[:alpha:]]+(\d+)/
+      # convert maximum number of bits per one chracter to NLS ratio.
+      #   charset name  max bits  max bytes
+      #   ------------  --------  ---------
+      #   US7ASCII          7         1
+      #   WE8ISO8859P1      8         1
+      #   JA16SJIS         16         2
+      #   AL32UTF8         32         4
+      #   ...
+      OCI8.nls_ratio = (($1.to_i + 7) >> 3)
+    else
+      raise "Unknown NLS character set name format: #{@@client_charset_name}"
+    end
   end
 end



More information about the ruby-oci8-commit mailing list