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: 061904632288
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: cc7a72ffc78b
Choose a head ref
  • 3 commits
  • 17 files changed
  • 1 contributor

Commits on Jul 12, 2016

  1. Copy the full SHA
    e66b127 View commit details
  2. Copy the full SHA
    1939d1e View commit details
  3. Copy the full SHA
    cc7a72f View commit details
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;
}
38 changes: 28 additions & 10 deletions tool/jt.rb
Original file line number Diff line number Diff line change
@@ -31,6 +31,9 @@
JEXCEPTION = "-Xtruffle.exceptions.print_java=true"
METRICS_REPS = 10

LIBXML_HOME = ENV['LIBXML_HOME'] = ENV['LIBXML_HOME'] || '/usr'
OPENSSL_HOME = ENV['OPENSSL_HOME'] = ENV['OPENSSL_HOME'] || '/usr'

# wait for sub-processes to handle the interrupt
trap(:INT) {}

@@ -346,6 +349,10 @@ def sulong_run(*args)
mx SULONG_DIR, 'su-run', *args
end

def sulong_link(*args)
mx SULONG_DIR, 'su-link', *args
end

def mspec(command, *args)
env_vars = {}
if command.is_a?(Hash)
@@ -613,7 +620,11 @@ def cextc(cext_dir, *clang_opts)
lls.push ll
end

mx SULONG_DIR, 'su-link', '-o', out, *lls
config_libs = config['libs'] || ''
config_libs = `echo #{config_libs}`.strip
config_libs = config_libs.split(' ')

sulong_link '-o', out, *((config_libs.map { |l| ['-l', l] }).flatten), *lls
end

def test(*args)
@@ -697,24 +708,31 @@ def test_compiler(*args)
private :test_compiler

def test_cexts(*args)
libxml_home = ENV['LIBXML_HOME'] || '/usr'
openssl_home = ENV['OPENSSL_HOME'] || '/usr'

# Test that we can compile and run some basic C code that uses libxml and openssl

clang '-S', '-emit-llvm', "-I#{libxml_home}/include/libxml2", 'test/truffle/cexts/xml/main.c', '-o', 'test/truffle/cexts/xml/main.ll'
out, _ = sulong_run("-l#{libxml_home}/lib/libxml2.dylib", 'test/truffle/cexts/xml/main.ll', {capture: true})
clang '-S', '-emit-llvm', "-I#{LIBXML_HOME}/include/libxml2", 'test/truffle/cexts/xml/main.c', '-o', 'test/truffle/cexts/xml/main.ll'
out, _ = sulong_run("-l#{LIBXML_HOME}/lib/libxml2.dylib", 'test/truffle/cexts/xml/main.ll', {capture: true})
raise unless out == "7\n"

clang '-S', '-emit-llvm', "-I#{OPENSSL_HOME}/include", 'test/truffle/cexts/xopenssl/main.c', '-o', 'test/truffle/cexts/xopenssl/main.ll'
out, _ = sulong_run("-l#{OPENSSL_HOME}/lib/libssl.dylib", 'test/truffle/cexts/xopenssl/main.ll', {capture: true})
raise unless out == "5d41402abc4b2a76b9719d911017c592\n"

# Test that we can run those same test when they're build as a .su and we load the code and libraries from that

sulong_link '-o', 'test/truffle/cexts/xml/main.su', '-l', "#{LIBXML_HOME}/lib/libxml2.dylib", 'test/truffle/cexts/xml/main.ll'
out, _ = sulong_run('test/truffle/cexts/xml/main.su', {capture: true})
raise unless out == "7\n"

clang '-S', '-emit-llvm', "-I#{openssl_home}/include", 'test/truffle/cexts/openssl/main.c', '-o', 'test/truffle/cexts/openssl/main.ll'
out, _ = sulong_run("-l#{openssl_home}/lib/libssl.dylib", 'test/truffle/cexts/openssl/main.ll', {capture: true})
raise unless out == "7369676e616c2066756e6374696f6e20\n"
sulong_link '-o', 'test/truffle/cexts/xopenssl/main.su', '-l', "#{OPENSSL_HOME}/lib/libssl.dylib", 'test/truffle/cexts/xopenssl/main.ll'
out, _ = sulong_run('test/truffle/cexts/xopenssl/main.su', {capture: true})
raise unless out == "5d41402abc4b2a76b9719d911017c592\n"

# Test that we can compile and run some very basic C extensions

begin
output_file = 'cext-output.txt'
['minimum', 'method', 'module'].each do |gem_name|
['minimum', 'method', 'module', 'xml', 'xopenssl'].each do |gem_name|
dir = "#{JRUBY_DIR}/test/truffle/cexts/#{gem_name}"
cextc dir
name = File.basename(dir)
2 changes: 2 additions & 0 deletions truffle/src/main/c/openssl/.jruby-cext-build.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
src: ./*.c
cflags: -I$OPENSSL_HOME/include
libs: $OPENSSL_HOME/lib/libssl.dylib
out: ../../../../../lib/ruby/truffle/openssl/openssl.su