summaryrefslogtreecommitdiff
path: root/Include
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2020-02-07 09:17:07 +0100
committerGitHub <noreply@github.com>2020-02-07 09:17:07 +0100
commitd2ec81a8c99796b51fb8c49b77a7fe369863226f (patch)
treed88e7cbe89f65366d5591338fbe59a71192950db /Include
parentdaa9756cb6395323d6f291efe5c7d7fdc6b2e9d8 (diff)
downloadcpython-git-d2ec81a8c99796b51fb8c49b77a7fe369863226f.tar.gz
bpo-39573: Add Py_SET_TYPE() function (GH-18394)
Add Py_SET_TYPE() function to set the type of an object.
Diffstat (limited to 'Include')
-rw-r--r--Include/cpython/objimpl.h2
-rw-r--r--Include/object.h6
2 files changed, 7 insertions, 1 deletions
diff --git a/Include/cpython/objimpl.h b/Include/cpython/objimpl.h
index 3f148146f6..ebb3e234e3 100644
--- a/Include/cpython/objimpl.h
+++ b/Include/cpython/objimpl.h
@@ -15,7 +15,7 @@ static inline PyObject*
_PyObject_INIT(PyObject *op, PyTypeObject *typeobj)
{
assert(op != NULL);
- Py_TYPE(op) = typeobj;
+ Py_SET_TYPE(op, typeobj);
if (PyType_GetFlags(typeobj) & Py_TPFLAGS_HEAPTYPE) {
Py_INCREF(typeobj);
}
diff --git a/Include/object.h b/Include/object.h
index 0b63051337..eb887f4c6e 100644
--- a/Include/object.h
+++ b/Include/object.h
@@ -128,6 +128,12 @@ static inline void _Py_SET_REFCNT(PyObject *ob, Py_ssize_t 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)
+
+
/*
Type objects contain a string containing the type name (to help somewhat
in debugging), the allocation parameters (see PyObject_New() and