dumping ground for random patches and texts
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: spew@80x24.org
Subject: [PATCH 2/2] wip
Date: Mon, 17 Apr 2023 23:06:03 +0000	[thread overview]
Message-ID: <20230417230604.2659188-2-e@80x24.org> (raw)
In-Reply-To: <20230417230604.2659188-1-e@80x24.org>

---
 load.c | 16 +++++++++++-----
 ruby.c |  8 +++++---
 2 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/load.c b/load.c
index 9025a89c87..9599b5266e 100644
--- a/load.c
+++ b/load.c
@@ -675,13 +675,22 @@ rb_provide(const char *feature)
 
 NORETURN(static void load_failed(VALUE));
 
+static void fls_close(struct ruby_file_load_state *fls)
+{
+    if (fls->filev == Qfalse) return;
+    rb_io_close(fls->filev);
+    fls->filev = Qfalse;
+}
+
 static inline void
 load_iseq_eval(rb_execution_context_t *ec, VALUE fname,
                 struct ruby_file_load_state *fls)
 {
     const rb_iseq_t *iseq = rb_iseq_load_iseq(fname);
 
-    if (!iseq) {
+    if (iseq) {
+        fls_close(fls);
+    } else {
         rb_execution_context_t *ec = GET_EC();
         VALUE v = rb_vm_push_frame_fname(ec, fname);
         rb_ast_t *ast;
@@ -1210,10 +1219,7 @@ require_internal(rb_execution_context_t *ec, VALUE fname, int exception, bool wa
                     break;
 
                   case 's':
-                    if (fls.filev != Qfalse) {
-                        rb_io_close(fls.filev);
-                        fls.filev = Qfalse;
-                    }
+                    fls_close(&fls);
                     reset_ext_config = true;
                     ext_config_push(th, &prev_ext_config);
                     handle = (long)rb_vm_call_cfunc(rb_vm_top_self(), load_ext,
diff --git a/ruby.c b/ruby.c
index 057589db73..b32b845777 100644
--- a/ruby.c
+++ b/ruby.c
@@ -2545,19 +2545,21 @@ rb_parser_load_state(VALUE parser, VALUE fname_v,
 {
     if (fls->filev != Qfalse) {
         ruby_cmdline_options_t opt;
+        VALUE f = fls->filev;
 
+        fls->filev = Qfalse;
         cmdline_options_init(&opt);
         /* TODO: xflag for DOSISH || __CYGWIN__ */
         if (fls->is_nonblock) {
             struct rb_io_t *fptr;
 
-            RB_IO_POINTER(fls->filev, fptr);
+            RB_IO_POINTER(f, fptr);
             disable_nonblock(fptr->fd);
         }
         if (fls->is_fifo) {
-            rb_io_wait(fls->filev, RB_INT2NUM(RUBY_IO_READABLE), Qnil);
+            rb_io_wait(f, RB_INT2NUM(RUBY_IO_READABLE), Qnil);
         }
-        return load_file(parser, fname_v, fls->filev, 0, &opt);
+        return load_file(parser, fname_v, f, 0, &opt);
     }
     return rb_parser_load_file(parser, fname_v);
 }

  reply	other threads:[~2023-04-17 23:06 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-17 23:06 [PATCH 1/2] reuse open(2) from rb_file_load_ok on POSIX-like system Eric Wong
2023-04-17 23:06 ` Eric Wong [this message]
  -- strict thread matches above, loose matches on Subject: below --
2023-05-13 22:16 [PATCH 1/2] search: add comments wrt codesearch, reduce ops Eric Wong
2023-05-13 22:16 ` [PATCH 2/2] WIP Eric Wong
2023-05-04 11:07 [PATCH 1/2] reuse open(2) from rb_file_load_ok on POSIX-like system Eric Wong
2023-05-04 11:07 ` [PATCH 2/2] wip Eric Wong
2021-01-15 10:24 [PATCH 1/2] lei_to_mail: prepare Eric Wong
2021-01-15 10:24 ` [PATCH 2/2] wip Eric Wong
2020-03-31  6:42 [PATCH 1/2] v2writable: index Message-IDs w/ spaces properly Eric Wong
2020-03-31  6:42 ` [PATCH 2/2] WIP Eric Wong
2019-11-03  3:17 [PATCH 1/2] edit: hoist out prompt functions into sub functions Eric Wong
2019-11-03  3:17 ` [PATCH 2/2] wip Eric Wong
2019-09-23  3:16 [PATCH 1/2] edit: hoist out prompt functions into sub functions ew
2019-09-23  3:16 ` [PATCH 2/2] wip ew
2019-01-07  8:02 [PATCH 1/2] hoist out resolve_repo_dir from -index Eric Wong
2019-01-07  8:02 ` [PATCH 2/2] wip Eric Wong
2018-09-09  8:35 [PATCH 1/2] cont.c (fiber_memsize): do not rely on ROOT_FIBER_CONTEXT Eric Wong
2018-09-09  8:35 ` [PATCH 2/2] wip Eric Wong
2018-09-09  8:00 [PATCH 1/2] test_fiber: show crash on GC after forking Eric Wong
2018-09-09  8:00 ` [PATCH 2/2] wip Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230417230604.2659188-2-e@80x24.org \
    --to=e@80x24.org \
    --cc=spew@80x24.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).