diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2013-10-10 14:18:20 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2013-10-10 14:18:20 (GMT) |
commit | 2fe9bac4dca34e86d44b7e169f3795fde4c841a1 (patch) | |
tree | bdfa2e05ffa05074b815c1c02ec23d3effcd23d3 /Doc | |
parent | 6cf185dc064577c6f472c86741e91fb28ec82e2d (diff) | |
download | cpython-2fe9bac4dca34e86d44b7e169f3795fde4c841a1.zip cpython-2fe9bac4dca34e86d44b7e169f3795fde4c841a1.tar.gz cpython-2fe9bac4dca34e86d44b7e169f3795fde4c841a1.tar.bz2 |
Close #16742: Fix misuse of memory allocations in PyOS_Readline()
The GIL must be held to call PyMem_Malloc(), whereas PyOS_Readline() releases
the GIL to read input.
The result of the C callback PyOS_ReadlineFunctionPointer must now be a string
allocated by PyMem_RawMalloc() or PyMem_RawRealloc() (or NULL if an error
occurred), instead of a string allocated by PyMem_Malloc() or PyMem_Realloc().
Fixing this issue was required to setup a hook on PyMem_Malloc(), for example
using the tracemalloc module.
PyOS_Readline() copies the result of PyOS_ReadlineFunctionPointer() into a new
buffer allocated by PyMem_Malloc(). So the public API of PyOS_Readline() does
not change.
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/c-api/veryhigh.rst | 8 | ||||
-rw-r--r-- | Doc/whatsnew/3.4.rst | 6 |
2 files changed, 14 insertions, 0 deletions
diff --git a/Doc/c-api/veryhigh.rst b/Doc/c-api/veryhigh.rst index 19af7bf..a129963 100644 --- a/Doc/c-api/veryhigh.rst +++ b/Doc/c-api/veryhigh.rst @@ -166,6 +166,14 @@ the same library that the Python runtime is using. 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) diff --git a/Doc/whatsnew/3.4.rst b/Doc/whatsnew/3.4.rst index 636d05d..ed4ea17 100644 --- a/Doc/whatsnew/3.4.rst +++ b/Doc/whatsnew/3.4.rst @@ -587,3 +587,9 @@ that may require changes to your code. attribute in the chain referring to the innermost function. Introspection libraries that assumed the previous behaviour was intentional can use :func:`inspect.unwrap` to gain equivalent behaviour. + +* (C API) The result of the :c:var:`PyOS_ReadlineFunctionPointer` callback must + now be a string allocated by :c:func:`PyMem_RawMalloc` or + :c:func:`PyMem_RawRealloc`, or *NULL* if an error occurred, instead of a + string allocated by :c:func:`PyMem_Malloc` or :c:func:`PyMem_Realloc`. + |