Skip to content

Commit 8aadf6e

Browse files
committed
Refactoring: simplify definition of some internal variables.
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.
1 parent bd93bcb commit 8aadf6e

File tree

2 files changed

+17
-23
lines changed

2 files changed

+17
-23
lines changed

src/emacs-module.c

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,8 @@ module_get_environment (struct emacs_runtime *ert)
349349
/* To make global refs (GC-protected global values) keep a hash that
350350
maps global Lisp objects to reference counts. */
351351

352+
static Lisp_Object Vmodule_refs_hash;
353+
352354
static emacs_value
353355
module_make_global_ref (emacs_env *env, emacs_value ref)
354356
{
@@ -760,6 +762,10 @@ module_signal_or_throw (struct emacs_env_private *env)
760762
}
761763
}
762764

765+
/* Live runtime and environment objects, for assertions. */
766+
static Lisp_Object Vmodule_runtimes;
767+
static Lisp_Object Vmodule_environments;
768+
763769
DEFUN ("module-load", Fmodule_load, Smodule_load, 1, 1, 0,
764770
doc: /* Load module FILE. */)
765771
(Lisp_Object file)
@@ -1228,31 +1234,17 @@ module_abort (const char *format, ...)
12281234
void
12291235
syms_of_module (void)
12301236
{
1231-
DEFSYM (Qmodule_refs_hash, "module-refs-hash");
1232-
DEFVAR_LISP ("module-refs-hash", Vmodule_refs_hash,
1233-
doc: /* Module global reference table. */);
1234-
1237+
staticpro (&Vmodule_refs_hash);
12351238
Vmodule_refs_hash
12361239
= make_hash_table (hashtest_eq, DEFAULT_HASH_SIZE,
12371240
DEFAULT_REHASH_SIZE, DEFAULT_REHASH_THRESHOLD,
12381241
Qnil, false);
1239-
Funintern (Qmodule_refs_hash, Qnil);
12401242

1241-
DEFSYM (Qmodule_runtimes, "module-runtimes");
1242-
DEFVAR_LISP ("module-runtimes", Vmodule_runtimes,
1243-
doc: /* List of active module runtimes. */);
1243+
staticpro (&Vmodule_runtimes);
12441244
Vmodule_runtimes = Qnil;
1245-
/* Unintern `module-runtimes' because it is only used
1246-
internally. */
1247-
Funintern (Qmodule_runtimes, Qnil);
12481245

1249-
DEFSYM (Qmodule_environments, "module-environments");
1250-
DEFVAR_LISP ("module-environments", Vmodule_environments,
1251-
doc: /* List of active module environments. */);
1246+
staticpro (&Vmodule_environments);
12521247
Vmodule_environments = Qnil;
1253-
/* Unintern `module-environments' because it is only used
1254-
internally. */
1255-
Funintern (Qmodule_environments, Qnil);
12561248

12571249
DEFSYM (Qmodule_load_failed, "module-load-failed");
12581250
Fput (Qmodule_load_failed, Qerror_conditions,
@@ -1291,10 +1283,6 @@ syms_of_module (void)
12911283
Fput (Qinvalid_arity, Qerror_message,
12921284
build_pure_c_string ("Invalid function arity"));
12931285

1294-
/* Unintern `module-refs-hash' because it is internal-only and Lisp
1295-
code or modules should not access it. */
1296-
Funintern (Qmodule_refs_hash, Qnil);
1297-
12981286
DEFSYM (Qmodule_function_p, "module-function-p");
12991287

13001288
defsubr (&Smodule_load);

src/eval.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,6 +1429,8 @@ internal_condition_case_n (Lisp_Object (*bfun) (ptrdiff_t, Lisp_Object *),
14291429
}
14301430
}
14311431

1432+
static Lisp_Object Qcatch_all_memory_full;
1433+
14321434
/* Like a combination of internal_condition_case_1 and internal_catch.
14331435
Catches all signals and throws. Never exits nonlocally; returns
14341436
Qcatch_all_memory_full if no handler could be allocated. */
@@ -4188,8 +4190,12 @@ alist of active lexical bindings. */);
41884190
staticpro (&Vsignaling_function);
41894191
Vsignaling_function = Qnil;
41904192

4191-
DEFSYM (Qcatch_all_memory_full, "catch-all-memory-full");
4192-
Funintern (Qcatch_all_memory_full, Qnil);
4193+
staticpro (&Qcatch_all_memory_full);
4194+
/* Make sure Qcatch_all_memory_full is a unique object. We could
4195+
also use something like Fcons (Qnil, Qnil), but json.c treats any
4196+
cons cell as error data, so use an uninterned symbol instead. */
4197+
Qcatch_all_memory_full
4198+
= Fmake_symbol (build_pure_c_string ("catch-all-memory-full"));
41934199

41944200
defsubr (&Sor);
41954201
defsubr (&Sand);

0 commit comments

Comments
 (0)