diff options
author | Benoit Daloze <[email protected]> | 2019-12-27 16:46:08 +0100 |
---|---|---|
committer | Benoit Daloze <[email protected]> | 2019-12-27 16:46:08 +0100 |
commit | a2fac1d72c225192018f8f3f3dfcfcc46f66c08a (patch) | |
tree | dc2d44079962ce242d971a4d1c2a2b1333e64cec /spec/ruby/optional/capi | |
parent | 26a9f80c823a9f536a235d80d600aa9e03ed7a2f (diff) |
Update to ruby/spec@d419e74
Diffstat (limited to 'spec/ruby/optional/capi')
-rw-r--r-- | spec/ruby/optional/capi/encoding_spec.rb | 10 | ||||
-rw-r--r-- | spec/ruby/optional/capi/ext/encoding_spec.c | 9 | ||||
-rw-r--r-- | spec/ruby/optional/capi/ext/gc_spec.c | 6 | ||||
-rw-r--r-- | spec/ruby/optional/capi/ext/hash_spec.c | 10 | ||||
-rw-r--r-- | spec/ruby/optional/capi/ext/io_spec.c | 14 | ||||
-rw-r--r-- | spec/ruby/optional/capi/ext/symbol_spec.c | 5 | ||||
-rw-r--r-- | spec/ruby/optional/capi/gc_spec.rb | 6 | ||||
-rw-r--r-- | spec/ruby/optional/capi/hash_spec.rb | 9 | ||||
-rw-r--r-- | spec/ruby/optional/capi/io_spec.rb | 10 | ||||
-rw-r--r-- | spec/ruby/optional/capi/symbol_spec.rb | 13 |
10 files changed, 92 insertions, 0 deletions
diff --git a/spec/ruby/optional/capi/encoding_spec.rb b/spec/ruby/optional/capi/encoding_spec.rb index 003edc9669..857e421ddb 100644 --- a/spec/ruby/optional/capi/encoding_spec.rb +++ b/spec/ruby/optional/capi/encoding_spec.rb @@ -479,4 +479,14 @@ describe "C-API Encoding function" do length.should == 4 end end + + describe "rb_enc_str_asciionly_p" do + it "returns true for an ASCII string" do + @s.rb_enc_str_asciionly_p("hello").should be_true + end + + it "returns false for a non-ASCII string" do + @s.rb_enc_str_asciionly_p("hüllo").should be_false + end + end end diff --git a/spec/ruby/optional/capi/ext/encoding_spec.c b/spec/ruby/optional/capi/ext/encoding_spec.c index 3cde884225..52ed4fdb2e 100644 --- a/spec/ruby/optional/capi/ext/encoding_spec.c +++ b/spec/ruby/optional/capi/ext/encoding_spec.c @@ -196,6 +196,14 @@ static VALUE encoding_spec_rb_enc_codepoint_len(VALUE self, VALUE str) { return rb_ary_new3(2, LONG2NUM(codepoint), LONG2NUM(len)); } +static VALUE encoding_spec_rb_enc_str_asciionly_p(VALUE self, VALUE str) { + if (rb_enc_str_asciionly_p(str)) { + return Qtrue; + } else { + return Qfalse; + } +} + void Init_encoding_spec(void) { VALUE cls = rb_define_class("CApiEncodingSpecs", rb_cObject); rb_define_method(cls, "ENC_CODERANGE_ASCIIONLY", @@ -242,6 +250,7 @@ void Init_encoding_spec(void) { rb_define_method(cls, "rb_to_encoding_index", encoding_spec_rb_to_encoding_index, 1); rb_define_method(cls, "rb_enc_nth", encoding_spec_rb_enc_nth, 2); rb_define_method(cls, "rb_enc_codepoint_len", encoding_spec_rb_enc_codepoint_len, 1); + rb_define_method(cls, "rb_enc_str_asciionly_p", encoding_spec_rb_enc_str_asciionly_p, 1); } #ifdef __cplusplus diff --git a/spec/ruby/optional/capi/ext/gc_spec.c b/spec/ruby/optional/capi/ext/gc_spec.c index 57b1f11faa..983b021df9 100644 --- a/spec/ruby/optional/capi/ext/gc_spec.c +++ b/spec/ruby/optional/capi/ext/gc_spec.c @@ -34,6 +34,11 @@ static VALUE gc_spec_rb_gc_adjust_memory_usage(VALUE self, VALUE diff) { return Qnil; } +static VALUE gc_spec_rb_gc_register_mark_object(VALUE self, VALUE obj) { + rb_gc_register_mark_object(obj); + return Qnil; +} + void Init_gc_spec(void) { VALUE cls = rb_define_class("CApiGCSpecs", rb_cObject); registered_tagged_value = INT2NUM(10); @@ -48,6 +53,7 @@ void Init_gc_spec(void) { 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); + rb_define_method(cls, "rb_gc_register_mark_object", gc_spec_rb_gc_register_mark_object, 1); } #ifdef __cplusplus diff --git a/spec/ruby/optional/capi/ext/hash_spec.c b/spec/ruby/optional/capi/ext/hash_spec.c index c8735cec2c..36a07d74f6 100644 --- a/spec/ruby/optional/capi/ext/hash_spec.c +++ b/spec/ruby/optional/capi/ext/hash_spec.c @@ -113,6 +113,15 @@ VALUE hash_spec_rb_hash_set_ifnone(VALUE self, VALUE hash, VALUE def) { return rb_hash_set_ifnone(hash, def); } +VALUE hash_spec_compute_a_hash_code(VALUE self, VALUE seed) { + int int_seed = FIX2INT(seed); + st_index_t h = rb_hash_start(int_seed); + h = rb_hash_uint32(h, 540u); + h = rb_hash_uint32(h, 340u); + h = rb_hash_end(h); + return ULONG2NUM(h); +} + void Init_hash_spec(void) { VALUE cls = rb_define_class("CApiHashSpecs", rb_cObject); rb_define_method(cls, "rb_hash", hash_spec_rb_hash, 1); @@ -136,6 +145,7 @@ void Init_hash_spec(void) { rb_define_method(cls, "rb_hash_new", hash_spec_rb_hash_new, 0); rb_define_method(cls, "rb_hash_size", hash_spec_rb_hash_size, 1); rb_define_method(cls, "rb_hash_set_ifnone", hash_spec_rb_hash_set_ifnone, 2); + rb_define_method(cls, "compute_a_hash_code", hash_spec_compute_a_hash_code, 1); } #ifdef __cplusplus diff --git a/spec/ruby/optional/capi/ext/io_spec.c b/spec/ruby/optional/capi/ext/io_spec.c index b656de081a..45f57810db 100644 --- a/spec/ruby/optional/capi/ext/io_spec.c +++ b/spec/ruby/optional/capi/ext/io_spec.c @@ -201,6 +201,19 @@ VALUE io_spec_rb_io_close(VALUE self, VALUE io) { return rb_io_close(io); } +VALUE io_spec_rb_io_set_nonblock(VALUE self, VALUE io) { + rb_io_t* fp; + int flags; + GetOpenFile(io, fp); + rb_io_set_nonblock(fp); +#ifdef F_GETFL + flags = fcntl(fp->fd, F_GETFL, 0); + return flags & O_NONBLOCK ? Qtrue : Qfalse; +#else + return Qfalse; +#endif +} + /* * this is needed to ensure rb_io_wait_*able functions behave * predictably because errno may be set to unexpected values @@ -225,6 +238,7 @@ void Init_io_spec(void) { rb_define_method(cls, "rb_io_check_readable", io_spec_rb_io_check_readable, 1); rb_define_method(cls, "rb_io_check_writable", io_spec_rb_io_check_writable, 1); rb_define_method(cls, "rb_io_check_closed", io_spec_rb_io_check_closed, 1); + rb_define_method(cls, "rb_io_set_nonblock", io_spec_rb_io_set_nonblock, 1); rb_define_method(cls, "rb_io_taint_check", io_spec_rb_io_taint_check, 1); rb_define_method(cls, "rb_io_wait_readable", io_spec_rb_io_wait_readable, 2); rb_define_method(cls, "rb_io_wait_writable", io_spec_rb_io_wait_writable, 1); diff --git a/spec/ruby/optional/capi/ext/symbol_spec.c b/spec/ruby/optional/capi/ext/symbol_spec.c index 28da69ea3c..27732ae58f 100644 --- a/spec/ruby/optional/capi/ext/symbol_spec.c +++ b/spec/ruby/optional/capi/ext/symbol_spec.c @@ -51,6 +51,10 @@ VALUE symbol_spec_rb_intern_str(VALUE self, VALUE str) { return ID2SYM(rb_intern_str(str)); } +VALUE symbol_spec_rb_check_symbol_cstr(VALUE self, VALUE str) { + return rb_check_symbol_cstr(RSTRING_PTR(str), RSTRING_LEN(str), rb_enc_get(str)); +} + VALUE symbol_spec_rb_is_class_id(VALUE self, VALUE sym) { return rb_is_class_id(SYM2ID(sym)) ? Qtrue : Qfalse; } @@ -79,6 +83,7 @@ void Init_symbol_spec(void) { rb_define_method(cls, "rb_id2name", symbol_spec_rb_id2name, 1); rb_define_method(cls, "rb_id2str", symbol_spec_rb_id2str, 1); rb_define_method(cls, "rb_intern_str", symbol_spec_rb_intern_str, 1); + rb_define_method(cls, "rb_check_symbol_cstr", symbol_spec_rb_check_symbol_cstr, 1); rb_define_method(cls, "rb_is_class_id", symbol_spec_rb_is_class_id, 1); rb_define_method(cls, "rb_is_const_id", symbol_spec_rb_is_const_id, 1); rb_define_method(cls, "rb_is_instance_id", symbol_spec_rb_is_instance_id, 1); diff --git a/spec/ruby/optional/capi/gc_spec.rb b/spec/ruby/optional/capi/gc_spec.rb index 46c03156e4..528dd291ba 100644 --- a/spec/ruby/optional/capi/gc_spec.rb +++ b/spec/ruby/optional/capi/gc_spec.rb @@ -58,4 +58,10 @@ describe "CApiGCSpecs" do }.should_not raise_error end end + + describe "rb_gc_register_mark_object" do + it "can be called with an object" do + @f.rb_gc_register_mark_object(Object.new).should be_nil + end + end end diff --git a/spec/ruby/optional/capi/hash_spec.rb b/spec/ruby/optional/capi/hash_spec.rb index 2923faf7de..90d9c53456 100644 --- a/spec/ruby/optional/capi/hash_spec.rb +++ b/spec/ruby/optional/capi/hash_spec.rb @@ -254,4 +254,13 @@ describe "C-API Hash function" do -> { @s.rb_Hash(h) }.should raise_error(TypeError) end end + + describe "hash code functions" do + it "computes a deterministic number" do + hash_code = @s.compute_a_hash_code(53) + hash_code.should be_an_instance_of(Integer) + hash_code.should == @s.compute_a_hash_code(53) + @s.compute_a_hash_code(90) == @s.compute_a_hash_code(90) + end + end end diff --git a/spec/ruby/optional/capi/io_spec.rb b/spec/ruby/optional/capi/io_spec.rb index 4d61fc8755..c3c1189a43 100644 --- a/spec/ruby/optional/capi/io_spec.rb +++ b/spec/ruby/optional/capi/io_spec.rb @@ -151,6 +151,16 @@ describe "C-API IO function" do end end + describe "rb_io_set_nonblock" do + platform_is_not :windows do + it "returns true when nonblock flag is set" do + require 'io/nonblock' + @o.rb_io_set_nonblock(@io) + @io.nonblock?.should be_true + end + end + end + # NOTE: unlike the name might suggest in MRI this function checks if an # object is frozen, *not* if it's tainted. describe "rb_io_taint_check" do diff --git a/spec/ruby/optional/capi/symbol_spec.rb b/spec/ruby/optional/capi/symbol_spec.rb index ddc748c8d8..7f345f879f 100644 --- a/spec/ruby/optional/capi/symbol_spec.rb +++ b/spec/ruby/optional/capi/symbol_spec.rb @@ -71,6 +71,19 @@ describe "C-API Symbol function" do end end + describe "rb_check_symbol_cstr" do + it "returns a Symbol if a Symbol already exists for the given C string" do + sym = :test_symbol + @s.rb_check_symbol_cstr('test_symbol').should == sym + end + + it "returns nil if the Symbol does not exist yet and does not create it" do + str = "symbol_does_not_exist_#{Object.new.object_id}_#{rand}" + @s.rb_check_symbol_cstr(str).should == nil # does not create the Symbol + @s.rb_check_symbol_cstr(str).should == nil + end + end + describe "rb_is_const_id" do it "returns true given a const-like symbol" do @s.rb_is_const_id(:Foo).should == true |