Skip to content

Commit 1f2921b

Browse files
authored
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).
1 parent e6379f7 commit 1f2921b

12 files changed

+33
-8
lines changed

Doc/data/stable_abi.dat

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/abstract.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -80,25 +80,23 @@ extern "C" {
8080
8181
This is the equivalent of the Python statement o.attr_name=v. */
8282

83-
/* Implemented as a macro:
83+
/* Implemented elsewhere:
8484
8585
int PyObject_DelAttrString(PyObject *o, const char *attr_name);
8686
8787
Delete attribute named attr_name, for object o. Returns
8888
-1 on failure.
8989
9090
This is the equivalent of the Python statement: del o.attr_name. */
91-
#define PyObject_DelAttrString(O, A) PyObject_SetAttrString((O), (A), NULL)
9291

9392

94-
/* Implemented as a macro:
93+
/* Implemented elsewhere:
9594
9695
int PyObject_DelAttr(PyObject *o, PyObject *attr_name);
9796
9897
Delete attribute named attr_name, for object o. Returns -1
9998
on failure. This is the equivalent of the Python
10099
statement: del o.attr_name. */
101-
#define PyObject_DelAttr(O, A) PyObject_SetAttr((O), (A), NULL)
102100

103101

104102
/* Implemented elsewhere:

Include/object.h

+2
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,11 @@ PyAPI_FUNC(PyObject *) PyObject_RichCompare(PyObject *, PyObject *, int);
391391
PyAPI_FUNC(int) PyObject_RichCompareBool(PyObject *, PyObject *, int);
392392
PyAPI_FUNC(PyObject *) PyObject_GetAttrString(PyObject *, const char *);
393393
PyAPI_FUNC(int) PyObject_SetAttrString(PyObject *, const char *, PyObject *);
394+
PyAPI_FUNC(int) PyObject_DelAttrString(PyObject *v, const char *name);
394395
PyAPI_FUNC(int) PyObject_HasAttrString(PyObject *, const char *);
395396
PyAPI_FUNC(PyObject *) PyObject_GetAttr(PyObject *, PyObject *);
396397
PyAPI_FUNC(int) PyObject_SetAttr(PyObject *, PyObject *, PyObject *);
398+
PyAPI_FUNC(int) PyObject_DelAttr(PyObject *v, PyObject *name);
397399
PyAPI_FUNC(int) PyObject_HasAttr(PyObject *, PyObject *);
398400
PyAPI_FUNC(PyObject *) PyObject_SelfIter(PyObject *);
399401
PyAPI_FUNC(PyObject *) PyObject_GenericGetAttr(PyObject *, PyObject *);

Lib/test/test_stable_abi_ctypes.py

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Convert :c:func:`PyObject_DelAttr` and :c:func:`PyObject_DelAttrString`
2+
macros to functions. Patch by Victor Stinner.

Misc/stable_abi.toml

+4
Original file line numberDiff line numberDiff line change
@@ -2432,3 +2432,7 @@
24322432
added = '3.13'
24332433
[function.PyWeakref_GetRef]
24342434
added = '3.13'
2435+
[function.PyObject_DelAttr]
2436+
added = '3.13'
2437+
[function.PyObject_DelAttrString]
2438+
added = '3.13'

Objects/object.c

+12
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,12 @@ PyObject_SetAttrString(PyObject *v, const char *name, PyObject *w)
942942
return res;
943943
}
944944

945+
int
946+
PyObject_DelAttrString(PyObject *v, const char *name)
947+
{
948+
return PyObject_SetAttrString(v, name, NULL);
949+
}
950+
945951
int
946952
_PyObject_IsAbstract(PyObject *obj)
947953
{
@@ -1185,6 +1191,12 @@ PyObject_SetAttr(PyObject *v, PyObject *name, PyObject *value)
11851191
return -1;
11861192
}
11871193

1194+
int
1195+
PyObject_DelAttr(PyObject *v, PyObject *name)
1196+
{
1197+
return PyObject_SetAttr(v, name, NULL);
1198+
}
1199+
11881200
PyObject **
11891201
_PyObject_ComputedDictPointer(PyObject *obj)
11901202
{

PC/python3dll.c

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/bltinmodule.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -1567,8 +1567,9 @@ static PyObject *
15671567
builtin_delattr_impl(PyObject *module, PyObject *obj, PyObject *name)
15681568
/*[clinic end generated code: output=85134bc58dff79fa input=164865623abe7216]*/
15691569
{
1570-
if (PyObject_SetAttr(obj, name, (PyObject *)NULL) != 0)
1570+
if (PyObject_DelAttr(obj, name) < 0) {
15711571
return NULL;
1572+
}
15721573
Py_RETURN_NONE;
15731574
}
15741575

Python/bytecodes.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1240,7 +1240,7 @@ dummy_func(
12401240

12411241
inst(DELETE_ATTR, (owner --)) {
12421242
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg);
1243-
int err = PyObject_SetAttr(owner, name, (PyObject *)NULL);
1243+
int err = PyObject_DelAttr(owner, name);
12441244
DECREF_INPUTS();
12451245
ERROR_IF(err, error);
12461246
}

Python/executor_cases.c.h

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/generated_cases.c.h

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)