Skip to content

Commit

Permalink
[Truffle] Fix rb_str_new for NULL string.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisseaton committed Sep 6, 2016
1 parent affe1ce commit 9121a0e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 3 additions & 1 deletion truffle/src/main/c/cext/ruby.c
Expand Up @@ -350,7 +350,9 @@ int rb_str_len(VALUE string) {
}

VALUE rb_str_new(const char *string, long length) {
if (truffle_is_truffle_object((VALUE) string)) {
if (string == NULL) {
return (VALUE) truffle_invoke(RUBY_CEXT, "rb_str_new_nul", length);
} else if (truffle_is_truffle_object((VALUE) string)) {
return (VALUE) 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));
Expand Down
4 changes: 4 additions & 0 deletions truffle/src/main/ruby/core/truffle/cext.rb
Expand Up @@ -292,6 +292,10 @@ def rb_str_new(cext_str, length)
to_ruby_string(cext_str)[0, length].b
end

def rb_str_new_nul(length)
'\0' * length
end

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

0 comments on commit 9121a0e

Please sign in to comment.