diff options
author | Benoit Daloze <eregontp@gmail.com> | 2021-07-30 11:36:20 +0200 |
---|---|---|
committer | Benoit Daloze <eregontp@gmail.com> | 2021-07-30 11:36:20 +0200 |
commit | ff6c17602841bff57d3a489b8119c9643dbc7ebe (patch) | |
tree | 8a30881a31ffe29c18a02c8dc7c68af8da60cc65 /spec/ruby/optional/capi/ext | |
parent | fd96503f7bf0ef8262691eac190fe53344ce55fc (diff) |
Tweak rb_str_modify_expand() + read() spec to try to find out why it fails on some platforms
* Use a longer string as <= 23 characters it's embedded on CRuby and
the value of rb_str_capacity() is implementation-specific.
Diffstat (limited to 'spec/ruby/optional/capi/ext')
-rw-r--r-- | spec/ruby/optional/capi/ext/string_spec.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/spec/ruby/optional/capi/ext/string_spec.c b/spec/ruby/optional/capi/ext/string_spec.c index f2245be0ef..b7bfcf8c88 100644 --- a/spec/ruby/optional/capi/ext/string_spec.c +++ b/spec/ruby/optional/capi/ext/string_spec.c @@ -4,6 +4,7 @@ #include <fcntl.h> #include <string.h> #include <stdarg.h> +#include <errno.h> #include "ruby/encoding.h" @@ -388,15 +389,24 @@ VALUE string_spec_RSTRING_PTR_after_yield(VALUE self, VALUE str) { VALUE string_spec_RSTRING_PTR_read(VALUE self, VALUE str, VALUE path) { char *cpath = StringValueCStr(path); int fd = open(cpath, O_RDONLY); - rb_str_modify_expand(str, 10); + VALUE capacities = rb_ary_new(); + if (fd < 0) { + rb_syserr_fail(errno, "open"); + } + + rb_str_modify_expand(str, 30); + rb_ary_push(capacities, SIZET2NUM(rb_str_capacity(str))); char *buffer = RSTRING_PTR(str); - read(fd, buffer, 10); - rb_str_modify_expand(str, 21); + read(fd, buffer, 30); + + rb_str_modify_expand(str, 53); + rb_ary_push(capacities, SIZET2NUM(rb_str_capacity(str))); char *buffer2 = RSTRING_PTR(str); - read(fd, buffer2 + 10, 11); - rb_str_set_len(str, 21); + read(fd, buffer2 + 30, 53 - 30); + + rb_str_set_len(str, 53); close(fd); - return str; + return capacities; } VALUE string_spec_StringValue(VALUE self, VALUE str) { |