emacs-module-rs
emacs-module-rs copied to clipboard
Support long-lived values that are not bound to &Env (GlobalValue)
- Module code can store values for later use, e.g. in background threads.
- Frequently-used symbols won't require repeated
interncalls into the Lisp runtime. We can haveemacs::sym::nil,emacs::sym::t. Modules will also be able to declare symbols they often use. - Error handling will not need
unsafe(even though the safety requirement is almost trivial currently).
The biggest problem with this is that free_global_ref() requires an emacs_env, thus cannot be used directly in GlobalValue::drop() (this is likely a mis-design in emacs-module (BEAM's enif_release_resource doesn't need an env, for example)). There are 2 potential ways to solve this:
- Add
fn free(self, env: &Env), and just leak on normal drops. They are supposed to be long-lived anyway. - Add a "mini-GC" by globally tracking to-be-free values, and freeing them in
Env::drop(), once in a while.
This was added in release 0.13.0, but has not been stabilized/documented yet.