Mercurial > hg > xemacs-beta
comparison src/lisp.h @ 851:e7ee5f8bde58
[xemacs-hg @ 2002-05-23 11:46:08 by ben]
fix for raymond toy's crash, alloca crashes, some recover-session improvements
files.el: Recover-session improvements: Only show session files where some
files can actually be recovered, and show in chronological order.
subr.el, menubar-items.el: As promised to rms, the functionality in
truncate-string-with-continuation-dots has been merged into
truncate-string-to-width. Change callers in menubar-items.el.
select.el: Document some of these funs better. Fix problem where we were
doing own-clipboard twice.
Makefile.in.in: Add alloca.o. Ensure that alloca.s doesn't compile into alloca.o,
but allocax.o (not that it's currently used or anything.)
EmacsFrame.c, abbrev.c, alloc.c, alloca.c, callint.c, callproc.c, config.h.in, device-msw.c, device-x.c, dired.c, doc.c, editfns.c, emacs.c, emodules.c, eval.c, event-Xt.c, event-msw.c, event-stream.c, file-coding.c, fileio.c, filelock.c, fns.c, glyphs-gtk.c, glyphs-msw.c, glyphs-x.c, gui-x.c, input-method-xlib.c, intl-win32.c, lisp.h, lread.c, menubar-gtk.c, menubar-msw.c, menubar.c, mule-wnnfns.c, nt.c, objects-msw.c, process-nt.c, realpath.c, redisplay-gtk.c, redisplay-output.c, redisplay-x.c, redisplay.c, search.c, select-msw.c, sysdep.c, syswindows.h, text.c, text.h, ui-byhand.c: Fix Raymond Toy's crash. Repeat to self: 2^21 - 1 is NOT the
same as (2 << 21) - 1.
Fix crashes due to excessive alloca(). replace alloca() with
ALLOCA(), which calls the C alloca() [which uses xmalloc()]
when the size is too big. Insert in various places calls to
try to flush the C alloca() stored info if there is any.
Add MALLOC_OR_ALLOCA(), for places that expect to be alloca()ing
large blocks. This xmalloc()s when too large and records an
unwind-protect to free -- relying on the caller to unbind_to()
elsewhere in the function. Use it in concat().
Use MALLOC instead of ALLOCA in select-msw.c.
xemacs.mak: Add alloca.o.
author | ben |
---|---|
date | Thu, 23 May 2002 11:46:46 +0000 |
parents | 047d37eb70d7 |
children | 2b6fa2618f76 |
comparison
equal
deleted
inserted
replaced
850:f915ad7befaf | 851:e7ee5f8bde58 |
---|---|
937 #define xnew_array(type, len) ((type *) xmalloc ((len) * sizeof (type))) | 937 #define xnew_array(type, len) ((type *) xmalloc ((len) * sizeof (type))) |
938 #define xnew_and_zero(type) ((type *) xmalloc_and_zero (sizeof (type))) | 938 #define xnew_and_zero(type) ((type *) xmalloc_and_zero (sizeof (type))) |
939 #define xzero(lvalue) ((void) memset (&(lvalue), '\0', sizeof (lvalue))) | 939 #define xzero(lvalue) ((void) memset (&(lvalue), '\0', sizeof (lvalue))) |
940 #define xnew_array_and_zero(type, len) ((type *) xmalloc_and_zero ((len) * sizeof (type))) | 940 #define xnew_array_and_zero(type, len) ((type *) xmalloc_and_zero ((len) * sizeof (type))) |
941 #define XREALLOC_ARRAY(ptr, type, len) ((void) (ptr = (type *) xrealloc (ptr, (len) * sizeof (type)))) | 941 #define XREALLOC_ARRAY(ptr, type, len) ((void) (ptr = (type *) xrealloc (ptr, (len) * sizeof (type)))) |
942 #define alloca_new(type) ((type *) alloca (sizeof (type))) | 942 #define alloca_new(type) ((type *) ALLOCA (sizeof (type))) |
943 #define alloca_array(type, len) ((type *) alloca ((len) * sizeof (type))) | 943 #define alloca_array(type, len) ((type *) ALLOCA ((len) * sizeof (type))) |
944 | |
945 void *xemacs_c_alloca (unsigned int size); | |
946 | |
947 int record_unwind_protect_freeing (void *ptr); | |
948 | |
949 DECLARE_INLINE_HEADER ( | |
950 void * | |
951 xmalloc_and_record_unwind (Bytecount size) | |
952 ) | |
953 { | |
954 void *ptr = xmalloc (size); | |
955 record_unwind_protect_freeing (ptr); | |
956 return ptr; | |
957 } | |
958 | |
959 /* Stack allocation. | |
960 | |
961 Allocating excessively large blocks on the stack can cause crashes. | |
962 We provide MALLOC_OR_ALLOCA() below for places where it's likely that | |
963 large amounts will be allocated; it mallocs the block if it's too big. | |
964 Unfortunately, that requires a call to unbind_to() at the end of the | |
965 function, and it's not feasible to rewrite all calls to alloca() this | |
966 way. | |
967 | |
968 Instead, we use the portable C alloca() substitute in alloca.c above a | |
969 certain size. This actually uses malloc(), but checks the current stack | |
970 pointer to see if data from previous alloca() calls needs to be freed. | |
971 However, this can lead to large heap sizes -- especially since cleanup | |
972 can only happen in a parent function, and will never happen if (as will | |
973 often be the case) it's the same function in the same place in the code | |
974 that keeps tripping the alloca() limit. | |
975 | |
976 So we set up a system to periodically force cleanup. Currently we | |
977 do cleanup: | |
978 | |
979 -- Only when there's C alloca() data, and then | |
980 -- Every stack alloca() or allocation of Lisp data, every call to | |
981 next_event_internal() [typically near the top of the stack], | |
982 or every 10th funcall | |
983 | |
984 This should not be a big penalty because | |
985 | |
986 (a) If there are few C alloca() chunks, checking them will be fast | |
987 (b) If not, we've allocated a huge amount of heap space (remember, each | |
988 chunk represents > 256K of heap), and we really want them gone | |
989 */ | |
990 | |
991 /* We use a larger maximum when the choice is alloca() vs. the C alloca() | |
992 substitute than when the choice is vs. malloc(), because in the former | |
993 case, our alternative choice is less palatable because the memory may | |
994 not be freed for awhile. */ | |
995 | |
996 #define MAX_ALLOCA_VS_C_ALLOCA 262144 | |
997 #define MAX_ALLOCA_VS_MALLOC 65536 | |
998 | |
999 #define MAX_FUNCALLS_BETWEEN_ALLOCA_CLEANUP 10 | |
1000 | |
1001 extern Bytecount __temp_alloca_size__; | |
1002 extern Bytecount funcall_alloca_count; | |
1003 | |
1004 /* Do stack or heap alloca() depending on size. | |
1005 | |
1006 NOTE: The use of a global temporary like this is unsafe if ALLOCA() occurs | |
1007 twice anywhere in the same expression; but that seems highly unlikely. The | |
1008 alternative is to force all callers to declare a local temporary if the | |
1009 expression has side effects -- something easy to forget. */ | |
1010 | |
1011 #define ALLOCA(size) \ | |
1012 (__temp_alloca_size__ = (size), \ | |
1013 __temp_alloca_size__ > MAX_ALLOCA_VS_C_ALLOCA ? \ | |
1014 xemacs_c_alloca (__temp_alloca_size__) : \ | |
1015 (need_to_check_c_alloca ? xemacs_c_alloca (0) : 0, \ | |
1016 alloca (__temp_alloca_size__))) | |
1017 | |
1018 /* WARNING: If you use this, you must unbind_to() at the end of your | |
1019 function! */ | |
1020 | |
1021 #define MALLOC_OR_ALLOCA(size) \ | |
1022 (__temp_alloca_size__ = (size), \ | |
1023 __temp_alloca_size__ > MAX_ALLOCA_VS_MALLOC ? \ | |
1024 xmalloc_and_record_unwind (__temp_alloca_size__) : \ | |
1025 (need_to_check_c_alloca ? xemacs_c_alloca (0) : 0, \ | |
1026 alloca (__temp_alloca_size__))) | |
944 | 1027 |
945 /* also generally useful if you want to avoid arbitrary size limits | 1028 /* also generally useful if you want to avoid arbitrary size limits |
946 but don't need a full dynamic array. Assumes that BASEVAR points | 1029 but don't need a full dynamic array. Assumes that BASEVAR points |
947 to a malloced array of TYPE objects (or possibly a NULL pointer, | 1030 to a malloced array of TYPE objects (or possibly a NULL pointer, |
948 if SIZEVAR is 0), with the total size stored in SIZEVAR. This | 1031 if SIZEVAR is 0), with the total size stored in SIZEVAR. This |
1927 Intbyte *data_; | 2010 Intbyte *data_; |
1928 Lisp_Object plist; | 2011 Lisp_Object plist; |
1929 }; | 2012 }; |
1930 typedef struct Lisp_String Lisp_String; | 2013 typedef struct Lisp_String Lisp_String; |
1931 | 2014 |
1932 #define MAX_STRING_ASCII_BEGIN ((2 << 21) - 1) | 2015 #define MAX_STRING_ASCII_BEGIN ((1 << 21) - 1) |
1933 | 2016 |
1934 DECLARE_LRECORD (string, Lisp_String); | 2017 DECLARE_LRECORD (string, Lisp_String); |
1935 #define XSTRING(x) XRECORD (x, string, Lisp_String) | 2018 #define XSTRING(x) XRECORD (x, string, Lisp_String) |
1936 #define wrap_string(p) wrap_record (p, string) | 2019 #define wrap_string(p) wrap_record (p, string) |
1937 #define STRINGP(x) RECORDP (x, string) | 2020 #define STRINGP(x) RECORDP (x, string) |
3119 void mark_conses_in_list (Lisp_Object); | 3202 void mark_conses_in_list (Lisp_Object); |
3120 void free_marker (Lisp_Marker *); | 3203 void free_marker (Lisp_Marker *); |
3121 int object_dead_p (Lisp_Object); | 3204 int object_dead_p (Lisp_Object); |
3122 void mark_object (Lisp_Object obj); | 3205 void mark_object (Lisp_Object obj); |
3123 int marked_p (Lisp_Object obj); | 3206 int marked_p (Lisp_Object obj); |
3207 extern int funcall_allocation_flag; | |
3124 extern int need_to_garbage_collect; | 3208 extern int need_to_garbage_collect; |
3209 extern int need_to_check_c_alloca; | |
3210 void recompute_funcall_allocation_flag (void); | |
3125 | 3211 |
3126 #ifdef MEMORY_USAGE_STATS | 3212 #ifdef MEMORY_USAGE_STATS |
3127 Bytecount malloced_storage_size (void *, Bytecount, struct overhead_stats *); | 3213 Bytecount malloced_storage_size (void *, Bytecount, struct overhead_stats *); |
3128 Bytecount fixed_type_block_overhead (Bytecount); | 3214 Bytecount fixed_type_block_overhead (Bytecount); |
3129 #endif | 3215 #endif |
3589 Lisp_Object condition_case_3 (Lisp_Object, Lisp_Object, Lisp_Object); | 3675 Lisp_Object condition_case_3 (Lisp_Object, Lisp_Object, Lisp_Object); |
3590 Lisp_Object unbind_to_1 (int, Lisp_Object); | 3676 Lisp_Object unbind_to_1 (int, Lisp_Object); |
3591 #define unbind_to(obj) unbind_to_1 (obj, Qnil) | 3677 #define unbind_to(obj) unbind_to_1 (obj, Qnil) |
3592 void specbind (Lisp_Object, Lisp_Object); | 3678 void specbind (Lisp_Object, Lisp_Object); |
3593 int record_unwind_protect (Lisp_Object (*) (Lisp_Object), Lisp_Object); | 3679 int record_unwind_protect (Lisp_Object (*) (Lisp_Object), Lisp_Object); |
3594 int record_unwind_protect_freeing (void *ptr); | |
3595 int record_unwind_protect_freeing_dynarr (void *ptr); | 3680 int record_unwind_protect_freeing_dynarr (void *ptr); |
3596 int internal_bind_int (int *addr, int newval); | 3681 int internal_bind_int (int *addr, int newval); |
3597 int internal_bind_lisp_object (Lisp_Object *addr, Lisp_Object newval); | 3682 int internal_bind_lisp_object (Lisp_Object *addr, Lisp_Object newval); |
3598 void do_autoload (Lisp_Object, Lisp_Object); | 3683 void do_autoload (Lisp_Object, Lisp_Object); |
3599 Lisp_Object un_autoload (Lisp_Object); | 3684 Lisp_Object un_autoload (Lisp_Object); |