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/lisp.h | |
| 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/lisp.h')
| -rw-r--r-- | src/lisp.h | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/src/lisp.h b/src/lisp.h index 71dca7201d0..9af13a85557 100644 --- a/src/lisp.h +++ b/src/lisp.h | |||
| @@ -847,7 +847,9 @@ INLINE EMACS_INT | |||
| 847 | INLINE EMACS_INT | 847 | INLINE EMACS_INT |
| 848 | (XFASTINT) (Lisp_Object a) | 848 | (XFASTINT) (Lisp_Object a) |
| 849 | { | 849 | { |
| 850 | return lisp_h_XFASTINT (a); | 850 | EMACS_INT n = lisp_h_XFASTINT (a); |
| 851 | eassume (0 <= n); | ||
| 852 | return n; | ||
| 851 | } | 853 | } |
| 852 | 854 | ||
| 853 | INLINE struct Lisp_Symbol * | 855 | INLINE struct Lisp_Symbol * |
| @@ -915,7 +917,7 @@ XFASTINT (Lisp_Object a) | |||
| 915 | { | 917 | { |
| 916 | EMACS_INT int0 = Lisp_Int0; | 918 | EMACS_INT int0 = Lisp_Int0; |
| 917 | EMACS_INT n = USE_LSB_TAG ? XINT (a) : XLI (a) - (int0 << VALBITS); | 919 | EMACS_INT n = USE_LSB_TAG ? XINT (a) : XLI (a) - (int0 << VALBITS); |
| 918 | eassert (0 <= n); | 920 | eassume (0 <= n); |
| 919 | return n; | 921 | return n; |
| 920 | } | 922 | } |
| 921 | 923 | ||
| @@ -923,6 +925,7 @@ XFASTINT (Lisp_Object a) | |||
| 923 | INLINE struct Lisp_Symbol * | 925 | INLINE struct Lisp_Symbol * |
| 924 | XSYMBOL (Lisp_Object a) | 926 | XSYMBOL (Lisp_Object a) |
| 925 | { | 927 | { |
| 928 | eassert (SYMBOLP (a)); | ||
| 926 | uintptr_t i = (uintptr_t) XUNTAG (a, Lisp_Symbol); | 929 | uintptr_t i = (uintptr_t) XUNTAG (a, Lisp_Symbol); |
| 927 | void *p = (char *) lispsym + i; | 930 | void *p = (char *) lispsym + i; |
| 928 | return p; | 931 | return p; |
| @@ -1536,7 +1539,16 @@ aref_addr (Lisp_Object array, ptrdiff_t idx) | |||
| 1536 | INLINE ptrdiff_t | 1539 | INLINE ptrdiff_t |
| 1537 | ASIZE (Lisp_Object array) | 1540 | ASIZE (Lisp_Object array) |
| 1538 | { | 1541 | { |
| 1539 | return XVECTOR (array)->header.size; | 1542 | ptrdiff_t size = XVECTOR (array)->header.size; |
| 1543 | eassume (0 <= size); | ||
| 1544 | return size; | ||
| 1545 | } | ||
| 1546 | |||
| 1547 | INLINE ptrdiff_t | ||
| 1548 | gc_asize (Lisp_Object array) | ||
| 1549 | { | ||
| 1550 | /* Like ASIZE, but also can be used in the garbage collector. */ | ||
| 1551 | return XVECTOR (array)->header.size & ~ARRAY_MARK_FLAG; | ||
| 1540 | } | 1552 | } |
| 1541 | 1553 | ||
| 1542 | INLINE void | 1554 | INLINE void |
| @@ -1551,7 +1563,7 @@ gc_aset (Lisp_Object array, ptrdiff_t idx, Lisp_Object val) | |||
| 1551 | { | 1563 | { |
| 1552 | /* Like ASET, but also can be used in the garbage collector: | 1564 | /* Like ASET, but also can be used in the garbage collector: |
| 1553 | sweep_weak_table calls set_hash_key etc. while the table is marked. */ | 1565 | sweep_weak_table calls set_hash_key etc. while the table is marked. */ |
| 1554 | eassert (0 <= idx && idx < (ASIZE (array) & ~ARRAY_MARK_FLAG)); | 1566 | eassert (0 <= idx && idx < gc_asize (array)); |
| 1555 | XVECTOR (array)->contents[idx] = val; | 1567 | XVECTOR (array)->contents[idx] = val; |
| 1556 | } | 1568 | } |
| 1557 | 1569 | ||
| @@ -1933,21 +1945,22 @@ struct Lisp_Hash_Table | |||
| 1933 | }; | 1945 | }; |
| 1934 | 1946 | ||
| 1935 | 1947 | ||
| 1948 | INLINE bool | ||
| 1949 | HASH_TABLE_P (Lisp_Object a) | ||
| 1950 | { | ||
| 1951 | return PSEUDOVECTORP (a, PVEC_HASH_TABLE); | ||
| 1952 | } | ||
| 1953 | |||
| 1936 | INLINE struct Lisp_Hash_Table * | 1954 | INLINE struct Lisp_Hash_Table * |
| 1937 | XHASH_TABLE (Lisp_Object a) | 1955 | XHASH_TABLE (Lisp_Object a) |
| 1938 | { | 1956 | { |
| 1957 | eassert (HASH_TABLE_P (a)); | ||
| 1939 | return XUNTAG (a, Lisp_Vectorlike); | 1958 | return XUNTAG (a, Lisp_Vectorlike); |
| 1940 | } | 1959 | } |
| 1941 | 1960 | ||
| 1942 | #define XSET_HASH_TABLE(VAR, PTR) \ | 1961 | #define XSET_HASH_TABLE(VAR, PTR) \ |
| 1943 | (XSETPSEUDOVECTOR (VAR, PTR, PVEC_HASH_TABLE)) | 1962 | (XSETPSEUDOVECTOR (VAR, PTR, PVEC_HASH_TABLE)) |
| 1944 | 1963 | ||
| 1945 | INLINE bool | ||
| 1946 | HASH_TABLE_P (Lisp_Object a) | ||
| 1947 | { | ||
| 1948 | return PSEUDOVECTORP (a, PVEC_HASH_TABLE); | ||
| 1949 | } | ||
| 1950 | |||
| 1951 | /* Value is the key part of entry IDX in hash table H. */ | 1964 | /* Value is the key part of entry IDX in hash table H. */ |
| 1952 | INLINE Lisp_Object | 1965 | INLINE Lisp_Object |
| 1953 | HASH_KEY (struct Lisp_Hash_Table *h, ptrdiff_t idx) | 1966 | HASH_KEY (struct Lisp_Hash_Table *h, ptrdiff_t idx) |