2006-12-31 18:02:22 +03:00
|
|
|
/*
|
|
|
|
* load methods from eval.c
|
|
|
|
*/
|
|
|
|
|
* common.mk: clean up
- remove blockinlining.$(OBJEXT) to built
- make ENCODING_H_INCLDUES variable (include/ruby/encoding.h)
- make VM_CORE_H_INCLUDES variable (vm_core.h)
- simplify rules.
- make depends rule to output depend status using gcc -MM.
* include/ruby/mvm.h, include/ruby/vm.h: rename mvm.h to vm.h.
* include/ruby.h: ditto.
* load.c: add inclusion explicitly.
* enumerator.c, object.c, parse.y, thread.c, vm_dump.c:
remove useless inclusion.
* eval_intern.h: cleanup inclusion.
* vm_core.h: rb_thread_t should be defined in this file.
* vm_evalbody.c, vm_exec.c: rename vm_evalbody.c to vm_exec.c.
* vm.h, vm_exec.h: rename vm.h to vm_exec.h.
* insnhelper.h, vm_insnhelper.h: rename insnhelper.h to vm_insnhelper.h.
* vm.c, vm_insnhelper.c, vm_insnhelper.h:
- rename vm_eval() to vm_exec_core().
- rename vm_eval_body() to vm_exec().
- cleanup include order.
* vm_method.c: fix comment.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19466 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 04:20:28 +04:00
|
|
|
#include "dln.h"
|
2006-12-31 18:02:22 +03:00
|
|
|
#include "eval_intern.h"
|
2019-12-04 11:16:30 +03:00
|
|
|
#include "internal.h"
|
|
|
|
#include "internal/dir.h"
|
|
|
|
#include "internal/error.h"
|
|
|
|
#include "internal/file.h"
|
2023-12-08 09:06:12 +03:00
|
|
|
#include "internal/hash.h"
|
2019-12-04 11:16:30 +03:00
|
|
|
#include "internal/load.h"
|
2023-05-28 14:00:20 +03:00
|
|
|
#include "internal/ruby_parser.h"
|
2019-12-04 11:16:30 +03:00
|
|
|
#include "internal/thread.h"
|
|
|
|
#include "internal/variable.h"
|
2018-12-06 16:42:32 +03:00
|
|
|
#include "iseq.h"
|
2019-12-04 11:16:30 +03:00
|
|
|
#include "probes.h"
|
Rust YJIT
In December 2021, we opened an [issue] to solicit feedback regarding the
porting of the YJIT codebase from C99 to Rust. There were some
reservations, but this project was given the go ahead by Ruby core
developers and Matz. Since then, we have successfully completed the port
of YJIT to Rust.
The new Rust version of YJIT has reached parity with the C version, in
that it passes all the CRuby tests, is able to run all of the YJIT
benchmarks, and performs similarly to the C version (because it works
the same way and largely generates the same machine code). We've even
incorporated some design improvements, such as a more fine-grained
constant invalidation mechanism which we expect will make a big
difference in Ruby on Rails applications.
Because we want to be careful, YJIT is guarded behind a configure
option:
```shell
./configure --enable-yjit # Build YJIT in release mode
./configure --enable-yjit=dev # Build YJIT in dev/debug mode
```
By default, YJIT does not get compiled and cargo/rustc is not required.
If YJIT is built in dev mode, then `cargo` is used to fetch development
dependencies, but when building in release, `cargo` is not required,
only `rustc`. At the moment YJIT requires Rust 1.60.0 or newer.
The YJIT command-line options remain mostly unchanged, and more details
about the build process are documented in `doc/yjit/yjit.md`.
The CI tests have been updated and do not take any more resources than
before.
The development history of the Rust port is available at the following
commit for interested parties:
https://github.com/Shopify/ruby/commit/1fd9573d8b4b65219f1c2407f30a0a60e537f8be
Our hope is that Rust YJIT will be compiled and included as a part of
system packages and compiled binaries of the Ruby 3.2 release. We do not
anticipate any major problems as Rust is well supported on every
platform which YJIT supports, but to make sure that this process works
smoothly, we would like to reach out to those who take care of building
systems packages before the 3.2 release is shipped and resolve any
issues that may come up.
[issue]: https://bugs.ruby-lang.org/issues/18481
Co-authored-by: Maxime Chevalier-Boisvert <maximechevalierb@gmail.com>
Co-authored-by: Noah Gibbs <the.codefolio.guy@gmail.com>
Co-authored-by: Kevin Newton <kddnewton@gmail.com>
2022-04-19 21:40:21 +03:00
|
|
|
#include "darray.h"
|
2019-12-04 11:16:30 +03:00
|
|
|
#include "ruby/encoding.h"
|
|
|
|
#include "ruby/util.h"
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2023-12-08 09:06:12 +03:00
|
|
|
static VALUE ruby_dln_libmap;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2011-05-22 16:52:18 +04:00
|
|
|
#define IS_RBEXT(e) (strcmp((e), ".rb") == 0)
|
|
|
|
#define IS_SOEXT(e) (strcmp((e), ".so") == 0 || strcmp((e), ".o") == 0)
|
|
|
|
#define IS_DLEXT(e) (strcmp((e), DLEXT) == 0)
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2023-12-08 09:06:12 +03:00
|
|
|
#if SIZEOF_VALUE <= SIZEOF_LONG
|
|
|
|
# define SVALUE2NUM(x) LONG2NUM((long)(x))
|
|
|
|
# define NUM2SVALUE(x) (SIGNED_VALUE)NUM2LONG(x)
|
|
|
|
#elif SIZEOF_VALUE <= SIZEOF_LONG_LONG
|
|
|
|
# define SVALUE2NUM(x) LL2NUM((LONG_LONG)(x))
|
|
|
|
# define NUM2SVALUE(x) (SIGNED_VALUE)NUM2LL(x)
|
|
|
|
#else
|
|
|
|
# error Need integer for VALUE
|
|
|
|
#endif
|
|
|
|
|
2023-08-22 12:13:09 +03:00
|
|
|
enum {
|
|
|
|
loadable_ext_rb = (0+ /* .rb extension is the first in both tables */
|
|
|
|
1) /* offset by rb_find_file_ext() */
|
|
|
|
};
|
|
|
|
|
2007-05-03 17:19:11 +04:00
|
|
|
static const char *const loadable_ext[] = {
|
|
|
|
".rb", DLEXT,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
2021-07-27 23:55:21 +03:00
|
|
|
static const char *const ruby_ext[] = {
|
|
|
|
".rb",
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
2012-11-05 19:27:08 +04:00
|
|
|
enum expand_type {
|
|
|
|
EXPAND_ALL,
|
|
|
|
EXPAND_RELATIVE,
|
|
|
|
EXPAND_HOME,
|
|
|
|
EXPAND_NON_CACHE
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Construct expanded load path and store it to cache.
|
|
|
|
We rebuild load path partially if the cache is invalid.
|
2012-11-07 02:00:12 +04:00
|
|
|
We don't cache non string object and expand it every time. We ensure that
|
2012-11-05 19:27:08 +04:00
|
|
|
string objects in $LOAD_PATH are frozen.
|
|
|
|
*/
|
2012-11-05 19:27:05 +04:00
|
|
|
static void
|
2021-09-16 19:20:10 +03:00
|
|
|
rb_construct_expanded_load_path(rb_vm_t *vm, enum expand_type type, int *has_relative, int *has_non_cache)
|
2008-12-12 05:00:55 +03:00
|
|
|
{
|
2012-11-05 19:27:05 +04:00
|
|
|
VALUE load_path = vm->load_path;
|
2012-11-05 19:27:08 +04:00
|
|
|
VALUE expanded_load_path = vm->expanded_load_path;
|
2010-03-13 04:34:38 +03:00
|
|
|
VALUE ary;
|
2008-12-12 05:00:55 +03:00
|
|
|
long i;
|
|
|
|
|
2022-07-25 17:40:45 +03:00
|
|
|
ary = rb_ary_hidden_new(RARRAY_LEN(load_path));
|
2008-12-12 05:00:55 +03:00
|
|
|
for (i = 0; i < RARRAY_LEN(load_path); ++i) {
|
2012-11-05 19:27:05 +04:00
|
|
|
VALUE path, as_str, expanded_path;
|
2012-11-05 19:27:08 +04:00
|
|
|
int is_string, non_cache;
|
|
|
|
char *as_cstr;
|
2013-05-13 13:56:22 +04:00
|
|
|
as_str = path = RARRAY_AREF(load_path, i);
|
2012-11-05 19:27:08 +04:00
|
|
|
is_string = RB_TYPE_P(path, T_STRING) ? 1 : 0;
|
|
|
|
non_cache = !is_string ? 1 : 0;
|
2019-09-21 05:06:22 +03:00
|
|
|
as_str = rb_get_path_check_to_string(path);
|
2012-11-05 19:27:08 +04:00
|
|
|
as_cstr = RSTRING_PTR(as_str);
|
2022-07-21 19:23:58 +03:00
|
|
|
|
2012-11-05 19:27:08 +04:00
|
|
|
if (!non_cache) {
|
|
|
|
if ((type == EXPAND_RELATIVE &&
|
|
|
|
rb_is_absolute_path(as_cstr)) ||
|
|
|
|
(type == EXPAND_HOME &&
|
|
|
|
(!as_cstr[0] || as_cstr[0] != '~')) ||
|
|
|
|
(type == EXPAND_NON_CACHE)) {
|
|
|
|
/* Use cached expanded path. */
|
2013-05-13 13:56:22 +04:00
|
|
|
rb_ary_push(ary, RARRAY_AREF(expanded_load_path, i));
|
2012-11-05 19:27:08 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!*has_relative && !rb_is_absolute_path(as_cstr))
|
|
|
|
*has_relative = 1;
|
|
|
|
if (!*has_non_cache && non_cache)
|
|
|
|
*has_non_cache = 1;
|
2012-11-07 02:00:12 +04:00
|
|
|
/* Freeze only string object. We expand other objects every time. */
|
2012-11-05 19:27:08 +04:00
|
|
|
if (is_string)
|
|
|
|
rb_str_freeze(path);
|
2019-09-21 05:06:22 +03:00
|
|
|
as_str = rb_get_path_check_convert(as_str);
|
2019-12-03 02:12:57 +03:00
|
|
|
expanded_path = rb_check_realpath(Qnil, as_str, NULL);
|
2017-09-21 10:29:20 +03:00
|
|
|
if (NIL_P(expanded_path)) expanded_path = as_str;
|
2015-07-16 03:03:40 +03:00
|
|
|
rb_ary_push(ary, rb_fstring(expanded_path));
|
2008-12-12 05:00:55 +03:00
|
|
|
}
|
|
|
|
rb_obj_freeze(ary);
|
2012-11-05 19:27:05 +04:00
|
|
|
vm->expanded_load_path = ary;
|
|
|
|
rb_ary_replace(vm->load_path_snapshot, vm->load_path);
|
|
|
|
}
|
|
|
|
|
2021-09-16 19:20:10 +03:00
|
|
|
static VALUE
|
|
|
|
get_expanded_load_path(rb_vm_t *vm)
|
2012-11-05 19:27:05 +04:00
|
|
|
{
|
2012-11-05 19:27:08 +04:00
|
|
|
const VALUE non_cache = Qtrue;
|
|
|
|
|
2012-11-05 19:27:05 +04:00
|
|
|
if (!rb_ary_shared_with_p(vm->load_path_snapshot, vm->load_path)) {
|
2012-11-05 19:27:08 +04:00
|
|
|
/* The load path was modified. Rebuild the expanded load path. */
|
|
|
|
int has_relative = 0, has_non_cache = 0;
|
2021-09-16 19:20:10 +03:00
|
|
|
rb_construct_expanded_load_path(vm, EXPAND_ALL, &has_relative, &has_non_cache);
|
2012-11-05 19:27:08 +04:00
|
|
|
if (has_relative) {
|
2017-11-12 07:45:51 +03:00
|
|
|
vm->load_path_check_cache = rb_dir_getwd_ospath();
|
2012-11-05 19:27:08 +04:00
|
|
|
}
|
|
|
|
else if (has_non_cache) {
|
|
|
|
/* Non string object. */
|
|
|
|
vm->load_path_check_cache = non_cache;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
vm->load_path_check_cache = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (vm->load_path_check_cache == non_cache) {
|
|
|
|
int has_relative = 1, has_non_cache = 1;
|
|
|
|
/* Expand only non-cacheable objects. */
|
2021-09-16 19:20:10 +03:00
|
|
|
rb_construct_expanded_load_path(vm, EXPAND_NON_CACHE,
|
2012-11-05 19:27:08 +04:00
|
|
|
&has_relative, &has_non_cache);
|
|
|
|
}
|
|
|
|
else if (vm->load_path_check_cache) {
|
|
|
|
int has_relative = 1, has_non_cache = 1;
|
2017-11-12 07:45:51 +03:00
|
|
|
VALUE cwd = rb_dir_getwd_ospath();
|
2012-11-05 19:27:08 +04:00
|
|
|
if (!rb_str_equal(vm->load_path_check_cache, cwd)) {
|
|
|
|
/* Current working directory or filesystem encoding was changed.
|
|
|
|
Expand relative load path and non-cacheable objects again. */
|
|
|
|
vm->load_path_check_cache = cwd;
|
2021-09-16 19:20:10 +03:00
|
|
|
rb_construct_expanded_load_path(vm, EXPAND_RELATIVE,
|
2012-11-05 19:27:08 +04:00
|
|
|
&has_relative, &has_non_cache);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Expand only tilde (User HOME) and non-cacheable objects. */
|
2021-09-16 19:20:10 +03:00
|
|
|
rb_construct_expanded_load_path(vm, EXPAND_HOME,
|
2012-11-05 19:27:08 +04:00
|
|
|
&has_relative, &has_non_cache);
|
|
|
|
}
|
2012-11-05 19:27:05 +04:00
|
|
|
}
|
|
|
|
return vm->expanded_load_path;
|
2008-12-12 05:00:55 +03:00
|
|
|
}
|
|
|
|
|
2021-09-16 19:20:10 +03:00
|
|
|
VALUE
|
|
|
|
rb_get_expanded_load_path(void)
|
|
|
|
{
|
|
|
|
return get_expanded_load_path(GET_VM());
|
|
|
|
}
|
|
|
|
|
2008-04-30 13:03:03 +04:00
|
|
|
static VALUE
|
2019-08-27 05:16:52 +03:00
|
|
|
load_path_getter(ID id, VALUE * p)
|
2008-04-30 13:03:03 +04:00
|
|
|
{
|
2019-08-27 05:16:52 +03:00
|
|
|
rb_vm_t *vm = (void *)p;
|
2008-04-30 13:03:03 +04:00
|
|
|
return vm->load_path;
|
|
|
|
}
|
|
|
|
|
2007-02-14 05:19:02 +03:00
|
|
|
static VALUE
|
2021-09-16 19:20:10 +03:00
|
|
|
get_loaded_features(rb_vm_t *vm)
|
2007-02-14 05:19:02 +03:00
|
|
|
{
|
2021-09-16 19:20:10 +03:00
|
|
|
return vm->loaded_features;
|
2007-02-14 05:19:02 +03:00
|
|
|
}
|
|
|
|
|
Do not load file with same realpath twice when requiring
This fixes issues with paths being loaded twice in certain cases
when symlinks are used.
It took me multiple attempts to get this working. My original
attempt tried to convert paths to realpaths before adding them
to $LOADED_FEATURES. Unfortunately, this doesn't work well
with the loaded feature index, which is based off load paths
and not realpaths. While I was able to get require working, I'm
fairly sure the loaded feature index was not being used as
expected, which would have significant performance implications.
Additionally, I was never able to get that approach working with
autoload when autoloading a non-realpath file. It also broke
some specs.
This takes a more conservative approach. Directly before loading the
file, if the file with the same realpath has been required, the
loading of the file is skipped. The realpaths are stored as
fstrings in a hidden hash.
When rebuilding the loaded feature index, the hash of realpaths
is also rebuilt. I'm guessing this makes rebuilding process
slower, but I don think that is a hot path. In general, modifying
loaded features is only done when reloading, and that tends to be
in non-production environments.
Change test_require_with_loaded_features_pop test to use 30 threads
and 300 iterations, instead of 4 threads and 1000 iterations.
I saw only sporadic failures with 4/1000, but consistent failures
30/300 threads. These failures were due to the fact that the
concurrent deletions from $LOADED_FEATURES in other threads can
result in rb_ary_entry returning nil when rebuilding the loaded
features index.
To avoid concurrency issues when rebuilding the loaded features
index, the building of the index itself is left alone, and
afterwards, a separate loop is done on a copy of the loaded feature
snapshot in order to rebuild the realpaths hash.
Fixes [Bug #17885]
2021-06-30 23:50:19 +03:00
|
|
|
static VALUE
|
2021-09-16 19:20:10 +03:00
|
|
|
get_loaded_features_realpaths(rb_vm_t *vm)
|
Do not load file with same realpath twice when requiring
This fixes issues with paths being loaded twice in certain cases
when symlinks are used.
It took me multiple attempts to get this working. My original
attempt tried to convert paths to realpaths before adding them
to $LOADED_FEATURES. Unfortunately, this doesn't work well
with the loaded feature index, which is based off load paths
and not realpaths. While I was able to get require working, I'm
fairly sure the loaded feature index was not being used as
expected, which would have significant performance implications.
Additionally, I was never able to get that approach working with
autoload when autoloading a non-realpath file. It also broke
some specs.
This takes a more conservative approach. Directly before loading the
file, if the file with the same realpath has been required, the
loading of the file is skipped. The realpaths are stored as
fstrings in a hidden hash.
When rebuilding the loaded feature index, the hash of realpaths
is also rebuilt. I'm guessing this makes rebuilding process
slower, but I don think that is a hot path. In general, modifying
loaded features is only done when reloading, and that tends to be
in non-production environments.
Change test_require_with_loaded_features_pop test to use 30 threads
and 300 iterations, instead of 4 threads and 1000 iterations.
I saw only sporadic failures with 4/1000, but consistent failures
30/300 threads. These failures were due to the fact that the
concurrent deletions from $LOADED_FEATURES in other threads can
result in rb_ary_entry returning nil when rebuilding the loaded
features index.
To avoid concurrency issues when rebuilding the loaded features
index, the building of the index itself is left alone, and
afterwards, a separate loop is done on a copy of the loaded feature
snapshot in order to rebuild the realpaths hash.
Fixes [Bug #17885]
2021-06-30 23:50:19 +03:00
|
|
|
{
|
2021-09-16 19:20:10 +03:00
|
|
|
return vm->loaded_features_realpaths;
|
Do not load file with same realpath twice when requiring
This fixes issues with paths being loaded twice in certain cases
when symlinks are used.
It took me multiple attempts to get this working. My original
attempt tried to convert paths to realpaths before adding them
to $LOADED_FEATURES. Unfortunately, this doesn't work well
with the loaded feature index, which is based off load paths
and not realpaths. While I was able to get require working, I'm
fairly sure the loaded feature index was not being used as
expected, which would have significant performance implications.
Additionally, I was never able to get that approach working with
autoload when autoloading a non-realpath file. It also broke
some specs.
This takes a more conservative approach. Directly before loading the
file, if the file with the same realpath has been required, the
loading of the file is skipped. The realpaths are stored as
fstrings in a hidden hash.
When rebuilding the loaded feature index, the hash of realpaths
is also rebuilt. I'm guessing this makes rebuilding process
slower, but I don think that is a hot path. In general, modifying
loaded features is only done when reloading, and that tends to be
in non-production environments.
Change test_require_with_loaded_features_pop test to use 30 threads
and 300 iterations, instead of 4 threads and 1000 iterations.
I saw only sporadic failures with 4/1000, but consistent failures
30/300 threads. These failures were due to the fact that the
concurrent deletions from $LOADED_FEATURES in other threads can
result in rb_ary_entry returning nil when rebuilding the loaded
features index.
To avoid concurrency issues when rebuilding the loaded features
index, the building of the index itself is left alone, and
afterwards, a separate loop is done on a copy of the loaded feature
snapshot in order to rebuild the realpaths hash.
Fixes [Bug #17885]
2021-06-30 23:50:19 +03:00
|
|
|
}
|
|
|
|
|
2023-04-12 22:33:16 +03:00
|
|
|
static VALUE
|
|
|
|
get_loaded_features_realpath_map(rb_vm_t *vm)
|
|
|
|
{
|
|
|
|
return vm->loaded_features_realpath_map;
|
|
|
|
}
|
|
|
|
|
2019-08-27 05:16:52 +03:00
|
|
|
static VALUE
|
2019-08-27 08:21:18 +03:00
|
|
|
get_LOADED_FEATURES(ID _x, VALUE *_y)
|
2019-08-27 05:16:52 +03:00
|
|
|
{
|
2021-09-16 19:20:10 +03:00
|
|
|
return get_loaded_features(GET_VM());
|
2019-08-27 05:16:52 +03:00
|
|
|
}
|
|
|
|
|
2012-11-05 19:27:01 +04:00
|
|
|
static void
|
2021-09-16 19:20:10 +03:00
|
|
|
reset_loaded_features_snapshot(rb_vm_t *vm)
|
2012-11-05 19:27:01 +04:00
|
|
|
{
|
|
|
|
rb_ary_replace(vm->loaded_features_snapshot, vm->loaded_features);
|
|
|
|
}
|
|
|
|
|
2013-03-22 12:38:51 +04:00
|
|
|
static struct st_table *
|
2021-09-16 19:20:10 +03:00
|
|
|
get_loaded_features_index_raw(rb_vm_t *vm)
|
2012-11-05 19:27:01 +04:00
|
|
|
{
|
2021-09-16 19:20:10 +03:00
|
|
|
return vm->loaded_features_index;
|
2012-11-05 19:27:01 +04:00
|
|
|
}
|
|
|
|
|
2007-05-03 17:19:11 +04:00
|
|
|
static st_table *
|
2021-09-16 19:20:10 +03:00
|
|
|
get_loading_table(rb_vm_t *vm)
|
2007-05-03 17:19:11 +04:00
|
|
|
{
|
2021-09-16 19:20:10 +03:00
|
|
|
return vm->loading_table;
|
2007-05-03 17:19:11 +04:00
|
|
|
}
|
|
|
|
|
2018-02-14 21:38:33 +03:00
|
|
|
static st_data_t
|
|
|
|
feature_key(const char *str, size_t len)
|
|
|
|
{
|
|
|
|
return st_hash(str, len, 0xfea7009e);
|
|
|
|
}
|
|
|
|
|
2021-07-12 19:03:26 +03:00
|
|
|
static bool
|
|
|
|
is_rbext_path(VALUE feature_path)
|
|
|
|
{
|
|
|
|
long len = RSTRING_LEN(feature_path);
|
|
|
|
long rbext_len = rb_strlen_lit(".rb");
|
|
|
|
if (len <= rbext_len) return false;
|
|
|
|
return IS_RBEXT(RSTRING_PTR(feature_path) + len - rbext_len);
|
|
|
|
}
|
|
|
|
|
2022-02-15 17:57:33 +03:00
|
|
|
typedef rb_darray(long) feature_indexes_t;
|
|
|
|
|
|
|
|
struct features_index_add_single_args {
|
|
|
|
rb_vm_t *vm;
|
|
|
|
VALUE offset;
|
|
|
|
bool rb;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
features_index_add_single_callback(st_data_t *key, st_data_t *value, st_data_t raw_args, int existing)
|
|
|
|
{
|
|
|
|
struct features_index_add_single_args *args = (struct features_index_add_single_args *)raw_args;
|
|
|
|
rb_vm_t *vm = args->vm;
|
|
|
|
VALUE offset = args->offset;
|
|
|
|
bool rb = args->rb;
|
|
|
|
|
|
|
|
if (existing) {
|
|
|
|
VALUE this_feature_index = *value;
|
|
|
|
|
|
|
|
if (FIXNUM_P(this_feature_index)) {
|
|
|
|
VALUE loaded_features = get_loaded_features(vm);
|
|
|
|
VALUE this_feature_path = RARRAY_AREF(loaded_features, FIX2LONG(this_feature_index));
|
|
|
|
|
|
|
|
feature_indexes_t feature_indexes;
|
2022-05-02 21:45:52 +03:00
|
|
|
rb_darray_make(&feature_indexes, 2);
|
2022-02-15 17:57:33 +03:00
|
|
|
int top = (rb && !is_rbext_path(this_feature_path)) ? 1 : 0;
|
|
|
|
rb_darray_set(feature_indexes, top^0, FIX2LONG(this_feature_index));
|
|
|
|
rb_darray_set(feature_indexes, top^1, FIX2LONG(offset));
|
|
|
|
|
|
|
|
assert(rb_darray_size(feature_indexes) == 2);
|
|
|
|
// assert feature_indexes does not look like a special const
|
|
|
|
assert(!SPECIAL_CONST_P((VALUE)feature_indexes));
|
|
|
|
|
|
|
|
*value = (st_data_t)feature_indexes;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
feature_indexes_t feature_indexes = (feature_indexes_t)this_feature_index;
|
|
|
|
long pos = -1;
|
|
|
|
|
|
|
|
if (rb) {
|
|
|
|
VALUE loaded_features = get_loaded_features(vm);
|
|
|
|
for (size_t i = 0; i < rb_darray_size(feature_indexes); ++i) {
|
|
|
|
long idx = rb_darray_get(feature_indexes, i);
|
|
|
|
VALUE this_feature_path = RARRAY_AREF(loaded_features, idx);
|
|
|
|
Check_Type(this_feature_path, T_STRING);
|
|
|
|
if (!is_rbext_path(this_feature_path)) {
|
|
|
|
pos = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-02 21:45:52 +03:00
|
|
|
rb_darray_append(&feature_indexes, FIX2LONG(offset));
|
2022-02-15 17:57:33 +03:00
|
|
|
/* darray may realloc which will change the pointer */
|
|
|
|
*value = (st_data_t)feature_indexes;
|
|
|
|
|
|
|
|
if (pos >= 0) {
|
|
|
|
long *ptr = rb_darray_data_ptr(feature_indexes);
|
|
|
|
long len = rb_darray_size(feature_indexes);
|
|
|
|
MEMMOVE(ptr + pos, ptr + pos + 1, long, len - pos - 1);
|
|
|
|
ptr[pos] = FIX2LONG(offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*value = offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ST_CONTINUE;
|
|
|
|
}
|
|
|
|
|
2012-11-05 19:27:01 +04:00
|
|
|
static void
|
2021-09-16 19:20:10 +03:00
|
|
|
features_index_add_single(rb_vm_t *vm, const char* str, size_t len, VALUE offset, bool rb)
|
2012-11-05 19:27:01 +04:00
|
|
|
{
|
2013-03-22 12:38:51 +04:00
|
|
|
struct st_table *features_index;
|
2018-02-14 21:38:33 +03:00
|
|
|
st_data_t short_feature_key;
|
2013-03-22 12:38:51 +04:00
|
|
|
|
|
|
|
Check_Type(offset, T_FIXNUM);
|
2018-02-14 21:38:33 +03:00
|
|
|
short_feature_key = feature_key(str, len);
|
2013-03-22 12:38:51 +04:00
|
|
|
|
2021-09-16 19:20:10 +03:00
|
|
|
features_index = get_loaded_features_index_raw(vm);
|
2021-07-12 19:03:26 +03:00
|
|
|
|
2022-02-15 17:57:33 +03:00
|
|
|
struct features_index_add_single_args args = {
|
|
|
|
.vm = vm,
|
|
|
|
.offset = offset,
|
|
|
|
.rb = rb,
|
|
|
|
};
|
|
|
|
|
|
|
|
st_update(features_index, short_feature_key, features_index_add_single_callback, (st_data_t)&args);
|
2012-11-05 19:27:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Add to the loaded-features index all the required entries for
|
|
|
|
`feature`, located at `offset` in $LOADED_FEATURES. We add an
|
|
|
|
index entry at each string `short_feature` for which
|
2015-08-13 02:43:41 +03:00
|
|
|
feature == "#{prefix}#{short_feature}#{ext}"
|
|
|
|
where `ext` is empty or matches %r{^\.[^./]*$}, and `prefix` is empty
|
2012-11-05 19:27:01 +04:00
|
|
|
or ends in '/'. This maintains the invariant that `rb_feature_p()`
|
|
|
|
relies on for its fast lookup.
|
|
|
|
*/
|
|
|
|
static void
|
2021-09-16 19:20:10 +03:00
|
|
|
features_index_add(rb_vm_t *vm, VALUE feature, VALUE offset)
|
2012-11-05 19:27:01 +04:00
|
|
|
{
|
|
|
|
const char *feature_str, *feature_end, *ext, *p;
|
2021-07-12 19:03:26 +03:00
|
|
|
bool rb = false;
|
2012-11-05 19:27:01 +04:00
|
|
|
|
|
|
|
feature_str = StringValuePtr(feature);
|
|
|
|
feature_end = feature_str + RSTRING_LEN(feature);
|
|
|
|
|
|
|
|
for (ext = feature_end; ext > feature_str; ext--)
|
2016-12-09 05:59:55 +03:00
|
|
|
if (*ext == '.' || *ext == '/')
|
|
|
|
break;
|
2012-11-05 19:27:01 +04:00
|
|
|
if (*ext != '.')
|
2016-12-09 05:59:55 +03:00
|
|
|
ext = NULL;
|
2021-07-12 19:03:26 +03:00
|
|
|
else
|
|
|
|
rb = IS_RBEXT(ext);
|
2012-11-05 19:27:01 +04:00
|
|
|
/* Now `ext` points to the only string matching %r{^\.[^./]*$} that is
|
|
|
|
at the end of `feature`, or is NULL if there is no such string. */
|
|
|
|
|
|
|
|
p = ext ? ext : feature_end;
|
|
|
|
while (1) {
|
|
|
|
p--;
|
|
|
|
while (p >= feature_str && *p != '/')
|
|
|
|
p--;
|
|
|
|
if (p < feature_str)
|
|
|
|
break;
|
|
|
|
/* Now *p == '/'. We reach this point for every '/' in `feature`. */
|
2021-09-16 19:20:10 +03:00
|
|
|
features_index_add_single(vm, p + 1, feature_end - p - 1, offset, false);
|
2012-11-05 19:27:01 +04:00
|
|
|
if (ext) {
|
2021-09-16 19:20:10 +03:00
|
|
|
features_index_add_single(vm, p + 1, ext - p - 1, offset, rb);
|
2012-11-05 19:27:01 +04:00
|
|
|
}
|
|
|
|
}
|
2021-09-16 19:20:10 +03:00
|
|
|
features_index_add_single(vm, feature_str, feature_end - feature_str, offset, false);
|
2012-11-05 19:27:01 +04:00
|
|
|
if (ext) {
|
2021-09-16 19:20:10 +03:00
|
|
|
features_index_add_single(vm, feature_str, ext - feature_str, offset, rb);
|
2012-11-05 19:27:01 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-22 12:38:51 +04:00
|
|
|
static int
|
|
|
|
loaded_features_index_clear_i(st_data_t key, st_data_t val, st_data_t arg)
|
|
|
|
{
|
2013-12-03 12:13:31 +04:00
|
|
|
VALUE obj = (VALUE)val;
|
|
|
|
if (!SPECIAL_CONST_P(obj)) {
|
2022-05-02 21:45:52 +03:00
|
|
|
rb_darray_free((void *)obj);
|
2013-12-03 12:13:31 +04:00
|
|
|
}
|
2013-03-22 12:38:51 +04:00
|
|
|
return ST_DELETE;
|
|
|
|
}
|
|
|
|
|
2023-10-12 21:15:53 +03:00
|
|
|
void
|
|
|
|
rb_free_loaded_features_index(rb_vm_t *vm)
|
|
|
|
{
|
|
|
|
st_foreach(vm->loaded_features_index, loaded_features_index_clear_i, 0);
|
|
|
|
st_free_table(vm->loaded_features_index);
|
|
|
|
}
|
|
|
|
|
2013-03-22 12:38:51 +04:00
|
|
|
static st_table *
|
2021-09-16 19:20:10 +03:00
|
|
|
get_loaded_features_index(rb_vm_t *vm)
|
2012-11-05 19:27:01 +04:00
|
|
|
{
|
|
|
|
VALUE features;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!rb_ary_shared_with_p(vm->loaded_features_snapshot, vm->loaded_features)) {
|
|
|
|
/* The sharing was broken; something (other than us in rb_provide_feature())
|
|
|
|
modified loaded_features. Rebuild the index. */
|
2013-03-22 12:38:51 +04:00
|
|
|
st_foreach(vm->loaded_features_index, loaded_features_index_clear_i, 0);
|
Do not load file with same realpath twice when requiring
This fixes issues with paths being loaded twice in certain cases
when symlinks are used.
It took me multiple attempts to get this working. My original
attempt tried to convert paths to realpaths before adding them
to $LOADED_FEATURES. Unfortunately, this doesn't work well
with the loaded feature index, which is based off load paths
and not realpaths. While I was able to get require working, I'm
fairly sure the loaded feature index was not being used as
expected, which would have significant performance implications.
Additionally, I was never able to get that approach working with
autoload when autoloading a non-realpath file. It also broke
some specs.
This takes a more conservative approach. Directly before loading the
file, if the file with the same realpath has been required, the
loading of the file is skipped. The realpaths are stored as
fstrings in a hidden hash.
When rebuilding the loaded feature index, the hash of realpaths
is also rebuilt. I'm guessing this makes rebuilding process
slower, but I don think that is a hot path. In general, modifying
loaded features is only done when reloading, and that tends to be
in non-production environments.
Change test_require_with_loaded_features_pop test to use 30 threads
and 300 iterations, instead of 4 threads and 1000 iterations.
I saw only sporadic failures with 4/1000, but consistent failures
30/300 threads. These failures were due to the fact that the
concurrent deletions from $LOADED_FEATURES in other threads can
result in rb_ary_entry returning nil when rebuilding the loaded
features index.
To avoid concurrency issues when rebuilding the loaded features
index, the building of the index itself is left alone, and
afterwards, a separate loop is done on a copy of the loaded feature
snapshot in order to rebuild the realpaths hash.
Fixes [Bug #17885]
2021-06-30 23:50:19 +03:00
|
|
|
|
|
|
|
VALUE realpaths = vm->loaded_features_realpaths;
|
2023-04-12 22:33:16 +03:00
|
|
|
VALUE realpath_map = vm->loaded_features_realpath_map;
|
|
|
|
VALUE previous_realpath_map = rb_hash_dup(realpath_map);
|
Do not load file with same realpath twice when requiring
This fixes issues with paths being loaded twice in certain cases
when symlinks are used.
It took me multiple attempts to get this working. My original
attempt tried to convert paths to realpaths before adding them
to $LOADED_FEATURES. Unfortunately, this doesn't work well
with the loaded feature index, which is based off load paths
and not realpaths. While I was able to get require working, I'm
fairly sure the loaded feature index was not being used as
expected, which would have significant performance implications.
Additionally, I was never able to get that approach working with
autoload when autoloading a non-realpath file. It also broke
some specs.
This takes a more conservative approach. Directly before loading the
file, if the file with the same realpath has been required, the
loading of the file is skipped. The realpaths are stored as
fstrings in a hidden hash.
When rebuilding the loaded feature index, the hash of realpaths
is also rebuilt. I'm guessing this makes rebuilding process
slower, but I don think that is a hot path. In general, modifying
loaded features is only done when reloading, and that tends to be
in non-production environments.
Change test_require_with_loaded_features_pop test to use 30 threads
and 300 iterations, instead of 4 threads and 1000 iterations.
I saw only sporadic failures with 4/1000, but consistent failures
30/300 threads. These failures were due to the fact that the
concurrent deletions from $LOADED_FEATURES in other threads can
result in rb_ary_entry returning nil when rebuilding the loaded
features index.
To avoid concurrency issues when rebuilding the loaded features
index, the building of the index itself is left alone, and
afterwards, a separate loop is done on a copy of the loaded feature
snapshot in order to rebuild the realpaths hash.
Fixes [Bug #17885]
2021-06-30 23:50:19 +03:00
|
|
|
rb_hash_clear(realpaths);
|
2023-04-12 22:33:16 +03:00
|
|
|
rb_hash_clear(realpath_map);
|
2012-11-05 19:27:01 +04:00
|
|
|
features = vm->loaded_features;
|
|
|
|
for (i = 0; i < RARRAY_LEN(features); i++) {
|
|
|
|
VALUE entry, as_str;
|
|
|
|
as_str = entry = rb_ary_entry(features, i);
|
|
|
|
StringValue(as_str);
|
2022-12-27 04:32:07 +03:00
|
|
|
as_str = rb_fstring(as_str);
|
2012-11-05 19:27:01 +04:00
|
|
|
if (as_str != entry)
|
|
|
|
rb_ary_store(features, i, as_str);
|
2021-09-16 19:20:10 +03:00
|
|
|
features_index_add(vm, as_str, INT2FIX(i));
|
2012-11-05 19:27:01 +04:00
|
|
|
}
|
2021-09-16 19:20:10 +03:00
|
|
|
reset_loaded_features_snapshot(vm);
|
Do not load file with same realpath twice when requiring
This fixes issues with paths being loaded twice in certain cases
when symlinks are used.
It took me multiple attempts to get this working. My original
attempt tried to convert paths to realpaths before adding them
to $LOADED_FEATURES. Unfortunately, this doesn't work well
with the loaded feature index, which is based off load paths
and not realpaths. While I was able to get require working, I'm
fairly sure the loaded feature index was not being used as
expected, which would have significant performance implications.
Additionally, I was never able to get that approach working with
autoload when autoloading a non-realpath file. It also broke
some specs.
This takes a more conservative approach. Directly before loading the
file, if the file with the same realpath has been required, the
loading of the file is skipped. The realpaths are stored as
fstrings in a hidden hash.
When rebuilding the loaded feature index, the hash of realpaths
is also rebuilt. I'm guessing this makes rebuilding process
slower, but I don think that is a hot path. In general, modifying
loaded features is only done when reloading, and that tends to be
in non-production environments.
Change test_require_with_loaded_features_pop test to use 30 threads
and 300 iterations, instead of 4 threads and 1000 iterations.
I saw only sporadic failures with 4/1000, but consistent failures
30/300 threads. These failures were due to the fact that the
concurrent deletions from $LOADED_FEATURES in other threads can
result in rb_ary_entry returning nil when rebuilding the loaded
features index.
To avoid concurrency issues when rebuilding the loaded features
index, the building of the index itself is left alone, and
afterwards, a separate loop is done on a copy of the loaded feature
snapshot in order to rebuild the realpaths hash.
Fixes [Bug #17885]
2021-06-30 23:50:19 +03:00
|
|
|
|
|
|
|
features = rb_ary_dup(vm->loaded_features_snapshot);
|
|
|
|
long j = RARRAY_LEN(features);
|
|
|
|
for (i = 0; i < j; i++) {
|
|
|
|
VALUE as_str = rb_ary_entry(features, i);
|
2023-04-12 22:33:16 +03:00
|
|
|
VALUE realpath = rb_hash_aref(previous_realpath_map, as_str);
|
|
|
|
if (NIL_P(realpath)) {
|
|
|
|
realpath = rb_check_realpath(Qnil, as_str, NULL);
|
|
|
|
if (NIL_P(realpath)) realpath = as_str;
|
|
|
|
realpath = rb_fstring(realpath);
|
|
|
|
}
|
|
|
|
rb_hash_aset(realpaths, realpath, Qtrue);
|
|
|
|
rb_hash_aset(realpath_map, as_str, realpath);
|
Do not load file with same realpath twice when requiring
This fixes issues with paths being loaded twice in certain cases
when symlinks are used.
It took me multiple attempts to get this working. My original
attempt tried to convert paths to realpaths before adding them
to $LOADED_FEATURES. Unfortunately, this doesn't work well
with the loaded feature index, which is based off load paths
and not realpaths. While I was able to get require working, I'm
fairly sure the loaded feature index was not being used as
expected, which would have significant performance implications.
Additionally, I was never able to get that approach working with
autoload when autoloading a non-realpath file. It also broke
some specs.
This takes a more conservative approach. Directly before loading the
file, if the file with the same realpath has been required, the
loading of the file is skipped. The realpaths are stored as
fstrings in a hidden hash.
When rebuilding the loaded feature index, the hash of realpaths
is also rebuilt. I'm guessing this makes rebuilding process
slower, but I don think that is a hot path. In general, modifying
loaded features is only done when reloading, and that tends to be
in non-production environments.
Change test_require_with_loaded_features_pop test to use 30 threads
and 300 iterations, instead of 4 threads and 1000 iterations.
I saw only sporadic failures with 4/1000, but consistent failures
30/300 threads. These failures were due to the fact that the
concurrent deletions from $LOADED_FEATURES in other threads can
result in rb_ary_entry returning nil when rebuilding the loaded
features index.
To avoid concurrency issues when rebuilding the loaded features
index, the building of the index itself is left alone, and
afterwards, a separate loop is done on a copy of the loaded feature
snapshot in order to rebuild the realpaths hash.
Fixes [Bug #17885]
2021-06-30 23:50:19 +03:00
|
|
|
}
|
2012-11-05 19:27:01 +04:00
|
|
|
}
|
|
|
|
return vm->loaded_features_index;
|
|
|
|
}
|
|
|
|
|
2012-11-05 19:24:03 +04:00
|
|
|
/* This searches `load_path` for a value such that
|
|
|
|
name == "#{load_path[i]}/#{feature}"
|
|
|
|
if `feature` is a suffix of `name`, or otherwise
|
|
|
|
name == "#{load_path[i]}/#{feature}#{ext}"
|
|
|
|
for an acceptable string `ext`. It returns
|
|
|
|
`load_path[i].to_str` if found, else 0.
|
|
|
|
|
|
|
|
If type is 's', then `ext` is acceptable only if IS_DLEXT(ext);
|
|
|
|
if 'r', then only if IS_RBEXT(ext); otherwise `ext` may be absent
|
|
|
|
or have any value matching `%r{^\.[^./]*$}`.
|
|
|
|
*/
|
2007-11-06 09:52:01 +03:00
|
|
|
static VALUE
|
2007-11-06 10:37:49 +03:00
|
|
|
loaded_feature_path(const char *name, long vlen, const char *feature, long len,
|
2007-11-09 06:56:38 +03:00
|
|
|
int type, VALUE load_path)
|
2007-11-06 09:52:01 +03:00
|
|
|
{
|
|
|
|
long i;
|
2011-06-01 01:56:01 +04:00
|
|
|
long plen;
|
|
|
|
const char *e;
|
|
|
|
|
2012-11-05 19:24:07 +04:00
|
|
|
if (vlen < len+1) return 0;
|
2015-05-16 22:02:38 +03:00
|
|
|
if (strchr(feature, '.') && !strncmp(name+(vlen-len), feature, len)) {
|
2013-05-23 12:35:34 +04:00
|
|
|
plen = vlen - len;
|
2012-10-29 13:31:50 +04:00
|
|
|
}
|
|
|
|
else {
|
2011-06-01 01:56:01 +04:00
|
|
|
for (e = name + vlen; name != e && *e != '.' && *e != '/'; --e);
|
2012-10-29 13:31:50 +04:00
|
|
|
if (*e != '.' ||
|
2011-06-01 01:56:01 +04:00
|
|
|
e-name < len ||
|
2012-10-29 13:31:50 +04:00
|
|
|
strncmp(e-len, feature, len))
|
2011-06-01 01:56:01 +04:00
|
|
|
return 0;
|
2013-05-23 12:35:34 +04:00
|
|
|
plen = e - name - len;
|
2011-06-01 01:56:01 +04:00
|
|
|
}
|
2013-05-23 12:35:34 +04:00
|
|
|
if (plen > 0 && name[plen-1] != '/') {
|
2013-03-08 09:47:52 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2013-05-23 12:35:34 +04:00
|
|
|
if (type == 's' ? !IS_DLEXT(&name[plen+len]) :
|
|
|
|
type == 'r' ? !IS_RBEXT(&name[plen+len]) :
|
2013-03-08 09:47:52 +04:00
|
|
|
0) {
|
|
|
|
return 0;
|
2012-11-05 19:24:03 +04:00
|
|
|
}
|
|
|
|
/* Now name == "#{prefix}/#{feature}#{ext}" where ext is acceptable
|
|
|
|
(possibly empty) and prefix is some string of length plen. */
|
|
|
|
|
2013-05-23 12:35:34 +04:00
|
|
|
if (plen > 0) --plen; /* exclude '.' */
|
2007-11-06 10:37:49 +03:00
|
|
|
for (i = 0; i < RARRAY_LEN(load_path); ++i) {
|
2013-05-13 13:56:22 +04:00
|
|
|
VALUE p = RARRAY_AREF(load_path, i);
|
2007-11-06 09:52:01 +03:00
|
|
|
const char *s = StringValuePtr(p);
|
|
|
|
long n = RSTRING_LEN(p);
|
|
|
|
|
2012-10-29 13:31:50 +04:00
|
|
|
if (n != plen) continue;
|
2012-11-05 19:24:03 +04:00
|
|
|
if (n && strncmp(name, s, n)) continue;
|
|
|
|
return p;
|
2007-11-06 09:52:01 +03:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct loaded_feature_searching {
|
|
|
|
const char *name;
|
|
|
|
long len;
|
2007-11-09 06:56:38 +03:00
|
|
|
int type;
|
2007-11-06 10:37:49 +03:00
|
|
|
VALUE load_path;
|
2007-11-06 09:52:01 +03:00
|
|
|
const char *result;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
loaded_feature_path_i(st_data_t v, st_data_t b, st_data_t f)
|
|
|
|
{
|
|
|
|
const char *s = (const char *)v;
|
|
|
|
struct loaded_feature_searching *fp = (struct loaded_feature_searching *)f;
|
2007-11-09 06:56:38 +03:00
|
|
|
VALUE p = loaded_feature_path(s, strlen(s), fp->name, fp->len,
|
|
|
|
fp->type, fp->load_path);
|
2007-11-06 09:52:01 +03:00
|
|
|
if (!p) return ST_CONTINUE;
|
|
|
|
fp->result = s;
|
|
|
|
return ST_STOP;
|
|
|
|
}
|
|
|
|
|
2023-08-22 12:13:09 +03:00
|
|
|
/*
|
|
|
|
* Returns the type of already provided feature.
|
|
|
|
* 'r': ruby script (".rb")
|
|
|
|
* 's': shared object (".so"/"."DLEXT)
|
|
|
|
* 'u': unsuffixed
|
|
|
|
*/
|
2006-12-31 18:02:22 +03:00
|
|
|
static int
|
2021-09-16 19:20:10 +03:00
|
|
|
rb_feature_p(rb_vm_t *vm, const char *feature, const char *ext, int rb, int expanded, const char **fn)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2013-03-24 04:04:43 +04:00
|
|
|
VALUE features, this_feature_index = Qnil, v, p, load_path = 0;
|
2007-05-03 17:19:11 +04:00
|
|
|
const char *f, *e;
|
2007-11-06 09:52:01 +03:00
|
|
|
long i, len, elen, n;
|
2013-03-22 12:38:51 +04:00
|
|
|
st_table *loading_tbl, *features_index;
|
2007-12-24 11:06:16 +03:00
|
|
|
st_data_t data;
|
2018-02-14 21:38:33 +03:00
|
|
|
st_data_t key;
|
2007-11-09 06:56:38 +03:00
|
|
|
int type;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2007-12-24 11:06:16 +03:00
|
|
|
if (fn) *fn = 0;
|
2006-12-31 18:02:22 +03:00
|
|
|
if (ext) {
|
|
|
|
elen = strlen(ext);
|
2009-01-29 10:32:07 +03:00
|
|
|
len = strlen(feature) - elen;
|
2007-11-09 06:56:38 +03:00
|
|
|
type = rb ? 'r' : 's';
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
len = strlen(feature);
|
|
|
|
elen = 0;
|
2007-11-09 06:56:38 +03:00
|
|
|
type = 0;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2021-09-16 19:20:10 +03:00
|
|
|
features = get_loaded_features(vm);
|
|
|
|
features_index = get_loaded_features_index(vm);
|
2012-11-05 19:27:01 +04:00
|
|
|
|
2018-02-14 21:38:33 +03:00
|
|
|
key = feature_key(feature, strlen(feature));
|
2012-11-05 19:27:01 +04:00
|
|
|
/* We search `features` for an entry such that either
|
|
|
|
"#{features[i]}" == "#{load_path[j]}/#{feature}#{e}"
|
|
|
|
for some j, or
|
|
|
|
"#{features[i]}" == "#{feature}#{e}"
|
|
|
|
Here `e` is an "allowed" extension -- either empty or one
|
|
|
|
of the extensions accepted by IS_RBEXT, IS_SOEXT, or
|
|
|
|
IS_DLEXT. Further, if `ext && rb` then `IS_RBEXT(e)`,
|
|
|
|
and if `ext && !rb` then `IS_SOEXT(e) || IS_DLEXT(e)`.
|
|
|
|
|
|
|
|
If `expanded`, then only the latter form (without load_path[j])
|
|
|
|
is accepted. Otherwise either form is accepted, *unless* `ext`
|
|
|
|
is false and an otherwise-matching entry of the first form is
|
|
|
|
preceded by an entry of the form
|
|
|
|
"#{features[i2]}" == "#{load_path[j2]}/#{feature}#{e2}"
|
|
|
|
where `e2` matches %r{^\.[^./]*$} but is not an allowed extension.
|
|
|
|
After a "distractor" entry of this form, only entries of the
|
|
|
|
form "#{feature}#{e}" are accepted.
|
|
|
|
|
|
|
|
In `rb_provide_feature()` and `get_loaded_features_index()` we
|
|
|
|
maintain an invariant that the array `this_feature_index` will
|
|
|
|
point to every entry in `features` which has the form
|
|
|
|
"#{prefix}#{feature}#{e}"
|
|
|
|
where `e` is empty or matches %r{^\.[^./]*$}, and `prefix` is empty
|
|
|
|
or ends in '/'. This includes both match forms above, as well
|
|
|
|
as any distractors, so we may ignore all other entries in `features`.
|
|
|
|
*/
|
2021-07-13 18:51:53 +03:00
|
|
|
if (st_lookup(features_index, key, &data) && !NIL_P(this_feature_index = (VALUE)data)) {
|
2022-02-15 17:57:33 +03:00
|
|
|
for (size_t i = 0; ; i++) {
|
2013-03-09 03:54:41 +04:00
|
|
|
long index;
|
2022-02-15 17:57:33 +03:00
|
|
|
if (FIXNUM_P(this_feature_index)) {
|
2013-03-09 03:54:41 +04:00
|
|
|
if (i > 0) break;
|
2022-02-15 17:57:33 +03:00
|
|
|
index = FIX2LONG(this_feature_index);
|
2013-03-09 03:54:41 +04:00
|
|
|
}
|
2022-02-15 17:57:33 +03:00
|
|
|
else {
|
|
|
|
feature_indexes_t feature_indexes = (feature_indexes_t)this_feature_index;
|
|
|
|
if (i >= rb_darray_size(feature_indexes)) break;
|
|
|
|
index = rb_darray_get(feature_indexes, i);
|
|
|
|
}
|
2013-03-09 03:54:41 +04:00
|
|
|
|
2013-05-13 13:56:22 +04:00
|
|
|
v = RARRAY_AREF(features, index);
|
2013-03-09 03:54:41 +04:00
|
|
|
f = StringValuePtr(v);
|
|
|
|
if ((n = RSTRING_LEN(v)) < len) continue;
|
|
|
|
if (strncmp(f, feature, len) != 0) {
|
|
|
|
if (expanded) continue;
|
2021-09-16 19:20:10 +03:00
|
|
|
if (!load_path) load_path = get_expanded_load_path(vm);
|
2013-03-09 03:54:41 +04:00
|
|
|
if (!(p = loaded_feature_path(f, n, feature, len, type, load_path)))
|
|
|
|
continue;
|
|
|
|
expanded = 1;
|
|
|
|
f += RSTRING_LEN(p) + 1;
|
|
|
|
}
|
|
|
|
if (!*(e = f + len)) {
|
|
|
|
if (ext) continue;
|
|
|
|
return 'u';
|
|
|
|
}
|
|
|
|
if (*e != '.') continue;
|
|
|
|
if ((!rb || !ext) && (IS_SOEXT(e) || IS_DLEXT(e))) {
|
|
|
|
return 's';
|
|
|
|
}
|
|
|
|
if ((rb || !ext) && (IS_RBEXT(e))) {
|
|
|
|
return 'r';
|
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
}
|
2012-11-05 19:27:01 +04:00
|
|
|
|
2021-09-16 19:20:10 +03:00
|
|
|
loading_tbl = get_loading_table(vm);
|
2015-06-03 10:21:37 +03:00
|
|
|
f = 0;
|
|
|
|
if (!expanded) {
|
|
|
|
struct loaded_feature_searching fs;
|
|
|
|
fs.name = feature;
|
|
|
|
fs.len = len;
|
|
|
|
fs.type = type;
|
2021-09-16 19:20:10 +03:00
|
|
|
fs.load_path = load_path ? load_path : get_expanded_load_path(vm);
|
2015-06-03 10:21:37 +03:00
|
|
|
fs.result = 0;
|
|
|
|
st_foreach(loading_tbl, loaded_feature_path_i, (st_data_t)&fs);
|
|
|
|
if ((f = fs.result) != 0) {
|
|
|
|
if (fn) *fn = f;
|
|
|
|
goto loading;
|
2007-05-03 17:19:11 +04:00
|
|
|
}
|
2015-06-03 10:21:37 +03:00
|
|
|
}
|
|
|
|
if (st_get_key(loading_tbl, (st_data_t)feature, &data)) {
|
|
|
|
if (fn) *fn = (const char*)data;
|
2020-06-15 09:31:07 +03:00
|
|
|
goto loading;
|
2015-06-03 10:21:37 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
VALUE bufstr;
|
|
|
|
char *buf;
|
|
|
|
static const char so_ext[][4] = {
|
|
|
|
".so", ".o",
|
|
|
|
};
|
2022-07-21 19:23:58 +03:00
|
|
|
|
2015-06-03 10:21:37 +03:00
|
|
|
if (ext && *ext) return 0;
|
|
|
|
bufstr = rb_str_tmp_new(len + DLEXT_MAXLEN);
|
|
|
|
buf = RSTRING_PTR(bufstr);
|
|
|
|
MEMCPY(buf, feature, char, len);
|
|
|
|
for (i = 0; (e = loadable_ext[i]) != 0; i++) {
|
|
|
|
strlcpy(buf + len, e, DLEXT_MAXLEN + 1);
|
|
|
|
if (st_get_key(loading_tbl, (st_data_t)buf, &data)) {
|
|
|
|
rb_str_resize(bufstr, 0);
|
|
|
|
if (fn) *fn = (const char*)data;
|
|
|
|
return i ? 's' : 'r';
|
2007-05-03 17:19:11 +04:00
|
|
|
}
|
2015-06-03 10:21:37 +03:00
|
|
|
}
|
|
|
|
for (i = 0; i < numberof(so_ext); i++) {
|
|
|
|
strlcpy(buf + len, so_ext[i], DLEXT_MAXLEN + 1);
|
|
|
|
if (st_get_key(loading_tbl, (st_data_t)buf, &data)) {
|
|
|
|
rb_str_resize(bufstr, 0);
|
|
|
|
if (fn) *fn = (const char*)data;
|
|
|
|
return 's';
|
2013-11-03 04:35:49 +04:00
|
|
|
}
|
2007-05-03 17:19:11 +04:00
|
|
|
}
|
2015-06-03 10:21:37 +03:00
|
|
|
rb_str_resize(bufstr, 0);
|
2007-05-03 17:19:11 +04:00
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
return 0;
|
2020-06-15 09:31:07 +03:00
|
|
|
|
|
|
|
loading:
|
|
|
|
if (!ext) return 'u';
|
|
|
|
return !IS_RBEXT(ext) ? 's' : 'r';
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
rb_provided(const char *feature)
|
2008-12-04 21:29:20 +03:00
|
|
|
{
|
|
|
|
return rb_feature_provided(feature, 0);
|
|
|
|
}
|
|
|
|
|
2021-09-16 19:20:10 +03:00
|
|
|
static int
|
|
|
|
feature_provided(rb_vm_t *vm, const char *feature, const char **loading)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2007-05-03 17:19:11 +04:00
|
|
|
const char *ext = strrchr(feature, '.');
|
2015-06-24 11:28:47 +03:00
|
|
|
VALUE fullpath = 0;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2008-04-07 22:39:28 +04:00
|
|
|
if (*feature == '.' &&
|
|
|
|
(feature[1] == '/' || strncmp(feature+1, "./", 2) == 0)) {
|
2012-11-05 19:27:08 +04:00
|
|
|
fullpath = rb_file_expand_path_fast(rb_get_path(rb_str_new2(feature)), Qnil);
|
2008-04-07 22:39:28 +04:00
|
|
|
feature = RSTRING_PTR(fullpath);
|
|
|
|
}
|
2007-05-03 17:19:11 +04:00
|
|
|
if (ext && !strchr(ext, '/')) {
|
2007-11-09 06:56:38 +03:00
|
|
|
if (IS_RBEXT(ext)) {
|
2021-09-16 19:20:10 +03:00
|
|
|
if (rb_feature_p(vm, feature, ext, TRUE, FALSE, loading)) return TRUE;
|
2009-07-18 12:05:32 +04:00
|
|
|
return FALSE;
|
2007-05-03 17:19:11 +04:00
|
|
|
}
|
|
|
|
else if (IS_SOEXT(ext) || IS_DLEXT(ext)) {
|
2021-09-16 19:20:10 +03:00
|
|
|
if (rb_feature_p(vm, feature, ext, FALSE, FALSE, loading)) return TRUE;
|
2009-07-18 12:05:32 +04:00
|
|
|
return FALSE;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
}
|
2021-09-16 19:20:10 +03:00
|
|
|
if (rb_feature_p(vm, feature, 0, TRUE, FALSE, loading))
|
2009-07-18 12:05:32 +04:00
|
|
|
return TRUE;
|
2015-06-24 11:28:47 +03:00
|
|
|
RB_GC_GUARD(fullpath);
|
2009-07-18 12:05:32 +04:00
|
|
|
return FALSE;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
2021-09-16 19:20:10 +03:00
|
|
|
int
|
|
|
|
rb_feature_provided(const char *feature, const char **loading)
|
|
|
|
{
|
|
|
|
return feature_provided(GET_VM(), feature, loading);
|
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
static void
|
2021-09-16 19:20:10 +03:00
|
|
|
rb_provide_feature(rb_vm_t *vm, VALUE feature)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2012-11-05 19:27:01 +04:00
|
|
|
VALUE features;
|
|
|
|
|
2021-09-16 19:20:10 +03:00
|
|
|
features = get_loaded_features(vm);
|
2012-11-05 19:27:01 +04:00
|
|
|
if (OBJ_FROZEN(features)) {
|
2010-08-29 07:51:39 +04:00
|
|
|
rb_raise(rb_eRuntimeError,
|
|
|
|
"$LOADED_FEATURES is frozen; cannot append feature");
|
|
|
|
}
|
2022-12-27 04:32:07 +03:00
|
|
|
feature = rb_fstring(feature);
|
2012-11-05 19:27:01 +04:00
|
|
|
|
2021-09-16 19:20:10 +03:00
|
|
|
get_loaded_features_index(vm);
|
2022-02-23 18:51:28 +03:00
|
|
|
// If loaded_features and loaded_features_snapshot share the same backing
|
|
|
|
// array, pushing into it would cause the whole array to be copied.
|
|
|
|
// To avoid this we first clear loaded_features_snapshot.
|
|
|
|
rb_ary_clear(vm->loaded_features_snapshot);
|
2022-12-27 04:32:07 +03:00
|
|
|
rb_ary_push(features, feature);
|
2021-09-16 19:20:10 +03:00
|
|
|
features_index_add(vm, feature, INT2FIX(RARRAY_LEN(features)-1));
|
|
|
|
reset_loaded_features_snapshot(vm);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rb_provide(const char *feature)
|
|
|
|
{
|
2021-09-16 19:20:10 +03:00
|
|
|
rb_provide_feature(GET_VM(), rb_fstring_cstr(feature));
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
2007-12-25 07:17:06 +03:00
|
|
|
NORETURN(static void load_failed(VALUE));
|
* this commit is a result of refactoring. only renaming functions,
moving definitions place, add/remove prototypes, deleting
unused variables and removing yarv.h.
This commit doesn't change any behavior of ruby/vm.
* yarv.h, common.mk: remove yarv.h (contents are moved to yarvcore.h).
* error.c, eval_intern.h: include yarvcore.h instead yarv.h
* rename some functions:
* debug.[ch]: debug_*() -> ruby_debug_*()
* iseq.c: iseq_*() -> rb_iseq_*(), ruby_iseq_disasm()
* iseq.c: node_name() -> ruby_node_name()
* vm.c: yarv_check_redefinition_opt_method() ->
rb_vm_check_redefinition_opt_method()
* some refactoring with checking -Wall.
* array.c: remove rb_ary_ptr() (unused) and remove unused
local variables.
* object.c: add a prototype of rb_mod_module_exec().
* eval_intern.h (ruby_cref): set it inline.
* eval_load.c (rb_load), yarvcore.c: yarv_load() -> rb_load_internal().
* parse.y: add a prototype of rb_parse_in_eval() (in eval.c).
* process.c: add a prototype of rb_thread_stop_timer_thread() (in thread.c).
* thread.c: remove raw_gets() function (unused) and fix some format
mismatch (format mismatchs have remained yet. this is todo).
* thread.c (rb_thread_wait_fd_rw): fix typo on label name.
* thread_pthread.ci: comment out codes with USE_THREAD_CACHE.
* vm.c (rb_svar, rb_backref_get, rb_backref_get,
rb_lastline_get, rb_lastline_set) : moved from yarvcore.c.
* vm.c (yarv_init_redefined_flag): add a prototype and rename
yarv_opt_method_table to vm_opt_method_table.
* vm.c (rb_thread_eval): moved from yarvcore.c.
* yarvcore.c: remove unused global variables and fix to use nsdr().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11652 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-07 04:25:05 +03:00
|
|
|
|
2023-07-03 03:00:00 +03:00
|
|
|
static inline VALUE
|
|
|
|
realpath_internal_cached(VALUE hash, VALUE path)
|
|
|
|
{
|
|
|
|
VALUE ret = rb_hash_aref(hash, path);
|
|
|
|
if(RTEST(ret)) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE realpath = rb_realpath_internal(Qnil, path, 1);
|
|
|
|
rb_hash_aset(hash, rb_fstring(path), rb_fstring(realpath));
|
|
|
|
return realpath;
|
|
|
|
}
|
|
|
|
|
2019-08-08 11:53:36 +03:00
|
|
|
static inline void
|
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)>'
```
2023-02-27 20:24:45 +03:00
|
|
|
load_iseq_eval(rb_execution_context_t *ec, VALUE fname)
|
2019-08-08 16:17:22 +03:00
|
|
|
{
|
|
|
|
const rb_iseq_t *iseq = rb_iseq_load_iseq(fname);
|
2023-12-02 00:25:41 +03:00
|
|
|
|
2023-12-06 03:57:29 +03:00
|
|
|
if (!iseq) {
|
2023-12-08 02:47:36 +03:00
|
|
|
if (*rb_ruby_prism_ptr()) {
|
|
|
|
pm_string_t input;
|
|
|
|
pm_options_t options = { 0 };
|
|
|
|
|
|
|
|
pm_string_mapped_init(&input, RSTRING_PTR(fname));
|
|
|
|
pm_options_filepath_set(&options, RSTRING_PTR(fname));
|
|
|
|
|
|
|
|
pm_parser_t parser;
|
|
|
|
pm_parser_init(&parser, pm_string_source(&input), pm_string_length(&input), &options);
|
|
|
|
|
|
|
|
iseq = rb_iseq_new_main_prism(&input, &options, fname);
|
|
|
|
|
|
|
|
pm_string_free(&input);
|
|
|
|
pm_options_free(&options);
|
|
|
|
} else {
|
|
|
|
rb_execution_context_t *ec = GET_EC();
|
|
|
|
VALUE v = rb_vm_push_frame_fname(ec, fname);
|
|
|
|
rb_ast_t *ast;
|
|
|
|
VALUE parser = rb_parser_new();
|
|
|
|
rb_parser_set_context(parser, NULL, FALSE);
|
|
|
|
ast = (rb_ast_t *)rb_parser_load_file(parser, fname);
|
|
|
|
|
|
|
|
rb_thread_t *th = rb_ec_thread_ptr(ec);
|
|
|
|
VALUE realpath_map = get_loaded_features_realpath_map(th->vm);
|
|
|
|
|
|
|
|
iseq = rb_iseq_new_top(&ast->body, rb_fstring_lit("<top (required)>"),
|
|
|
|
fname, realpath_internal_cached(realpath_map, fname), NULL);
|
|
|
|
rb_ast_dispose(ast);
|
|
|
|
rb_vm_pop_frame(ec);
|
|
|
|
RB_GC_GUARD(v);
|
|
|
|
}
|
2019-08-08 16:17:22 +03:00
|
|
|
}
|
|
|
|
rb_exec_event_hook_script_compiled(ec, iseq, Qnil);
|
|
|
|
rb_iseq_eval(iseq);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline enum ruby_tag_type
|
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)>'
```
2023-02-27 20:24:45 +03:00
|
|
|
load_wrapping(rb_execution_context_t *ec, VALUE fname, VALUE load_wrapper)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2017-06-23 10:25:52 +03:00
|
|
|
enum ruby_tag_type state;
|
2017-11-07 08:45:46 +03:00
|
|
|
rb_thread_t *th = rb_ec_thread_ptr(ec);
|
2007-11-06 09:52:01 +03:00
|
|
|
volatile VALUE wrapper = th->top_wrapper;
|
|
|
|
volatile VALUE self = th->top_self;
|
2013-11-01 11:37:27 +04:00
|
|
|
#if !defined __GNUC__
|
2007-11-06 09:52:01 +03:00
|
|
|
rb_thread_t *volatile th0 = th;
|
|
|
|
#endif
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2019-08-08 15:08:00 +03:00
|
|
|
ec->errinfo = Qnil; /* ensure */
|
2007-02-25 19:29:26 +03:00
|
|
|
|
2021-10-18 18:50:10 +03:00
|
|
|
/* load in module as toplevel */
|
2019-08-17 17:33:12 +03:00
|
|
|
th->top_self = rb_obj_clone(rb_vm_top_self());
|
2021-10-18 18:50:10 +03:00
|
|
|
th->top_wrapper = load_wrapper;
|
2019-08-17 17:33:12 +03:00
|
|
|
rb_extend_object(th->top_self, th->top_wrapper);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2019-08-08 15:08:00 +03:00
|
|
|
EC_PUSH_TAG(ec);
|
2017-12-06 06:16:08 +03:00
|
|
|
state = EC_EXEC_TAG();
|
2017-06-23 10:25:52 +03:00
|
|
|
if (state == TAG_NONE) {
|
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)>'
```
2023-02-27 20:24:45 +03:00
|
|
|
load_iseq_eval(ec, fname);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2017-10-26 14:02:13 +03:00
|
|
|
EC_POP_TAG();
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2013-11-01 11:37:27 +04:00
|
|
|
#if !defined __GNUC__
|
2007-11-06 09:52:01 +03:00
|
|
|
th = th0;
|
|
|
|
fname = RB_GC_GUARD(fname);
|
|
|
|
#endif
|
2007-02-25 19:29:26 +03:00
|
|
|
th->top_self = self;
|
|
|
|
th->top_wrapper = wrapper;
|
2019-08-08 16:17:22 +03:00
|
|
|
return state;
|
|
|
|
}
|
2007-02-25 19:29:26 +03:00
|
|
|
|
2019-08-08 16:17:22 +03:00
|
|
|
static inline void
|
|
|
|
raise_load_if_failed(rb_execution_context_t *ec, enum ruby_tag_type state)
|
|
|
|
{
|
2006-12-31 18:02:22 +03:00
|
|
|
if (state) {
|
2019-08-08 11:53:36 +03:00
|
|
|
rb_vm_jump_tag_but_local_jump(state);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
2019-08-08 15:08:00 +03:00
|
|
|
if (!NIL_P(ec->errinfo)) {
|
|
|
|
rb_exc_raise(ec->errinfo);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-01 11:37:27 +04:00
|
|
|
static void
|
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)>'
```
2023-02-27 20:24:45 +03:00
|
|
|
rb_load_internal(VALUE fname, VALUE wrap)
|
2013-11-01 11:37:27 +04:00
|
|
|
{
|
2017-11-07 08:45:46 +03:00
|
|
|
rb_execution_context_t *ec = GET_EC();
|
2019-08-17 17:33:12 +03:00
|
|
|
enum ruby_tag_type state = TAG_NONE;
|
2021-10-18 18:50:10 +03:00
|
|
|
if (RTEST(wrap)) {
|
|
|
|
if (!RB_TYPE_P(wrap, T_MODULE)) {
|
|
|
|
wrap = rb_module_new();
|
|
|
|
}
|
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)>'
```
2023-02-27 20:24:45 +03:00
|
|
|
state = load_wrapping(ec, fname, wrap);
|
2019-08-17 17:33:12 +03:00
|
|
|
}
|
|
|
|
else {
|
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)>'
```
2023-02-27 20:24:45 +03:00
|
|
|
load_iseq_eval(ec, fname);
|
2019-08-17 17:33:12 +03:00
|
|
|
}
|
|
|
|
raise_load_if_failed(ec, state);
|
2015-07-18 14:44:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rb_load(VALUE fname, int wrap)
|
|
|
|
{
|
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)>'
```
2023-02-27 20:24:45 +03:00
|
|
|
VALUE tmp = rb_find_file(FilePathValue(fname));
|
2019-08-08 11:53:36 +03:00
|
|
|
if (!tmp) load_failed(fname);
|
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)>'
```
2023-02-27 20:24:45 +03:00
|
|
|
rb_load_internal(tmp, RBOOL(wrap));
|
2009-06-23 11:05:04 +04:00
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
void
|
2017-06-23 10:25:52 +03:00
|
|
|
rb_load_protect(VALUE fname, int wrap, int *pstate)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2017-06-23 10:25:52 +03:00
|
|
|
enum ruby_tag_type state;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2017-12-06 06:16:08 +03:00
|
|
|
EC_PUSH_TAG(GET_EC());
|
|
|
|
if ((state = EC_EXEC_TAG()) == TAG_NONE) {
|
2019-08-08 11:53:36 +03:00
|
|
|
rb_load(fname, wrap);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2017-12-06 06:16:08 +03:00
|
|
|
EC_POP_TAG();
|
2017-06-23 10:25:52 +03:00
|
|
|
|
|
|
|
if (state != TAG_NONE) *pstate = state;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:31:22 +04:00
|
|
|
* load(filename, wrap=false) -> true
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2020-05-29 18:57:09 +03:00
|
|
|
* Loads and executes the Ruby program in the file _filename_.
|
|
|
|
*
|
2020-07-10 00:47:13 +03:00
|
|
|
* If the filename is an absolute path (e.g. starts with '/'), the file
|
|
|
|
* will be loaded directly using the absolute path.
|
|
|
|
*
|
|
|
|
* If the filename is an explicit relative path (e.g. starts with './' or
|
|
|
|
* '../'), the file will be loaded using the relative path from the current
|
|
|
|
* directory.
|
|
|
|
*
|
|
|
|
* Otherwise, the file will be searched for in the library
|
2020-05-30 16:04:49 +03:00
|
|
|
* directories listed in <code>$LOAD_PATH</code> (<code>$:</code>).
|
2020-07-10 00:47:13 +03:00
|
|
|
* If the file is found in a directory, it will attempt to load the file
|
|
|
|
* relative to that directory. If the file is not found in any of the
|
|
|
|
* directories in <code>$LOAD_PATH</code>, the file will be loaded using
|
|
|
|
* the relative path from the current directory.
|
|
|
|
*
|
|
|
|
* If the file doesn't exist when there is an attempt to load it, a
|
|
|
|
* LoadError will be raised.
|
2020-05-29 18:57:09 +03:00
|
|
|
*
|
|
|
|
* If the optional _wrap_ parameter is +true+, the loaded script will
|
|
|
|
* be executed under an anonymous module, protecting the calling
|
2021-10-18 18:50:10 +03:00
|
|
|
* program's global namespace. If the optional _wrap_ parameter is a
|
|
|
|
* module, the loaded script will be executed under the given module.
|
|
|
|
* In no circumstance will any local variables in the loaded file be
|
|
|
|
* propagated to the loading environment.
|
2006-12-31 18:02:22 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
2019-08-28 12:19:11 +03:00
|
|
|
rb_f_load(int argc, VALUE *argv, VALUE _)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2014-10-29 08:44:33 +03:00
|
|
|
VALUE fname, wrap, path, orig_fname;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
rb_scan_args(argc, argv, "11", &fname, &wrap);
|
* probes.d: add DTrace probe declarations. [ruby-core:27448]
* array.c (empty_ary_alloc, ary_new): added array create DTrace probe.
* compile.c (rb_insns_name): allowing DTrace probes to access
instruction sequence name.
* Makefile.in: translate probes.d file to appropriate header file.
* common.mk: declare dependencies on the DTrace header.
* configure.in: add a test for existence of DTrace.
* eval.c (setup_exception): add a probe for when an exception is
raised.
* gc.c: Add DTrace probes for mark begin and end, and sweep begin and
end.
* hash.c (empty_hash_alloc): Add a probe for hash allocation.
* insns.def: Add probes for function entry and return.
* internal.h: function declaration for compile.c change.
* load.c (rb_f_load): add probes for `load` entry and exit, require
entry and exit, and wrapping search_required for load path search.
* object.c (rb_obj_alloc): added a probe for general object creation.
* parse.y (yycompile0): added a probe around parse and compile phase.
* string.c (empty_str_alloc, str_new): DTrace probes for string
allocation.
* test/dtrace/*: tests for DTrace probes.
* vm.c (vm_invoke_proc): add probes for function return on exception
raise, hash create, and instruction sequence execution.
* vm_core.h: add probe declarations for function entry and exit.
* vm_dump.c: add probes header file.
* vm_eval.c (vm_call0_cfunc, vm_call0_cfunc_with_frame): add probe on
function entry and return.
* vm_exec.c: expose instruction number to instruction name function.
* vm_insnshelper.c: add function entry and exit probes for cfunc
methods.
* vm_insnhelper.h: vm usage information is always collected, so
uncomment the functions.
12 19:14:50 2012 Akinori MUSHA <knu@iDaemons.org>
* configure.in (isinf, isnan): isinf() and isnan() are macros on
DragonFly which cannot be found by AC_REPLACE_FUNCS(). This
workaround enforces the fact that they exist on DragonFly.
12 15:59:38 2012 Shugo Maeda <shugo@ruby-lang.org>
* vm_core.h (rb_call_info_t::refinements), compile.c (new_callinfo),
vm_insnhelper.c (vm_search_method): revert r37616 because it's too
slow. [ruby-dev:46477]
* test/ruby/test_refinement.rb (test_inline_method_cache): skip
the test until the bug is fixed efficiently.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37631 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-13 01:52:12 +04:00
|
|
|
|
2019-09-21 05:06:22 +03:00
|
|
|
orig_fname = rb_get_path_check_to_string(fname);
|
2016-04-09 06:58:01 +03:00
|
|
|
fname = rb_str_encode_ospath(orig_fname);
|
2017-06-07 17:36:18 +03:00
|
|
|
RUBY_DTRACE_HOOK(LOAD_ENTRY, RSTRING_PTR(orig_fname));
|
|
|
|
|
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)>'
```
2023-02-27 20:24:45 +03:00
|
|
|
path = rb_find_file(fname);
|
2009-06-23 11:05:04 +04:00
|
|
|
if (!path) {
|
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)>'
```
2023-02-27 20:24:45 +03:00
|
|
|
if (!rb_file_load_ok(RSTRING_PTR(fname)))
|
2014-10-29 08:44:33 +03:00
|
|
|
load_failed(orig_fname);
|
2009-06-23 11:05:04 +04:00
|
|
|
path = fname;
|
|
|
|
}
|
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)>'
```
2023-02-27 20:24:45 +03:00
|
|
|
rb_load_internal(path, wrap);
|
* probes.d: add DTrace probe declarations. [ruby-core:27448]
* array.c (empty_ary_alloc, ary_new): added array create DTrace probe.
* compile.c (rb_insns_name): allowing DTrace probes to access
instruction sequence name.
* Makefile.in: translate probes.d file to appropriate header file.
* common.mk: declare dependencies on the DTrace header.
* configure.in: add a test for existence of DTrace.
* eval.c (setup_exception): add a probe for when an exception is
raised.
* gc.c: Add DTrace probes for mark begin and end, and sweep begin and
end.
* hash.c (empty_hash_alloc): Add a probe for hash allocation.
* insns.def: Add probes for function entry and return.
* internal.h: function declaration for compile.c change.
* load.c (rb_f_load): add probes for `load` entry and exit, require
entry and exit, and wrapping search_required for load path search.
* object.c (rb_obj_alloc): added a probe for general object creation.
* parse.y (yycompile0): added a probe around parse and compile phase.
* string.c (empty_str_alloc, str_new): DTrace probes for string
allocation.
* test/dtrace/*: tests for DTrace probes.
* vm.c (vm_invoke_proc): add probes for function return on exception
raise, hash create, and instruction sequence execution.
* vm_core.h: add probe declarations for function entry and exit.
* vm_dump.c: add probes header file.
* vm_eval.c (vm_call0_cfunc, vm_call0_cfunc_with_frame): add probe on
function entry and return.
* vm_exec.c: expose instruction number to instruction name function.
* vm_insnshelper.c: add function entry and exit probes for cfunc
methods.
* vm_insnhelper.h: vm usage information is always collected, so
uncomment the functions.
12 19:14:50 2012 Akinori MUSHA <knu@iDaemons.org>
* configure.in (isinf, isnan): isinf() and isnan() are macros on
DragonFly which cannot be found by AC_REPLACE_FUNCS(). This
workaround enforces the fact that they exist on DragonFly.
12 15:59:38 2012 Shugo Maeda <shugo@ruby-lang.org>
* vm_core.h (rb_call_info_t::refinements), compile.c (new_callinfo),
vm_insnhelper.c (vm_search_method): revert r37616 because it's too
slow. [ruby-dev:46477]
* test/ruby/test_refinement.rb (test_inline_method_cache): skip
the test until the bug is fixed efficiently.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37631 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-13 01:52:12 +04:00
|
|
|
|
2017-06-07 17:36:18 +03:00
|
|
|
RUBY_DTRACE_HOOK(LOAD_RETURN, RSTRING_PTR(orig_fname));
|
* probes.d: add DTrace probe declarations. [ruby-core:27448]
* array.c (empty_ary_alloc, ary_new): added array create DTrace probe.
* compile.c (rb_insns_name): allowing DTrace probes to access
instruction sequence name.
* Makefile.in: translate probes.d file to appropriate header file.
* common.mk: declare dependencies on the DTrace header.
* configure.in: add a test for existence of DTrace.
* eval.c (setup_exception): add a probe for when an exception is
raised.
* gc.c: Add DTrace probes for mark begin and end, and sweep begin and
end.
* hash.c (empty_hash_alloc): Add a probe for hash allocation.
* insns.def: Add probes for function entry and return.
* internal.h: function declaration for compile.c change.
* load.c (rb_f_load): add probes for `load` entry and exit, require
entry and exit, and wrapping search_required for load path search.
* object.c (rb_obj_alloc): added a probe for general object creation.
* parse.y (yycompile0): added a probe around parse and compile phase.
* string.c (empty_str_alloc, str_new): DTrace probes for string
allocation.
* test/dtrace/*: tests for DTrace probes.
* vm.c (vm_invoke_proc): add probes for function return on exception
raise, hash create, and instruction sequence execution.
* vm_core.h: add probe declarations for function entry and exit.
* vm_dump.c: add probes header file.
* vm_eval.c (vm_call0_cfunc, vm_call0_cfunc_with_frame): add probe on
function entry and return.
* vm_exec.c: expose instruction number to instruction name function.
* vm_insnshelper.c: add function entry and exit probes for cfunc
methods.
* vm_insnhelper.h: vm usage information is always collected, so
uncomment the functions.
12 19:14:50 2012 Akinori MUSHA <knu@iDaemons.org>
* configure.in (isinf, isnan): isinf() and isnan() are macros on
DragonFly which cannot be found by AC_REPLACE_FUNCS(). This
workaround enforces the fact that they exist on DragonFly.
12 15:59:38 2012 Shugo Maeda <shugo@ruby-lang.org>
* vm_core.h (rb_call_info_t::refinements), compile.c (new_callinfo),
vm_insnhelper.c (vm_search_method): revert r37616 because it's too
slow. [ruby-dev:46477]
* test/ruby/test_refinement.rb (test_inline_method_cache): skip
the test until the bug is fixed efficiently.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37631 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-13 01:52:12 +04:00
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
return Qtrue;
|
|
|
|
}
|
|
|
|
|
2007-05-03 17:19:11 +04:00
|
|
|
static char *
|
2021-09-16 19:20:10 +03:00
|
|
|
load_lock(rb_vm_t *vm, const char *ftptr, bool warn)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2007-05-03 17:19:11 +04:00
|
|
|
st_data_t data;
|
2021-09-16 19:20:10 +03:00
|
|
|
st_table *loading_tbl = get_loading_table(vm);
|
2007-05-03 17:19:11 +04:00
|
|
|
|
2015-06-03 10:21:37 +03:00
|
|
|
if (!st_lookup(loading_tbl, (st_data_t)ftptr, &data)) {
|
2007-05-03 17:19:11 +04:00
|
|
|
/* partial state */
|
|
|
|
ftptr = ruby_strdup(ftptr);
|
2012-07-05 11:00:29 +04:00
|
|
|
data = (st_data_t)rb_thread_shield_new();
|
2007-05-03 17:19:11 +04:00
|
|
|
st_insert(loading_tbl, (st_data_t)ftptr, data);
|
|
|
|
return (char *)ftptr;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2023-02-07 01:30:42 +03:00
|
|
|
|
|
|
|
if (warn && rb_thread_shield_owned((VALUE)data)) {
|
2017-04-27 15:07:43 +03:00
|
|
|
VALUE warning = rb_warning_string("loading in progress, circular require considered harmful - %s", ftptr);
|
|
|
|
rb_backtrace_each(rb_str_append, warning);
|
2018-01-21 01:07:36 +03:00
|
|
|
rb_warning("%"PRIsVALUE, warning);
|
2009-06-13 10:03:44 +04:00
|
|
|
}
|
2012-07-05 11:00:29 +04:00
|
|
|
switch (rb_thread_shield_wait((VALUE)data)) {
|
2011-12-14 05:20:11 +04:00
|
|
|
case Qfalse:
|
|
|
|
case Qnil:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return (char *)ftptr;
|
2007-05-03 17:19:11 +04:00
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2012-01-13 12:23:43 +04:00
|
|
|
static int
|
2012-07-05 11:00:29 +04:00
|
|
|
release_thread_shield(st_data_t *key, st_data_t *value, st_data_t done, int existing)
|
2012-01-13 12:23:43 +04:00
|
|
|
{
|
2012-07-05 11:00:29 +04:00
|
|
|
VALUE thread_shield = (VALUE)*value;
|
2012-03-29 11:36:12 +04:00
|
|
|
if (!existing) return ST_STOP;
|
2016-12-05 14:10:05 +03:00
|
|
|
if (done) {
|
|
|
|
rb_thread_shield_destroy(thread_shield);
|
2016-12-06 02:37:25 +03:00
|
|
|
/* Delete the entry even if there are waiting threads, because they
|
|
|
|
* won't load the file and won't delete the entry. */
|
2016-12-05 14:10:05 +03:00
|
|
|
}
|
|
|
|
else if (rb_thread_shield_release(thread_shield)) {
|
2012-01-13 12:23:43 +04:00
|
|
|
/* still in-use */
|
|
|
|
return ST_CONTINUE;
|
|
|
|
}
|
2012-03-29 18:50:20 +04:00
|
|
|
xfree((char *)*key);
|
2012-01-13 12:23:43 +04:00
|
|
|
return ST_DELETE;
|
|
|
|
}
|
|
|
|
|
2007-05-03 17:19:11 +04:00
|
|
|
static void
|
2021-09-16 19:20:10 +03:00
|
|
|
load_unlock(rb_vm_t *vm, const char *ftptr, int done)
|
2007-05-03 17:19:11 +04:00
|
|
|
{
|
|
|
|
if (ftptr) {
|
|
|
|
st_data_t key = (st_data_t)ftptr;
|
2021-09-16 19:20:10 +03:00
|
|
|
st_table *loading_tbl = get_loading_table(vm);
|
2007-05-03 17:19:11 +04:00
|
|
|
|
2012-07-05 11:00:29 +04:00
|
|
|
st_update(loading_tbl, key, release_thread_shield, done);
|
2007-05-03 17:19:11 +04:00
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
2023-11-27 18:13:05 +03:00
|
|
|
static VALUE rb_require_string_internal(VALUE fname, bool resurrect);
|
2007-05-03 17:19:11 +04:00
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2011-08-23 10:26:11 +04:00
|
|
|
* require(name) -> true or false
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2011-08-23 10:26:11 +04:00
|
|
|
* Loads the given +name+, returning +true+ if successful and +false+ if the
|
|
|
|
* feature is already loaded.
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2020-05-30 16:04:49 +03:00
|
|
|
* If the filename neither resolves to an absolute path nor starts with
|
|
|
|
* './' or '../', the file will be searched for in the library
|
|
|
|
* directories listed in <code>$LOAD_PATH</code> (<code>$:</code>).
|
2020-05-31 17:06:07 +03:00
|
|
|
* If the filename starts with './' or '../', resolution is based on Dir.pwd.
|
2011-08-23 10:26:11 +04:00
|
|
|
*
|
|
|
|
* If the filename has the extension ".rb", it is loaded as a source file; if
|
2023-12-12 01:13:54 +03:00
|
|
|
* the extension is ".so", ".o", or the default shared library extension on
|
|
|
|
* the current platform, Ruby loads the shared library as a Ruby extension.
|
|
|
|
* Otherwise, Ruby tries adding ".rb", ".so", and so on to the name until
|
|
|
|
* found. If the file named cannot be found, a LoadError will be raised.
|
2011-08-23 10:26:11 +04:00
|
|
|
*
|
2023-12-12 01:13:54 +03:00
|
|
|
* For Ruby extensions the filename given may use ".so" or ".o". For example,
|
2023-12-12 03:39:13 +03:00
|
|
|
* on macOS the socket extension is "socket.bundle" and
|
2023-12-12 01:13:54 +03:00
|
|
|
* <code>require 'socket.so'</code> will load the socket extension.
|
2011-08-23 10:26:11 +04:00
|
|
|
*
|
|
|
|
* The absolute path of the loaded file is added to
|
|
|
|
* <code>$LOADED_FEATURES</code> (<code>$"</code>). A file will not be
|
|
|
|
* loaded again if its path already appears in <code>$"</code>. For example,
|
|
|
|
* <code>require 'a'; require './a'</code> will not load <code>a.rb</code>
|
|
|
|
* again.
|
|
|
|
*
|
|
|
|
* require "my-library.rb"
|
|
|
|
* require "db-driver"
|
2012-02-23 05:58:01 +04:00
|
|
|
*
|
|
|
|
* Any constants or globals within the loaded source file will be available
|
|
|
|
* in the calling program's global namespace. However, local variables will
|
|
|
|
* not be propagated to the loading environment.
|
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
VALUE
|
|
|
|
rb_f_require(VALUE obj, VALUE fname)
|
|
|
|
{
|
2019-09-21 05:06:22 +03:00
|
|
|
return rb_require_string(fname);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
2010-12-25 05:07:13 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* require_relative(string) -> true or false
|
|
|
|
*
|
2022-06-21 19:40:28 +03:00
|
|
|
* Ruby tries to load the library named _string_ relative to the directory
|
|
|
|
* containing the requiring file. If the file does not exist a LoadError is
|
|
|
|
* raised. Returns +true+ if the file was loaded and +false+ if the file was
|
|
|
|
* already loaded before.
|
2010-12-25 05:07:13 +03:00
|
|
|
*/
|
2010-12-25 06:48:57 +03:00
|
|
|
VALUE
|
2010-03-16 20:40:00 +03:00
|
|
|
rb_f_require_relative(VALUE obj, VALUE fname)
|
|
|
|
{
|
|
|
|
VALUE base = rb_current_realfilepath();
|
|
|
|
if (NIL_P(base)) {
|
2012-03-07 03:38:33 +04:00
|
|
|
rb_loaderror("cannot infer basepath");
|
2010-03-16 20:40:00 +03:00
|
|
|
}
|
2010-03-30 13:26:09 +04:00
|
|
|
base = rb_file_dirname(base);
|
2023-11-27 18:13:05 +03:00
|
|
|
return rb_require_string_internal(rb_file_absolute_path(fname, base), false);
|
2010-03-16 20:40:00 +03:00
|
|
|
}
|
|
|
|
|
2021-09-16 19:20:10 +03:00
|
|
|
typedef int (*feature_func)(rb_vm_t *vm, const char *feature, const char *ext, int rb, int expanded, const char **fn);
|
2018-12-31 04:14:51 +03:00
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
static int
|
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)>'
```
2023-02-27 20:24:45 +03:00
|
|
|
search_required(rb_vm_t *vm, VALUE fname, volatile VALUE *path, feature_func rb_feature_p)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
VALUE tmp;
|
|
|
|
char *ext, *ftptr;
|
2023-08-22 12:13:09 +03:00
|
|
|
int ft = 0;
|
2007-12-24 11:06:16 +03:00
|
|
|
const char *loading;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
*path = 0;
|
|
|
|
ext = strrchr(ftptr = RSTRING_PTR(fname), '.');
|
|
|
|
if (ext && !strchr(ext, '/')) {
|
2007-11-09 06:56:38 +03:00
|
|
|
if (IS_RBEXT(ext)) {
|
2021-09-16 19:20:10 +03:00
|
|
|
if (rb_feature_p(vm, ftptr, ext, TRUE, FALSE, &loading)) {
|
2012-08-23 11:46:12 +04:00
|
|
|
if (loading) *path = rb_filesystem_str_new_cstr(loading);
|
2006-12-31 18:02:22 +03:00
|
|
|
return 'r';
|
2007-12-24 11:06:16 +03:00
|
|
|
}
|
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)>'
```
2023-02-27 20:24:45 +03:00
|
|
|
if ((tmp = rb_find_file(fname)) != 0) {
|
2006-12-31 18:02:22 +03:00
|
|
|
ext = strrchr(ftptr = RSTRING_PTR(tmp), '.');
|
2021-09-16 19:20:10 +03:00
|
|
|
if (!rb_feature_p(vm, ftptr, ext, TRUE, TRUE, &loading) || loading)
|
2006-12-31 18:02:22 +03:00
|
|
|
*path = tmp;
|
|
|
|
return 'r';
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else if (IS_SOEXT(ext)) {
|
2021-09-16 19:20:10 +03:00
|
|
|
if (rb_feature_p(vm, ftptr, ext, FALSE, FALSE, &loading)) {
|
2012-08-23 11:46:12 +04:00
|
|
|
if (loading) *path = rb_filesystem_str_new_cstr(loading);
|
2006-12-31 18:02:22 +03:00
|
|
|
return 's';
|
2007-12-24 11:06:16 +03:00
|
|
|
}
|
2012-08-23 11:46:12 +04:00
|
|
|
tmp = rb_str_subseq(fname, 0, ext - RSTRING_PTR(fname));
|
2006-12-31 18:02:22 +03:00
|
|
|
rb_str_cat2(tmp, DLEXT);
|
|
|
|
OBJ_FREEZE(tmp);
|
2019-09-21 05:06:22 +03:00
|
|
|
if ((tmp = rb_find_file(tmp)) != 0) {
|
2006-12-31 18:02:22 +03:00
|
|
|
ext = strrchr(ftptr = RSTRING_PTR(tmp), '.');
|
2021-09-16 19:20:10 +03:00
|
|
|
if (!rb_feature_p(vm, ftptr, ext, FALSE, TRUE, &loading) || loading)
|
2006-12-31 18:02:22 +03:00
|
|
|
*path = tmp;
|
|
|
|
return 's';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (IS_DLEXT(ext)) {
|
2021-09-16 19:20:10 +03:00
|
|
|
if (rb_feature_p(vm, ftptr, ext, FALSE, FALSE, &loading)) {
|
2012-08-23 11:46:12 +04:00
|
|
|
if (loading) *path = rb_filesystem_str_new_cstr(loading);
|
2006-12-31 18:02:22 +03:00
|
|
|
return 's';
|
2007-12-24 11:06:16 +03:00
|
|
|
}
|
2019-09-21 05:06:22 +03:00
|
|
|
if ((tmp = rb_find_file(fname)) != 0) {
|
2006-12-31 18:02:22 +03:00
|
|
|
ext = strrchr(ftptr = RSTRING_PTR(tmp), '.');
|
2021-09-16 19:20:10 +03:00
|
|
|
if (!rb_feature_p(vm, ftptr, ext, FALSE, TRUE, &loading) || loading)
|
2006-12-31 18:02:22 +03:00
|
|
|
*path = tmp;
|
|
|
|
return 's';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-09-16 19:20:10 +03:00
|
|
|
else if ((ft = rb_feature_p(vm, ftptr, 0, FALSE, FALSE, &loading)) == 'r') {
|
2012-08-23 11:46:12 +04:00
|
|
|
if (loading) *path = rb_filesystem_str_new_cstr(loading);
|
2006-12-31 18:02:22 +03:00
|
|
|
return 'r';
|
|
|
|
}
|
|
|
|
tmp = fname;
|
2023-08-22 12:13:09 +03:00
|
|
|
const unsigned int type = rb_find_file_ext(&tmp, ft == 's' ? ruby_ext : loadable_ext);
|
2023-04-20 16:44:02 +03:00
|
|
|
|
|
|
|
// Check if it's a statically linked extension when
|
|
|
|
// not already a feature and not found as a dynamic library.
|
2023-08-22 12:13:09 +03:00
|
|
|
if (!ft && type != loadable_ext_rb && vm->static_ext_inits) {
|
2022-11-18 01:33:18 +03:00
|
|
|
VALUE lookup_name = tmp;
|
|
|
|
// Append ".so" if not already present so for example "etc" can find "etc.so".
|
|
|
|
// We always register statically linked extensions with a ".so" extension.
|
|
|
|
// See encinit.c and extinit.c (generated at build-time).
|
|
|
|
if (!ext) {
|
|
|
|
lookup_name = rb_str_dup(lookup_name);
|
|
|
|
rb_str_cat_cstr(lookup_name, ".so");
|
|
|
|
}
|
|
|
|
ftptr = RSTRING_PTR(lookup_name);
|
|
|
|
if (st_lookup(vm->static_ext_inits, (st_data_t)ftptr, NULL)) {
|
|
|
|
*path = rb_filesystem_str_new_cstr(ftptr);
|
|
|
|
return 's';
|
|
|
|
}
|
|
|
|
}
|
2023-04-20 16:44:02 +03:00
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
switch (type) {
|
2007-05-03 17:19:11 +04:00
|
|
|
case 0:
|
2006-12-31 18:02:22 +03:00
|
|
|
if (ft)
|
2022-11-19 03:42:24 +03:00
|
|
|
goto feature_present;
|
2007-12-24 11:06:16 +03:00
|
|
|
ftptr = RSTRING_PTR(tmp);
|
2021-09-16 19:20:10 +03:00
|
|
|
return rb_feature_p(vm, ftptr, 0, FALSE, TRUE, 0);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2007-05-03 17:19:11 +04:00
|
|
|
default:
|
2013-11-03 04:35:49 +04:00
|
|
|
if (ft) {
|
2022-11-19 03:42:24 +03:00
|
|
|
goto feature_present;
|
2013-11-03 04:35:49 +04:00
|
|
|
}
|
2019-07-14 11:32:49 +03:00
|
|
|
/* fall through */
|
2023-08-22 12:13:09 +03:00
|
|
|
case loadable_ext_rb:
|
2006-12-31 18:02:22 +03:00
|
|
|
ext = strrchr(ftptr = RSTRING_PTR(tmp), '.');
|
2023-08-22 12:13:09 +03:00
|
|
|
if (rb_feature_p(vm, ftptr, ext, type == loadable_ext_rb, TRUE, &loading) && !loading)
|
2006-12-31 18:02:22 +03:00
|
|
|
break;
|
|
|
|
*path = tmp;
|
|
|
|
}
|
2023-08-22 12:13:09 +03:00
|
|
|
return type > loadable_ext_rb ? 's' : 'r';
|
2020-06-15 10:04:52 +03:00
|
|
|
|
2022-11-19 03:42:24 +03:00
|
|
|
feature_present:
|
2020-06-15 10:04:52 +03:00
|
|
|
if (loading) *path = rb_filesystem_str_new_cstr(loading);
|
|
|
|
return ft;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
load_failed(VALUE fname)
|
|
|
|
{
|
2012-03-07 11:30:31 +04:00
|
|
|
rb_load_fail(fname, "cannot load such file");
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
2007-06-18 12:02:30 +04:00
|
|
|
static VALUE
|
2007-06-19 05:53:31 +04:00
|
|
|
load_ext(VALUE path)
|
2007-06-18 12:02:30 +04:00
|
|
|
{
|
2015-06-03 17:07:24 +03:00
|
|
|
rb_scope_visibility_set(METHOD_VISI_PUBLIC);
|
2010-02-24 05:52:08 +03:00
|
|
|
return (VALUE)dln_load(RSTRING_PTR(path));
|
2007-06-18 12:02:30 +04:00
|
|
|
}
|
|
|
|
|
2022-11-18 01:33:18 +03:00
|
|
|
static bool
|
|
|
|
run_static_ext_init(rb_vm_t *vm, const char *feature)
|
|
|
|
{
|
|
|
|
st_data_t key = (st_data_t)feature;
|
|
|
|
st_data_t init_func;
|
2023-04-20 16:44:02 +03:00
|
|
|
|
|
|
|
if (vm->static_ext_inits && st_delete(vm->static_ext_inits, &key, &init_func)) {
|
2022-11-18 01:33:18 +03:00
|
|
|
((void (*)(void))init_func)();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-12-31 04:14:51 +03:00
|
|
|
static int
|
2021-09-16 19:20:10 +03:00
|
|
|
no_feature_p(rb_vm_t *vm, const char *feature, const char *ext, int rb, int expanded, const char **fn)
|
2018-12-31 04:14:51 +03:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-07-13 16:23:49 +03:00
|
|
|
// Documented in doc/globals.rdoc
|
2018-12-06 09:40:54 +03:00
|
|
|
VALUE
|
|
|
|
rb_resolve_feature_path(VALUE klass, VALUE fname)
|
|
|
|
{
|
|
|
|
VALUE path;
|
|
|
|
int found;
|
|
|
|
VALUE sym;
|
|
|
|
|
2019-09-21 05:06:22 +03:00
|
|
|
fname = rb_get_path(fname);
|
2018-12-06 09:40:54 +03:00
|
|
|
path = rb_str_encode_ospath(fname);
|
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)>'
```
2023-02-27 20:24:45 +03:00
|
|
|
found = search_required(GET_VM(), path, &path, no_feature_p);
|
2018-12-06 09:40:54 +03:00
|
|
|
|
|
|
|
switch (found) {
|
|
|
|
case 'r':
|
|
|
|
sym = ID2SYM(rb_intern("rb"));
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
sym = ID2SYM(rb_intern("so"));
|
|
|
|
break;
|
|
|
|
default:
|
2019-08-04 14:09:30 +03:00
|
|
|
return Qnil;
|
2018-12-06 09:40:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return rb_ary_new_from_args(2, sym, path);
|
|
|
|
}
|
|
|
|
|
2020-11-30 10:18:43 +03:00
|
|
|
static void
|
|
|
|
ext_config_push(rb_thread_t *th, struct rb_ext_config *prev)
|
|
|
|
{
|
|
|
|
*prev = th->ext_config;
|
|
|
|
th->ext_config = (struct rb_ext_config){0};
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ext_config_pop(rb_thread_t *th, struct rb_ext_config *prev)
|
|
|
|
{
|
|
|
|
th->ext_config = *prev;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rb_ext_ractor_safe(bool flag)
|
|
|
|
{
|
|
|
|
GET_THREAD()->ext_config.ractor_safe = flag;
|
|
|
|
}
|
|
|
|
|
2014-12-03 09:13:58 +03:00
|
|
|
/*
|
|
|
|
* returns
|
|
|
|
* 0: if already loaded (false)
|
|
|
|
* 1: successfully loaded (true)
|
|
|
|
* <0: not found (LoadError)
|
|
|
|
* >1: exception
|
|
|
|
*/
|
2019-08-08 16:17:22 +03:00
|
|
|
static int
|
2021-09-23 22:31:32 +03:00
|
|
|
require_internal(rb_execution_context_t *ec, VALUE fname, int exception, bool warn)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2014-12-03 09:13:58 +03:00
|
|
|
volatile int result = -1;
|
2019-08-08 18:06:08 +03:00
|
|
|
rb_thread_t *th = rb_ec_thread_ptr(ec);
|
2021-06-14 07:52:26 +03:00
|
|
|
volatile const struct {
|
|
|
|
VALUE wrapper, self, errinfo;
|
2023-07-28 11:50:25 +03:00
|
|
|
rb_execution_context_t *ec;
|
2021-06-14 07:52:26 +03:00
|
|
|
} saved = {
|
|
|
|
th->top_wrapper, th->top_self, ec->errinfo,
|
2023-07-28 11:50:25 +03:00
|
|
|
ec,
|
2021-06-14 07:52:26 +03:00
|
|
|
};
|
2017-06-23 10:25:52 +03:00
|
|
|
enum ruby_tag_type state;
|
2006-12-31 18:02:22 +03:00
|
|
|
char *volatile ftptr = 0;
|
2017-06-04 10:29:52 +03:00
|
|
|
VALUE path;
|
2021-06-14 07:49:10 +03:00
|
|
|
volatile VALUE saved_path;
|
2021-10-08 09:44:47 +03:00
|
|
|
volatile VALUE realpath = 0;
|
2021-09-16 19:20:10 +03:00
|
|
|
VALUE realpaths = get_loaded_features_realpaths(th->vm);
|
2023-04-12 22:33:16 +03:00
|
|
|
VALUE realpath_map = get_loaded_features_realpath_map(th->vm);
|
2020-11-30 10:18:43 +03:00
|
|
|
volatile bool reset_ext_config = false;
|
|
|
|
struct rb_ext_config prev_ext_config;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2017-06-04 10:29:52 +03:00
|
|
|
path = rb_str_encode_ospath(fname);
|
2017-06-07 17:36:18 +03:00
|
|
|
RUBY_DTRACE_HOOK(REQUIRE_ENTRY, RSTRING_PTR(fname));
|
2021-06-14 07:49:10 +03:00
|
|
|
saved_path = path;
|
2017-06-01 16:05:54 +03:00
|
|
|
|
2017-11-07 08:45:46 +03:00
|
|
|
EC_PUSH_TAG(ec);
|
2019-08-08 16:17:22 +03:00
|
|
|
ec->errinfo = Qnil; /* ensure */
|
2019-08-08 18:06:08 +03:00
|
|
|
th->top_wrapper = 0;
|
2017-12-06 06:16:08 +03:00
|
|
|
if ((state = EC_EXEC_TAG()) == TAG_NONE) {
|
2023-12-08 09:06:12 +03:00
|
|
|
VALUE handle;
|
2006-12-31 18:02:22 +03:00
|
|
|
int found;
|
|
|
|
|
2017-06-07 17:36:18 +03:00
|
|
|
RUBY_DTRACE_HOOK(FIND_REQUIRE_ENTRY, RSTRING_PTR(fname));
|
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)>'
```
2023-02-27 20:24:45 +03:00
|
|
|
found = search_required(th->vm, path, &saved_path, rb_feature_p);
|
2017-06-07 17:36:18 +03:00
|
|
|
RUBY_DTRACE_HOOK(FIND_REQUIRE_RETURN, RSTRING_PTR(fname));
|
2021-06-14 07:49:10 +03:00
|
|
|
path = saved_path;
|
2017-06-01 16:05:54 +03:00
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
if (found) {
|
2021-09-16 19:20:10 +03:00
|
|
|
if (!path || !(ftptr = load_lock(th->vm, RSTRING_PTR(path), warn))) {
|
2014-12-03 09:13:58 +03:00
|
|
|
result = 0;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2013-11-03 04:35:49 +04:00
|
|
|
else if (!*ftptr) {
|
2015-07-18 17:47:11 +03:00
|
|
|
result = TAG_RETURN;
|
2013-11-03 04:35:49 +04:00
|
|
|
}
|
2022-11-18 01:33:18 +03:00
|
|
|
else if (found == 's' && run_static_ext_init(th->vm, RSTRING_PTR(path))) {
|
|
|
|
result = TAG_RETURN;
|
|
|
|
}
|
Do not load file with same realpath twice when requiring
This fixes issues with paths being loaded twice in certain cases
when symlinks are used.
It took me multiple attempts to get this working. My original
attempt tried to convert paths to realpaths before adding them
to $LOADED_FEATURES. Unfortunately, this doesn't work well
with the loaded feature index, which is based off load paths
and not realpaths. While I was able to get require working, I'm
fairly sure the loaded feature index was not being used as
expected, which would have significant performance implications.
Additionally, I was never able to get that approach working with
autoload when autoloading a non-realpath file. It also broke
some specs.
This takes a more conservative approach. Directly before loading the
file, if the file with the same realpath has been required, the
loading of the file is skipped. The realpaths are stored as
fstrings in a hidden hash.
When rebuilding the loaded feature index, the hash of realpaths
is also rebuilt. I'm guessing this makes rebuilding process
slower, but I don think that is a hot path. In general, modifying
loaded features is only done when reloading, and that tends to be
in non-production environments.
Change test_require_with_loaded_features_pop test to use 30 threads
and 300 iterations, instead of 4 threads and 1000 iterations.
I saw only sporadic failures with 4/1000, but consistent failures
30/300 threads. These failures were due to the fact that the
concurrent deletions from $LOADED_FEATURES in other threads can
result in rb_ary_entry returning nil when rebuilding the loaded
features index.
To avoid concurrency issues when rebuilding the loaded features
index, the building of the index itself is left alone, and
afterwards, a separate loop is done on a copy of the loaded feature
snapshot in order to rebuild the realpaths hash.
Fixes [Bug #17885]
2021-06-30 23:50:19 +03:00
|
|
|
else if (RTEST(rb_hash_aref(realpaths,
|
2023-07-03 03:00:00 +03:00
|
|
|
realpath = realpath_internal_cached(realpath_map, path)))) {
|
Do not load file with same realpath twice when requiring
This fixes issues with paths being loaded twice in certain cases
when symlinks are used.
It took me multiple attempts to get this working. My original
attempt tried to convert paths to realpaths before adding them
to $LOADED_FEATURES. Unfortunately, this doesn't work well
with the loaded feature index, which is based off load paths
and not realpaths. While I was able to get require working, I'm
fairly sure the loaded feature index was not being used as
expected, which would have significant performance implications.
Additionally, I was never able to get that approach working with
autoload when autoloading a non-realpath file. It also broke
some specs.
This takes a more conservative approach. Directly before loading the
file, if the file with the same realpath has been required, the
loading of the file is skipped. The realpaths are stored as
fstrings in a hidden hash.
When rebuilding the loaded feature index, the hash of realpaths
is also rebuilt. I'm guessing this makes rebuilding process
slower, but I don think that is a hot path. In general, modifying
loaded features is only done when reloading, and that tends to be
in non-production environments.
Change test_require_with_loaded_features_pop test to use 30 threads
and 300 iterations, instead of 4 threads and 1000 iterations.
I saw only sporadic failures with 4/1000, but consistent failures
30/300 threads. These failures were due to the fact that the
concurrent deletions from $LOADED_FEATURES in other threads can
result in rb_ary_entry returning nil when rebuilding the loaded
features index.
To avoid concurrency issues when rebuilding the loaded features
index, the building of the index itself is left alone, and
afterwards, a separate loop is done on a copy of the loaded feature
snapshot in order to rebuild the realpaths hash.
Fixes [Bug #17885]
2021-06-30 23:50:19 +03:00
|
|
|
result = 0;
|
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
else {
|
|
|
|
switch (found) {
|
2007-05-03 17:19:11 +04:00
|
|
|
case 'r':
|
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)>'
```
2023-02-27 20:24:45 +03:00
|
|
|
load_iseq_eval(ec, path);
|
2006-12-31 18:02:22 +03:00
|
|
|
break;
|
|
|
|
|
2007-05-03 17:19:11 +04:00
|
|
|
case 's':
|
2020-11-30 10:18:43 +03:00
|
|
|
reset_ext_config = true;
|
|
|
|
ext_config_push(th, &prev_ext_config);
|
2023-12-08 09:06:12 +03:00
|
|
|
handle = rb_vm_call_cfunc(rb_vm_top_self(), load_ext,
|
|
|
|
path, VM_BLOCK_HANDLER_NONE, path);
|
|
|
|
rb_hash_aset(ruby_dln_libmap, path, SVALUE2NUM((SIGNED_VALUE)handle));
|
2006-12-31 18:02:22 +03:00
|
|
|
break;
|
|
|
|
}
|
2019-08-08 11:53:36 +03:00
|
|
|
result = TAG_RETURN;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-10-26 14:02:13 +03:00
|
|
|
EC_POP_TAG();
|
2020-11-30 10:18:43 +03:00
|
|
|
|
2023-07-28 11:50:25 +03:00
|
|
|
ec = saved.ec;
|
2020-12-10 18:56:06 +03:00
|
|
|
rb_thread_t *th2 = rb_ec_thread_ptr(ec);
|
2021-06-14 07:52:26 +03:00
|
|
|
th2->top_self = saved.self;
|
|
|
|
th2->top_wrapper = saved.wrapper;
|
2020-12-10 18:56:06 +03:00
|
|
|
if (reset_ext_config) ext_config_pop(th2, &prev_ext_config);
|
2020-11-30 10:18:43 +03:00
|
|
|
|
2021-06-14 07:49:10 +03:00
|
|
|
path = saved_path;
|
2021-09-16 19:20:10 +03:00
|
|
|
if (ftptr) load_unlock(th2->vm, RSTRING_PTR(path), !state);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
if (state) {
|
2022-01-29 17:11:10 +03:00
|
|
|
if (state == TAG_FATAL || state == TAG_THROW) {
|
2019-11-19 10:56:56 +03:00
|
|
|
EC_JUMP_TAG(ec, state);
|
|
|
|
}
|
|
|
|
else if (exception) {
|
2019-08-08 16:17:22 +03:00
|
|
|
/* usually state == TAG_RAISE only, except for
|
|
|
|
* rb_iseq_load_iseq in load_iseq_eval case */
|
|
|
|
VALUE exc = rb_vm_make_jump_tag_but_local_jump(state, Qundef);
|
|
|
|
if (!NIL_P(exc)) ec->errinfo = exc;
|
|
|
|
return TAG_RAISE;
|
|
|
|
}
|
|
|
|
else if (state == TAG_RETURN) {
|
|
|
|
return TAG_RAISE;
|
|
|
|
}
|
2017-06-01 16:05:54 +03:00
|
|
|
RB_GC_GUARD(fname);
|
2014-12-03 09:13:58 +03:00
|
|
|
/* never TAG_RETURN */
|
2014-12-03 08:51:28 +03:00
|
|
|
return state;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2019-08-08 16:17:22 +03:00
|
|
|
if (!NIL_P(ec->errinfo)) {
|
|
|
|
if (!exception) return TAG_RAISE;
|
|
|
|
rb_exc_raise(ec->errinfo);
|
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
|
Do not load file with same realpath twice when requiring
This fixes issues with paths being loaded twice in certain cases
when symlinks are used.
It took me multiple attempts to get this working. My original
attempt tried to convert paths to realpaths before adding them
to $LOADED_FEATURES. Unfortunately, this doesn't work well
with the loaded feature index, which is based off load paths
and not realpaths. While I was able to get require working, I'm
fairly sure the loaded feature index was not being used as
expected, which would have significant performance implications.
Additionally, I was never able to get that approach working with
autoload when autoloading a non-realpath file. It also broke
some specs.
This takes a more conservative approach. Directly before loading the
file, if the file with the same realpath has been required, the
loading of the file is skipped. The realpaths are stored as
fstrings in a hidden hash.
When rebuilding the loaded feature index, the hash of realpaths
is also rebuilt. I'm guessing this makes rebuilding process
slower, but I don think that is a hot path. In general, modifying
loaded features is only done when reloading, and that tends to be
in non-production environments.
Change test_require_with_loaded_features_pop test to use 30 threads
and 300 iterations, instead of 4 threads and 1000 iterations.
I saw only sporadic failures with 4/1000, but consistent failures
30/300 threads. These failures were due to the fact that the
concurrent deletions from $LOADED_FEATURES in other threads can
result in rb_ary_entry returning nil when rebuilding the loaded
features index.
To avoid concurrency issues when rebuilding the loaded features
index, the building of the index itself is left alone, and
afterwards, a separate loop is done on a copy of the loaded feature
snapshot in order to rebuild the realpaths hash.
Fixes [Bug #17885]
2021-06-30 23:50:19 +03:00
|
|
|
if (result == TAG_RETURN) {
|
2021-09-16 19:20:10 +03:00
|
|
|
rb_provide_feature(th2->vm, path);
|
2021-10-08 09:44:47 +03:00
|
|
|
VALUE real = realpath;
|
|
|
|
if (real) {
|
2023-04-12 22:33:16 +03:00
|
|
|
real = rb_fstring(real);
|
|
|
|
rb_hash_aset(realpaths, real, Qtrue);
|
Do not load file with same realpath twice when requiring
This fixes issues with paths being loaded twice in certain cases
when symlinks are used.
It took me multiple attempts to get this working. My original
attempt tried to convert paths to realpaths before adding them
to $LOADED_FEATURES. Unfortunately, this doesn't work well
with the loaded feature index, which is based off load paths
and not realpaths. While I was able to get require working, I'm
fairly sure the loaded feature index was not being used as
expected, which would have significant performance implications.
Additionally, I was never able to get that approach working with
autoload when autoloading a non-realpath file. It also broke
some specs.
This takes a more conservative approach. Directly before loading the
file, if the file with the same realpath has been required, the
loading of the file is skipped. The realpaths are stored as
fstrings in a hidden hash.
When rebuilding the loaded feature index, the hash of realpaths
is also rebuilt. I'm guessing this makes rebuilding process
slower, but I don think that is a hot path. In general, modifying
loaded features is only done when reloading, and that tends to be
in non-production environments.
Change test_require_with_loaded_features_pop test to use 30 threads
and 300 iterations, instead of 4 threads and 1000 iterations.
I saw only sporadic failures with 4/1000, but consistent failures
30/300 threads. These failures were due to the fact that the
concurrent deletions from $LOADED_FEATURES in other threads can
result in rb_ary_entry returning nil when rebuilding the loaded
features index.
To avoid concurrency issues when rebuilding the loaded features
index, the building of the index itself is left alone, and
afterwards, a separate loop is done on a copy of the loaded feature
snapshot in order to rebuild the realpaths hash.
Fixes [Bug #17885]
2021-06-30 23:50:19 +03:00
|
|
|
}
|
|
|
|
}
|
2021-06-14 07:52:26 +03:00
|
|
|
ec->errinfo = saved.errinfo;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2017-06-07 17:36:18 +03:00
|
|
|
RUBY_DTRACE_HOOK(REQUIRE_RETURN, RSTRING_PTR(fname));
|
* probes.d: add DTrace probe declarations. [ruby-core:27448]
* array.c (empty_ary_alloc, ary_new): added array create DTrace probe.
* compile.c (rb_insns_name): allowing DTrace probes to access
instruction sequence name.
* Makefile.in: translate probes.d file to appropriate header file.
* common.mk: declare dependencies on the DTrace header.
* configure.in: add a test for existence of DTrace.
* eval.c (setup_exception): add a probe for when an exception is
raised.
* gc.c: Add DTrace probes for mark begin and end, and sweep begin and
end.
* hash.c (empty_hash_alloc): Add a probe for hash allocation.
* insns.def: Add probes for function entry and return.
* internal.h: function declaration for compile.c change.
* load.c (rb_f_load): add probes for `load` entry and exit, require
entry and exit, and wrapping search_required for load path search.
* object.c (rb_obj_alloc): added a probe for general object creation.
* parse.y (yycompile0): added a probe around parse and compile phase.
* string.c (empty_str_alloc, str_new): DTrace probes for string
allocation.
* test/dtrace/*: tests for DTrace probes.
* vm.c (vm_invoke_proc): add probes for function return on exception
raise, hash create, and instruction sequence execution.
* vm_core.h: add probe declarations for function entry and exit.
* vm_dump.c: add probes header file.
* vm_eval.c (vm_call0_cfunc, vm_call0_cfunc_with_frame): add probe on
function entry and return.
* vm_exec.c: expose instruction number to instruction name function.
* vm_insnshelper.c: add function entry and exit probes for cfunc
methods.
* vm_insnhelper.h: vm usage information is always collected, so
uncomment the functions.
12 19:14:50 2012 Akinori MUSHA <knu@iDaemons.org>
* configure.in (isinf, isnan): isinf() and isnan() are macros on
DragonFly which cannot be found by AC_REPLACE_FUNCS(). This
workaround enforces the fact that they exist on DragonFly.
12 15:59:38 2012 Shugo Maeda <shugo@ruby-lang.org>
* vm_core.h (rb_call_info_t::refinements), compile.c (new_callinfo),
vm_insnhelper.c (vm_search_method): revert r37616 because it's too
slow. [ruby-dev:46477]
* test/ruby/test_refinement.rb (test_inline_method_cache): skip
the test until the bug is fixed efficiently.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37631 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-13 01:52:12 +04:00
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-09-23 22:31:32 +03:00
|
|
|
int
|
|
|
|
rb_require_internal_silent(VALUE fname)
|
|
|
|
{
|
|
|
|
rb_execution_context_t *ec = GET_EC();
|
|
|
|
return require_internal(ec, fname, 1, false);
|
|
|
|
}
|
|
|
|
|
2019-08-08 16:17:22 +03:00
|
|
|
int
|
2019-09-21 05:06:22 +03:00
|
|
|
rb_require_internal(VALUE fname)
|
2019-08-08 16:17:22 +03:00
|
|
|
{
|
|
|
|
rb_execution_context_t *ec = GET_EC();
|
2021-09-23 22:31:32 +03:00
|
|
|
return require_internal(ec, fname, 1, RTEST(ruby_verbose));
|
2019-08-08 16:17:22 +03:00
|
|
|
}
|
|
|
|
|
2014-12-03 08:51:28 +03:00
|
|
|
int
|
|
|
|
ruby_require_internal(const char *fname, unsigned int len)
|
|
|
|
{
|
|
|
|
struct RString fake;
|
|
|
|
VALUE str = rb_setup_fake_str(&fake, fname, len, 0);
|
2019-08-08 16:17:22 +03:00
|
|
|
rb_execution_context_t *ec = GET_EC();
|
2021-09-23 22:31:32 +03:00
|
|
|
int result = require_internal(ec, str, 0, RTEST(ruby_verbose));
|
2014-12-03 22:20:36 +03:00
|
|
|
rb_set_errinfo(Qnil);
|
2015-07-18 17:47:11 +03:00
|
|
|
return result == TAG_RETURN ? 1 : result ? -1 : 0;
|
2014-12-03 08:51:28 +03:00
|
|
|
}
|
|
|
|
|
2019-09-21 05:06:22 +03:00
|
|
|
VALUE
|
|
|
|
rb_require_string(VALUE fname)
|
2023-11-06 10:59:55 +03:00
|
|
|
{
|
2023-11-27 18:13:05 +03:00
|
|
|
return rb_require_string_internal(FilePathValue(fname), false);
|
2023-11-06 10:59:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2023-11-27 18:13:05 +03:00
|
|
|
rb_require_string_internal(VALUE fname, bool resurrect)
|
2014-12-03 08:51:28 +03:00
|
|
|
{
|
2019-08-08 16:17:22 +03:00
|
|
|
rb_execution_context_t *ec = GET_EC();
|
2021-09-23 22:31:32 +03:00
|
|
|
int result = require_internal(ec, fname, 1, RTEST(ruby_verbose));
|
2014-12-03 08:51:28 +03:00
|
|
|
|
2015-07-18 17:47:11 +03:00
|
|
|
if (result > TAG_RETURN) {
|
2019-08-08 16:17:22 +03:00
|
|
|
EC_JUMP_TAG(ec, result);
|
2014-12-03 08:51:28 +03:00
|
|
|
}
|
2014-12-03 09:13:58 +03:00
|
|
|
if (result < 0) {
|
2023-11-27 18:13:05 +03:00
|
|
|
if (resurrect) fname = rb_str_resurrect(fname);
|
2014-12-03 08:51:28 +03:00
|
|
|
load_failed(fname);
|
|
|
|
}
|
|
|
|
|
2021-08-02 06:06:44 +03:00
|
|
|
return RBOOL(result);
|
2014-12-03 08:51:28 +03:00
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
VALUE
|
|
|
|
rb_require(const char *fname)
|
|
|
|
{
|
2023-11-06 10:59:55 +03:00
|
|
|
struct RString fake;
|
|
|
|
VALUE str = rb_setup_fake_str(&fake, fname, strlen(fname), 0);
|
2023-11-27 18:13:05 +03:00
|
|
|
return rb_require_string_internal(str, true);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
2013-11-03 04:35:49 +04:00
|
|
|
static int
|
|
|
|
register_init_ext(st_data_t *key, st_data_t *value, st_data_t init, int existing)
|
2007-06-18 12:02:30 +04:00
|
|
|
{
|
2013-11-03 04:35:49 +04:00
|
|
|
const char *name = (char *)*key;
|
|
|
|
if (existing) {
|
|
|
|
/* already registered */
|
|
|
|
rb_warn("%s is already registered", name);
|
|
|
|
}
|
|
|
|
else {
|
2022-11-18 01:33:18 +03:00
|
|
|
*value = (st_data_t)init;
|
2013-11-03 04:35:49 +04:00
|
|
|
}
|
|
|
|
return ST_CONTINUE;
|
2007-06-18 12:02:30 +04:00
|
|
|
}
|
|
|
|
|
2023-04-20 16:44:02 +03:00
|
|
|
// Private API for statically linked extensions.
|
|
|
|
// Used with the ext/Setup file, the --with-setup and
|
|
|
|
// --with-static-linked-ext configuration option, etc.
|
2022-11-18 01:33:18 +03:00
|
|
|
void
|
2007-05-03 17:19:11 +04:00
|
|
|
ruby_init_ext(const char *name, void (*init)(void))
|
|
|
|
{
|
2023-04-20 16:44:02 +03:00
|
|
|
st_table *inits_table;
|
2021-09-16 19:20:10 +03:00
|
|
|
rb_vm_t *vm = GET_VM();
|
2013-11-03 04:35:49 +04:00
|
|
|
|
2021-09-16 19:20:10 +03:00
|
|
|
if (feature_provided(vm, name, 0))
|
2014-03-02 05:49:15 +04:00
|
|
|
return;
|
2023-04-20 16:44:02 +03:00
|
|
|
|
|
|
|
inits_table = vm->static_ext_inits;
|
|
|
|
if (!inits_table) {
|
|
|
|
inits_table = st_init_strtable();
|
|
|
|
vm->static_ext_inits = inits_table;
|
|
|
|
}
|
2022-11-18 01:33:18 +03:00
|
|
|
st_update(inits_table, (st_data_t)name, register_init_ext, (st_data_t)init);
|
2007-05-03 17:19:11 +04:00
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2022-06-03 08:09:11 +03:00
|
|
|
* mod.autoload(const, filename) -> nil
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2019-03-22 14:04:59 +03:00
|
|
|
* Registers _filename_ to be loaded (using Kernel::require)
|
2022-06-03 08:09:11 +03:00
|
|
|
* the first time that _const_ (which may be a String or
|
2006-12-31 18:02:22 +03:00
|
|
|
* a symbol) is accessed in the namespace of _mod_.
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* module A
|
|
|
|
* end
|
|
|
|
* A.autoload(:B, "b")
|
|
|
|
* A::B.doit # autoloads "b"
|
2022-06-03 08:10:30 +03:00
|
|
|
*
|
|
|
|
* If _const_ in _mod_ is defined as autoload, the file name to be
|
|
|
|
* loaded is replaced with _filename_. If _const_ is defined but not
|
|
|
|
* as autoload, does nothing.
|
2006-12-31 18:02:22 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_mod_autoload(VALUE mod, VALUE sym, VALUE file)
|
|
|
|
{
|
|
|
|
ID id = rb_to_id(sym);
|
|
|
|
|
2009-06-13 09:57:41 +04:00
|
|
|
FilePathValue(file);
|
introduce rb_autoload_str to replace rb_autoload
rb_autoload_str may be safer by preventing premature GC. It
can also be more efficient by passing a pre-frozen string that
can be deduped using rb_fstring. Common autoload callers (e.g.
rubygems, rdoc) already use string literals as the file
argument.
There seems to be no reason to expose rb_autoload_str to the
public C API since autoload is not performance-critical.
Applications may declare autoloads in Ruby code or via
rb_funcall; so merely deprecate rb_autoload without exposing
rb_autoload_str to new users.
Running: valgrind -v ruby -rrdoc -rubygems -e exit
shows a minor memory reduction (32-bit userspace)
before:
in use at exit: 1,600,621 bytes in 28,819 blocks
total heap usage: 55,786 allocs, 26,967 frees, 6,693,790 bytes allocated
after:
in use at exit: 1,599,778 bytes in 28,789 blocks
total heap usage: 55,739 allocs, 26,950 frees, 6,692,973 bytes allocated
* include/ruby/intern.h (rb_autoload): deprecate
* internal.h (rb_autoload_str): declare
* load.c (rb_mod_autoload): use rb_autoload_str
* variable.c (rb_autoload): become compatibility wrapper
(rb_autoload_str): hoisted out from old rb_autoload
[ruby-core:71369] [Feature #11664]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52909 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-06 15:28:09 +03:00
|
|
|
rb_autoload_str(mod, id, file);
|
2006-12-31 18:02:22 +03:00
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2009-09-23 23:45:37 +04:00
|
|
|
* call-seq:
|
2019-05-07 13:52:24 +03:00
|
|
|
* mod.autoload?(name, inherit=true) -> String or nil
|
2009-09-23 23:45:37 +04:00
|
|
|
*
|
|
|
|
* Returns _filename_ to be loaded if _name_ is registered as
|
2019-05-07 13:52:24 +03:00
|
|
|
* +autoload+ in the namespace of _mod_ or one of its ancestors.
|
2009-09-23 23:45:37 +04:00
|
|
|
*
|
|
|
|
* module A
|
|
|
|
* end
|
|
|
|
* A.autoload(:B, "b")
|
2010-05-18 01:07:33 +04:00
|
|
|
* A.autoload?(:B) #=> "b"
|
2019-05-07 13:52:24 +03:00
|
|
|
*
|
|
|
|
* If +inherit+ is false, the lookup only checks the autoloads in the receiver:
|
|
|
|
*
|
|
|
|
* class A
|
|
|
|
* autoload :CONST, "const.rb"
|
|
|
|
* end
|
|
|
|
*
|
|
|
|
* class B < A
|
|
|
|
* end
|
|
|
|
*
|
|
|
|
* B.autoload?(:CONST) #=> "const.rb", found in A (ancestor)
|
|
|
|
* B.autoload?(:CONST, false) #=> nil, not found in B itself
|
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
2019-05-07 13:52:24 +03:00
|
|
|
rb_mod_autoload_p(int argc, VALUE *argv, VALUE mod)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2019-06-21 11:21:34 +03:00
|
|
|
int recur = (rb_check_arity(argc, 1, 2) == 1) ? TRUE : RTEST(argv[1]);
|
2019-05-07 13:52:24 +03:00
|
|
|
VALUE sym = argv[0];
|
|
|
|
|
2014-07-09 10:14:41 +04:00
|
|
|
ID id = rb_check_id(&sym);
|
2011-07-26 20:05:35 +04:00
|
|
|
if (!id) {
|
|
|
|
return Qnil;
|
|
|
|
}
|
2019-05-07 13:52:24 +03:00
|
|
|
return rb_autoload_at_p(mod, id, recur);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
2022-06-03 08:09:11 +03:00
|
|
|
* autoload(const, filename) -> nil
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2019-03-22 14:04:59 +03:00
|
|
|
* Registers _filename_ to be loaded (using Kernel::require)
|
2022-06-03 08:09:11 +03:00
|
|
|
* the first time that _const_ (which may be a String or
|
2006-12-31 18:02:22 +03:00
|
|
|
* a symbol) is accessed.
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* autoload(:MyModule, "/usr/local/lib/modules/my_module.rb")
|
2022-06-03 08:10:30 +03:00
|
|
|
*
|
|
|
|
* If _const_ is defined as autoload, the file name to be loaded is
|
|
|
|
* replaced with _filename_. If _const_ is defined but not as
|
|
|
|
* autoload, does nothing.
|
2006-12-31 18:02:22 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_f_autoload(VALUE obj, VALUE sym, VALUE file)
|
|
|
|
{
|
2011-07-10 10:32:06 +04:00
|
|
|
VALUE klass = rb_class_real(rb_vm_cbase());
|
2020-10-08 19:21:10 +03:00
|
|
|
if (!klass) {
|
2006-12-31 18:02:22 +03:00
|
|
|
rb_raise(rb_eTypeError, "Can not set autoload on singleton class");
|
|
|
|
}
|
|
|
|
return rb_mod_autoload(klass, sym, file);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2009-09-23 23:45:37 +04:00
|
|
|
* call-seq:
|
2019-05-07 13:52:24 +03:00
|
|
|
* autoload?(name, inherit=true) -> String or nil
|
2009-09-23 23:45:37 +04:00
|
|
|
*
|
|
|
|
* Returns _filename_ to be loaded if _name_ is registered as
|
|
|
|
* +autoload+.
|
|
|
|
*
|
|
|
|
* autoload(:B, "b")
|
2010-05-18 01:07:33 +04:00
|
|
|
* autoload?(:B) #=> "b"
|
2006-12-31 18:02:22 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
2019-05-07 13:52:24 +03:00
|
|
|
rb_f_autoload_p(int argc, VALUE *argv, VALUE obj)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
* vm.c, insns.def, eval.c, vm_insnhelper.c: fix CREF handling.
VM value stack frame of block contains cref information.
(dfp[-1] points CREF)
* compile.c, eval_intern.h, eval_method.c, load.c, proc.c,
vm_dump.h, vm_core.h: ditto.
* include/ruby/ruby.h, gc.c: remove T_VALUES because of above
changes.
* bootstraptest/test_eval.rb, test_knownbug.rb: move solved test.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16468 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-05-19 07:08:50 +04:00
|
|
|
/* use rb_vm_cbase() as same as rb_f_autoload. */
|
|
|
|
VALUE klass = rb_vm_cbase();
|
2006-12-31 18:02:22 +03:00
|
|
|
if (NIL_P(klass)) {
|
|
|
|
return Qnil;
|
|
|
|
}
|
2019-05-07 13:52:24 +03:00
|
|
|
return rb_mod_autoload_p(argc, argv, klass);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
2023-12-08 09:06:12 +03:00
|
|
|
void *
|
|
|
|
rb_ext_resolve_symbol(const char* fname, const char* symbol)
|
|
|
|
{
|
|
|
|
VALUE handle;
|
|
|
|
VALUE resolved;
|
|
|
|
VALUE path;
|
|
|
|
char *ext;
|
|
|
|
VALUE fname_str = rb_str_new_cstr(fname);
|
|
|
|
|
|
|
|
resolved = rb_resolve_feature_path((VALUE)NULL, fname_str);
|
|
|
|
if (NIL_P(resolved)) {
|
|
|
|
ext = strrchr(fname, '.');
|
|
|
|
if (!ext || !IS_SOEXT(ext)) {
|
|
|
|
rb_str_cat_cstr(fname_str, ".so");
|
|
|
|
}
|
|
|
|
if (rb_feature_p(GET_VM(), fname, 0, FALSE, FALSE, 0)) {
|
|
|
|
return dln_symbol(NULL, symbol);
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (RARRAY_LEN(resolved) != 2 || rb_ary_entry(resolved, 0) != ID2SYM(rb_intern("so"))) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
path = rb_ary_entry(resolved, 1);
|
|
|
|
handle = rb_hash_lookup(ruby_dln_libmap, path);
|
|
|
|
if (NIL_P(handle)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return dln_symbol((void *)NUM2SVALUE(handle), symbol);
|
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
void
|
2014-09-30 09:25:32 +04:00
|
|
|
Init_load(void)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2008-04-30 13:03:03 +04:00
|
|
|
rb_vm_t *vm = GET_VM();
|
2008-08-16 04:20:31 +04:00
|
|
|
static const char var_load_path[] = "$:";
|
|
|
|
ID id_load_path = rb_intern2(var_load_path, sizeof(var_load_path)-1);
|
2008-04-30 13:03:03 +04:00
|
|
|
|
2009-06-21 17:35:41 +04:00
|
|
|
rb_define_hooked_variable(var_load_path, (VALUE*)vm, load_path_getter, rb_gvar_readonly_setter);
|
2020-09-25 20:56:30 +03:00
|
|
|
rb_alias_variable(rb_intern_const("$-I"), id_load_path);
|
|
|
|
rb_alias_variable(rb_intern_const("$LOAD_PATH"), id_load_path);
|
2008-04-30 13:03:03 +04:00
|
|
|
vm->load_path = rb_ary_new();
|
2022-07-25 17:40:45 +03:00
|
|
|
vm->expanded_load_path = rb_ary_hidden_new(0);
|
|
|
|
vm->load_path_snapshot = rb_ary_hidden_new(0);
|
2012-11-05 19:27:08 +04:00
|
|
|
vm->load_path_check_cache = 0;
|
2019-07-11 08:05:34 +03:00
|
|
|
rb_define_singleton_method(vm->load_path, "resolve_feature_path", rb_resolve_feature_path, 1);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2019-08-27 08:21:18 +03:00
|
|
|
rb_define_virtual_variable("$\"", get_LOADED_FEATURES, 0);
|
|
|
|
rb_define_virtual_variable("$LOADED_FEATURES", get_LOADED_FEATURES, 0);
|
2008-04-30 13:03:03 +04:00
|
|
|
vm->loaded_features = rb_ary_new();
|
2022-07-25 17:40:45 +03:00
|
|
|
vm->loaded_features_snapshot = rb_ary_hidden_new(0);
|
2018-02-14 21:38:33 +03:00
|
|
|
vm->loaded_features_index = st_init_numtable();
|
Do not load file with same realpath twice when requiring
This fixes issues with paths being loaded twice in certain cases
when symlinks are used.
It took me multiple attempts to get this working. My original
attempt tried to convert paths to realpaths before adding them
to $LOADED_FEATURES. Unfortunately, this doesn't work well
with the loaded feature index, which is based off load paths
and not realpaths. While I was able to get require working, I'm
fairly sure the loaded feature index was not being used as
expected, which would have significant performance implications.
Additionally, I was never able to get that approach working with
autoload when autoloading a non-realpath file. It also broke
some specs.
This takes a more conservative approach. Directly before loading the
file, if the file with the same realpath has been required, the
loading of the file is skipped. The realpaths are stored as
fstrings in a hidden hash.
When rebuilding the loaded feature index, the hash of realpaths
is also rebuilt. I'm guessing this makes rebuilding process
slower, but I don think that is a hot path. In general, modifying
loaded features is only done when reloading, and that tends to be
in non-production environments.
Change test_require_with_loaded_features_pop test to use 30 threads
and 300 iterations, instead of 4 threads and 1000 iterations.
I saw only sporadic failures with 4/1000, but consistent failures
30/300 threads. These failures were due to the fact that the
concurrent deletions from $LOADED_FEATURES in other threads can
result in rb_ary_entry returning nil when rebuilding the loaded
features index.
To avoid concurrency issues when rebuilding the loaded features
index, the building of the index itself is left alone, and
afterwards, a separate loop is done on a copy of the loaded feature
snapshot in order to rebuild the realpaths hash.
Fixes [Bug #17885]
2021-06-30 23:50:19 +03:00
|
|
|
vm->loaded_features_realpaths = rb_hash_new();
|
|
|
|
rb_obj_hide(vm->loaded_features_realpaths);
|
2023-04-12 22:33:16 +03:00
|
|
|
vm->loaded_features_realpath_map = rb_hash_new();
|
|
|
|
rb_obj_hide(vm->loaded_features_realpath_map);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
rb_define_global_function("load", rb_f_load, -1);
|
|
|
|
rb_define_global_function("require", rb_f_require, 1);
|
2010-03-16 20:40:00 +03:00
|
|
|
rb_define_global_function("require_relative", rb_f_require_relative, 1);
|
2006-12-31 18:02:22 +03:00
|
|
|
rb_define_method(rb_cModule, "autoload", rb_mod_autoload, 2);
|
2019-05-07 13:52:24 +03:00
|
|
|
rb_define_method(rb_cModule, "autoload?", rb_mod_autoload_p, -1);
|
2006-12-31 18:02:22 +03:00
|
|
|
rb_define_global_function("autoload", rb_f_autoload, 2);
|
2019-05-07 13:52:24 +03:00
|
|
|
rb_define_global_function("autoload?", rb_f_autoload_p, -1);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2023-12-08 09:06:12 +03:00
|
|
|
ruby_dln_libmap = rb_hash_new_with_size(0);
|
|
|
|
rb_gc_register_mark_object(ruby_dln_libmap);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|