Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Doc/data/stable_abi.dat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions Include/abstract.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,25 +80,23 @@ extern "C" {

This is the equivalent of the Python statement o.attr_name=v. */

/* Implemented as a macro:
/* Implemented elsewhere:

int PyObject_DelAttrString(PyObject *o, const char *attr_name);

Delete attribute named attr_name, for object o. Returns
-1 on failure.

This is the equivalent of the Python statement: del o.attr_name. */
#define PyObject_DelAttrString(O, A) PyObject_SetAttrString((O), (A), NULL)


/* Implemented as a macro:
/* Implemented elsewhere:

int PyObject_DelAttr(PyObject *o, PyObject *attr_name);

Delete attribute named attr_name, for object o. Returns -1
on failure. This is the equivalent of the Python
statement: del o.attr_name. */
#define PyObject_DelAttr(O, A) PyObject_SetAttr((O), (A), NULL)


/* Implemented elsewhere:
Expand Down
2 changes: 2 additions & 0 deletions Include/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,11 @@ PyAPI_FUNC(PyObject *) PyObject_RichCompare(PyObject *, PyObject *, int);
PyAPI_FUNC(int) PyObject_RichCompareBool(PyObject *, PyObject *, int);
PyAPI_FUNC(PyObject *) PyObject_GetAttrString(PyObject *, const char *);
PyAPI_FUNC(int) PyObject_SetAttrString(PyObject *, const char *, PyObject *);
PyAPI_FUNC(int) PyObject_DelAttrString(PyObject *v, const char *name);
PyAPI_FUNC(int) PyObject_HasAttrString(PyObject *, const char *);
PyAPI_FUNC(PyObject *) PyObject_GetAttr(PyObject *, PyObject *);
PyAPI_FUNC(int) PyObject_SetAttr(PyObject *, PyObject *, PyObject *);
PyAPI_FUNC(int) PyObject_DelAttr(PyObject *v, PyObject *name);
PyAPI_FUNC(int) PyObject_HasAttr(PyObject *, PyObject *);
PyAPI_FUNC(PyObject *) PyObject_SelfIter(PyObject *);
PyAPI_FUNC(PyObject *) PyObject_GenericGetAttr(PyObject *, PyObject *);
Expand Down
2 changes: 2 additions & 0 deletions Lib/test/test_stable_abi_ctypes.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Convert :c:func:`PyObject_DelAttr` and :c:func:`PyObject_DelAttrString`
macros to functions. Patch by Victor Stinner.
4 changes: 4 additions & 0 deletions Misc/stable_abi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2432,3 +2432,7 @@
added = '3.13'
[function.PyWeakref_GetRef]
added = '3.13'
[function.PyObject_DelAttr]
added = '3.13'
[function.PyObject_DelAttrString]
added = '3.13'
12 changes: 12 additions & 0 deletions Objects/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,12 @@ PyObject_SetAttrString(PyObject *v, const char *name, PyObject *w)
return res;
}

int
PyObject_DelAttrString(PyObject *v, const char *name)
{
return PyObject_SetAttrString(v, name, NULL);
}

int
_PyObject_IsAbstract(PyObject *obj)
{
Expand Down Expand Up @@ -1185,6 +1191,12 @@ PyObject_SetAttr(PyObject *v, PyObject *name, PyObject *value)
return -1;
}

int
PyObject_DelAttr(PyObject *v, PyObject *name)
{
return PyObject_SetAttr(v, name, NULL);
}

PyObject **
_PyObject_ComputedDictPointer(PyObject *obj)
{
Expand Down
2 changes: 2 additions & 0 deletions PC/python3dll.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Python/bltinmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
16 changes: 8 additions & 8 deletions Python/executor_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Python/generated_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.