* transcode.c (econv_data_type): typed.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24810 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2009-09-09 03:56:58 +00:00
parent 5c0a8e947a
commit 913fdf25bc
2 changed files with 25 additions and 14 deletions

View File

@ -1,4 +1,4 @@
Wed Sep 9 12:43:47 2009 Nobuyoshi Nakada <nobu@ruby-lang.org> Wed Sep 9 12:56:56 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* dir.c (dir_data_type): typed. * dir.c (dir_data_type): typed.
@ -14,6 +14,8 @@ Wed Sep 9 12:43:47 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* time.c (time_data_type): typed. * time.c (time_data_type): typed.
* transcode.c (econv_data_type): typed.
Wed Sep 9 11:11:33 2009 Nobuyoshi Nakada <nobu@ruby-lang.org> Wed Sep 9 11:11:33 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* include/ruby/ruby.h (rb_data_type_struct): constified dsize. * include/ruby/ruby.h (rb_data_type_struct): constified dsize.

View File

@ -2738,15 +2738,27 @@ rb_str_encode(VALUE str, VALUE to, int ecflags, VALUE ecopts)
} }
static void static void
econv_free(rb_econv_t *ec) econv_free(void *ptr)
{ {
rb_econv_t *ec = ptr;
rb_econv_close(ec); rb_econv_close(ec);
} }
static size_t
econv_memsize(const void *ptr)
{
return ptr ? sizeof(rb_econv_t) : 0;
}
static const rb_data_type_t econv_data_type = {
"econv",
NULL, econv_free, econv_memsize,
};
static VALUE static VALUE
econv_s_allocate(VALUE klass) econv_s_allocate(VALUE klass)
{ {
return Data_Wrap_Struct(klass, NULL, econv_free, NULL); return TypedData_Wrap_Struct(klass, &econv_data_type, NULL);
} }
static rb_encoding * static rb_encoding *
@ -3189,7 +3201,7 @@ econv_init(int argc, VALUE *argv, VALUE self)
int ecflags; int ecflags;
VALUE convpath; VALUE convpath;
if (DATA_PTR(self)) { if (rb_check_typeddata(self, &econv_data_type)) {
rb_raise(rb_eTypeError, "already initialized"); rb_raise(rb_eTypeError, "already initialized");
} }
@ -3236,8 +3248,9 @@ static VALUE
econv_inspect(VALUE self) econv_inspect(VALUE self)
{ {
const char *cname = rb_obj_classname(self); const char *cname = rb_obj_classname(self);
rb_econv_t *ec = DATA_PTR(self); rb_econv_t *ec;
TypedData_Get_Struct(self, rb_econv_t, &econv_data_type, ec);
if (!ec) if (!ec)
return rb_sprintf("#<%s: uninitialized>", cname); return rb_sprintf("#<%s: uninitialized>", cname);
else { else {
@ -3251,20 +3264,16 @@ econv_inspect(VALUE self)
} }
} }
#define IS_ECONV(obj) (RDATA(obj)->dfree == (RUBY_DATA_FUNC)econv_free)
static rb_econv_t * static rb_econv_t *
check_econv(VALUE self) check_econv(VALUE self)
{ {
Check_Type(self, T_DATA); rb_econv_t *ec;
if (!IS_ECONV(self)) {
rb_raise(rb_eTypeError, "wrong argument type %s (expected Encoding::Converter)", TypedData_Get_Struct(self, rb_econv_t, &econv_data_type, ec);
rb_class2name(CLASS_OF(self))); if (!ec) {
}
if (!DATA_PTR(self)) {
rb_raise(rb_eTypeError, "uninitialized encoding converter"); rb_raise(rb_eTypeError, "uninitialized encoding converter");
} }
return DATA_PTR(self); return ec;
} }
/* /*