diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-10-04 23:33:19 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-10-04 23:33:19 +0000 |
commit | acf1ea1ab4e534794cebbfbabf32e7713af377d1 (patch) | |
tree | cca6524aaad652a5983229ec999ffe3ebfae337d /ext/psych/psych_parser.c | |
parent | 163cb5b43de68cef7ae4fa053d710098399d1359 (diff) | |
download | ruby-acf1ea1ab4e534794cebbfbabf32e7713af377d1.tar.gz |
psych: typed data
* ext/psych/psych_emitter.c (psych_emitter_type): turn into typed
data.
* ext/psych/psych_parser.c (psych_parser_type): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47800 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/psych/psych_parser.c')
-rw-r--r-- | ext/psych/psych_parser.c | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/ext/psych/psych_parser.c b/ext/psych/psych_parser.c index 19c7484124..7aad9213c4 100644 --- a/ext/psych/psych_parser.c +++ b/ext/psych/psych_parser.c @@ -49,6 +49,22 @@ static void dealloc(void * ptr) xfree(parser); } +#if 0 +static size_t memsize(const void *ptr) +{ + const yaml_parser_t *parser = ptr; + /* TODO: calculate parser's size */ + return 0; +} +#endif + +static const rb_data_type_t psych_parser_type = { + "Psych/parser", + {0, dealloc, 0,}, + NULL, NULL, + RUBY_TYPED_FREE_IMMEDIATELY, +}; + static VALUE allocate(VALUE klass) { yaml_parser_t * parser; @@ -56,7 +72,7 @@ static VALUE allocate(VALUE klass) parser = xmalloc(sizeof(yaml_parser_t)); yaml_parser_initialize(parser); - return Data_Wrap_Struct(klass, 0, dealloc, parser); + return TypedData_Wrap_Struct(klass, &psych_parser_type, parser); } static VALUE make_exception(yaml_parser_t * parser, VALUE path) @@ -248,7 +264,7 @@ static VALUE parse(int argc, VALUE *argv, VALUE self) path = rb_str_new2("<unknown>"); } - Data_Get_Struct(self, yaml_parser_t, parser); + TypedData_Get_Struct(self, yaml_parser_t, &psych_parser_type, parser); yaml_parser_delete(parser); yaml_parser_initialize(parser); @@ -526,7 +542,7 @@ static VALUE mark(VALUE self) VALUE args[3]; yaml_parser_t * parser; - Data_Get_Struct(self, yaml_parser_t, parser); + TypedData_Get_Struct(self, yaml_parser_t, &psych_parser_type, parser); mark_klass = rb_const_get_at(cPsychParser, rb_intern("Mark")); args[0] = INT2NUM(parser->mark.index); args[1] = INT2NUM(parser->mark.line); |