diff options
author | Alan Wu <[email protected]> | 2024-08-27 12:19:37 -0400 |
---|---|---|
committer | Alan Wu <[email protected]> | 2024-08-27 17:39:34 -0400 |
commit | 1729f47e72b22c3d13203548583e7d70c0b44427 () | |
tree | d65016879de2794f2a3568267d529da8a1f727d2 /prism_compile.c | |
parent | 2157dcb568de0e387c6a203a731caea7923f856e (diff) |
[PRISM] Wait for data before reading pipes and chardevs
With the parse.y parser, when a fifo (named pipe) is passed to Kernel#load and friends, we wait for data to be available first before reading. Note that with fifos, opening with `O_RDONLY|O_NONBLOCK` and then reading will look like EOF with read(2) returning 0, but data can become available later. The prism compiler needs to match this behavior to pass `test_loading_fifo_{fd_,threading_raise,threading_success}`. I chose to use IO#read to do this. An alternative way to match behavior would be to use open_load_file() from ruby.c like parse.y, but I opted to only allocate an IO to deal with threading when reading from pipes and character devices. The memory mapping code seems to work fine for regular files.
Notes: Merged: https://.com/ruby/ruby/pull/11472
-rw-r--r-- | prism_compile.c | 119 |
1 files changed, 118 insertions, 1 deletions
@@ -10456,6 +10456,123 @@ pm_parse_file_script_lines(const pm_scope_node_t *scope_node, const pm_parser_t return lines; } /** * Attempt to load the file into memory. Return a Ruby error if the file cannot * be read. @@ -10463,7 +10580,7 @@ pm_parse_file_script_lines(const pm_scope_node_t *scope_node, const pm_parser_t VALUE pm_load_file(pm_parse_result_t *result, VALUE filepath, bool load_error) { - if (!pm_string_mapped_init(&result->input, RSTRING_PTR(filepath))) { #ifdef _WIN32 int e = rb_w32_map_errno(GetLastError()); #else |