Skip to content

Commit

Permalink
Merge pull request #653 from headius/remove_ineffective_snakeyaml_set…
Browse files Browse the repository at this point in the history
…tings

Remove SnakeYAML settings that don't work
  • Loading branch information
headius authored Oct 7, 2023
2 parents e8188ce + 307c368 commit cc5daad
Showing 1 changed file with 0 additions and 87 deletions.
87 changes: 0 additions & 87 deletions ext/java/org/jruby/ext/psych/PsychParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,6 @@ public class PsychParser extends RubyObject {
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) {
Expand All @@ -124,9 +121,6 @@ public static void initPsychParser(Ruby runtime, RubyModule psych) {

// 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()));
}

Expand All @@ -138,9 +132,6 @@ 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());
this.loadSettingsBuilder = lsb;
}
Expand Down Expand Up @@ -538,42 +529,6 @@ public IRubyObject mark(ThreadContext context) {
);
}

@JRubyMethod(name = "max_aliases_for_collections=")
public IRubyObject max_aliases_for_collections_set(IRubyObject max) {
loadSettingsBuilder.setMaxAliasesForCollections(max.convertToInteger().getIntValue());

return max;
}

@JRubyMethod(name = MAX_ALIASES_FOR_COLLECTIONS)
public IRubyObject max_aliases_for_collections(ThreadContext context) {
return context.runtime.newFixnum(buildSettings().getMaxAliasesForCollections());
}

@JRubyMethod(name = "allow_duplicate_keys=")
public IRubyObject allow_duplicate_keys_set(IRubyObject allow) {
loadSettingsBuilder.setAllowDuplicateKeys(allow.isTrue());

return allow;
}

@JRubyMethod(name = ALLOW_DUPLICATE_KEYS)
public IRubyObject allow_duplicate_keys(ThreadContext context) {
return RubyBoolean.newBoolean(context, buildSettings().getAllowDuplicateKeys());
}

@JRubyMethod(name = "allow_recursive_keys=")
public IRubyObject allow_recursive_keys_set(IRubyObject allow) {
loadSettingsBuilder.setAllowRecursiveKeys(allow.isTrue());

return allow;
}

@JRubyMethod(name = ALLOW_RECURSIVE_KEYS)
public IRubyObject allow_recursive_keys(ThreadContext context) {
return RubyBoolean.newBoolean(context, buildSettings().getAllowRecursiveKeys());
}

@JRubyMethod(name = "code_point_limit=")
public IRubyObject code_point_limit_set(IRubyObject limit) {
loadSettingsBuilder.setCodePointLimit(limit.convertToInteger().getIntValue());
Expand All @@ -588,48 +543,6 @@ public IRubyObject code_point_limit(ThreadContext context) {

// class-level accessors for default values

@JRubyMethod(name = "max_aliases_for_collections=", meta = true)
public static IRubyObject max_aliases_for_collections_set(ThreadContext context, IRubyObject self, IRubyObject max) {
int maxAliasesForCollections = RubyNumeric.num2int(max);

if (maxAliasesForCollections <= 0) {
throw context.runtime.newRangeError("max_aliases_for_collections must be positive");
}

self.getInternalVariables().setInternalVariable(MAX_ALIASES_FOR_COLLECTIONS, max);

return max;
}

@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);
}

@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);

return allow;
}

@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);
}

@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);

return allow;
}

@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);
}

@JRubyMethod(name = "code_point_limit=", meta = true)
public static IRubyObject code_point_limit_set(ThreadContext context, IRubyObject self, IRubyObject limit) {
int codePointLimit = RubyNumeric.num2int(limit);
Expand Down

0 comments on commit cc5daad

Please sign in to comment.