gh-106572: Convert PyObject_DelAttr() to a function (#106611)

* Convert PyObject_DelAttr() and PyObject_DelAttrString() macros to
  functions.
* Add PyObject_DelAttr() and PyObject_DelAttrString() functions to
  the stable ABI.
* Replace PyObject_SetAttr(obj, name, NULL) with
  PyObject_DelAttr(obj, name).
This commit is contained in:
Victor Stinner 2023-07-11 11:38:22 +02:00 committed by GitHub
parent e6379f72cb
commit 1f2921b72c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 33 additions and 8 deletions

View file

@ -1567,8 +1567,9 @@ static PyObject *
builtin_delattr_impl(PyObject *module, PyObject *obj, PyObject *name)
/*[clinic end generated code: output=85134bc58dff79fa input=164865623abe7216]*/
{
if (PyObject_SetAttr(obj, name, (PyObject *)NULL) != 0)
if (PyObject_DelAttr(obj, name) < 0) {
return NULL;
}
Py_RETURN_NONE;
}

View file

@ -1240,7 +1240,7 @@ dummy_func(
inst(DELETE_ATTR, (owner --)) {
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg);
int err = PyObject_SetAttr(owner, name, (PyObject *)NULL);
int err = PyObject_DelAttr(owner, name);
DECREF_INPUTS();
ERROR_IF(err, error);
}

View file

@ -1018,7 +1018,7 @@
PyObject *owner = stack_pointer[-1];
#line 1242 "Python/bytecodes.c"
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg);
int err = PyObject_SetAttr(owner, name, (PyObject *)NULL);
int err = PyObject_DelAttr(owner, name);
#line 1023 "Python/executor_cases.c.h"
Py_DECREF(owner);
#line 1245 "Python/bytecodes.c"

View file

@ -1696,7 +1696,7 @@
PyObject *owner = stack_pointer[-1];
#line 1242 "Python/bytecodes.c"
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg);
int err = PyObject_SetAttr(owner, name, (PyObject *)NULL);
int err = PyObject_DelAttr(owner, name);
#line 1701 "Python/generated_cases.c.h"
Py_DECREF(owner);
#line 1245 "Python/bytecodes.c"