diff options
| author | Paul Eggert | 2015-11-21 10:38:19 -0800 |
|---|---|---|
| committer | Paul Eggert | 2015-11-21 10:44:04 -0800 |
| commit | 8afaa1321f8088bfb877fe4b6676e8517adb0bb7 (patch) | |
| tree | 7e865f4b42fc44ba38abf7d0188db0aa05096fbd /src/emacs-module.c | |
| parent | d696d62fea48096680d6d511a71c4df56d00a51f (diff) | |
| download | emacs-8afaa1321f8088bfb877fe4b6676e8517adb0bb7.tar.gz emacs-8afaa1321f8088bfb877fe4b6676e8517adb0bb7.zip | |
Add a few safety checks when ENABLE_CHECKING
This was motivated by the recent addition of module code,
which added some ENABLE_CHECKING-enabled checks that are
useful elsewhere too.
* src/alloc.c (compact_font_cache_entry):
* src/fns.c (sweep_weak_table):
* src/lread.c (oblookup):
Use gc_asize rather than doing it by hand.
* src/emacs-module.c (module_make_global_ref)
(module_free_global_ref, module_vec_size):
Omit assertions that lisp.h now checks.
* src/lisp.h (XFASTINT, ASIZE): In functional implementations,
check that the result is nonnegative. Use eassume, as this
info can help a bit when optimizing production code.
(XSYMBOL) [!USE_LSB_TAG]: Assert that argument is a symbol,
to be consistent with the USE_LSB_TAG case.
(gc_asize): New function, when ASIZE is needed in the gc.
(gc_aset): Use it.
(HASH_TABLE_P): Move definition up, so that it can be used ...
(XHASH_TABLE): ... here, to assert that the arg is a hash table.
Diffstat (limited to 'src/emacs-module.c')
| -rw-r--r-- | src/emacs-module.c | 12 |
1 files changed, 2 insertions, 10 deletions
diff --git a/src/emacs-module.c b/src/emacs-module.c index 011cc7be914..c8a0d89492a 100644 --- a/src/emacs-module.c +++ b/src/emacs-module.c | |||
| @@ -257,7 +257,6 @@ module_make_global_ref (emacs_env *env, emacs_value ref) | |||
| 257 | check_main_thread (); | 257 | check_main_thread (); |
| 258 | eassert (module_non_local_exit_check (env) == emacs_funcall_exit_return); | 258 | eassert (module_non_local_exit_check (env) == emacs_funcall_exit_return); |
| 259 | MODULE_HANDLE_SIGNALS; | 259 | MODULE_HANDLE_SIGNALS; |
| 260 | eassert (HASH_TABLE_P (Vmodule_refs_hash)); | ||
| 261 | struct Lisp_Hash_Table *h = XHASH_TABLE (Vmodule_refs_hash); | 260 | struct Lisp_Hash_Table *h = XHASH_TABLE (Vmodule_refs_hash); |
| 262 | Lisp_Object new_obj = value_to_lisp (ref); | 261 | Lisp_Object new_obj = value_to_lisp (ref); |
| 263 | EMACS_UINT hashcode; | 262 | EMACS_UINT hashcode; |
| @@ -266,7 +265,6 @@ module_make_global_ref (emacs_env *env, emacs_value ref) | |||
| 266 | if (i >= 0) | 265 | if (i >= 0) |
| 267 | { | 266 | { |
| 268 | Lisp_Object value = HASH_VALUE (h, i); | 267 | Lisp_Object value = HASH_VALUE (h, i); |
| 269 | eassert (NATNUMP (value)); | ||
| 270 | EMACS_INT refcount = XFASTINT (value) + 1; | 268 | EMACS_INT refcount = XFASTINT (value) + 1; |
| 271 | if (refcount > MOST_POSITIVE_FIXNUM) | 269 | if (refcount > MOST_POSITIVE_FIXNUM) |
| 272 | { | 270 | { |
| @@ -293,7 +291,6 @@ module_free_global_ref (emacs_env *env, emacs_value ref) | |||
| 293 | /* FIXME: Wait a minute. Shouldn't this function report an error if | 291 | /* FIXME: Wait a minute. Shouldn't this function report an error if |
| 294 | the hash lookup fails? */ | 292 | the hash lookup fails? */ |
| 295 | MODULE_HANDLE_SIGNALS_VOID; | 293 | MODULE_HANDLE_SIGNALS_VOID; |
| 296 | eassert (HASH_TABLE_P (Vmodule_refs_hash)); | ||
| 297 | struct Lisp_Hash_Table *h = XHASH_TABLE (Vmodule_refs_hash); | 294 | struct Lisp_Hash_Table *h = XHASH_TABLE (Vmodule_refs_hash); |
| 298 | Lisp_Object obj = value_to_lisp (ref); | 295 | Lisp_Object obj = value_to_lisp (ref); |
| 299 | EMACS_UINT hashcode; | 296 | EMACS_UINT hashcode; |
| @@ -302,7 +299,6 @@ module_free_global_ref (emacs_env *env, emacs_value ref) | |||
| 302 | if (i >= 0) | 299 | if (i >= 0) |
| 303 | { | 300 | { |
| 304 | Lisp_Object value = HASH_VALUE (h, i); | 301 | Lisp_Object value = HASH_VALUE (h, i); |
| 305 | eassert (NATNUMP (value)); | ||
| 306 | EMACS_INT refcount = XFASTINT (value) - 1; | 302 | EMACS_INT refcount = XFASTINT (value) - 1; |
| 307 | if (refcount > 0) | 303 | if (refcount > 0) |
| 308 | { | 304 | { |
| @@ -310,10 +306,7 @@ module_free_global_ref (emacs_env *env, emacs_value ref) | |||
| 310 | set_hash_value_slot (h, i, value); | 306 | set_hash_value_slot (h, i, value); |
| 311 | } | 307 | } |
| 312 | else | 308 | else |
| 313 | { | 309 | hash_remove_from_table (h, value); |
| 314 | eassert (refcount == 0); | ||
| 315 | hash_remove_from_table (h, value); | ||
| 316 | } | ||
| 317 | } | 310 | } |
| 318 | } | 311 | } |
| 319 | 312 | ||
| @@ -670,7 +663,6 @@ module_vec_size (emacs_env *env, emacs_value vec) | |||
| 670 | module_wrong_type (env, Qvectorp, lvec); | 663 | module_wrong_type (env, Qvectorp, lvec); |
| 671 | return 0; | 664 | return 0; |
| 672 | } | 665 | } |
| 673 | eassert (ASIZE (lvec) >= 0); | ||
| 674 | return ASIZE (lvec); | 666 | return ASIZE (lvec); |
| 675 | } | 667 | } |
| 676 | 668 | ||
| @@ -894,7 +886,7 @@ finalize_storage (struct emacs_value_storage *storage) | |||
| 894 | } | 886 | } |
| 895 | 887 | ||
| 896 | /* Allocate a new value from STORAGE and stores OBJ in it. Return | 888 | /* Allocate a new value from STORAGE and stores OBJ in it. Return |
| 897 | NULL if allocations fails and use ENV for non local exit reporting. */ | 889 | NULL if allocation fails and use ENV for non local exit reporting. */ |
| 898 | static emacs_value | 890 | static emacs_value |
| 899 | allocate_emacs_value (emacs_env *env, struct emacs_value_storage *storage, | 891 | allocate_emacs_value (emacs_env *env, struct emacs_value_storage *storage, |
| 900 | Lisp_Object obj) | 892 | Lisp_Object obj) |