emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

emacs-27 73a2f51: Add another test for global module references


From: Philipp Stephani
Subject: emacs-27 73a2f51: Add another test for global module references
Date: Sun, 26 Jul 2020 16:55:17 -0400 (EDT)

branch: emacs-27
commit 73a2f5104331264656ac830c848912af9389a04b
Author: Philipp Stephani <phst@google.com>
Commit: Philipp Stephani <phst@google.com>

    Add another test for global module references
    
    * test/src/emacs-module-tests.el (mod-test-globref-reordered): New
    unit test.
    
    * test/data/emacs-module/mod-test.c (Fmod_test_globref_reordered): New
    test module function.
    (emacs_module_init): Export it.
---
 test/data/emacs-module/mod-test.c | 31 +++++++++++++++++++++++++++++++
 test/src/emacs-module-tests.el    |  3 +++
 2 files changed, 34 insertions(+)

diff --git a/test/data/emacs-module/mod-test.c 
b/test/data/emacs-module/mod-test.c
index 986c20a..8d1b421 100644
--- a/test/data/emacs-module/mod-test.c
+++ b/test/data/emacs-module/mod-test.c
@@ -205,6 +205,35 @@ Fmod_test_globref_invalid_free (emacs_env *env, ptrdiff_t 
nargs,
   return env->intern (env, "nil");
 }
 
+/* Allocate and free global references in a different order.  */
+
+static emacs_value
+Fmod_test_globref_reordered (emacs_env *env, ptrdiff_t nargs,
+                                emacs_value *args, void *data)
+{
+  emacs_value booleans[2] = {
+    env->intern (env, "nil"),
+    env->intern (env, "t"),
+  };
+  emacs_value local = env->intern (env, "foo");
+  emacs_value globals[4] = {
+    env->make_global_ref (env, local),
+    env->make_global_ref (env, local),
+    env->make_global_ref (env, env->intern (env, "foo")),
+    env->make_global_ref (env, env->intern (env, "bar")),
+  };
+  emacs_value elements[4];
+  for (int i = 0; i < 4; ++i)
+    elements[i] = booleans[env->eq (env, globals[i], local)];
+  emacs_value ret = env->funcall (env, env->intern (env, "list"), 4, elements);
+  env->free_global_ref (env, globals[2]);
+  env->free_global_ref (env, globals[1]);
+  env->free_global_ref (env, globals[3]);
+  env->free_global_ref (env, globals[0]);
+  return ret;
+}
+
+
 /* Return a copy of the argument string where every 'a' is replaced
    with 'b'.  */
 static emacs_value
@@ -583,6 +612,8 @@ emacs_module_init (struct emacs_runtime *ert)
   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-globref-reordered", Fmod_test_globref_reordered, 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 e9f13ba..9120615 100644
--- a/test/src/emacs-module-tests.el
+++ b/test/src/emacs-module-tests.el
@@ -160,6 +160,9 @@ changes."
 (ert-deftest mod-test-globref-free-test ()
   (should (eq (mod-test-globref-free 1 'a "test" 'b) 'ok)))
 
+(ert-deftest mod-test-globref-reordered ()
+  (should (equal (mod-test-globref-reordered) '(t t t nil))))
+
 (ert-deftest mod-test-string-a-to-b-test ()
   (should (string= (mod-test-string-a-to-b "aaa") "bbb")))
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]