diff options
author | Victor Stinner <vstinner@python.org> | 2023-11-14 12:51:00 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-14 12:51:00 (GMT) |
commit | 4f04172c9287c507f1426e02ddfc432f1f3ade54 (patch) | |
tree | 800ac400c3776336e1f52b49a0f10b4dae9af8c1 /Objects/structseq.c | |
parent | f44d6ff6e0c9eeb0bb246a3dd8f99d40b7050054 (diff) | |
download | cpython-4f04172c9287c507f1426e02ddfc432f1f3ade54.zip cpython-4f04172c9287c507f1426e02ddfc432f1f3ade54.tar.gz cpython-4f04172c9287c507f1426e02ddfc432f1f3ade54.tar.bz2 |
gh-111262: Add PyDict_Pop() function (#112028)
_PyDict_Pop_KnownHash(): remove the default value and the return type
becomes an int.
Co-authored-by: Stefan Behnel <stefan_ml@behnel.de>
Co-authored-by: Antoine Pitrou <pitrou@free.fr>
Diffstat (limited to 'Objects/structseq.c')
-rw-r--r-- | Objects/structseq.c | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/Objects/structseq.c b/Objects/structseq.c index db4aebe..581d6ad 100644 --- a/Objects/structseq.c +++ b/Objects/structseq.c @@ -8,7 +8,6 @@ */ #include "Python.h" -#include "pycore_dict.h" // _PyDict_Pop() #include "pycore_initconfig.h" // _PyStatus_OK() #include "pycore_modsupport.h" // _PyArg_NoPositional() #include "pycore_object.h" // _PyObject_GC_TRACK() @@ -417,14 +416,13 @@ structseq_replace(PyStructSequence *self, PyObject *args, PyObject *kwargs) // We do not support types with unnamed fields, so we can iterate over // i >= n_visible_fields case without slicing with (i - n_unnamed_fields). for (i = 0; i < n_fields; ++i) { - PyObject *key = PyUnicode_FromString(Py_TYPE(self)->tp_members[i].name); - if (!key) { + PyObject *ob; + if (PyDict_PopString(kwargs, Py_TYPE(self)->tp_members[i].name, + &ob) < 0) { goto error; } - PyObject *ob = _PyDict_Pop(kwargs, key, self->ob_item[i]); - Py_DECREF(key); - if (!ob) { - goto error; + if (ob == NULL) { + ob = Py_NewRef(self->ob_item[i]); } result->ob_item[i] = ob; } |