summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRob Holland <rob@inversepath.com>2008-05-12 09:31:30 +0100
committerRob Holland <rob@inversepath.com>2008-05-12 09:31:30 +0100
commit2198de6b7f2aa6ef6dc135877fc9d179e5739225 (patch)
tree5f999d3d2a308a08a43af6dd5176df81f302c3b0
parentf41134d86c76e8ef37b877df7989d02ec579305a (diff)
downloadthird_party-sqlite3-ruby-2198de6b7f2aa6ef6dc135877fc9d179e5739225.tar.gz
third_party-sqlite3-ruby-2198de6b7f2aa6ef6dc135877fc9d179e5739225.tar.xz
third_party-sqlite3-ruby-2198de6b7f2aa6ef6dc135877fc9d179e5739225.zip
Use int_bind64 on Fixnum values larger than a 32bit C int can take.
-rw-r--r--ext/sqlite3_api/sqlite3_api.i2
-rw-r--r--ext/sqlite3_api/sqlite3_api_wrap.c220
-rw-r--r--lib/sqlite3/statement.rb6
3 files changed, 116 insertions, 112 deletions
diff --git a/ext/sqlite3_api/sqlite3_api.i b/ext/sqlite3_api/sqlite3_api.i
index 91ccea2..0cf74f4 100644
--- a/ext/sqlite3_api/sqlite3_api.i
+++ b/ext/sqlite3_api/sqlite3_api.i
@@ -236,7 +236,7 @@ typedef void VALBLOB;
}
%typemap(in) sqlite_int64 {
- $1 = rb_big2ll( $input );
+ $1 = rb_num2ll( $input );
}
%typemap(in) (sqlite3_context*,int data_size) {
diff --git a/ext/sqlite3_api/sqlite3_api_wrap.c b/ext/sqlite3_api/sqlite3_api_wrap.c
index f900e4b..ae78b77 100644
--- a/ext/sqlite3_api/sqlite3_api_wrap.c
+++ b/ext/sqlite3_api/sqlite3_api_wrap.c
@@ -617,121 +617,121 @@ SWIG_UnpackDataName(const char *c, void *ptr, size_t sz, const char *name) {
}
#endif
-/***********************************************************************
- * rubytracking.swg
- *
- * This file contains support for tracking mappings from
- * Ruby objects to C++ objects. This functionality is needed
- * to implement mark functions for Ruby's mark and sweep
- * garbage collector.
- ************************************************************************/
-
-/* Global Ruby hash table to store Trackings from C/C++
- structs to Ruby Objects. */
-static VALUE swig_ruby_trackings;
-
-/* Setup a Ruby hash table to store Trackings */
-static void SWIG_RubyInitializeTrackings() {
- /* Create a ruby hash table to store Trackings from C++
- objects to Ruby objects. Also make sure to tell
- the garabage collector about the hash table. */
- swig_ruby_trackings = rb_hash_new();
- rb_gc_register_address(&swig_ruby_trackings);
-}
-
-/* Get a Ruby number to reference a pointer */
-static VALUE SWIG_RubyPtrToReference(void* ptr) {
- /* We cast the pointer to an unsigned long
- and then store a reference to it using
- a Ruby number object. */
-
- /* Convert the pointer to a Ruby number */
- unsigned long value = (unsigned long) ptr;
- return LONG2NUM(value);
-}
-
-/* Get a Ruby number to reference an object */
-static VALUE SWIG_RubyObjectToReference(VALUE object) {
- /* We cast the object to an unsigned long
- and then store a reference to it using
- a Ruby number object. */
-
- /* Convert the Object to a Ruby number */
- unsigned long value = (unsigned long) object;
- return LONG2NUM(value);
-}
-
-/* Get a Ruby object from a previously stored reference */
-static VALUE SWIG_RubyReferenceToObject(VALUE reference) {
- /* The provided Ruby number object is a reference
- to the Ruby object we want.*/
-
- /* First convert the Ruby number to a C number */
- unsigned long value = NUM2LONG(reference);
- return (VALUE) value;
-}
-
-/* Add a Tracking from a C/C++ struct to a Ruby object */
-static void SWIG_RubyAddTracking(void* ptr, VALUE object) {
- /* In a Ruby hash table we store the pointer and
- the associated Ruby object. The trick here is
- that we cannot store the Ruby object directly - if
- we do then it cannot be garbage collected. So
- instead we typecast it as a unsigned long and
- convert it to a Ruby number object.*/
-
- /* Get a reference to the pointer as a Ruby number */
- VALUE key = SWIG_RubyPtrToReference(ptr);
-
- /* Get a reference to the Ruby object as a Ruby number */
- VALUE value = SWIG_RubyObjectToReference(object);
-
- /* Store the mapping to the global hash table. */
- rb_hash_aset(swig_ruby_trackings, key, value);
-}
-
-/* Get the Ruby object that owns the specified C/C++ struct */
-static VALUE SWIG_RubyInstanceFor(void* ptr) {
- /* Get a reference to the pointer as a Ruby number */
- VALUE key = SWIG_RubyPtrToReference(ptr);
-
- /* Now lookup the value stored in the global hash table */
- VALUE value = rb_hash_aref(swig_ruby_trackings, key);
-
- if (value == Qnil) {
- /* No object exists - return nil. */
- return Qnil;
- }
- else {
- /* Convert this value to Ruby object */
- return SWIG_RubyReferenceToObject(value);
- }
-}
-
-/* Remove a Tracking from a C/C++ struct to a Ruby object */
-static void SWIG_RubyRemoveTracking(void* ptr) {
- /* Get a reference to the pointer as a Ruby number */
- VALUE key = SWIG_RubyPtrToReference(ptr);
+/***********************************************************************
+ * rubytracking.swg
+ *
+ * This file contains support for tracking mappings from
+ * Ruby objects to C++ objects. This functionality is needed
+ * to implement mark functions for Ruby's mark and sweep
+ * garbage collector.
+ ************************************************************************/
+
+/* Global Ruby hash table to store Trackings from C/C++
+ structs to Ruby Objects. */
+static VALUE swig_ruby_trackings;
+
+/* Setup a Ruby hash table to store Trackings */
+static void SWIG_RubyInitializeTrackings() {
+ /* Create a ruby hash table to store Trackings from C++
+ objects to Ruby objects. Also make sure to tell
+ the garabage collector about the hash table. */
+ swig_ruby_trackings = rb_hash_new();
+ rb_gc_register_address(&swig_ruby_trackings);
+}
+
+/* Get a Ruby number to reference a pointer */
+static VALUE SWIG_RubyPtrToReference(void* ptr) {
+ /* We cast the pointer to an unsigned long
+ and then store a reference to it using
+ a Ruby number object. */
+
+ /* Convert the pointer to a Ruby number */
+ unsigned long value = (unsigned long) ptr;
+ return LONG2NUM(value);
+}
+
+/* Get a Ruby number to reference an object */
+static VALUE SWIG_RubyObjectToReference(VALUE object) {
+ /* We cast the object to an unsigned long
+ and then store a reference to it using
+ a Ruby number object. */
+
+ /* Convert the Object to a Ruby number */
+ unsigned long value = (unsigned long) object;
+ return LONG2NUM(value);
+}
+
+/* Get a Ruby object from a previously stored reference */
+static VALUE SWIG_RubyReferenceToObject(VALUE reference) {
+ /* The provided Ruby number object is a reference
+ to the Ruby object we want.*/
+
+ /* First convert the Ruby number to a C number */
+ unsigned long value = NUM2LONG(reference);
+ return (VALUE) value;
+}
+
+/* Add a Tracking from a C/C++ struct to a Ruby object */
+static void SWIG_RubyAddTracking(void* ptr, VALUE object) {
+ /* In a Ruby hash table we store the pointer and
+ the associated Ruby object. The trick here is
+ that we cannot store the Ruby object directly - if
+ we do then it cannot be garbage collected. So
+ instead we typecast it as a unsigned long and
+ convert it to a Ruby number object.*/
+
+ /* Get a reference to the pointer as a Ruby number */
+ VALUE key = SWIG_RubyPtrToReference(ptr);
+
+ /* Get a reference to the Ruby object as a Ruby number */
+ VALUE value = SWIG_RubyObjectToReference(object);
+
+ /* Store the mapping to the global hash table. */
+ rb_hash_aset(swig_ruby_trackings, key, value);
+}
+
+/* Get the Ruby object that owns the specified C/C++ struct */
+static VALUE SWIG_RubyInstanceFor(void* ptr) {
+ /* Get a reference to the pointer as a Ruby number */
+ VALUE key = SWIG_RubyPtrToReference(ptr);
+
+ /* Now lookup the value stored in the global hash table */
+ VALUE value = rb_hash_aref(swig_ruby_trackings, key);
+
+ if (value == Qnil) {
+ /* No object exists - return nil. */
+ return Qnil;
+ }
+ else {
+ /* Convert this value to Ruby object */
+ return SWIG_RubyReferenceToObject(value);
+ }
+}
+
+/* Remove a Tracking from a C/C++ struct to a Ruby object */
+static void SWIG_RubyRemoveTracking(void* ptr) {
+ /* Get a reference to the pointer as a Ruby number */
+ VALUE key = SWIG_RubyPtrToReference(ptr);
/* Define delete method - in C++ this could be marked as
static but unfortunately not in C. */
- VALUE delete_function = rb_intern("delete");
+ VALUE delete_function = rb_intern("delete");
/* Delete the object from the hash table by calling Ruby's
do this we need to call the Hash.delete method.*/
rb_funcall(swig_ruby_trackings, delete_function, 1, key);
-}
-
-/* This is a helper method that unlinks a Ruby object from its
- underlying C++ object. This is needed if the lifetime of the
- Ruby object is longer than the C++ object */
-static void SWIG_RubyUnlinkObjects(void* ptr) {
- VALUE object = SWIG_RubyInstanceFor(ptr);
-
- if (object != Qnil) {
- DATA_PTR(object) = 0;
- }
-}
+}
+
+/* This is a helper method that unlinks a Ruby object from its
+ underlying C++ object. This is needed if the lifetime of the
+ Ruby object is longer than the C++ object */
+static void SWIG_RubyUnlinkObjects(void* ptr) {
+ VALUE object = SWIG_RubyInstanceFor(ptr);
+
+ if (object != Qnil) {
+ DATA_PTR(object) = 0;
+ }
+}
/* Common SWIG API */
#define SWIG_ConvertPtr(obj, pp, type, flags) \
@@ -1762,7 +1762,7 @@ _wrap_sqlite3_bind_int64(int argc, VALUE *argv, VALUE self) {
SWIG_ConvertPtr(argv[0], (void **) &arg1, SWIGTYPE_p_sqlite3_stmt, 0);
arg2 = NUM2INT(argv[1]);
{
- arg3 = rb_big2ll( argv[2] );
+ arg3 = rb_num2ll( argv[2] );
}
result = (int)sqlite3_bind_int64(arg1,arg2,arg3);
@@ -2614,7 +2614,7 @@ _wrap_sqlite3_result_int64(int argc, VALUE *argv, VALUE self) {
rb_raise(rb_eArgError, "wrong # of arguments(%d for 2)",argc);
SWIG_ConvertPtr(argv[0], (void **) &arg1, SWIGTYPE_p_sqlite3_context, 0);
{
- arg2 = rb_big2ll( argv[1] );
+ arg2 = rb_num2ll( argv[1] );
}
sqlite3_result_int64(arg1,arg2);
diff --git a/lib/sqlite3/statement.rb b/lib/sqlite3/statement.rb
index a78cc11..eeca6a2 100644
--- a/lib/sqlite3/statement.rb
+++ b/lib/sqlite3/statement.rb
@@ -90,7 +90,11 @@ module SQLite3
when Bignum then
@driver.bind_int64( @handle, param, value )
when Integer then
- @driver.bind_int( @handle, param, value )
+ if value >= (2 ** 31)
+ @driver.bind_int64( @handle, param, value )
+ else
+ @driver.bind_int( @handle, param, value )
+ end
when Numeric then
@driver.bind_double( @handle, param, value.to_f )
when Blob then