[ruby-oci8-commit] [370] trunk/ruby-oci8: * ext/oci8/extconf.rb, ext/oci8/oci8.h, ext/oci8/ oci8lib.c,

nobody at rubyforge.org nobody at rubyforge.org
Fri Oct 23 03:24:50 EDT 2009


Revision: 370
Author:   kubo
Date:     2009-10-23 03:24:50 -0400 (Fri, 23 Oct 2009)

Log Message:
-----------
* ext/oci8/extconf.rb, ext/oci8/oci8.h, ext/oci8/oci8lib.c,
  ext/oci8/ocihandle.c: add ocihandle.c and move OCIHandle
    definitions from oci8lib.c to the file.

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

Added Paths:
-----------
    trunk/ruby-oci8/ext/oci8/ocihandle.c

Modified: trunk/ruby-oci8/ChangeLog
===================================================================
--- trunk/ruby-oci8/ChangeLog	2009-10-21 13:57:34 UTC (rev 369)
+++ trunk/ruby-oci8/ChangeLog	2009-10-23 07:24:50 UTC (rev 370)
@@ -1,3 +1,8 @@
+2009-10-23  KUBO Takehiro  <kubo at jiubao.org>
+	* ext/oci8/extconf.rb, ext/oci8/oci8.h, ext/oci8/oci8lib.c,
+	  ext/oci8/ocihandle.c: add ocihandle.c and move OCIHandle
+	    definitions from oci8lib.c to the file.
+
 2009-10-21  KUBO Takehiro  <kubo at jiubao.org>
 	* NEWS: add changes between 2.0.2 and 2.0.3.
 	* VERSION, Makefile: change the version to 2.0.3.

Modified: trunk/ruby-oci8/ext/oci8/extconf.rb
===================================================================
--- trunk/ruby-oci8/ext/oci8/extconf.rb	2009-10-21 13:57:34 UTC (rev 369)
+++ trunk/ruby-oci8/ext/oci8/extconf.rb	2009-10-23 07:24:50 UTC (rev 370)
@@ -82,7 +82,7 @@
   $libs = saved_libs
 end
 
-$objs = ["oci8lib.o", "env.o", "error.o", "oci8.o",
+$objs = ["oci8lib.o", "env.o", "error.o", "oci8.o", "ocihandle.o",
          "stmt.o", "bind.o", "metadata.o", "attr.o",
          "lob.o", "oradate.o",
          "ocinumber.o", "ocidatetime.o", "object.o", "apiwrap.o",

Modified: trunk/ruby-oci8/ext/oci8/oci8.h
===================================================================
--- trunk/ruby-oci8/ext/oci8/oci8.h	2009-10-21 13:57:34 UTC (rev 369)
+++ trunk/ruby-oci8/ext/oci8/oci8.h	2009-10-23 07:24:50 UTC (rev 370)
@@ -389,6 +389,7 @@
 extern ID oci8_id_get;
 extern ID oci8_id_set;
 extern ID oci8_id_keys;
+extern ID oci8_id_oci8_class;
 extern int oci8_in_finalizer;
 extern VALUE oci8_cOCIHandle;
 void oci8_base_free(oci8_base_t *base);
@@ -412,6 +413,9 @@
 NORETURN(void oci8_do_raise_init_error(const char *file, int line));
 sb4 oci8_get_error_code(OCIError *errhp);
 
+/* ocihandle.c */
+void Init_oci8_handle(void);
+
 /* oci8.c */
 VALUE Init_oci8(void);
 oci8_svcctx_t *oci8_get_svcctx(VALUE obj);

Modified: trunk/ruby-oci8/ext/oci8/oci8lib.c
===================================================================
--- trunk/ruby-oci8/ext/oci8/oci8lib.c	2009-10-21 13:57:34 UTC (rev 369)
+++ trunk/ruby-oci8/ext/oci8/oci8lib.c	2009-10-23 07:24:50 UTC (rev 370)
@@ -10,29 +10,18 @@
 #include <signal.h>
 #endif
 
-static oci8_base_class_t oci8_base_class = {
-    NULL,
-    NULL,
-    sizeof(oci8_base_t),
-};
-
 ID oci8_id_new;
 ID oci8_id_get;
 ID oci8_id_set;
 ID oci8_id_keys;
+ID oci8_id_oci8_class;
 int oci8_in_finalizer = 0;
 VALUE oci8_cOCIHandle;
 
-static ID id_oci8_class;
 
 static VALUE mOCI8BindType;
 static VALUE cOCI8BindTypeBase;
 
-static VALUE oci8_handle_initialize(VALUE self)
-{
-    rb_raise(rb_eNameError, "private method `new' called for %s:Class", rb_class2name(CLASS_OF(self)));
-}
-
 void oci8_base_free(oci8_base_t *base)
 {
     while (base->children != NULL) {
@@ -49,55 +38,6 @@
     base->hp.ptr = NULL;
 }
 
-static VALUE oci8_handle_free(VALUE self)
-{
-    oci8_base_t *base = DATA_PTR(self);
-
-    oci8_base_free(base);
-    return self;
-}
-
-static void oci8_handle_mark(oci8_base_t *base)
-{
-    if (base->klass->mark != NULL)
-        base->klass->mark(base);
-}
-
-static void oci8_handle_cleanup(oci8_base_t *base)
-{
-    oci8_base_free(base);
-    xfree(base);
-}
-
-static VALUE oci8_s_allocate(VALUE klass)
-{
-    oci8_base_t *base;
-    const oci8_base_class_t *base_class;
-    VALUE superklass;
-    VALUE obj;
-
-    superklass = klass;
-    while (!RTEST(rb_ivar_defined(superklass, id_oci8_class))) {
-        superklass = RCLASS_SUPER(superklass);
-        if (superklass == rb_cObject)
-            rb_raise(rb_eRuntimeError, "private method `new' called for %s:Class", rb_class2name(klass));
-    }
-    obj = rb_ivar_get(superklass, id_oci8_class);
-    base_class = DATA_PTR(obj);
-
-    base = xmalloc(base_class->size);
-    memset(base, 0, base_class->size);
-
-    obj = Data_Wrap_Struct(klass, oci8_handle_mark, oci8_handle_cleanup, base);
-    base->self = obj;
-    base->klass = base_class;
-    base->parent = NULL;
-    base->next = base;
-    base->prev = base;
-    base->children = NULL;
-    return obj;
-}
-
 static void at_exit_func(VALUE val)
 {
     oci8_in_finalizer = 1;
@@ -107,7 +47,6 @@
 Init_oci8lib()
 {
     VALUE cOCI8;
-    VALUE obj;
     OCIEnv *envhp;
     OCIError *errhp;
     sword rv;
@@ -121,23 +60,18 @@
     }
 #endif
 
-    id_oci8_class = rb_intern("__oci8_class__");
     oci8_id_new = rb_intern("new");
     oci8_id_get = rb_intern("get");
     oci8_id_set = rb_intern("set");
     oci8_id_keys = rb_intern("keys");
+    oci8_id_oci8_class = rb_intern("__oci8_class__");
     rb_set_end_proc(at_exit_func, Qnil);
 
     Init_oci8_error();
     Init_oci8_env();
 
     /* OCIHandle class */
-    oci8_cOCIHandle = rb_define_class("OCIHandle", rb_cObject);
-    rb_define_alloc_func(oci8_cOCIHandle, oci8_s_allocate);
-    rb_define_method(oci8_cOCIHandle, "initialize", oci8_handle_initialize, 0);
-    rb_define_method(oci8_cOCIHandle, "free", oci8_handle_free, 0);
-    obj = Data_Wrap_Struct(rb_cObject, 0, 0, &oci8_base_class);
-    rb_ivar_set(oci8_cOCIHandle, id_oci8_class, obj);
+    Init_oci8_handle();
 
     /* OCI8 class */
     cOCI8 = Init_oci8();
@@ -207,7 +141,7 @@
 {
     VALUE klass = rb_define_class(name, oci8_cOCIHandle);
     VALUE obj = Data_Wrap_Struct(rb_cObject, 0, 0, base_class);
-    rb_ivar_set(klass, id_oci8_class, obj);
+    rb_ivar_set(klass, oci8_id_oci8_class, obj);
     return klass;
 }
 
@@ -215,7 +149,7 @@
 {
     VALUE klass = rb_define_class_under(outer, name, oci8_cOCIHandle);
     VALUE obj = Data_Wrap_Struct(rb_cObject, 0, 0, base_class);
-    rb_ivar_set(klass, id_oci8_class, obj);
+    rb_ivar_set(klass, oci8_id_oci8_class, obj);
     return klass;
 }
 
@@ -223,7 +157,7 @@
 {
     VALUE klass = rb_define_class_under(mOCI8BindType, name, cOCI8BindTypeBase);
     VALUE obj = Data_Wrap_Struct(rb_cObject, 0, 0, (void*)bind_class);
-    rb_ivar_set(klass, id_oci8_class, obj);
+    rb_ivar_set(klass, oci8_id_oci8_class, obj);
     return klass;
 }
 

Added: trunk/ruby-oci8/ext/oci8/ocihandle.c
===================================================================
--- trunk/ruby-oci8/ext/oci8/ocihandle.c	                        (rev 0)
+++ trunk/ruby-oci8/ext/oci8/ocihandle.c	2009-10-23 07:24:50 UTC (rev 370)
@@ -0,0 +1,82 @@
+/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
+/*
+ * ocihandle.c
+ *
+ * Copyright (C) 2009 KUBO Takehiro <kubo at jiubao.org>
+ *
+ * implement OCIHandle
+ *
+ */
+#include "oci8.h"
+
+static oci8_base_class_t oci8_base_class = {
+    NULL,
+    NULL,
+    sizeof(oci8_base_t),
+};
+
+static VALUE oci8_handle_initialize(VALUE self)
+{
+    rb_raise(rb_eNameError, "private method `new' called for %s:Class", rb_class2name(CLASS_OF(self)));
+}
+
+static VALUE oci8_handle_free(VALUE self)
+{
+    oci8_base_t *base = DATA_PTR(self);
+
+    oci8_base_free(base);
+    return self;
+}
+
+static void oci8_handle_mark(oci8_base_t *base)
+{
+    if (base->klass->mark != NULL)
+        base->klass->mark(base);
+}
+
+static void oci8_handle_cleanup(oci8_base_t *base)
+{
+    oci8_base_free(base);
+    xfree(base);
+}
+
+static VALUE oci8_s_allocate(VALUE klass)
+{
+    oci8_base_t *base;
+    const oci8_base_class_t *base_class;
+    VALUE superklass;
+    VALUE obj;
+
+    superklass = klass;
+    while (!RTEST(rb_ivar_defined(superklass, oci8_id_oci8_class))) {
+        superklass = RCLASS_SUPER(superklass);
+        if (superklass == rb_cObject)
+            rb_raise(rb_eRuntimeError, "private method `new' called for %s:Class", rb_class2name(klass));
+    }
+    obj = rb_ivar_get(superklass, oci8_id_oci8_class);
+    base_class = DATA_PTR(obj);
+
+    base = xmalloc(base_class->size);
+    memset(base, 0, base_class->size);
+
+    obj = Data_Wrap_Struct(klass, oci8_handle_mark, oci8_handle_cleanup, base);
+    base->self = obj;
+    base->klass = base_class;
+    base->parent = NULL;
+    base->next = base;
+    base->prev = base;
+    base->children = NULL;
+    return obj;
+}
+
+void Init_oci8_handle(void)
+{
+    VALUE obj;
+
+    oci8_cOCIHandle = rb_define_class("OCIHandle", rb_cObject);
+    rb_define_alloc_func(oci8_cOCIHandle, oci8_s_allocate);
+    rb_define_method(oci8_cOCIHandle, "initialize", oci8_handle_initialize, 0);
+    rb_define_method(oci8_cOCIHandle, "free", oci8_handle_free, 0);
+    obj = Data_Wrap_Struct(rb_cObject, 0, 0, &oci8_base_class);
+    rb_ivar_set(oci8_cOCIHandle, oci8_id_oci8_class, obj);
+}




More information about the ruby-oci8-commit mailing list