]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-106572: Convert PyObject_DelAttr() to a function (#106611)
authorVictor Stinner <vstinner@python.org>
Tue, 11 Jul 2023 09:38:22 +0000 (11:38 +0200)
committerGitHub <noreply@github.com>
Tue, 11 Jul 2023 09:38:22 +0000 (11:38 +0200)
* 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).

12 files changed:
Doc/data/stable_abi.dat
Include/abstract.h
Include/object.h
Lib/test/test_stable_abi_ctypes.py
Misc/NEWS.d/next/C API/2023-07-11-01-07-39.gh-issue-106572.y1b35X.rst [new file with mode: 0644]
Misc/stable_abi.toml
Objects/object.c
PC/python3dll.c
Python/bltinmodule.c
Python/bytecodes.c
Python/executor_cases.c.h
Python/generated_cases.c.h

index 7fb002cd80369b6db516c8452940aa21eb32dc97..9a61ddc39a353fdcc1fb57d04d9189f604a20189 100644 (file)
@@ -490,6 +490,8 @@ function,PyObject_Calloc,3.7,,
 function,PyObject_CheckBuffer,3.11,,
 function,PyObject_ClearWeakRefs,3.2,,
 function,PyObject_CopyData,3.11,,
+function,PyObject_DelAttr,3.13,,
+function,PyObject_DelAttrString,3.13,,
 function,PyObject_DelItem,3.2,,
 function,PyObject_DelItemString,3.2,,
 function,PyObject_Dir,3.2,,
index 016ace9bc89e964295ea6d8e597e2542af2f4fd3..c84d2c704e9605180f5526105d16cb93b407371f 100644 (file)
@@ -80,7 +80,7 @@ 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);
 
@@ -88,17 +88,15 @@ extern "C" {
    -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:
index 3ef64511399c66f711ea801e0f0d939a4c62ccec..dccab07e5f2c6fe915b801322e6c500b8519585d 100644 (file)
@@ -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 *);
index 038c978e7bbd02b7bfd08d3cefbe56990deccb45..20bc2624c8136114662e43e18598dd1ad9c6b46e 100644 (file)
@@ -509,6 +509,8 @@ SYMBOL_NAMES = (
     "PyObject_CheckReadBuffer",
     "PyObject_ClearWeakRefs",
     "PyObject_CopyData",
+    "PyObject_DelAttr",
+    "PyObject_DelAttrString",
     "PyObject_DelItem",
     "PyObject_DelItemString",
     "PyObject_Dir",
diff --git a/Misc/NEWS.d/next/C API/2023-07-11-01-07-39.gh-issue-106572.y1b35X.rst b/Misc/NEWS.d/next/C API/2023-07-11-01-07-39.gh-issue-106572.y1b35X.rst
new file mode 100644 (file)
index 0000000..140e9fe
--- /dev/null
@@ -0,0 +1,2 @@
+Convert :c:func:`PyObject_DelAttr` and :c:func:`PyObject_DelAttrString`
+macros to functions. Patch by Victor Stinner.
index bc7259f11816f3d48fffc8b053b9666afa462cca..c61fedf8390e2831052ad09334617d26dfa78078 100644 (file)
     added = '3.13'
 [function.PyWeakref_GetRef]
     added = '3.13'
+[function.PyObject_DelAttr]
+    added = '3.13'
+[function.PyObject_DelAttrString]
+    added = '3.13'
index c27b13e9e0c31ac9f6c334b2aa67c3e8d8826a8c..540ba5d07427cd07cf7d6afc0d764a6507582e68 100644 (file)
@@ -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)
 {
@@ -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)
 {
index 65bdf326ffbc7f0627647baf0dfd8f8dfaff331f..a7173911c7c1e841a044ec85f5dbd657bf42979d 100755 (executable)
@@ -447,6 +447,8 @@ EXPORT_FUNC(PyObject_CheckBuffer)
 EXPORT_FUNC(PyObject_CheckReadBuffer)
 EXPORT_FUNC(PyObject_ClearWeakRefs)
 EXPORT_FUNC(PyObject_CopyData)
+EXPORT_FUNC(PyObject_DelAttr)
+EXPORT_FUNC(PyObject_DelAttrString)
 EXPORT_FUNC(PyObject_DelItem)
 EXPORT_FUNC(PyObject_DelItemString)
 EXPORT_FUNC(PyObject_Dir)
index 49efafc07f4245fa78b5aa4b766aa2c4ac286138..20a86fc6f583d3d0b78745ea8bdf2ef1fe4f5790 100644 (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;
 }
 
index 0848bbfd203ec491c54419510b594f57760340af..88444293aa228b918fbaaca39f818f766d9de60d 100644 (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);
         }
index eccb30348173af46d6ff5c4501f83e74e3f81f24..030d7ac15ef066b1ed4115c3797d1ac50e831027 100644 (file)
             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"
index 11823cf9cd293c0efce9224ca0f4dd26ca09b373..ecbf8ee59da1da1a7a1facec9940fd70c4a7d733 100644 (file)
             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"