ext/swift.cc in swift-0.6.1 vs ext/swift.cc in swift-0.7.0
- old
+ new
@@ -5,14 +5,10 @@
VALUE eSwiftError;
VALUE eSwiftArgumentError;
VALUE eSwiftRuntimeError;
VALUE eSwiftConnectionError;
-VALUE rb_special_constant(VALUE self, VALUE obj) {
- return rb_special_const_p(obj) ? Qtrue : Qfalse;
-}
-
VALUE swift_init(VALUE self, VALUE path) {
try { dbi::dbiInitialize(CSTRING(path)); } CATCH_DBI_EXCEPTIONS();
return Qtrue;
}
@@ -33,26 +29,42 @@
dbi::trace(flag == Qtrue ? true : false, fd);
return flag;
}
+VALUE atexit_gc(...) {
+ rb_gc();
+ return Qnil;
+}
+
+void atexit_caller(VALUE data) {
+ rb_proc_call(data, rb_ary_new());
+}
+
extern "C" {
void Init_swift(void) {
mSwift = rb_define_module("Swift");
eSwiftError = rb_define_class("SwiftError", CONST_GET(rb_mKernel, "StandardError"));
eSwiftArgumentError = rb_define_class("SwiftArgumentError", eSwiftError);
eSwiftRuntimeError = rb_define_class("SwiftRuntimeError", eSwiftError);
eSwiftConnectionError = rb_define_class("SwiftConnectionError", eSwiftError);
init_swift_adapter();
+ init_swift_attribute();
+ init_swift_pool();
+ init_swift_request();
init_swift_result();
init_swift_statement();
- init_swift_request();
- init_swift_pool();
+ init_swift_query();
rb_define_module_function(mSwift, "init", RUBY_METHOD_FUNC(swift_init), 1);
rb_define_module_function(mSwift, "trace", RUBY_METHOD_FUNC(swift_trace), -1);
- rb_define_module_function(mSwift, "special_constant?", RUBY_METHOD_FUNC(rb_special_constant), 1);
+
+ // NOTE
+ // Swift adapter and statement objects need to be deallocated or garbage collected in the reverse
+ // allocation order. rb_gc() does that but gc at exit time seems to do it in allocation order which
+ // stuffs up dbic++ destructors.
+ rb_set_end_proc(atexit_caller, rb_proc_new(atexit_gc, mSwift));
}
}