aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPhilipp Stephani2019-01-19 23:40:35 +0100
committerPhilipp Stephani2019-04-19 22:33:40 +0200
commitba2e3a8abb5657e350d7653dd7580e1ebe84c7ab (patch)
tree8c4a291084b94dcc0e7e259b03bc81b86727a932 /src
parenta59c41ee81568a5e56d7a6545be6d18b37ef2d60 (diff)
downloademacs-ba2e3a8abb5657e350d7653dd7580e1ebe84c7ab.tar.gz
emacs-ba2e3a8abb5657e350d7653dd7580e1ebe84c7ab.zip
Refactoring: Reduce code duplication
* src/emacs-module.c (value_storage_contains_p): New function. (module_free_global_ref, value_to_lisp): Use it.
Diffstat (limited to 'src')
-rw-r--r--src/emacs-module.c58
1 files changed, 28 insertions, 30 deletions
diff --git a/src/emacs-module.c b/src/emacs-module.c
index ad32d3a91f1..5467704df7f 100644
--- a/src/emacs-module.c
+++ b/src/emacs-module.c
@@ -209,6 +209,8 @@ static void module_non_local_exit_throw_1 (emacs_env *,
209 Lisp_Object, Lisp_Object); 209 Lisp_Object, Lisp_Object);
210static void module_out_of_memory (emacs_env *); 210static void module_out_of_memory (emacs_env *);
211static void module_reset_handlerlist (struct handler **); 211static void module_reset_handlerlist (struct handler **);
212static bool value_storage_contains_p (const struct emacs_value_storage *,
213 emacs_value, ptrdiff_t *);
212 214
213static bool module_assertions = false; 215static bool module_assertions = false;
214 216
@@ -403,16 +405,8 @@ module_free_global_ref (emacs_env *env, emacs_value ref)
403 if (module_assertions) 405 if (module_assertions)
404 { 406 {
405 ptrdiff_t count = 0; 407 ptrdiff_t count = 0;
406 for (struct emacs_value_frame *frame = &global_storage.initial; 408 if (value_storage_contains_p (&global_storage, ref, &count))
407 frame != NULL; frame = frame->next) 409 return;
408 {
409 for (int i = 0; i < frame->offset; ++i)
410 {
411 if (&frame->objects[i] == ref)
412 return;
413 ++count;
414 }
415 }
416 module_abort ("Global value was not found in list of %"pD"d globals", 410 module_abort ("Global value was not found in list of %"pD"d globals",
417 count); 411 count);
418 } 412 }
@@ -978,29 +972,13 @@ value_to_lisp (emacs_value v)
978 if (&priv->non_local_exit_symbol == v 972 if (&priv->non_local_exit_symbol == v
979 || &priv->non_local_exit_data == v) 973 || &priv->non_local_exit_data == v)
980 goto ok; 974 goto ok;
981 for (struct emacs_value_frame *frame = &priv->storage.initial; 975 if (value_storage_contains_p (&priv->storage, v, &num_values))
982 frame != NULL; frame = frame->next) 976 goto ok;
983 {
984 for (int i = 0; i < frame->offset; ++i)
985 {
986 if (&frame->objects[i] == v)
987 goto ok;
988 ++num_values;
989 }
990 }
991 ++num_environments; 977 ++num_environments;
992 } 978 }
993 /* Also check global values. */ 979 /* Also check global values. */
994 for (struct emacs_value_frame *frame = &global_storage.initial; 980 if (value_storage_contains_p (&global_storage, v, &num_values))
995 frame != NULL; frame = frame->next) 981 goto ok;
996 {
997 for (int i = 0; i < frame->offset; ++i)
998 {
999 if (&frame->objects[i] == v)
1000 goto ok;
1001 ++num_values;
1002 }
1003 }
1004 module_abort (("Emacs value not found in %"pD"d values " 982 module_abort (("Emacs value not found in %"pD"d values "
1005 "of %"pD"d environments"), 983 "of %"pD"d environments"),
1006 num_values, num_environments); 984 num_values, num_environments);
@@ -1215,6 +1193,26 @@ init_module_assertions (bool enable)
1215 initialize_storage (&global_storage); 1193 initialize_storage (&global_storage);
1216} 1194}
1217 1195
1196/* Return whether STORAGE contains VALUE. Used to check module
1197 assertions. Increment *COUNT by the number of values searched. */
1198
1199static bool
1200value_storage_contains_p (const struct emacs_value_storage *storage,
1201 emacs_value value, ptrdiff_t *count)
1202{
1203 for (const struct emacs_value_frame *frame = &storage->initial; frame != NULL;
1204 frame = frame->next)
1205 {
1206 for (int i = 0; i < frame->offset; ++i)
1207 {
1208 if (&frame->objects[i] == value)
1209 return true;
1210 ++count;
1211 }
1212 }
1213 return false;
1214}
1215
1218static AVOID ATTRIBUTE_FORMAT_PRINTF (1, 2) 1216static AVOID ATTRIBUTE_FORMAT_PRINTF (1, 2)
1219module_abort (const char *format, ...) 1217module_abort (const char *format, ...)
1220{ 1218{