diff options
| author | Tom Tromey <tromey@redhat.com> | 2012-09-04 10:10:06 -0600 |
|---|---|---|
| committer | Tom Tromey <tromey@redhat.com> | 2012-09-04 10:10:06 -0600 |
| commit | bf69f522a9e135f9aa483cedd53e71e915f2bf75 (patch) | |
| tree | 3f73c47fb863ef87f420de1d30858da821072bd9 /src/alloc.c | |
| parent | 303324a9232dbc89369faceb6b3530740d0fc1bd (diff) | |
| parent | 6ec9a5a7b5efb129807f567709ca858211ed7840 (diff) | |
| download | emacs-bf69f522a9e135f9aa483cedd53e71e915f2bf75.tar.gz | |
merge from trunk
Diffstat (limited to 'src/alloc.c')
| -rw-r--r-- | src/alloc.c | 121 |
1 files changed, 66 insertions, 55 deletions
diff --git a/src/alloc.c b/src/alloc.c index a8830684580..859961781e0 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -69,6 +69,9 @@ extern void *sbrk (); #include <fcntl.h> +#ifdef USE_GTK +# include "gtkutil.h" +#endif #ifdef WINDOWSNT #include "w32.h" #endif @@ -173,15 +176,15 @@ EMACS_INT gc_relative_threshold; EMACS_INT memory_full_cons_threshold; -/* Nonzero during GC. */ +/* True during GC. */ -int gc_in_progress; +bool gc_in_progress; -/* Nonzero means abort if try to GC. +/* True means abort if try to GC. This is for code which is written on the assumption that no GC will happen, so as to verify that assumption. */ -int abort_on_gc; +bool abort_on_gc; /* Number of live and free conses etc. */ @@ -223,7 +226,7 @@ static ptrdiff_t pure_size; static ptrdiff_t pure_bytes_used_before_overflow; -/* Value is non-zero if P points into pure space. */ +/* True if P points into pure space. */ #define PURE_POINTER_P(P) \ ((uintptr_t) (P) - (uintptr_t) purebeg <= pure_size) @@ -305,7 +308,9 @@ enum mem_type and runtime slowdown. Minor but pointless. */ MEM_TYPE_VECTORLIKE, /* Special type to denote vector blocks. */ - MEM_TYPE_VECTOR_BLOCK + MEM_TYPE_VECTOR_BLOCK, + /* Special type to denote reserved memory. */ + MEM_TYPE_SPARE }; static void *lisp_malloc (size_t, enum mem_type); @@ -387,13 +392,13 @@ static struct mem_node mem_z; static struct Lisp_Vector *allocate_vectorlike (ptrdiff_t); static void lisp_free (void *); -static int live_vector_p (struct mem_node *, void *); -static int live_buffer_p (struct mem_node *, void *); -static int live_string_p (struct mem_node *, void *); -static int live_cons_p (struct mem_node *, void *); -static int live_symbol_p (struct mem_node *, void *); -static int live_float_p (struct mem_node *, void *); -static int live_misc_p (struct mem_node *, void *); +static bool live_vector_p (struct mem_node *, void *); +static bool live_buffer_p (struct mem_node *, void *); +static bool live_string_p (struct mem_node *, void *); +static bool live_cons_p (struct mem_node *, void *); +static bool live_symbol_p (struct mem_node *, void *); +static bool live_float_p (struct mem_node *, void *); +static bool live_misc_p (struct mem_node *, void *); static void mark_maybe_object (Lisp_Object); static void mark_memory (void *, void *); #if GC_MARK_STACK || defined GC_MALLOC_CHECK @@ -1232,7 +1237,7 @@ static void (*old_free_hook) (void*, const void*); #endif #ifdef GC_MALLOC_CHECK -static int dont_register_blocks; +static bool dont_register_blocks; #endif static size_t bytes_used_when_reconsidered; @@ -1819,11 +1824,11 @@ check_sblock (struct sblock *b) /* Check validity of Lisp strings' string_bytes member. ALL_P - non-zero means check all strings, otherwise check only most + means check all strings, otherwise check only most recently allocated strings. Used for hunting a bug. */ static void -check_string_bytes (int all_p) +check_string_bytes (bool all_p) { if (all_p) { @@ -2428,9 +2433,9 @@ make_string_from_bytes (const char *contents, Lisp_Object make_specified_string (const char *contents, - ptrdiff_t nchars, ptrdiff_t nbytes, int multibyte) + ptrdiff_t nchars, ptrdiff_t nbytes, bool multibyte) { - register Lisp_Object val; + Lisp_Object val; if (nchars < 0) { @@ -3085,7 +3090,7 @@ sweep_vectors (void) for (block = vector_blocks; block; block = *bprev) { - int free_this_block = 0; + bool free_this_block = 0; for (vector = (struct Lisp_Vector *) block->data; VECTOR_IN_BLOCK (vector, block); vector = next) @@ -3751,7 +3756,7 @@ void memory_full (size_t nbytes) { /* Do not go into hysterics merely because a large request failed. */ - int enough_free_memory = 0; + bool enough_free_memory = 0; if (SPARE_MEMORY < nbytes) { void *p; @@ -3814,22 +3819,22 @@ refill_memory_reserve (void) spare_memory[0] = malloc (SPARE_MEMORY); if (spare_memory[1] == 0) spare_memory[1] = lisp_align_malloc (sizeof (struct cons_block), - MEM_TYPE_CONS); + MEM_TYPE_SPARE); if (spare_memory[2] == 0) spare_memory[2] = lisp_align_malloc (sizeof (struct cons_block), - MEM_TYPE_CONS); + MEM_TYPE_SPARE); if (spare_memory[3] == 0) spare_memory[3] = lisp_align_malloc (sizeof (struct cons_block), - MEM_TYPE_CONS); + MEM_TYPE_SPARE); if (spare_memory[4] == 0) spare_memory[4] = lisp_align_malloc (sizeof (struct cons_block), - MEM_TYPE_CONS); + MEM_TYPE_SPARE); if (spare_memory[5] == 0) spare_memory[5] = lisp_malloc (sizeof (struct string_block), - MEM_TYPE_STRING); + MEM_TYPE_SPARE); if (spare_memory[6] == 0) spare_memory[6] = lisp_malloc (sizeof (struct string_block), - MEM_TYPE_STRING); + MEM_TYPE_SPARE); if (spare_memory[0] && spare_memory[1] && spare_memory[5]) Vmemory_full = Qnil; #endif @@ -4244,7 +4249,7 @@ mem_delete_fixup (struct mem_node *x) /* Value is non-zero if P is a pointer to a live Lisp string on the heap. M is a pointer to the mem_block for P. */ -static inline int +static inline bool live_string_p (struct mem_node *m, void *p) { if (m->type == MEM_TYPE_STRING) @@ -4267,7 +4272,7 @@ live_string_p (struct mem_node *m, void *p) /* Value is non-zero if P is a pointer to a live Lisp cons on the heap. M is a pointer to the mem_block for P. */ -static inline int +static inline bool live_cons_p (struct mem_node *m, void *p) { if (m->type == MEM_TYPE_CONS) @@ -4293,7 +4298,7 @@ live_cons_p (struct mem_node *m, void *p) /* Value is non-zero if P is a pointer to a live Lisp symbol on the heap. M is a pointer to the mem_block for P. */ -static inline int +static inline bool live_symbol_p (struct mem_node *m, void *p) { if (m->type == MEM_TYPE_SYMBOL) @@ -4319,7 +4324,7 @@ live_symbol_p (struct mem_node *m, void *p) /* Value is non-zero if P is a pointer to a live Lisp float on the heap. M is a pointer to the mem_block for P. */ -static inline int +static inline bool live_float_p (struct mem_node *m, void *p) { if (m->type == MEM_TYPE_FLOAT) @@ -4343,7 +4348,7 @@ live_float_p (struct mem_node *m, void *p) /* Value is non-zero if P is a pointer to a live Lisp Misc on the heap. M is a pointer to the mem_block for P. */ -static inline int +static inline bool live_misc_p (struct mem_node *m, void *p) { if (m->type == MEM_TYPE_MISC) @@ -4369,7 +4374,7 @@ live_misc_p (struct mem_node *m, void *p) /* Value is non-zero if P is a pointer to a live vector-like object. M is a pointer to the mem_block for P. */ -static inline int +static inline bool live_vector_p (struct mem_node *m, void *p) { if (m->type == MEM_TYPE_VECTOR_BLOCK) @@ -4405,7 +4410,7 @@ live_vector_p (struct mem_node *m, void *p) /* Value is non-zero if P is a pointer to a live buffer. M is a pointer to the mem_block for P. */ -static inline int +static inline bool live_buffer_p (struct mem_node *m, void *p) { /* P must point to the start of the block, and the buffer @@ -4485,7 +4490,7 @@ mark_maybe_object (Lisp_Object obj) if (m != MEM_NIL) { - int mark_p = 0; + bool mark_p = 0; switch (XTYPE (obj)) { @@ -4559,6 +4564,7 @@ mark_maybe_pointer (void *p) switch (m->type) { case MEM_TYPE_NON_LISP: + case MEM_TYPE_SPARE: /* Nothing to do; not a pointer to Lisp memory. */ break; @@ -4705,7 +4711,8 @@ mark_memory (void *start, void *end) #if !defined GC_SAVE_REGISTERS_ON_STACK && !defined GC_SETJMP_WORKS -static int setjmp_tested_p, longjmps_done; +static bool setjmp_tested_p; +static int longjmps_done; #define SETJMP_WILL_LIKELY_WORK "\ \n\ @@ -4749,14 +4756,13 @@ test_setjmp (void) char buf[10]; register int x; jmp_buf jbuf; - int result = 0; /* Arrange for X to be put in a register. */ sprintf (buf, "1"); x = strlen (buf); x = 2 * x - 1; - setjmp (jbuf); + _setjmp (jbuf); if (longjmps_done == 1) { /* Came here after the longjmp at the end of the function. @@ -4781,7 +4787,7 @@ test_setjmp (void) ++longjmps_done; x = 2; if (longjmps_done == 1) - longjmp (jbuf, 1); + _longjmp (jbuf, 1); } #endif /* not GC_SAVE_REGISTERS_ON_STACK && not GC_SETJMP_WORKS */ @@ -4908,7 +4914,7 @@ flush_stack_call_func (void (*func) (void *arg), void *arg) Lisp_Object o; jmp_buf j; } j; - volatile int stack_grows_down_p = (char *) &j > (char *) stack_bottom; + volatile bool stack_grows_down_p = (char *) &j > (char *) stack_bottom; #endif /* This trick flushes the register windows so that all the state of the process is contained in the stack. */ @@ -4942,7 +4948,7 @@ flush_stack_call_func (void (*func) (void *arg), void *arg) } #endif /* GC_SETJMP_WORKS */ - setjmp (j.j); + _setjmp (j.j); end = stack_grows_down_p ? (char *) &j + sizeof j : (char *) &j; #endif /* not GC_SAVE_REGISTERS_ON_STACK */ #endif /* not HAVE___BUILTIN_UNWIND_INIT */ @@ -4970,7 +4976,7 @@ valid_pointer_p (void *p) if (pipe (fd) == 0) { - int valid = (emacs_write (fd[1], (char *) p, 16) == 16); + bool valid = emacs_write (fd[1], (char *) p, 16) == 16; emacs_close (fd[1]); emacs_close (fd[0]); return valid; @@ -5022,6 +5028,7 @@ valid_lisp_object_p (Lisp_Object obj) switch (m->type) { case MEM_TYPE_NON_LISP: + case MEM_TYPE_SPARE: return 0; case MEM_TYPE_BUFFER: @@ -5191,7 +5198,7 @@ find_string_data_in_pure (const char *data, ptrdiff_t nbytes) /* Return a string allocated in pure space. DATA is a buffer holding NCHARS characters, and NBYTES bytes of string data. MULTIBYTE - non-zero means make the result string multibyte. + means make the result string multibyte. Must get an error if pure storage is full, since if it cannot hold a large string it may be able to hold conses that point to that @@ -5199,7 +5206,7 @@ find_string_data_in_pure (const char *data, ptrdiff_t nbytes) Lisp_Object make_pure_string (const char *data, - ptrdiff_t nchars, ptrdiff_t nbytes, int multibyte) + ptrdiff_t nchars, ptrdiff_t nbytes, bool multibyte) { Lisp_Object string; struct Lisp_String *s = pure_alloc (sizeof *s, Lisp_String); @@ -5394,11 +5401,11 @@ returns nil, because real GC can't be done. See Info node `(elisp)Garbage Collection'. */) (void) { - register struct specbinding *bind; - register struct buffer *nextb; + struct specbinding *bind; + struct buffer *nextb; char stack_top_variable; ptrdiff_t i; - int message_p; + bool message_p; ptrdiff_t count = SPECPDL_INDEX (); EMACS_TIME start; Lisp_Object retval = Qnil; @@ -5473,13 +5480,9 @@ See Info node `(elisp)Garbage Collection'. */) mark_threads (); mark_terminals (); mark_kboards (); - mark_ttys (); #ifdef USE_GTK - { - extern void xg_mark_data (void); - xg_mark_data (); - } + xg_mark_data (); #endif #ifdef HAVE_WINDOW_SYSTEM @@ -6181,10 +6184,10 @@ mark_terminals (void) /* Value is non-zero if OBJ will survive the current GC because it's either marked or does not need to be marked to survive. */ -int +bool survives_gc_p (Lisp_Object obj) { - int survives_p; + bool survives_p; switch (XTYPE (obj)) { @@ -6429,7 +6432,7 @@ gc_sweep (void) /* Check if the symbol was created during loadup. In such a case it might be pointed to by pure bytecode which we don't trace, so we conservatively assume that it is live. */ - int pure_p = PURE_POINTER_P (XSTRING (sym->s.name)); + bool pure_p = PURE_POINTER_P (XSTRING (sym->s.name)); if (!sym->s.gcmarkbit && !pure_p) { @@ -6654,13 +6657,21 @@ which_symbols (Lisp_Object obj, EMACS_INT find_max) } #ifdef ENABLE_CHECKING -int suppress_checking; + +# include <execinfo.h> + +bool suppress_checking; void die (const char *msg, const char *file, int line) { + enum { NPOINTERS_MAX = 500 }; + void *buffer[NPOINTERS_MAX]; + int npointers; fprintf (stderr, "\r\n%s:%d: Emacs fatal error: %s\r\n", file, line, msg); + npointers = backtrace (buffer, NPOINTERS_MAX); + backtrace_symbols_fd (buffer, npointers, STDERR_FILENO); abort (); } #endif |
