1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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.
@ -14,6 +14,8 @@ Wed Sep 9 12:43:47 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* 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>
* 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
econv_free(rb_econv_t *ec)
econv_free(void *ptr)
{
rb_econv_t *ec = ptr;
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
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 *
@ -3189,7 +3201,7 @@ econv_init(int argc, VALUE *argv, VALUE self)
int ecflags;
VALUE convpath;
if (DATA_PTR(self)) {
if (rb_check_typeddata(self, &econv_data_type)) {
rb_raise(rb_eTypeError, "already initialized");
}
@ -3236,8 +3248,9 @@ static VALUE
econv_inspect(VALUE 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)
return rb_sprintf("#<%s: uninitialized>", cname);
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 *
check_econv(VALUE self)
{
Check_Type(self, T_DATA);
if (!IS_ECONV(self)) {
rb_raise(rb_eTypeError, "wrong argument type %s (expected Encoding::Converter)",
rb_class2name(CLASS_OF(self)));
}
if (!DATA_PTR(self)) {
rb_econv_t *ec;
TypedData_Get_Struct(self, rb_econv_t, &econv_data_type, ec);
if (!ec) {
rb_raise(rb_eTypeError, "uninitialized encoding converter");
}
return DATA_PTR(self);
return ec;
}
/*