summaryrefslogtreecommitdiffstats
path: root/Include
diff options
context:
space:
mode:
authorPetr Viktorin <encukou@gmail.com>2023-05-04 07:56:53 (GMT)
committerGitHub <noreply@github.com>2023-05-04 07:56:53 (GMT)
commitcd9a56c2b0e14f56f2e83dd4db43c5c69a74b232 (patch)
treeff971ebbdb11701bab003d743a6d5b928c35184f /Include
parent35d273825abc319d0ecbd69110e847f6040d0cd7 (diff)
downloadcpython-cd9a56c2b0e14f56f2e83dd4db43c5c69a74b232.zip
cpython-cd9a56c2b0e14f56f2e83dd4db43c5c69a74b232.tar.gz
cpython-cd9a56c2b0e14f56f2e83dd4db43c5c69a74b232.tar.bz2
gh-103509: PEP 697 -- Limited C API for Extending Opaque Types (GH-103511)
Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net> Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
Diffstat (limited to 'Include')
-rw-r--r--Include/cpython/object.h1
-rw-r--r--Include/descrobject.h1
-rw-r--r--Include/internal/pycore_object.h5
-rw-r--r--Include/object.h5
-rw-r--r--Include/pyport.h11
5 files changed, 18 insertions, 5 deletions
diff --git a/Include/cpython/object.h b/Include/cpython/object.h
index ce4d13c..d8eff69 100644
--- a/Include/cpython/object.h
+++ b/Include/cpython/object.h
@@ -553,6 +553,7 @@ Py_DEPRECATED(3.11) typedef int UsingDeprecatedTrashcanMacro;
Py_TRASHCAN_END; \
} while(0);
+PyAPI_FUNC(void *) PyObject_GetItemData(PyObject *obj);
PyAPI_FUNC(int) _PyObject_VisitManagedDict(PyObject *obj, visitproc visit, void *arg);
PyAPI_FUNC(void) _PyObject_ClearManagedDict(PyObject *obj);
diff --git a/Include/descrobject.h b/Include/descrobject.h
index 0a420b8..fd66d17 100644
--- a/Include/descrobject.h
+++ b/Include/descrobject.h
@@ -83,6 +83,7 @@ struct PyMemberDef {
#define Py_READONLY 1
#define Py_AUDIT_READ 2 // Added in 3.10, harmless no-op before that
#define _Py_WRITE_RESTRICTED 4 // Deprecated, no-op. Do not reuse the value.
+#define Py_RELATIVE_OFFSET 8
PyAPI_FUNC(PyObject *) PyMember_GetOne(const char *, PyMemberDef *);
PyAPI_FUNC(int) PyMember_SetOne(char *, PyMemberDef *, PyObject *);
diff --git a/Include/internal/pycore_object.h b/Include/internal/pycore_object.h
index 91853ad..b9e700e 100644
--- a/Include/internal/pycore_object.h
+++ b/Include/internal/pycore_object.h
@@ -389,11 +389,6 @@ extern PyObject ** _PyObject_ComputedDictPointer(PyObject *);
extern void _PyObject_FreeInstanceAttributes(PyObject *obj);
extern int _PyObject_IsInstanceDictEmpty(PyObject *);
-// Access macro to the members which are floating "behind" the object
-static inline PyMemberDef* _PyHeapType_GET_MEMBERS(PyHeapTypeObject *etype) {
- return (PyMemberDef*)((char*)etype + Py_TYPE(etype)->tp_basicsize);
-}
-
PyAPI_FUNC(PyObject *) _PyObject_LookupSpecial(PyObject *, PyObject *);
/* C function call trampolines to mitigate bad function pointer casts.
diff --git a/Include/object.h b/Include/object.h
index 66c3df0..81aeb2d 100644
--- a/Include/object.h
+++ b/Include/object.h
@@ -355,6 +355,8 @@ PyAPI_FUNC(PyObject *) PyType_GetQualName(PyTypeObject *);
#endif
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030C0000
PyAPI_FUNC(PyObject *) PyType_FromMetaclass(PyTypeObject*, PyObject*, PyType_Spec*, PyObject*);
+PyAPI_FUNC(void *) PyObject_GetTypeData(PyObject *obj, PyTypeObject *cls);
+PyAPI_FUNC(Py_ssize_t) PyType_GetTypeDataSize(PyTypeObject *cls);
#endif
/* Generic type check */
@@ -521,6 +523,9 @@ given type object has a specified feature.
// subject itself (rather than a mapped attribute on it):
#define _Py_TPFLAGS_MATCH_SELF (1UL << 22)
+/* Items (ob_size*tp_itemsize) are found at the end of an instance's memory */
+#define Py_TPFLAGS_ITEMS_AT_END (1UL << 23)
+
/* These flags are used to determine if a type is a subclass. */
#define Py_TPFLAGS_LONG_SUBCLASS (1UL << 24)
#define Py_TPFLAGS_LIST_SUBCLASS (1UL << 25)
diff --git a/Include/pyport.h b/Include/pyport.h
index bd0ba6d..d7c6ae6 100644
--- a/Include/pyport.h
+++ b/Include/pyport.h
@@ -765,4 +765,15 @@ extern char * _getpty(int *, int, mode_t, int);
#undef __bool__
#endif
+// Make sure we have maximum alignment, even if the current compiler
+// does not support max_align_t. Note that:
+// - Autoconf reports alignment of unknown types to 0.
+// - 'long double' has maximum alignment on *most* platforms,
+// looks like the best we can do for pre-C11 compilers.
+// - The value is tested, see test_alignof_max_align_t
+#if !defined(ALIGNOF_MAX_ALIGN_T) || ALIGNOF_MAX_ALIGN_T == 0
+# undef ALIGNOF_MAX_ALIGN_T
+# define ALIGNOF_MAX_ALIGN_T _Alignof(long double)
+#endif
+
#endif /* Py_PYPORT_H */