* 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
This commit is contained in:
nobu 2009-10-27 13:14:52 +00:00
parent aacc33649a
commit 0d76affdf9
2 changed files with 25 additions and 15 deletions

View File

@ -1,3 +1,7 @@
Tue Oct 27 22:14:50 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/stringio/stringio.c (strio_data_type): typed.
Tue Oct 27 21:20:35 2009 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp> Tue Oct 27 21:20:35 2009 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tk/variable.rb: add TkVariable#+@ and -@ method. * ext/tk/lib/tk/variable.rb: add TkVariable#+@ and -@ method.

View File

@ -28,15 +28,13 @@ struct StringIO {
int count; int count;
}; };
static void strio_mark _((struct StringIO *));
static void strio_free _((struct StringIO *));
static void strio_init(int, VALUE *, 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)) #define error_inval(msg) (errno = EINVAL, rb_sys_fail(msg))
static struct StringIO * static struct StringIO *
strio_alloc() strio_alloc(void)
{ {
struct StringIO *ptr = ALLOC(struct StringIO); struct StringIO *ptr = ALLOC(struct StringIO);
ptr->string = Qnil; ptr->string = Qnil;
@ -48,32 +46,40 @@ strio_alloc()
} }
static void static void
strio_mark(struct StringIO *ptr) strio_mark(void *p)
{ {
struct StringIO *ptr = p;
if (ptr) { if (ptr) {
rb_gc_mark(ptr->string); rb_gc_mark(ptr->string);
} }
} }
static void static void
strio_free(struct StringIO *ptr) strio_free(void *p)
{ {
struct StringIO *ptr = p;
if (--ptr->count <= 0) { if (--ptr->count <= 0) {
xfree(ptr); xfree(ptr);
} }
} }
static struct StringIO* static size_t
check_strio(VALUE self) strio_memsize(const void *p)
{ {
Check_Type(self, T_DATA); const struct StringIO *ptr = p;
if (!IS_STRIO(self)) { if (!ptr) return 0;
rb_raise(rb_eTypeError, "wrong argument type %s (expected StringIO)", return sizeof(struct StringIO);
rb_class2name(CLASS_OF(self)));
}
return DATA_PTR(self);
} }
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* static struct StringIO*
get_strio(VALUE self) get_strio(VALUE self)
{ {
@ -135,7 +141,7 @@ check_modifiable(struct StringIO *ptr)
static VALUE static VALUE
strio_s_allocate(VALUE klass) strio_s_allocate(VALUE klass)
{ {
return Data_Wrap_Struct(klass, strio_mark, strio_free, 0); return TypedData_Wrap_Struct(klass, &strio_data_type, 0);
} }
/* /*