Skip to content

Commit

Permalink
Implement write barriers for Database and Query classes
Browse files Browse the repository at this point in the history
  • Loading branch information
noteflakes committed Dec 24, 2023
1 parent 7801411 commit 1417d5a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions ext/extralite/database.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}

Expand Down
6 changes: 4 additions & 2 deletions ext/extralite/query.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 1417d5a

Please sign in to comment.