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

ruby-changes:14381

From: nobu <ko1@a...>
Date: Thu, 31 Dec 2009 06:04:07 +0900 (JST)
Subject: [ruby-changes:14381] Ruby:r26211 (trunk): * ext/socket/raddrinfo.c (addrinfo_type): typed.

nobu	2009-12-31 06:03:51 +0900 (Thu, 31 Dec 2009)

  New Revision: 26211

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

  Log:
    * ext/socket/raddrinfo.c (addrinfo_type): typed.

  Modified files:
    trunk/ChangeLog
    trunk/ext/socket/raddrinfo.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 26210)
+++ ChangeLog	(revision 26211)
@@ -1,5 +1,7 @@
-Thu Dec 31 05:56:38 2009  Nobuyoshi Nakada  <nobu@r...>
+Thu Dec 31 06:03:48 2009  Nobuyoshi Nakada  <nobu@r...>
 
+	* ext/socket/raddrinfo.c (addrinfo_type): typed.
+
 	* ext/socket/extconf.rb: fix for wide-getaddrinfo option.
 
 	* ext/socket/addrinfo.c: rename {addr,name}info functions to ensure
Index: ext/socket/raddrinfo.c
===================================================================
--- ext/socket/raddrinfo.c	(revision 26210)
+++ ext/socket/raddrinfo.c	(revision 26211)
@@ -479,36 +479,39 @@
 } rb_addrinfo_t;
 
 static void
-addrinfo_mark(rb_addrinfo_t *rai)
+addrinfo_mark(void *ptr)
 {
+    rb_addrinfo_t *rai = ptr;
     if (rai) {
         rb_gc_mark(rai->inspectname);
         rb_gc_mark(rai->canonname);
     }
 }
 
-static void
-addrinfo_free(rb_addrinfo_t *rai)
+#define addrinfo_free RUBY_TYPED_DEFAULT_FREE
+
+static size_t
+addrinfo_memsize(const void *ptr)
 {
-    xfree(rai);
+    return ptr ? sizeof(rb_addrinfo_t) : 0;
 }
 
+static const rb_data_type_t addrinfo_type = {
+    "socket/addrinfo",
+    addrinfo_mark, addrinfo_free, addrinfo_memsize,
+};
+
 static VALUE
 addrinfo_s_allocate(VALUE klass)
 {
-    return Data_Wrap_Struct(klass, addrinfo_mark, addrinfo_free, 0);
+    return TypedData_Wrap_Struct(klass, &addrinfo_type, 0);
 }
 
-#define IS_ADDRINFO(obj) (RDATA(obj)->dmark == (RUBY_DATA_FUNC)addrinfo_mark)
-static rb_addrinfo_t *
+#define IS_ADDRINFO(obj) rb_typeddata_is_kind_of(obj, &addrinfo_type)
+static inline rb_addrinfo_t *
 check_addrinfo(VALUE self)
 {
-    Check_Type(self, RUBY_T_DATA);
-    if (!IS_ADDRINFO(self)) {
-        rb_raise(rb_eTypeError, "wrong argument type %s (expected Addrinfo)",
-                 rb_class2name(CLASS_OF(self)));
-    }
-    return DATA_PTR(self);
+    return rb_check_typeddata(self, &addrinfo_type);
 }
 
 static rb_addrinfo_t *
@@ -2040,7 +2043,7 @@
 rsock_sockaddr_string_value(volatile VALUE *v)
 {
     VALUE val = *v;
-    if (TYPE(val) == RUBY_T_DATA && IS_ADDRINFO(val)) {
+    if (IS_ADDRINFO(val)) {
         *v = addrinfo_to_sockaddr(val);
     }
     StringValue(*v);
@@ -2057,7 +2060,7 @@
 VALUE
 rb_check_sockaddr_string_type(VALUE val)
 {
-    if (TYPE(val) == RUBY_T_DATA && IS_ADDRINFO(val))
+    if (IS_ADDRINFO(val))
         return addrinfo_to_sockaddr(val);
     return rb_check_string_type(val);
 }

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

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