summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-10-04 23:33:06 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-10-04 23:33:06 +0000
commitab7695fc5080fe0313ec4b62f3abb3156df08e3b (patch)
tree5fc19be891bf90a25762838274caf3ca7737459f /ext
parent20904659c3e8911e222a6d86cdddc114e75ca4d7 (diff)
sdbm: typed data
* ext/sdbm/init.c (sdbm_type): turn into typed data. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47796 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/sdbm/init.c30
1 files changed, 25 insertions, 5 deletions
diff --git a/ext/sdbm/init.c b/ext/sdbm/init.c
index eb9d3c9..821918c 100644
--- a/ext/sdbm/init.c
+++ b/ext/sdbm/init.c
@@ -78,7 +78,7 @@ closed_sdbm(void)
}
#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)
} 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)
{
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)
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, VALUE obj)
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;