Skip to content

Commit

Permalink
Showing 36 changed files with 393 additions and 65 deletions.
20 changes: 11 additions & 9 deletions COPYING
Original file line number Diff line number Diff line change
@@ -21,22 +21,24 @@ The Truffle component also distributes:

Antlr4 runtime (Copyright (c) 2015 Terence Parr, Sam Harwell, BSD licence)

truffle-api and truffle-debug (Copyright Oracle and/or its affiliates,
GPL v2, with classpath exception)
truffle-api and truffle-debug (Copyright Oracle and/or its affiliates, GPL
v2, with classpath exception)

The Rubinius API implementation in truffle/src/main/ruby/core/rubinius/api
is copyright (c) 2011, Evan Phoenix, and released under the 3-clause BSD license.

The Rubinius core library implementation in truffle/src/main/ruby/core/rubinius
is copyright (c) 2007-2015, Evan Phoenix and contributors, and released under
Parts of the core library implementation in truffle/src/main/ruby/core
are copyright (c) 2011, Evan Phoenix, and released under the 3-clause BSD
license.

Parts of the core library implementation in truffle/src/main/ruby/core
are copyright (c) 2007-2015, Evan Phoenix and contributors, and released under
the 3-clause BSD license.

Some parts of the Truffle Java code is derived from Rubinius C++ code which is
copyright (c) 2007-2015, Evan Phoenix and contributors, and released under the
3-clause BSD license.

Some parts of the RubySL implementations of the stdlib in lib/ruby/truffle/rubysl
are copyright (c) 2013 Brian Shirai and are licensed under the 3-clause BSD license.
Some parts of the RubySL implementations of the stdlib in
lib/ruby/truffle/rubysl are copyright (c) 2013 Brian Shirai and are licensed
under the 3-clause BSD license.

pr-zlib is copyright Park Heesob and Daniel Berger. "This library is covered
under the same license as zlib itself. For the text of the zlib license,
1 change: 1 addition & 0 deletions core/src/main/java/org/jruby/RubyRegexp.java
Original file line number Diff line number Diff line change
@@ -1725,6 +1725,7 @@ private static IRubyObject regOperand(IRubyObject str, boolean check) {
return check ? str.convertToString() : str.checkStringType();
}

@Deprecated
public static RubyRegexp unmarshalFrom(UnmarshalStream input) throws java.io.IOException {
RubyRegexp result = newRegexp(input.getRuntime(), input.unmarshalString(), RegexpOptions.fromJoniOptions(input.readSignedByte()));
input.registerLinkTarget(result);
73 changes: 71 additions & 2 deletions core/src/main/java/org/jruby/runtime/marshal/UnmarshalStream.java
Original file line number Diff line number Diff line change
@@ -37,6 +37,7 @@
import java.io.InputStream;
import org.jcodings.Encoding;
import org.jcodings.EncodingDB.Entry;
import org.jcodings.specific.ASCIIEncoding;
import org.jcodings.specific.USASCIIEncoding;
import org.jcodings.specific.UTF8Encoding;

@@ -61,6 +62,7 @@
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.encoding.EncodingCapable;
import org.jruby.util.ByteList;
import org.jruby.util.RegexpOptions;

/**
* Unmarshals objects from strings or streams in Ruby's marshal format.
@@ -222,8 +224,8 @@ private IRubyObject unmarshalObjectDirectly(int type, MarshalState state, boolea
case 'f' :
rubyObj = RubyFloat.unmarshalFrom(this);
break;
case '/' :
rubyObj = RubyRegexp.unmarshalFrom(this);
case '/':
rubyObj = unmarshalRegexp(state);
break;
case ':' :
rubyObj = RubySymbol.unmarshalFrom(this);
@@ -282,6 +284,73 @@ private IRubyObject unmarshalObjectDirectly(int type, MarshalState state, boolea
return rubyObj;
}

private IRubyObject unmarshalRegexp(MarshalState state) throws IOException {
IRubyObject rubyObj;ByteList byteList = unmarshalString();
byte opts = readSignedByte();
RegexpOptions reOpts = RegexpOptions.fromJoniOptions(opts);

if (state.isIvarWaiting()) {
RubyString tmpStr = RubyString.newString(runtime, byteList);
registerLinkTarget(tmpStr);
defaultVariablesUnmarshal(tmpStr);
byteList = tmpStr.getByteList();
state.setIvarWaiting(false);
}
if (byteList.getEncoding() == ASCIIEncoding.INSTANCE) {
/* 1.8 compatibility; remove escapes undefined in 1.8 */
byte[] ptrBytes = byteList.unsafeBytes();
int ptr = byteList.begin();
int dst = ptr;
int src = ptr;
int len = byteList.realSize();
long bs = 0;
for (; len-- > 0; ptrBytes[dst++] = ptrBytes[src++]) {
switch (ptrBytes[src]) {
case '\\':
bs++;
break;
case 'g':
case 'h':
case 'i':
case 'j':
case 'k':
case 'l':
case 'm':
case 'o':
case 'p':
case 'q':
case 'u':
case 'y':
case 'E':
case 'F':
case 'H':
case 'I':
case 'J':
case 'K':
case 'L':
case 'N':
case 'O':
case 'P':
case 'Q':
case 'R':
case 'S':
case 'T':
case 'U':
case 'V':
case 'X':
case 'Y':
if ((bs & 1) != 0) --dst;
default:
bs = 0;
break;
}
}
byteList.setRealSize(dst - ptr);
}

rubyObj = RubyRegexp.newRegexp(runtime, byteList, reOpts);
return rubyObj;
}

public Ruby getRuntime() {
return runtime;
4 changes: 0 additions & 4 deletions spec/truffle/tags/core/exception/system_call_error_tags.txt

This file was deleted.

4 changes: 0 additions & 4 deletions test/mri/excludes/TestMarshal.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
exclude :test_change_struct, "needs investigation"
exclude :test_class_ivar, "needs investigation"
exclude :test_class_nonascii, "needs investigation"
exclude :test_continuation, "not supported"
@@ -8,13 +7,10 @@
exclude :test_marshal_load_ivar, "needs investigation"
exclude :test_marshal_load_should_not_taint_classes, "needs investigation"
exclude :test_marshal_rational, "needs investigation"
exclude :test_marshal_symbol_ascii8bit, "needs investigation"
exclude :test_modify_array_during_dump, "needs investigation"
exclude :test_module_ivar, "needs investigation"
exclude :test_no_internal_ids, "debug info for frozen strings is visible in JRuby"
exclude :test_object_prepend, "needs investigation"
exclude :test_regexp, "needs investigation"
exclude :test_regexp2, "needs investigation"
exclude :test_singleton, "needs investigation"
exclude :test_struct_invalid_members, "needs investigation"
exclude :test_symlink_in_ivar, "seems to be trying to deserialize a symbol with ivars, which we don't support"
3 changes: 2 additions & 1 deletion test/truffle/cexts/nokogiri/.jruby-cext-build.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
src: $GEM_HOME/gems/nokogiri-1.6.8/ext/nokogiri/*.c
cflags: -I$GEM_HOME/gems/nokogiri-1.6.8/ext/nokogiri `xml2-config --cflags`
cflags: -I$GEM_HOME/gems/nokogiri-1.6.8/ext/nokogiri -I$LIBXML_HOME/include/libxml2
libs: $LIBXML_HOME/lib/libxml2.dylib
out: lib/nokogiri/nokogiri.su
4 changes: 4 additions & 0 deletions test/truffle/cexts/xml/.jruby-cext-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
src: ext/xml/*.c
cflags: -I$LIBXML_HOME/include/libxml2
libs: $LIBXML_HOME/lib/libxml2.dylib
out: lib/xml/xml.su
5 changes: 5 additions & 0 deletions test/truffle/cexts/xml/bin/xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env ruby

require 'xml'

puts XML.UTF8Strlen("hello π")
1 change: 1 addition & 0 deletions test/truffle/cexts/xml/expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7
25 changes: 25 additions & 0 deletions test/truffle/cexts/xml/ext/xml/xml.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <ruby.h>

#include <libxml/xmlstring.h>

VALUE xml_UTF8Strlen(VALUE self, VALUE str) {
// We need to copy to a native string as we can't pass Ruby strings into native at the moment

size_t str_len = RSTRING_LEN(str);
char *str_ptr = RSTRING_PTR(str);

unsigned char *native_str = alloca(str_len + 1);

for (int n = 0; n < str_len; n++) {
native_str[n] = str_ptr[n];
}

native_str[str_len] = '\0';

return INT2NUM(xmlUTF8Strlen(native_str));
}

void Init_xml() {
VALUE module = rb_define_module("XML");
rb_define_module_function(module, "UTF8Strlen", &xml_UTF8Strlen, 1);
}
1 change: 1 addition & 0 deletions test/truffle/cexts/xml/lib/xml.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require 'xml/xml'
Empty file.
8 changes: 8 additions & 0 deletions test/truffle/cexts/xml/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <stdio.h>

#include <libxml/xmlstring.h>

int main(int argc, char **argv) {
printf("%d\n", xmlUTF8Strlen(BAD_CAST "hello π"));
return 0;
}
4 changes: 4 additions & 0 deletions test/truffle/cexts/xopenssl/.jruby-cext-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
src: ext/xopenssl/*.c
cflags: -I$OPENSSL_HOME/include
libs: $OPENSSL_HOME/lib/libssl.dylib
out: lib/xopenssl/xopenssl.su
5 changes: 5 additions & 0 deletions test/truffle/cexts/xopenssl/bin/xopenssl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env ruby

require 'xopenssl'

puts XOpenSSL.md5('hello')
1 change: 1 addition & 0 deletions test/truffle/cexts/xopenssl/expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5d41402abc4b2a76b9719d911017c592
39 changes: 39 additions & 0 deletions test/truffle/cexts/xopenssl/ext/xopenssl/xopenssl.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include <ruby.h>

#include <openssl/md5.h>

VALUE xopenssl_md5(VALUE self, VALUE str) {
// We need to copy to a native string as we can't pass Ruby strings into native at the moment

size_t str_len = RSTRING_LEN(str);
char *str_ptr = RSTRING_PTR(str);

unsigned char *native_str = alloca(str_len + 1);

for (int n = 0; n < str_len; n++) {
native_str[n] = str_ptr[n];
}

native_str[str_len] = '\0';

unsigned char digest[MD5_DIGEST_LENGTH];

MD5(native_str, str_len, digest);

char *hex = alloca(MD5_DIGEST_LENGTH * 2 + 1);

char *hex_ptr = hex;

for (int n = 0; n < MD5_DIGEST_LENGTH; n++){
hex_ptr += sprintf(hex_ptr, "%02x", digest[n]);
}

*hex_ptr = '\0';

return rb_str_new_cstr(hex);
}

void Init_xopenssl() {
VALUE module = rb_define_module("XOpenSSL");
rb_define_module_function(module, "md5", &xopenssl_md5, 1);
}
1 change: 1 addition & 0 deletions test/truffle/cexts/xopenssl/lib/xopenssl.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require 'xopenssl/xopenssl'
Empty file.
20 changes: 20 additions & 0 deletions test/truffle/cexts/xopenssl/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <string.h>
#include <stdio.h>

#include <openssl/md5.h>

static char *hello = "hello";

int main(int argc, char **argv) {
unsigned char digest[MD5_DIGEST_LENGTH];

MD5((unsigned char *)hello, strlen(hello), digest);

for (int n = 0; n < MD5_DIGEST_LENGTH; n++) {
printf("%02x", digest[n]);
}

printf("\n");

return 0;
}
Loading

0 comments on commit f7ec563

Please sign in to comment.