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

ruby-changes:35650

From: nobu <ko1@a...>
Date: Mon, 29 Sep 2014 09:49:29 +0900 (JST)
Subject: [ruby-changes:35650] nobu:r47732 (trunk): date_core.c: typed data

nobu	2014-09-29 09:49:12 +0900 (Mon, 29 Sep 2014)

  New Revision: 47732

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

  Log:
    date_core.c: typed data
    
    * ext/date/date_core.c (d_lite_type): turn into typed data.

  Modified files:
    trunk/ext/date/date_core.c
Index: ext/date/date_core.c
===================================================================
--- ext/date/date_core.c	(revision 47731)
+++ ext/date/date_core.c	(revision 47732)
@@ -286,20 +286,20 @@ union DateData { https://github.com/ruby/ruby/blob/trunk/ext/date/date_core.c#L286
 
 #define get_d1(x)\
     union DateData *dat;\
-    Data_Get_Struct(x, union DateData, dat);
+    TypedData_Get_Struct(x, union DateData, &d_lite_type, dat);
 
 #define get_d1a(x)\
     union DateData *adat;\
-    Data_Get_Struct(x, union DateData, adat);
+    TypedData_Get_Struct(x, union DateData, &d_lite_type, adat);
 
 #define get_d1b(x)\
     union DateData *bdat;\
-    Data_Get_Struct(x, union DateData, bdat);
+    TypedData_Get_Struct(x, union DateData, &d_lite_type, bdat);
 
 #define get_d2(x,y)\
     union DateData *adat, *bdat;\
-    Data_Get_Struct(x, union DateData, adat);\
-    Data_Get_Struct(y, union DateData, bdat);
+    TypedData_Get_Struct(x, union DateData, &d_lite_type, adat);\
+    TypedData_Get_Struct(y, union DateData, &d_lite_type, bdat);
 
 inline static VALUE
 canon(VALUE x)
@@ -2922,17 +2922,31 @@ date_s_gregorian_leap_p(VALUE klass, VAL https://github.com/ruby/ruby/blob/trunk/ext/date/date_core.c#L2922
 }
 
 static void
-d_lite_gc_mark(union DateData *dat)
+d_lite_gc_mark(void *ptr)
 {
+    union DateData *dat = ptr;
     if (simple_dat_p(dat))
 	rb_gc_mark(dat->s.nth);
     else {
 	rb_gc_mark(dat->c.nth);
 	rb_gc_mark(dat->c.sf);
-
     }
 }
 
+static size_t
+d_lite_memsize(const void *ptr)
+{
+    const union DateData *dat = ptr;
+    return complex_dat_p(dat) ? sizeof(struct ComplexDateData) : sizeof(struct SimpleDateData);
+}
+
+static const rb_data_type_t d_lite_type = {
+    "Date",
+    {d_lite_gc_mark, RUBY_TYPED_DEFAULT_FREE, d_lite_memsize,},
+    NULL, NULL,
+    RUBY_TYPED_FREE_IMMEDIATELY,
+};
+
 inline static VALUE
 d_simple_new_internal(VALUE klass,
 		      VALUE nth, int jd,
@@ -2943,8 +2957,8 @@ d_simple_new_internal(VALUE klass, https://github.com/ruby/ruby/blob/trunk/ext/date/date_core.c#L2957
     struct SimpleDateData *dat;
     VALUE obj;
 
-    obj = Data_Make_Struct(klass, struct SimpleDateData,
-			   d_lite_gc_mark, -1, dat);
+    obj = TypedData_Make_Struct(klass, struct SimpleDateData,
+				&d_lite_type, dat);
     set_to_simple(dat, nth, jd, sg, y, m, d, flags & ~COMPLEX_DAT);
 
     assert(have_jd_p(dat) || have_civil_p(dat));
@@ -2964,8 +2978,8 @@ d_complex_new_internal(VALUE klass, https://github.com/ruby/ruby/blob/trunk/ext/date/date_core.c#L2978
     struct ComplexDateData *dat;
     VALUE obj;
 
-    obj = Data_Make_Struct(klass, struct ComplexDateData,
-			   d_lite_gc_mark, -1, dat);
+    obj = TypedData_Make_Struct(klass, struct ComplexDateData,
+				&d_lite_type, dat);
     set_to_complex(dat, nth, jd, df, sf, of, sg,
 		   y, m, d, h, min, s, flags | COMPLEX_DAT);
 

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

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