]> git.eshelyaron.com Git - emacs.git/commitdiff
Refactoring: simplify definition of some internal variables.
authorPhilipp Stephani <phst@google.com>
Fri, 19 Apr 2019 16:38:19 +0000 (18:38 +0200)
committerPhilipp Stephani <phst@google.com>
Fri, 19 Apr 2019 16:41:15 +0000 (18:41 +0200)
In some cases, we never specbind internal objects, so they don't have
to be symbols.  Rather than using DEFSYM/DEFVAR and then uninterning
the symbols, use plain static variables.  Call staticpro for all of
them, to protect them from the garbage collector.

* src/eval.c (syms_of_eval): Use a static variable for
Qcatch_all_memory_full.

* src/emacs-module.c (syms_of_module): Use static variables for
Vmodule_refs_hash, Vmodule_runtimes, and Vmodule_environments.

src/emacs-module.c
src/eval.c

index 393a4354b88d39cbc17beb61686edcd728065722..ad32d3a91f1c72642dc43d03af9cebb99e5f5bd3 100644 (file)
@@ -349,6 +349,8 @@ module_get_environment (struct emacs_runtime *ert)
 /* To make global refs (GC-protected global values) keep a hash that
    maps global Lisp objects to reference counts.  */
 
+static Lisp_Object Vmodule_refs_hash;
+
 static emacs_value
 module_make_global_ref (emacs_env *env, emacs_value ref)
 {
@@ -760,6 +762,10 @@ module_signal_or_throw (struct emacs_env_private *env)
     }
 }
 
+/* Live runtime and environment objects, for assertions.  */
+static Lisp_Object Vmodule_runtimes;
+static Lisp_Object Vmodule_environments;
+
 DEFUN ("module-load", Fmodule_load, Smodule_load, 1, 1, 0,
        doc: /* Load module FILE.  */)
   (Lisp_Object file)
@@ -1228,31 +1234,17 @@ module_abort (const char *format, ...)
 void
 syms_of_module (void)
 {
-  DEFSYM (Qmodule_refs_hash, "module-refs-hash");
-  DEFVAR_LISP ("module-refs-hash", Vmodule_refs_hash,
-              doc: /* Module global reference table.  */);
-
+  staticpro (&Vmodule_refs_hash);
   Vmodule_refs_hash
     = make_hash_table (hashtest_eq, DEFAULT_HASH_SIZE,
                       DEFAULT_REHASH_SIZE, DEFAULT_REHASH_THRESHOLD,
                       Qnil, false);
-  Funintern (Qmodule_refs_hash, Qnil);
 
-  DEFSYM (Qmodule_runtimes, "module-runtimes");
-  DEFVAR_LISP ("module-runtimes", Vmodule_runtimes,
-               doc: /* List of active module runtimes.  */);
+  staticpro (&Vmodule_runtimes);
   Vmodule_runtimes = Qnil;
-  /* Unintern `module-runtimes' because it is only used
-     internally.  */
-  Funintern (Qmodule_runtimes, Qnil);
 
-  DEFSYM (Qmodule_environments, "module-environments");
-  DEFVAR_LISP ("module-environments", Vmodule_environments,
-               doc: /* List of active module environments.  */);
+  staticpro (&Vmodule_environments);
   Vmodule_environments = Qnil;
-  /* Unintern `module-environments' because it is only used
-     internally.  */
-  Funintern (Qmodule_environments, Qnil);
 
   DEFSYM (Qmodule_load_failed, "module-load-failed");
   Fput (Qmodule_load_failed, Qerror_conditions,
@@ -1291,10 +1283,6 @@ syms_of_module (void)
   Fput (Qinvalid_arity, Qerror_message,
         build_pure_c_string ("Invalid function arity"));
 
-  /* Unintern `module-refs-hash' because it is internal-only and Lisp
-     code or modules should not access it.  */
-  Funintern (Qmodule_refs_hash, Qnil);
-
   DEFSYM (Qmodule_function_p, "module-function-p");
 
   defsubr (&Smodule_load);
index 23fd0efd54ab05ec6ff0116fba906f78c67132af..a2b95172d8716136b4dd9a537bda74d8f8d40ebf 100644 (file)
@@ -1429,6 +1429,8 @@ internal_condition_case_n (Lisp_Object (*bfun) (ptrdiff_t, Lisp_Object *),
     }
 }
 
+static Lisp_Object Qcatch_all_memory_full;
+
 /* Like a combination of internal_condition_case_1 and internal_catch.
    Catches all signals and throws.  Never exits nonlocally; returns
    Qcatch_all_memory_full if no handler could be allocated.  */
@@ -4188,8 +4190,12 @@ alist of active lexical bindings.  */);
   staticpro (&Vsignaling_function);
   Vsignaling_function = Qnil;
 
-  DEFSYM (Qcatch_all_memory_full, "catch-all-memory-full");
-  Funintern (Qcatch_all_memory_full, Qnil);
+  staticpro (&Qcatch_all_memory_full);
+  /* Make sure Qcatch_all_memory_full is a unique object.  We could
+     also use something like Fcons (Qnil, Qnil), but json.c treats any
+     cons cell as error data, so use an uninterned symbol instead.  */
+  Qcatch_all_memory_full
+    = Fmake_symbol (build_pure_c_string ("catch-all-memory-full"));
 
   defsubr (&Sor);
   defsubr (&Sand);