mirror of
https://github.com/python/cpython.git
synced 2025-12-23 09:19:18 +00:00
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>
This commit is contained in:
parent
35d273825a
commit
cd9a56c2b0
30 changed files with 970 additions and 19 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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 *);
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue