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: c0c70807d637
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: e59790b4b0a3
Choose a head ref

Commits on Sep 26, 2016

  1. Copy the full SHA
    86c730d View commit details
  2. Copy the full SHA
    fffdf8f View commit details
  3. [Truffle] Make native openssl the default and replace JRUBY_TRUFFLE_N…

    …ATIVE_OPENSSL with JRUBY_TRUFFLE_SHIM_OPENSSL
    chrisseaton committed Sep 26, 2016
    Copy the full SHA
    df5f2b2 View commit details
  4. Copy the full SHA
    806c161 View commit details
  5. Copy the full SHA
    f84bf9b View commit details
  6. Copy the full SHA
    383c2be View commit details
  7. 2
    Copy the full SHA
    febe6a1 View commit details
  8. Copy the full SHA
    0438e07 View commit details
  9. Copy the full SHA
    aac248b View commit details
  10. Copy the full SHA
    7d4c8d9 View commit details
  11. Copy the full SHA
    39e6a77 View commit details
  12. Copy the full SHA
    cb35247 View commit details
  13. 2
    Copy the full SHA
    ff08b65 View commit details
  14. [Truffle] We have to be more explicit about how we load openssl, as t…

    …he .so seems to take priority - make it's in the wrong place?
    chrisseaton committed Sep 26, 2016
    Copy the full SHA
    9a9d43f View commit details
  15. Copy the full SHA
    61d0fa3 View commit details
  16. [Truffle] Use the global context if we can't find one locally, for te…

    …mporarily, and warn about it.
    chrisseaton committed Sep 26, 2016
    Copy the full SHA
    13ad4fd View commit details
  17. Copy the full SHA
    7fa82dc View commit details
  18. [Truffle] Not sure how to implement the variadics of rb_scan_args, so…

    … introduce specialisations for now.
    chrisseaton committed Sep 26, 2016
    4
    Copy the full SHA
    601b267 View commit details
  19. Copy the full SHA
    540cad5 View commit details
  20. Copy the full SHA
    0b636cd View commit details
  21. Copy the full SHA
    f601990 View commit details
  22. 1
    Copy the full SHA
    5d39b74 View commit details
  23. Copy the full SHA
    2009591 View commit details
  24. Copy the full SHA
    ee07d6b View commit details
  25. Copy the full SHA
    ad203cc View commit details
  26. Copy the full SHA
    d391a90 View commit details
  27. Copy the full SHA
    e59790b View commit details
80 changes: 67 additions & 13 deletions lib/ruby/truffle/cext/ruby.h
Original file line number Diff line number Diff line change
@@ -32,6 +32,7 @@ extern "C" {
// Support

#define RUBY_CEXT (void *)truffle_import_cached("ruby_cext")
#define MUST_INLINE __attribute__((always_inline))

// Configuration

@@ -60,6 +61,13 @@ typedef VALUE ID;

NORETURN(VALUE rb_f_notimplement(int args_count, const VALUE *args, VALUE object));

// Non-standard

NORETURN(void rb_jt_error(const char *message));

void *rb_jt_to_native_handle(VALUE managed);
VALUE rb_jt_from_native_handle(void *native);

// Memory

#define xmalloc malloc
@@ -345,11 +353,36 @@ VALUE rb_str_new_cstr(const char *string);
VALUE rb_str_cat(VALUE string, const char *to_concat, long length);
VALUE rb_str_cat2(VALUE string, const char *to_concat);
VALUE rb_str_to_str(VALUE string);
VALUE rb_string_value(volatile VALUE *value_pointer);

MUST_INLINE VALUE rb_string_value(VALUE *value_pointer) {
VALUE value = *value_pointer;

if (!RB_TYPE_P(value, T_STRING)) {
value = rb_str_to_str(value);
*value_pointer = value;
}

return value;
}

MUST_INLINE char *rb_string_value_ptr(volatile VALUE* value_pointer) {
VALUE string = rb_string_value(value_pointer);
return RSTRING_PTR(string);
}

MUST_INLINE char *rb_string_value_cstr(volatile VALUE* value_pointer) {
VALUE string = rb_string_value(value_pointer);

if (!truffle_invoke_b(RUBY_CEXT, "rb_string_value_cstr_check", string)) {
rb_jt_error("rb_string_value_cstr failure case not implemented");
abort();
}

return RSTRING_PTR(string);
}

#define StringValue(value) rb_string_value(&(value))
#define SafeStringValue StringValue
char *rb_string_value_ptr(volatile VALUE* value_pointer);
char *rb_string_value_cstr(volatile VALUE* value_pointer);
#define StringValuePtr(string) rb_string_value_ptr(&(string))
#define StringValueCStr(string) rb_string_value_cstr(&(string))
VALUE rb_str_buf_new(long capacity);
@@ -432,6 +465,14 @@ void rb_warning(const char *fmt, ...);

int rb_scan_args(int argc, VALUE *argv, const char *format, ...);

MUST_INLINE int rb_jt_scan_args_02(int argc, VALUE *argv, VALUE *v1, VALUE *v2) {
if (argc >= 1) *v1 = argv[0];
if (argc >= 2) *v2 = argv[1];
return argc;
}

int rb_scan_args(int argc, VALUE *argv, const char *format, ...);

// Calls

int rb_respond_to(VALUE object, ID name);
@@ -614,20 +655,26 @@ void rb_thread_wait_fd(int fd);

NORETURN(void rb_eof_error(void));

// Objects

struct RBasic {
// Empty
};

// Data

struct RData {
// No RBasic object header
struct RBasic basic;
void (*dmark)(void *data);
void (*dfree)(void *data);
void *data;
};

struct RData *rb_jt_wrap_rdata(VALUE value);
struct RData *rb_jt_adapt_rdata(VALUE value);

#define RDATA(value) rb_jt_wrap_rdata(value)
#define RDATA(value) rb_jt_adapt_rdata(value)

#define DATA_PTR(value) *((volatile intptr_t*) 0)
#define DATA_PTR(value) (RDATA(value)->data)

// Typed data

@@ -646,8 +693,21 @@ struct rb_data_type_struct {
VALUE flags;
};

struct RTypedData {
struct RBasic basic;
const rb_data_type_t *type;
VALUE typed_flag;
void *data;
};

#define RUBY_TYPED_FREE_IMMEDIATELY 1

struct RTypedData *rb_jt_adapt_rtypeddata(VALUE value);

#define RTYPEDDATA(value) rb_jt_adapt_rtypeddata(value)

#define RTYPEDDATA_DATA(value) (RTYPEDDATA(value)->data)

VALUE rb_data_typed_object_wrap(VALUE ruby_class, void *data, const rb_data_type_t *data_type);

#define TypedData_Wrap_Struct(ruby_class, data_type, data) rb_data_typed_object_wrap((ruby_class), (data), (data_type))
@@ -666,8 +726,6 @@ void *rb_check_typeddata(VALUE value, const rb_data_type_t *data_type);

#define TypedData_Get_Struct(value, type, data_type, variable) ((variable) = (type *)rb_check_typeddata((value), (data_type)))

#define RTYPEDDATA_DATA(value) *((volatile int*) 0)

// VM

VALUE *rb_ruby_verbose_ptr(void);
@@ -676,10 +734,6 @@ VALUE *rb_ruby_verbose_ptr(void);
VALUE *rb_ruby_debug_ptr(void);
#define ruby_debug (*rb_ruby_debug_ptr())

// Non-standard

NORETURN(void rb_jt_error(const char *message));

#if defined(__cplusplus)
}
#endif
1 change: 1 addition & 0 deletions lib/ruby/truffle/truffle/io/nonblock.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# TODO
9 changes: 5 additions & 4 deletions lib/ruby/truffle/truffle/openssl.rb
Original file line number Diff line number Diff line change
@@ -6,14 +6,15 @@
# GNU General Public License version 2
# GNU Lesser General Public License version 2.1

if ENV['JRUBY_TRUFFLE_NATIVE_OPENSSL']
require_relative '../openssl/openssl'
else
if ENV['JRUBY_TRUFFLE_SHIM_OPENSSL']
# If loaded directly simulate as it was not found, it can added only
# explicitly by loading openssl-stubs which makes it look like
# openssl was loaded.

load_error = LoadError.new("cannot load such file -- openssl")
load_error = LoadError.new('cannot load such file -- openssl')
load_error.instance_variable_set :@path, 'openssl'
raise load_error
else
$LOAD_PATH.unshift File.expand_path('../../openssl', __FILE__)
require_relative '../openssl/openssl.rb'
end
1 change: 1 addition & 0 deletions tool/jt.rb
Original file line number Diff line number Diff line change
@@ -707,6 +707,7 @@ def cextc(cext_dir, *clang_opts)
ll = File.join(File.dirname(out), File.basename(src, '.*') + '.ll')

clang "-I#{SULONG_HOME}/include", '-Ilib/ruby/truffle/cext', '-S', '-emit-llvm', *config_cflags, *clang_opts, src, '-o', ll
llvm_opt '-S', '-always-inline', ll, '-o', ll
llvm_opt '-S', '-mem2reg', ll, '-o', ll

lls.push ll
78 changes: 40 additions & 38 deletions truffle/src/main/c/cext/ruby.c
Original file line number Diff line number Diff line change
@@ -51,7 +51,7 @@ int rb_type(VALUE value) {
}

bool RB_TYPE_P(VALUE value, int type) {
return truffle_invoke_i(RUBY_CEXT, "RB_TYPE_P", value, type);
return truffle_invoke_b(RUBY_CEXT, "RB_TYPE_P", value, type);
}

void rb_check_type(VALUE value, int type) {
@@ -67,8 +67,10 @@ VALUE rb_obj_is_kind_of(VALUE object, VALUE ruby_class) {
}

void rb_check_frozen(VALUE object) {
rb_jt_error("rb_check_frozen not implemented");
abort();
if (OBJ_FROZEN(object)){
rb_jt_error("rb_check_frozen failure case not implemented");
abort();
}
}

void rb_check_safe_obj(VALUE object) {
@@ -342,7 +344,7 @@ double RFLOAT_VALUE(VALUE value){
// String

char *RSTRING_PTR(VALUE string) {
return (char *)truffle_invoke(RUBY_CEXT, "CExtString", string);
return (char *)truffle_invoke(RUBY_CEXT, "RSTRING_PTR", string);
}

int rb_str_len(VALUE string) {
@@ -385,27 +387,6 @@ VALUE rb_str_to_str(VALUE string) {
return (VALUE) truffle_invoke((void *)string, "to_str");
}

VALUE rb_string_value(volatile VALUE *value_pointer) {
VALUE value = *value_pointer;

if (!RB_TYPE_P(value, T_STRING)) {
value = rb_str_to_str(value);
*value_pointer = value;
}

return value;
}

char *rb_string_value_ptr(volatile VALUE* value_pointer) {
VALUE string = rb_string_value(value_pointer);
return RSTRING_PTR(string);
}

char *rb_string_value_cstr(volatile VALUE* value_pointer) {
rb_jt_error("rb_string_value_cstr not implemented");
abort();
}

VALUE rb_str_buf_new(long capacity) {
return rb_str_new_cstr("");
}
@@ -647,7 +628,8 @@ void rb_warning(const char *format, ...) {
}

int rb_scan_args(int argc, VALUE *argv, const char *format, ...) {
return truffle_invoke_i(RUBY_CEXT, "rb_scan_args", argc, argv, format /*, where to get args? */);
rb_jt_error("generic rb_scan_args not implemented - use a specialisation such as rb_jt_scan_args_02");
abort();
}

// Calls
@@ -696,24 +678,33 @@ VALUE rb_yield(VALUE value) {

// Instance variables

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

VALUE rb_iv_set(VALUE object, const char *name, VALUE value) {
truffle_write(object, rb_intern(name), value);
if (name[0] == '@') {
truffle_write(object, name, value);
} else {
truffle_invoke(RUBY_CEXT, "rb_iv_set_hidden", object, rb_str_new_cstr(name), value);
}

return value;
}

VALUE rb_ivar_get(VALUE object, ID name) {
return truffle_read(object, name);
VALUE rb_iv_get(VALUE object, const char *name) {
if (name[0] == '@') {
return truffle_read(object, name);
} else {
return truffle_invoke(RUBY_CEXT, "rb_iv_get_hidden", object, rb_str_new_cstr(name));
}
}

VALUE rb_ivar_set(VALUE object, ID name, VALUE value) {
truffle_write(object, name, value);
return value;
}

VALUE rb_ivar_get(VALUE object, ID name) {
return truffle_read(object, name);
}

VALUE rb_ivar_lookup(VALUE object, const char *name, VALUE default_value) {
return (VALUE) truffle_invoke(RUBY_CEXT, "rb_ivar_lookup", name, default_value);
}
@@ -1059,13 +1050,16 @@ NORETURN(void rb_eof_error(void)) {

// Data

struct RData *rb_jt_wrap_rdata(VALUE value) {
rb_jt_error("RDATA not implemented");
abort();
struct RData *rb_jt_adapt_rdata(VALUE value) {
return (struct RData *)truffle_invoke(RUBY_CEXT, "rb_jt_adapt_rdata", value);
}

// Typed data

struct RTypedData *rb_jt_adapt_rtypeddata(VALUE value) {
return (struct RTypedData *)truffle_invoke(RUBY_CEXT, "rb_jt_adapt_rtypeddata", value);
}

VALUE rb_data_typed_object_wrap(VALUE ruby_class, void *data, const rb_data_type_t *data_type) {
return (VALUE) truffle_invoke(RUBY_CEXT, "rb_data_typed_object_wrap", ruby_class, data, data_type);
}
@@ -1082,8 +1076,8 @@ VALUE rb_data_typed_object_make(VALUE ruby_class, const rb_data_type_t *type, vo
}

void *rb_check_typeddata(VALUE value, const rb_data_type_t *data_type) {
rb_jt_error("rb_check_typeddata not implemented");
abort();
// TODO CS 24-Sep-2016 we're supposed to do some error checking here
return RTYPEDDATA_DATA(value);
}

// VM
@@ -1107,3 +1101,11 @@ VALUE *rb_ruby_debug_ptr(void) {
void rb_jt_error(const char *message) {
truffle_invoke(RUBY_CEXT, "rb_jt_error", rb_str_new_cstr(message));
}

void *rb_jt_to_native_handle(VALUE managed) {
(void *)truffle_invoke_l(RUBY_CEXT, "rb_jt_to_native_handle", managed);
}

VALUE rb_jt_from_native_handle(void *native) {
return (VALUE) truffle_invoke(RUBY_CEXT, "rb_jt_from_native_handle", (long) native);
}
2 changes: 1 addition & 1 deletion truffle/src/main/c/openssl/ossl_pkey_dh.c
Original file line number Diff line number Diff line change
@@ -207,7 +207,7 @@ ossl_dh_initialize(int argc, VALUE *argv, VALUE self)
VALUE arg, gen;

GetPKey(self, pkey);
if(rb_scan_args(argc, argv, "02", &arg, &gen) == 0) {
if(rb_jt_scan_args_02(argc, argv, &arg, &gen) == 0) {
dh = DH_new();
}
else if (FIXNUM_P(arg)) {
2 changes: 1 addition & 1 deletion truffle/src/main/c/openssl/ossl_ssl.c
Original file line number Diff line number Diff line change
@@ -161,7 +161,7 @@ ossl_sslctx_s_alloc(VALUE klass)
}
SSL_CTX_set_mode(ctx, mode);
RTYPEDDATA_DATA(obj) = ctx;
SSL_CTX_set_ex_data(ctx, ossl_ssl_ex_ptr_idx, (void*)obj);
SSL_CTX_set_ex_data(ctx, ossl_ssl_ex_ptr_idx, rb_jt_to_native_handle(obj));

#if !defined(OPENSSL_NO_EC) && defined(HAVE_SSL_CTX_SET_ECDH_AUTO)
/* We use SSL_CTX_set1_curves_list() to specify the curve used in ECDH. It
2 changes: 1 addition & 1 deletion truffle/src/main/c/openssl/ossl_x509store.c
Original file line number Diff line number Diff line change
@@ -130,7 +130,7 @@ ossl_x509store_set_vfy_cb(VALUE self, VALUE cb)
X509_STORE *store;

GetX509Store(self, store);
X509_STORE_set_ex_data(store, ossl_store_ex_verify_cb_idx, (void *)cb);
X509_STORE_set_ex_data(store, ossl_store_ex_verify_cb_idx, rb_jt_to_native_handle(cb));
rb_iv_set(self, "@verify_callback", cb);

return cb;
Loading