diff options
author | Guido van Rossum <guido@python.org> | 2000-05-03 23:44:39 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2000-05-03 23:44:39 (GMT) |
commit | b18618dab7b6b85bb05b084693706e59211fa180 (patch) | |
tree | 785d51f6677da8366be2ad4b4296a62f53161276 /Parser/myreadline.c | |
parent | 2808b744e8d94459f189e1d89c97072d6a1f53b6 (diff) | |
download | cpython-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/myreadline.c')
-rw-r--r-- | Parser/myreadline.c | 12 |
1 files changed, 7 insertions, 5 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 *)); |