mirror of
https://github.com/python/cpython.git
synced 2025-08-27 20:25:18 +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
|
@ -395,8 +395,8 @@ remove_module(PyThreadState *tstate, PyObject *name)
|
|||
|
||||
PyObject *modules = MODULES(tstate->interp);
|
||||
if (PyDict_CheckExact(modules)) {
|
||||
PyObject *mod = _PyDict_Pop(modules, name, Py_None);
|
||||
Py_XDECREF(mod);
|
||||
// Error is reported to the caller
|
||||
(void)PyDict_Pop(modules, name, NULL);
|
||||
}
|
||||
else if (PyMapping_DelItem(modules, name) < 0) {
|
||||
if (_PyErr_ExceptionMatches(tstate, PyExc_KeyError)) {
|
||||
|
|
|
@ -125,11 +125,9 @@ sys_set_object(PyInterpreterState *interp, PyObject *key, PyObject *v)
|
|||
}
|
||||
PyObject *sd = interp->sysdict;
|
||||
if (v == NULL) {
|
||||
v = _PyDict_Pop(sd, key, Py_None);
|
||||
if (v == NULL) {
|
||||
if (PyDict_Pop(sd, key, NULL) < 0) {
|
||||
return -1;
|
||||
}
|
||||
Py_DECREF(v);
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue