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

ruby-changes:13063

From: nobu <ko1@a...>
Date: Wed, 9 Sep 2009 12:57:13 +0900 (JST)
Subject: [ruby-changes:13063] Ruby:r24810 (trunk): * transcode.c (econv_data_type): typed.

nobu	2009-09-09 12:56:58 +0900 (Wed, 09 Sep 2009)

  New Revision: 24810

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

  Log:
    * transcode.c (econv_data_type): typed.

  Modified files:
    trunk/ChangeLog
    trunk/transcode.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 24809)
+++ ChangeLog	(revision 24810)
@@ -1,4 +1,4 @@
-Wed Sep  9 12:43:47 2009  Nobuyoshi Nakada  <nobu@r...>
+Wed Sep  9 12:56:56 2009  Nobuyoshi Nakada  <nobu@r...>
 
 	* dir.c (dir_data_type): typed.
 
@@ -14,6 +14,8 @@
 
 	* time.c (time_data_type): typed.
 
+	* transcode.c (econv_data_type): typed.
+
 Wed Sep  9 11:11:33 2009  Nobuyoshi Nakada  <nobu@r...>
 
 	* include/ruby/ruby.h (rb_data_type_struct): constified dsize.
Index: transcode.c
===================================================================
--- transcode.c	(revision 24809)
+++ transcode.c	(revision 24810)
@@ -2738,15 +2738,27 @@
 }
 
 static void
-econv_free(rb_econv_t *ec)
+econv_free(void *ptr)
 {
+    rb_econv_t *ec = ptr;
     rb_econv_close(ec);
 }
 
+static size_t
+econv_memsize(const void *ptr)
+{
+    return ptr ? sizeof(rb_econv_t) : 0;
+}
+
+static const rb_data_type_t econv_data_type = {
+    "econv",
+    NULL, econv_free, econv_memsize,
+};
+
 static VALUE
 econv_s_allocate(VALUE klass)
 {
-    return Data_Wrap_Struct(klass, NULL, econv_free, NULL);
+    return TypedData_Wrap_Struct(klass, &econv_data_type, NULL);
 }
 
 static rb_encoding *
@@ -3189,7 +3201,7 @@
     int ecflags;
     VALUE convpath;
 
-    if (DATA_PTR(self)) {
+    if (rb_check_typeddata(self, &econv_data_type)) {
         rb_raise(rb_eTypeError, "already initialized");
     }
 
@@ -3236,8 +3248,9 @@
 econv_inspect(VALUE self)
 {
     const char *cname = rb_obj_classname(self);
-    rb_econv_t *ec = DATA_PTR(self);
+    rb_econv_t *ec;
 
+    TypedData_Get_Struct(self, rb_econv_t, &econv_data_type, ec);
     if (!ec)
         return rb_sprintf("#<%s: uninitialized>", cname);
     else {
@@ -3251,20 +3264,16 @@
     }
 }
 
-#define IS_ECONV(obj) (RDATA(obj)->dfree == (RUBY_DATA_FUNC)econv_free)
-
 static rb_econv_t *
 check_econv(VALUE self)
 {
-    Check_Type(self, T_DATA);
-    if (!IS_ECONV(self)) {
-        rb_raise(rb_eTypeError, "wrong argument type %s (expected Encoding::Converter)",
-                 rb_class2name(CLASS_OF(self)));
-    }
-    if (!DATA_PTR(self)) {
+    rb_econv_t *ec;
+
+    TypedData_Get_Struct(self, rb_econv_t, &econv_data_type, ec);
+    if (!ec) {
         rb_raise(rb_eTypeError, "uninitialized encoding converter");
     }
-    return DATA_PTR(self);
+    return ec;
 }
 
 /*

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

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