From 1417d5aa0a6d8c71e929abe0494668b3e58ef0d5 Mon Sep 17 00:00:00 2001 From: Sharon Rosner Date: Sun, 24 Dec 2023 10:42:26 +0100 Subject: [PATCH] Implement write barriers for Database and Query classes --- ext/extralite/database.c | 4 ++-- ext/extralite/query.c | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/ext/extralite/database.c b/ext/extralite/database.c index bc83f4c..21b451d 100644 --- a/ext/extralite/database.c +++ b/ext/extralite/database.c @@ -37,7 +37,7 @@ static void Database_free(void *ptr) { static const rb_data_type_t Database_type = { "Database", {Database_mark, Database_free, Database_size,}, - 0, 0, RUBY_TYPED_FREE_IMMEDIATELY + 0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED }; static VALUE Database_allocate(VALUE klass) { @@ -696,7 +696,7 @@ VALUE Database_total_changes(VALUE self) { VALUE Database_trace(VALUE self) { Database_t *db = self_to_open_database(self); - db->trace_block = rb_block_given_p() ? rb_block_proc() : Qnil; + RB_OBJ_WRITE(self, &db->trace_block, rb_block_given_p() ? rb_block_proc() : Qnil); return self; } diff --git a/ext/extralite/query.c b/ext/extralite/query.c index fec6e7a..a1d0b48 100644 --- a/ext/extralite/query.c +++ b/ext/extralite/query.c @@ -33,7 +33,7 @@ static void Query_free(void *ptr) { static const rb_data_type_t Query_type = { "Query", {Query_mark, Query_free, Query_size,}, - 0, 0, RUBY_TYPED_FREE_IMMEDIATELY + 0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED }; static VALUE Query_allocate(VALUE klass) { @@ -67,10 +67,12 @@ VALUE Query_initialize(VALUE self, VALUE db, VALUE sql) { if (!RSTRING_LEN(sql)) rb_raise(cError, "Cannot prepare an empty SQL query"); + RB_OBJ_WRITE(self, &query->db, db); + RB_OBJ_WRITE(self, &query->sql, sql); + query->db = db; query->db_struct = self_to_database(db); query->sqlite3_db = Database_sqlite3_db(db); - query->sql = sql; query->stmt = NULL; query->closed = 0; query->eof = 0;