diff options
author | Philipp Stephani <phst@google.com> | 2020-07-25 23:04:05 +0200 |
---|---|---|
committer | Philipp Stephani <phst@google.com> | 2020-07-25 23:04:05 +0200 |
commit | 6355a3ec62f43c9b99d483982ff851d32dd78891 (patch) | |
tree | 2a9896b373c7e713c8ec504a464d5401e8134ab8 /test/src | |
parent | 609cbd63c31a21ca521507695abeda1203134c99 (diff) | |
download | emacs-6355a3ec62f43c9b99d483982ff851d32dd78891.tar.gz |
Fix subtle bug when checking liveness of module values.
We can't simply look up the Lisp object in the global reference table
because an invalid local and a valid global reference might refer to
the same object. Instead, we have to test the address of the global
reference against the stored references.
* src/emacs-module.c (module_global_reference_p): New helper function.
(value_to_lisp): Use it.
* test/data/emacs-module/mod-test.c
(Fmod_test_invalid_store_copy): New test module function.
(emacs_module_init): Export it.
* test/src/emacs-module-tests.el
(module--test-assertions--load-non-live-object-with-global-copy):
New unit test.
Diffstat (limited to 'test/src')
-rw-r--r-- | test/src/emacs-module-tests.el | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/test/src/emacs-module-tests.el b/test/src/emacs-module-tests.el index 411b4505da0..7ed9ecf84e8 100644 --- a/test/src/emacs-module-tests.el +++ b/test/src/emacs-module-tests.el @@ -272,6 +272,24 @@ must evaluate to a regular expression string." (mod-test-invalid-store) (mod-test-invalid-load))) +(ert-deftest module--test-assertions--load-non-live-object-with-global-copy () + "Check that -module-assertions verify that non-live objects aren't accessed. +This differs from `module--test-assertions-load-non-live-object' +in that it stows away a global reference. The module assertions +should nevertheless detect the invalid load." + (skip-unless (or (file-executable-p mod-test-emacs) + (and (eq system-type 'windows-nt) + (file-executable-p (concat mod-test-emacs ".exe"))))) + ;; This doesn't yet cause undefined behavior. + (should (eq (mod-test-invalid-store-copy) 123)) + (module--test-assertion (rx "Emacs value not found in " + (+ digit) " values of " + (+ digit) " environments\n") + ;; Storing and reloading a local value causes undefined behavior, + ;; which should be detected by the module assertions. + (mod-test-invalid-store-copy) + (mod-test-invalid-load))) + (ert-deftest module--test-assertions--call-emacs-from-gc () "Check that -module-assertions prevents calling Emacs functions during garbage collection." |