Skip to content

Commit

Permalink
Showing 7 changed files with 26 additions and 16 deletions.
3 changes: 0 additions & 3 deletions spec/ruby/optional/capi/ext/jruby_truffle.h
Original file line number Diff line number Diff line change
@@ -175,7 +175,6 @@
#undef HAVE_RB_OBJ_ENCODING

#undef HAVE_RB_STR_ENCODE
#undef HAVE_RB_STR_NEW_CSTR
#undef HAVE_RB_USASCII_STR_NEW
#undef HAVE_RB_USASCII_STR_NEW_CSTR
#undef HAVE_RB_EXTERNAL_STR_NEW
@@ -409,8 +408,6 @@
#undef HAVE_RB_STR_UPDATE
#undef HAVE_RB_STR_INSPECT
#undef HAVE_RB_STR_INTERN
#undef HAVE_RB_STR_NEW
#undef HAVE_RB_STR_NEW2
#undef HAVE_RB_STR_NEW3
#undef HAVE_RB_STR_NEW4
#undef HAVE_RB_STR_NEW5
3 changes: 2 additions & 1 deletion spec/ruby/optional/capi/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -110,7 +110,8 @@ def compile_extension_jruby_truffle(name)
f.puts "out: #{output_file}"
end

system "#{RbConfig::CONFIG['bindir']}/jruby", "#{RbConfig::CONFIG['bindir']}/../tool/jt.rb", 'cextc', extension_path
system "#{RbConfig::CONFIG['bindir']}/../tool/jt.rb", 'cextc', extension_path
raise "Compilation of #{extension_path} failed" unless $?.success?

output_file
ensure
5 changes: 0 additions & 5 deletions spec/truffle/tags/optional/capi/string_tags.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
fails:C-API String function rb_str_set_len reduces the size of the string
fails:C-API String function rb_str_set_len inserts a NULL byte at the length
fails:C-API String function rb_str_set_len updates the string's attributes visible in C code
fails:C-API String function rb_str_buf_new returns the equivalent of an empty string
fails:C-API String function rb_str_buf_new returns a string that can be appended to
fails:C-API String function rb_str_buf_new returns a string that can be concatenated to another string
fails:C-API String function rb_str_buf_new returns a string whose bytes can be accessed by RSTRING_PTR
fails:C-API String function rb_str_buf_new returns a string that can be modified by rb_str_set_len
fails:C-API String function rb_str_buf_new2 returns a new string object calling strlen on the passed C string
fails:C-API String function rb_str_new returns a new string object from a char buffer of len characters
fails:C-API String function rb_str_new returns an empty string if len is 0
fails:C-API String function rb_str_new2 returns a new string object calling strlen on the passed C string
fails:C-API String function rb_str_new2 encodes the string with ASCII_8BIT
fails:C-API String function rb_str_new creates a new String with ASCII-8BIT Encoding
fails:C-API String function rb_str_new_cstr returns a new string object calling strlen on the passed C string
fails:C-API String function rb_str_new_cstr encodes the string with ASCII_8BIT
fails:C-API String function rb_usascii_str_new creates a new String with US-ASCII Encoding from a char buffer of len characters
@@ -53,7 +49,6 @@ fails:C-API String function rb_str_subseq returns a byte-indexed substring
fails:C-API String function rb_str_substr returns a substring
fails:C-API String function rb_str_to_str calls #to_str to coerce the value to a String
fails:C-API String function rb_str_to_str raises a TypeError if coercion fails
fails:C-API String function RSTRING_LEN returns the size of the string
fails:C-API String function RSTRING_LENINT returns the size of a string
fails:C-API String function StringValue does not call #to_str on a String
fails:C-API String function StringValue does not call #to_s on a String
19 changes: 14 additions & 5 deletions tool/jt.rb
Original file line number Diff line number Diff line change
@@ -351,28 +351,33 @@ def mx(dir, *args)
sh *command
end

def mx_sulong(*args)
abort "You need to set SULONG_HOME" unless SULONG_HOME
mx SULONG_HOME, *args
end

def clang(*args)
if ENV['USE_SYSTEM_CLANG']
sh 'clang', *args
else
mx SULONG_HOME, 'su-clang', *args
mx_sulong 'su-clang', *args
end
end

def llvm_opt(*args)
if ENV['USE_SYSTEM_CLANG']
sh 'opt', *args
else
mx SULONG_HOME, 'su-opt', *args
mx_sulong 'su-opt', *args
end
end

def sulong_run(*args)
mx SULONG_HOME, 'su-run', *args
mx_sulong 'su-run', *args
end

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

def mspec(command, *args)
@@ -611,6 +616,8 @@ def command_p(*args)
end

def cextc(cext_dir, *clang_opts)
abort "You need to set SULONG_HOME" unless SULONG_HOME

config_file = File.join(cext_dir, '.jruby-cext-build.yml')

unless File.exist?(config_file)
@@ -657,7 +664,9 @@ def cextc(cext_dir, *clang_opts)
end
end

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

sulong_link '-o', out, *config_libs, *lls
end

def test(*args)
6 changes: 5 additions & 1 deletion truffle/src/main/c/cext/ruby.c
Original file line number Diff line number Diff line change
@@ -158,7 +158,11 @@ int RSTRING_LEN(VALUE string) {
}

VALUE rb_str_new(const char *string, long length) {
return (VALUE) truffle_invoke(RUBY_CEXT, "rb_str_new_cstr", truffle_read_n_string(string, length));
if (truffle_is_truffle_object((VALUE) string)) {
return truffle_invoke(RUBY_CEXT, "rb_str_new", string, length);
} else {
return (VALUE) truffle_invoke(RUBY_CEXT, "rb_str_new_cstr", truffle_read_n_string(string, length));
}
}

VALUE rb_str_new_cstr(const char *string) {
Original file line number Diff line number Diff line change
@@ -1275,7 +1275,7 @@ public DynamicObject initialize(DynamicObject self, NotProvided from) {
@Specialization
public DynamicObject initializeJavaString(DynamicObject self, String from) {
raiseIfFrozen(self);
StringOperations.setRope(self, StringOperations.createRope(from, UTF8Encoding.INSTANCE));
StringOperations.setRope(self, StringOperations.createRope(from, ASCIIEncoding.INSTANCE));
return self;
}

4 changes: 4 additions & 0 deletions truffle/src/main/ruby/core/truffle/cext.rb
Original file line number Diff line number Diff line change
@@ -101,6 +101,10 @@ def rb_intern(str)
str.intern
end

def rb_str_new(cext_str, length)
to_ruby_string(cext_str)[0, length].b
end

def rb_str_new_cstr(java_string)
String.new(java_string)
end

0 comments on commit 0d79d02

Please sign in to comment.