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

Commits on May 22, 2016

  1. Copy the full SHA
    a316eef View commit details
  2. [Truffle] Specify when C functions take 0 arguments with (void).

    * Otherwise they can take any number of arguments.
    eregon committed May 22, 2016
    Copy the full SHA
    37512a5 View commit details
  3. Copy the full SHA
    8b111dd View commit details
  4. Copy the full SHA
    1ad016a View commit details
  5. Copy the full SHA
    85eee91 View commit details
  6. [Truffle] Classify C-ext methods by category.

    * Also implement RARRAY_AREF.
    eregon committed May 22, 2016
    Copy the full SHA
    f9d422a View commit details
62 changes: 46 additions & 16 deletions lib/ruby/truffle/cext/ruby.h
Original file line number Diff line number Diff line change
@@ -29,30 +29,33 @@ extern "C" {
typedef void *ID;
typedef void *VALUE;

VALUE get_Qfalse();
VALUE get_Qtrue();
VALUE get_Qnil();
VALUE get_rb_cProc();
VALUE get_rb_eException();
// Constants

VALUE get_Qfalse(void);
VALUE get_Qtrue(void);
VALUE get_Qnil(void);
VALUE get_rb_cProc(void);
VALUE get_rb_eException(void);

#define Qfalse get_Qfalse()
#define Qtrue get_Qtrue()
#define Qnil get_Qnil()
#define rb_cProc get_rb_cProc();
#define rb_eException get_rb_eException();

VALUE get_rb_cObject();
VALUE get_rb_cArray();
VALUE get_rb_cHash();
VALUE get_rb_cObject(void);
VALUE get_rb_cArray(void);
VALUE get_rb_cHash(void);

#define rb_cObject get_rb_cObject()
#define rb_cArray get_rb_cArray()
#define rb_cHash get_rb_cHash()

VALUE get_rb_eRuntimeError();
VALUE get_rb_eRuntimeError(void);

#define rb_eRuntimeError get_rb_eRuntimeError()

// Conversions

int NUM2INT(VALUE value);
unsigned int NUM2UINT(VALUE value);
@@ -69,44 +72,71 @@ VALUE UINT2NUM(unsigned int value);
VALUE LONG2NUM(long value);
VALUE LONG2FIX(long value);

// Type checks

int FIXNUM_P(VALUE value);

// Float

VALUE rb_float_new(double value);

// String

char *RSTRING_PTR(VALUE string);
int RSTRING_LEN(VALUE string);
ID rb_intern(const char *string);
VALUE rb_str_new2(const char *string);
VALUE ID2SYM(ID id);
VALUE rb_intern_str(VALUE string);
VALUE rb_str_new2(const char *string);
void rb_str_cat(VALUE string, const char *to_concat, long length);

// Symbol

ID rb_intern(const char *string);
VALUE ID2SYM(ID id);

// Array

int RARRAY_LEN(VALUE array);
int RARRAY_LENINT(VALUE array);
VALUE *RARRAY_PTR(VALUE array);
VALUE RARRAY_AREF(VALUE array, long index);
VALUE rb_ary_new(void);
VALUE rb_ary_new_capa(long capacity);
VALUE rb_ary_new2();
VALUE rb_ary_new();
#define rb_ary_new2 rb_ary_new_capa
void rb_ary_push(VALUE array, VALUE value);
VALUE rb_ary_pop(VALUE array);
void rb_ary_store(VALUE array, long index, VALUE value);
VALUE rb_ary_entry(VALUE array, long index);
int RARRAY_LENINT(VALUE array);
VALUE rb_ary_dup(VALUE array);

VALUE rb_hash_new();
// Hash

VALUE rb_hash_new(void);
VALUE rb_hash_aref(VALUE hash, VALUE key);
void rb_hash_aset(VALUE hash, VALUE key, VALUE value);

// Utilities

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

// Calls

VALUE rb_funcall(VALUE object, ID name, int argc, ...);

// Instance variables

VALUE rb_iv_get(VALUE object, const char *name);
VALUE rb_iv_set(VALUE object, const char *name, VALUE value);

// Accessing constants

VALUE rb_const_get(VALUE object, ID name);

// Raising exceptions

void rb_raise(VALUE exception, const char *format, ...);

// Defining classes, modules and methods

VALUE rb_define_class(const char *name, VALUE superclass);
VALUE rb_define_module(const char *name);
VALUE rb_define_module_under(VALUE module, const char *name);
Binary file modified lib/ruby/truffle/cext/ruby.su
Binary file not shown.
6 changes: 6 additions & 0 deletions lib/ruby/truffle/cext/version.h
Original file line number Diff line number Diff line change
@@ -11,4 +11,10 @@
#ifndef TRUFFLE_VERSION_H
#define TRUFFLE_VERSION_H

/* API version */
#define RUBY_API_VERSION_MAJOR 2
#define RUBY_API_VERSION_MINOR 3
#define RUBY_API_VERSION_TEENY 0
#define RUBY_API_VERSION_CODE (RUBY_API_VERSION_MAJOR*10000+RUBY_API_VERSION_MINOR*100+RUBY_API_VERSION_TEENY)

#endif
7 changes: 6 additions & 1 deletion spec/ruby/optional/capi/ext/array_spec.c
Original file line number Diff line number Diff line change
@@ -35,7 +35,9 @@ static VALUE array_spec_RARRAY_PTR_assign(VALUE self, VALUE array, VALUE value)
}
return Qnil;
}
#endif

#ifdef HAVE_RARRAY_LEN
static VALUE array_spec_RARRAY_LEN(VALUE self, VALUE array) {
return INT2FIX(RARRAY_LEN(array));
}
@@ -272,8 +274,11 @@ void Init_array_spec() {
rb_define_method(cls, "rb_Array", array_spec_rb_Array, 1);
#endif

#if defined(HAVE_RARRAY_LEN) && defined(HAVE_RARRAY_PTR)
#ifdef HAVE_RARRAY_LEN
rb_define_method(cls, "RARRAY_LEN", array_spec_RARRAY_LEN, 1);
#endif

#if defined(HAVE_RARRAY_LEN) && defined(HAVE_RARRAY_PTR)
rb_define_method(cls, "RARRAY_PTR_iterate", array_spec_RARRAY_PTR_iterate, 1);
rb_define_method(cls, "RARRAY_PTR_assign", array_spec_RARRAY_PTR_assign, 2);
#endif
8 changes: 0 additions & 8 deletions spec/ruby/optional/capi/ext/jruby_truffle.h
Original file line number Diff line number Diff line change
@@ -13,17 +13,11 @@

/* Array */
#undef HAVE_RB_ARRAY
#ifdef RUBY_VERSION_IS_2_1
#undef HAVE_RARRAY_AREF
#endif
#undef HAVE_RARRAY_LEN
#undef HAVE_RARRAY_PTR
#undef HAVE_RB_ARY_AREF
#undef HAVE_RB_ARY_CLEAR
#undef HAVE_RB_ARY_DELETE
#undef HAVE_RB_ARY_DELETE_AT
#undef HAVE_RB_ARY_DUP
#undef HAVE_RB_ARY_ENTRY
#undef HAVE_RB_ARY_FREEZE
#undef HAVE_RB_ARY_INCLUDES
#undef HAVE_RB_ARY_JOIN
@@ -32,8 +26,6 @@
#undef HAVE_RB_ARY_NEW_FROM_ARGS
#endif
#undef HAVE_RB_ARY_NEW4
#undef HAVE_RB_ARY_POP
#undef HAVE_RB_ARY_PUSH
#undef HAVE_RB_ARY_REVERSE
#undef HAVE_RB_ARY_SHIFT
#undef HAVE_RB_ARY_STORE
8 changes: 0 additions & 8 deletions spec/truffle/tags/optional/capi/array_tags.txt
Original file line number Diff line number Diff line change
@@ -4,17 +4,11 @@ fails:C-API Array function rb_Array returns obj wrapped in an array if it cannot
fails:C-API Array function rb_ary_new3 returns an array with the passed cardinality and varargs
fails:C-API Array function rb_ary_new_from_args returns an array with the passed cardinality and varargs
fails:C-API Array function rb_ary_new4 returns returns an array with the passed values
fails:C-API Array function rb_ary_push adds an element to the array
fails:C-API Array function rb_ary_pop removes and returns the last element in the array
fails:C-API Array function rb_ary_join joins elements of an array with a string
fails:C-API Array function rb_ary_to_s creates an Array literal representation as a String
fails:C-API Array function rb_ary_reverse reverses the order of elements in the array
fails:C-API Array function rb_ary_reverse returns the original array
fails:C-API Array function rb_ary_entry returns nil when passed an empty array
fails:C-API Array function rb_ary_entry returns elements from the end when passed a negative index
fails:C-API Array function rb_ary_entry returns nil if the index is out of range
fails:C-API Array function rb_ary_clear removes all elements from the array
fails:C-API Array function rb_ary_dup duplicates the array
fails:C-API Array function rb_ary_unshift prepends the element to the array
fails:C-API Array function rb_ary_shift removes and returns the first element
fails:C-API Array function rb_ary_shift returns nil when the array is empty
@@ -26,8 +20,6 @@ fails:C-API Array function rb_ary_concat concats two arrays
fails:C-API Array function rb_ary_plus adds two arrays together
fails:C-API Array function RARRAY_PTR returns a pointer to a C array of the array's elements
fails:C-API Array function RARRAY_PTR allows assigning to the elements of the C array
fails:C-API Array function RARRAY_LEN returns the size of the array
fails:C-API Array function RARRAY_AREF returns an element from the array
fails:C-API Array function rb_assoc_new returns an array containing the two elements
fails:C-API Array function rb_ary_includes returns true if the array includes the element
fails:C-API Array function rb_ary_includes returns false if the array does not include the element
66 changes: 49 additions & 17 deletions truffle/src/main/c/cext/ruby.c
Original file line number Diff line number Diff line change
@@ -14,6 +14,8 @@

#define RUBY_CEXT truffle_import_cached("ruby_cext")

// Constants

VALUE get_Qfalse() {
return (VALUE) truffle_read(RUBY_CEXT, "Qfalse");
}
@@ -42,6 +44,8 @@ VALUE get_rb_eRuntimeError() {
return (VALUE) truffle_read(RUBY_CEXT, "rb_eRuntimeError");
}

// Conversions

int NUM2INT(VALUE value) {
return truffle_invoke_i(RUBY_CEXT, "NUM2INT", value);
}
@@ -86,14 +90,20 @@ VALUE LONG2FIX(long value) {
return (VALUE) truffle_invoke(RUBY_CEXT, "LONG2FIX", value);
}

// Type checks

int FIXNUM_P(VALUE value) {
return truffle_invoke_i(RUBY_CEXT, "FIXNUM_P", value);
}

// Float

VALUE rb_float_new(double value) {
return (VALUE) truffle_invoke(RUBY_CEXT, "rb_float_new", value);
}

// String

char *RSTRING_PTR(VALUE string) {
// Needs to return a fake char* which actually calls back into Ruby when read or written
return (char*) truffle_invoke(RUBY_CEXT, "RSTRING_PTR", string);
@@ -103,14 +113,6 @@ int RSTRING_LEN(VALUE string) {
return truffle_get_size(string);
}

VALUE rb_ary_dup(VALUE array) {
return (VALUE) truffle_invoke(array, "dup");
}

ID rb_intern(const char *string) {
return (ID) truffle_invoke(RUBY_CEXT, "rb_intern", string);
}

VALUE rb_str_new2(const char *string) {
return (VALUE) truffle_invoke(RUBY_CEXT, "rb_str_new2", truffle_read_string(string));
}
@@ -119,29 +121,41 @@ VALUE rb_intern_str(VALUE string) {
return (VALUE) truffle_invoke(RUBY_CEXT, "rb_intern_str", string);
}

void rb_str_cat(VALUE string, const char *to_concat, long length) {
truffle_invoke(RUBY_CEXT, "rb_str_cat", string, truffle_read_string(to_concat), length);
}

// Symbol

ID rb_intern(const char *string) {
return (ID) truffle_invoke(RUBY_CEXT, "rb_intern", string);
}

VALUE ID2SYM(ID id) {
return truffle_invoke(RUBY_CEXT, "ID2SYM", id);
}

void rb_str_cat(VALUE string, const char *to_concat, long length) {
truffle_invoke(RUBY_CEXT, "rb_str_cat", string, truffle_read_string(to_concat), length);
}
// Array

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

int RARRAY_LENINT(VALUE array) {
return truffle_get_size(array);
}

VALUE *RARRAY_PTR(VALUE array) {
// Needs to return a fake VALUE* which actually calls back into Ruby when read or written
return (VALUE*) truffle_invoke(RUBY_CEXT, "RARRAY_PTR", array);
}

VALUE rb_ary_new_capa(long capacity) {
return (VALUE) truffle_invoke(RUBY_CEXT, "rb_ary_new_capa", capacity);
VALUE RARRAY_AREF(VALUE array, long index) {
return truffle_read_idx(array, (int) index);
}

VALUE rb_ary_new2() {
return (VALUE) truffle_invoke(RUBY_CEXT, "rb_ary_new2");
VALUE rb_ary_new_capa(long capacity) {
return (VALUE) truffle_invoke(RUBY_CEXT, "rb_ary_new_capa", capacity);
}

VALUE rb_ary_new() {
@@ -152,6 +166,10 @@ void rb_ary_push(VALUE array, VALUE value) {
truffle_invoke(array, "push", value);
}

VALUE rb_ary_pop(VALUE array) {
return truffle_invoke(array, "pop");
}

void rb_ary_store(VALUE array, long index, VALUE value) {
truffle_write_idx(array, (int) index, value);
}
@@ -160,10 +178,12 @@ VALUE rb_ary_entry(VALUE array, long index) {
return truffle_read_idx(array, (int) index);
}

int RARRAY_LENINT(VALUE array) {
return truffle_get_size(array);
VALUE rb_ary_dup(VALUE array) {
return (VALUE) truffle_invoke(array, "dup");
}

// Hash

VALUE rb_hash_new() {
return (VALUE) truffle_invoke(RUBY_CEXT, "rb_hash_new");
}
@@ -176,14 +196,20 @@ void rb_hash_aset(VALUE hash, VALUE key, VALUE value) {
truffle_write(hash, key, value);
}

// Utilities

void rb_scan_args(int argc, VALUE *argv, const char *format, ...) {
truffle_invoke(RUBY_CEXT, "rb_scan_args", argc, argv, format /*, where to get args? */);
}

// Calls

VALUE rb_funcall(VALUE object, ID name, int argc, ...) {
return truffle_invoke(object, name /*, where to get args? */);
}

// Instance variables

VALUE rb_iv_get(VALUE object, const char *name) {
return truffle_read(object, truffle_read_string(name));
}
@@ -193,14 +219,20 @@ VALUE rb_iv_set(VALUE object, const char *name, VALUE value) {
return value;
}

// Accessing constants

VALUE rb_const_get(VALUE object, ID name) {
return truffle_invoke(object, "const_get", name);
}

// Raising exceptions

void rb_raise(VALUE exception, const char *format, ...) {
truffle_invoke(RUBY_CEXT, "rb_raise", format /*, where to get args? */);
}

// Defining classes, modules and methods

VALUE rb_define_class(const char *name, VALUE superclass) {
return truffle_invoke(RUBY_CEXT, "rb_define_class", truffle_read_string(name), superclass);
}
8 changes: 2 additions & 6 deletions truffle/src/main/ruby/core/truffle/cext.rb
Original file line number Diff line number Diff line change
@@ -78,15 +78,11 @@ def RARRAY_PTR(array)
array
end

def rb_ary_new_capa(capacity)
[]
end

def rb_ary_new2
def rb_ary_new
[]
end

def rb_ary_new
def rb_ary_new_capa(capacity)
[]
end