ruby-changes:35713
From: nobu <ko1@a...>
Date: Sun, 5 Oct 2014 08:33:17 +0900 (JST)
Subject: [ruby-changes:35713] nobu:r47796 (trunk): sdbm: typed data
nobu 2014-10-05 08:33:06 +0900 (Sun, 05 Oct 2014) New Revision: 47796 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47796 Log: sdbm: typed data * ext/sdbm/init.c (sdbm_type): turn into typed data. Modified files: trunk/ext/sdbm/init.c Index: ext/sdbm/init.c =================================================================== --- ext/sdbm/init.c (revision 47795) +++ ext/sdbm/init.c (revision 47796) @@ -78,7 +78,7 @@ closed_sdbm(void) https://github.com/ruby/ruby/blob/trunk/ext/sdbm/init.c#L78 } #define GetDBM(obj, dbmp) do {\ - Data_Get_Struct((obj), struct dbmdata, (dbmp));\ + TypedData_Get_Struct((obj), struct dbmdata, &sdbm_type, (dbmp));\ if ((dbmp) == 0) closed_sdbm();\ if ((dbmp)->di_dbm == 0) closed_sdbm();\ } while (0) @@ -89,13 +89,33 @@ closed_sdbm(void) https://github.com/ruby/ruby/blob/trunk/ext/sdbm/init.c#L89 } while (0) static void -free_sdbm(struct dbmdata *dbmp) +free_sdbm(void *ptr) { + struct dbmdata *dbmp = ptr; if (dbmp->di_dbm) sdbm_close(dbmp->di_dbm); ruby_xfree(dbmp); } +static size_t +memsize_dbm(const void *ptr) +{ + size_t size = 0; + const struct dbmdata *dbmp = ptr; + if (dbmp) { + size += sizeof(*dbmp); + if (dbmp->di_dbm) size += sizeof(DBM); + } + return size; +} + +static const rb_data_type_t sdbm_type = { + "sdbm", + {0, free_sdbm, memsize_dbm,}, + NULL, NULL, + RUBY_TYPED_FREE_IMMEDIATELY, +}; + /* * call-seq: * sdbm.close -> nil @@ -127,7 +147,7 @@ fsdbm_closed(VALUE obj) https://github.com/ruby/ruby/blob/trunk/ext/sdbm/init.c#L147 { struct dbmdata *dbmp; - Data_Get_Struct(obj, struct dbmdata, dbmp); + TypedData_Get_Struct(obj, struct dbmdata, &sdbm_type, dbmp); if (dbmp == 0) return Qtrue; if (dbmp->di_dbm == 0) @@ -139,7 +159,7 @@ fsdbm_closed(VALUE obj) https://github.com/ruby/ruby/blob/trunk/ext/sdbm/init.c#L159 static VALUE fsdbm_alloc(VALUE klass) { - return Data_Wrap_Struct(klass, 0, free_sdbm, 0); + return TypedData_Wrap_Struct(klass, &sdbm_type, 0); } /* * call-seq: @@ -218,7 +238,7 @@ fsdbm_initialize(int argc, VALUE *argv, https://github.com/ruby/ruby/blob/trunk/ext/sdbm/init.c#L238 static VALUE fsdbm_s_open(int argc, VALUE *argv, VALUE klass) { - VALUE obj = Data_Wrap_Struct(klass, 0, free_sdbm, 0); + VALUE obj = fsdbm_alloc(klass); if (NIL_P(fsdbm_initialize(argc, argv, obj))) { return Qnil; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/