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>
This commit is contained in:
Samuel Williams 2023-05-30 10:02:40 +09:00 committed by GitHub
parent 7ddcd0622f
commit 18e55fc1e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
Notes: git 2023-05-30 01:03:01 +00:00
Merged-By: ioquatix <samuel@codeotaku.com>
14 changed files with 298 additions and 211 deletions

1
file.c
View file

@ -169,7 +169,6 @@ int flock(int, int);
#include "internal/thread.h"
#include "internal/vm.h"
#include "ruby/encoding.h"
#include "ruby/io.h"
#include "ruby/thread.h"
#include "ruby/util.h"