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

Commits on Apr 25, 2016

  1. Copy the full SHA
    46d8857 View commit details
  2. Copy the full SHA
    168b208 View commit details
  3. Copy the full SHA
    66ba6d0 View commit details
Binary file added lib/ruby/truffle/cext/ruby.su
Binary file not shown.
2 changes: 1 addition & 1 deletion truffle/src/main/c/cext/.jruby-cext-build.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
src: ./*.c
out: ruby.su
out: ../../../../../lib/ruby/truffle/cext/ruby.su
10 changes: 10 additions & 0 deletions truffle/src/main/c/cext/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
This is the library that implements the Ruby C API for JRuby+Truffle. We
include the built version in the repository (under the lib directory) because
building it requires some complex dependencies.

To rebuild it, you need Sulong checked out and built. Then set `SULONG_DIR`
and run:

```
$ bin/jruby bin/jruby-cext-c truffle/src/main/c/cext
```
28 changes: 14 additions & 14 deletions truffle/src/main/c/cext/ruby.c
Original file line number Diff line number Diff line change
@@ -48,27 +48,27 @@ VALUE get_rb_eRuntimeError() {
}

int NUM2INT(VALUE value) {
return *((int*) truffle_invoke(ruby_cext, "num2int", value));
return truffle_invoke_i(ruby_cext, "num2int", value);
}

unsigned int NUM2UINT(VALUE value) {
return *((unsigned int*) truffle_invoke(ruby_cext, "num2uint", value));
return (unsigned int) truffle_invoke_i(ruby_cext, "num2uint", value);
}

long NUM2LONG(VALUE value) {
return *((long*) truffle_invoke(ruby_cext, "num2long", value));
return truffle_invoke_l(ruby_cext, "num2long", value);
}

int FIX2INT(VALUE value) {
return *((int*) truffle_invoke(ruby_cext, "fix2int", value));
return truffle_invoke_i(ruby_cext, "fix2int", value);
}

unsigned int FIX2UINT(VALUE value) {
return *((unsigned int*) truffle_invoke(ruby_cext, "fix2uint", value));
return (unsigned int) truffle_invoke_i(ruby_cext, "fix2uint", value);
}

long FIX2LONG(VALUE value) {
return *((long*) truffle_invoke(ruby_cext, "fix2long", value));
return truffle_invoke_l(ruby_cext, "fix2long", value);
}

VALUE INT2NUM(int value) {
@@ -92,7 +92,7 @@ VALUE LONG2FIX(long value) {
}

int FIXNUM_P(VALUE value) {
return *((int*) truffle_invoke(ruby_cext, "fixnum?", value));
return truffle_invoke_i(ruby_cext, "fixnum?", value);
}

char *RSTRING_PTR(VALUE string) {
@@ -101,7 +101,7 @@ char *RSTRING_PTR(VALUE string) {
}

int RSTRING_LEN(VALUE string) {
return *((int*) truffle_get_size(string));
return truffle_get_size(string);
}

ID rb_intern(const char *string) {
@@ -117,7 +117,7 @@ void rb_str_cat(VALUE string, char *to_concat, long length) {
}

int RARRAY_LEN(VALUE array) {
return *((int*) truffle_get_size(array));
return truffle_get_size(array);
}

VALUE *RARRAY_PTR(VALUE array) {
@@ -142,11 +142,11 @@ void rb_ary_push(VALUE array, VALUE value) {
}

void rb_ary_store(VALUE array, long index, VALUE value) {
truffle_write(array, &index, value);
truffle_write_idx(array, (int) index, value);
}

VALUE rb_ary_entry(VALUE array, long index) {
return truffle_read(array, &index);
return truffle_read_idx(array, (int) index);
}

VALUE rb_hash_aref(VALUE hash, VALUE key) {
@@ -166,11 +166,11 @@ VALUE rb_funcall(VALUE object, ID name, int argc, ...) {
}

VALUE rb_iv_get(VALUE object, const char *name) {
return truffle_read(object, (void*) name);
return truffle_read(object, name);
}

VALUE rb_iv_set(VALUE object, const char *name, VALUE value) {
truffle_write(object, (void*) name, value);
truffle_write(object, name, value);
return value;
}

@@ -199,5 +199,5 @@ void rb_define_private_method(VALUE module, char *name, void *function, int args
}

int rb_define_module_function(VALUE module, char *name, void *function, int args) {
return *((int*) truffle_invoke(ruby_cext, "define_module_function", module, name, function, args));
return truffle_invoke_i(ruby_cext, "define_module_function", module, name, function, args);
}
Original file line number Diff line number Diff line change
@@ -42,8 +42,12 @@
public class FeatureLoader {

private final RubyContext context;

private final ConcurrentHashMap<String, ReentrantLock> fileLocks = new ConcurrentHashMap<>();

private final Object cextImplementationLock = new Object();
private boolean cextImplementationLoaded = false;

public FeatureLoader(RubyContext context) {
this.context = context;
}
@@ -194,6 +198,8 @@ public Boolean block() throws InterruptedException {
} break;

case RubyLanguage.CEXT_MIME_TYPE: {
ensureCExtImplementationLoaded(frame, callNode);

final CallTarget callTarget;

try {
@@ -244,6 +250,26 @@ public Boolean block() throws InterruptedException {

}

private void ensureCExtImplementationLoaded(VirtualFrame frame, IndirectCallNode callNode) {
synchronized (cextImplementationLock) {
if (cextImplementationLoaded) {
return;
}

final CallTarget callTarget;

try {
callTarget = context.getEnv().parse(Source.fromFileName(context.getJRubyRuntime().getJRubyHome() + "/lib/ruby/truffle/cext/ruby.su"));
} catch (IOException e) {
throw new RuntimeException(e);
}

callNode.call(frame, callTarget, new Object[]{});

cextImplementationLoaded = true;
}
}

private String getBaseName(String path) {
final String name = new File(path).getName();