From 7b5a439567b81378ab96518e1ca1c3d44a01312d Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Mon, 15 Feb 2021 13:36:42 +0100 Subject: [PATCH 1/5] bpo-40170: Convert PyDescr_IsData macro to a function --- Doc/c-api/descriptor.rst | 4 ++-- Include/descrobject.h | 2 +- Objects/descrobject.c | 5 +++++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Doc/c-api/descriptor.rst b/Doc/c-api/descriptor.rst index 1005140c7acb3a..b32c113e5f0457 100644 --- a/Doc/c-api/descriptor.rst +++ b/Doc/c-api/descriptor.rst @@ -32,8 +32,8 @@ found in the dictionary of type objects. .. c:function:: int PyDescr_IsData(PyObject *descr) - Return true if the descriptor objects *descr* describes a data attribute, or - false if it describes a method. *descr* must be a descriptor object; there is + Return non-zero if the descriptor objects *descr* describes a data attribute, or + ``0`` if it describes a method. *descr* must be a descriptor object; there is no error checking. diff --git a/Include/descrobject.h b/Include/descrobject.h index ead269d1d2f796..703bc8fd6df213 100644 --- a/Include/descrobject.h +++ b/Include/descrobject.h @@ -93,7 +93,7 @@ PyAPI_FUNC(PyObject *) PyDescr_NewGetSet(PyTypeObject *, #ifndef Py_LIMITED_API PyAPI_FUNC(PyObject *) PyDescr_NewWrapper(PyTypeObject *, struct wrapperbase *, void *); -#define PyDescr_IsData(d) (Py_TYPE(d)->tp_descr_set != NULL) +PyAPI_FUNC(int) PyDescr_IsData(PyObject *); #endif PyAPI_FUNC(PyObject *) PyDictProxy_New(PyObject *); diff --git a/Objects/descrobject.c b/Objects/descrobject.c index 16c695a08f47d9..35fbffd914a94c 100644 --- a/Objects/descrobject.c +++ b/Objects/descrobject.c @@ -995,6 +995,11 @@ PyDescr_NewWrapper(PyTypeObject *type, struct wrapperbase *base, void *wrapped) return (PyObject *)descr; } +int +PyDescr_IsData(PyObject *ob) +{ + return Py_TYPE(ob)->tp_descr_set != NULL; +} /* --- mappingproxy: read-only proxy for mappings --- */ From dbcef69787af4845d3b6b4eedce471fe41131c86 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Mon, 15 Feb 2021 13:41:19 +0100 Subject: [PATCH 2/5] Add NEWS --- .../Core and Builtins/2021-02-15-13-41-14.bpo-40170.r2FAtl.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2021-02-15-13-41-14.bpo-40170.r2FAtl.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2021-02-15-13-41-14.bpo-40170.r2FAtl.rst b/Misc/NEWS.d/next/Core and Builtins/2021-02-15-13-41-14.bpo-40170.r2FAtl.rst new file mode 100644 index 00000000000000..dba3b14a9a57fd --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2021-02-15-13-41-14.bpo-40170.r2FAtl.rst @@ -0,0 +1,2 @@ +Convert :c:func:`PyDescr_IsData` macro to function. Patch by Erlend E. +Aasland. From c64feb5603f5c17b40a43c51b3ab74eb35b76872 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Mon, 15 Feb 2021 20:37:14 +0100 Subject: [PATCH 3/5] Address review: Improve NEWS entry --- .../2021-02-15-13-41-14.bpo-40170.r2FAtl.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Misc/NEWS.d/next/Core and Builtins/2021-02-15-13-41-14.bpo-40170.r2FAtl.rst b/Misc/NEWS.d/next/Core and Builtins/2021-02-15-13-41-14.bpo-40170.r2FAtl.rst index dba3b14a9a57fd..82e844bc284092 100644 --- a/Misc/NEWS.d/next/Core and Builtins/2021-02-15-13-41-14.bpo-40170.r2FAtl.rst +++ b/Misc/NEWS.d/next/Core and Builtins/2021-02-15-13-41-14.bpo-40170.r2FAtl.rst @@ -1,2 +1,3 @@ -Convert :c:func:`PyDescr_IsData` macro to function. Patch by Erlend E. -Aasland. +Convert :c:func:`PyDescr_IsData` macro to a function to hide implementation +details: The macro accessed :c:member:`PyTypeObject.tp_descr_set` directly. +Patch by Erlend E. Aasland. From 7d71a1a5c26a8289d70e599b4dd2c6763340290a Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Mon, 15 Feb 2021 23:12:57 +0100 Subject: [PATCH 4/5] Add PyDescr_IsData to the limited API --- Include/descrobject.h | 3 +++ .../Core and Builtins/2021-02-15-13-41-14.bpo-40170.r2FAtl.rst | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Include/descrobject.h b/Include/descrobject.h index 703bc8fd6df213..cfc1d8c683782b 100644 --- a/Include/descrobject.h +++ b/Include/descrobject.h @@ -93,6 +93,9 @@ PyAPI_FUNC(PyObject *) PyDescr_NewGetSet(PyTypeObject *, #ifndef Py_LIMITED_API PyAPI_FUNC(PyObject *) PyDescr_NewWrapper(PyTypeObject *, struct wrapperbase *, void *); +#endif + +#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030A0000 PyAPI_FUNC(int) PyDescr_IsData(PyObject *); #endif diff --git a/Misc/NEWS.d/next/Core and Builtins/2021-02-15-13-41-14.bpo-40170.r2FAtl.rst b/Misc/NEWS.d/next/Core and Builtins/2021-02-15-13-41-14.bpo-40170.r2FAtl.rst index 82e844bc284092..209c59d0f2085b 100644 --- a/Misc/NEWS.d/next/Core and Builtins/2021-02-15-13-41-14.bpo-40170.r2FAtl.rst +++ b/Misc/NEWS.d/next/Core and Builtins/2021-02-15-13-41-14.bpo-40170.r2FAtl.rst @@ -1,3 +1,3 @@ Convert :c:func:`PyDescr_IsData` macro to a function to hide implementation details: The macro accessed :c:member:`PyTypeObject.tp_descr_set` directly. -Patch by Erlend E. Aasland. +The function is now a part of the limited C API. Patch by Erlend E. Aasland. From 00b89fd91b0b46ed218f671d99411b9872c448b6 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Tue, 16 Feb 2021 00:40:59 +0100 Subject: [PATCH 5/5] Revert "Add PyDescr_IsData to the limited API" This reverts commit 7d71a1a5c26a8289d70e599b4dd2c6763340290a. --- Include/descrobject.h | 3 --- .../Core and Builtins/2021-02-15-13-41-14.bpo-40170.r2FAtl.rst | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/Include/descrobject.h b/Include/descrobject.h index cfc1d8c683782b..703bc8fd6df213 100644 --- a/Include/descrobject.h +++ b/Include/descrobject.h @@ -93,9 +93,6 @@ PyAPI_FUNC(PyObject *) PyDescr_NewGetSet(PyTypeObject *, #ifndef Py_LIMITED_API PyAPI_FUNC(PyObject *) PyDescr_NewWrapper(PyTypeObject *, struct wrapperbase *, void *); -#endif - -#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030A0000 PyAPI_FUNC(int) PyDescr_IsData(PyObject *); #endif diff --git a/Misc/NEWS.d/next/Core and Builtins/2021-02-15-13-41-14.bpo-40170.r2FAtl.rst b/Misc/NEWS.d/next/Core and Builtins/2021-02-15-13-41-14.bpo-40170.r2FAtl.rst index 209c59d0f2085b..82e844bc284092 100644 --- a/Misc/NEWS.d/next/Core and Builtins/2021-02-15-13-41-14.bpo-40170.r2FAtl.rst +++ b/Misc/NEWS.d/next/Core and Builtins/2021-02-15-13-41-14.bpo-40170.r2FAtl.rst @@ -1,3 +1,3 @@ Convert :c:func:`PyDescr_IsData` macro to a function to hide implementation details: The macro accessed :c:member:`PyTypeObject.tp_descr_set` directly. -The function is now a part of the limited C API. Patch by Erlend E. Aasland. +Patch by Erlend E. Aasland.