diff -r 5619bc2d8207 Modules/readline.c --- a/Modules/readline.c Fri Jun 14 19:02:34 2013 -0400 +++ Modules/readline.c Sat Jun 15 02:15:50 2013 +0200 @@ -1097,7 +1097,7 @@ call_readline(FILE *sys_stdin, FILE *sys /* We got an EOF, return a empty string. */ if (p == NULL) { - p = PyMem_Malloc(1); + p = PyMem_RawMalloc(1); if (p != NULL) *p = '\0'; RESTORE_LOCALE(saved_locale) @@ -1128,7 +1128,7 @@ call_readline(FILE *sys_stdin, FILE *sys /* Copy the malloc'ed buffer into a PyMem_Malloc'ed one and release the original. */ q = p; - p = PyMem_Malloc(n+2); + p = PyMem_RawMalloc(n+2); if (p != NULL) { strncpy(p, q, n); p[n] = '\n'; diff -r 5619bc2d8207 Parser/myreadline.c --- a/Parser/myreadline.c Fri Jun 14 19:02:34 2013 -0400 +++ b/Parser/myreadline.c Sat Jun 15 02:15:50 2013 +0200 @@ -113,8 +113,10 @@ PyOS_StdioReadline(FILE *sys_stdin, FILE { size_t n; char *p; + n = 100; - if ((p = (char *)PyMem_MALLOC(n)) == NULL) + p = (char *)PyMem_RawMalloc(n); + if (p == NULL) return NULL; fflush(sys_stdout); if (prompt) @@ -124,7 +126,7 @@ PyOS_StdioReadline(FILE *sys_stdin, FILE case 0: /* Normal case */ break; case 1: /* Interrupt */ - PyMem_FREE(p); + PyMem_RawFree(p); return NULL; case -1: /* EOF */ case -2: /* Error */ @@ -135,7 +137,7 @@ PyOS_StdioReadline(FILE *sys_stdin, FILE n = strlen(p); while (n > 0 && p[n-1] != '\n') { size_t incr = n+2; - p = (char *)PyMem_REALLOC(p, n + incr); + p = (char *)PyMem_RawRealloc(p, n + incr); if (p == NULL) return NULL; if (incr > INT_MAX) { @@ -145,7 +147,7 @@ PyOS_StdioReadline(FILE *sys_stdin, FILE break; n += strlen(p+n); } - return (char *)PyMem_REALLOC(p, n+1); + return (char *)PyMem_RawRealloc(p, n+1); } @@ -162,7 +164,8 @@ char *(*PyOS_ReadlineFunctionPointer)(FI char * PyOS_Readline(FILE *sys_stdin, FILE *sys_stdout, char *prompt) { - char *rv; + char *rv, *res; + size_t len; if (_PyOS_ReadlineTState == PyThreadState_GET()) { PyErr_SetString(PyExc_RuntimeError, @@ -209,5 +212,14 @@ PyOS_Readline(FILE *sys_stdin, FILE *sys _PyOS_ReadlineTState = NULL; - return rv; + if (rv == NULL) + return NULL; + + len = strlen(rv) + 1; + res = PyMem_Malloc(len); + if (res != NULL) + memcpy(res, rv, len); + PyMem_RawFree(rv); + + return res; } diff -r 5619bc2d8207 Doc/c-api/veryhigh.rst --- a/Doc/c-api/veryhigh.rst Fri Jun 14 19:02:34 2013 -0400 +++ b/Doc/c-api/veryhigh.rst Sat Jun 15 02:31:36 2013 +0200 @@ -166,6 +166,14 @@ the same library that the Python runtime resulting string. For example, The :mod:`readline` module sets this hook to provide line-editing and tab-completion features. + The result must be a string allocated by :c:func:`PyMem_RawMalloc` or + :c:func:`PyMem_RawRealloc`, or *NULL* if an error occurred. + + .. versionchanged:: 3.4 + The result must be allocated by :c:func:`PyMem_RawMalloc` or + :c:func:`PyMem_RawRealloc`, instead of being allocated by + :c:func:`PyMem_Malloc` or :c:func:`PyMem_Realloc`. + .. c:function:: struct _node* PyParser_SimpleParseString(const char *str, int start)