From e912c167d23a7ec07f7ccbfc674532ff7714dd34 Mon Sep 17 00:00:00 2001 From: nobu Date: Mon, 29 Sep 2014 00:49:12 +0000 Subject: date_core.c: typed data * ext/date/date_core.c (d_lite_type): turn into typed data. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47732 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/date/date_core.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) (limited to 'ext') diff --git a/ext/date/date_core.c b/ext/date/date_core.c index 7ed21db5fc..690c335f32 100644 --- a/ext/date/date_core.c +++ b/ext/date/date_core.c @@ -286,20 +286,20 @@ union DateData { #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, VALUE y) } 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, 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, 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); -- cgit v1.2.3