[ruby-oci8-commit] [241] trunk/ruby-oci8: * ext/oci8/oci8.h ext/oci8/oci8lib.c: rename variable name

nobody at rubyforge.org nobody at rubyforge.org
Mon Jan 14 10:44:44 EST 2008


Revision: 241
Author:   kubo
Date:     2008-01-14 10:44:44 -0500 (Mon, 14 Jan 2008)

Log Message:
-----------
* ext/oci8/oci8.h ext/oci8/oci8lib.c: rename variable name
    cOCIHandle to oci8_cOCIHandle to use outside of oci8lib.c.
* ext/oci8/metadata.c: use oci8_cOCIHandle instead of rb_cObject
    to hold a descrbe handle. check parent object's handle type
    in oci8_metadata_create().

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

Modified: trunk/ruby-oci8/ChangeLog
===================================================================
--- trunk/ruby-oci8/ChangeLog	2008-01-14 05:38:49 UTC (rev 240)
+++ trunk/ruby-oci8/ChangeLog	2008-01-14 15:44:44 UTC (rev 241)
@@ -1,4 +1,11 @@
 2008-01-14  KUBO Takehiro  <kubo at jiubao.org>
+	* ext/oci8/oci8.h ext/oci8/oci8lib.c: rename variable name
+	    cOCIHandle to oci8_cOCIHandle to use outside of oci8lib.c.
+	* ext/oci8/metadata.c: use oci8_cOCIHandle instead of rb_cObject
+	    to hold a descrbe handle. check parent object's handle type
+	    in oci8_metadata_create().
+
+2008-01-14  KUBO Takehiro  <kubo at jiubao.org>
 	* ext/oci8/apiwrap.c.tmpl: fix a bug on runtime-api check.
 	* ext/oci8/ocidatetime.c, test/test_datetime.rb: use
 	    DateTime.parse('0001-01-01 00:00:00.1') instead of 

Modified: trunk/ruby-oci8/ext/oci8/metadata.c
===================================================================
--- trunk/ruby-oci8/ext/oci8/metadata.c	2008-01-14 05:38:49 UTC (rev 240)
+++ trunk/ruby-oci8/ext/oci8/metadata.c	2008-01-14 15:44:44 UTC (rev 241)
@@ -38,6 +38,8 @@
     VALUE klass;
     VALUE obj;
 
+    Check_Handle(parent, oci8_cOCIHandle, p);
+
     oci_lc(OCIAttrGet(parmhp, OCI_DTYPE_PARAM, &ptype, &size, OCI_ATTR_PTYPE, oci8_errhp));
     klass = rb_hash_aref(ptype_to_class, INT2FIX(ptype));
     if (NIL_P(klass))
@@ -51,7 +53,6 @@
     md->base.hp.prm = parmhp;
     md->svc = svc;
 
-    p = DATA_PTR(parent);
     if (p->type == OCI_HTYPE_STMT) {
         md->is_implicit = 1;
     } else {
@@ -261,39 +262,30 @@
     return md->is_implicit ? Qtrue : Qfalse;
 }
 
-static void oci8_desc_free(OCIDescribe *dschp)
-{
-    if (dschp != NULL)
-        OCIHandleFree(dschp, OCI_HTYPE_DESCRIBE);
-}
-
 static VALUE oci8_do_describe(VALUE self, void *objptr, ub4 objlen, ub1 objtype, VALUE klass, VALUE check_public)
 {
     oci8_svcctx_t *svcctx = DATA_PTR(self);
-    OCIDescribe *dschp;
     OCIParam *parmhp;
     VALUE type;
-    sword rv;
-    VALUE desc;
+    VALUE obj;
+    oci8_base_t *desc;
 
+    /* make a describe handle object */
+    obj = rb_obj_alloc(oci8_cOCIHandle);
+    desc = DATA_PTR(obj);
+    oci_lc(OCIHandleAlloc(oci8_envhp, (dvoid *)&desc->hp.dschp, OCI_HTYPE_DESCRIBE, 0, 0));
+    desc->type = OCI_HTYPE_DESCRIBE;
+
     type = rb_hash_aref(class_to_ptype, klass);
-    oci_lc(OCIHandleAlloc(oci8_envhp, (dvoid *)&dschp, OCI_HTYPE_DESCRIBE, 0, 0));
-    /* dschp is freed when GC runs. */
-    desc = Data_Wrap_Struct(rb_cObject, NULL, oci8_desc_free, dschp);
     if (RTEST(check_public)) {
         sb4 val = -1;
         /* size of OCI_ATTR_DESC_PUBLIC is undocumented. */
-        oci_lc(OCIAttrSet(dschp, OCI_HTYPE_DESCRIBE, &val, 0, OCI_ATTR_DESC_PUBLIC, oci8_errhp));
+        oci_lc(OCIAttrSet(desc->hp.dschp, OCI_HTYPE_DESCRIBE, &val, 0, OCI_ATTR_DESC_PUBLIC, oci8_errhp));
     }
-    rv = OCIDescribeAny_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, objptr, objlen,
-                           objtype, OCI_DEFAULT, FIX2INT(type), dschp);
-    if (rv != OCI_SUCCESS) {
-        OCIHandleFree(dschp, OCI_HTYPE_DESCRIBE);
-        DATA_PTR(desc) = NULL;
-        oci8_raise(oci8_errhp, rv, NULL);
-    }
-    oci_lc(OCIAttrGet(dschp, OCI_HTYPE_DESCRIBE, &parmhp, 0, OCI_ATTR_PARAM, oci8_errhp));
-    return oci8_metadata_create(parmhp, self, desc);
+    oci_lc(OCIDescribeAny_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, objptr, objlen,
+                             objtype, OCI_DEFAULT, FIX2INT(type), desc->hp.dschp));
+    oci_lc(OCIAttrGet(desc->hp.dschp, OCI_HTYPE_DESCRIBE, &parmhp, 0, OCI_ATTR_PARAM, oci8_errhp));
+    return oci8_metadata_create(parmhp, self, obj);
 }
 
 static VALUE oci8_describe(VALUE self, VALUE name, VALUE klass, VALUE check_public)

Modified: trunk/ruby-oci8/ext/oci8/oci8.h
===================================================================
--- trunk/ruby-oci8/ext/oci8/oci8.h	2008-01-14 05:38:49 UTC (rev 240)
+++ trunk/ruby-oci8/ext/oci8/oci8.h	2008-01-14 15:44:44 UTC (rev 241)
@@ -144,6 +144,7 @@
         OCIParam *prm;
         OCILobLocator *lob;
         OCIType *tdo;
+        OCIDescribe *dschp;
     } hp;
     VALUE self;
     oci8_base_class_t *klass;
@@ -234,6 +235,7 @@
 extern ID oci8_id_set;
 extern ID oci8_id_keys;
 extern int oci8_in_finalizer;
+extern VALUE oci8_cOCIHandle;
 void oci8_base_free(oci8_base_t *base);
 VALUE oci8_define_class(const char *name, oci8_base_class_t *klass);
 VALUE oci8_define_class_under(VALUE outer, const char *name, oci8_base_class_t *klass);

Modified: trunk/ruby-oci8/ext/oci8/oci8lib.c
===================================================================
--- trunk/ruby-oci8/ext/oci8/oci8lib.c	2008-01-14 05:38:49 UTC (rev 240)
+++ trunk/ruby-oci8/ext/oci8/oci8lib.c	2008-01-14 15:44:44 UTC (rev 241)
@@ -26,9 +26,10 @@
 ID oci8_id_set;
 ID oci8_id_keys;
 int oci8_in_finalizer = 0;
+VALUE oci8_cOCIHandle;
+
 static ID id_oci8_class;
 
-static VALUE cOCIHandle;
 static VALUE mOCI8BindType;
 static VALUE cOCI8BindTypeBase;
 
@@ -111,6 +112,7 @@
 Init_oci8lib()
 {
     VALUE cOCI8;
+    VALUE obj;
 
 #ifdef RUNTIME_API_CHECK
     Init_oci8_apiwrap();
@@ -127,17 +129,19 @@
     Init_oci8_env();
 
     /* OCIHandle class */
-    cOCIHandle = rb_define_class("OCIHandle", rb_cObject);
-    rb_define_alloc_func(cOCIHandle, oci8_s_allocate);
-    rb_define_method(cOCIHandle, "initialize", oci8_handle_initialize, 0);
-    rb_define_method(cOCIHandle, "free", oci8_handle_free, 0);
+    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);
 
     /* OCI8 class */
     cOCI8 = Init_oci8();
     /* OCI8::BindType module */
     mOCI8BindType = rb_define_module_under(cOCI8, "BindType");
     /* OCI8::BindType::Base class */
-    cOCI8BindTypeBase = rb_define_class_under(mOCI8BindType, "Base", cOCIHandle);
+    cOCI8BindTypeBase = rb_define_class_under(mOCI8BindType, "Base", oci8_cOCIHandle);
 
     /* Handle */
     Init_oci8_bind(cOCI8BindTypeBase);
@@ -161,7 +165,7 @@
 
 VALUE oci8_define_class(const char *name, oci8_base_class_t *base_class)
 {
-    VALUE klass = rb_define_class(name, cOCIHandle);
+    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);
     return klass;
@@ -169,7 +173,7 @@
 
 VALUE oci8_define_class_under(VALUE outer, const char *name, oci8_base_class_t *base_class)
 {
-    VALUE klass = rb_define_class_under(outer, name, cOCIHandle);
+    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);
     return klass;




More information about the ruby-oci8-commit mailing list