[New-bugs-announce] [issue18205] PyOS_ReadlineFunctionPointer violates PyMem_Malloc() API: the GIL is not hold

STINNER Victor report at bugs.python.org
Thu Jun 13 23:02:17 CEST 2013


New submission from STINNER Victor:

The callback PyOS_ReadlineFunctionPointer (used to read a line from the standard input) must return a buffer allocated by PyMem_Malloc(), but PyOS_Readline() releases the GIL before calling PyOS_ReadlineFunctionPointer.

Simplified extract of PyOS_Readline():

    Py_BEGIN_ALLOW_THREADS
    if (!isatty (fileno (sys_stdin)) || !isatty (fileno (sys_stdout)))
        rv = PyOS_StdioReadline (sys_stdin, sys_stdout, prompt);
    else
        rv = (*PyOS_ReadlineFunctionPointer)(sys_stdin, sys_stdout,
                                             prompt);
    Py_END_ALLOW_THREADS

tok_nextc() calls PyOS_Readline() and calls PyMem_FREE() to release its result.

PyOS_ReadlineFunctionPointer should allocate memory using malloc(), not using PyMem_Malloc(). But PyOS_Readline() should copy the line into a buffer allocated by PyMem_Malloc() to keep backward compatibility.

See also issue #18203 and #3329.

----------
components: Interpreter Core, Library (Lib)
messages: 191089
nosy: haypo
priority: normal
severity: normal
status: open
title: PyOS_ReadlineFunctionPointer violates PyMem_Malloc() API: the GIL is not hold
versions: Python 2.7, Python 3.3, Python 3.4

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue18205>
_______________________________________


More information about the New-bugs-announce mailing list