summaryrefslogtreecommitdiff
path: root/spec/ruby/optional/capi/ext
diff options
context:
space:
mode:
authoreregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-06-13 21:58:54 +0000
committereregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-06-13 21:58:54 +0000
commitb46da8d84efeb97cb52ba0560d5b149ccda0d561 (patch)
tree382ba848ef97215f1a5ec991727db3ed7f90973c /spec/ruby/optional/capi/ext
parent5b55eaa00db05004d1a6b74c3aaa5e680fc73235 (diff)
Update to ruby/spec@4bb0f25
* Specs added by TruffleRuby. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63654 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/optional/capi/ext')
-rw-r--r--spec/ruby/optional/capi/ext/string_spec.c46
1 files changed, 44 insertions, 2 deletions
diff --git a/spec/ruby/optional/capi/ext/string_spec.c b/spec/ruby/optional/capi/ext/string_spec.c
index 929d69f9e5..1b9c11a149 100644
--- a/spec/ruby/optional/capi/ext/string_spec.c
+++ b/spec/ruby/optional/capi/ext/string_spec.c
@@ -12,6 +12,19 @@
extern "C" {
#endif
+/* Make sure the RSTRING_PTR and the bytes are in native memory.
+ * On TruffleRuby RSTRING_PTR and the bytes remain in managed memory
+ * until they must be written to native memory.
+ * In some specs we want to test using the native memory. */
+char* NATIVE_RSTRING_PTR(VALUE str) {
+ char* ptr = RSTRING_PTR(str);
+ char** native = malloc(sizeof(char*));
+ *native = ptr;
+ ptr = *native;
+ free(native);
+ return ptr;
+}
+
#ifdef HAVE_RB_CSTR2INUM
VALUE string_spec_rb_cstr2inum(VALUE self, VALUE str, VALUE inum) {
int num = FIX2INT(inum);
@@ -65,6 +78,10 @@ VALUE string_spec_rb_str_buf_new(VALUE self, VALUE len, VALUE str) {
return buf;
}
+
+VALUE string_spec_rb_str_capacity(VALUE self, VALUE str) {
+ return SIZET2NUM(rb_str_capacity(str));
+}
#endif
#ifdef HAVE_RB_STR_BUF_NEW2
@@ -182,6 +199,10 @@ VALUE string_spec_rb_str_new(VALUE self, VALUE str, VALUE len) {
return rb_str_new(RSTRING_PTR(str), FIX2INT(len));
}
+VALUE string_spec_rb_str_new_native(VALUE self, VALUE str, VALUE len) {
+ return rb_str_new(NATIVE_RSTRING_PTR(str), FIX2INT(len));
+}
+
VALUE string_spec_rb_str_new_offset(VALUE self, VALUE str, VALUE offset, VALUE len) {
return rb_str_new(RSTRING_PTR(str) + FIX2INT(offset), FIX2INT(len));
}
@@ -358,6 +379,11 @@ VALUE string_spec_RSTRING_PTR_assign(VALUE self, VALUE str, VALUE chr) {
return Qnil;
}
+VALUE string_spec_RSTRING_PTR_set(VALUE self, VALUE str, VALUE i, VALUE chr) {
+ RSTRING_PTR(str)[FIX2INT(i)] = (char) FIX2INT(chr);
+ return str;
+}
+
VALUE string_spec_RSTRING_PTR_after_funcall(VALUE self, VALUE str, VALUE cb) {
/* Silence gcc 4.3.2 warning about computed value not used */
if(RSTRING_PTR(str)) { /* force it out */
@@ -366,6 +392,19 @@ VALUE string_spec_RSTRING_PTR_after_funcall(VALUE self, VALUE str, VALUE cb) {
return rb_str_new2(RSTRING_PTR(str));
}
+
+VALUE string_spec_RSTRING_PTR_after_yield(VALUE self, VALUE str) {
+ char* ptr = NATIVE_RSTRING_PTR(str);
+ long len = RSTRING_LEN(str);
+ VALUE from_rstring_ptr;
+
+ ptr[0] = '1';
+ rb_yield(str);
+ ptr[2] = '2';
+
+ from_rstring_ptr = rb_str_new(ptr, len);
+ return from_rstring_ptr;
+}
#endif
#ifdef HAVE_STRINGVALUE
@@ -480,6 +519,7 @@ void Init_string_spec(void) {
#ifdef HAVE_RB_STR_BUF_NEW
rb_define_method(cls, "rb_str_buf_new", string_spec_rb_str_buf_new, 2);
+ rb_define_method(cls, "rb_str_capacity", string_spec_rb_str_capacity, 1);
#endif
#ifdef HAVE_RB_STR_BUF_NEW2
@@ -540,6 +580,7 @@ void Init_string_spec(void) {
#ifdef HAVE_RB_STR_NEW
rb_define_method(cls, "rb_str_new", string_spec_rb_str_new, 2);
+ rb_define_method(cls, "rb_str_new_native", string_spec_rb_str_new_native, 2);
rb_define_method(cls, "rb_str_new_offset", string_spec_rb_str_new_offset, 3);
#endif
@@ -643,8 +684,9 @@ void Init_string_spec(void) {
#ifdef HAVE_RSTRING_PTR
rb_define_method(cls, "RSTRING_PTR_iterate", string_spec_RSTRING_PTR_iterate, 1);
rb_define_method(cls, "RSTRING_PTR_assign", string_spec_RSTRING_PTR_assign, 2);
- rb_define_method(cls, "RSTRING_PTR_after_funcall",
- string_spec_RSTRING_PTR_after_funcall, 2);
+ rb_define_method(cls, "RSTRING_PTR_set", string_spec_RSTRING_PTR_set, 3);
+ rb_define_method(cls, "RSTRING_PTR_after_funcall", string_spec_RSTRING_PTR_after_funcall, 2);
+ rb_define_method(cls, "RSTRING_PTR_after_yield", string_spec_RSTRING_PTR_after_yield, 1);
#endif
#ifdef HAVE_STRINGVALUE