Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: b95f7d131c5e
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 9e99b0d9c3b4
Choose a head ref
  • 2 commits
  • 64 files changed
  • 1 contributor

Commits on Aug 21, 2015

  1. Update psych+tests to 2.0.15.

    headius committed Aug 21, 2015
    Copy the full SHA
    b0e2c64 View commit details
  2. Copy the full SHA
    9e99b0d View commit details
Showing with 1,374 additions and 429 deletions.
  1. +21 −8 core/src/main/java/org/jruby/ext/psych/PsychLibrary.java
  2. +18 −5 core/src/main/java/org/jruby/ext/psych/PsychParser.java
  3. +24 −17 core/src/main/java/org/jruby/ext/psych/PsychToRuby.java
  4. +220 −50 lib/ruby/shared/psych.rb
  5. +101 −0 lib/ruby/shared/psych/class_loader.rb
  6. +2 −1 lib/ruby/shared/psych/deprecated.rb
  7. +13 −0 lib/ruby/shared/psych/exception.rb
  8. +0 −6 lib/ruby/shared/psych/json.rb
  9. +1 −0 lib/ruby/shared/psych/json/stream.rb
  10. +3 −1 lib/ruby/shared/psych/nodes/node.rb
  11. +1 −1 lib/ruby/shared/psych/nodes/sequence.rb
  12. +17 −12 lib/ruby/shared/psych/scalar_scanner.rb
  13. +1 −0 lib/ruby/shared/psych/stream.rb
  14. +10 −5 lib/ruby/shared/psych/streaming.rb
  15. +3 −4 lib/ruby/shared/psych/syntax_error.rb
  16. +3 −0 lib/ruby/shared/psych/versions.rb
  17. +5 −2 lib/ruby/shared/psych/visitors/json_tree.rb
  18. +113 −55 lib/ruby/shared/psych/visitors/to_ruby.rb
  19. +169 −49 lib/ruby/shared/psych/visitors/yaml_tree.rb
  20. +2 −0 lib/ruby/shared/psych/y.rb
  21. +1 −0 test/externals/ruby1.9/excludes/Psych/TestDateTime.rb
  22. +67 −2 test/externals/ruby1.9/psych/helper.rb
  23. +1 −1 test/externals/ruby1.9/psych/json/test_stream.rb
  24. +1 −1 test/externals/ruby1.9/psych/test_alias_and_anchor.rb
  25. +1 −1 test/externals/ruby1.9/psych/test_array.rb
  26. +1 −1 test/externals/ruby1.9/psych/test_boolean.rb
  27. +1 −1 test/externals/ruby1.9/psych/test_class.rb
  28. +25 −3 test/externals/ruby1.9/psych/test_coder.rb
  29. +22 −1 test/externals/ruby1.9/psych/test_date_time.rb
  30. +6 −2 test/externals/ruby1.9/psych/test_deprecated.rb
  31. +1 −1 test/externals/ruby1.9/psych/test_document.rb
  32. +2 −3 test/externals/ruby1.9/psych/test_emitter.rb
  33. +56 −65 test/externals/ruby1.9/psych/test_encoding.rb
  34. +0 −47 test/externals/ruby1.9/psych/test_engine_manager.rb
  35. +26 −21 test/externals/ruby1.9/psych/test_exception.rb
  36. +51 −1 test/externals/ruby1.9/psych/test_hash.rb
  37. +2 −2 test/externals/ruby1.9/psych/test_json_tree.rb
  38. +54 −0 test/externals/ruby1.9/psych/test_marshalable.rb
  39. +49 −1 test/externals/ruby1.9/psych/test_merge_keys.rb
  40. +1 −1 test/externals/ruby1.9/psych/test_nil.rb
  41. +1 −1 test/externals/ruby1.9/psych/test_null.rb
  42. +1 −1 test/externals/ruby1.9/psych/test_numeric.rb
  43. +1 −1 test/externals/ruby1.9/psych/test_object.rb
  44. +5 −1 test/externals/ruby1.9/psych/test_object_references.rb
  45. +1 −1 test/externals/ruby1.9/psych/test_omap.rb
  46. +1 −1 test/externals/ruby1.9/psych/test_parser.rb
  47. +14 −14 test/externals/ruby1.9/psych/test_psych.rb
  48. +97 −0 test/externals/ruby1.9/psych/test_safe_load.rb
  49. +1 −1 test/externals/ruby1.9/psych/test_scalar.rb
  50. +2 −2 test/externals/ruby1.9/psych/test_scalar_scanner.rb
  51. +1 −1 test/externals/ruby1.9/psych/test_serialize_subclasses.rb
  52. +1 −1 test/externals/ruby1.9/psych/test_set.rb
  53. +1 −1 test/externals/ruby1.9/psych/test_stream.rb
  54. +110 −2 test/externals/ruby1.9/psych/test_string.rb
  55. +1 −1 test/externals/ruby1.9/psych/test_struct.rb
  56. +9 −1 test/externals/ruby1.9/psych/test_symbol.rb
  57. +8 −8 test/externals/ruby1.9/psych/test_tainted.rb
  58. +2 −2 test/externals/ruby1.9/psych/test_to_yaml_properties.rb
  59. +1 −1 test/externals/ruby1.9/psych/test_tree_builder.rb
  60. +6 −3 test/externals/ruby1.9/psych/test_yaml.rb
  61. +1 −5 test/externals/ruby1.9/psych/test_yamldbm.rb
  62. +1 −3 test/externals/ruby1.9/psych/test_yamlstore.rb
  63. +11 −4 test/externals/ruby1.9/psych/visitors/test_to_ruby.rb
  64. +2 −2 test/externals/ruby1.9/psych/visitors/test_yaml_tree.rb
29 changes: 21 additions & 8 deletions core/src/main/java/org/jruby/ext/psych/PsychLibrary.java
Original file line number Diff line number Diff line change
@@ -27,6 +27,10 @@
***** END LICENSE BLOCK *****/
package org.jruby.ext.psych;

import java.io.InputStream;
import java.io.IOException;
import java.util.Properties;

import org.jcodings.Encoding;
import org.jcodings.specific.UTF16BEEncoding;
import org.jcodings.specific.UTF16LEEncoding;
@@ -42,19 +46,28 @@
import org.jruby.runtime.load.Library;

public class PsychLibrary implements Library {
// NOTE: we add the last .0 for format compat with libyaml version numbers
// TODO: This should always reflect the SnakeYAML version
private static final String SNAKEYAML_VERSION = "1.13.0";
public void load(final Ruby runtime, boolean wrap) {
RubyModule psych = runtime.defineModule("Psych");

RubyString version = runtime.newString(SNAKEYAML_VERSION);

// load version from properties packed with the jar
Properties props = new Properties();
InputStream is = runtime.getJRubyClassLoader().getResourceAsStream("META-INF/maven/org.yaml/snakeyaml/pom.properties");
try {
props.load(is);
}
catch( IOException e ) {
// ignored
} finally {
try {is.close();} catch (IOException ioe) {}
}
RubyString version = runtime.newString(props.getProperty("version", "0.0") + ".0");
version.setFrozen(true);

final RubyArray versionElements = runtime.newArray(runtime.newFixnum(1), runtime.newFixnum(13), runtime.newFixnum(0));
psych.setConstant("SNAKEYAML_VERSION", version);

String[] versionParts = version.toString().split("\\.");
final RubyArray versionElements = runtime.newArray(runtime.newFixnum(Integer.parseInt(versionParts[0])), runtime.newFixnum(Integer.parseInt(versionParts[1])), runtime.newFixnum(Integer.parseInt(versionParts[2])));
versionElements.setFrozen(true);

psych.setConstant("LIBYAML_VERSION", version);
psych.getSingletonClass().addMethod("libyaml_version", new JavaMethodZero(psych, Visibility.PUBLIC) {
@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name) {
23 changes: 18 additions & 5 deletions core/src/main/java/org/jruby/ext/psych/PsychParser.java
Original file line number Diff line number Diff line change
@@ -34,6 +34,7 @@

import org.jcodings.Encoding;
import org.jcodings.specific.UTF8Encoding;
import org.jcodings.unicode.UnicodeEncoding;
import org.jruby.Ruby;
import org.jruby.RubyArray;
import org.jruby.RubyClass;
@@ -51,6 +52,8 @@
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.util.IOInputStream;
import org.jruby.util.encoding.CharsetTranscoder;
import org.jruby.util.io.EncodingUtils;
import org.jruby.util.log.Logger;
import org.jruby.util.log.LoggerFactory;
import org.yaml.snakeyaml.DumperOptions;
@@ -135,10 +138,19 @@ private StreamReader readerFor(ThreadContext context, IRubyObject yaml) {

if (yaml instanceof RubyString) {
ByteList byteList = ((RubyString)yaml).getByteList();
Encoding enc = byteList.getEncoding();

// if not unicode, transcode to UTF8
if (!(enc instanceof UnicodeEncoding)) {
byteList = CharsetTranscoder.strTranscode(context, (RubyString)yaml, enc, UTF8Encoding.INSTANCE, context.nil);
enc = UTF8Encoding.INSTANCE;
}

ByteArrayInputStream bais = new ByteArrayInputStream(byteList.getUnsafeBytes(), byteList.getBegin(), byteList.getRealSize());

Charset charset = byteList.getEncoding().getCharset();
if (charset == null) charset = Charset.defaultCharset();
Charset charset = enc.getCharset();

assert charset != null : "charset for encoding " + enc + " should not be null";

InputStreamReader isr = new InputStreamReader(bais, charset);

@@ -147,9 +159,10 @@ private StreamReader readerFor(ThreadContext context, IRubyObject yaml) {

// fall back on IOInputStream, using default charset
if (yaml.respondsTo("read")) {
Charset charset = (yaml instanceof RubyIO)
? ((RubyIO)yaml).getReadEncoding().getCharset()
: Charset.defaultCharset();
Encoding enc = (yaml instanceof RubyIO)
? ((RubyIO)yaml).getReadEncoding()
: UTF8Encoding.INSTANCE;
Charset charset = enc.getCharset();
return new StreamReader(new InputStreamReader(new IOInputStream(yaml), charset));
} else {
throw runtime.newTypeError(yaml, runtime.getIO());
41 changes: 24 additions & 17 deletions core/src/main/java/org/jruby/ext/psych/PsychToRuby.java
Original file line number Diff line number Diff line change
@@ -40,33 +40,40 @@

public class PsychToRuby {
public static void initPsychToRuby(Ruby runtime, RubyModule psych) {
RubyClass classLoader = runtime.defineClassUnder("ClassLoader", runtime.getObject(), RubyObject.OBJECT_ALLOCATOR, psych);

RubyModule visitors = runtime.defineModuleUnder("Visitors", psych);
RubyClass visitor = runtime.defineClassUnder("Visitor", runtime.getObject(), runtime.getObject().getAllocator(), visitors);
RubyClass psychToRuby = runtime.defineClassUnder("ToRuby", visitor, RubyObject.OBJECT_ALLOCATOR, visitors);

psychToRuby.defineAnnotatedMethods(PsychToRuby.class);
psychToRuby.defineAnnotatedMethods(ToRuby.class);
classLoader.defineAnnotatedMethods(ClassLoader.class);
}

@JRubyMethod(visibility = PRIVATE)
public static IRubyObject build_exception(ThreadContext context, IRubyObject self, IRubyObject klass, IRubyObject message) {
if (klass instanceof RubyClass) {
IRubyObject exception = ((RubyClass)klass).allocate();
((RubyException)exception).message = message;
return exception;
} else {
throw context.runtime.newTypeError(klass, context.runtime.getClassClass());
public static class ToRuby {
@JRubyMethod(visibility = PRIVATE)
public static IRubyObject build_exception(ThreadContext context, IRubyObject self, IRubyObject klass, IRubyObject message) {
if (klass instanceof RubyClass) {
IRubyObject exception = ((RubyClass)klass).allocate();
((RubyException)exception).message = message;
return exception;
} else {
throw context.runtime.newTypeError(klass, context.runtime.getClassClass());
}
}
}

@JRubyMethod(visibility = PRIVATE)
public static IRubyObject path2class(ThreadContext context, IRubyObject self, IRubyObject path) {
try {
return context.runtime.getClassFromPath(path.asJavaString());
} catch (RaiseException re) {
if (re.getException().getMetaClass() == context.runtime.getNameError()) {
throw context.runtime.newArgumentError("undefined class/module " + path);
public static class ClassLoader {
@JRubyMethod(visibility = PRIVATE)
public static IRubyObject path2class(ThreadContext context, IRubyObject self, IRubyObject path) {
try {
return context.runtime.getClassFromPath(path.asJavaString());
} catch (RaiseException re) {
if (re.getException().getMetaClass() == context.runtime.getNameError()) {
throw context.runtime.newArgumentError("undefined class/module " + path);
}
throw re;
}
throw re;
}
}
}
Loading