[前][次][番号順一覧][スレッド一覧]

ruby-changes:35712

From: nobu <ko1@a...>
Date: Sun, 5 Oct 2014 08:33:06 +0900 (JST)
Subject: [ruby-changes:35712] nobu:r47794 (trunk): dbm: typed data

nobu	2014-10-05 08:33:01 +0900 (Sun, 05 Oct 2014)

  New Revision: 47794

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47794

  Log:
    dbm: typed data
    
    * ext/dbm/dbm.c (dbm_type): turn into typed data.

  Modified files:
    trunk/ext/dbm/dbm.c
    trunk/ext/dbm/extconf.rb
Index: ext/dbm/dbm.c
===================================================================
--- ext/dbm/dbm.c	(revision 47793)
+++ ext/dbm/dbm.c	(revision 47794)
@@ -46,7 +46,7 @@ closed_dbm(void) https://github.com/ruby/ruby/blob/trunk/ext/dbm/dbm.c#L46
 }
 
 #define GetDBM(obj, dbmp) do {\
-    Data_Get_Struct((obj), struct dbmdata, (dbmp));\
+    TypedData_Get_Struct((obj), struct dbmdata, &dbm_type, (dbmp));\
     if ((dbmp) == 0) closed_dbm();\
     if ((dbmp)->di_dbm == 0) closed_dbm();\
 } while (0)
@@ -57,14 +57,34 @@ closed_dbm(void) https://github.com/ruby/ruby/blob/trunk/ext/dbm/dbm.c#L57
 } while (0)
 
 static void
-free_dbm(struct dbmdata *dbmp)
+free_dbm(void *ptr)
 {
+    struct dbmdata *dbmp = ptr;
     if (dbmp) {
 	if (dbmp->di_dbm) dbm_close(dbmp->di_dbm);
 	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 += DBM_SIZEOF_DBM;
+    }
+    return size;
+}
+
+static const rb_data_type_t dbm_type = {
+    "dbm",
+    {0, free_dbm, memsize_dbm,},
+    NULL, NULL,
+    RUBY_TYPED_FREE_IMMEDIATELY,
+};
+
 /*
  * call-seq:
  *   dbm.close
@@ -94,7 +114,7 @@ fdbm_closed(VALUE obj) https://github.com/ruby/ruby/blob/trunk/ext/dbm/dbm.c#L114
 {
     struct dbmdata *dbmp;
 
-    Data_Get_Struct(obj, struct dbmdata, dbmp);
+    TypedData_Get_Struct(obj, struct dbmdata, &dbm_type, dbmp);
     if (dbmp == 0)
 	return Qtrue;
     if (dbmp->di_dbm == 0)
@@ -106,7 +126,7 @@ fdbm_closed(VALUE obj) https://github.com/ruby/ruby/blob/trunk/ext/dbm/dbm.c#L126
 static VALUE
 fdbm_alloc(VALUE klass)
 {
-    return Data_Wrap_Struct(klass, 0, free_dbm, 0);
+    return TypedData_Wrap_Struct(klass, &dbm_type, 0);
 }
 
 /*
@@ -228,7 +248,7 @@ fdbm_initialize(int argc, VALUE *argv, V https://github.com/ruby/ruby/blob/trunk/ext/dbm/dbm.c#L248
 static VALUE
 fdbm_s_open(int argc, VALUE *argv, VALUE klass)
 {
-    VALUE obj = Data_Wrap_Struct(klass, 0, free_dbm, 0);
+    VALUE obj = fdbm_alloc(klass);
 
     if (NIL_P(fdbm_initialize(argc, argv, obj))) {
 	return Qnil;
Index: ext/dbm/extconf.rb
===================================================================
--- ext/dbm/extconf.rb	(revision 47793)
+++ ext/dbm/extconf.rb	(revision 47794)
@@ -267,6 +267,23 @@ if dblib.any? {|db| headers.fetch(db, [" https://github.com/ruby/ruby/blob/trunk/ext/dbm/extconf.rb#L267
   have_func("dbm_pagfno((DBM *)0)", headers.found, headers.defs)
   have_func("dbm_dirfno((DBM *)0)", headers.found, headers.defs)
   convertible_int("datum.dsize", headers.found, headers.defs)
+  checking_for("sizeof(DBM) is available") {
+    if try_compile(<<SRC)
+#ifdef HAVE_CDEFS_H
+# include <cdefs.h>
+#endif
+#ifdef HAVE_SYS_CDEFS_H
+# include <sys/cdefs.h>
+#endif
+#include DBM_HDR
+
+const int sizeof_DBM = (int)sizeof(DBM);
+SRC
+      $defs << '-DDBM_SIZEOF_DBM=sizeof(DBM)'
+    else
+      $defs << '-DDBM_SIZEOF_DBM=0'
+    end
+  }
   create_makefile("dbm")
 end
 # :startdoc:

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]