aboutsummaryrefslogtreecommitdiffstats
path: root/spec/ruby/optional/capi/ext
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/optional/capi/ext')
-rw-r--r--spec/ruby/optional/capi/ext/array_spec.c6
-rw-r--r--spec/ruby/optional/capi/ext/bignum_spec.c4
-rw-r--r--spec/ruby/optional/capi/ext/boolean_spec.c2
-rw-r--r--spec/ruby/optional/capi/ext/class_id_under_autoload_spec.c8
-rw-r--r--spec/ruby/optional/capi/ext/class_spec.c2
-rw-r--r--spec/ruby/optional/capi/ext/class_under_autoload_spec.c8
-rw-r--r--spec/ruby/optional/capi/ext/data_spec.c8
-rw-r--r--spec/ruby/optional/capi/ext/gc_spec.c6
-rw-r--r--spec/ruby/optional/capi/ext/globals_spec.c8
-rw-r--r--spec/ruby/optional/capi/ext/integer_spec.c2
-rw-r--r--spec/ruby/optional/capi/ext/io_spec.c6
-rw-r--r--spec/ruby/optional/capi/ext/kernel_spec.c6
-rw-r--r--spec/ruby/optional/capi/ext/language_spec.c34
-rw-r--r--spec/ruby/optional/capi/ext/module_under_autoload_spec.c8
-rw-r--r--spec/ruby/optional/capi/ext/numeric_spec.c5
-rw-r--r--spec/ruby/optional/capi/ext/object_spec.c2
-rw-r--r--spec/ruby/optional/capi/ext/proc_spec.c5
-rw-r--r--spec/ruby/optional/capi/ext/rubyspec.h26
-rw-r--r--spec/ruby/optional/capi/ext/string_spec.c26
-rw-r--r--spec/ruby/optional/capi/ext/symbol_spec.c5
-rw-r--r--spec/ruby/optional/capi/ext/thread_spec.c4
-rw-r--r--spec/ruby/optional/capi/ext/typed_data_spec.c51
-rw-r--r--spec/ruby/optional/capi/ext/util_spec.c4
23 files changed, 186 insertions, 50 deletions
diff --git a/spec/ruby/optional/capi/ext/array_spec.c b/spec/ruby/optional/capi/ext/array_spec.c
index 454cf03303..afd6aeef15 100644
--- a/spec/ruby/optional/capi/ext/array_spec.c
+++ b/spec/ruby/optional/capi/ext/array_spec.c
@@ -54,6 +54,11 @@ static VALUE array_spec_RARRAY_AREF(VALUE self, VALUE array, VALUE index) {
return RARRAY_AREF(array, FIX2INT(index));
}
+static VALUE array_spec_RARRAY_ASET(VALUE self, VALUE array, VALUE index, VALUE value) {
+ RARRAY_ASET(array, FIX2INT(index), value);
+ return value;
+}
+
static VALUE array_spec_rb_ary_aref(int argc, VALUE *argv, VALUE self) {
VALUE ary, args;
rb_scan_args(argc, argv, "1*", &ary, &args);
@@ -244,6 +249,7 @@ void Init_array_spec(void) {
rb_define_method(cls, "RARRAY_PTR_assign", array_spec_RARRAY_PTR_assign, 2);
rb_define_method(cls, "RARRAY_PTR_memcpy", array_spec_RARRAY_PTR_memcpy, 2);
rb_define_method(cls, "RARRAY_AREF", array_spec_RARRAY_AREF, 2);
+ rb_define_method(cls, "RARRAY_ASET", array_spec_RARRAY_ASET, 3);
rb_define_method(cls, "rb_ary_aref", array_spec_rb_ary_aref, -1);
rb_define_method(cls, "rb_ary_clear", array_spec_rb_ary_clear, 1);
rb_define_method(cls, "rb_ary_delete", array_spec_rb_ary_delete, 2);
diff --git a/spec/ruby/optional/capi/ext/bignum_spec.c b/spec/ruby/optional/capi/ext/bignum_spec.c
index 14a51f5099..a950d8b16f 100644
--- a/spec/ruby/optional/capi/ext/bignum_spec.c
+++ b/spec/ruby/optional/capi/ext/bignum_spec.c
@@ -65,7 +65,7 @@ static VALUE bignum_spec_rb_big_pack_array(VALUE self, VALUE val, VALUE len) {
long long_len = NUM2LONG(len);
VALUE ary = rb_ary_new_capa(long_len);
- unsigned long *buf = malloc(long_len * SIZEOF_LONG);
+ unsigned long *buf = (unsigned long*) malloc(long_len * SIZEOF_LONG);
/* The array should be filled with recognisable junk so we can check
it is all cleared properly. */
@@ -102,5 +102,5 @@ void Init_bignum_spec(void) {
}
#ifdef __cplusplus
-extern "C" {
+}
#endif
diff --git a/spec/ruby/optional/capi/ext/boolean_spec.c b/spec/ruby/optional/capi/ext/boolean_spec.c
index 7bb6fe569d..081cffa103 100644
--- a/spec/ruby/optional/capi/ext/boolean_spec.c
+++ b/spec/ruby/optional/capi/ext/boolean_spec.c
@@ -29,5 +29,5 @@ void Init_boolean_spec(void) {
}
#ifdef __cplusplus
-extern "C" {
+}
#endif
diff --git a/spec/ruby/optional/capi/ext/class_id_under_autoload_spec.c b/spec/ruby/optional/capi/ext/class_id_under_autoload_spec.c
index 64393a9397..cc5550f041 100644
--- a/spec/ruby/optional/capi/ext/class_id_under_autoload_spec.c
+++ b/spec/ruby/optional/capi/ext/class_id_under_autoload_spec.c
@@ -1,5 +1,13 @@
#include "ruby.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
void Init_class_id_under_autoload_spec(void) {
rb_define_class_id_under(rb_cObject, rb_intern("ClassIdUnderAutoload"), rb_cObject);
}
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/spec/ruby/optional/capi/ext/class_spec.c b/spec/ruby/optional/capi/ext/class_spec.c
index 6e5c02e657..e62b9efe2e 100644
--- a/spec/ruby/optional/capi/ext/class_spec.c
+++ b/spec/ruby/optional/capi/ext/class_spec.c
@@ -45,7 +45,7 @@ static VALUE class_spec_rb_class_new_instance(VALUE self,
VALUE nargs, VALUE args,
VALUE klass) {
int c_nargs = FIX2INT(nargs);
- VALUE *c_args = alloca(sizeof(VALUE) * c_nargs);
+ VALUE *c_args = (VALUE*)alloca(sizeof(VALUE) * c_nargs);
int i;
for (i = 0; i < c_nargs; i++)
diff --git a/spec/ruby/optional/capi/ext/class_under_autoload_spec.c b/spec/ruby/optional/capi/ext/class_under_autoload_spec.c
index 120dec7327..e0b1f249c0 100644
--- a/spec/ruby/optional/capi/ext/class_under_autoload_spec.c
+++ b/spec/ruby/optional/capi/ext/class_under_autoload_spec.c
@@ -1,5 +1,13 @@
#include "ruby.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
void Init_class_under_autoload_spec(void) {
rb_define_class_under(rb_cObject, "ClassUnderAutoload", rb_cObject);
}
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/spec/ruby/optional/capi/ext/data_spec.c b/spec/ruby/optional/capi/ext/data_spec.c
index a41666f655..109bded1d1 100644
--- a/spec/ruby/optional/capi/ext/data_spec.c
+++ b/spec/ruby/optional/capi/ext/data_spec.c
@@ -19,7 +19,7 @@ void sample_wrapped_struct_mark(void* st) {
}
VALUE sdaf_alloc_func(VALUE klass) {
- struct sample_wrapped_struct* bar = malloc(sizeof(struct sample_wrapped_struct));
+ struct sample_wrapped_struct* bar = (struct sample_wrapped_struct*) malloc(sizeof(struct sample_wrapped_struct));
bar->foo = 42;
return Data_Wrap_Struct(klass, &sample_wrapped_struct_mark, &sample_wrapped_struct_free, bar);
}
@@ -32,7 +32,7 @@ VALUE sdaf_get_struct(VALUE self) {
}
VALUE sws_wrap_struct(VALUE self, VALUE val) {
- struct sample_wrapped_struct* bar = malloc(sizeof(struct sample_wrapped_struct));
+ struct sample_wrapped_struct* bar = (struct sample_wrapped_struct*) malloc(sizeof(struct sample_wrapped_struct));
bar->foo = FIX2INT(val);
return Data_Wrap_Struct(rb_cObject, &sample_wrapped_struct_mark, &sample_wrapped_struct_free, bar);
}
@@ -58,9 +58,9 @@ VALUE sws_get_struct_data_ptr(VALUE self, VALUE obj) {
VALUE sws_change_struct(VALUE self, VALUE obj, VALUE new_val) {
struct sample_wrapped_struct *old_struct, *new_struct;
- new_struct = malloc(sizeof(struct sample_wrapped_struct));
+ new_struct = (struct sample_wrapped_struct*) malloc(sizeof(struct sample_wrapped_struct));
new_struct->foo = FIX2INT(new_val);
- old_struct = RDATA(obj)->data;
+ old_struct = (struct sample_wrapped_struct*) RDATA(obj)->data;
free(old_struct);
RDATA(obj)->data = new_struct;
return Qnil;
diff --git a/spec/ruby/optional/capi/ext/gc_spec.c b/spec/ruby/optional/capi/ext/gc_spec.c
index 983b021df9..4611617c18 100644
--- a/spec/ruby/optional/capi/ext/gc_spec.c
+++ b/spec/ruby/optional/capi/ext/gc_spec.c
@@ -16,15 +16,15 @@ static VALUE registered_reference_address(VALUE self) {
return registered_reference_value;
}
-static VALUE gc_spec_rb_gc_enable() {
+static VALUE gc_spec_rb_gc_enable(VALUE self) {
return rb_gc_enable();
}
-static VALUE gc_spec_rb_gc_disable() {
+static VALUE gc_spec_rb_gc_disable(VALUE self) {
return rb_gc_disable();
}
-static VALUE gc_spec_rb_gc() {
+static VALUE gc_spec_rb_gc(VALUE self) {
rb_gc();
return Qnil;
}
diff --git a/spec/ruby/optional/capi/ext/globals_spec.c b/spec/ruby/optional/capi/ext/globals_spec.c
index f70622f66c..75860d3774 100644
--- a/spec/ruby/optional/capi/ext/globals_spec.c
+++ b/spec/ruby/optional/capi/ext/globals_spec.c
@@ -7,12 +7,16 @@ extern "C" {
VALUE g_hooked_var;
+VALUE var_2x_getter(ID id, VALUE *data) {
+ return *data;
+}
+
void var_2x_setter(VALUE val, ID id, VALUE *var) {
- *var = INT2NUM(NUM2INT(val) * 2);
+ *var = INT2NUM(NUM2INT(val) * 2);
}
static VALUE sb_define_hooked_variable(VALUE self, VALUE var_name) {
- rb_define_hooked_variable(StringValuePtr(var_name), &g_hooked_var, 0, var_2x_setter);
+ rb_define_hooked_variable(StringValuePtr(var_name), &g_hooked_var, var_2x_getter, var_2x_setter);
return Qnil;
}
diff --git a/spec/ruby/optional/capi/ext/integer_spec.c b/spec/ruby/optional/capi/ext/integer_spec.c
index 7e9e8b26bd..124591e231 100644
--- a/spec/ruby/optional/capi/ext/integer_spec.c
+++ b/spec/ruby/optional/capi/ext/integer_spec.c
@@ -30,5 +30,5 @@ void Init_integer_spec(void) {
}
#ifdef __cplusplus
-extern "C" {
+}
#endif
diff --git a/spec/ruby/optional/capi/ext/io_spec.c b/spec/ruby/optional/capi/ext/io_spec.c
index 45f57810db..59613c110f 100644
--- a/spec/ruby/optional/capi/ext/io_spec.c
+++ b/spec/ruby/optional/capi/ext/io_spec.c
@@ -43,7 +43,7 @@ VALUE io_spec_rb_io_addstr(VALUE self, VALUE io, VALUE str) {
VALUE io_spec_rb_io_printf(VALUE self, VALUE io, VALUE ary) {
long argc = RARRAY_LEN(ary);
- VALUE *argv = alloca(sizeof(VALUE) * argc);
+ VALUE *argv = (VALUE*) alloca(sizeof(VALUE) * argc);
int i;
for (i = 0; i < argc; i++) {
@@ -55,7 +55,7 @@ VALUE io_spec_rb_io_printf(VALUE self, VALUE io, VALUE ary) {
VALUE io_spec_rb_io_print(VALUE self, VALUE io, VALUE ary) {
long argc = RARRAY_LEN(ary);
- VALUE *argv = alloca(sizeof(VALUE) * argc);
+ VALUE *argv = (VALUE*) alloca(sizeof(VALUE) * argc);
int i;
for (i = 0; i < argc; i++) {
@@ -67,7 +67,7 @@ VALUE io_spec_rb_io_print(VALUE self, VALUE io, VALUE ary) {
VALUE io_spec_rb_io_puts(VALUE self, VALUE io, VALUE ary) {
long argc = RARRAY_LEN(ary);
- VALUE *argv = alloca(sizeof(VALUE) * argc);
+ VALUE *argv = (VALUE*) alloca(sizeof(VALUE) * argc);
int i;
for (i = 0; i < argc; i++) {
diff --git a/spec/ruby/optional/capi/ext/kernel_spec.c b/spec/ruby/optional/capi/ext/kernel_spec.c
index c5bb4a1d9a..13d9598125 100644
--- a/spec/ruby/optional/capi/ext/kernel_spec.c
+++ b/spec/ruby/optional/capi/ext/kernel_spec.c
@@ -68,7 +68,7 @@ VALUE rb_block_call_extra_data(VALUE self, VALUE object) {
}
VALUE kernel_spec_rb_block_call_no_func(VALUE self, VALUE ary) {
- return rb_block_call(ary, rb_intern("map"), 0, NULL, NULL, Qnil);
+ return rb_block_call(ary, rb_intern("map"), 0, NULL, (rb_block_call_func_t)NULL, Qnil);
}
@@ -153,6 +153,10 @@ VALUE kernel_spec_rb_rescue(VALUE self, VALUE main_proc, VALUE arg,
rb_ary_push(main_array, main_proc);
rb_ary_push(main_array, arg);
+ if (raise_proc == Qnil) {
+ return rb_rescue(kernel_spec_call_proc, main_array, NULL, arg2);
+ }
+
raise_array = rb_ary_new();
rb_ary_push(raise_array, raise_proc);
rb_ary_push(raise_array, arg2);
diff --git a/spec/ruby/optional/capi/ext/language_spec.c b/spec/ruby/optional/capi/ext/language_spec.c
new file mode 100644
index 0000000000..5aeac63f53
--- /dev/null
+++ b/spec/ruby/optional/capi/ext/language_spec.c
@@ -0,0 +1,34 @@
+#include "ruby.h"
+#include "rubyspec.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+static VALUE language_spec_switch(VALUE self, VALUE value) {
+ if (value == ID2SYM(rb_intern("undef"))) {
+ value = Qundef;
+ }
+
+ switch (value) {
+ case Qtrue:
+ return ID2SYM(rb_intern("true"));
+ case Qfalse:
+ return ID2SYM(rb_intern("false"));
+ case Qnil:
+ return ID2SYM(rb_intern("nil"));
+ case Qundef:
+ return ID2SYM(rb_intern("undef"));
+ default:
+ return ID2SYM(rb_intern("default"));
+ }
+}
+
+void Init_language_spec(void) {
+ VALUE cls = rb_define_class("CApiLanguageSpecs", rb_cObject);
+ rb_define_method(cls, "switch", language_spec_switch, 1);
+}
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/spec/ruby/optional/capi/ext/module_under_autoload_spec.c b/spec/ruby/optional/capi/ext/module_under_autoload_spec.c
index c8f19a287b..b19466e555 100644
--- a/spec/ruby/optional/capi/ext/module_under_autoload_spec.c
+++ b/spec/ruby/optional/capi/ext/module_under_autoload_spec.c
@@ -1,7 +1,15 @@
#include "ruby.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
void Init_module_under_autoload_spec(void) {
VALUE specs = rb_const_get(rb_cObject, rb_intern("CApiModuleSpecs"));
rb_define_module_under(specs, "ModuleUnderAutoload");
rb_define_module_under(specs, "RubyUnderAutoload");
}
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/spec/ruby/optional/capi/ext/numeric_spec.c b/spec/ruby/optional/capi/ext/numeric_spec.c
index 556c71a587..33f3a18c00 100644
--- a/spec/ruby/optional/capi/ext/numeric_spec.c
+++ b/spec/ruby/optional/capi/ext/numeric_spec.c
@@ -61,6 +61,10 @@ static VALUE numeric_spec_NUM2LONG(VALUE self, VALUE num) {
return LONG2NUM(NUM2LONG(num));
}
+static VALUE numeric_spec_NUM2SHORT(VALUE self, VALUE num) {
+ return LONG2NUM(NUM2SHORT(num));
+}
+
static VALUE numeric_spec_NUM2UINT(VALUE self, VALUE num) {
return ULONG2NUM(NUM2UINT(num));
}
@@ -109,6 +113,7 @@ void Init_numeric_spec(void) {
rb_define_method(cls, "NUM2DBL", numeric_spec_NUM2DBL, 1);
rb_define_method(cls, "NUM2INT", numeric_spec_NUM2INT, 1);
rb_define_method(cls, "NUM2LONG", numeric_spec_NUM2LONG, 1);
+ rb_define_method(cls, "NUM2SHORT", numeric_spec_NUM2SHORT, 1);
rb_define_method(cls, "INT2NUM", numeric_spec_INT2NUM, 1);
rb_define_method(cls, "NUM2UINT", numeric_spec_NUM2UINT, 1);
rb_define_method(cls, "NUM2ULONG", numeric_spec_NUM2ULONG, 1);
diff --git a/spec/ruby/optional/capi/ext/object_spec.c b/spec/ruby/optional/capi/ext/object_spec.c
index 2151e37e5c..c95e1b553f 100644
--- a/spec/ruby/optional/capi/ext/object_spec.c
+++ b/spec/ruby/optional/capi/ext/object_spec.c
@@ -102,7 +102,7 @@ static VALUE so_rb_obj_dup(VALUE self, VALUE klass) {
static VALUE so_rb_obj_call_init(VALUE self, VALUE object,
VALUE nargs, VALUE args) {
int c_nargs = FIX2INT(nargs);
- VALUE *c_args = alloca(sizeof(VALUE) * c_nargs);
+ VALUE *c_args = (VALUE*) alloca(sizeof(VALUE) * c_nargs);
int i;
for (i = 0; i < c_nargs; i++)
diff --git a/spec/ruby/optional/capi/ext/proc_spec.c b/spec/ruby/optional/capi/ext/proc_spec.c
index 18fd1997ee..e0bd8b1bbc 100644
--- a/spec/ruby/optional/capi/ext/proc_spec.c
+++ b/spec/ruby/optional/capi/ext/proc_spec.c
@@ -23,6 +23,10 @@ VALUE proc_spec_rb_proc_call(VALUE self, VALUE prc, VALUE args) {
return rb_proc_call(prc, args);
}
+VALUE proc_spec_rb_obj_is_proc(VALUE self, VALUE prc) {
+ return rb_obj_is_proc(prc);
+}
+
/* This helper is not strictly necessary but reflects the code in wxRuby that
* originally exposed issues with this Proc.new behavior.
*/
@@ -61,6 +65,7 @@ void Init_proc_spec(void) {
rb_define_method(cls, "rb_proc_arity", proc_spec_rb_proc_arity, 1);
rb_define_method(cls, "rb_proc_call", proc_spec_rb_proc_call, 2);
rb_define_method(cls, "rb_Proc_new", proc_spec_rb_Proc_new, 1);
+ rb_define_method(cls, "rb_obj_is_proc", proc_spec_rb_obj_is_proc, 1);
}
#ifdef __cplusplus
diff --git a/spec/ruby/optional/capi/ext/rubyspec.h b/spec/ruby/optional/capi/ext/rubyspec.h
index 78e298fddb..cce3af22f2 100644
--- a/spec/ruby/optional/capi/ext/rubyspec.h
+++ b/spec/ruby/optional/capi/ext/rubyspec.h
@@ -23,6 +23,10 @@
(RUBY_VERSION_MAJOR == (major) && RUBY_VERSION_MINOR < (minor)) || \
(RUBY_VERSION_MAJOR == (major) && RUBY_VERSION_MINOR == (minor) && RUBY_VERSION_TEENY < (teeny)))
+#if RUBY_VERSION_MAJOR > 2 || (RUBY_VERSION_MAJOR == 2 && RUBY_VERSION_MINOR >= 7)
+#define RUBY_VERSION_IS_2_7
+#endif
+
#if RUBY_VERSION_MAJOR > 2 || (RUBY_VERSION_MAJOR == 2 && RUBY_VERSION_MINOR >= 6)
#define RUBY_VERSION_IS_2_6
#endif
@@ -31,4 +35,26 @@
#define RUBY_VERSION_IS_2_4
#endif
+#if defined(__cplusplus) && !defined(RUBY_VERSION_IS_2_7)
+/* Ruby < 2.7 needs this to let these function with callbacks and compile in C++ code */
+#define rb_define_method(mod, name, func, argc) rb_define_method(mod, name, RUBY_METHOD_FUNC(func), argc)
+#define rb_define_protected_method(mod, name, func, argc) rb_define_protected_method(mod, name, RUBY_METHOD_FUNC(func), argc)
+#define rb_define_private_method(mod, name, func, argc) rb_define_private_method(mod, name, RUBY_METHOD_FUNC(func), argc)
+#define rb_define_singleton_method(mod, name, func, argc) rb_define_singleton_method(mod, name, RUBY_METHOD_FUNC(func), argc)
+#define rb_define_module_function(mod, name, func, argc) rb_define_module_function(mod, name, RUBY_METHOD_FUNC(func), argc)
+#define rb_define_global_function(name, func, argc) rb_define_global_function(name, RUBY_METHOD_FUNC(func), argc)
+#define rb_iterate(function, arg1, block, arg2) rb_iterate(function, arg1, RUBY_METHOD_FUNC(block), arg2)
+#define rb_hash_foreach(hash, func, farg) rb_hash_foreach(hash, (int (*)(...))func, farg)
+#define st_foreach(tab, func, arg) st_foreach(tab, (int (*)(...))func, arg)
+#define rb_block_call(object, name, args_count, args, block_call_func, data) rb_block_call(object, name, args_count, args, RUBY_METHOD_FUNC(block_call_func), data)
+#define rb_ensure(b_proc, data1, e_proc, data2) rb_ensure(RUBY_METHOD_FUNC(b_proc), data1, RUBY_METHOD_FUNC(e_proc), data2)
+#define rb_rescue(b_proc, data1, e_proc, data2) rb_rescue(RUBY_METHOD_FUNC(b_proc), data1, RUBY_METHOD_FUNC(e_proc), data2)
+#define rb_rescue2(b_proc, data1, e_proc, data2, ...) rb_rescue2(RUBY_METHOD_FUNC(b_proc), data1, RUBY_METHOD_FUNC(e_proc), data2, __VA_ARGS__)
+#define rb_catch(tag, func, data) rb_catch(tag, RUBY_METHOD_FUNC(func), data)
+#define rb_catch_obj(tag, func, data) rb_catch_obj(tag, RUBY_METHOD_FUNC(func), data)
+#define rb_proc_new(fn, arg) rb_proc_new(RUBY_METHOD_FUNC(fn), arg)
+#define rb_thread_create(fn, arg) rb_thread_create(RUBY_METHOD_FUNC(fn), arg)
+#define rb_define_hooked_variable(name, var, getter, setter) rb_define_hooked_variable(name, var, RUBY_METHOD_FUNC(getter), (void (*)(...))setter)
+#endif
+
#endif
diff --git a/spec/ruby/optional/capi/ext/string_spec.c b/spec/ruby/optional/capi/ext/string_spec.c
index a44e437bba..97f6b031ef 100644
--- a/spec/ruby/optional/capi/ext/string_spec.c
+++ b/spec/ruby/optional/capi/ext/string_spec.c
@@ -284,6 +284,26 @@ VALUE string_spec_RSTRING_PTR_iterate(VALUE self, VALUE str) {
return Qnil;
}
+VALUE string_spec_RSTRING_PTR_iterate_uint32(VALUE self, VALUE str) {
+ int i;
+ uint32_t* ptr;
+ int l = RSTRING_LEN(str) / sizeof(uint32_t);
+
+ ptr = (uint32_t *)RSTRING_PTR(str);
+ for(i = 0; i < l; i++) {
+ rb_yield(UINT2NUM(ptr[i]));
+ }
+ return Qnil;
+}
+
+VALUE string_spec_RSTRING_PTR_short_memcpy(VALUE self, VALUE str) {
+ // Short memcpy operations may be optimised by the compiler to a single write.
+ if (RSTRING_LEN(str) >= 8) {
+ memcpy(RSTRING_PTR(str), "Infinity", 8);
+ }
+ return str;
+}
+
VALUE string_spec_RSTRING_PTR_assign(VALUE self, VALUE str, VALUE chr) {
int i;
char c;
@@ -362,11 +382,11 @@ static VALUE string_spec_rb_sprintf2(VALUE self, VALUE str, VALUE repl1, VALUE r
}
static VALUE string_spec_rb_sprintf3(VALUE self, VALUE str) {
- return rb_sprintf("Result: %"PRIsVALUE".", str);
+ return rb_sprintf("Result: %" PRIsVALUE ".", str);
}
static VALUE string_spec_rb_sprintf4(VALUE self, VALUE str) {
- return rb_sprintf("Result: %+"PRIsVALUE".", str);
+ return rb_sprintf("Result: %+" PRIsVALUE ".", str);
}
static VALUE string_spec_rb_vsprintf_worker(char* fmt, ...) {
@@ -477,6 +497,8 @@ void Init_string_spec(void) {
rb_define_method(cls, "RSTRING_LEN", string_spec_RSTRING_LEN, 1);
rb_define_method(cls, "RSTRING_LENINT", string_spec_RSTRING_LENINT, 1);
rb_define_method(cls, "RSTRING_PTR_iterate", string_spec_RSTRING_PTR_iterate, 1);
+ rb_define_method(cls, "RSTRING_PTR_iterate_uint32", string_spec_RSTRING_PTR_iterate_uint32, 1);
+ rb_define_method(cls, "RSTRING_PTR_short_memcpy", string_spec_RSTRING_PTR_short_memcpy, 1);
rb_define_method(cls, "RSTRING_PTR_assign", string_spec_RSTRING_PTR_assign, 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);
diff --git a/spec/ruby/optional/capi/ext/symbol_spec.c b/spec/ruby/optional/capi/ext/symbol_spec.c
index 27732ae58f..d2ca62d81e 100644
--- a/spec/ruby/optional/capi/ext/symbol_spec.c
+++ b/spec/ruby/optional/capi/ext/symbol_spec.c
@@ -7,6 +7,10 @@
extern "C" {
#endif
+VALUE symbol_spec_SYMBOL_P(VALUE self, VALUE obj) {
+ return SYMBOL_P(obj) ? Qtrue : Qfalse;
+}
+
VALUE symbol_spec_rb_intern(VALUE self, VALUE string) {
return ID2SYM(rb_intern(RSTRING_PTR(string)));
}
@@ -73,6 +77,7 @@ VALUE symbol_spec_rb_sym2str(VALUE self, VALUE sym) {
void Init_symbol_spec(void) {
VALUE cls = rb_define_class("CApiSymbolSpecs", rb_cObject);
+ rb_define_method(cls, "SYMBOL_P", symbol_spec_SYMBOL_P, 1);
rb_define_method(cls, "rb_intern", symbol_spec_rb_intern, 1);
rb_define_method(cls, "rb_intern2", symbol_spec_rb_intern2, 2);
rb_define_method(cls, "rb_intern_const", symbol_spec_rb_intern_const, 1);
diff --git a/spec/ruby/optional/capi/ext/thread_spec.c b/spec/ruby/optional/capi/ext/thread_spec.c
index 139652e326..743828b523 100644
--- a/spec/ruby/optional/capi/ext/thread_spec.c
+++ b/spec/ruby/optional/capi/ext/thread_spec.c
@@ -15,7 +15,7 @@
extern "C" {
#endif
-static VALUE thread_spec_rb_thread_alone() {
+static VALUE thread_spec_rb_thread_alone(VALUE self) {
return rb_thread_alone() ? Qtrue : Qfalse;
}
@@ -89,7 +89,7 @@ static VALUE thread_spec_rb_thread_call_without_gvl_with_ubf_io(VALUE self) {
return (VALUE)ret;
}
-static VALUE thread_spec_rb_thread_current() {
+static VALUE thread_spec_rb_thread_current(VALUE self) {
return rb_thread_current();
}
diff --git a/spec/ruby/optional/capi/ext/typed_data_spec.c b/spec/ruby/optional/capi/ext/typed_data_spec.c
index a2cc53f54d..6eb91b76bf 100644
--- a/spec/ruby/optional/capi/ext/typed_data_spec.c
+++ b/spec/ruby/optional/capi/ext/typed_data_spec.c
@@ -8,7 +8,7 @@ extern "C" {
#endif
struct sample_typed_wrapped_struct_parent {
- int foo;
+ int foo;
};
void sample_typed_wrapped_struct_parent_free(void* st) {
@@ -32,7 +32,7 @@ static const rb_data_type_t sample_typed_wrapped_struct_parent_data_type = {
};
struct sample_typed_wrapped_struct {
- int foo;
+ int foo;
};
void sample_typed_wrapped_struct_free(void* st) {
@@ -61,7 +61,7 @@ static const rb_data_type_t sample_typed_wrapped_struct_data_type = {
};
struct sample_typed_wrapped_struct_other {
- int foo;
+ int foo;
};
void sample_typed_wrapped_struct_other_free(void* st) {
@@ -86,43 +86,45 @@ static const rb_data_type_t sample_typed_wrapped_struct_other_data_type = {
VALUE sdaf_alloc_typed_func(VALUE klass) {
- struct sample_typed_wrapped_struct* bar = (struct sample_typed_wrapped_struct *)malloc(sizeof(struct sample_typed_wrapped_struct));
- bar->foo = 42;
- return TypedData_Wrap_Struct(klass, &sample_typed_wrapped_struct_data_type, bar);
+ struct sample_typed_wrapped_struct* bar;
+ bar = (struct sample_typed_wrapped_struct *) malloc(sizeof(struct sample_typed_wrapped_struct));
+ bar->foo = 42;
+ return TypedData_Wrap_Struct(klass, &sample_typed_wrapped_struct_data_type, bar);
}
VALUE sdaf_typed_get_struct(VALUE self) {
- struct sample_typed_wrapped_struct* bar;
- TypedData_Get_Struct(self, struct sample_typed_wrapped_struct, &sample_typed_wrapped_struct_data_type, bar);
+ struct sample_typed_wrapped_struct* bar;
+ TypedData_Get_Struct(self, struct sample_typed_wrapped_struct, &sample_typed_wrapped_struct_data_type, bar);
- return INT2FIX((*bar).foo);
+ return INT2FIX((*bar).foo);
}
VALUE sws_typed_wrap_struct(VALUE self, VALUE val) {
- struct sample_typed_wrapped_struct* bar = (struct sample_typed_wrapped_struct *)malloc(sizeof(struct sample_typed_wrapped_struct));
- bar->foo = FIX2INT(val);
- return TypedData_Wrap_Struct(rb_cObject, &sample_typed_wrapped_struct_data_type, bar);
+ struct sample_typed_wrapped_struct* bar;
+ bar = (struct sample_typed_wrapped_struct *) malloc(sizeof(struct sample_typed_wrapped_struct));
+ bar->foo = FIX2INT(val);
+ return TypedData_Wrap_Struct(rb_cObject, &sample_typed_wrapped_struct_data_type, bar);
}
VALUE sws_typed_get_struct(VALUE self, VALUE obj) {
- struct sample_typed_wrapped_struct* bar;
- TypedData_Get_Struct(obj, struct sample_typed_wrapped_struct, &sample_typed_wrapped_struct_data_type, bar);
+ struct sample_typed_wrapped_struct* bar;
+ TypedData_Get_Struct(obj, struct sample_typed_wrapped_struct, &sample_typed_wrapped_struct_data_type, bar);
- return INT2FIX((*bar).foo);
+ return INT2FIX((*bar).foo);
}
VALUE sws_typed_get_struct_different_type(VALUE self, VALUE obj) {
- struct sample_typed_wrapped_struct_other* bar;
- TypedData_Get_Struct(obj, struct sample_typed_wrapped_struct_other, &sample_typed_wrapped_struct_other_data_type, bar);
+ struct sample_typed_wrapped_struct_other* bar;
+ TypedData_Get_Struct(obj, struct sample_typed_wrapped_struct_other, &sample_typed_wrapped_struct_other_data_type, bar);
- return INT2FIX((*bar).foo);
+ return INT2FIX((*bar).foo);
}
VALUE sws_typed_get_struct_parent_type(VALUE self, VALUE obj) {
- struct sample_typed_wrapped_struct_parent* bar;
- TypedData_Get_Struct(obj, struct sample_typed_wrapped_struct_parent, &sample_typed_wrapped_struct_parent_data_type, bar);
+ struct sample_typed_wrapped_struct_parent* bar;
+ TypedData_Get_Struct(obj, struct sample_typed_wrapped_struct_parent, &sample_typed_wrapped_struct_parent_data_type, bar);
- return INT2FIX((*bar).foo);
+ return INT2FIX((*bar).foo);
}
VALUE sws_typed_get_struct_rdata(VALUE self, VALUE obj) {
@@ -138,11 +140,10 @@ VALUE sws_typed_get_struct_data_ptr(VALUE self, VALUE obj) {
}
VALUE sws_typed_change_struct(VALUE self, VALUE obj, VALUE new_val) {
- struct sample_typed_wrapped_struct *old_struct, *new_struct;
- new_struct = (struct sample_typed_wrapped_struct *)malloc(sizeof(struct sample_typed_wrapped_struct));
+ struct sample_typed_wrapped_struct *new_struct;
+ new_struct = (struct sample_typed_wrapped_struct *) malloc(sizeof(struct sample_typed_wrapped_struct));
new_struct->foo = FIX2INT(new_val);
- old_struct = RTYPEDDATA(obj)->data;
- free(old_struct);
+ free(RTYPEDDATA(obj)->data);
RTYPEDDATA(obj)->data = new_struct;
return Qnil;
}
diff --git a/spec/ruby/optional/capi/ext/util_spec.c b/spec/ruby/optional/capi/ext/util_spec.c
index f3c6a1ba58..f7b45de6b6 100644
--- a/spec/ruby/optional/capi/ext/util_spec.c
+++ b/spec/ruby/optional/capi/ext/util_spec.c
@@ -60,8 +60,8 @@ static VALUE util_spec_rb_get_kwargs(VALUE self, VALUE keyword_hash, VALUE keys,
int values_len = req + (opt < 0 ? -1 - opt : opt);
int i = 0;
- ID *ids = malloc(sizeof(VALUE) * len);
- VALUE *results = malloc(sizeof(VALUE) * values_len);
+ ID *ids = (ID*) malloc(sizeof(VALUE) * len);
+ VALUE *results = (VALUE*) malloc(sizeof(VALUE) * values_len);
int extracted = 0;
VALUE ary = Qundef;