Skip to content

Commit 7dbd82d

Browse files
committed
Cleaning up more warnings.
* Use LONG_LONG functions for sqlite3_int64 because long may be 32bit. The maccro LONG_LONG is platform independent long long int. LONG_LONG is not always exist but sqlite3.h uses related items, so I assumed LONG_LONG exist and it is 64bit or larger. * Add Bignum cases. On platforms whose long is 32bit, a bignum can be included in sqlite3_int64.
1 parent 217f6dc commit 7dbd82d

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

ext/sqlite3/database.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,14 +241,14 @@ static VALUE last_insert_row_id(VALUE self)
241241
Data_Get_Struct(self, sqlite3Ruby, ctx);
242242
REQUIRE_OPEN_DB(ctx);
243243

244-
return LONG2NUM(sqlite3_last_insert_rowid(ctx->db));
244+
return LL2NUM(sqlite3_last_insert_rowid(ctx->db));
245245
}
246246

247247
static VALUE sqlite3val2rb(sqlite3_value * val)
248248
{
249249
switch(sqlite3_value_type(val)) {
250250
case SQLITE_INTEGER:
251-
return LONG2NUM(sqlite3_value_int64(val));
251+
return LL2NUM(sqlite3_value_int64(val));
252252
break;
253253
case SQLITE_FLOAT:
254254
return rb_float_new(sqlite3_value_double(val));
@@ -274,8 +274,15 @@ static void set_sqlite3_func_result(sqlite3_context * ctx, VALUE result)
274274
sqlite3_result_null(ctx);
275275
break;
276276
case T_FIXNUM:
277-
sqlite3_result_int64(ctx, NUM2LONG(result));
277+
sqlite3_result_int64(ctx, FIX2LONG(result));
278278
break;
279+
case T_BIGNUM:
280+
#if SIZEOF_LONG < 8
281+
if (RBIGNUM_LEN(result) * SIZEOF_BDIGITS <= 8) {
282+
sqlite3_result_int64(ctx, NUM2LL(result));
283+
break;
284+
}
285+
#endif
279286
case T_FLOAT:
280287
sqlite3_result_double(ctx, NUM2DBL(result));
281288
break;

ext/sqlite3/statement.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,11 @@ static VALUE step(VALUE self)
108108
{
109109
sqlite3StmtRubyPtr ctx;
110110
sqlite3_stmt *stmt;
111-
int value, length, enc_index;
111+
int value, length;
112112
VALUE list;
113+
#ifdef HAVE_RUBY_ENCODING_H
114+
int enc_index;
115+
#endif
113116

114117
Data_Get_Struct(self, sqlite3StmtRuby, ctx);
115118

@@ -138,7 +141,7 @@ static VALUE step(VALUE self)
138141
for(i = 0; i < length; i++) {
139142
switch(sqlite3_column_type(stmt, i)) {
140143
case SQLITE_INTEGER:
141-
rb_ary_push(list, LONG2NUM(sqlite3_column_int64(stmt, i)));
144+
rb_ary_push(list, LL2NUM(sqlite3_column_int64(stmt, i)));
142145
break;
143146
case SQLITE_FLOAT:
144147
rb_ary_push(list, rb_float_new(sqlite3_column_double(stmt, i)));
@@ -249,14 +252,17 @@ static VALUE bind_param(VALUE self, VALUE key, VALUE value)
249252
}
250253
break;
251254
case T_BIGNUM:
255+
#if SIZEOF_LONG < 8
256+
if (RBIGNUM_LEN(result) * SIZEOF_BDIGITS <= 8) {
257+
sqlite3_result_int64(ctx, NUM2LL(result));
258+
break;
259+
}
260+
#endif
252261
case T_FLOAT:
253262
status = sqlite3_bind_double(ctx->st, index, NUM2DBL(value));
254263
break;
255264
case T_FIXNUM:
256-
{
257-
long v = NUM2LONG(value);
258-
status = sqlite3_bind_int64(ctx->st, index, v);
259-
}
265+
status = sqlite3_bind_int64(ctx->st, index, FIX2LONG(value));
260266
break;
261267
case T_NIL:
262268
status = sqlite3_bind_null(ctx->st, index);

0 commit comments

Comments
 (0)