[ruby-oci8-commit] [403] branches/ruby-oci8-2.0: * ext/oci8/bind.c: fix a bug that a string is bound to RAW.
nobody at rubyforge.org
nobody at rubyforge.org
Sat Aug 14 08:37:21 EDT 2010
Revision: 403
Author: kubo
Date: 2010-08-14 08:37:20 -0400 (Sat, 14 Aug 2010)
Log Message:
-----------
* ext/oci8/bind.c: fix a bug that a string is bound to RAW.
Its encoding had been convertd to OCI.encoding incorrectly.
(backport from the trunk)
* ext/oci8/stmt.c: fix SEGV when an exception is raised while
a bind value is deallocated.
(backport from the trunk)
Modified Paths:
--------------
branches/ruby-oci8-2.0/ChangeLog
branches/ruby-oci8-2.0/ext/oci8/bind.c
branches/ruby-oci8-2.0/ext/oci8/stmt.c
Modified: branches/ruby-oci8-2.0/ChangeLog
===================================================================
--- branches/ruby-oci8-2.0/ChangeLog 2010-08-14 09:32:00 UTC (rev 402)
+++ branches/ruby-oci8-2.0/ChangeLog 2010-08-14 12:37:20 UTC (rev 403)
@@ -1,3 +1,11 @@
+2010-08-14 KUBO Takehiro <kubo at jiubao.org>
+ * ext/oci8/bind.c: fix a bug that a string is bound to RAW.
+ Its encoding had been convertd to OCI.encoding incorrectly.
+ (backport from the trunk)
+ * ext/oci8/stmt.c: fix SEGV when an exception is raised while
+ a bind value is deallocated.
+ (backport from the trunk)
+
2010-04-23 KUBO Takehiro <kubo at jiubao.org>
* ext/oci8/oranumber_util.c, test/test_oranumber.rb:
add limitted support for OraNumber's positive and negative
Modified: branches/ruby-oci8-2.0/ext/oci8/bind.c
===================================================================
--- branches/ruby-oci8-2.0/ext/oci8/bind.c 2010-08-14 09:32:00 UTC (rev 402)
+++ branches/ruby-oci8-2.0/ext/oci8/bind.c 2010-08-14 12:37:20 UTC (rev 403)
@@ -79,6 +79,18 @@
return rb_str_new(vstr->buf, vstr->size);
}
+static void bind_raw_set(oci8_bind_t *obind, void *data, void **null_structp, VALUE val)
+{
+ oci8_vstr_t *vstr = (oci8_vstr_t *)data;
+
+ StringValue(val);
+ if (RSTRING_LEN(val) > obind->value_sz - sizeof(vstr->size)) {
+ rb_raise(rb_eArgError, "too long String to set. (%ld for %d)", RSTRING_LEN(val), obind->value_sz - (sb4)sizeof(vstr->size));
+ }
+ memcpy(vstr->buf, RSTRING_PTR(val), RSTRING_LEN(val));
+ vstr->size = RSTRING_LEN(val);
+}
+
static const oci8_bind_class_t bind_raw_class = {
{
NULL,
@@ -86,7 +98,7 @@
sizeof(oci8_bind_t)
},
bind_raw_get,
- bind_string_set,
+ bind_raw_set,
bind_string_init,
NULL,
NULL,
Modified: branches/ruby-oci8-2.0/ext/oci8/stmt.c
===================================================================
--- branches/ruby-oci8-2.0/ext/oci8/stmt.c 2010-08-14 09:32:00 UTC (rev 402)
+++ branches/ruby-oci8-2.0/ext/oci8/stmt.c 2010-08-14 12:37:20 UTC (rev 403)
@@ -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,6 +117,10 @@
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));
}
@@ -135,8 +139,6 @@
oci_lc(OCIAttrSet(obind->base.hp.ptr, OCI_HTYPE_DEFINE, (void*)&bind_class->csfrm, 0, OCI_ATTR_CHARSET_FORM, oci8_errhp));
}
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;
}
@@ -197,6 +199,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));
}
@@ -213,8 +219,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;
}
More information about the ruby-oci8-commit
mailing list