comparison src/lisp.h @ 5023:838630c0734f

error-checking, Windows shutdown changes -------------------- ChangeLog entries follow: -------------------- src/ChangeLog addition: 2010-02-09 Ben Wing <ben@xemacs.org> * dynarr.c (Dynarr_insert_many): * dynarr.c (Dynarr_delete_many): * emacs.c: * emacs.c (pause_so_user_can_read_messages): * emacs.c (Fkill_emacs): * emacs.c (guts_of_fatal_error_signal): * lisp.h: * lisp.h (INLINE_ERROR_CHECK_ARGS): * lisp.h (Dynarr_set_length_1): * lisp.h (Dynarr_set_length): * lisp.h (Dynarr_pop): Add ERROR_CHECK_DYNARR, dynarr_checking_assert(). Use it. Sort existing error-check categories in lisp.h, remove most of the (unused) assert variations from most categories. Add a long comment about reorganizing the system by categories and subcategories. Create ERROR_CHECK_ANY if any error-checking categories defined, and use it in emacs.c to define USER_IS_DEVELOPING_XEMACS. In emacs.c and cmdloop.c, don't display a message at early shutdown or fatal shutdown when on Cygwin, only Windows native -- Cygwin has a working stderr that shows error output. Update comment in Dynarr_verify_pos_atp().
author Ben Wing <ben@xemacs.org>
date Tue, 09 Feb 2010 19:13:44 -0600
parents 4e784bfabae7
children 9410323e4b0d 6f2158fa75ed b5df3737028a
comparison
equal deleted inserted replaced
5022:cfe36e196dc7 5023:838630c0734f
19 along with XEmacs; see the file COPYING. If not, write to 19 along with XEmacs; see the file COPYING. If not, write to
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */ 21 Boston, MA 02111-1307, USA. */
22 22
23 /* Synched up with: FSF 19.30. */ 23 /* Synched up with: FSF 19.30. */
24
25 #ifndef INCLUDED_lisp_h_
26 #define INCLUDED_lisp_h_
24 27
25 /* Authorship: 28 /* Authorship:
26 29
27 Based on code from pre-release FSF 19, c. 1991. 30 Based on code from pre-release FSF 19, c. 1991.
28 Various changes by Jamie Zawinski 1991-1994: 31 Various changes by Jamie Zawinski 1991-1994:
48 Various macro-related changes by Jerry James, 2003: 51 Various macro-related changes by Jerry James, 2003:
49 MODULE_API introduced; 52 MODULE_API introduced;
50 Compiler-specific definitions modernized and moved to compiler.h. 53 Compiler-specific definitions modernized and moved to compiler.h.
51 */ 54 */
52 55
53 #ifndef INCLUDED_lisp_h_
54 #define INCLUDED_lisp_h_
55
56 /************************************************************************/
57 /* general definitions */
58 /************************************************************************/
59
60 /* Conventions in comments: 56 /* Conventions in comments:
61 57
62 "Mule-izing" is the process of going through a file and eliminating 58 "Mule-izing" is the process of going through a file and eliminating
63 assumptions that the internal format (Ibyte * text) is the same as the 59 assumptions that the internal format (Ibyte * text) is the same as the
64 external format used by library routines. Mule-ization should also 60 external format used by library routines. Mule-ization should also
89 85
90 %%#### marks places that need work for KKCC (the new garbage collector). 86 %%#### marks places that need work for KKCC (the new garbage collector).
91 87
92 */ 88 */
93 89
94 /* -------------------------- include files --------------------- */ 90 /************************************************************************/
91 /* include files */
92 /************************************************************************/
95 93
96 /* We include the following generally useful header files so that you 94 /* We include the following generally useful header files so that you
97 don't have to worry about prototypes when using the standard C 95 don't have to worry about prototypes when using the standard C
98 library functions and macros. These files shouldn't be excessively 96 library functions and macros. These files shouldn't be excessively
99 large so they shouldn't cause that much of a slowdown. */ 97 large so they shouldn't cause that much of a slowdown. */
114 #ifdef __cplusplus 112 #ifdef __cplusplus
115 #include <limits> /* necessary for max()/min() under G++ 4 */ 113 #include <limits> /* necessary for max()/min() under G++ 4 */
116 #endif 114 #endif
117 115
118 116
119 /* -------------------------- error-checking ------------------------ */ 117 /************************************************************************/
120 118 /* error checking */
121 /* The large categories established by configure can be subdivided into 119 /************************************************************************/
122 smaller subcategories, for problems in specific modules. You can't 120
123 control this using configure, but you can manually stick in a define as 121 /* ------------------------- large categories ------------------------- */
124 necessary. */
125 122
126 /* How these work: 123 /* How these work:
127 124
128 The most common classes will be `text' and `type', followed by `structure'. 125 The most common classes will be `text' and `type', followed by `structure'.
129 `text' is for problems related to bad textual format. `type' is for 126 `text' is for problems related to bad textual format. `type' is for
144 macro that calls your inline function and includes INLINE_TEXT_CHECK_CALL 141 macro that calls your inline function and includes INLINE_TEXT_CHECK_CALL
145 at the end of the parameter list. This will arrange to pass in and receive 142 at the end of the parameter list. This will arrange to pass in and receive
146 the file and line (__FILE__, __LINE__) at place where the call occurs in 143 the file and line (__FILE__, __LINE__) at place where the call occurs in
147 the calling function; but nothing will get passed in when ERROR_CHECK_TEXT 144 the calling function; but nothing will get passed in when ERROR_CHECK_TEXT
148 is not defined. 145 is not defined.
146
147 Currently the full bevy of *foo_checking_assert* macros are defined only
148 for `text' and `types'; for others, only the basic foo_checking_assert()
149 macro is defined. Writing out all the variations for all possible error
150 categories would produce too much clutter. If any of these become
151 needed, they can always be defined. */
152
153 /* #### I suggest revamping these and making proper use of the
154 category/subcategory system. Here is one proposal:
155
156 Major category Minor categories
157 --------------------------------
158 Allocation
159 Malloc
160 Dynarr
161
162 Display
163 Extents
164 Glyphs
165 Redisplay
166
167 Execution
168 Byte-Code
169 Catch
170 Garbage Collection
171 Trapping-Problems
172
173 Lisp Objects
174 Buffers
175 Char Tables
176 Events
177 Lstreams
178 Hash Tables
179 Range Tables
180
181 Types
182 Lrecord Types
183 Subtypes
184
185 Text
186 Byte Positions
187 Conversion
188 Eistrings
189 Itext
190 Lisp Strings
191
192 --ben
149 */ 193 */
150 194
151
152 #ifdef ERROR_CHECK_STRUCTURES
153 /* Check for problems with the catch list and specbind stack */
154 #define ERROR_CHECK_CATCH
155 /* Check for insufficient use of call_trapping_problems(), particularly
156 due to glyph-related changes causing eval or QUIT within redisplay */
157 #define ERROR_CHECK_TRAPPING_PROBLEMS
158 #endif /* ERROR_CHECK_STRUCTURES */
159 195
160 #define INLINE_ERROR_CHECK_ARGS , const char *__file__, int __line__ 196 #define INLINE_ERROR_CHECK_ARGS , const char *__file__, int __line__
161 #define INLINE_ERROR_CHECK_CALL , __FILE__, __LINE__ 197 #define INLINE_ERROR_CHECK_CALL , __FILE__, __LINE__
162 #define DISABLED_INLINE_ERROR_CHECK_ARGS 198 #define DISABLED_INLINE_ERROR_CHECK_ARGS
163 #define DISABLED_INLINE_ERROR_CHECK_CALL 199 #define DISABLED_INLINE_ERROR_CHECK_CALL
166 line of the calling function */ 202 line of the calling function */
167 #define inline_assert(assertion) assert_at_line (assertion, __file__, __line__) 203 #define inline_assert(assertion) assert_at_line (assertion, __file__, __line__)
168 /* The following should not use disabled_assert_at_line() because when the 204 /* The following should not use disabled_assert_at_line() because when the
169 inline assert is disabled, params __file__ and __line__ do not exist. */ 205 inline assert is disabled, params __file__ and __line__ do not exist. */
170 #define disabled_inline_assert(assertion) disabled_assert (assertion) 206 #define disabled_inline_assert(assertion) disabled_assert (assertion)
207
208 /* ------- the specific categories -------- */
209
210 #if defined (ERROR_CHECK_BYTE_CODE) || defined (ERROR_CHECK_DISPLAY) || defined (ERROR_CHECK_EXTENTS) || defined (ERROR_CHECK_GC) || defined (ERROR_CHECK_GLYPHS) || defined (ERROR_CHECK_MALLOC) || defined (ERROR_CHECK_STRUCTURES) || defined (ERROR_CHECK_TEXT) || defined (ERROR_CHECK_TYPES)
211 #define ERROR_CHECK_ANY
212 #endif
213
214 /* KEEP THESE SORTED! */
215
216 #ifdef ERROR_CHECK_BYTE_CODE
217 #define byte_code_checking_assert(assertion) assert (assertion)
218 #else /* not ERROR_CHECK_BYTE_CODE */
219 #define byte_code_checking_assert(assertion) disabled_assert (assertion)
220 #endif /* ERROR_CHECK_BYTE_CODE */
221
222 #ifdef ERROR_CHECK_DISPLAY
223 #define display_checking_assert(assertion) assert (assertion)
224 #else /* not ERROR_CHECK_DISPLAY */
225 #define display_checking_assert(assertion) disabled_assert (assertion)
226 #endif /* ERROR_CHECK_DISPLAY */
227
228 #ifdef ERROR_CHECK_EXTENTS
229 #define extent_checking_assert(assertion) assert (assertion)
230 #else /* not ERROR_CHECK_EXTENTS */
231 #define extent_checking_assert(assertion) disabled_assert (assertion)
232 #endif /* ERROR_CHECK_EXTENTS */
233
234 #ifdef ERROR_CHECK_GC
235 #define gc_checking_assert(assertion) assert (assertion)
236 #else /* not ERROR_CHECK_GC */
237 #define gc_checking_assert(assertion) disabled_assert (assertion)
238 #endif /* ERROR_CHECK_GC */
239
240 #ifdef ERROR_CHECK_GLYPHS
241 #define glyph_checking_assert(assertion) assert (assertion)
242 #else /* not ERROR_CHECK_GLYPHS */
243 #define glyph_checking_assert(assertion) disabled_assert (assertion)
244 #endif /* ERROR_CHECK_GLYPHS */
245
246 #ifdef ERROR_CHECK_MALLOC
247 #define malloc_checking_assert(assertion) assert (assertion)
248 #else /* not ERROR_CHECK_MALLOC */
249 #define malloc_checking_assert(assertion) disabled_assert (assertion)
250 #endif /* ERROR_CHECK_MALLOC */
251
252 #ifdef ERROR_CHECK_STRUCTURES
253 #define structure_checking_assert(assertion) assert (assertion)
254 #else /* not ERROR_CHECK_STRUCTURES */
255 #define structure_checking_assert(assertion) disabled_assert (assertion)
256 #endif /* ERROR_CHECK_STRUCTURES */
171 257
172 #ifdef ERROR_CHECK_TEXT 258 #ifdef ERROR_CHECK_TEXT
173 #define text_checking_assert(assertion) assert (assertion) 259 #define text_checking_assert(assertion) assert (assertion)
174 #define text_checking_assert_at_line(assertion, file, line) \ 260 #define text_checking_assert_at_line(assertion, file, line) \
175 assert_at_line (assertion, file, line) 261 assert_at_line (assertion, file, line)
209 #define INLINE_TYPE_CHECK_CALL DISABLED_INLINE_ERROR_CHECK_CALL 295 #define INLINE_TYPE_CHECK_CALL DISABLED_INLINE_ERROR_CHECK_CALL
210 #define type_checking_assert_with_message(assertion, msg) \ 296 #define type_checking_assert_with_message(assertion, msg) \
211 disabled_assert_with_message (assertion, msg) 297 disabled_assert_with_message (assertion, msg)
212 #endif /* ERROR_CHECK_TYPES */ 298 #endif /* ERROR_CHECK_TYPES */
213 299
300 /* ------------------------- small categories ------------------------- */
301
302 /* The large categories established by configure can be subdivided into
303 smaller subcategories, for problems in specific modules. You can't
304 control this using configure, but you can manually stick in a define as
305 necessary.
306
307 The idea is to go ahead and create a new type of error-checking and
308 have it turned on if the larger category it is a part of is also
309 turned on. For example, ERROR_CHECK_DYNARR is considered a subcategory
310 of ERROR_CHECK_STRUCTURES.
311
312 We also define foo_checking_assert() macros for convenience, but
313 generally don't define the many variations of this macro as for the
314 major types above, because it produces too much clutter. If any of
315 these become needed, they can always be defined. */
316
214 #ifdef ERROR_CHECK_STRUCTURES 317 #ifdef ERROR_CHECK_STRUCTURES
215 #define structure_checking_assert(assertion) assert (assertion) 318 /* Check for problems with the catch list and specbind stack */
216 #define structure_checking_assert_at_line(assertion, file, line) \ 319 #define ERROR_CHECK_CATCH
217 assert_at_line (assertion, file, line) 320 /* Check for incoherent Dynarr structures, attempts to access Dynarr
218 #define inline_structure_checking_assert(assertion) inline_assert (assertion) 321 positions out of range, reentrant use of Dynarrs through Dynarr locking,
219 #define INLINE_STRUCTURE_CHECK_ARGS INLINE_ERROR_CHECK_ARGS 322 etc. */
220 #define INLINE_STRUCTURE_CHECK_CALL INLINE_ERROR_CHECK_CALL 323 #define ERROR_CHECK_DYNARR
221 #define structure_checking_assert_with_message(assertion, msg) \ 324 /* Check for insufficient use of call_trapping_problems(), particularly
222 assert_with_message (assertion, msg) 325 due to glyph-related changes causing eval or QUIT within redisplay */
223 #else /* not ERROR_CHECK_STRUCTURES */ 326 #define ERROR_CHECK_TRAPPING_PROBLEMS
224 #define structure_checking_assert(assertion) disabled_assert (assertion)
225 #define structure_checking_assert_at_line(assertion, file, line) \
226 disabled_assert_at_line (assertion, file, line)
227 #define inline_structure_checking_assert(assertion) \
228 disabled_inline_assert (assertion)
229 #define INLINE_STRUCTURE_CHECK_ARGS DISABLED_INLINE_ERROR_CHECK_ARGS
230 #define INLINE_STRUCTURE_CHECK_CALL DISABLED_INLINE_ERROR_CHECK_CALL
231 #define structure_checking_assert_with_message(assertion, msg) \
232 disabled_assert_with_message (assertion, msg)
233 #endif /* ERROR_CHECK_STRUCTURES */ 327 #endif /* ERROR_CHECK_STRUCTURES */
234 328
235 #ifdef ERROR_CHECK_GC 329 #ifdef ERROR_CHECK_CATCH
236 #define gc_checking_assert(assertion) assert (assertion) 330 #define catch_checking_assert(assertion) assert (assertion)
237 #define gc_checking_assert_at_line(assertion, file, line) \ 331 #else /* not ERROR_CHECK_CATCH */
238 assert_at_line (assertion, file, line) 332 #define catch_checking_assert(assertion) disabled_assert (assertion)
239 #define inline_gc_checking_assert(assertion) inline_assert (assertion) 333 #endif /* ERROR_CHECK_CATCH */
240 #define INLINE_GC_CHECK_ARGS INLINE_ERROR_CHECK_ARGS 334
241 #define INLINE_GC_CHECK_CALL INLINE_ERROR_CHECK_CALL 335 #ifdef ERROR_CHECK_DYNARR
242 #define gc_checking_assert_with_message(assertion, msg) \ 336 #define dynarr_checking_assert(assertion) assert (assertion)
243 assert_with_message (assertion, msg) 337 #else /* not ERROR_CHECK_DYNARR */
244 #else /* not ERROR_CHECK_GC */ 338 #define dynarr_checking_assert(assertion) disabled_assert (assertion)
245 #define gc_checking_assert(assertion) disabled_assert (assertion) 339 #endif /* ERROR_CHECK_DYNARR */
246 #define gc_checking_assert_at_line(assertion, file, line) \
247 disabled_assert_at_line (assertion, file, line)
248 #define inline_gc_checking_assert(assertion) \
249 disabled_inline_assert (assertion)
250 #define INLINE_GC_CHECK_ARGS DISABLED_INLINE_ERROR_CHECK_ARGS
251 #define INLINE_GC_CHECK_CALL DISABLED_INLINE_ERROR_CHECK_CALL
252 #define gc_checking_assert_with_message(assertion, msg) \
253 disabled_assert_with_message (assertion, msg)
254 #endif /* ERROR_CHECK_GC */
255
256 #ifdef ERROR_CHECK_DISPLAY
257 #define display_checking_assert(assertion) assert (assertion)
258 #define display_checking_assert_at_line(assertion, file, line) \
259 assert_at_line (assertion, file, line)
260 #define inline_display_checking_assert(assertion) inline_assert (assertion)
261 #define INLINE_DISPLAY_CHECK_ARGS INLINE_ERROR_CHECK_ARGS
262 #define INLINE_DISPLAY_CHECK_CALL INLINE_ERROR_CHECK_CALL
263 #define display_checking_assert_with_message(assertion, msg) \
264 assert_with_message (assertion, msg)
265 #else /* not ERROR_CHECK_DISPLAY */
266 #define display_checking_assert(assertion) disabled_assert (assertion)
267 #define display_checking_assert_at_line(assertion, file, line) \
268 disabled_assert_at_line (assertion, file, line)
269 #define inline_display_checking_assert(assertion) \
270 disabled_inline_assert (assertion)
271 #define INLINE_DISPLAY_CHECK_ARGS DISABLED_INLINE_ERROR_CHECK_ARGS
272 #define INLINE_DISPLAY_CHECK_CALL DISABLED_INLINE_ERROR_CHECK_CALL
273 #define display_checking_assert_with_message(assertion, msg) \
274 disabled_assert_with_message (assertion, msg)
275 #endif /* ERROR_CHECK_DISPLAY */
276
277 #ifdef ERROR_CHECK_GLYPHS
278 #define glyph_checking_assert(assertion) assert (assertion)
279 #define glyph_checking_assert_at_line(assertion, file, line) \
280 assert_at_line (assertion, file, line)
281 #define inline_glyph_checking_assert(assertion) inline_assert (assertion)
282 #define INLINE_GLYPH_CHECK_ARGS INLINE_ERROR_CHECK_ARGS
283 #define INLINE_GLYPH_CHECK_CALL INLINE_ERROR_CHECK_CALL
284 #define glyph_checking_assert_with_message(assertion, msg) \
285 assert_with_message (assertion, msg)
286 #else /* not ERROR_CHECK_GLYPHS */
287 #define glyph_checking_assert(assertion) disabled_assert (assertion)
288 #define glyph_checking_assert_at_line(assertion, file, line) \
289 disabled_assert_at_line (assertion, file, line)
290 #define inline_glyph_checking_assert(assertion) \
291 disabled_inline_assert (assertion)
292 #define INLINE_GLYPH_CHECK_ARGS DISABLED_INLINE_ERROR_CHECK_ARGS
293 #define INLINE_GLYPH_CHECK_CALL DISABLED_INLINE_ERROR_CHECK_CALL
294 #define glyph_checking_assert_with_message(assertion, msg) \
295 disabled_assert_with_message (assertion, msg)
296 #endif /* ERROR_CHECK_GLYPHS */
297
298 #ifdef ERROR_CHECK_EXTENTS
299 #define extent_checking_assert(assertion) assert (assertion)
300 #define extent_checking_assert_at_line(assertion, file, line) \
301 assert_at_line (assertion, file, line)
302 #define inline_extent_checking_assert(assertion) inline_assert (assertion)
303 #define INLINE_EXTENT_CHECK_ARGS INLINE_ERROR_CHECK_ARGS
304 #define INLINE_EXTENT_CHECK_CALL INLINE_ERROR_CHECK_CALL
305 #define extent_checking_assert_with_message(assertion, msg) \
306 assert_with_message (assertion, msg)
307 #else /* not ERROR_CHECK_EXTENTS */
308 #define extent_checking_assert(assertion) disabled_assert (assertion)
309 #define extent_checking_assert_at_line(assertion, file, line) \
310 disabled_assert_at_line (assertion, file, line)
311 #define inline_extent_checking_assert(assertion) \
312 disabled_inline_assert (assertion)
313 #define INLINE_EXTENT_CHECK_ARGS DISABLED_INLINE_ERROR_CHECK_ARGS
314 #define INLINE_EXTENT_CHECK_CALL DISABLED_INLINE_ERROR_CHECK_CALL
315 #define extent_checking_assert_with_message(assertion, msg) \
316 disabled_assert_with_message (assertion, msg)
317 #endif /* ERROR_CHECK_EXTENTS */
318
319 #ifdef ERROR_CHECK_MALLOC
320 #define malloc_checking_assert(assertion) assert (assertion)
321 #define malloc_checking_assert_at_line(assertion, file, line) \
322 assert_at_line (assertion, file, line)
323 #define inline_malloc_checking_assert(assertion) inline_assert (assertion)
324 #define INLINE_MALLOC_CHECK_ARGS INLINE_ERROR_CHECK_ARGS
325 #define INLINE_MALLOC_CHECK_CALL INLINE_ERROR_CHECK_CALL
326 #define malloc_checking_assert_with_message(assertion, msg) \
327 assert_with_message (assertion, msg)
328 #else /* not ERROR_CHECK_MALLOC */
329 #define malloc_checking_assert(assertion) disabled_assert (assertion)
330 #define malloc_checking_assert_at_line(assertion, file, line) \
331 disabled_assert_at_line (assertion, file, line)
332 #define inline_malloc_checking_assert(assertion) \
333 disabled_inline_assert (assertion)
334 #define INLINE_MALLOC_CHECK_ARGS DISABLED_INLINE_ERROR_CHECK_ARGS
335 #define INLINE_MALLOC_CHECK_CALL DISABLED_INLINE_ERROR_CHECK_CALL
336 #define malloc_checking_assert_with_message(assertion, msg) \
337 disabled_assert_with_message (assertion, msg)
338 #endif /* ERROR_CHECK_MALLOC */
339
340 #ifdef ERROR_CHECK_BYTE_CODE
341 #define byte_code_checking_assert(assertion) assert (assertion)
342 #define byte_code_checking_assert_at_line(assertion, file, line) \
343 assert_at_line (assertion, file, line)
344 #define inline_byte_code_checking_assert(assertion) inline_assert (assertion)
345 #define INLINE_BYTE_CODE_CHECK_ARGS INLINE_ERROR_CHECK_ARGS
346 #define INLINE_BYTE_CODE_CHECK_CALL INLINE_ERROR_CHECK_CALL
347 #define byte_code_checking_assert_with_message(assertion, msg) \
348 assert_with_message (assertion, msg)
349 #else /* not ERROR_CHECK_BYTE_CODE */
350 #define byte_code_checking_assert(assertion) disabled_assert (assertion)
351 #define byte_code_checking_assert_at_line(assertion, file, line) \
352 disabled_assert_at_line (assertion, file, line)
353 #define inline_byte_code_checking_assert(assertion) \
354 disabled_inline_assert (assertion)
355 #define INLINE_BYTE_CODE_CHECK_ARGS DISABLED_INLINE_ERROR_CHECK_ARGS
356 #define INLINE_BYTE_CODE_CHECK_CALL DISABLED_INLINE_ERROR_CHECK_CALL
357 #define byte_code_checking_assert_with_message(assertion, msg) \
358 disabled_assert_with_message (assertion, msg)
359 #endif /* ERROR_CHECK_BYTE_CODE */
360 340
361 #ifdef ERROR_CHECK_TRAPPING_PROBLEMS 341 #ifdef ERROR_CHECK_TRAPPING_PROBLEMS
362 #define trapping_problems_checking_assert(assertion) assert (assertion) 342 #define trapping_problems_checking_assert(assertion) assert (assertion)
363 #define trapping_problems_checking_assert_at_line(assertion, file, line) \
364 assert_at_line (assertion, file, line)
365 #define inline_trapping_problems_checking_assert(assertion) inline_assert (assertion)
366 #define INLINE_TRAPPING_PROBLEMS_CHECK_ARGS INLINE_ERROR_CHECK_ARGS
367 #define INLINE_TRAPPING_PROBLEMS_CHECK_CALL INLINE_ERROR_CHECK_CALL
368 #define trapping_problems_checking_assert_with_message(assertion, msg) \
369 assert_with_message (assertion, msg)
370 #else /* not ERROR_CHECK_TRAPPING_PROBLEMS */ 343 #else /* not ERROR_CHECK_TRAPPING_PROBLEMS */
371 #define trapping_problems_checking_assert(assertion) disabled_assert (assertion) 344 #define trapping_problems_checking_assert(assertion) disabled_assert (assertion)
372 #define trapping_problems_checking_assert_at_line(assertion, file, line) \
373 disabled_assert_at_line (assertion, file, line)
374 #define inline_trapping_problems_checking_assert(assertion) \
375 disabled_inline_assert (assertion)
376 #define INLINE_TRAPPING_PROBLEMS_CHECK_ARGS DISABLED_INLINE_ERROR_CHECK_ARGS
377 #define INLINE_TRAPPING_PROBLEMS_CHECK_CALL DISABLED_INLINE_ERROR_CHECK_CALL
378 #define trapping_problems_checking_assert_with_message(assertion, msg) \
379 disabled_assert_with_message (assertion, msg)
380 #endif /* ERROR_CHECK_TRAPPING_PROBLEMS */ 345 #endif /* ERROR_CHECK_TRAPPING_PROBLEMS */
381 346
382 /************************************************************************/ 347 /************************************************************************/
383 /** Definitions of basic types **/ 348 /** Definitions of basic types **/
384 /************************************************************************/ 349 /************************************************************************/
1768 const struct lrecord_implementation *lisp_imp; 1733 const struct lrecord_implementation *lisp_imp;
1769 #else 1734 #else
1770 #define DECLARE_DYNARR_LISP_IMP() 1735 #define DECLARE_DYNARR_LISP_IMP()
1771 #endif 1736 #endif
1772 1737
1773 #ifdef ERROR_CHECK_STRUCTURES 1738 #ifdef ERROR_CHECK_DYNARR
1774 #define DECLARE_DYNARR_LOCKED() \ 1739 #define DECLARE_DYNARR_LOCKED() \
1775 int locked; 1740 int locked;
1776 #else 1741 #else
1777 #define DECLARE_DYNARR_LOCKED() 1742 #define DECLARE_DYNARR_LOCKED()
1778 #endif 1743 #endif
1808 { XD_INT_RESET, offsetof (base_type, max_), XD_INDIRECT(1, 0) } 1773 { XD_INT_RESET, offsetof (base_type, max_), XD_INDIRECT(1, 0) }
1809 #endif /* NEW_GC */ 1774 #endif /* NEW_GC */
1810 1775
1811 /************* Dynarr verification *************/ 1776 /************* Dynarr verification *************/
1812 1777
1813 #ifdef ERROR_CHECK_STRUCTURES 1778 #ifdef ERROR_CHECK_DYNARR
1814 DECLARE_INLINE_HEADER ( 1779 DECLARE_INLINE_HEADER (
1815 int 1780 int
1816 Dynarr_verify_pos_at (void *d, int pos, const Ascbyte *file, int line) 1781 Dynarr_verify_pos_at (void *d, int pos, const Ascbyte *file, int line)
1817 ) 1782 )
1818 { 1783 {
1829 ) 1794 )
1830 { 1795 {
1831 Dynarr *dy = (Dynarr *) d; 1796 Dynarr *dy = (Dynarr *) d;
1832 /* We use `largest', not `len', because the redisplay code often 1797 /* We use `largest', not `len', because the redisplay code often
1833 accesses stuff between len and largest. */ 1798 accesses stuff between len and largest. */
1834 /* Code will often do something like ... 1799 /* [[ Code will often do something like ...
1835 1800
1836 val = make_bit_vector_from_byte_vector (Dynarr_atp (dyn, 0), 1801 val = make_bit_vector_from_byte_vector (Dynarr_atp (dyn, 0),
1837 Dynarr_length (dyn)); 1802 Dynarr_length (dyn));
1838 1803
1839 which works fine when the Dynarr_length is non-zero, but when zero, 1804 which works fine when the Dynarr_length is non-zero, but when zero,
1840 the result of Dynarr_atp() not only points past the end of the 1805 the result of Dynarr_atp() not only points past the end of the
1841 allocated array, but the array may not have ever been allocated and 1806 allocated array, but the array may not have ever been allocated and
1842 hence the return value is NULL. But the length of 0 causes the 1807 hence the return value is NULL. But the length of 0 causes the
1843 pointer to never get checked. These can occur throughout the code 1808 pointer to never get checked. These can occur throughout the code
1844 so we put in a special check. */ 1809 so we put in a special check. --ben ]]
1810
1811 Update: The common idiom `Dynarr_atp (dyn, 0)' has been changed to
1812 `Dynarr_begin (dyn)'. Possibly this special check at POS 0 can be
1813 done only for Dynarr_begin() not for general Dynarr_atp(). --ben */
1845 if (pos == 0 && dy->len_ == 0) 1814 if (pos == 0 && dy->len_ == 0)
1846 return pos; 1815 return pos;
1847 /* #### It's vaguely possible that some code could legitimately want to 1816 /* #### It's vaguely possible that some code could legitimately want to
1848 retrieve a pointer to the position just past the end of dynarr memory. 1817 retrieve a pointer to the position just past the end of dynarr memory.
1849 This could happen with Dynarr_atp() but not Dynarr_at(). If so, it 1818 This could happen with Dynarr_atp() but not Dynarr_at(). If so, it
1852 probably create a new macro Dynarr_atp_allow_end() which is like 1821 probably create a new macro Dynarr_atp_allow_end() which is like
1853 Dynarr_atp() but which allows for pointing at invalid addresses -- we 1822 Dynarr_atp() but which allows for pointing at invalid addresses -- we
1854 really want to check for cases of accessing just past the end of 1823 really want to check for cases of accessing just past the end of
1855 memory, which is a likely off-by-one problem to occur and will usually 1824 memory, which is a likely off-by-one problem to occur and will usually
1856 not trigger a protection fault (instead, you'll just get random 1825 not trigger a protection fault (instead, you'll just get random
1857 behavior, possibly overwriting other memory, which is bad). */ 1826 behavior, possibly overwriting other memory, which is bad). --ben */
1858 assert_at_line (pos >= 0 && pos < dy->largest_, file, line); 1827 assert_at_line (pos >= 0 && pos < dy->largest_, file, line);
1859 return pos; 1828 return pos;
1860 } 1829 }
1861 1830
1862 DECLARE_INLINE_HEADER ( 1831 DECLARE_INLINE_HEADER (
1876 1845
1877 #else 1846 #else
1878 #define Dynarr_verify_pos_at(d, pos, file, line) (pos) 1847 #define Dynarr_verify_pos_at(d, pos, file, line) (pos)
1879 #define Dynarr_verify_pos_atp(d, pos, file, line) (pos) 1848 #define Dynarr_verify_pos_atp(d, pos, file, line) (pos)
1880 #define Dynarr_verify_pos_atp_allow_end(d, pos, file, line) (pos) 1849 #define Dynarr_verify_pos_atp_allow_end(d, pos, file, line) (pos)
1881 #endif /* ERROR_CHECK_STRUCTURES */ 1850 #endif /* ERROR_CHECK_DYNARR */
1882 1851
1883 #ifdef ERROR_CHECK_STRUCTURES 1852 #ifdef ERROR_CHECK_DYNARR
1884 DECLARE_INLINE_HEADER ( 1853 DECLARE_INLINE_HEADER (
1885 Dynarr * 1854 Dynarr *
1886 Dynarr_verify_1 (void *d, const Ascbyte *file, int line) 1855 Dynarr_verify_1 (void *d, const Ascbyte *file, int line)
1887 ) 1856 )
1888 { 1857 {
1917 #else 1886 #else
1918 #define Dynarr_verify(d) ((Dynarr *) d) 1887 #define Dynarr_verify(d) ((Dynarr *) d)
1919 #define Dynarr_verify_mod(d) ((Dynarr *) d) 1888 #define Dynarr_verify_mod(d) ((Dynarr *) d)
1920 #define Dynarr_lock(d) DO_NOTHING 1889 #define Dynarr_lock(d) DO_NOTHING
1921 #define Dynarr_unlock(d) DO_NOTHING 1890 #define Dynarr_unlock(d) DO_NOTHING
1922 #endif /* ERROR_CHECK_STRUCTURES */ 1891 #endif /* ERROR_CHECK_DYNARR */
1923 1892
1924 /************* Dynarr creation *************/ 1893 /************* Dynarr creation *************/
1925 1894
1926 MODULE_API void *Dynarr_newf (int elsize); 1895 MODULE_API void *Dynarr_newf (int elsize);
1927 MODULE_API void Dynarr_free (void *d); 1896 MODULE_API void Dynarr_free (void *d);
1941 #define Dynarr_new2(dynarr_type, type) \ 1910 #define Dynarr_new2(dynarr_type, type) \
1942 ((dynarr_type *) Dynarr_newf (sizeof (type))) 1911 ((dynarr_type *) Dynarr_newf (sizeof (type)))
1943 1912
1944 /************* Dynarr access *************/ 1913 /************* Dynarr access *************/
1945 1914
1946 #ifdef ERROR_CHECK_STRUCTURES 1915 #ifdef ERROR_CHECK_DYNARR
1947 /* Enabling this leads to crashes in Cygwin 1.7, gcc 3.4.4 */
1948 #define Dynarr_at(d, pos) \ 1916 #define Dynarr_at(d, pos) \
1949 ((d)->base[Dynarr_verify_pos_at (d, pos, __FILE__, __LINE__)]) 1917 ((d)->base[Dynarr_verify_pos_at (d, pos, __FILE__, __LINE__)])
1950 #define Dynarr_atp_allow_end(d, pos) \ 1918 #define Dynarr_atp_allow_end(d, pos) \
1951 (&((d)->base[Dynarr_verify_pos_atp_allow_end (d, pos, __FILE__, __LINE__)])) 1919 (&((d)->base[Dynarr_verify_pos_atp_allow_end (d, pos, __FILE__, __LINE__)]))
1952 #define Dynarr_atp(d, pos) \ 1920 #define Dynarr_atp(d, pos) \
1981 should not be directly used; use Dynarr_set_length() instead if you need 1949 should not be directly used; use Dynarr_set_length() instead if you need
1982 to, but be very careful when doing so! */ 1950 to, but be very careful when doing so! */
1983 #define Dynarr_set_length_1(d, n) \ 1951 #define Dynarr_set_length_1(d, n) \
1984 do { \ 1952 do { \
1985 Elemcount _dsl1_n = (n); \ 1953 Elemcount _dsl1_n = (n); \
1986 structure_checking_assert (_dsl1_n >= 0 && _dsl1_n <= Dynarr_max (d)); \ 1954 dynarr_checking_assert (_dsl1_n >= 0 && _dsl1_n <= Dynarr_max (d)); \
1987 (void) Dynarr_verify_mod (d); \ 1955 (void) Dynarr_verify_mod (d); \
1988 (d)->len_ = _dsl1_n; \ 1956 (d)->len_ = _dsl1_n; \
1989 /* Use the raw field references here otherwise we get a crash because \ 1957 /* Use the raw field references here otherwise we get a crash because \
1990 we've set the length but not yet fixed up the largest value. */ \ 1958 we've set the length but not yet fixed up the largest value. */ \
1991 if ((d)->len_ > (d)->largest_) \ 1959 if ((d)->len_ > (d)->largest_) \
1996 /* The following two defines will get you into real trouble if you aren't 1964 /* The following two defines will get you into real trouble if you aren't
1997 careful. But they can save a lot of execution time when used wisely. */ 1965 careful. But they can save a lot of execution time when used wisely. */
1998 #define Dynarr_set_length(d, n) \ 1966 #define Dynarr_set_length(d, n) \
1999 do { \ 1967 do { \
2000 Elemcount _dsl_n = (n); \ 1968 Elemcount _dsl_n = (n); \
2001 structure_checking_assert (_dsl_n >= 0 && _dsl_n <= Dynarr_largest (d)); \ 1969 dynarr_checking_assert (_dsl_n >= 0 && _dsl_n <= Dynarr_largest (d)); \
2002 Dynarr_set_length_1 (d, _dsl_n); \ 1970 Dynarr_set_length_1 (d, _dsl_n); \
2003 } while (0) 1971 } while (0)
2004 #define Dynarr_increment(d) \ 1972 #define Dynarr_increment(d) \
2005 Dynarr_set_length (d, Dynarr_length (d) + 1) 1973 Dynarr_set_length (d, Dynarr_length (d) + 1)
2006 1974
2086 Dynarr_set_length_1 (dy, Dynarr_length (dy) + len); 2054 Dynarr_set_length_1 (dy, Dynarr_length (dy) + len);
2087 (void) Dynarr_verify_mod (dy); 2055 (void) Dynarr_verify_mod (dy);
2088 } 2056 }
2089 2057
2090 #define Dynarr_pop(d) \ 2058 #define Dynarr_pop(d) \
2091 (structure_checking_assert (Dynarr_length (d) > 0), \ 2059 (dynarr_checking_assert (Dynarr_length (d) > 0), \
2092 Dynarr_verify_mod (d)->len_--, \ 2060 Dynarr_verify_mod (d)->len_--, \
2093 Dynarr_at (d, Dynarr_length (d))) 2061 Dynarr_at (d, Dynarr_length (d)))
2094 #define Dynarr_delete(d, i) Dynarr_delete_many (d, i, 1) 2062 #define Dynarr_delete(d, i) Dynarr_delete_many (d, i, 1)
2095 #define Dynarr_delete_by_pointer(d, p) \ 2063 #define Dynarr_delete_by_pointer(d, p) \
2096 Dynarr_delete_many (d, (p) - ((d)->base), 1) 2064 Dynarr_delete_many (d, (p) - ((d)->base), 1)