ext/duckdb/column.c in duckdb-0.3.4.0 vs ext/duckdb/column.c in duckdb-0.5.0

- old
+ new

@@ -2,36 +2,50 @@ static VALUE cDuckDBColumn; static void deallocate(void *ctx); static VALUE allocate(VALUE klass); +static size_t memsize(const void *p); static VALUE duckdb_column__type(VALUE oDuckDBColumn); static VALUE duckdb_column_get_name(VALUE oDuckDBColumn); +static const rb_data_type_t column_data_type = { + "DuckDB/Column", + {NULL, deallocate, memsize,}, + 0, 0, RUBY_TYPED_FREE_IMMEDIATELY +}; + static void deallocate(void *ctx) { rubyDuckDBColumn *p = (rubyDuckDBColumn *)ctx; xfree(p); } static VALUE allocate(VALUE klass) { rubyDuckDBColumn *ctx = xcalloc((size_t)1, sizeof(rubyDuckDBColumn)); - return Data_Wrap_Struct(klass, NULL, deallocate, ctx); + return TypedData_Wrap_Struct(klass, &column_data_type, ctx); } +static size_t memsize(const void *p) { + return sizeof(rubyDuckDBColumn); +} + /* * */ VALUE duckdb_column__type(VALUE oDuckDBColumn) { rubyDuckDBColumn *ctx; - Data_Get_Struct(oDuckDBColumn, rubyDuckDBColumn, ctx); - - VALUE result = rb_ivar_get(oDuckDBColumn, rb_intern("result")); rubyDuckDBResult *ctxresult; - Data_Get_Struct(result, rubyDuckDBResult, ctxresult); - duckdb_type type = duckdb_column_type(&(ctxresult->result), ctx->col); + VALUE result; + duckdb_type type; + TypedData_Get_Struct(oDuckDBColumn, rubyDuckDBColumn, &column_data_type, ctx); + + result = rb_ivar_get(oDuckDBColumn, rb_intern("result")); + ctxresult = get_struct_result(result); + type = duckdb_column_type(&(ctxresult->result), ctx->col); + return INT2FIX(type); } /* * call-seq: @@ -40,24 +54,27 @@ * Returns the column name. * */ VALUE duckdb_column_get_name(VALUE oDuckDBColumn) { rubyDuckDBColumn *ctx; - Data_Get_Struct(oDuckDBColumn, rubyDuckDBColumn, ctx); - - VALUE result = rb_ivar_get(oDuckDBColumn, rb_intern("result")); + VALUE result; rubyDuckDBResult *ctxresult; - Data_Get_Struct(result, rubyDuckDBResult, ctxresult); - return rb_str_new2(duckdb_column_name(&(ctxresult->result), ctx->col)); + TypedData_Get_Struct(oDuckDBColumn, rubyDuckDBColumn, &column_data_type, ctx); + + result = rb_ivar_get(oDuckDBColumn, rb_intern("result")); + + ctxresult = get_struct_result(result); + + return rb_utf8_str_new_cstr(duckdb_column_name(&(ctxresult->result), ctx->col)); } VALUE create_column(VALUE oDuckDBResult, idx_t col) { VALUE obj; + rubyDuckDBColumn *ctx; obj = allocate(cDuckDBColumn); - rubyDuckDBColumn *ctx; - Data_Get_Struct(obj, rubyDuckDBColumn, ctx); + TypedData_Get_Struct(obj, rubyDuckDBColumn, &column_data_type, ctx); rb_ivar_set(obj, rb_intern("result"), oDuckDBResult); ctx->col = col; return obj;