diff options
| author | Philipp Stephani | 2020-07-25 23:04:05 +0200 |
|---|---|---|
| committer | Philipp Stephani | 2020-07-25 23:04:05 +0200 |
| commit | 6355a3ec62f43c9b99d483982ff851d32dd78891 (patch) | |
| tree | 2a9896b373c7e713c8ec504a464d5401e8134ab8 /test/data | |
| parent | 609cbd63c31a21ca521507695abeda1203134c99 (diff) | |
| download | emacs-6355a3ec62f43c9b99d483982ff851d32dd78891.tar.gz emacs-6355a3ec62f43c9b99d483982ff851d32dd78891.zip | |
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/data')
| -rw-r--r-- | test/data/emacs-module/mod-test.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/test/data/emacs-module/mod-test.c b/test/data/emacs-module/mod-test.c index 1e64bcd65f1..437faaee2a0 100644 --- a/test/data/emacs-module/mod-test.c +++ b/test/data/emacs-module/mod-test.c | |||
| @@ -306,6 +306,22 @@ Fmod_test_invalid_load (emacs_env *env, ptrdiff_t nargs, emacs_value *args, | |||
| 306 | return invalid_stored_value; | 306 | return invalid_stored_value; |
| 307 | } | 307 | } |
| 308 | 308 | ||
| 309 | /* The next function works in conjunction with the two previous ones. | ||
| 310 | It stows away a copy of the object created by | ||
| 311 | `Fmod_test_invalid_store' in a global reference. Module assertions | ||
| 312 | should still detect the invalid load of the local reference. */ | ||
| 313 | |||
| 314 | static emacs_value global_copy_of_invalid_stored_value; | ||
| 315 | |||
| 316 | static emacs_value | ||
| 317 | Fmod_test_invalid_store_copy (emacs_env *env, ptrdiff_t nargs, | ||
| 318 | emacs_value *args, void *data) | ||
| 319 | { | ||
| 320 | emacs_value local = Fmod_test_invalid_store (env, 0, NULL, NULL); | ||
| 321 | return global_copy_of_invalid_stored_value | ||
| 322 | = env->make_global_ref (env, local); | ||
| 323 | } | ||
| 324 | |||
| 309 | /* An invalid finalizer: Finalizers are run during garbage collection, | 325 | /* An invalid finalizer: Finalizers are run during garbage collection, |
| 310 | where Lisp code can't be executed. -module-assertions tests for | 326 | where Lisp code can't be executed. -module-assertions tests for |
| 311 | this case. */ | 327 | this case. */ |
| @@ -684,6 +700,8 @@ emacs_module_init (struct emacs_runtime *ert) | |||
| 684 | DEFUN ("mod-test-vector-fill", Fmod_test_vector_fill, 2, 2, NULL, NULL); | 700 | DEFUN ("mod-test-vector-fill", Fmod_test_vector_fill, 2, 2, NULL, NULL); |
| 685 | DEFUN ("mod-test-vector-eq", Fmod_test_vector_eq, 2, 2, NULL, NULL); | 701 | DEFUN ("mod-test-vector-eq", Fmod_test_vector_eq, 2, 2, NULL, NULL); |
| 686 | DEFUN ("mod-test-invalid-store", Fmod_test_invalid_store, 0, 0, NULL, NULL); | 702 | DEFUN ("mod-test-invalid-store", Fmod_test_invalid_store, 0, 0, NULL, NULL); |
| 703 | DEFUN ("mod-test-invalid-store-copy", Fmod_test_invalid_store_copy, 0, 0, | ||
| 704 | NULL, NULL); | ||
| 687 | DEFUN ("mod-test-invalid-load", Fmod_test_invalid_load, 0, 0, NULL, NULL); | 705 | DEFUN ("mod-test-invalid-load", Fmod_test_invalid_load, 0, 0, NULL, NULL); |
| 688 | DEFUN ("mod-test-invalid-finalizer", Fmod_test_invalid_finalizer, 0, 0, | 706 | DEFUN ("mod-test-invalid-finalizer", Fmod_test_invalid_finalizer, 0, 0, |
| 689 | NULL, NULL); | 707 | NULL, NULL); |