@thisismissem One problem: Rust extensions have the same GC interactions with Ruby as C extensions. So there is a danger of losing references (and AFAIK there's no way to do RB_GC_GUARD from Rust). Rust extension authors must understand Ruby GC behavior and carefully design their API to ensure Ruby objects are always reachable by the GC. Other issues include longjumps (calling any Ruby method can possibly raise)

2
Share
Share on Mastodon
Share on Twitter
Share on Facebook
Share on Linkedin
Aaron Patterson ✅

@thisismissem the meta frustration I have is that Rust extension authors must be equally aware of how Ruby internals work as C extension authors. Rust code only buys you safety with other Rust code and I'm worried that extension authors "feel safe" because they're writing in Rust. IOW it's giving a false sense of security

1
12mo
Tony Arcieri 🌹🦀

@tenderlove @thisismissem if I understand how RB_GC_GUARD works, you could probably build something similar in Rust using a RAII wrapper/"smart pointer" placed around the VALUE's pointer and having it perform a `core::ptr::volatile_read` in the `Drop` handler, which would ensure it lives on the stack until dropped

2
12mo
Replies