]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-39153: Clarify C API *SetItem refcounting semantics (GH-18220)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 29 Jan 2020 11:29:35 +0000 (03:29 -0800)
committerGitHub <noreply@github.com>
Wed, 29 Jan 2020 11:29:35 +0000 (03:29 -0800)
Some of the *SetItem methods in the C API steal a reference to the
given value. This annotates the better behaved ones to assure the
reader that these are not the ones with the inconsistent behaviour.

* ðŸ“œðŸ¤– Added by blurb_it.

* make docs consistent with signature

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
(cherry picked from commit e1e80002e28e1055f399a20918c49d50d093709e)

Co-authored-by: Joannah Nanjekye <33177550+nanjekyejoannah@users.noreply.github.com>
Doc/c-api/dict.rst
Doc/c-api/mapping.rst
Doc/c-api/object.rst
Misc/NEWS.d/next/Documentation/2020-01-27-22-24-51.bpo-39153.Pjl8jV.rst [new file with mode: 0644]

index e7922dc0c73f2a06fa5d178c17462e37cc77f177..e48c11d336b8ce8e024bab0736733313f8573e0f 100644 (file)
@@ -62,19 +62,20 @@ Dictionary Objects
 
 .. c:function:: int PyDict_SetItem(PyObject *p, PyObject *key, PyObject *val)
 
-   Insert *value* into the dictionary *p* with a key of *key*.  *key* must be
+   Insert *val* into the dictionary *p* with a key of *key*.  *key* must be
    :term:`hashable`; if it isn't, :exc:`TypeError` will be raised. Return
-   ``0`` on success or ``-1`` on failure.
+   ``0`` on success or ``-1`` on failure.  This function *does not* steal a
+   reference to *val*.
 
 
 .. c:function:: int PyDict_SetItemString(PyObject *p, const char *key, PyObject *val)
 
    .. index:: single: PyUnicode_FromString()
 
-   Insert *value* into the dictionary *p* using *key* as a key. *key* should
+   Insert *val* into the dictionary *p* using *key* as a key. *key* should
    be a :c:type:`const char\*`.  The key object is created using
    ``PyUnicode_FromString(key)``.  Return ``0`` on success or ``-1`` on
-   failure.
+   failure.  This function *does not* steal a reference to *val*.
 
 
 .. c:function:: int PyDict_DelItem(PyObject *p, PyObject *key)
index 6a80b033b651ec8d0523106949795b55c7129dc7..682160d1475c1c4b9cfff1aa0b386dff9299ab9d 100644 (file)
@@ -37,7 +37,8 @@ See also :c:func:`PyObject_GetItem`, :c:func:`PyObject_SetItem` and
 
    Map the string *key* to the value *v* in object *o*.  Returns ``-1`` on
    failure.  This is the equivalent of the Python statement ``o[key] = v``.
-   See also :c:func:`PyObject_SetItem`.
+   See also :c:func:`PyObject_SetItem`.  This function *does not* steal a
+   reference to *v*.
 
 
 .. c:function:: int PyMapping_DelItem(PyObject *o, PyObject *key)
index 404a98fb417bb1565b170c4fcc75e4d7db924841..db815ae288b8699ff8fd1536508a264e1551c88f 100644 (file)
@@ -503,7 +503,8 @@ Object Protocol
 
    Map the object *key* to the value *v*.  Raise an exception and
    return ``-1`` on failure; return ``0`` on success.  This is the
-   equivalent of the Python statement ``o[key] = v``.
+   equivalent of the Python statement ``o[key] = v``.  This function *does
+   not* steal a reference to *v*.
 
 
 .. c:function:: int PyObject_DelItem(PyObject *o, PyObject *key)
diff --git a/Misc/NEWS.d/next/Documentation/2020-01-27-22-24-51.bpo-39153.Pjl8jV.rst b/Misc/NEWS.d/next/Documentation/2020-01-27-22-24-51.bpo-39153.Pjl8jV.rst
new file mode 100644 (file)
index 0000000..95be00b
--- /dev/null
@@ -0,0 +1,5 @@
+Clarify refcounting semantics for the following functions:\r
+- PyObject_SetItem\r
+- PyMapping_SetItemString\r
+- PyDict_SetItem\r
+- PyDict_SetItemString
\ No newline at end of file