@@ -2084,6 +2084,21 @@ ruby_vm_method_state_version()
2084
2084
return ULONG2NUM (ruby_method_global_state_version );
2085
2085
}
2086
2086
2087
+ static VALUE constant_invalidation_proc = Qnil ;
2088
+ static VALUE method_invalidation_proc = Qnil ;
2089
+
2090
+ static VALUE
2091
+ on_constant_invalidation ()
2092
+ {
2093
+ return constant_invalidation_proc = rb_block_proc ();
2094
+ }
2095
+
2096
+ static VALUE
2097
+ on_method_invalidation ()
2098
+ {
2099
+ return method_invalidation_proc = rb_block_proc ();
2100
+ }
2101
+
2087
2102
void
2088
2103
Init_VM (void )
2089
2104
{
@@ -2100,6 +2115,12 @@ Init_VM(void)
2100
2115
rb_define_singleton_method (rb_cRubyVM , "constant_state_version" , ruby_vm_constant_state_version , 0 );
2101
2116
rb_define_singleton_method (rb_cRubyVM , "method_state_version" , ruby_vm_method_state_version , 0 );
2102
2117
2118
+ rb_define_singleton_method (rb_cRubyVM , "on_constant_invalidation" , on_constant_invalidation , 0 );
2119
+ rb_define_singleton_method (rb_cRubyVM , "on_method_invalidation" , on_method_invalidation , 0 );
2120
+
2121
+ rb_global_variable (& constant_invalidation_proc );
2122
+ rb_global_variable (& method_invalidation_proc );
2123
+
2103
2124
/* ::VM::FrozenCore */
2104
2125
fcore = rb_class_new (rb_cBasicObject );
2105
2126
RBASIC (fcore )-> flags = T_ICLASS ;
@@ -2308,6 +2329,10 @@ void
2308
2329
rb_inc_method_state_version ()
2309
2330
{
2310
2331
ruby_method_global_state_version ++ ;
2332
+
2333
+ if (method_invalidation_proc != Qnil ) {
2334
+ rb_proc_call (method_invalidation_proc , rb_ary_new ());
2335
+ }
2311
2336
}
2312
2337
2313
2338
uint64_t
@@ -2320,5 +2345,9 @@ void
2320
2345
rb_inc_constant_state_version ()
2321
2346
{
2322
2347
ruby_constant_global_state_version ++ ;
2348
+
2349
+ if (constant_invalidation_proc != Qnil ) {
2350
+ rb_proc_call (constant_invalidation_proc , rb_ary_new ());
2351
+ }
2323
2352
}
2324
2353
0 commit comments