summaryrefslogtreecommitdiff
path: root/variable.c
AgeCommit message (Collapse)Author
2020-08-19ROBJECT_IV_INDEX_TBL: convert into an inline function卜部昌平
Former ROBJECT_IV_INDEX_TBL macro included RCLASS_IV_INDEX_TBL, which is not disclosed to extension libraies. The macro was kind of broken. Why not just deprecate it, and convert the internal use into an inline function. Notes: Merged: https://github.com/ruby/ruby/pull/3427
2020-08-17Ensure the shortcut cached in the classNobuyoshi Nakada
As well as the other places using RCLASS_IV_INDEX_TBL. `IO#reopen` seems the only case that the class of an object can be changed.
2020-08-02Improve docs for Module#remove_class_variable [ci skip]Alan Wu
2020-07-20Remove trailing spaces [ci skip]Nobuyoshi Nakada
2020-07-03Use ID instead of GENTRY for gvars. (#3278)Koichi Sasada
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. Notes: Merged-By: ko1 <ko1@atdot.net>
2020-06-29add UNREACHABLE_RETURN卜部昌平
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. Notes: Merged: https://github.com/ruby/ruby/pull/3247
2020-06-29rb_mod_remove_cvar: do not goto into a branch卜部昌平
I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor. Notes: Merged: https://github.com/ruby/ruby/pull/3247
2020-06-29rb_copy_generic_ivar: do not goto into a branch卜部昌平
I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor. Notes: Merged: https://github.com/ruby/ruby/pull/3247
2020-06-29generic_ivar_update: do not goto into a branch卜部昌平
I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor. Notes: Merged: https://github.com/ruby/ruby/pull/3247
2020-06-29rb_path_to_class: do not goto into a branch卜部昌平
I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor. Notes: Merged: https://github.com/ruby/ruby/pull/3247
2020-06-18Raise RuntimeError for class variable overtaken in nonverbose modeJeremy Evans
900e83b50115afda3f79712310e4cb95e4508972 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] Notes: Merged: https://github.com/ruby/ruby/pull/3210
2020-06-11Prohibit setting class variable on frozen module through inheritanceAlan Wu
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. Notes: Merged: https://github.com/ruby/ruby/pull/3203
2020-05-11sed -i 's|ruby/impl|ruby/internal|'卜部昌平
To fix build failures. Notes: Merged: https://github.com/ruby/ruby/pull/3079
2020-05-11sed -i s|ruby/3|ruby/impl|g卜部昌平
This shall fix compile errors. Notes: Merged: https://github.com/ruby/ruby/pull/3079
2020-05-07Allow global variables to moveAaron Patterson
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.
2020-04-10Turn class variable warnings into exceptionsJeremy Evans
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] Notes: Merged: https://github.com/ruby/ruby/pull/2987
2020-04-08Suppress -Wswitch warningsNobuyoshi Nakada
2020-04-08Merge pull request #2991 from shyouhei/ruby.h卜部昌平
Split ruby.h Notes: Merged-By: shyouhei <shyouhei@ruby-lang.org>
2020-04-07Fix source location of autoloaded constant [Bug #16764]Nobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/3009
2020-04-07Removed unnecessary castNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/3009
2020-02-12Workaround of instance variable on hidden objectNobuyoshi Nakada
Since 9d9aea7fe50f6340829faa105d9ffe08ebaee658, 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.
2020-02-11Removed unused variableNobuyoshi Nakada
`generic_iv_tbl_compat` has not been utilized since 14d61a94ff01.
2020-01-30Use `rb_gc_mark` when marking globalsAaron Patterson
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
2020-01-06always expand ivar arrays to max widthAaron Patterson
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. Notes: Merged: https://github.com/ruby/ruby/pull/2820
2019-12-26decouple internal.h headers卜部昌平
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). Notes: Merged: https://github.com/ruby/ruby/pull/2711
2019-12-22Enhance docs for Module#deprecate_constantzverok
Notes: Merged: https://github.com/ruby/ruby/pull/2768
2019-12-19Made the warning for deprecated constants follow the category flagNobuyoshi Nakada
2019-12-03Do not lose existing constant visibility when autoloadingJeremy Evans
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] Notes: Merged: https://github.com/ruby/ruby/pull/2716
2019-11-29Supress class variable overtaken warning when original modules are the sameJeremy Evans
This issue was exposed by recent commits to better support including refined modules. Notes: Merged: https://github.com/ruby/ruby/pull/2709
2019-11-29export func for MJITKoichi Sasada
2019-11-29Revert "export for MJIT"Koichi Sasada
This reverts commit 2e6f1cf8b264f4c8499c4e5f18bf662fdade04ff.
2019-11-29export for MJITKoichi Sasada
2019-11-29fastpath for ivar read of FL_EXIVAR objects.Koichi Sasada
vm_getivar() provides fastpath for T_OBJECT by caching an index of ivar. This patch also provides fastpath for FL_EXIVAR objects. FL_EXIVAR objects have an each ivar array and index can be cached as T_OBJECT. To access this ivar array, generic_iv_tbl is exposed by rb_ivar_generic_ivtbl() (declared in variable.h which is newly introduced). Benchmark script: Benchmark.driver(repeat_count: 3){|x| x.executable name: 'clean', command: %w'../clean/miniruby' x.executable name: 'trunk', command: %w'./miniruby' objs = [Object.new, 'str', {a: 1, b: 2}, [1, 2]] objs.each.with_index{|obj, i| rep = obj.inspect rep = 'Object.new' if /\#/ =~ rep x.prelude str = %Q{ v#{i} = #{rep} def v#{i}.foo @iv # ivar access method (attr_reader) end v#{i}.instance_variable_set(:@iv, :iv) } puts str x.report %Q{ v#{i}.foo } } } Result: v0.foo # T_OBJECT clean: 85387141.8 i/s trunk: 85249373.6 i/s - 1.00x slower v1.foo # T_STRING trunk: 57894407.5 i/s clean: 39957178.6 i/s - 1.45x slower v2.foo # T_HASH trunk: 56629413.2 i/s clean: 39227088.9 i/s - 1.44x slower v3.foo # T_ARRAY trunk: 55797530.2 i/s clean: 38263572.9 i/s - 1.46x slower
2019-11-25Improve consistency of bool/true/falseKazuhiro NISHIYAMA
2019-11-18Deprecate rb_eval_cmd, add rb_eval_cmd_kwJeremy Evans
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. Notes: Merged: https://github.com/ruby/ruby/pull/2476
2019-11-18Deprecate taint/trust and related methods, and make the methods no-opsJeremy Evans
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. Notes: Merged: https://github.com/ruby/ruby/pull/2476
2019-11-18Warn on access/modify of $SAFE, and remove effects of modifying $SAFEJeremy Evans
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. Notes: Merged: https://github.com/ruby/ruby/pull/2476
2019-11-14delete unused functions卜部昌平
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. Notes: Merged: https://github.com/ruby/ruby/pull/2677
2019-10-09Prefer st_is_member over st_lookup with 0Ben Woosley
The st_is_member DEFINE has simpler semantics, for more readable code. Notes: Merged: https://github.com/ruby/ruby/pull/1622
2019-09-26[EXPERIMENTAL] Make Module#name return a frozen StringJean Boussier
* Always the same frozen String for a given Module or Class. * Avoids extra allocations whenever calling Module#name. * See [Feature #16150] Notes: Merged: https://github.com/ruby/ruby/pull/2487
2019-09-22variable.c: Rename rb_st_copy to rb_iv_tbl_copyYusuke Endoh
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.
2019-09-21Fix Module#class_variables for singleton classes of classes/modulesJeremy Evans
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] Notes: Merged: https://github.com/ruby/ruby/pull/2478
2019-09-01Export rb_const_source_location_at for MJITKazuki Tsujimoto
2019-08-29move docs around [ci skip]卜部昌平
To properly generate documents.
2019-08-27rb_ivar_foreach now free from ANYARGS卜部昌平
After 5e86b005c0f2ef30df2f9906c7e2f3abefe286a2, 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.
2019-08-27rb_define_hooked_variable now free from ANYARGS卜部昌平
After 5e86b005c0f2ef30df2f9906c7e2f3abefe286a2, 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 dda5dc00cff334cac373096d444a0fd59e716124.
2019-08-27rb_ensure now free from ANYARGS卜部昌平
After 5e86b005c0f2ef30df2f9906c7e2f3abefe286a2, I now think ANYARGS is dangerous and should be extinct. This commit deletes ANYARGS from rb_ensure, which also revealed many arity / type mismatches.
2019-08-14Don't accidentally name anonymous module/classAlan Wu
b00f280d4b9569e7153365d7e1c522b3d6b3c6cf 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] Notes: Merged: https://github.com/ruby/ruby/pull/2337
2019-08-12Rename rb_gc_mark_no_pin -> rb_gc_mark_movableAaron Patterson
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.
2019-07-31remove RHash::iter_lev.Koichi Sasada
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).