diff options
| author | Philipp Stephani | 2019-04-19 18:38:19 +0200 |
|---|---|---|
| committer | Philipp Stephani | 2019-04-19 18:41:15 +0200 |
| commit | 8aadf6e415b7801cb9fa4c5670b1750da207cf87 (patch) | |
| tree | be5b2ff82b5ffa0ef44684a76a9ad1676f13d3ed | |
| parent | bd93bcb078f29e9b5fa127d6cef0bdeeab5c2285 (diff) | |
| download | emacs-8aadf6e415b7801cb9fa4c5670b1750da207cf87.tar.gz emacs-8aadf6e415b7801cb9fa4c5670b1750da207cf87.zip | |
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.
| -rw-r--r-- | src/emacs-module.c | 30 | ||||
| -rw-r--r-- | src/eval.c | 10 |
2 files changed, 17 insertions, 23 deletions
diff --git a/src/emacs-module.c b/src/emacs-module.c index 393a4354b88..ad32d3a91f1 100644 --- a/src/emacs-module.c +++ b/src/emacs-module.c | |||
| @@ -349,6 +349,8 @@ module_get_environment (struct emacs_runtime *ert) | |||
| 349 | /* To make global refs (GC-protected global values) keep a hash that | 349 | /* To make global refs (GC-protected global values) keep a hash that |
| 350 | maps global Lisp objects to reference counts. */ | 350 | maps global Lisp objects to reference counts. */ |
| 351 | 351 | ||
| 352 | static Lisp_Object Vmodule_refs_hash; | ||
| 353 | |||
| 352 | static emacs_value | 354 | static emacs_value |
| 353 | module_make_global_ref (emacs_env *env, emacs_value ref) | 355 | module_make_global_ref (emacs_env *env, emacs_value ref) |
| 354 | { | 356 | { |
| @@ -760,6 +762,10 @@ module_signal_or_throw (struct emacs_env_private *env) | |||
| 760 | } | 762 | } |
| 761 | } | 763 | } |
| 762 | 764 | ||
| 765 | /* Live runtime and environment objects, for assertions. */ | ||
| 766 | static Lisp_Object Vmodule_runtimes; | ||
| 767 | static Lisp_Object Vmodule_environments; | ||
| 768 | |||
| 763 | DEFUN ("module-load", Fmodule_load, Smodule_load, 1, 1, 0, | 769 | DEFUN ("module-load", Fmodule_load, Smodule_load, 1, 1, 0, |
| 764 | doc: /* Load module FILE. */) | 770 | doc: /* Load module FILE. */) |
| 765 | (Lisp_Object file) | 771 | (Lisp_Object file) |
| @@ -1228,31 +1234,17 @@ module_abort (const char *format, ...) | |||
| 1228 | void | 1234 | void |
| 1229 | syms_of_module (void) | 1235 | syms_of_module (void) |
| 1230 | { | 1236 | { |
| 1231 | DEFSYM (Qmodule_refs_hash, "module-refs-hash"); | 1237 | staticpro (&Vmodule_refs_hash); |
| 1232 | DEFVAR_LISP ("module-refs-hash", Vmodule_refs_hash, | ||
| 1233 | doc: /* Module global reference table. */); | ||
| 1234 | |||
| 1235 | Vmodule_refs_hash | 1238 | Vmodule_refs_hash |
| 1236 | = make_hash_table (hashtest_eq, DEFAULT_HASH_SIZE, | 1239 | = make_hash_table (hashtest_eq, DEFAULT_HASH_SIZE, |
| 1237 | DEFAULT_REHASH_SIZE, DEFAULT_REHASH_THRESHOLD, | 1240 | DEFAULT_REHASH_SIZE, DEFAULT_REHASH_THRESHOLD, |
| 1238 | Qnil, false); | 1241 | Qnil, false); |
| 1239 | Funintern (Qmodule_refs_hash, Qnil); | ||
| 1240 | 1242 | ||
| 1241 | DEFSYM (Qmodule_runtimes, "module-runtimes"); | 1243 | staticpro (&Vmodule_runtimes); |
| 1242 | DEFVAR_LISP ("module-runtimes", Vmodule_runtimes, | ||
| 1243 | doc: /* List of active module runtimes. */); | ||
| 1244 | Vmodule_runtimes = Qnil; | 1244 | Vmodule_runtimes = Qnil; |
| 1245 | /* Unintern `module-runtimes' because it is only used | ||
| 1246 | internally. */ | ||
| 1247 | Funintern (Qmodule_runtimes, Qnil); | ||
| 1248 | 1245 | ||
| 1249 | DEFSYM (Qmodule_environments, "module-environments"); | 1246 | staticpro (&Vmodule_environments); |
| 1250 | DEFVAR_LISP ("module-environments", Vmodule_environments, | ||
| 1251 | doc: /* List of active module environments. */); | ||
| 1252 | Vmodule_environments = Qnil; | 1247 | Vmodule_environments = Qnil; |
| 1253 | /* Unintern `module-environments' because it is only used | ||
| 1254 | internally. */ | ||
| 1255 | Funintern (Qmodule_environments, Qnil); | ||
| 1256 | 1248 | ||
| 1257 | DEFSYM (Qmodule_load_failed, "module-load-failed"); | 1249 | DEFSYM (Qmodule_load_failed, "module-load-failed"); |
| 1258 | Fput (Qmodule_load_failed, Qerror_conditions, | 1250 | Fput (Qmodule_load_failed, Qerror_conditions, |
| @@ -1291,10 +1283,6 @@ syms_of_module (void) | |||
| 1291 | Fput (Qinvalid_arity, Qerror_message, | 1283 | Fput (Qinvalid_arity, Qerror_message, |
| 1292 | build_pure_c_string ("Invalid function arity")); | 1284 | build_pure_c_string ("Invalid function arity")); |
| 1293 | 1285 | ||
| 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 | |||
| 1298 | DEFSYM (Qmodule_function_p, "module-function-p"); | 1286 | DEFSYM (Qmodule_function_p, "module-function-p"); |
| 1299 | 1287 | ||
| 1300 | defsubr (&Smodule_load); | 1288 | defsubr (&Smodule_load); |
diff --git a/src/eval.c b/src/eval.c index 23fd0efd54a..a2b95172d87 100644 --- a/src/eval.c +++ b/src/eval.c | |||
| @@ -1429,6 +1429,8 @@ internal_condition_case_n (Lisp_Object (*bfun) (ptrdiff_t, Lisp_Object *), | |||
| 1429 | } | 1429 | } |
| 1430 | } | 1430 | } |
| 1431 | 1431 | ||
| 1432 | static Lisp_Object Qcatch_all_memory_full; | ||
| 1433 | |||
| 1432 | /* Like a combination of internal_condition_case_1 and internal_catch. | 1434 | /* Like a combination of internal_condition_case_1 and internal_catch. |
| 1433 | Catches all signals and throws. Never exits nonlocally; returns | 1435 | Catches all signals and throws. Never exits nonlocally; returns |
| 1434 | Qcatch_all_memory_full if no handler could be allocated. */ | 1436 | Qcatch_all_memory_full if no handler could be allocated. */ |
| @@ -4188,8 +4190,12 @@ alist of active lexical bindings. */); | |||
| 4188 | staticpro (&Vsignaling_function); | 4190 | staticpro (&Vsignaling_function); |
| 4189 | Vsignaling_function = Qnil; | 4191 | Vsignaling_function = Qnil; |
| 4190 | 4192 | ||
| 4191 | DEFSYM (Qcatch_all_memory_full, "catch-all-memory-full"); | 4193 | staticpro (&Qcatch_all_memory_full); |
| 4192 | Funintern (Qcatch_all_memory_full, Qnil); | 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")); | ||
| 4193 | 4199 | ||
| 4194 | defsubr (&Sor); | 4200 | defsubr (&Sor); |
| 4195 | defsubr (&Sand); | 4201 | defsubr (&Sand); |