ruby-changes:73618
From: Aaron <ko1@a...>
Date: Tue, 20 Sep 2022 00:44:44 +0900 (JST)
Subject: [ruby-changes:73618] 26135312f6 (master): [ruby/psych] Convert some of Parser#parse to Ruby
https://git.ruby-lang.org/ruby.git/commit/?id=26135312f6 From 26135312f61014967ef223dd16ad6577ebd9c5d8 Mon Sep 17 00:00:00 2001 From: Aaron Patterson <tenderlove@r...> Date: Thu, 15 Sep 2022 17:48:52 -0700 Subject: [ruby/psych] Convert some of Parser#parse to Ruby This commit just converts some of the parse method to Ruby https://github.com/ruby/psych/commit/bca7d2c549 --- ext/psych/lib/psych/parser.rb | 13 +++++++++++++ ext/psych/psych_parser.c | 22 ++-------------------- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/ext/psych/lib/psych/parser.rb b/ext/psych/lib/psych/parser.rb index 39bc8289be..2181c730e5 100644 --- a/ext/psych/lib/psych/parser.rb +++ b/ext/psych/lib/psych/parser.rb @@ -48,5 +48,18 @@ module Psych https://github.com/ruby/ruby/blob/trunk/ext/psych/lib/psych/parser.rb#L48 @handler = handler @external_encoding = ANY end + + ### + # call-seq: + # parser.parse(yaml) + # + # Parse the YAML document contained in +yaml+. Events will be called on + # the handler set on the parser instance. + # + # See Psych::Parser and Psych::Parser#handler + + def parse yaml, path = yaml.respond_to?(:path) ? yaml.path : "<unknown>" + _native_parse @handler, yaml, path + end end end diff --git a/ext/psych/psych_parser.c b/ext/psych/psych_parser.c index f91475b835..9c5179cc44 100644 --- a/ext/psych/psych_parser.c +++ b/ext/psych/psych_parser.c @@ -245,18 +245,8 @@ static VALUE protected_event_location(VALUE pointer) https://github.com/ruby/ruby/blob/trunk/ext/psych/psych_parser.c#L245 return rb_funcall3(args[0], id_event_location, 4, args + 1); } -/* - * call-seq: - * parser.parse(yaml) - * - * Parse the YAML document contained in +yaml+. Events will be called on - * the handler set on the parser instance. - * - * See Psych::Parser and Psych::Parser#handler - */ -static VALUE parse(int argc, VALUE *argv, VALUE self) +static VALUE parse(VALUE self, VALUE handler, VALUE yaml, VALUE path) { - VALUE yaml, path; yaml_parser_t * parser; yaml_event_t event; int done = 0; @@ -264,14 +254,6 @@ static VALUE parse(int argc, VALUE *argv, VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/psych/psych_parser.c#L254 int parser_encoding = YAML_ANY_ENCODING; int encoding = rb_utf8_encindex(); rb_encoding * internal_enc = rb_default_internal_encoding(); - VALUE handler = rb_iv_get(self, "@handler"); - - if (rb_scan_args(argc, argv, "11", &yaml, &path) == 1) { - if(rb_respond_to(yaml, id_path)) - path = rb_funcall(yaml, id_path, 0); - else - path = rb_str_new2("<unknown>"); - } TypedData_Get_Struct(self, yaml_parser_t, &psych_parser_type, parser); @@ -562,7 +544,7 @@ void Init_psych_parser(void) https://github.com/ruby/ruby/blob/trunk/ext/psych/psych_parser.c#L544 rb_require("psych/syntax_error"); - rb_define_method(cPsychParser, "parse", parse, -1); + rb_define_private_method(cPsychParser, "_native_parse", parse, 3); rb_define_method(cPsychParser, "mark", mark, 0); id_read = rb_intern("read"); -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/