summaryrefslogtreecommitdiffstats
path: root/Include/object.h
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2020-05-27 12:55:10 (GMT)
committerGitHub <noreply@github.com>2020-05-27 12:55:10 (GMT)
commitfe2978b3b940fe2478335e3a2ca5ad22338cdf9c (patch)
tree046e4e97f50b96d62239f8081f7ce6263ef02d78 /Include/object.h
parent20941de0ddc39ce9f07e29b4cc770e8a9ef14d41 (diff)
downloadcpython-fe2978b3b940fe2478335e3a2ca5ad22338cdf9c.zip
cpython-fe2978b3b940fe2478335e3a2ca5ad22338cdf9c.tar.gz
cpython-fe2978b3b940fe2478335e3a2ca5ad22338cdf9c.tar.bz2
bpo-39573: Convert Py_REFCNT and Py_SIZE to functions (GH-20429)
Convert Py_REFCNT() and Py_SIZE() macros to static inline functions. They cannot be used as l-value anymore: use Py_SET_REFCNT() and Py_SET_SIZE() to set an object reference count and size. Replace &Py_SIZE(self) with &((PyVarObject*)self)->ob_size in arraymodule.c. This change is backward incompatible on purpose, to prepare the C API for an opaque PyObject structure.
Diffstat (limited to 'Include/object.h')
-rw-r--r--Include/object.h19
1 files changed, 17 insertions, 2 deletions
diff --git a/Include/object.h b/Include/object.h
index 5ad0569..5375670 100644
--- a/Include/object.h
+++ b/Include/object.h
@@ -119,30 +119,45 @@ typedef struct {
/* Cast argument to PyVarObject* type. */
#define _PyVarObject_CAST(op) ((PyVarObject*)(op))
+#define _PyVarObject_CAST_CONST(op) ((const PyVarObject*)(op))
+
+
+static inline Py_ssize_t _Py_REFCNT(const PyObject *ob) {
+ return ob->ob_refcnt;
+}
+#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))
-#define Py_REFCNT(ob) (_PyObject_CAST(ob)->ob_refcnt)
-#define Py_SIZE(ob) (_PyVarObject_CAST(ob)->ob_size)
static inline PyTypeObject* _Py_TYPE(const PyObject *ob) {
return ob->ob_type;
}
#define Py_TYPE(ob) _Py_TYPE(_PyObject_CAST_CONST(ob))
+
static inline int _Py_IS_TYPE(const PyObject *ob, const PyTypeObject *type) {
return ob->ob_type == type;
}
#define Py_IS_TYPE(ob, type) _Py_IS_TYPE(_PyObject_CAST_CONST(ob), type)
+
static inline void _Py_SET_REFCNT(PyObject *ob, Py_ssize_t refcnt) {
ob->ob_refcnt = refcnt;
}
#define Py_SET_REFCNT(ob, refcnt) _Py_SET_REFCNT(_PyObject_CAST(ob), refcnt)
+
static inline void _Py_SET_TYPE(PyObject *ob, PyTypeObject *type) {
ob->ob_type = type;
}
#define Py_SET_TYPE(ob, type) _Py_SET_TYPE(_PyObject_CAST(ob), type)
+
static inline void _Py_SET_SIZE(PyVarObject *ob, Py_ssize_t size) {
ob->ob_size = size;
}