diff options
| author | Jean Boussier <jean.boussier@gmail.com> | 2025-03-20 17:25:15 +0100 |
|---|---|---|
| committer | Jean Boussier <jean.boussier@gmail.com> | 2025-03-20 18:18:11 +0100 |
| commit | de097fbe5f3df105bd2a26e72db06b0f5139bc1a (patch) | |
| tree | 3a3fa5499e0ec9e6eba24fb8dfc62127dd373a89 /variable.c | |
| parent | a51364f54b644ba2d98779f0af8c7203822d9a31 (diff) | |
Trigger `inherited` and `const_set` callbacks after const has been defined
[Misc #21143]
[Bug #21193]
The previous change caused a backward compatibility issue with code
that called `Object.const_source_location` from the `inherited` callback.
To fix this, the order is now:
- Define the constant
- Invoke `inherited`
- Invoke `const_set`
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/12956
Diffstat (limited to 'variable.c')
| -rw-r--r-- | variable.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/variable.c b/variable.c index 23602687e2..468f2c3930 100644 --- a/variable.c +++ b/variable.c @@ -2624,7 +2624,6 @@ rb_autoload(VALUE module, ID name, const char *feature) } static void const_set(VALUE klass, ID id, VALUE val); -static void const_added(VALUE klass, ID const_name); struct autoload_arguments { VALUE module; @@ -2733,7 +2732,7 @@ rb_autoload_str(VALUE module, ID name, VALUE feature) VALUE result = rb_mutex_synchronize(autoload_mutex, autoload_synchronized, (VALUE)&arguments); if (result == Qtrue) { - const_added(module, name); + rb_const_added(module, name); } } @@ -3604,8 +3603,8 @@ set_namespace_path(VALUE named_namespace, VALUE namespace_path) RB_VM_LOCK_LEAVE(); } -static void -const_added(VALUE klass, ID const_name) +void +rb_const_added(VALUE klass, ID const_name) { if (GET_VM()->running) { VALUE name = ID2SYM(const_name); @@ -3681,10 +3680,16 @@ const_set(VALUE klass, ID id, VALUE val) } void +rb_const_set_raw(VALUE klass, ID id, VALUE val) +{ + const_set(klass, id, val); +} + +void rb_const_set(VALUE klass, ID id, VALUE val) { const_set(klass, id, val); - const_added(klass, id); + rb_const_added(klass, id); } static struct autoload_data * |
