mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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
This commit is contained in:
parent
20904659c3
commit
ab7695fc50
1 changed files with 25 additions and 5 deletions
|
@ -78,7 +78,7 @@ closed_sdbm(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
#define GetDBM(obj, dbmp) do {\
|
#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) == 0) closed_sdbm();\
|
||||||
if ((dbmp)->di_dbm == 0) closed_sdbm();\
|
if ((dbmp)->di_dbm == 0) closed_sdbm();\
|
||||||
} while (0)
|
} while (0)
|
||||||
|
@ -89,13 +89,33 @@ closed_sdbm(void)
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
static void
|
static void
|
||||||
free_sdbm(struct dbmdata *dbmp)
|
free_sdbm(void *ptr)
|
||||||
{
|
{
|
||||||
|
struct dbmdata *dbmp = ptr;
|
||||||
|
|
||||||
if (dbmp->di_dbm) sdbm_close(dbmp->di_dbm);
|
if (dbmp->di_dbm) sdbm_close(dbmp->di_dbm);
|
||||||
ruby_xfree(dbmp);
|
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:
|
* call-seq:
|
||||||
* sdbm.close -> nil
|
* sdbm.close -> nil
|
||||||
|
@ -127,7 +147,7 @@ fsdbm_closed(VALUE obj)
|
||||||
{
|
{
|
||||||
struct dbmdata *dbmp;
|
struct dbmdata *dbmp;
|
||||||
|
|
||||||
Data_Get_Struct(obj, struct dbmdata, dbmp);
|
TypedData_Get_Struct(obj, struct dbmdata, &sdbm_type, dbmp);
|
||||||
if (dbmp == 0)
|
if (dbmp == 0)
|
||||||
return Qtrue;
|
return Qtrue;
|
||||||
if (dbmp->di_dbm == 0)
|
if (dbmp->di_dbm == 0)
|
||||||
|
@ -139,7 +159,7 @@ fsdbm_closed(VALUE obj)
|
||||||
static VALUE
|
static VALUE
|
||||||
fsdbm_alloc(VALUE klass)
|
fsdbm_alloc(VALUE klass)
|
||||||
{
|
{
|
||||||
return Data_Wrap_Struct(klass, 0, free_sdbm, 0);
|
return TypedData_Wrap_Struct(klass, &sdbm_type, 0);
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
|
@ -218,7 +238,7 @@ fsdbm_initialize(int argc, VALUE *argv, VALUE obj)
|
||||||
static VALUE
|
static VALUE
|
||||||
fsdbm_s_open(int argc, VALUE *argv, VALUE klass)
|
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))) {
|
if (NIL_P(fsdbm_initialize(argc, argv, obj))) {
|
||||||
return Qnil;
|
return Qnil;
|
||||||
|
|
Loading…
Reference in a new issue