[Python-checkins] bpo-33583: Add note in PyObject_GC_Resize() doc (GH-7021)

Miss Islington (bot) webhook-mailer at python.org
Mon May 21 10:10:31 EDT 2018


https://github.com/python/cpython/commit/3ccc31386da5f35f83756a265429831d650db731
commit: 3ccc31386da5f35f83756a265429831d650db731
branch: 2.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2018-05-21T07:10:27-07:00
summary:

bpo-33583: Add note in PyObject_GC_Resize() doc (GH-7021)

(cherry picked from commit 1179f4b40f375af5c59cd4b6be9cc313fa0e1a37)

Co-authored-by: INADA Naoki <methane at users.noreply.github.com>

files:
M Doc/c-api/gcsupport.rst
M Modules/gcmodule.c

diff --git a/Doc/c-api/gcsupport.rst b/Doc/c-api/gcsupport.rst
index 9438feaeb18a..18ecd071d7a3 100644
--- a/Doc/c-api/gcsupport.rst
+++ b/Doc/c-api/gcsupport.rst
@@ -56,7 +56,7 @@ Constructors for container types must conform to two rules:
 .. c:function:: TYPE* PyObject_GC_Resize(TYPE, PyVarObject *op, Py_ssize_t newsize)
 
    Resize an object allocated by :c:func:`PyObject_NewVar`.  Returns the
-   resized object or *NULL* on failure.
+   resized object or *NULL* on failure.  *op* must not be tracked by the collector yet.
 
    .. versionchanged:: 2.5
       This function used an :c:type:`int` type for *newsize*. This might
diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c
index 916e4817d93e..19011c47b5c4 100644
--- a/Modules/gcmodule.c
+++ b/Modules/gcmodule.c
@@ -1539,6 +1539,7 @@ _PyObject_GC_Resize(PyVarObject *op, Py_ssize_t nitems)
 {
     const size_t basicsize = _PyObject_VAR_SIZE(Py_TYPE(op), nitems);
     PyGC_Head *g = AS_GC(op);
+    assert(!IS_TRACKED(op));
     if (basicsize > PY_SSIZE_T_MAX - sizeof(PyGC_Head))
         return (PyVarObject *)PyErr_NoMemory();
     g = (PyGC_Head *)PyObject_REALLOC(g,  sizeof(PyGC_Head) + basicsize);



More information about the Python-checkins mailing list