int undo_limit;
int undo_strong_limit;
+int total_conses, total_markers, total_symbols, total_string_size, total_vector_size;
+int total_free_conses, total_free_markers, total_free_symbols;
+#ifdef LISP_FLOAT_TYPE
+int total_free_floats, total_floats;
+#endif /* LISP_FLOAT_TYPE */
+
/* Points to memory space allocated as "spare",
to be freed if we run out of memory. */
static char *spare_memory;
}
/* malloc calls this if it finds we are near exhausting storage */
+
+void
malloc_warning (str)
char *str;
{
pending_malloc_warning = str;
}
+void
display_malloc_warning ()
{
register Lisp_Object val;
/* Called if malloc returns zero */
+void
memory_full ()
{
#ifndef SYSTEM_MALLOC
/* This used to call error, but if we've run out of memory, we could get
infinite recursion trying to build the string. */
while (1)
- Fsignal (Qerror, memory_signal_data);
+ Fsignal (Qnil, memory_signal_data);
}
/* Called if we can't allocate relocatable space for a buffer. */
#define MARK_INTERVAL_TREE(i) \
do { \
if (!NULL_INTERVAL_P (i) \
- && ! XMARKBIT ((Lisp_Object) i->parent)) \
+ && ! XMARKBIT (*(Lisp_Object *) &i->parent)) \
mark_interval_tree (i); \
} while (0)
free_float (ptr)
struct Lisp_Float *ptr;
{
- *(struct Lisp_Float **)&ptr->type = float_free_list;
+ *(struct Lisp_Float **)&ptr->data = float_free_list;
float_free_list = ptr;
}
if (float_free_list)
{
+ /* We use the data field for chaining the free list
+ so that we won't use the same field that has the mark bit. */
XSETFLOAT (val, float_free_list);
- float_free_list = *(struct Lisp_Float **)&float_free_list->type;
+ float_free_list = *(struct Lisp_Float **)&float_free_list->data;
}
else
{
}
/* Explicitly free a cons cell. */
+
+void
free_cons (ptr)
struct Lisp_Cons *ptr;
{
- *(struct Lisp_Cons **)&ptr->car = cons_free_list;
+ *(struct Lisp_Cons **)&ptr->cdr = cons_free_list;
cons_free_list = ptr;
}
if (cons_free_list)
{
+ /* We use the cdr for chaining the free list
+ so that we won't use the same field that has the mark bit. */
XSETCONS (val, cons_free_list);
- cons_free_list = *(struct Lisp_Cons **)&cons_free_list->car;
+ cons_free_list = *(struct Lisp_Cons **)&cons_free_list->cdr;
}
else
{
args[index] = Fpurecopy (args[index]);
p->contents[index] = args[index];
}
- XSETCOMPILED (val, val);
+ XSETCOMPILED (val, p);
return val;
}
\f
p->insertion_type = 0;
return val;
}
+
+/* Put MARKER back on the free list after using it temporarily. */
+
+void
+free_marker (marker)
+ Lisp_Object marker;
+{
+ unchain_marker (marker);
+
+ XMISC (marker)->u_marker.type = Lisp_Misc_Free;
+ XMISC (marker)->u_free.chain = marker_free_list;
+ marker_free_list = XMISC (marker);
+
+ total_free_markers++;
+}
\f
/* Allocation of strings */
{
Lisp_Object result;
- result = Fmake_string (nargs, make_number (0));
+ result = Fmake_string (make_number (nargs), make_number (0));
for (i = 0; i < nargs; i++)
{
XSTRING (result)->data[i] = XINT (args[i]);
\f
/* Garbage collection! */
-int total_conses, total_markers, total_symbols, total_string_size, total_vector_size;
-int total_free_conses, total_free_markers, total_free_symbols;
-#ifdef LISP_FLOAT_TYPE
-int total_free_floats, total_floats;
-#endif /* LISP_FLOAT_TYPE */
-
/* Temporarily prevent garbage collection. */
int
/* Put all unmarked conses on free list */
{
register struct cons_block *cblk;
+ struct cons_block **cprev = &cons_block;
register int lim = cons_block_index;
register int num_free = 0, num_used = 0;
cons_free_list = 0;
- for (cblk = cons_block; cblk; cblk = cblk->next)
+ for (cblk = cons_block; cblk; cblk = *cprev)
{
register int i;
+ int this_free = 0;
for (i = 0; i < lim; i++)
if (!XMARKBIT (cblk->conses[i].car))
{
num_free++;
- *(struct Lisp_Cons **)&cblk->conses[i].car = cons_free_list;
+ this_free++;
+ *(struct Lisp_Cons **)&cblk->conses[i].cdr = cons_free_list;
cons_free_list = &cblk->conses[i];
}
else
XUNMARK (cblk->conses[i].car);
}
lim = CONS_BLOCK_SIZE;
+ /* If this block contains only free conses and we have already
+ seen more than two blocks worth of free conses then deallocate
+ this block. */
+ if (this_free == CONS_BLOCK_SIZE && num_free > 2*CONS_BLOCK_SIZE)
+ {
+ num_free -= CONS_BLOCK_SIZE;
+ *cprev = cblk->next;
+ /* Unhook from the free list. */
+ cons_free_list = *(struct Lisp_Cons **) &cblk->conses[0].cdr;
+ xfree (cblk);
+ }
+ else
+ cprev = &cblk->next;
}
total_conses = num_used;
total_free_conses = num_free;
/* Put all unmarked floats on free list */
{
register struct float_block *fblk;
+ struct float_block **fprev = &float_block;
register int lim = float_block_index;
register int num_free = 0, num_used = 0;
float_free_list = 0;
- for (fblk = float_block; fblk; fblk = fblk->next)
+ for (fblk = float_block; fblk; fblk = *fprev)
{
register int i;
+ int this_free = 0;
for (i = 0; i < lim; i++)
if (!XMARKBIT (fblk->floats[i].type))
{
num_free++;
- *(struct Lisp_Float **)&fblk->floats[i].type = float_free_list;
+ this_free++;
+ *(struct Lisp_Float **)&fblk->floats[i].data = float_free_list;
float_free_list = &fblk->floats[i];
}
else
XUNMARK (fblk->floats[i].type);
}
lim = FLOAT_BLOCK_SIZE;
+ /* If this block contains only free floats and we have already
+ seen more than two blocks worth of free floats then deallocate
+ this block. */
+ if (this_free == FLOAT_BLOCK_SIZE && num_free > 2*FLOAT_BLOCK_SIZE)
+ {
+ num_free -= FLOAT_BLOCK_SIZE;
+ *fprev = fblk->next;
+ /* Unhook from the free list. */
+ float_free_list = *(struct Lisp_Float **) &fblk->floats[0].data;
+ xfree (fblk);
+ }
+ else
+ fprev = &fblk->next;
}
total_floats = num_used;
total_free_floats = num_free;
/* Put all unmarked intervals on free list */
{
register struct interval_block *iblk;
+ struct interval_block **iprev = &interval_block;
register int lim = interval_block_index;
register int num_free = 0, num_used = 0;
interval_free_list = 0;
- for (iblk = interval_block; iblk; iblk = iblk->next)
+ for (iblk = interval_block; iblk; iblk = *iprev)
{
register int i;
+ int this_free = 0;
for (i = 0; i < lim; i++)
{
iblk->intervals[i].parent = interval_free_list;
interval_free_list = &iblk->intervals[i];
num_free++;
+ this_free++;
}
else
{
}
}
lim = INTERVAL_BLOCK_SIZE;
+ /* If this block contains only free intervals and we have already
+ seen more than two blocks worth of free intervals then
+ deallocate this block. */
+ if (this_free == INTERVAL_BLOCK_SIZE
+ && num_free > 2*INTERVAL_BLOCK_SIZE)
+ {
+ num_free -= INTERVAL_BLOCK_SIZE;
+ *iprev = iblk->next;
+ /* Unhook from the free list. */
+ interval_free_list = iblk->intervals[0].parent;
+ xfree (iblk);
+ }
+ else
+ iprev = &iblk->next;
}
total_intervals = num_used;
total_free_intervals = num_free;
/* Put all unmarked symbols on free list */
{
register struct symbol_block *sblk;
+ struct symbol_block **sprev = &symbol_block;
register int lim = symbol_block_index;
register int num_free = 0, num_used = 0;
symbol_free_list = 0;
- for (sblk = symbol_block; sblk; sblk = sblk->next)
+ for (sblk = symbol_block; sblk; sblk = *sprev)
{
register int i;
+ int this_free = 0;
for (i = 0; i < lim; i++)
if (!XMARKBIT (sblk->symbols[i].plist))
{
*(struct Lisp_Symbol **)&sblk->symbols[i].value = symbol_free_list;
symbol_free_list = &sblk->symbols[i];
num_free++;
+ this_free++;
}
else
{
XUNMARK (sblk->symbols[i].plist);
}
lim = SYMBOL_BLOCK_SIZE;
+ /* If this block contains only free symbols and we have already
+ seen more than two blocks worth of free symbols then deallocate
+ this block. */
+ if (this_free == SYMBOL_BLOCK_SIZE && num_free > 2*SYMBOL_BLOCK_SIZE)
+ {
+ num_free -= SYMBOL_BLOCK_SIZE;
+ *sprev = sblk->next;
+ /* Unhook from the free list. */
+ symbol_free_list = *(struct Lisp_Symbol **)&sblk->symbols[0].value;
+ xfree (sblk);
+ }
+ else
+ sprev = &sblk->next;
}
total_symbols = num_used;
total_free_symbols = num_free;
but only if it's a real marker. */
{
register struct marker_block *mblk;
+ struct marker_block **mprev = &marker_block;
register int lim = marker_block_index;
register int num_free = 0, num_used = 0;
marker_free_list = 0;
- for (mblk = marker_block; mblk; mblk = mblk->next)
+ for (mblk = marker_block; mblk; mblk = *mprev)
{
register int i;
+ int this_free = 0;
EMACS_INT already_free = -1;
for (i = 0; i < lim; i++)
case Lisp_Misc_Free:
/* If the object was already free, keep it
on the free list. */
- markword = &already_free;
+ markword = (Lisp_Object *) &already_free;
break;
default:
markword = 0;
mblk->markers[i].u_free.chain = marker_free_list;
marker_free_list = &mblk->markers[i];
num_free++;
+ this_free++;
}
else
{
}
}
lim = MARKER_BLOCK_SIZE;
+ /* If this block contains only free markers and we have already
+ seen more than two blocks worth of free markers then deallocate
+ this block. */
+ if (this_free == MARKER_BLOCK_SIZE && num_free > 2*MARKER_BLOCK_SIZE)
+ {
+ num_free -= MARKER_BLOCK_SIZE;
+ *mprev = mblk->next;
+ /* Unhook from the free list. */
+ marker_free_list = mblk->markers[0].u_free.chain;
+ xfree (mblk);
+ }
+ else
+ mprev = &mblk->next;
}
total_markers = num_used;