diff options
author | Takashi Kokubun <takashikkbn@gmail.com> | 2023-02-27 09:24:45 -0800 |
---|---|---|
committer | Takashi Kokubun <takashikkbn@gmail.com> | 2023-02-27 09:24:45 -0800 |
commit | 526111290b2e01e798f436dfe4acc3bf10c6bbd1 (patch) | |
tree | 17c1fb9561c1234ca23fcd61807e46343adeb745 /load.c | |
parent | 0eb634ae73cb327ede833b72492f912792a4a9d5 (diff) |
Revert "reuse open(2) from rb_file_load_ok on POSIX-like system"
This reverts commit 35136e1e9c232ad7a03407b992b2e86b6df43f63.
test-spec has been failing since this revision.
.github/workflows/compilers.yml:82
https://github.com/ruby/ruby/actions/runs/4276884159/jobs/7445299562
```
env:
# Minimal flags to pass the check.
default_cc: 'gcc-11 -fcf-protection -Wa,--generate-missing-build-notes=yes'
optflags: '-O2'
LDFLAGS: '-Wl,-z,now'
# FIXME: Drop skipping options
# https://bugs.ruby-lang.org/issues/18061
# https://sourceware.org/annobin/annobin.html/Test-pie.html
TEST_ANNOCHECK_OPTS: "--skip-pie --skip-gaps"
```
Failure:
```
1)
An exception occurred during: Kernel#require (file extensions) does not load a C-extension file if a complex-extensioned .rb file is already loaded
/__w/ruby/ruby/src/spec/ruby/core/kernel/shared/require.rb:317
Kernel#require (file extensions) does not load a C-extension file if a complex-extensioned .rb file is already loaded ERROR
LeakError: Leaked file descriptor: 8 : #<File:/__w/ruby/ruby/src/spec/ruby/fixtures/code/load_fixture.ext.rb>
/__w/ruby/ruby/src/spec/ruby/core/kernel/require_spec.rb:5:in `<top (required)>'
2)
An exception occurred during: Kernel#require ($LOADED_FEATURES) stores an absolute path
/__w/ruby/ruby/src/spec/ruby/core/kernel/shared/require.rb:330
Kernel#require ($LOADED_FEATURES) stores an absolute path ERROR
LeakError: Closed file descriptor: 8
/__w/ruby/ruby/src/spec/ruby/core/kernel/require_spec.rb:5:in `<top (required)>'
3)
An exception occurred during: Kernel#require ($LOADED_FEATURES) does not load a non-canonical path for a file already loaded
/__w/ruby/ruby/src/spec/ruby/core/kernel/shared/require.rb:535
Kernel#require ($LOADED_FEATURES) does not load a non-canonical path for a file already loaded ERROR
LeakError: Leaked file descriptor: 8 : #<File:/__w/ruby/ruby/src/spec/ruby/fixtures/code/load_fixture.rb>
/__w/ruby/ruby/src/spec/ruby/core/kernel/require_spec.rb:5:in `<top (required)>'
4)
An exception occurred during: Kernel#require ($LOADED_FEATURES) does not load a ../ relative path for a file already loaded
/__w/ruby/ruby/src/spec/ruby/core/kernel/shared/require.rb:551
Kernel#require ($LOADED_FEATURES) does not load a ../ relative path for a file already loaded ERROR
LeakError: Leaked file descriptor: 9 : #<File:../code/load_fixture.rb>
/__w/ruby/ruby/src/spec/ruby/core/kernel/require_spec.rb:5:in `<top (required)>'
5)
An exception occurred during: Kernel#require ($LOADED_FEATURES) complex, enumerator, rational, thread, ruby2_keywords are already required
/__w/ruby/ruby/src/spec/ruby/core/kernel/shared/require.rb:563
Kernel#require ($LOADED_FEATURES) complex, enumerator, rational, thread, ruby2_keywords are already required ERROR
LeakError: Closed file descriptor: 8
Closed file descriptor: 9
/__w/ruby/ruby/src/spec/ruby/core/kernel/require_spec.rb:5:in `<top (required)>'
6)
An exception occurred during: Kernel.require (file extensions) does not load a C-extension file if a complex-extensioned .rb file is already loaded
/__w/ruby/ruby/src/spec/ruby/core/kernel/shared/require.rb:317
Kernel.require (file extensions) does not load a C-extension file if a complex-extensioned .rb file is already loaded ERROR
LeakError: Leaked file descriptor: 8 : #<File:/__w/ruby/ruby/src/spec/ruby/fixtures/code/load_fixture.ext.rb>
/__w/ruby/ruby/src/spec/ruby/core/kernel/require_spec.rb:23:in `<top (required)>'
7)
An exception occurred during: Kernel.require ($LOADED_FEATURES) stores an absolute path
/__w/ruby/ruby/src/spec/ruby/core/kernel/shared/require.rb:330
Kernel.require ($LOADED_FEATURES) stores an absolute path ERROR
LeakError: Closed file descriptor: 8
/__w/ruby/ruby/src/spec/ruby/core/kernel/require_spec.rb:23:in `<top (required)>'
8)
An exception occurred during: Kernel.require ($LOADED_FEATURES) does not load a non-canonical path for a file already loaded
/__w/ruby/ruby/src/spec/ruby/core/kernel/shared/require.rb:535
Kernel.require ($LOADED_FEATURES) does not load a non-canonical path for a file already loaded ERROR
LeakError: Leaked file descriptor: 8 : #<File:/__w/ruby/ruby/src/spec/ruby/fixtures/code/load_fixture.rb>
/__w/ruby/ruby/src/spec/ruby/core/kernel/require_spec.rb:23:in `<top (required)>'
9)
An exception occurred during: Kernel.require ($LOADED_FEATURES) does not load a ../ relative path for a file already loaded
/__w/ruby/ruby/src/spec/ruby/core/kernel/shared/require.rb:551
Kernel.require ($LOADED_FEATURES) does not load a ../ relative path for a file already loaded ERROR
LeakError: Leaked file descriptor: 9 : #<File:../code/load_fixture.rb>
/__w/ruby/ruby/src/spec/ruby/core/kernel/require_spec.rb:23:in `<top (required)>'
10)
An exception occurred during: Kernel.require ($LOADED_FEATURES) complex, enumerator, rational, thread, ruby2_keywords are already required
/__w/ruby/ruby/src/spec/ruby/core/kernel/shared/require.rb:563
Kernel.require ($LOADED_FEATURES) complex, enumerator, rational, thread, ruby2_keywords are already required ERROR
LeakError: Closed file descriptor: 8
Closed file descriptor: 9
/__w/ruby/ruby/src/spec/ruby/core/kernel/require_spec.rb:23:in `<top (required)>'
11)
An exception occurred during: Kernel#require_relative with a relative path (file extensions) does not load a C-extension file if a complex-extensioned .rb file is already loaded
/__w/ruby/ruby/src/spec/ruby/core/kernel/require_relative_spec.rb:197
Kernel#require_relative with a relative path (file extensions) does not load a C-extension file if a complex-extensioned .rb file is already loaded ERROR
LeakError: Leaked file descriptor: 8 : #<File:/__w/ruby/ruby/src/spec/ruby/fixtures/code/load_fixture.ext.rb>
/__w/ruby/ruby/src/spec/ruby/core/kernel/require_relative_spec.rb:4:in `<top (required)>'
12)
An exception occurred during: Kernel#require_relative with a relative path ($LOADED_FEATURES) stores an absolute path
/__w/ruby/ruby/src/spec/ruby/core/kernel/require_relative_spec.rb:205
Kernel#require_relative with a relative path ($LOADED_FEATURES) stores an absolute path ERROR
LeakError: Closed file descriptor: 8
/__w/ruby/ruby/src/spec/ruby/core/kernel/require_relative_spec.rb:4:in `<top (required)>'
13)
An exception occurred during: Kernel#require_relative with an absolute path (file extensions) does not load a C-extension file if a complex-extensioned .rb file is already loaded
/__w/ruby/ruby/src/spec/ruby/core/kernel/require_relative_spec.rb:399
Kernel#require_relative with an absolute path (file extensions) does not load a C-extension file if a complex-extensioned .rb file is already loaded ERROR
LeakError: Leaked file descriptor: 8 : #<File:/__w/ruby/ruby/src/spec/ruby/fixtures/code/load_fixture.ext.rb>
/__w/ruby/ruby/src/spec/ruby/core/kernel/require_relative_spec.rb:277:in `<top (required)>'
14)
An exception occurred during: Kernel#require_relative with an absolute path ($LOAD_FEATURES) stores an absolute path
/__w/ruby/ruby/src/spec/ruby/core/kernel/require_relative_spec.rb:407
Kernel#require_relative with an absolute path ($LOAD_FEATURES) stores an absolute path ERROR
LeakError: Closed file descriptor: 8
/__w/ruby/ruby/src/spec/ruby/core/kernel/require_relative_spec.rb:277:in `<top (required)>'
```
Diffstat (limited to 'load.c')
-rw-r--r-- | load.c | 46 |
1 files changed, 18 insertions, 28 deletions
@@ -676,8 +676,7 @@ rb_provide(const char *feature) NORETURN(static void load_failed(VALUE)); static inline void -load_iseq_eval(rb_execution_context_t *ec, VALUE fname, - struct ruby_file_load_state *fls) +load_iseq_eval(rb_execution_context_t *ec, VALUE fname) { const rb_iseq_t *iseq = rb_iseq_load_iseq(fname); @@ -687,7 +686,7 @@ load_iseq_eval(rb_execution_context_t *ec, VALUE fname, rb_ast_t *ast; VALUE parser = rb_parser_new(); rb_parser_set_context(parser, NULL, FALSE); - ast = (rb_ast_t *)rb_parser_load_state(parser, fname, fls); + ast = (rb_ast_t *)rb_parser_load_file(parser, fname); iseq = rb_iseq_new_top(&ast->body, rb_fstring_lit("<top (required)>"), fname, rb_realpath_internal(Qnil, fname, 1), NULL); rb_ast_dispose(ast); @@ -699,8 +698,7 @@ load_iseq_eval(rb_execution_context_t *ec, VALUE fname, } static inline enum ruby_tag_type -load_wrapping(rb_execution_context_t *ec, VALUE fname, VALUE load_wrapper, - struct ruby_file_load_state *fls) +load_wrapping(rb_execution_context_t *ec, VALUE fname, VALUE load_wrapper) { enum ruby_tag_type state; rb_thread_t *th = rb_ec_thread_ptr(ec); @@ -720,7 +718,7 @@ load_wrapping(rb_execution_context_t *ec, VALUE fname, VALUE load_wrapper, EC_PUSH_TAG(ec); state = EC_EXEC_TAG(); if (state == TAG_NONE) { - load_iseq_eval(ec, fname, fls); + load_iseq_eval(ec, fname); } EC_POP_TAG(); @@ -746,7 +744,7 @@ raise_load_if_failed(rb_execution_context_t *ec, enum ruby_tag_type state) } static void -rb_load_internal(VALUE fname, VALUE wrap, struct ruby_file_load_state *fls) +rb_load_internal(VALUE fname, VALUE wrap) { rb_execution_context_t *ec = GET_EC(); enum ruby_tag_type state = TAG_NONE; @@ -754,10 +752,10 @@ rb_load_internal(VALUE fname, VALUE wrap, struct ruby_file_load_state *fls) if (!RB_TYPE_P(wrap, T_MODULE)) { wrap = rb_module_new(); } - state = load_wrapping(ec, fname, wrap, fls); + state = load_wrapping(ec, fname, wrap); } else { - load_iseq_eval(ec, fname, fls); + load_iseq_eval(ec, fname); } raise_load_if_failed(ec, state); } @@ -765,10 +763,9 @@ rb_load_internal(VALUE fname, VALUE wrap, struct ruby_file_load_state *fls) void rb_load(VALUE fname, int wrap) { - struct ruby_file_load_state fls = { .filev = Qfalse }; - VALUE tmp = ruby_find_file(FilePathValue(fname), &fls); + VALUE tmp = rb_find_file(FilePathValue(fname)); if (!tmp) load_failed(fname); - rb_load_internal(tmp, RBOOL(wrap), &fls); + rb_load_internal(tmp, RBOOL(wrap)); } void @@ -820,7 +817,6 @@ static VALUE rb_f_load(int argc, VALUE *argv, VALUE _) { VALUE fname, wrap, path, orig_fname; - struct ruby_file_load_state fls = { .filev = Qfalse }; rb_scan_args(argc, argv, "11", &fname, &wrap); @@ -828,13 +824,13 @@ rb_f_load(int argc, VALUE *argv, VALUE _) fname = rb_str_encode_ospath(orig_fname); RUBY_DTRACE_HOOK(LOAD_ENTRY, RSTRING_PTR(orig_fname)); - path = ruby_find_file(fname, &fls); + path = rb_find_file(fname); if (!path) { - if (!rb_file_load_ok(RSTRING_PTR(fname), &fls)) + if (!rb_file_load_ok(RSTRING_PTR(fname))) load_failed(orig_fname); path = fname; } - rb_load_internal(path, wrap, &fls); + rb_load_internal(path, wrap); RUBY_DTRACE_HOOK(LOAD_RETURN, RSTRING_PTR(orig_fname)); @@ -965,8 +961,7 @@ rb_f_require_relative(VALUE obj, VALUE fname) typedef int (*feature_func)(rb_vm_t *vm, const char *feature, const char *ext, int rb, int expanded, const char **fn); static int -search_required(rb_vm_t *vm, VALUE fname, volatile VALUE *path, - feature_func rb_feature_p, struct ruby_file_load_state *fls) +search_required(rb_vm_t *vm, VALUE fname, volatile VALUE *path, feature_func rb_feature_p) { VALUE tmp; char *ext, *ftptr; @@ -981,7 +976,7 @@ search_required(rb_vm_t *vm, VALUE fname, volatile VALUE *path, if (loading) *path = rb_filesystem_str_new_cstr(loading); return 'r'; } - if ((tmp = ruby_find_file(fname, fls)) != 0) { + if ((tmp = rb_find_file(fname)) != 0) { ext = strrchr(ftptr = RSTRING_PTR(tmp), '.'); if (!rb_feature_p(vm, ftptr, ext, TRUE, TRUE, &loading) || loading) *path = tmp; @@ -1022,7 +1017,7 @@ search_required(rb_vm_t *vm, VALUE fname, volatile VALUE *path, return 'r'; } tmp = fname; - type = ruby_find_file_ext(&tmp, ft == 's' ? ruby_ext : loadable_ext, fls); + type = rb_find_file_ext(&tmp, ft == 's' ? ruby_ext : loadable_ext); #if EXTSTATIC if (!ft && type != 1) { // not already a feature and not found as a dynamic library VALUE lookup_name = tmp; @@ -1108,7 +1103,7 @@ rb_resolve_feature_path(VALUE klass, VALUE fname) fname = rb_get_path(fname); path = rb_str_encode_ospath(fname); - found = search_required(GET_VM(), path, &path, no_feature_p, NULL); + found = search_required(GET_VM(), path, &path, no_feature_p); switch (found) { case 'r': @@ -1168,7 +1163,6 @@ require_internal(rb_execution_context_t *ec, VALUE fname, int exception, bool wa VALUE realpaths = get_loaded_features_realpaths(th->vm); volatile bool reset_ext_config = false; struct rb_ext_config prev_ext_config; - struct ruby_file_load_state fls = { .filev = Qfalse }; fname = rb_get_path(fname); path = rb_str_encode_ospath(fname); @@ -1183,7 +1177,7 @@ require_internal(rb_execution_context_t *ec, VALUE fname, int exception, bool wa int found; RUBY_DTRACE_HOOK(FIND_REQUIRE_ENTRY, RSTRING_PTR(fname)); - found = search_required(th->vm, path, &saved_path, rb_feature_p, &fls); + found = search_required(th->vm, path, &saved_path, rb_feature_p); RUBY_DTRACE_HOOK(FIND_REQUIRE_RETURN, RSTRING_PTR(fname)); path = saved_path; @@ -1206,14 +1200,10 @@ require_internal(rb_execution_context_t *ec, VALUE fname, int exception, bool wa else { switch (found) { case 'r': - load_iseq_eval(ec, path, &fls); + load_iseq_eval(ec, path); break; case 's': - if (fls.filev != Qfalse) { - rb_io_close(fls.filev); - fls.filev = Qfalse; - } reset_ext_config = true; ext_config_push(th, &prev_ext_config); handle = (long)rb_vm_call_cfunc(rb_vm_top_self(), load_ext, |