Use ID instead of GENTRY for gvars.
Global variables are compiled into GENTRY (a pointer to struct
rb_global_entry). This patch replace this GENTRY to ID and
make the code simple.
We need to search GENTRY from ID every time (st_lookup), so
additional overhead will be introduced.
However, the performance of accessing global variables is not
important now a day and this simplicity helps Ractor development.
Not every compilers understand that rb_raise does not return. When a
function does not end with a return statement, such compilers can issue
warnings. We would better tell them about reachabilities.
900e83b501 changed from a warning
to an error in this case, but the warning was only issued in
verbose mode, and therefore the error was only raised in verbose
mode. That was not intentional, verbose mode should only change
whether warnings are emitted, not other behavior. This issues
the RuntimeError in all cases.
This change broke a couple tests, as the tests actually issued
the warning and therefore now raise an error. This wasn't caught
earlier as test_variable suppressed the warning in this case,
effectively setting $VERBOSE = false around the code that warned.
basictest isn't run in verbose mode and therefore didn't expose
the issue previously. Fix these tests.
Fixes [Bug #14541]
Setting class varibles goes through the ancestor list which can
contain iclasses. Iclasses share a lot of information with the
module they are made from, but not the frozen status.
Check the frozen status of the module instead of the iclass.
This patch allows global variables that have been assigned in Ruby to
move. I added a new function for the GC to call that will update
global references and introduced a new callback in the global variable
struct for updating references.
Only pure Ruby global variables are supported right now, other
references will be pinned.
This changes the following warnings:
* warning: class variable access from toplevel
* warning: class variable @foo of D is overtaken by C
into RuntimeErrors. Handle defined?(@@foo) at toplevel
by returning nil instead of raising an exception (the previous
behavior warned before returning nil when defined? was used).
Refactor the specs to avoid the warnings even in older versions.
The specs were checking for the warnings, but the purpose of
the related specs as evidenced from their description is to
test for behavior, not for warnings.
Fixes [Bug #14541]
Since 9d9aea7fe5, generic instance
variables need `iv_index_tbl` in the object's class. As hidden
objects, however, have no class, access to the variables causes a
segfault. Get rid of that segfault by raising an exception, for
the time being.
I think global references should either be 0 or valid heap pointers.
`rb_gc_mark_maybe` checks to see if the pointer is a valid heap pointer,
but I believe we already know they are valid addresses
If the instance variable table hasn't been "expanded", allocate the
maximum size of the ivar table. This operates under the assumption that
most objects will eventually expand their ivar array to the maximum
width anyway, so we may as well avoid realloc calls.
Saves comitters' daily life by avoid #include-ing everything from
internal.h to make each file do so instead. This would significantly
speed up incremental builds.
We take the following inclusion order in this changeset:
1. "ruby/config.h", where _GNU_SOURCE is defined (must be the very
first thing among everything).
2. RUBY_EXTCONF_H if any.
3. Standard C headers, sorted alphabetically.
4. Other system headers, maybe guarded by #ifdef
5. Everything else, sorted alphabetically.
Exceptions are those win32-related headers, which tend not be self-
containing (headers have inclusion order dependencies).
This copies the private/deprecate constant visibility across the
autoload. It still is backwards compatible with setting the
private/deprecate constant visibility in the autoloaded file.
However, if you explicitly set public constant in the autoloaded
file, that will be reset after the autoload.
Fixes [Bug #11055]
rb_eval_cmd takes a safe level, and now that $SAFE is deprecated,
it should be deprecated as well.
Replace with rb_eval_cmd_kw, which takes a keyword flag. Switch
the two callers to this function.
This removes the related tests, and puts the related specs behind
version guards. This affects all code in lib, including some
libraries that may want to support older versions of Ruby.
This removes the security features added by $SAFE = 1, and warns for access
or modification of $SAFE from Ruby-level, as well as warning when calling
all public C functions related to $SAFE.
This modifies some internal functions that took a safe level argument
to no longer take the argument.
rb_require_safe now warns, rb_require_string has been added as a
version that takes a VALUE and does not warn.
One public C function that still takes a safe level argument and that
this doesn't warn for is rb_eval_cmd. We may want to consider
adding an alternative method that does not take a safe level argument,
and warn for rb_eval_cmd.
Looking at the list of symbols inside of libruby-static.a, I found
hundreds of functions that are defined, but used from nowhere.
There can be reasons for each of them (e.g. some functions are
specific to some platform, some are useful when debugging, etc).
However it seems the functions deleted here exist for no reason.
This changeset reduces the size of ruby binary from 26,671,456
bytes to 26,592,864 bytes on my machine.
This function was created as a variant of st_copy with firing write
barrier.
It should have more explicit name, such as st_copy_with_write_barrier.
But because it is used only for copying iv_tbl, so I rename it to
rb_iv_tbl_copy now. If we face other use case than iv_tbl, we may want
to rename it to more general name.
Module#class_variables should reflect class variable lookup. For
singleton classes of classes/modules, this means the lookup should
be:
* Singleton Class
* Class
* All Ancestors of Class
Note that this doesn't include modules included in the singleton
class, because class variable lookup doesn't include those.
Singleton classes of other objects do not have this behavior and
always just search all ancestors of the singleton class, so do not
change the behavior for them.
Fixes [Bug #8297]
After 5e86b005c0, I now think ANYARGS is
dangerous and should be extinct. This commit adds a function
prototype for rb_ivar_foreach. Luckily this change revealed no
problematic usage of the function.
After 5e86b005c0, I now think ANYARGS is
dangerous and should be extinct. This commit uses rb_gvar_getter_t /
rb_gvar_setter_t for rb_define_hooked_variable /
rb_define_virtual_variable which revealed lots of function prototype
inconsistencies. Some of them were literally decades old, going back
to dda5dc00cf.
After 5e86b005c0, I now think ANYARGS is
dangerous and should be extinct. This commit deletes ANYARGS from
rb_ensure, which also revealed many arity / type mismatches.
b00f280d4b introduced
an accidental behavior change in that defining a module/class under
`m` gives `m` a name when `m` is anonymous.
`ruby -ve 'Module.new { class self::A; end; p name }'` outputs a name
similar to `Module#inspect` when it should output `nil` like in Ruby
2.6.x.
* variable.c: Use `make_temporary_path` instead of `save_temporary_path`
when getting the name of the parent module.
* variable.c (rb_set_class_path): Delegate to `rb_set_class_path_string`
instead of duplicating the logic.
[Bug #16097]
Renaming this function. "No pin" leaks some implementation details. We
just want users to know that if they mark this object, the reference may
move and they'll need to update the reference accordingly.
iter_lev is used to detect the hash is iterating or not.
Usually, iter_lev should be very small number (1 or 2) so
`int` is overkill.
This patch introduce iter_lev in flags (7 bits, FL13 to FL19)
and if iter_lev exceeds this range, save it in hidden attribute.
We can get 1 word in RHash.
We can't modify frozen objects. Therefore I added new internal API
`rb_ivar_set_internal()` which allows us to set an attribute
even if the target object is frozen
if the name is hidden ivar (the name without `@` prefix).
* variable.c: make the hidden ivars `classpath` and `tmp_classpath` the source
of truth for module and constant names. Assign to them when modules are bind
to constants.
* variable.c: remove references to module name cache, as what used to be the cache
is now the source of truth. Remove rb_class_path_no_cache().
* variable.c: remove the hidden ivar `classid`. This existed for the purposes of
module name search, which is now replaced. Also, remove the associated
rb_name_class().
* class.c: use rb_set_class_path_string to set the name of Object during boot.
Must use a fstring as this runs before rb_cString is initialized and
creating a normal string leads to a VALUE without a class.
* spec/ruby/core/module/name_spec.rb: add a few specs to specify what happens
to Module#name across multiple operations. These specs pass without other
code changes in this commit.
[Feature #15765]
autoload_reset() can read this state.result. Because autoload_reset
is a function passed to rb_ensure, there is a chance when an
execption raises before actually filling this memory region.
test/ruby/test_defined.rb:test_autoload_noload is one of such case.
Found using memory sanitizer.
==54014==WARNING: MemorySanitizer: use-of-uninitialized-value
#0 0x557a683f3e5a in autoload_reset variable.c:2372:9
#1 0x557a6707a93b in rb_ensure eval.c:1084:5
#2 0x557a683efbf5 in rb_autoload_load variable.c:2475:14
#3 0x557a685fc460 in vm_get_ev_const vm_insnhelper.c:938:4
#4 0x557a68448e0a in vm_exec_core insns.def:267:11
For some reason symbols (or classes) are being overridden in trunk
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67598 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit adds the new method `GC.compact` and compacting GC support.
Please see this issue for caveats:
https://bugs.ruby-lang.org/issues/15626
[Feature #15626]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67576 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Because hard to specify commits related to r67479 only.
So please commit again.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67499 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit adds the new method `GC.compact` and compacting GC support.
Please see this issue for caveats:
https://bugs.ruby-lang.org/issues/15626
[Feature #15626]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67479 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Especially over checking argc then calling rb_scan_args just to
raise an ArgumentError.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66238 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* variable.c (obj_ivar_set): remove '//' style comments pointed out by the
following build log: https://travis-ci.org/ruby/ruby/jobs/448551951
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65466 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* variable.c: now instance variable space has theap supports.
obj_ivar_heap_alloc() tries to acquire memory from theap.
* debug_counter.h: add some counters for theap.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65451 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* variable.c: now instance variable space has theap supports.
obj_ivar_heap_alloc() tries to acquire memory from theap.
* debug_counter.h: add some counters for theap.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65446 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
An instruction is leaf if it has no rb_funcall inside. In order to
check this property, we introduce stack canary which is a random
number collected at runtime. Stack top is always filled with this
number and checked for stack smashing operations, when VM_CHECK_MODE.
[GH-1947]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64677 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Just refactoring. Despite its name, the function does NOT return a
boolean but raises an exception when the class given is frozen.
I don't think the new name "rb_class_modify_check" is the best, but
it follows the precedeint "rb_ary_modify_check", and is definitely
better than "*_p".
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64078 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* include/ruby/ruby.h (UNREACHABLE_RETURN): UNREACHABLE at the end
of non-void functions.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64025 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
It should be described that the string argument will be accept like Object#instance_variable_get.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63966 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* variable.c (rb_const_search): call #const_missing method on
private constants, as well as uninitialized constants.
[Feature #14328]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63871 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* variable.c (rb_const_search): fix NameError :receiver attribute
on private constant, should raise with the included module, not
the ICLASS.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63696 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
We need to ensure autoload declarations pointing to the same
feature (aka "file") can wait on each other to avoid deadlock
situations.
So, reorganize autoload data structures to maintain a
feature => autoload_data_i mapping, and have module constant
tables point to the new autoload_const struct instead of
directly to autoload_data_i. This allows multiple
autoload_const structs to refer to the SAME autoload_data_i
struct, and with it, the on-stack autoload_state.waitq.
The end result is different constants can share the same waitq
(tied to the feature name), and not deadlock each other during
loading.
Thanks to Eugene Kenny for the bug report and reproducible test case.
Reported-by: Eugene Kenny <elkenny@gmail.com>
* variable.c (autoload_featuremap): new global
(struct autoload_const): new per-const struct
(struct autoload_state): reference autoload_const instead of autoload_data_i
(struct autoload_data_i): remove per-const
(autoload_i_mark): delete from autoload_featuremap if unreferenced
(autoload_c_mark): new dmark callback
(autoload_c_free): new dfree callback
(autoload_c_memsize): new memsize callback
(autoload_const_type): new data type
(get_autoload_data): set autoload_const as well
(rb_autoload_str): use new data structures
(autoload_delete): cleanup from autoload_featuremap
(check_autoload_required): adjust for new internals
(rb_autoloading_value): ditto
(struct autoload_const_set_args): remove, redundant with autoload_const
(const_tbl_update): adjust for new internals
(autoload_const_set): ditto
(autoload_require): ditto
(autoload_reset): ditto
(rb_autoload_load): ditto
(rb_const_set): ditto
(current_autoload_data): ditto
(set_const_visibility): ditto
* test/ruby/test_autoload.rb (test_autoload_same_file): new test
(test_no_leak): new test
[ruby-core:86935] [Bug #14742]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63392 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
I can't reproduce the problem on my 32-bit machine, and I have
connectivity problems to my 64-bit systems at the moment.
Will revisit in a few hours hopefully.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63390 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
We must not call normal Hash methods inside GC free callback,
either, however identity hash may be used.
[ruby-core:86935] [Bug #14742]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63389 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
We need to ensure autoload declarations pointing to the same
feature (aka "file") can wait on each other to avoid deadlock
situations.
So, reorganize autoload data structures to maintain a
feature => autoload_data_i mapping, and have module constant
tables point to the new autoload_const struct instead of
directly to autoload_data_i. This allows multiple
autoload_const structs to refer to the SAME autoload_data_i
struct, and with it, the on-stack autoload_state.waitq.
The end result is different constants can share the same waitq
(tied to the feature name), and not deadlock each other during
loading.
Thanks to Eugene Kenny for the bug report and reproducible test case.
Reported-by: Eugene Kenny <elkenny@gmail.com>
* variable.c (autoload_featuremap): new global
(struct autoload_const): new per-const struct
(struct autoload_state): reference autoload_const instead of autoload_data_i
(struct autoload_data_i): remove per-const
(autoload_i_mark): delete from autoload_featuremap if unreferenced
(autoload_c_mark): new dmark callback
(autoload_c_free): new dfree callback
(autoload_c_memsize): new memsize callback
(autoload_const_type): new data type
(get_autoload_data): set autoload_const as well
(rb_autoload_str): use new data structures
(autoload_delete): cleanup from autoload_featuremap
(check_autoload_required): adjust for new internals
(rb_autoloading_value): ditto
(struct autoload_const_set_args): remove, redundant with autoload_const
(const_tbl_update): adjust for new internals
(autoload_const_set): ditto
(autoload_require): ditto
(autoload_reset): ditto
(rb_autoload_load): ditto
(rb_const_set): ditto
(current_autoload_data): ditto
(set_const_visibility): ditto
* test/ruby/test_autoload.rb (test_autoload_same_file): new test
[ruby-core:86935] [Bug #14742]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63387 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This is fairly non-intrusive bugfix to prevent children
from trying to reach into thread stacks of the parent.
I will probably reuse this idea and redo r62934, too
(same bug).
* vm_core.h (typedef struct rb_vm_struct): add fork_gen counter
* thread.c (rb_thread_atfork_internal): increment fork_gen
* variable.c (struct autoload_data_i): store fork_gen
* variable.c (check_autoload_data): remove (replaced with get_...)
* variable.c (get_autoload_data): check fork_gen when retrieving
* variable.c (check_autoload_required): use get_autoload_data
* variable.c (rb_autoloading_value): ditto
* variable.c (rb_autoload_p): ditto
* variable.c (current_autoload_data): ditto
* variable.c (autoload_reset): reset fork_gen, adjust indent
* variable.c (rb_autoload_load): set fork_gen when setting state
* test/ruby/test_autoload.rb (test_autoload_fork): new test
[ruby-core:86410] [Bug #14634]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63210 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* variable.c (const_tbl_update): flags by deprecate_constant /
private_constant set during autoloading should be preserved
after required. [ruby-core:85516] [Bug #14469]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62395 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
check the declaration of `rb_autoloading_value()` in vm_core.h and the call in
vm_insnhelper.c, and retry it.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62393 b2dd03c8-39d4-4d8f-98ff-823fe69b080e