aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2020-11-18 18:48:06 +0100
committerGitHub <noreply@github.com>2020-11-18 18:48:06 +0100
commit0e2ac21dd4960574e89561243763eabba685296a (patch)
tree62d5b28d9f66f40020d3fa403ac639a781d70d80 /Include
parentbpo-42336: Improve PCbuild batch files (GH-23275) (diff)
downloadcpython-0e2ac21dd4960574e89561243763eabba685296a.tar.gz
cpython-0e2ac21dd4960574e89561243763eabba685296a.tar.bz2
cpython-0e2ac21dd4960574e89561243763eabba685296a.zip
bpo-39573: Convert Py_TYPE() and Py_SIZE() back to macros (GH-23366)
This change partically reverts commit ad3252bad905d41635bcbb4b76db30d570cf0087 and the commit fe2978b3b940fe2478335e3a2ca5ad22338cdf9c. Many third party C extension modules rely on the ability of using Py_TYPE() to set an object type: "Py_TYPE(obj) = type;" or to set an object type using: "Py_SIZE(obj) = size;".
Diffstat (limited to 'Include')
-rw-r--r--Include/object.h13
1 files changed, 4 insertions, 9 deletions
diff --git a/Include/object.h b/Include/object.h
index dd1b2176867..f68423a09c4 100644
--- a/Include/object.h
+++ b/Include/object.h
@@ -128,16 +128,11 @@ static inline Py_ssize_t _Py_REFCNT(const PyObject *ob) {
#define Py_REFCNT(ob) _Py_REFCNT(_PyObject_CAST_CONST(ob))
-static inline Py_ssize_t _Py_SIZE(const PyVarObject *ob) {
- return ob->ob_size;
-}
-#define Py_SIZE(ob) _Py_SIZE(_PyVarObject_CAST_CONST(ob))
-
+// bpo-39573: The Py_SET_TYPE() function must be used to set an object type.
+#define Py_TYPE(ob) (_PyObject_CAST(ob)->ob_type)
-static inline PyTypeObject* _Py_TYPE(const PyObject *ob) {
- return ob->ob_type;
-}
-#define Py_TYPE(ob) _Py_TYPE(_PyObject_CAST_CONST(ob))
+// bpo-39573: The Py_SET_SIZE() function must be used to set an object size.
+#define Py_SIZE(ob) (_PyVarObject_CAST(ob)->ob_size)
static inline int _Py_IS_TYPE(const PyObject *ob, const PyTypeObject *type) {