From 094c8115882116d631acb982bf512017e0933d32 Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Tue, 19 Sep 2023 09:16:55 -0500 Subject: [PATCH 1/6] Update SnakeYAML Engine to 2.7 --- lib/psych/versions.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/psych/versions.rb b/lib/psych/versions.rb index 57b7659b..840deadf 100644 --- a/lib/psych/versions.rb +++ b/lib/psych/versions.rb @@ -5,6 +5,6 @@ module Psych VERSION = '5.1.0' if RUBY_ENGINE == 'jruby' - DEFAULT_SNAKEYAML_VERSION = '2.6'.freeze + DEFAULT_SNAKEYAML_VERSION = '2.7'.freeze end end From 8caff506336c4ef44ddd6b3cc4eff82356b36096 Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Tue, 19 Sep 2023 09:57:02 -0500 Subject: [PATCH 2/6] Add SnakeYAML exception as cause --- ext/java/org/jruby/ext/psych/PsychParser.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/ext/java/org/jruby/ext/psych/PsychParser.java b/ext/java/org/jruby/ext/psych/PsychParser.java index e29b9e3d..29edffb0 100644 --- a/ext/java/org/jruby/ext/psych/PsychParser.java +++ b/ext/java/org/jruby/ext/psych/PsychParser.java @@ -37,6 +37,7 @@ import org.jruby.RubyBoolean; import org.jruby.RubyClass; import org.jruby.RubyEncoding; +import org.jruby.RubyException; import org.jruby.RubyFixnum; import org.jruby.RubyIO; import org.jruby.RubyKernel; @@ -45,6 +46,7 @@ import org.jruby.RubyObject; import org.jruby.RubyString; import org.jruby.anno.JRubyMethod; +import org.jruby.javasupport.JavaUtil; import org.jruby.runtime.Block; import org.jruby.runtime.Helpers; import org.jruby.runtime.ThreadContext; @@ -408,11 +410,11 @@ private void handleSequenceStart(ThreadContext context, SequenceStartEvent sse, private static void raiseParserException(ThreadContext context, ReaderException re, IRubyObject rbPath) { Ruby runtime = context.runtime; RubyClass se; - IRubyObject exception; + RubyException exception; se = (RubyClass) runtime.getModule("Psych").getConstant("SyntaxError"); - exception = se.newInstance(context, + exception = (RubyException) se.newInstance(context, new IRubyObject[] { rbPath, RubyFixnum.zero(runtime), @@ -423,6 +425,8 @@ private static void raiseParserException(ThreadContext context, ReaderException }, Block.NULL_BLOCK); + exception.setCause(JavaUtil.convertJavaToUsableRubyObject(runtime, re)); + RubyKernel.raise(context, runtime.getKernel(), new IRubyObject[] { exception }, Block.NULL_BLOCK); } @@ -430,13 +434,13 @@ private static void raiseParserException(ThreadContext context, MarkedYamlEngine Ruby runtime = context.runtime; Mark mark; RubyClass se; - IRubyObject exception; + RubyException exception; se = (RubyClass)runtime.getModule("Psych").getConstant("SyntaxError"); mark = mye.getProblemMark().get(); - exception = se.newInstance(context, + exception = (RubyException) se.newInstance(context, new IRubyObject[] { rbPath, runtime.newFixnum(mark.getLine() + 1), @@ -447,19 +451,21 @@ private static void raiseParserException(ThreadContext context, MarkedYamlEngine }, Block.NULL_BLOCK); + exception.setCause(JavaUtil.convertJavaToUsableRubyObject(runtime, mye)); + RubyKernel.raise(context, runtime.getKernel(), new IRubyObject[] { exception }, Block.NULL_BLOCK); } private static void raiseParserException(ThreadContext context, MalformedInputException mie, IRubyObject rbPath) { Ruby runtime = context.runtime; RubyClass se; - IRubyObject exception; + RubyException exception; se = (RubyClass)runtime.getModule("Psych").getConstant("SyntaxError"); mie.getInputLength(); - exception = se.newInstance(context, + exception = (RubyException) se.newInstance(context, arrayOf( rbPath, RubyFixnum.minus_one(runtime), @@ -470,6 +476,8 @@ private static void raiseParserException(ThreadContext context, MalformedInputEx ), Block.NULL_BLOCK); + exception.setCause(JavaUtil.convertJavaToUsableRubyObject(runtime, mie)); + RubyKernel.raise(context, runtime.getKernel(), new IRubyObject[] { exception }, Block.NULL_BLOCK); } From ac6ae9e7842ecbf67d7ebdd45a6c0cbf756b04c5 Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Tue, 19 Sep 2023 10:07:02 -0500 Subject: [PATCH 3/6] Move call sites to a data structure * Reduced size of parser * Reduced init cost of parser * Slightly more indirection --- ext/java/org/jruby/ext/psych/PsychParser.java | 63 +++++++++---------- 1 file changed, 29 insertions(+), 34 deletions(-) diff --git a/ext/java/org/jruby/ext/psych/PsychParser.java b/ext/java/org/jruby/ext/psych/PsychParser.java index 29edffb0..3653ad8a 100644 --- a/ext/java/org/jruby/ext/psych/PsychParser.java +++ b/ext/java/org/jruby/ext/psych/PsychParser.java @@ -103,11 +103,7 @@ public class PsychParser extends RubyObject { public static void initPsychParser(Ruby runtime, RubyModule psych) { RubyClass psychParser = runtime.defineClassUnder("Parser", runtime.getObject(), PsychParser::new, psych); - CachingCallSite[] sites = - Arrays.stream(Call.values()) - .map((call) -> new FunctionalCachingCallSite(call.name())) - .toArray(CachingCallSite[]::new); - psychParser.setInternalVariable(JRUBY_CALL_SITES, sites); + psychParser.setInternalVariable(JRUBY_CALL_SITES, new CallSites()); runtime.getLoadService().require("psych/syntax_error"); psychParser.defineConstant("ANY", runtime.newFixnum(YAML_ANY_ENCODING.ordinal())); @@ -128,19 +124,7 @@ public static void initPsychParser(Ruby runtime, RubyModule psych) { public PsychParser(Ruby runtime, RubyClass klass) { super(runtime, klass); - CachingCallSite[] sites = (CachingCallSite[]) klass.getInternalVariable(JRUBY_CALL_SITES); - this.path = sites[Call.path.ordinal()]; - this.event_location = sites[Call.event_location.ordinal()]; - this.start_stream = sites[Call.start_stream.ordinal()]; - this.start_document = sites[Call.start_document.ordinal()]; - this.end_document = sites[Call.end_document.ordinal()]; - this.alias = sites[Call.alias.ordinal()]; - this.scalar = sites[Call.scalar.ordinal()]; - this.start_sequence = sites[Call.start_sequence.ordinal()]; - this.end_sequence = sites[Call.end_sequence.ordinal()]; - this.start_mapping = sites[Call.start_mapping.ordinal()]; - this.end_mapping = sites[Call.end_mapping.ordinal()]; - this.end_stream = sites[Call.end_stream.ordinal()]; + this.sites = (CallSites) klass.getInternalVariable(JRUBY_CALL_SITES); // prepare settings builder and apply global defaults LoadSettingsBuilder lsb = LoadSettings.builder(); @@ -257,7 +241,7 @@ public IRubyObject parse(ThreadContext context, IRubyObject handler, IRubyObject parser = new ParserImpl(loadSettings, new ScannerImpl(loadSettings, readerFor(context, yaml, loadSettings))); if (path.isNil() && yaml.respondsTo("path")) { - path = this.path.call(context, this, yaml); + path = sites.path.call(context, this, yaml); } while (parser.hasNext()) { @@ -271,11 +255,11 @@ public IRubyObject parse(ThreadContext context, IRubyObject handler, IRubyObject IRubyObject end_line = runtime.newFixnum(end.getLine()); IRubyObject end_column = runtime.newFixnum(end.getColumn()); - event_location.call(context, this, handler, start_line, start_column, end_line, end_column); + sites.event_location.call(context, this, handler, start_line, start_column, end_line, end_column); switch (event.getEventId()) { case StreamStart: - start_stream.call(context, this, handler, runtime.newFixnum(YAML_ANY_ENCODING.ordinal())); + sites.start_stream.call(context, this, handler, runtime.newFixnum(YAML_ANY_ENCODING.ordinal())); break; case DocumentStart: handleDocumentStart(context, (DocumentStartEvent) event, handler); @@ -283,12 +267,12 @@ public IRubyObject parse(ThreadContext context, IRubyObject handler, IRubyObject case DocumentEnd: IRubyObject notExplicit = runtime.newBoolean(!((DocumentEndEvent) event).isExplicit()); - end_document.call(context, this, handler, notExplicit); + sites.end_document.call(context, this, handler, notExplicit); break; case Alias: IRubyObject alias = stringOrNilForAnchor(context, ((AliasEvent) event).getAnchor()); - this.alias.call(context, this, handler, alias); + sites.alias.call(context, this, handler, alias); break; case Scalar: handleScalar(context, (ScalarEvent) event, handler); @@ -297,16 +281,16 @@ public IRubyObject parse(ThreadContext context, IRubyObject handler, IRubyObject handleSequenceStart(context, (SequenceStartEvent) event, handler); break; case SequenceEnd: - end_sequence.call(context, this, handler); + sites.end_sequence.call(context, this, handler); break; case MappingStart: handleMappingStart(context, (MappingStartEvent) event, handler); break; case MappingEnd: - end_mapping.call(context, this, handler); + sites.end_mapping.call(context, this, handler); break; case StreamEnd: - end_stream.call(context, this, handler); + sites.end_stream.call(context, this, handler); break; } } @@ -369,7 +353,7 @@ private void handleDocumentStart(ThreadContext context, DocumentStartEvent dse, IRubyObject notExplicit = runtime.newBoolean(!dse.isExplicit()); - start_document.call(context, this, handler, version, tags, notExplicit); + sites.start_document.call(context, this, handler, version, tags, notExplicit); } private void handleMappingStart(ThreadContext context, MappingStartEvent mse, IRubyObject handler) { @@ -379,7 +363,7 @@ private void handleMappingStart(ThreadContext context, MappingStartEvent mse, IR IRubyObject implicit = runtime.newBoolean(mse.isImplicit()); IRubyObject style = runtime.newFixnum(translateFlowStyle(mse.getFlowStyle())); - start_mapping.call(context, this, handler, anchor, tag, implicit, style); + sites.start_mapping.call(context, this, handler, anchor, tag, implicit, style); } private void handleScalar(ThreadContext context, ScalarEvent se, IRubyObject handler) { @@ -393,7 +377,7 @@ private void handleScalar(ThreadContext context, ScalarEvent se, IRubyObject han IRubyObject style = runtime.newFixnum(translateStyle(se.getScalarStyle())); IRubyObject val = stringFor(context, se.getValue()); - scalar.call(context, this, handler, val, anchor, tag, plain_implicit, + sites.scalar.call(context, this, handler, val, anchor, tag, plain_implicit, quoted_implicit, style); } @@ -404,7 +388,7 @@ private void handleSequenceStart(ThreadContext context, SequenceStartEvent sse, IRubyObject implicit = runtime.newBoolean(sse.isImplicit()); IRubyObject style = runtime.newFixnum(translateFlowStyle(sse.getFlowStyle())); - start_sequence.call(context, this, handler, anchor, tag, implicit, style); + sites.start_sequence.call(context, this, handler, anchor, tag, implicit, style); } private static void raiseParserException(ThreadContext context, ReaderException re, IRubyObject rbPath) { @@ -656,10 +640,21 @@ private LoadSettings buildSettings() { private Parser parser; private Event event; private final LoadSettingsBuilder loadSettingsBuilder; - - private enum Call { - path, event_location, start_stream, start_document, end_document, alias, scalar, start_sequence, end_sequence, start_mapping, end_mapping, end_stream + private final CallSites sites; + + private static class CallSites { + private final CachingCallSite path = new FunctionalCachingCallSite("path"); + private final CachingCallSite event_location = new FunctionalCachingCallSite("event_location"); + private final CachingCallSite start_stream = new FunctionalCachingCallSite("start_stream"); + private final CachingCallSite start_document = new FunctionalCachingCallSite("start_document"); + private final CachingCallSite end_document = new FunctionalCachingCallSite("end_document"); + private final CachingCallSite alias = new FunctionalCachingCallSite("alias"); + private final CachingCallSite scalar = new FunctionalCachingCallSite("scalar"); + private final CachingCallSite start_sequence = new FunctionalCachingCallSite("start_sequence"); + private final CachingCallSite end_sequence = new FunctionalCachingCallSite("end_sequence"); + private final CachingCallSite start_mapping = new FunctionalCachingCallSite("start_mapping"); + private final CachingCallSite end_mapping = new FunctionalCachingCallSite("end_mapping"); + private final CachingCallSite end_stream = new FunctionalCachingCallSite("end_stream"); } - private final CachingCallSite path, event_location, start_stream, start_document, end_document, alias, scalar, start_sequence, end_sequence, start_mapping, end_mapping, end_stream; } From 1c7dd96fe2d87460447cda4f94581bfaa0ecd1cc Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Tue, 19 Sep 2023 10:16:42 -0500 Subject: [PATCH 4/6] Move some bare strings into constants --- ext/java/org/jruby/ext/psych/PsychParser.java | 64 +++++++++++-------- 1 file changed, 36 insertions(+), 28 deletions(-) diff --git a/ext/java/org/jruby/ext/psych/PsychParser.java b/ext/java/org/jruby/ext/psych/PsychParser.java index 3653ad8a..ebaee4c6 100644 --- a/ext/java/org/jruby/ext/psych/PsychParser.java +++ b/ext/java/org/jruby/ext/psych/PsychParser.java @@ -99,6 +99,14 @@ public class PsychParser extends RubyObject { public static final String JRUBY_CALL_SITES = "_jruby_call_sites"; + public static final String ENCODING_ANY = "ANY"; + public static final String ENCODING_UTF8 = "UTF8"; + public static final String ENCODING_UTF16LE = "UTF16LE"; + public static final String ENCODING_UTF16BE = "UTF16BE"; + public static final String MAX_ALIASES_FOR_COLLECTIONS = "max_aliases_for_collections"; + public static final String ALLOW_DUPLICATE_KEYS = "allow_duplicate_keys"; + public static final String ALLOW_RECURSIVE_KEYS = "allow_recursive_keys"; + public static final String CODE_POINT_LIMIT = "code_point_limit"; public static void initPsychParser(Ruby runtime, RubyModule psych) { RubyClass psychParser = runtime.defineClassUnder("Parser", runtime.getObject(), PsychParser::new, psych); @@ -106,19 +114,19 @@ public static void initPsychParser(Ruby runtime, RubyModule psych) { psychParser.setInternalVariable(JRUBY_CALL_SITES, new CallSites()); runtime.getLoadService().require("psych/syntax_error"); - psychParser.defineConstant("ANY", runtime.newFixnum(YAML_ANY_ENCODING.ordinal())); - psychParser.defineConstant("UTF8", runtime.newFixnum(YAML_UTF8_ENCODING.ordinal())); - psychParser.defineConstant("UTF16LE", runtime.newFixnum(YAML_UTF16LE_ENCODING.ordinal())); - psychParser.defineConstant("UTF16BE", runtime.newFixnum(YAML_UTF16BE_ENCODING.ordinal())); + psychParser.defineConstant(ENCODING_ANY, runtime.newFixnum(YAML_ANY_ENCODING.ordinal())); + psychParser.defineConstant(ENCODING_UTF8, runtime.newFixnum(YAML_UTF8_ENCODING.ordinal())); + psychParser.defineConstant(ENCODING_UTF16LE, runtime.newFixnum(YAML_UTF16LE_ENCODING.ordinal())); + psychParser.defineConstant(ENCODING_UTF16BE, runtime.newFixnum(YAML_UTF16BE_ENCODING.ordinal())); psychParser.defineAnnotatedMethods(PsychParser.class); // defaults for SnakeYAML load settings LoadSettings defaults = LoadSettings.builder().build(); - psychParser.setInternalVariable("max_aliases_for_collections", runtime.newFixnum(defaults.getMaxAliasesForCollections())); - psychParser.setInternalVariable("allow_duplicate_keys", runtime.newBoolean(defaults.getAllowDuplicateKeys())); - psychParser.setInternalVariable("allow_recursive_keys", runtime.newBoolean(defaults.getAllowRecursiveKeys())); - psychParser.setInternalVariable("code_point_limit", runtime.newFixnum(defaults.getCodePointLimit())); + psychParser.setInternalVariable(MAX_ALIASES_FOR_COLLECTIONS, runtime.newFixnum(defaults.getMaxAliasesForCollections())); + psychParser.setInternalVariable(ALLOW_DUPLICATE_KEYS, runtime.newBoolean(defaults.getAllowDuplicateKeys())); + psychParser.setInternalVariable(ALLOW_RECURSIVE_KEYS, runtime.newBoolean(defaults.getAllowRecursiveKeys())); + psychParser.setInternalVariable(CODE_POINT_LIMIT, runtime.newFixnum(defaults.getCodePointLimit())); } public PsychParser(Ruby runtime, RubyClass klass) { @@ -129,10 +137,10 @@ public PsychParser(Ruby runtime, RubyClass klass) { // prepare settings builder and apply global defaults LoadSettingsBuilder lsb = LoadSettings.builder(); lsb.setSchema(new CoreSchema()); - lsb.setMaxAliasesForCollections(((IRubyObject) klass.getInternalVariable("max_aliases_for_collections")).convertToInteger().getIntValue()); - lsb.setAllowDuplicateKeys(((IRubyObject) klass.getInternalVariable("allow_duplicate_keys")).isTrue()); - lsb.setAllowRecursiveKeys(((IRubyObject) klass.getInternalVariable("allow_recursive_keys")).isTrue()); - lsb.setCodePointLimit(((IRubyObject) klass.getInternalVariable("code_point_limit")).convertToInteger().getIntValue()); + lsb.setMaxAliasesForCollections(((IRubyObject) klass.getInternalVariable(MAX_ALIASES_FOR_COLLECTIONS)).convertToInteger().getIntValue()); + lsb.setAllowDuplicateKeys(((IRubyObject) klass.getInternalVariable(ALLOW_DUPLICATE_KEYS)).isTrue()); + lsb.setAllowRecursiveKeys(((IRubyObject) klass.getInternalVariable(ALLOW_RECURSIVE_KEYS)).isTrue()); + lsb.setCodePointLimit(((IRubyObject) klass.getInternalVariable(CODE_POINT_LIMIT)).convertToInteger().getIntValue()); this.loadSettingsBuilder = lsb; } @@ -530,7 +538,7 @@ public IRubyObject max_aliases_for_collections_set(IRubyObject max) { return max; } - @JRubyMethod(name = "max_aliases_for_collections") + @JRubyMethod(name = MAX_ALIASES_FOR_COLLECTIONS) public IRubyObject max_aliases_for_collections(ThreadContext context) { return context.runtime.newFixnum(buildSettings().getMaxAliasesForCollections()); } @@ -542,7 +550,7 @@ public IRubyObject allow_duplicate_keys_set(IRubyObject allow) { return allow; } - @JRubyMethod(name = "allow_duplicate_keys") + @JRubyMethod(name = ALLOW_DUPLICATE_KEYS) public IRubyObject allow_duplicate_keys(ThreadContext context) { return RubyBoolean.newBoolean(context, buildSettings().getAllowDuplicateKeys()); } @@ -554,7 +562,7 @@ public IRubyObject allow_recursive_keys_set(IRubyObject allow) { return allow; } - @JRubyMethod(name = "allow_recursive_keys") + @JRubyMethod(name = ALLOW_RECURSIVE_KEYS) public IRubyObject allow_recursive_keys(ThreadContext context) { return RubyBoolean.newBoolean(context, buildSettings().getAllowRecursiveKeys()); } @@ -566,7 +574,7 @@ public IRubyObject code_point_limit_set(IRubyObject limit) { return limit; } - @JRubyMethod(name = "code_point_limit") + @JRubyMethod(name = CODE_POINT_LIMIT) public IRubyObject code_point_limit(ThreadContext context) { return context.runtime.newFixnum(buildSettings().getCodePointLimit()); } @@ -581,38 +589,38 @@ public static IRubyObject max_aliases_for_collections_set(ThreadContext context, throw context.runtime.newRangeError("max_aliases_for_collections must be positive"); } - self.getInternalVariables().setInternalVariable("max_aliases_for_collections", max); + self.getInternalVariables().setInternalVariable(MAX_ALIASES_FOR_COLLECTIONS, max); return max; } - @JRubyMethod(name = "max_aliases_for_collections") + @JRubyMethod(name = MAX_ALIASES_FOR_COLLECTIONS) public static IRubyObject max_aliases_for_collections(ThreadContext context, IRubyObject self) { - return (IRubyObject) self.getInternalVariables().getInternalVariable("max_aliases_for_collections"); + return (IRubyObject) self.getInternalVariables().getInternalVariable(MAX_ALIASES_FOR_COLLECTIONS); } @JRubyMethod(name = "allow_duplicate_keys=", meta = true) public static IRubyObject allow_duplicate_keys_set(IRubyObject self, IRubyObject allow) { - self.getInternalVariables().setInternalVariable("allow_duplicate_keys", allow); + self.getInternalVariables().setInternalVariable(ALLOW_DUPLICATE_KEYS, allow); return allow; } - @JRubyMethod(name = "allow_duplicate_keys", meta = true) + @JRubyMethod(name = ALLOW_DUPLICATE_KEYS, meta = true) public static IRubyObject allow_duplicate_keys(ThreadContext context, IRubyObject self) { - return (IRubyObject) self.getInternalVariables().getInternalVariable("allow_duplicate_keys"); + return (IRubyObject) self.getInternalVariables().getInternalVariable(ALLOW_DUPLICATE_KEYS); } @JRubyMethod(name = "allow_recursive_keys=", meta = true) public static IRubyObject allow_recursive_keys_set(IRubyObject self, IRubyObject allow) { - self.getInternalVariables().setInternalVariable("allow_recursive_keys", allow); + self.getInternalVariables().setInternalVariable(ALLOW_RECURSIVE_KEYS, allow); return allow; } - @JRubyMethod(name = "allow_recursive_keys", meta = true) + @JRubyMethod(name = ALLOW_RECURSIVE_KEYS, meta = true) public static IRubyObject allow_recursive_keys(ThreadContext context, IRubyObject self) { - return (IRubyObject) self.getInternalVariables().getInternalVariable("allow_recursive_keys"); + return (IRubyObject) self.getInternalVariables().getInternalVariable(ALLOW_RECURSIVE_KEYS); } @JRubyMethod(name = "code_point_limit=", meta = true) @@ -623,14 +631,14 @@ public static IRubyObject code_point_limit_set(ThreadContext context, IRubyObjec throw context.runtime.newRangeError("code_point_limit must be positive"); } - self.getInternalVariables().setInternalVariable("code_point_limit", limit); + self.getInternalVariables().setInternalVariable(CODE_POINT_LIMIT, limit); return limit; } - @JRubyMethod(name = "code_point_limit", meta = true) + @JRubyMethod(name = CODE_POINT_LIMIT, meta = true) public static IRubyObject code_point_limit(ThreadContext context, IRubyObject self) { - return (IRubyObject) self.getInternalVariables().getInternalVariable("code_point_limit"); + return (IRubyObject) self.getInternalVariables().getInternalVariable(CODE_POINT_LIMIT); } private LoadSettings buildSettings() { From 1330f22e3bac686b2016c21e704e853c97c53fee Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Tue, 19 Sep 2023 10:16:54 -0500 Subject: [PATCH 5/6] Use a respond_to site for path check --- ext/java/org/jruby/ext/psych/PsychParser.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ext/java/org/jruby/ext/psych/PsychParser.java b/ext/java/org/jruby/ext/psych/PsychParser.java index ebaee4c6..5508ffd7 100644 --- a/ext/java/org/jruby/ext/psych/PsychParser.java +++ b/ext/java/org/jruby/ext/psych/PsychParser.java @@ -49,6 +49,7 @@ import org.jruby.javasupport.JavaUtil; import org.jruby.runtime.Block; import org.jruby.runtime.Helpers; +import org.jruby.runtime.JavaSites; import org.jruby.runtime.ThreadContext; import org.jruby.runtime.builtin.IRubyObject; import org.jruby.runtime.callsite.CachingCallSite; @@ -248,8 +249,9 @@ public IRubyObject parse(ThreadContext context, IRubyObject handler, IRubyObject LoadSettings loadSettings = loadSettingsBuilder.build(); parser = new ParserImpl(loadSettings, new ScannerImpl(loadSettings, readerFor(context, yaml, loadSettings))); - if (path.isNil() && yaml.respondsTo("path")) { - path = sites.path.call(context, this, yaml); + JavaSites.CheckedSites pathSites = sites.path; + if (path.isNil() && pathSites.respond_to_X.respondsTo(context, yaml, yaml)) { + path = pathSites.site.call(context, this, yaml); } while (parser.hasNext()) { @@ -651,7 +653,7 @@ private LoadSettings buildSettings() { private final CallSites sites; private static class CallSites { - private final CachingCallSite path = new FunctionalCachingCallSite("path"); + private final JavaSites.CheckedSites path = new JavaSites.CheckedSites("path"); private final CachingCallSite event_location = new FunctionalCachingCallSite("event_location"); private final CachingCallSite start_stream = new FunctionalCachingCallSite("start_stream"); private final CachingCallSite start_document = new FunctionalCachingCallSite("start_document"); From 323530a8b984cd28488760bbe9b6f3a5a8b1a998 Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Tue, 19 Sep 2023 10:19:14 -0500 Subject: [PATCH 6/6] Whitespace style changes --- ext/java/org/jruby/ext/psych/PsychParser.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ext/java/org/jruby/ext/psych/PsychParser.java b/ext/java/org/jruby/ext/psych/PsychParser.java index 5508ffd7..b52857cc 100644 --- a/ext/java/org/jruby/ext/psych/PsychParser.java +++ b/ext/java/org/jruby/ext/psych/PsychParser.java @@ -368,6 +368,7 @@ private void handleDocumentStart(ThreadContext context, DocumentStartEvent dse, private void handleMappingStart(ThreadContext context, MappingStartEvent mse, IRubyObject handler) { Ruby runtime = context.runtime; + IRubyObject anchor = stringOrNilForAnchor(context, mse.getAnchor()); IRubyObject tag = stringOrNilFor(context, mse.getTag()); IRubyObject implicit = runtime.newBoolean(mse.isImplicit()); @@ -393,6 +394,7 @@ private void handleScalar(ThreadContext context, ScalarEvent se, IRubyObject han private void handleSequenceStart(ThreadContext context, SequenceStartEvent sse, IRubyObject handler) { Ruby runtime = context.runtime; + IRubyObject anchor = stringOrNilForAnchor(context, sse.getAnchor()); IRubyObject tag = stringOrNilFor(context, sse.getTag()); IRubyObject implicit = runtime.newBoolean(sse.isImplicit()); @@ -403,6 +405,7 @@ private void handleSequenceStart(ThreadContext context, SequenceStartEvent sse, private static void raiseParserException(ThreadContext context, ReaderException re, IRubyObject rbPath) { Ruby runtime = context.runtime; + RubyClass se; RubyException exception; @@ -426,6 +429,7 @@ private static void raiseParserException(ThreadContext context, ReaderException private static void raiseParserException(ThreadContext context, MarkedYamlEngineException mye, IRubyObject rbPath) { Ruby runtime = context.runtime; + Mark mark; RubyClass se; RubyException exception; @@ -452,6 +456,7 @@ private static void raiseParserException(ThreadContext context, MarkedYamlEngine private static void raiseParserException(ThreadContext context, MalformedInputException mie, IRubyObject rbPath) { Ruby runtime = context.runtime; + RubyClass se; RubyException exception;