diff options
author | Benoit Daloze <eregontp@gmail.com> | 2019-11-30 21:26:52 +0100 |
---|---|---|
committer | Benoit Daloze <eregontp@gmail.com> | 2019-11-30 21:26:52 +0100 |
commit | 1243255c3a36433041012b6107a5ac48658a0895 (patch) | |
tree | 04440f84b48999ff08d4a2a16d066d0ad731400e /spec/ruby/optional | |
parent | ab8345271eb87ff155d8bd5f22f53a4cf2902c26 (diff) | |
download | ruby-1243255c3a36433041012b6107a5ac48658a0895.tar.gz |
Update to ruby/spec@4eec3dc
Diffstat (limited to 'spec/ruby/optional')
-rw-r--r-- | spec/ruby/optional/capi/array_spec.rb | 8 | ||||
-rw-r--r-- | spec/ruby/optional/capi/ext/array_spec.c | 14 | ||||
-rw-r--r-- | spec/ruby/optional/capi/ext/gc_spec.c | 5 | ||||
-rw-r--r-- | spec/ruby/optional/capi/ext/kernel_spec.c | 9 | ||||
-rw-r--r-- | spec/ruby/optional/capi/ext/string_spec.c | 15 | ||||
-rw-r--r-- | spec/ruby/optional/capi/gc_spec.rb | 11 | ||||
-rw-r--r-- | spec/ruby/optional/capi/kernel_spec.rb | 5 | ||||
-rw-r--r-- | spec/ruby/optional/capi/string_spec.rb | 24 |
8 files changed, 89 insertions, 2 deletions
diff --git a/spec/ruby/optional/capi/array_spec.rb b/spec/ruby/optional/capi/array_spec.rb index acd225e0e0..cf65bc19b6 100644 --- a/spec/ruby/optional/capi/array_spec.rb +++ b/spec/ruby/optional/capi/array_spec.rb @@ -249,6 +249,14 @@ describe "C-API Array function" do @s.RARRAY_PTR_assign(a, :set) a.should == [:set, :set, :set] end + + it "allows memcpying between arrays" do + a = [1, 2, 3] + b = [0, 0, 0] + @s.RARRAY_PTR_memcpy(a, b) + b.should == [1, 2, 3] + a.should == [1, 2, 3] # check a was not modified + end end describe "RARRAY_LEN" do diff --git a/spec/ruby/optional/capi/ext/array_spec.c b/spec/ruby/optional/capi/ext/array_spec.c index 69cb035e61..379ced318d 100644 --- a/spec/ruby/optional/capi/ext/array_spec.c +++ b/spec/ruby/optional/capi/ext/array_spec.c @@ -33,6 +33,19 @@ static VALUE array_spec_RARRAY_PTR_assign(VALUE self, VALUE array, VALUE value) return Qnil; } + +static VALUE array_spec_RARRAY_PTR_memcpy(VALUE self, VALUE array1, VALUE array2) { + VALUE *ptr1, *ptr2; + int size; + size = RARRAY_LEN(array1); + ptr1 = RARRAY_PTR(array1); + ptr2 = RARRAY_PTR(array2); + if (ptr1 != NULL && ptr2 != NULL) { + memcpy(ptr2, ptr1, size * sizeof(VALUE)); + } + return Qnil; +} + static VALUE array_spec_RARRAY_LEN(VALUE self, VALUE array) { return INT2FIX(RARRAY_LEN(array)); } @@ -229,6 +242,7 @@ void Init_array_spec(void) { rb_define_method(cls, "RARRAY_LEN", array_spec_RARRAY_LEN, 1); 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); + 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, "rb_ary_aref", array_spec_rb_ary_aref, -1); rb_define_method(cls, "rb_ary_clear", array_spec_rb_ary_clear, 1); diff --git a/spec/ruby/optional/capi/ext/gc_spec.c b/spec/ruby/optional/capi/ext/gc_spec.c index 0a76b9d40a..57b1f11faa 100644 --- a/spec/ruby/optional/capi/ext/gc_spec.c +++ b/spec/ruby/optional/capi/ext/gc_spec.c @@ -29,6 +29,10 @@ static VALUE gc_spec_rb_gc() { return Qnil; } +static VALUE gc_spec_rb_gc_adjust_memory_usage(VALUE self, VALUE diff) { + rb_gc_adjust_memory_usage(NUM2SSIZET(diff)); + return Qnil; +} void Init_gc_spec(void) { VALUE cls = rb_define_class("CApiGCSpecs", rb_cObject); @@ -43,6 +47,7 @@ void Init_gc_spec(void) { rb_define_method(cls, "rb_gc_enable", gc_spec_rb_gc_enable, 0); rb_define_method(cls, "rb_gc_disable", gc_spec_rb_gc_disable, 0); rb_define_method(cls, "rb_gc", gc_spec_rb_gc, 0); + rb_define_method(cls, "rb_gc_adjust_memory_usage", gc_spec_rb_gc_adjust_memory_usage, 1); } #ifdef __cplusplus diff --git a/spec/ruby/optional/capi/ext/kernel_spec.c b/spec/ruby/optional/capi/ext/kernel_spec.c index 63a2ff8432..e98ae35067 100644 --- a/spec/ruby/optional/capi/ext/kernel_spec.c +++ b/spec/ruby/optional/capi/ext/kernel_spec.c @@ -59,6 +59,14 @@ VALUE kernel_spec_rb_block_call_multi_arg(VALUE self, VALUE ary) { return rb_block_call(ary, rb_intern("inject"), 1, method_args, block_call_inject_multi_arg, Qnil); } +static VALUE return_extra_data(RB_BLOCK_CALL_FUNC_ARGLIST(yield_value, extra_data)) { + return extra_data; +} + +VALUE rb_block_call_extra_data(VALUE self, VALUE object) { + return rb_block_call(object, rb_intern("instance_exec"), 0, NULL, return_extra_data, 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); } @@ -304,6 +312,7 @@ void Init_kernel_spec(void) { rb_define_method(cls, "rb_block_call", kernel_spec_rb_block_call, 1); rb_define_method(cls, "rb_block_call_multi_arg", kernel_spec_rb_block_call_multi_arg, 1); rb_define_method(cls, "rb_block_call_no_func", kernel_spec_rb_block_call_no_func, 1); + rb_define_method(cls, "rb_block_call_extra_data", rb_block_call_extra_data, 1); rb_define_method(cls, "rb_block_proc", kernel_spec_rb_block_proc, 0); rb_define_method(cls, "rb_block_lambda", kernel_spec_rb_block_lambda, 0); rb_define_method(cls, "rb_frame_this_func_test", kernel_spec_rb_frame_this_func, 0); diff --git a/spec/ruby/optional/capi/ext/string_spec.c b/spec/ruby/optional/capi/ext/string_spec.c index 4976dc92c4..a44e437bba 100644 --- a/spec/ruby/optional/capi/ext/string_spec.c +++ b/spec/ruby/optional/capi/ext/string_spec.c @@ -411,6 +411,18 @@ static VALUE string_spec_rb_str_modify(VALUE self, VALUE str) { return str; } +static VALUE string_spec_rb_utf8_str_new_static(VALUE self) { + return rb_utf8_str_new_static("nokogiri", 8); +} + +static VALUE string_spec_rb_utf8_str_new(VALUE self) { + return rb_utf8_str_new("nokogiri", 8); +} + +static VALUE string_spec_rb_utf8_str_new_cstr(VALUE self) { + return rb_utf8_str_new_cstr("nokogiri"); +} + void Init_string_spec(void) { VALUE cls = rb_define_class("CApiStringSpecs", rb_cObject); rb_define_method(cls, "rb_cstr2inum", string_spec_rb_cstr2inum, 2); @@ -485,6 +497,9 @@ void Init_string_spec(void) { rb_define_method(cls, "rb_String", string_spec_rb_String, 1); rb_define_method(cls, "rb_string_value_cstr", string_spec_rb_string_value_cstr, 1); rb_define_method(cls, "rb_str_modify", string_spec_rb_str_modify, 1); + rb_define_method(cls, "rb_utf8_str_new_static", string_spec_rb_utf8_str_new_static, 0); + rb_define_method(cls, "rb_utf8_str_new", string_spec_rb_utf8_str_new, 0); + rb_define_method(cls, "rb_utf8_str_new_cstr", string_spec_rb_utf8_str_new_cstr, 0); } #ifdef __cplusplus diff --git a/spec/ruby/optional/capi/gc_spec.rb b/spec/ruby/optional/capi/gc_spec.rb index 1c34675f0d..46c03156e4 100644 --- a/spec/ruby/optional/capi/gc_spec.rb +++ b/spec/ruby/optional/capi/gc_spec.rb @@ -42,13 +42,20 @@ describe "CApiGCSpecs" do end describe "rb_gc" do - it "increases gc count" do gc_count = GC.count @f.rb_gc GC.count.should > gc_count end - end + describe "rb_gc_adjust_memory_usage" do + # Just check that it does not throw, as it seems hard to observe any effect + it "adjusts the amount of registered external memory" do + -> { + @f.rb_gc_adjust_memory_usage(8) + @f.rb_gc_adjust_memory_usage(-8) + }.should_not raise_error + end + end end diff --git a/spec/ruby/optional/capi/kernel_spec.rb b/spec/ruby/optional/capi/kernel_spec.rb index d123eb13ea..32cdd3f421 100644 --- a/spec/ruby/optional/capi/kernel_spec.rb +++ b/spec/ruby/optional/capi/kernel_spec.rb @@ -53,6 +53,11 @@ describe "C-API Kernel function" do i + 1 end.should == [2, 4, 6] end + + it "can pass extra data to the function" do + ary = [3] + @s.rb_block_call_extra_data(ary).should equal(ary) + end end describe "rb_frame_this_func" do diff --git a/spec/ruby/optional/capi/string_spec.rb b/spec/ruby/optional/capi/string_spec.rb index 4da31445fe..1ad35b9e8a 100644 --- a/spec/ruby/optional/capi/string_spec.rb +++ b/spec/ruby/optional/capi/string_spec.rb @@ -1007,4 +1007,28 @@ end str.should == "2345678".encode("UTF-32LE") end end + + describe "rb_utf8_str_new_static" do + it "returns a UTF-8 string of the correct characters and length" do + str = @s.rb_utf8_str_new_static + str.should == "nokogiri" + str.encoding.should == Encoding::UTF_8 + end + end + + describe "rb_utf8_str_new" do + it "returns a UTF-8 string of the correct characters and length" do + str = @s.rb_utf8_str_new + str.should == "nokogiri" + str.encoding.should == Encoding::UTF_8 + end + end + + describe "rb_utf8_str_new_cstr" do + it "returns a UTF-8 string of the correct characters and length" do + str = @s.rb_utf8_str_new_cstr + str.should == "nokogiri" + str.encoding.should == Encoding::UTF_8 + end + end end |