diff options
author | Philipp Stephani <phst@google.com> | 2020-07-25 23:23:19 +0200 |
---|---|---|
committer | Philipp Stephani <phst@google.com> | 2020-07-25 23:23:19 +0200 |
commit | 9f01ce6327af886f26399924a9aadf16cdd4fd9f (patch) | |
tree | a363d2673c61ac60183457965462b05b8b867f4b /src/emacs-module.c | |
parent | 6355a3ec62f43c9b99d483982ff851d32dd78891 (diff) | |
download | emacs-9f01ce6327af886f26399924a9aadf16cdd4fd9f.tar.gz |
Make checking for liveness of global values more precise.
We can't just use a hash lookup because a global and a local reference
might refer to the same Lisp object.
* src/emacs-module.c (module_free_global_ref): More precise check for
global liveness.
* test/data/emacs-module/mod-test.c (Fmod_test_globref_invalid_free):
New test module function.
(emacs_module_init): Export it.
* test/src/emacs-module-tests.el
(module--test-assertions--globref-invalid-free): New unit test.
Diffstat (limited to 'src/emacs-module.c')
-rw-r--r-- | src/emacs-module.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/emacs-module.c b/src/emacs-module.c index 02563a4b8b5..e4e7da088d7 100644 --- a/src/emacs-module.c +++ b/src/emacs-module.c @@ -468,6 +468,14 @@ module_free_global_ref (emacs_env *env, emacs_value global_value) Lisp_Object obj = value_to_lisp (global_value); ptrdiff_t i = hash_lookup (h, obj, NULL); + if (module_assertions) + { + ptrdiff_t n = 0; + if (! module_global_reference_p (global_value, &n)) + module_abort ("Global value was not found in list of %"pD"d globals", + n); + } + if (i >= 0) { Lisp_Object value = HASH_VALUE (h, i); @@ -476,11 +484,6 @@ module_free_global_ref (emacs_env *env, emacs_value global_value) if (--ref->refcount == 0) hash_remove_from_table (h, obj); } - else if (module_assertions) - { - module_abort ("Global value was not found in list of %"pD"d globals", - h->count); - } } static enum emacs_funcall_exit |