summaryrefslogtreecommitdiffstats
path: root/Parser
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2000-05-03 23:44:39 (GMT)
committerGuido van Rossum <guido@python.org>2000-05-03 23:44:39 (GMT)
commitb18618dab7b6b85bb05b084693706e59211fa180 (patch)
tree785d51f6677da8366be2ad4b4296a62f53161276 /Parser
parent2808b744e8d94459f189e1d89c97072d6a1f53b6 (diff)
downloadcpython-b18618dab7b6b85bb05b084693706e59211fa180.zip
cpython-b18618dab7b6b85bb05b084693706e59211fa180.tar.gz
cpython-b18618dab7b6b85bb05b084693706e59211fa180.tar.bz2
Vladimir Marangozov's long-awaited malloc restructuring.
For more comments, read the patches@python.org archives. For documentation read the comments in mymalloc.h and objimpl.h. (This is not exactly what Vladimir posted to the patches list; I've made a few changes, and Vladimir sent me a fix in private email for a problem that only occurs in debug mode. I'm also holding back on his change to main.c, which seems unnecessary to me.)
Diffstat (limited to 'Parser')
-rw-r--r--Parser/myreadline.c12
-rw-r--r--Parser/parsetok.c2
-rw-r--r--Parser/pgenmain.c6
-rw-r--r--Parser/tokenizer.c13
4 files changed, 18 insertions, 15 deletions
diff --git a/Parser/myreadline.c b/Parser/myreadline.c
index d626139..9bf770e 100644
--- a/Parser/myreadline.c
+++ b/Parser/myreadline.c
@@ -89,7 +89,7 @@ PyOS_StdioReadline(prompt)
int n;
char *p;
n = 100;
- if ((p = malloc(n)) == NULL)
+ if ((p = PyMem_MALLOC(n)) == NULL)
return NULL;
fflush(stdout);
if (prompt)
@@ -99,7 +99,7 @@ PyOS_StdioReadline(prompt)
case 0: /* Normal case */
break;
case 1: /* Interrupt */
- free(p);
+ PyMem_FREE(p);
return NULL;
case -1: /* EOF */
case -2: /* Error */
@@ -117,19 +117,21 @@ PyOS_StdioReadline(prompt)
n = strlen(p);
while (n > 0 && p[n-1] != '\n') {
int incr = n+2;
- p = realloc(p, n + incr);
+ p = PyMem_REALLOC(p, n + incr);
if (p == NULL)
return NULL;
if (my_fgets(p+n, incr, stdin) != 0)
break;
n += strlen(p+n);
}
- return realloc(p, n+1);
+ return PyMem_REALLOC(p, n+1);
}
/* By initializing this function pointer, systems embedding Python can
- override the readline function. */
+ override the readline function.
+
+ Note: Python expects in return a buffer allocated with PyMem_Malloc. */
char *(*PyOS_ReadlineFunctionPointer) Py_PROTO((char *));
diff --git a/Parser/parsetok.c b/Parser/parsetok.c
index 5b0d990..6d20d93 100644
--- a/Parser/parsetok.c
+++ b/Parser/parsetok.c
@@ -192,7 +192,7 @@ parsetok(tok, g, start, err_ret)
err_ret->offset = tok->cur - tok->buf;
if (tok->buf != NULL) {
int len = tok->inp - tok->buf;
- err_ret->text = malloc(len + 1);
+ err_ret->text = PyMem_NEW(char, len + 1);
if (err_ret->text != NULL) {
if (len > 0)
strncpy(err_ret->text, tok->buf, len);
diff --git a/Parser/pgenmain.c b/Parser/pgenmain.c
index 7292485..34c3b01 100644
--- a/Parser/pgenmain.c
+++ b/Parser/pgenmain.c
@@ -139,7 +139,7 @@ getgrammar(filename)
putc(' ', stderr);
}
fprintf(stderr, "^\n");
- free(err.text);
+ PyMem_DEL(err.text);
}
Py_Exit(1);
}
@@ -196,7 +196,7 @@ PyOS_Readline(prompt)
char *prompt;
{
int n = 1000;
- char *p = malloc(n);
+ char *p = PyMem_MALLOC(n);
char *q;
if (p == NULL)
return NULL;
@@ -209,7 +209,7 @@ PyOS_Readline(prompt)
n = strlen(p);
if (n > 0 && p[n-1] != '\n')
p[n-1] = '\n';
- return realloc(p, n+1);
+ return PyMem_REALLOC(p, n+1);
}
#ifdef HAVE_STDARG_PROTOTYPES
diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c
index e4b058e..7d9a273 100644
--- a/Parser/tokenizer.c
+++ b/Parser/tokenizer.c
@@ -219,26 +219,27 @@ tok_nextc(tok)
if (new == NULL)
tok->done = E_INTR;
else if (*new == '\0') {
- free(new);
+ PyMem_FREE(new);
tok->done = E_EOF;
}
else if (tok->start != NULL) {
int start = tok->start - tok->buf;
int oldlen = tok->cur - tok->buf;
int newlen = oldlen + strlen(new);
- char *buf = realloc(tok->buf, newlen+1);
+ char *buf = tok->buf;
+ PyMem_RESIZE(buf, char, newlen+1);
tok->lineno++;
if (buf == NULL) {
- free(tok->buf);
+ PyMem_DEL(tok->buf);
tok->buf = NULL;
- free(new);
+ PyMem_FREE(new);
tok->done = E_NOMEM;
return EOF;
}
tok->buf = buf;
tok->cur = tok->buf + oldlen;
strcpy(tok->buf + oldlen, new);
- free(new);
+ PyMem_FREE(new);
tok->inp = tok->buf + newlen;
tok->end = tok->inp + 1;
tok->start = tok->buf + start;
@@ -246,7 +247,7 @@ tok_nextc(tok)
else {
tok->lineno++;
if (tok->buf != NULL)
- free(tok->buf);
+ PyMem_DEL(tok->buf);
tok->buf = new;
tok->cur = tok->buf;
tok->inp = strchr(tok->buf, '\0');