summaryrefslogtreecommitdiffstats
path: root/transcode.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-09-09 03:56:58 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-09-09 03:56:58 +0000
commitb1cd8f1ab0dd155e8d69e31705eaad99c6b0ba8d (patch)
treee9b7ac576404e0e9f3f7955729e8cb47ec89dcfb /transcode.c
parent0d9e7815cec62b03c6563c66d4963640d80f208f (diff)
downloadruby-b1cd8f1ab0dd155e8d69e31705eaad99c6b0ba8d.tar.gz
ruby-b1cd8f1ab0dd155e8d69e31705eaad99c6b0ba8d.tar.xz
ruby-b1cd8f1ab0dd155e8d69e31705eaad99c6b0ba8d.zip
* transcode.c (econv_data_type): typed.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@24810 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'transcode.c')
-rw-r--r--transcode.c35
1 files changed, 22 insertions, 13 deletions
diff --git a/transcode.c b/transcode.c
index 418289392..bc67d3ed0 100644
--- a/transcode.c
+++ b/transcode.c
@@ -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;
}
/*