Actions
Feature #19627
closedEnsure the VM is alive before accessing objspace in C API
Feature #19627:
Ensure the VM is alive before accessing objspace in C API
Status:
Closed
Assignee:
-
Target version:
-
Description
Currently, there is no supported way to check if the Ruby VM has been shut down. There are a couple of workarounds that I know of:
- Setup an exit handler which sets a global variable (like I did in https://github.com/tmm1/stackprof/pull/200).
- In Ruby 2.4 thru 3.2, you could check the hidden
ruby_vm_global_ptr != NULL.
For my use, in rb-sys there is a feature to automatically report Rust memory allocations via rb_gc_adjust_memory_usage. However, there is a bug that can cause processes to deadlock and/or segfault if a Rust destructor gets called after the VM quits (which can happen in Rust background threads). Currently, I don’t think there’s a way to safely make this feature work. (https://github.com/oxidize-rb/rb-sys/pull/205)
It would be nice to have an official way to know if the Ruby VM is available, basically just a ruby_current_vm_ptr != null. Thoughts?
Actions