diff options
author | Samuel Williams <samuel.williams@oriontransfer.co.nz> | 2023-05-30 10:02:40 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-30 10:02:40 +0900 |
commit | 18e55fc1e1ec20e8f3166e3059e76c885fc9f8f2 (patch) | |
tree | 7e35773b3cd1ae50a0a94937df7fb175a3bed9ba /spec/ruby/optional/capi/ext | |
parent | 7ddcd0622f3275effa603c16934b0215cc8a542b (diff) |
Hide most of the implementation of `struct rb_io`. (#6511)
* Add rb_io_path and rb_io_open_descriptor.
* Use rb_io_open_descriptor to create PTY objects
* Rename FMODE_PREP -> FMODE_EXTERNAL and expose it
FMODE_PREP I believe refers to the concept of a "pre-prepared" file, but
FMODE_EXTERNAL is clearer about what the file descriptor represents and
aligns with language in the IO::Buffer module.
* Ensure that rb_io_open_descriptor closes the FD if it fails
If FMODE_EXTERNAL is not set, then it's guaranteed that Ruby will be
responsible for closing your file, eventually, if you pass it to
rb_io_open_descriptor, even if it raises an exception.
* Rename IS_EXTERNAL_FD -> RUBY_IO_EXTERNAL_P
* Expose `rb_io_closed_p`.
* Add `rb_io_mode` to get IO mode.
---------
Co-authored-by: KJ Tsanaktsidis <ktsanaktsidis@zendesk.com>
Notes
Notes:
Merged-By: ioquatix <samuel@codeotaku.com>
Diffstat (limited to 'spec/ruby/optional/capi/ext')
-rw-r--r-- | spec/ruby/optional/capi/ext/io_spec.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/spec/ruby/optional/capi/ext/io_spec.c b/spec/ruby/optional/capi/ext/io_spec.c index cd4bc80229..1c554a1a31 100644 --- a/spec/ruby/optional/capi/ext/io_spec.c +++ b/spec/ruby/optional/capi/ext/io_spec.c @@ -28,9 +28,13 @@ static int set_non_blocking(int fd) { } static int io_spec_get_fd(VALUE io) { +#ifdef RUBY_VERSION_IS_3_1 + return rb_io_descriptor(io); +#else rb_io_t* fp; GetOpenFile(io, fp); return fp->fd; +#endif } VALUE io_spec_GetOpenFile_fd(VALUE self, VALUE io) { @@ -303,7 +307,7 @@ VALUE io_spec_rb_io_set_nonblock(VALUE self, VALUE io) { GetOpenFile(io, fp); rb_io_set_nonblock(fp); #ifdef F_GETFL - flags = fcntl(fp->fd, F_GETFL, 0); + flags = fcntl(io_spec_get_fd(io), F_GETFL, 0); return flags & O_NONBLOCK ? Qtrue : Qfalse; #else return Qfalse; @@ -322,9 +326,13 @@ static VALUE io_spec_errno_set(VALUE self, VALUE val) { } VALUE io_spec_mode_sync_flag(VALUE self, VALUE io) { +#ifdef RUBY_VERSION_IS_3_3 + if (rb_io_mode(io) & FMODE_SYNC) { +#else rb_io_t *fp; GetOpenFile(io, fp); if (fp->mode & FMODE_SYNC) { +#endif return Qtrue; } else { return Qfalse; |