From 0d76affdf905a72a6bcb25530ca13468bc36a0bc Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 27 Oct 2009 13:14:52 +0000 Subject: * ext/stringio/stringio.c (strio_data_type): typed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25516 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/stringio/stringio.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) (limited to 'ext') diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c index a525dff235..ab4a78ce69 100644 --- a/ext/stringio/stringio.c +++ b/ext/stringio/stringio.c @@ -28,15 +28,13 @@ struct StringIO { int count; }; -static void strio_mark _((struct StringIO *)); -static void strio_free _((struct StringIO *)); static void strio_init(int, VALUE *, struct StringIO *); -#define IS_STRIO(obj) (RDATA(obj)->dmark == (RUBY_DATA_FUNC)strio_mark) +#define IS_STRIO(obj) (rb_typeddata_is_kind_of(obj, &strio_data_type)) #define error_inval(msg) (errno = EINVAL, rb_sys_fail(msg)) static struct StringIO * -strio_alloc() +strio_alloc(void) { struct StringIO *ptr = ALLOC(struct StringIO); ptr->string = Qnil; @@ -48,32 +46,40 @@ strio_alloc() } static void -strio_mark(struct StringIO *ptr) +strio_mark(void *p) { + struct StringIO *ptr = p; if (ptr) { rb_gc_mark(ptr->string); } } static void -strio_free(struct StringIO *ptr) +strio_free(void *p) { + struct StringIO *ptr = p; if (--ptr->count <= 0) { xfree(ptr); } } -static struct StringIO* -check_strio(VALUE self) +static size_t +strio_memsize(const void *p) { - Check_Type(self, T_DATA); - if (!IS_STRIO(self)) { - rb_raise(rb_eTypeError, "wrong argument type %s (expected StringIO)", - rb_class2name(CLASS_OF(self))); - } - return DATA_PTR(self); + const struct StringIO *ptr = p; + if (!ptr) return 0; + return sizeof(struct StringIO); } +static const rb_data_type_t strio_data_type = { + "strio", + strio_mark, + strio_free, + strio_memsize, +}; + +#define check_strio(self) ((struct StringIO*)rb_check_typeddata(self, &strio_data_type)) + static struct StringIO* get_strio(VALUE self) { @@ -135,7 +141,7 @@ check_modifiable(struct StringIO *ptr) static VALUE strio_s_allocate(VALUE klass) { - return Data_Wrap_Struct(klass, strio_mark, strio_free, 0); + return TypedData_Wrap_Struct(klass, &strio_data_type, 0); } /* -- cgit v1.2.3