mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
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>
This commit is contained in:
parent
f44d6ff6e0
commit
4f04172c92
15 changed files with 338 additions and 76 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue