2007-09-29 Stefan Monnier <monnier@iro.umontreal.ca>
+ * alloc.c (MALLOC_BLOCK_INPUT, MALLOC_UNBLOCK_INPUT): New macros
+ to avoid unnecessary BLOCK_INPUTs when SYNC_INPUT is used.
+ (xmalloc, xrealloc, xfree, lisp_malloc, lisp_free, lisp_align_malloc)
+ (lisp_align_free, make_interval, allocate_string, allocate_string_data)
+ (make_float, Fcons, allocate_vectorlike, Fmake_symbol, allocate_misc):
+ Use them.
+
* xfaces.c (load_face_font, free_realized_face, clear_face_gcs):
Don't let signal handlers run when a GC is freed but not yet NULL'ed.
(x_free_gc): Remove BLOCK_INPUT since it's now redundant.
#define free overrun_check_free
#endif
+#ifdef SYNC_INPUT
+/* When using SYNC_INPUT, we don't call malloc from a signal handler, so
+ there's no need to block input around malloc. */
+#define MALLOC_BLOCK_INPUT ((void)0)
+#define MALLOC_UNBLOCK_INPUT ((void)0)
+#else
+#define MALLOC_BLOCK_INPUT BLOCK_INPUT
+#define MALLOC_UNBLOCK_INPUT UNBLOCK_INPUT
+#endif
/* Like malloc but check for no memory and block interrupt input.. */
{
register POINTER_TYPE *val;
- BLOCK_INPUT;
+ MALLOC_BLOCK_INPUT;
val = (POINTER_TYPE *) malloc (size);
- UNBLOCK_INPUT;
+ MALLOC_UNBLOCK_INPUT;
if (!val && size)
memory_full ();
{
register POINTER_TYPE *val;
- BLOCK_INPUT;
+ MALLOC_BLOCK_INPUT;
/* We must call malloc explicitly when BLOCK is 0, since some
reallocs don't do this. */
if (! block)
val = (POINTER_TYPE *) malloc (size);
else
val = (POINTER_TYPE *) realloc (block, size);
- UNBLOCK_INPUT;
+ MALLOC_UNBLOCK_INPUT;
if (!val && size) memory_full ();
return val;
xfree (block)
POINTER_TYPE *block;
{
- BLOCK_INPUT;
+ MALLOC_BLOCK_INPUT;
free (block);
- UNBLOCK_INPUT;
+ MALLOC_UNBLOCK_INPUT;
/* We don't call refill_memory_reserve here
because that duplicates doing so in emacs_blocked_free
and the criterion should go there. */
{
register void *val;
- BLOCK_INPUT;
+ MALLOC_BLOCK_INPUT;
#ifdef GC_MALLOC_CHECK
allocated_mem_type = type;
mem_insert (val, (char *) val + nbytes, type);
#endif
- UNBLOCK_INPUT;
+ MALLOC_UNBLOCK_INPUT;
if (!val && nbytes)
memory_full ();
return val;
lisp_free (block)
POINTER_TYPE *block;
{
- BLOCK_INPUT;
+ MALLOC_BLOCK_INPUT;
free (block);
#if GC_MARK_STACK && !defined GC_MALLOC_CHECK
mem_delete (mem_find (block));
#endif
- UNBLOCK_INPUT;
+ MALLOC_UNBLOCK_INPUT;
}
/* Allocation of aligned blocks of memory to store Lisp data. */
eassert (nbytes <= BLOCK_BYTES);
- BLOCK_INPUT;
+ MALLOC_BLOCK_INPUT;
#ifdef GC_MALLOC_CHECK
allocated_mem_type = type;
if (base == 0)
{
- UNBLOCK_INPUT;
+ MALLOC_UNBLOCK_INPUT;
memory_full ();
}
{
lisp_malloc_loser = base;
free (base);
- UNBLOCK_INPUT;
+ MALLOC_UNBLOCK_INPUT;
memory_full ();
}
}
mem_insert (val, (char *) val + nbytes, type);
#endif
- UNBLOCK_INPUT;
+ MALLOC_UNBLOCK_INPUT;
if (!val && nbytes)
memory_full ();
struct ablock *ablock = block;
struct ablocks *abase = ABLOCK_ABASE (ablock);
- BLOCK_INPUT;
+ MALLOC_BLOCK_INPUT;
#if GC_MARK_STACK && !defined GC_MALLOC_CHECK
mem_delete (mem_find (block));
#endif
#endif
free (ABLOCKS_BASE (abase));
}
- UNBLOCK_INPUT;
+ MALLOC_UNBLOCK_INPUT;
}
/* Return a new buffer structure allocated from the heap with
can use GNU malloc. */
#ifndef SYNC_INPUT
+/* When using SYNC_INPUT, we don't call malloc from a signal handler, so
+ there's no need to block input around malloc. */
#ifndef DOUG_LEA_MALLOC
extern void * (*__malloc_hook) P_ ((size_t, const void *));
/* eassert (!handling_signal); */
-#ifndef SYNC_INPUT
- BLOCK_INPUT;
-#endif
+ MALLOC_BLOCK_INPUT;
if (interval_free_list)
{
val = &interval_block->intervals[interval_block_index++];
}
-#ifndef SYNC_INPUT
- UNBLOCK_INPUT;
-#endif
+ MALLOC_UNBLOCK_INPUT;
consing_since_gc += sizeof (struct interval);
intervals_consed++;
/* eassert (!handling_signal); */
-#ifndef SYNC_INPUT
- BLOCK_INPUT;
-#endif
+ MALLOC_BLOCK_INPUT;
/* If the free-list is empty, allocate a new string_block, and
add all the Lisp_Strings in it to the free-list. */
s = string_free_list;
string_free_list = NEXT_FREE_LISP_STRING (s);
-#ifndef SYNC_INPUT
- UNBLOCK_INPUT;
-#endif
+ MALLOC_UNBLOCK_INPUT;
/* Probably not strictly necessary, but play it safe. */
bzero (s, sizeof *s);
old_data = s->data ? SDATA_OF_STRING (s) : NULL;
old_nbytes = GC_STRING_BYTES (s);
-#ifndef SYNC_INPUT
- BLOCK_INPUT;
-#endif
+ MALLOC_BLOCK_INPUT;
if (nbytes > LARGE_STRING_BYTES)
{
mmap'ed data typically have an address towards the top of the
address space, which won't fit into an EMACS_INT (at least on
32-bit systems with the current tagging scheme). --fx */
- BLOCK_INPUT;
mallopt (M_MMAP_MAX, 0);
- UNBLOCK_INPUT;
#endif
b = (struct sblock *) lisp_malloc (size + GC_STRING_EXTRA, MEM_TYPE_NON_LISP);
#ifdef DOUG_LEA_MALLOC
/* Back to a reasonable maximum of mmap'ed areas. */
- BLOCK_INPUT;
mallopt (M_MMAP_MAX, MMAP_MAX_AREAS);
- UNBLOCK_INPUT;
#endif
b->next_free = &b->first_data;
data = b->next_free;
b->next_free = (struct sdata *) ((char *) data + needed + GC_STRING_EXTRA);
-#ifndef SYNC_INPUT
- UNBLOCK_INPUT;
-#endif
+ MALLOC_UNBLOCK_INPUT;
data->string = s;
s->data = SDATA_DATA (data);
/* eassert (!handling_signal); */
-#ifndef SYNC_INPUT
- BLOCK_INPUT;
-#endif
+ MALLOC_BLOCK_INPUT;
if (float_free_list)
{
float_block_index++;
}
-#ifndef SYNC_INPUT
- UNBLOCK_INPUT;
-#endif
+ MALLOC_UNBLOCK_INPUT;
XFLOAT_DATA (val) = float_value;
eassert (!FLOAT_MARKED_P (XFLOAT (val)));
/* eassert (!handling_signal); */
-#ifndef SYNC_INPUT
- BLOCK_INPUT;
-#endif
+ MALLOC_BLOCK_INPUT;
if (cons_free_list)
{
cons_block_index++;
}
-#ifndef SYNC_INPUT
- UNBLOCK_INPUT;
-#endif
+ MALLOC_UNBLOCK_INPUT;
XSETCAR (val, car);
XSETCDR (val, cdr);
struct Lisp_Vector *p;
size_t nbytes;
+ MALLOC_BLOCK_INPUT;
+
#ifdef DOUG_LEA_MALLOC
/* Prevent mmap'ing the chunk. Lisp data may not be mmap'ed
because mapped region contents are not preserved in
a dumped Emacs. */
- BLOCK_INPUT;
mallopt (M_MMAP_MAX, 0);
- UNBLOCK_INPUT;
#endif
/* This gets triggered by code which I haven't bothered to fix. --Stef */
#ifdef DOUG_LEA_MALLOC
/* Back to a reasonable maximum of mmap'ed areas. */
- BLOCK_INPUT;
mallopt (M_MMAP_MAX, MMAP_MAX_AREAS);
- UNBLOCK_INPUT;
#endif
consing_since_gc += nbytes;
vector_cells_consed += len;
-#ifndef SYNC_INPUT
- BLOCK_INPUT;
-#endif
-
p->next = all_vectors;
all_vectors = p;
-#ifndef SYNC_INPUT
- UNBLOCK_INPUT;
-#endif
+ MALLOC_UNBLOCK_INPUT;
++n_vectors;
return p;
/* eassert (!handling_signal); */
-#ifndef SYNC_INPUT
- BLOCK_INPUT;
-#endif
+ MALLOC_BLOCK_INPUT;
if (symbol_free_list)
{
symbol_block_index++;
}
-#ifndef SYNC_INPUT
- UNBLOCK_INPUT;
-#endif
+ MALLOC_UNBLOCK_INPUT;
p = XSYMBOL (val);
p->xname = name;
/* eassert (!handling_signal); */
-#ifndef SYNC_INPUT
- BLOCK_INPUT;
-#endif
+ MALLOC_BLOCK_INPUT;
if (marker_free_list)
{
marker_block_index++;
}
-#ifndef SYNC_INPUT
- UNBLOCK_INPUT;
-#endif
+ MALLOC_UNBLOCK_INPUT;
--total_free_markers;
consing_since_gc += sizeof (union Lisp_Misc);