Change the parser and compiler to use PyMalloc.

Only the files implementing processes that will request memory
allocations small enough for PyMalloc to be a win have been
changed, which are:-
 - Python/compile.c
 - Parser/acceler.c
 - Parser/node.c
 - Parser/parsetok.c

This augments the aggressive overallocation strategy implemented by
Tim Peters in PyNode_AddChild() [Parser/node.c], in reducing the
impact of platform malloc()/realloc()/free() corner case behaviour.
Such corner cases are known to be triggered by test_longexp and
test_import.

Jeremy Hylton, in accepting this patch, recommended this as a
bugfix candidate for 2.2.  While the changes to Python/compile.c
and Parser/node.c backport easily (and could go in), the changes
to Parser/acceler.c and Parser/parsetok.c require other not
insignificant changes as a result of the differences in the memory
APIs between 2.3 and 2.2, which I'm not in a position to work
through at the moment.  This is a pity, as the Parser/parsetok.c
changes are the most important after the Parser/node.c changes, due
to the size of the memory requests involved and their frequency.
This commit is contained in:
Andrew MacIntyre 2002-08-04 06:28:21 +00:00
parent 4104db39b8
commit 80d4e2acf5
4 changed files with 20 additions and 19 deletions

View file

@ -44,7 +44,7 @@ PyGrammar_RemoveAccelerators(grammar *g)
s = d->d_state;
for (j = 0; j < d->d_nstates; j++, s++) {
if (s->s_accel)
PyMem_DEL(s->s_accel);
PyObject_FREE(s->s_accel);
s->s_accel = NULL;
}
}
@ -68,7 +68,7 @@ fixstate(grammar *g, state *s)
int *accel;
int nl = g->g_ll.ll_nlabels;
s->s_accept = 0;
accel = PyMem_NEW(int, nl);
accel = (int *) PyObject_MALLOC(nl * sizeof(int));
for (k = 0; k < nl; k++)
accel[k] = -1;
a = s->s_arc;
@ -124,7 +124,7 @@ fixstate(grammar *g, state *s)
k++;
if (k < nl) {
int i;
s->s_accel = PyMem_NEW(int, nl-k);
s->s_accel = (int *) PyObject_MALLOC((nl-k) * sizeof(int));
if (s->s_accel == NULL) {
fprintf(stderr, "no mem to add parser accelerators\n");
exit(1);
@ -134,5 +134,5 @@ fixstate(grammar *g, state *s)
for (i = 0; k < nl; i++, k++)
s->s_accel[i] = accel[k];
}
PyMem_DEL(accel);
PyObject_FREE(accel);
}