summaryrefslogtreecommitdiffstats
path: root/Include
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2020-02-07 11:05:12 (GMT)
committerGitHub <noreply@github.com>2020-02-07 11:05:12 (GMT)
commitb10dc3e7a11fcdb97e285882eba6da92594f90f9 (patch)
tree6c304386f0a2be9d0d6213cbb45b3ff78f60b040 /Include
parent877ea88934a5164be4d9f15207694fad4173d87d (diff)
downloadcpython-b10dc3e7a11fcdb97e285882eba6da92594f90f9.zip
cpython-b10dc3e7a11fcdb97e285882eba6da92594f90f9.tar.gz
cpython-b10dc3e7a11fcdb97e285882eba6da92594f90f9.tar.bz2
bpo-39573: Add Py_SET_SIZE() function (GH-18400)
Add Py_SET_SIZE() function to set the size of an object.
Diffstat (limited to 'Include')
-rw-r--r--Include/cpython/objimpl.h2
-rw-r--r--Include/object.h5
2 files changed, 6 insertions, 1 deletions
diff --git a/Include/cpython/objimpl.h b/Include/cpython/objimpl.h
index ebb3e23..8e3c964 100644
--- a/Include/cpython/objimpl.h
+++ b/Include/cpython/objimpl.h
@@ -30,7 +30,7 @@ static inline PyVarObject*
_PyObject_INIT_VAR(PyVarObject *op, PyTypeObject *typeobj, Py_ssize_t size)
{
assert(op != NULL);
- Py_SIZE(op) = size;
+ Py_SET_SIZE(op, size);
PyObject_INIT((PyObject *)op, typeobj);
return op;
}
diff --git a/Include/object.h b/Include/object.h
index eb887f4..68200f7 100644
--- a/Include/object.h
+++ b/Include/object.h
@@ -133,6 +133,11 @@ static inline void _Py_SET_TYPE(PyObject *ob, PyTypeObject *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 refcnt) {
+ ob->ob_size = refcnt;
+}
+#define Py_SET_SIZE(ob, refcnt) _Py_SET_SIZE(_PyVarObject_CAST(ob), refcnt)
+
/*
Type objects contain a string containing the type name (to help somewhat