[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
emacs-27 3838aeb 2/2: Backport: add another test case for module asserti
From: |
Philipp Stephani |
Subject: |
emacs-27 3838aeb 2/2: Backport: add another test case for module assertions. |
Date: |
Sun, 26 Jul 2020 08:36:09 -0400 (EDT) |
branch: emacs-27
commit 3838aeb7397ce80134c70fd49f7e9e5ef7aff3e5
Author: Philipp Stephani <phst@google.com>
Commit: Philipp Stephani <phst@google.com>
Backport: add another test case for module assertions.
This backports commit 9f01ce6327 from master. Since the bug isn’t
present on emacs-27, just backport the new test case.
* 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.
---
test/data/emacs-module/mod-test.c | 14 ++++++++++++++
test/src/emacs-module-tests.el | 11 +++++++++++
2 files changed, 25 insertions(+)
diff --git a/test/data/emacs-module/mod-test.c
b/test/data/emacs-module/mod-test.c
index f6c1c7c..986c20a 100644
--- a/test/data/emacs-module/mod-test.c
+++ b/test/data/emacs-module/mod-test.c
@@ -191,7 +191,19 @@ Fmod_test_globref_free (emacs_env *env, ptrdiff_t nargs,
emacs_value args[],
return env->intern (env, "ok");
}
+/* Treat a local reference as global and free it. Module assertions
+ should detect this case even if a global reference representing the
+ same object also exists. */
+static emacs_value
+Fmod_test_globref_invalid_free (emacs_env *env, ptrdiff_t nargs,
+ emacs_value *args, void *data)
+{
+ emacs_value local = env->make_integer (env, 9876);
+ env->make_global_ref (env, local);
+ env->free_global_ref (env, local); /* Not allowed. */
+ return env->intern (env, "nil");
+}
/* Return a copy of the argument string where every 'a' is replaced
with 'b'. */
@@ -569,6 +581,8 @@ emacs_module_init (struct emacs_runtime *ert)
1, 1, NULL, NULL);
DEFUN ("mod-test-globref-make", Fmod_test_globref_make, 0, 0, NULL, NULL);
DEFUN ("mod-test-globref-free", Fmod_test_globref_free, 4, 4, NULL, NULL);
+ DEFUN ("mod-test-globref-invalid-free", Fmod_test_globref_invalid_free, 0, 0,
+ NULL, NULL);
DEFUN ("mod-test-string-a-to-b", Fmod_test_string_a_to_b, 1, 1, NULL, NULL);
DEFUN ("mod-test-userptr-make", Fmod_test_userptr_make, 1, 1, NULL, NULL);
DEFUN ("mod-test-userptr-get", Fmod_test_userptr_get, 1, 1, NULL, NULL);
diff --git a/test/src/emacs-module-tests.el b/test/src/emacs-module-tests.el
index de707a4..e9f13ba 100644
--- a/test/src/emacs-module-tests.el
+++ b/test/src/emacs-module-tests.el
@@ -299,6 +299,17 @@ during garbage collection."
(mod-test-invalid-finalizer)
(garbage-collect)))
+(ert-deftest module--test-assertions--globref-invalid-free ()
+ "Check that -module-assertions detects invalid freeing of a
+local reference."
+ (skip-unless (or (file-executable-p mod-test-emacs)
+ (and (eq system-type 'windows-nt)
+ (file-executable-p (concat mod-test-emacs ".exe")))))
+ (module--test-assertion
+ (rx "Global value was not found in list of " (+ digit) " globals")
+ (mod-test-globref-invalid-free)
+ (garbage-collect)))
+
(ert-deftest module/describe-function-1 ()
"Check that Bug#30163 is fixed."
(with-temp-buffer