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

ruby-changes:13062

From: nobu <ko1@a...>
Date: Wed, 9 Sep 2009 12:44:06 +0900 (JST)
Subject: [ruby-changes:13062] Ruby:r24809 (trunk): * time.c (time_data_type): typed.

nobu	2009-09-09 12:43:48 +0900 (Wed, 09 Sep 2009)

  New Revision: 24809

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

  Log:
    * time.c (time_data_type): typed.

  Modified files:
    trunk/ChangeLog
    trunk/time.c

Index: time.c
===================================================================
--- time.c	(revision 24808)
+++ time.c	(revision 24809)
@@ -1043,8 +1043,10 @@
 };
 
 #define GetTimeval(obj, tobj) \
-    Data_Get_Struct(obj, struct time_object, tobj)
+    TypedData_Get_Struct(obj, struct time_object, &time_data_type, tobj)
 
+#define IsTimeval(obj) rb_typeddata_is_kind_of(obj, &time_data_type)
+
 #define TIME_UTC_P(tobj) ((tobj)->gmt == 1)
 #define TIME_SET_UTC(tobj) ((tobj)->gmt = 1)
 
@@ -1084,13 +1086,24 @@
     if (tobj) xfree(tobj);
 }
 
+static size_t
+time_memsize(const void *tobj)
+{
+    return tobj ? sizeof(struct time_object) : 0;
+}
+
+static const rb_data_type_t time_data_type = {
+    "time",
+    time_mark, time_free, time_memsize,
+};
+
 static VALUE
 time_s_alloc(VALUE klass)
 {
     VALUE obj;
     struct time_object *tobj;
 
-    obj = Data_Make_Struct(klass, struct time_object, time_mark, time_free, tobj);
+    obj = TypedData_Make_Struct(klass, struct time_object, &time_data_type, tobj);
     tobj->tm_got=0;
     tobj->timexv = INT2FIX(0);
 
@@ -1705,7 +1718,7 @@
         timexv = add(rb_time_magnify(time), mulquo(t, INT2FIX(TIME_SCALE), INT2FIX(1000000)));
         t = time_new_timexv(klass, timexv);
     }
-    else if (TYPE(time) == T_DATA && RDATA(time)->dfree == time_free) {
+    else if (IsTimeval(time)) {
 	struct time_object *tobj, *tobj2;
         GetTimeval(time, tobj);
         t = time_new_timexv(klass, tobj->timexv);
@@ -2500,7 +2513,7 @@
     int n;
 
     GetTimeval(time1, tobj1);
-    if (TYPE(time2) == T_DATA && RDATA(time2)->dfree == time_free) {
+    if (IsTimeval(time2)) {
 	GetTimeval(time2, tobj2);
 	n = rb_cmpint(cmp(tobj1->timexv, tobj2->timexv), tobj1->timexv, tobj2->timexv);
     }
@@ -2532,7 +2545,7 @@
     struct time_object *tobj1, *tobj2;
 
     GetTimeval(time1, tobj1);
-    if (TYPE(time2) == T_DATA && RDATA(time2)->dfree == time_free) {
+    if (IsTimeval(time2)) {
 	GetTimeval(time2, tobj2);
         return rb_equal(tobj1->timexv, tobj2->timexv);
     }
@@ -2592,9 +2605,6 @@
 
     if (copy == time) return copy;
     time_modify(copy);
-    if (TYPE(time) != T_DATA || RDATA(time)->dfree != time_free) {
-	rb_raise(rb_eTypeError, "wrong argument type");
-    }
     GetTimeval(time, tobj);
     GetTimeval(copy, tcopy);
     MEMCPY(tcopy, tobj, struct time_object, 1);
@@ -2896,7 +2906,7 @@
     struct time_object *tobj;
     GetTimeval(time1, tobj);
 
-    if (TYPE(time2) == T_DATA && RDATA(time2)->dfree == time_free) {
+    if (IsTimeval(time2)) {
 	rb_raise(rb_eTypeError, "time + time?");
     }
     return time_add(tobj, time2, 1);
@@ -2923,7 +2933,7 @@
     struct time_object *tobj;
 
     GetTimeval(time1, tobj);
-    if (TYPE(time2) == T_DATA && RDATA(time2)->dfree == time_free) {
+    if (IsTimeval(time2)) {
 	struct time_object *tobj2;
 
 	GetTimeval(time2, tobj2);
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 24808)
+++ ChangeLog	(revision 24809)
@@ -1,4 +1,4 @@
-Wed Sep  9 12:21:12 2009  Nobuyoshi Nakada  <nobu@r...>
+Wed Sep  9 12:43:47 2009  Nobuyoshi Nakada  <nobu@r...>
 
 	* dir.c (dir_data_type): typed.
 
@@ -12,6 +12,8 @@
 	* thread.c (thgroup_data_type, mutex_data_type, barrier_data_type):
 	  typed.
 
+	* time.c (time_data_type): typed.
+
 Wed Sep  9 11:11:33 2009  Nobuyoshi Nakada  <nobu@r...>
 
 	* include/ruby/ruby.h (rb_data_type_struct): constified dsize.

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

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