Skip to content

Commit

Permalink
Make all remaining T_DATA objects GC.compact friendly
Browse files Browse the repository at this point in the history
  • Loading branch information
larskanis committed Aug 9, 2020
1 parent a817bff commit c5dcadc
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 22 deletions.
30 changes: 22 additions & 8 deletions ext/pg_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,27 @@ static const char *pg_cstr_enc(VALUE str, int enc_idx){
static void
pgconn_gc_mark( t_pg_connection *this )
{
rb_gc_mark( this->socket_io );
rb_gc_mark( this->notice_receiver );
rb_gc_mark( this->notice_processor );
rb_gc_mark( this->type_map_for_queries );
rb_gc_mark( this->type_map_for_results );
rb_gc_mark( this->trace_stream );
rb_gc_mark( this->encoder_for_put_copy_data );
rb_gc_mark( this->decoder_for_get_copy_data );
rb_gc_mark_movable( this->socket_io );
rb_gc_mark_movable( this->notice_receiver );
rb_gc_mark_movable( this->notice_processor );
rb_gc_mark_movable( this->type_map_for_queries );
rb_gc_mark_movable( this->type_map_for_results );
rb_gc_mark_movable( this->trace_stream );
rb_gc_mark_movable( this->encoder_for_put_copy_data );
rb_gc_mark_movable( this->decoder_for_get_copy_data );
}

static void
pgconn_gc_compact( t_pg_connection *this )
{
pg_gc_location( this->socket_io );
pg_gc_location( this->notice_receiver );
pg_gc_location( this->notice_processor );
pg_gc_location( this->type_map_for_queries );
pg_gc_location( this->type_map_for_results );
pg_gc_location( this->trace_stream );
pg_gc_location( this->encoder_for_put_copy_data );
pg_gc_location( this->decoder_for_get_copy_data );
}


Expand All @@ -181,6 +194,7 @@ static const rb_data_type_t pg_connection_type = {
(void (*)(void*))pgconn_gc_mark,
(void (*)(void*))pgconn_gc_free,
(size_t (*)(const void *))NULL,
pg_compact_callback(pgconn_gc_compact),
},
0,
0,
Expand Down
26 changes: 21 additions & 5 deletions ext/pg_result.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,28 @@ pgresult_gc_mark( t_pg_result *this )
{
int i;

rb_gc_mark( this->connection );
rb_gc_mark( this->typemap );
rb_gc_mark( this->tuple_hash );
rb_gc_mark( this->field_map );
rb_gc_mark_movable( this->connection );
rb_gc_mark_movable( this->typemap );
rb_gc_mark_movable( this->tuple_hash );
rb_gc_mark_movable( this->field_map );

for( i=0; i < this->nfields; i++ ){
rb_gc_mark( this->fnames[i] );
rb_gc_mark_movable( this->fnames[i] );
}
}

static void
pgresult_gc_compact( t_pg_result *this )
{
int i;

pg_gc_location( this->connection );
pg_gc_location( this->typemap );
pg_gc_location( this->tuple_hash );
pg_gc_location( this->field_map );

for( i=0; i < this->nfields; i++ ){
pg_gc_location( this->fnames[i] );
}
}

Expand Down Expand Up @@ -160,6 +175,7 @@ static const rb_data_type_t pgresult_type = {
(void (*)(void*))pgresult_gc_mark,
(void (*)(void*))pgresult_gc_free,
(size_t (*)(const void *))pgresult_memsize,
pg_compact_callback(pgresult_gc_compact),
},
0, 0,
#ifdef RUBY_TYPED_FREE_IMMEDIATELY
Expand Down
42 changes: 33 additions & 9 deletions ext/pg_tuple.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,30 +52,53 @@ typedef struct {
VALUE values[0];
} t_pg_tuple;

static inline VALUE
pg_tuple_get_field_names( t_pg_tuple *this )
static inline VALUE *
pg_tuple_get_field_names_ptr( t_pg_tuple *this )
{
if( this->num_fields != (int)RHASH_SIZE(this->field_map) ){
return this->values[this->num_fields];
return &this->values[this->num_fields];
} else {
return Qfalse;
static VALUE f = Qfalse;
return &f;
}
}

static inline VALUE
pg_tuple_get_field_names( t_pg_tuple *this )
{
return *pg_tuple_get_field_names_ptr(this);
}

static void
pg_tuple_gc_mark( t_pg_tuple *this )
{
int i;

if( !this ) return;
rb_gc_mark( this->result );
rb_gc_mark( this->typemap );
rb_gc_mark( this->field_map );
rb_gc_mark_movable( this->result );
rb_gc_mark_movable( this->typemap );
rb_gc_mark_movable( this->field_map );

for( i = 0; i < this->num_fields; i++ ){
rb_gc_mark_movable( this->values[i] );
}
rb_gc_mark_movable( pg_tuple_get_field_names(this) );
}

static void
pg_tuple_gc_compact( t_pg_tuple *this )
{
int i;

if( !this ) return;
pg_gc_location( this->result );
pg_gc_location( this->typemap );
pg_gc_location( this->field_map );

for( i = 0; i < this->num_fields; i++ ){
rb_gc_mark( this->values[i] );
pg_gc_location( this->values[i] );
}
rb_gc_mark( pg_tuple_get_field_names(this) );
pg_gc_location( *pg_tuple_get_field_names_ptr(this) );
}

static void
Expand All @@ -98,6 +121,7 @@ static const rb_data_type_t pg_tuple_type = {
(void (*)(void*))pg_tuple_gc_mark,
(void (*)(void*))pg_tuple_gc_free,
(size_t (*)(const void *))pg_tuple_memsize,
pg_compact_callback(pg_tuple_gc_compact),
},
0, 0,
#ifdef RUBY_TYPED_FREE_IMMEDIATELY
Expand Down

0 comments on commit c5dcadc

Please sign in to comment.