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

ruby-changes:36610

From: nobu <ko1@a...>
Date: Wed, 3 Dec 2014 12:25:09 +0900 (JST)
Subject: [ruby-changes:36610] nobu:r48691 (trunk): tkutil.c: typed data

nobu	2014-12-03 12:25:02 +0900 (Wed, 03 Dec 2014)

  New Revision: 48691

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

  Log:
    tkutil.c: typed data
    
    * ext/tk/tkutil/tkutil.c (cbsubst_info_type): use typed data.

  Modified files:
    trunk/ext/tk/tkutil/tkutil.c
Index: ext/tk/tkutil/tkutil.c
===================================================================
--- ext/tk/tkutil/tkutil.c	(revision 48690)
+++ ext/tk/tkutil/tkutil.c	(revision 48691)
@@ -24,7 +24,7 @@ static int rb_thread_critical; /* dummy https://github.com/ruby/ruby/blob/trunk/ext/tk/tkutil/tkutil.c#L24
 #endif
 
 #undef RUBY_UNTYPED_DATA_WARNING
-#define RUBY_UNTYPED_DATA_WARNING 0
+#define RUBY_UNTYPED_DATA_WARNING 1
 
 #if !defined(RHASH_TBL)
 #define RHASH_TBL(h) (RHASH(h)->tbl)
@@ -1171,6 +1171,23 @@ subst_free(ptr) https://github.com/ruby/ruby/blob/trunk/ext/tk/tkutil/tkutil.c#L1171
     }
 }
 
+static size_t
+subst_memsize(ptr)
+    const struct cbsubst_info *ptr;
+{
+    return sizeof(*ptr);
+}
+
+static const rb_data_type_t cbsubst_info_type = {
+    "TkUtil/CallbackSubst/Info",
+    {
+	subst_mark,
+	subst_free,
+	subst_memsize,
+    },
+    0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
+};
+
 static VALUE
 allocate_cbsubst_info(struct cbsubst_info **inf_ptr)
 {
@@ -1197,7 +1214,7 @@ allocate_cbsubst_info(struct cbsubst_inf https://github.com/ruby/ruby/blob/trunk/ext/tk/tkutil/tkutil.c#L1214
 
   if (inf_ptr != (struct cbsubst_info **)NULL) *inf_ptr = inf;
 
-  return Data_Wrap_Struct(cSUBST_INFO, subst_mark, subst_free, inf);
+  return TypedData_Wrap_Struct(cSUBST_INFO, &cbsubst_info_type, inf);
 }
 
 static void
@@ -1207,6 +1224,13 @@ cbsubst_init(void) https://github.com/ruby/ruby/blob/trunk/ext/tk/tkutil/tkutil.c#L1224
 	       allocate_cbsubst_info((struct cbsubst_info **)NULL));
 }
 
+static struct cbsubst_info *
+cbsubst_get_ptr(klass)
+    VALUE klass;
+{
+    return rb_check_typeddata(rb_const_get(klass, ID_SUBST_INFO), &cbsubst_info_type);
+}
+
 static VALUE
 cbsubst_initialize(argc, argv, self)
     int   argc;
@@ -1216,8 +1240,7 @@ cbsubst_initialize(argc, argv, self) https://github.com/ruby/ruby/blob/trunk/ext/tk/tkutil/tkutil.c#L1240
     struct cbsubst_info *inf;
     int idx, iv_idx;
 
-    Data_Get_Struct(rb_const_get(rb_obj_class(self), ID_SUBST_INFO),
-                    struct cbsubst_info, inf);
+    inf = cbsubst_get_ptr(rb_obj_class(self));
 
    idx = 0;
     for(iv_idx = 0; iv_idx < CBSUBST_TBL_MAX; iv_idx++) {
@@ -1288,8 +1311,7 @@ cbsubst_def_attr_aliases(self, tbl) https://github.com/ruby/ruby/blob/trunk/ext/tk/tkutil/tkutil.c#L1311
         rb_raise(rb_eArgError, "expected a Hash");
     }
 
-    Data_Get_Struct(rb_const_get(self, ID_SUBST_INFO),
-                    struct cbsubst_info, inf);
+    inf = cbsubst_get_ptr(self);
 
     rb_hash_foreach(tbl, each_attr_def, self);
 
@@ -1311,8 +1333,7 @@ cbsubst_sym_to_subst(self, sym) https://github.com/ruby/ruby/blob/trunk/ext/tk/tkutil/tkutil.c#L1333
 
     if (!RB_TYPE_P(sym, T_SYMBOL)) return sym;
 
-    Data_Get_Struct(rb_const_get(self, ID_SUBST_INFO),
-                    struct cbsubst_info, inf);
+    inf = cbsubst_get_ptr(self);
 
     if (!NIL_P(ret = rb_hash_aref(inf->aliases, sym))) {
 	str = rb_sym2str(ret);
@@ -1364,8 +1385,7 @@ cbsubst_get_subst_arg(argc, argv, self) https://github.com/ruby/ruby/blob/trunk/ext/tk/tkutil/tkutil.c#L1385
     ID id;
     volatile VALUE arg_sym, ret;
 
-    Data_Get_Struct(rb_const_get(self, ID_SUBST_INFO),
-                    struct cbsubst_info, inf);
+    inf = cbsubst_get_ptr(self);
 
     ptr = buf = ALLOC_N(char, inf->full_subst_length + 1);
 
@@ -1439,8 +1459,7 @@ cbsubst_get_subst_key(self, str) https://github.com/ruby/ruby/blob/trunk/ext/tk/tkutil/tkutil.c#L1459
     list = rb_funcall(cTclTkLib, ID_split_tklist, 1, str);
     len = RARRAY_LEN(list);
 
-    Data_Get_Struct(rb_const_get(self, ID_SUBST_INFO),
-                    struct cbsubst_info, inf);
+    inf = cbsubst_get_ptr(self);
 
     ptr = buf = ALLOC_N(char, inf->full_subst_length + len + 1);
 
@@ -1488,8 +1507,7 @@ cbsubst_get_all_subst_keys(self) https://github.com/ruby/ruby/blob/trunk/ext/tk/tkutil/tkutil.c#L1507
     long len;
     volatile VALUE ret;
 
-    Data_Get_Struct(rb_const_get(self, ID_SUBST_INFO),
-                    struct cbsubst_info, inf);
+    inf = cbsubst_get_ptr(self);
 
     ptr = buf = ALLOC_N(char, inf->full_subst_length + 1);
     keys_ptr = keys_buf = ALLOC_N(char, CBSUBST_TBL_MAX + 1);
@@ -1661,8 +1679,7 @@ cbsubst_scan_args(self, arg_key, val_ary https://github.com/ruby/ruby/blob/trunk/ext/tk/tkutil/tkutil.c#L1679
 
     old_gc = rb_gc_disable();
 
-    Data_Get_Struct(rb_const_get(self, ID_SUBST_INFO),
-                    struct cbsubst_info, inf);
+    inf = cbsubst_get_ptr(self);
 
     for(idx = 0; idx < vallen; idx++) {
       if (idx >= keylen) {

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

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