12
12
13
13
VALUE cSqlite3Database ;
14
14
15
+ static void
16
+ database_mark (void * ctx )
17
+ {
18
+ sqlite3RubyPtr c = (sqlite3RubyPtr )ctx ;
19
+ rb_gc_mark (c -> busy_handler );
20
+ }
21
+
15
22
static void
16
23
deallocate (void * ctx )
17
24
{
@@ -31,15 +38,13 @@ database_memsize(const void *ctx)
31
38
}
32
39
33
40
static const rb_data_type_t database_type = {
34
- "SQLite3::Backup" ,
35
- {
36
- NULL ,
37
- deallocate ,
38
- database_memsize ,
41
+ . wrap_struct_name = "SQLite3::Backup" ,
42
+ . function = {
43
+ . dmark = database_mark ,
44
+ . dfree = deallocate ,
45
+ . dsize = database_memsize ,
39
46
},
40
- 0 ,
41
- 0 ,
42
- RUBY_TYPED_WB_PROTECTED , // Not freed immediately because the dfree function do IOs.
47
+ .flags = RUBY_TYPED_WB_PROTECTED , // Not freed immediately because the dfree function do IOs.
43
48
};
44
49
45
50
static VALUE
@@ -202,10 +207,11 @@ trace(int argc, VALUE *argv, VALUE self)
202
207
}
203
208
204
209
static int
205
- rb_sqlite3_busy_handler (void * ctx , int count )
210
+ rb_sqlite3_busy_handler (void * context , int count )
206
211
{
207
- VALUE self = (VALUE )(ctx );
208
- VALUE handle = rb_iv_get (self , "@busy_handler" );
212
+ sqlite3RubyPtr ctx = (sqlite3RubyPtr )context ;
213
+
214
+ VALUE handle = ctx -> busy_handler ;
209
215
VALUE result = rb_funcall (handle , rb_intern ("call" ), 1 , INT2NUM (count ));
210
216
211
217
if (Qfalse == result ) { return 0 ; }
@@ -240,11 +246,13 @@ busy_handler(int argc, VALUE *argv, VALUE self)
240
246
rb_scan_args (argc , argv , "01" , & block );
241
247
242
248
if (NIL_P (block ) && rb_block_given_p ()) { block = rb_block_proc (); }
243
-
244
- rb_iv_set (self , "@busy_handler" , block );
249
+ ctx -> busy_handler = block ;
245
250
246
251
status = sqlite3_busy_handler (
247
- ctx -> db , NIL_P (block ) ? NULL : rb_sqlite3_busy_handler , (void * )self );
252
+ ctx -> db ,
253
+ NIL_P (block ) ? NULL : rb_sqlite3_busy_handler ,
254
+ (void * )ctx
255
+ );
248
256
249
257
CHECK (ctx -> db , status );
250
258
0 commit comments