emacs-module-rs icon indicating copy to clipboard operation
emacs-module-rs copied to clipboard

Support long-lived values that are not bound to &Env (GlobalValue)

Open ubolonton opened this issue 5 years ago • 1 comments

  • Module code can store values for later use, e.g. in background threads.
  • Frequently-used symbols won't require repeated intern calls into the Lisp runtime. We can have emacs::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.

ubolonton avatar Apr 22 '19 12:04 ubolonton

This was added in release 0.13.0, but has not been stabilized/documented yet.

ubolonton avatar Dec 27 '20 10:12 ubolonton