aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPhilipp Stephani2017-06-04 19:19:30 +0200
committerPhilipp Stephani2017-06-04 19:50:51 +0200
commit549706241e5ce6fe7f1131d7f132a19bdb1abdd9 (patch)
treeb7911a22dd11e55a8f5845d5686149f7ef94047d /src
parentfb3a9fd3185e081b3442d37ef3c27543d75849ac (diff)
downloademacs-549706241e5ce6fe7f1131d7f132a19bdb1abdd9.tar.gz
emacs-549706241e5ce6fe7f1131d7f132a19bdb1abdd9.zip
Add a couple more assertions to the module code
These can help module authors debug crashes. * emacs-module.c (module_non_local_exit_check) (module_non_local_exit_clear, module_non_local_exit_get) (module_non_local_exit_signal, module_non_local_exit_throw) (module_copy_string_contents, module_make_string) (funcall_module, initialize_environment): Add assertions
Diffstat (limited to 'src')
-rw-r--r--src/emacs-module.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/emacs-module.c b/src/emacs-module.c
index 1cd4eb2ddd8..d4047d67a36 100644
--- a/src/emacs-module.c
+++ b/src/emacs-module.c
@@ -307,6 +307,7 @@ module_free_global_ref (emacs_env *env, emacs_value ref)
307static enum emacs_funcall_exit 307static enum emacs_funcall_exit
308module_non_local_exit_check (emacs_env *env) 308module_non_local_exit_check (emacs_env *env)
309{ 309{
310 eassert (env != NULL);
310 check_main_thread (); 311 check_main_thread ();
311 return env->private_members->pending_non_local_exit; 312 return env->private_members->pending_non_local_exit;
312} 313}
@@ -314,6 +315,7 @@ module_non_local_exit_check (emacs_env *env)
314static void 315static void
315module_non_local_exit_clear (emacs_env *env) 316module_non_local_exit_clear (emacs_env *env)
316{ 317{
318 eassert (env != NULL);
317 check_main_thread (); 319 check_main_thread ();
318 env->private_members->pending_non_local_exit = emacs_funcall_exit_return; 320 env->private_members->pending_non_local_exit = emacs_funcall_exit_return;
319} 321}
@@ -321,6 +323,9 @@ module_non_local_exit_clear (emacs_env *env)
321static enum emacs_funcall_exit 323static enum emacs_funcall_exit
322module_non_local_exit_get (emacs_env *env, emacs_value *sym, emacs_value *data) 324module_non_local_exit_get (emacs_env *env, emacs_value *sym, emacs_value *data)
323{ 325{
326 eassert (env != NULL);
327 eassert (sym != NULL);
328 eassert (data != NULL);
324 check_main_thread (); 329 check_main_thread ();
325 struct emacs_env_private *p = env->private_members; 330 struct emacs_env_private *p = env->private_members;
326 if (p->pending_non_local_exit != emacs_funcall_exit_return) 331 if (p->pending_non_local_exit != emacs_funcall_exit_return)
@@ -336,6 +341,7 @@ module_non_local_exit_get (emacs_env *env, emacs_value *sym, emacs_value *data)
336static void 341static void
337module_non_local_exit_signal (emacs_env *env, emacs_value sym, emacs_value data) 342module_non_local_exit_signal (emacs_env *env, emacs_value sym, emacs_value data)
338{ 343{
344 eassert (env != NULL);
339 check_main_thread (); 345 check_main_thread ();
340 if (module_non_local_exit_check (env) == emacs_funcall_exit_return) 346 if (module_non_local_exit_check (env) == emacs_funcall_exit_return)
341 module_non_local_exit_signal_1 (env, value_to_lisp (sym), 347 module_non_local_exit_signal_1 (env, value_to_lisp (sym),
@@ -345,6 +351,7 @@ module_non_local_exit_signal (emacs_env *env, emacs_value sym, emacs_value data)
345static void 351static void
346module_non_local_exit_throw (emacs_env *env, emacs_value tag, emacs_value value) 352module_non_local_exit_throw (emacs_env *env, emacs_value tag, emacs_value value)
347{ 353{
354 eassert (env != NULL);
348 check_main_thread (); 355 check_main_thread ();
349 if (module_non_local_exit_check (env) == emacs_funcall_exit_return) 356 if (module_non_local_exit_check (env) == emacs_funcall_exit_return)
350 module_non_local_exit_throw_1 (env, value_to_lisp (tag), 357 module_non_local_exit_throw_1 (env, value_to_lisp (tag),
@@ -483,6 +490,7 @@ module_copy_string_contents (emacs_env *env, emacs_value value, char *buffer,
483 Lisp_Object lisp_str_utf8 = ENCODE_UTF_8 (lisp_str); 490 Lisp_Object lisp_str_utf8 = ENCODE_UTF_8 (lisp_str);
484 ptrdiff_t raw_size = SBYTES (lisp_str_utf8); 491 ptrdiff_t raw_size = SBYTES (lisp_str_utf8);
485 ptrdiff_t required_buf_size = raw_size + 1; 492 ptrdiff_t required_buf_size = raw_size + 1;
493 eassert (required_buf_size > 0);
486 494
487 eassert (length != NULL); 495 eassert (length != NULL);
488 496
@@ -501,6 +509,7 @@ module_copy_string_contents (emacs_env *env, emacs_value value, char *buffer,
501 } 509 }
502 510
503 *length = required_buf_size; 511 *length = required_buf_size;
512 eassert (SREF (lisp_str_utf8, raw_size) == '\0');
504 memcpy (buffer, SDATA (lisp_str_utf8), raw_size + 1); 513 memcpy (buffer, SDATA (lisp_str_utf8), raw_size + 1);
505 514
506 return true; 515 return true;
@@ -510,6 +519,7 @@ static emacs_value
510module_make_string (emacs_env *env, const char *str, ptrdiff_t length) 519module_make_string (emacs_env *env, const char *str, ptrdiff_t length)
511{ 520{
512 MODULE_FUNCTION_BEGIN (module_nil); 521 MODULE_FUNCTION_BEGIN (module_nil);
522 eassert (str != NULL);
513 AUTO_STRING_WITH_LEN (lstr, str, length); 523 AUTO_STRING_WITH_LEN (lstr, str, length);
514 return lisp_to_value (code_convert_string_norecord (lstr, Qutf_8, false)); 524 return lisp_to_value (code_convert_string_norecord (lstr, Qutf_8, false));
515} 525}
@@ -701,7 +711,11 @@ Lisp_Object
701module_function_arity (const struct Lisp_Module_Function *const function) 711module_function_arity (const struct Lisp_Module_Function *const function)
702{ 712{
703 ptrdiff_t minargs = function->min_arity; 713 ptrdiff_t minargs = function->min_arity;
714 eassert (minargs >= 0);
715 eassert (minargs <= MOST_POSITIVE_FIXNUM);
704 ptrdiff_t maxargs = function->max_arity; 716 ptrdiff_t maxargs = function->max_arity;
717 eassert (maxargs >= minargs || maxargs == MANY);
718 eassert (maxargs <= MOST_POSITIVE_FIXNUM);
705 return Fcons (make_number (minargs), 719 return Fcons (make_number (minargs),
706 maxargs == MANY ? Qmany : make_number (maxargs)); 720 maxargs == MANY ? Qmany : make_number (maxargs));
707} 721}
@@ -906,6 +920,8 @@ initialize_environment (emacs_env *env, struct emacs_env_private *priv)
906static void 920static void
907finalize_environment (emacs_env *env, struct emacs_env_private *priv) 921finalize_environment (emacs_env *env, struct emacs_env_private *priv)
908{ 922{
923 eassert (env->private_members == priv);
924 eassert (XSAVE_POINTER (XCAR (Vmodule_environments), 0) == env);
909 Vmodule_environments = XCDR (Vmodule_environments); 925 Vmodule_environments = XCDR (Vmodule_environments);
910} 926}
911 927