]> granicus.if.org Git - python/commitdiff
bpo-33583: Add note in PyObject_GC_Resize() doc (GH-7021)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 22 May 2018 02:18:41 +0000 (19:18 -0700)
committerGitHub <noreply@github.com>
Tue, 22 May 2018 02:18:41 +0000 (19:18 -0700)
(cherry picked from commit 1179f4b40f375af5c59cd4b6be9cc313fa0e1a37)

Co-authored-by: INADA Naoki <methane@users.noreply.github.com>
Doc/c-api/gcsupport.rst
Modules/gcmodule.c

index f5e0d7ec9c79c368f90e22b20785e5e31cfa528c..7f54b6a9cff8c5b97e725f4234d3d478e5a327f3 100644 (file)
@@ -49,7 +49,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.
 
 
 .. c:function:: void PyObject_GC_Track(PyObject *op)
index 754348e20a92d0b9e08c35ace72e784d53eebcda..0b057ddbf5e44b6be99b34be3e681b2a851ae9ea 100644 (file)
@@ -1773,6 +1773,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);