mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
GH-95245: Store object values and dict pointers in single tagged pointer. (GH-95278)
This commit is contained in:
parent
fb75d015f4
commit
de388c0a7b
10 changed files with 271 additions and 203 deletions
|
@ -274,24 +274,49 @@ extern int _PyObject_StoreInstanceAttribute(PyObject *obj, PyDictValues *values,
|
|||
PyObject * _PyObject_GetInstanceAttribute(PyObject *obj, PyDictValues *values,
|
||||
PyObject *name);
|
||||
|
||||
static inline PyDictValues **_PyObject_ValuesPointer(PyObject *obj)
|
||||
typedef union {
|
||||
PyObject *dict;
|
||||
/* Use a char* to generate a warning if directly assigning a PyDictValues */
|
||||
char *values;
|
||||
} PyDictOrValues;
|
||||
|
||||
static inline PyDictOrValues *
|
||||
_PyObject_DictOrValuesPointer(PyObject *obj)
|
||||
{
|
||||
assert(Py_TYPE(obj)->tp_flags & Py_TPFLAGS_MANAGED_DICT);
|
||||
return ((PyDictValues **)obj)-4;
|
||||
return ((PyDictOrValues *)obj)-3;
|
||||
}
|
||||
|
||||
static inline PyObject **_PyObject_ManagedDictPointer(PyObject *obj)
|
||||
static inline int
|
||||
_PyDictOrValues_IsValues(PyDictOrValues dorv)
|
||||
{
|
||||
assert(Py_TYPE(obj)->tp_flags & Py_TPFLAGS_MANAGED_DICT);
|
||||
return ((PyObject **)obj)-3;
|
||||
return ((uintptr_t)dorv.values) & 1;
|
||||
}
|
||||
|
||||
static inline PyDictValues *
|
||||
_PyDictOrValues_GetValues(PyDictOrValues dorv)
|
||||
{
|
||||
assert(_PyDictOrValues_IsValues(dorv));
|
||||
return (PyDictValues *)(dorv.values + 1);
|
||||
}
|
||||
|
||||
static inline PyObject *
|
||||
_PyDictOrValues_GetDict(PyDictOrValues dorv)
|
||||
{
|
||||
assert(!_PyDictOrValues_IsValues(dorv));
|
||||
return dorv.dict;
|
||||
}
|
||||
|
||||
static inline void
|
||||
_PyDictOrValues_SetValues(PyDictOrValues *ptr, PyDictValues *values)
|
||||
{
|
||||
ptr->values = ((char *)values) - 1;
|
||||
}
|
||||
|
||||
#define MANAGED_DICT_OFFSET (((int)sizeof(PyObject *))*-3)
|
||||
|
||||
extern PyObject ** _PyObject_DictPointer(PyObject *);
|
||||
extern int _PyObject_VisitInstanceAttributes(PyObject *self, visitproc visit, void *arg);
|
||||
extern void _PyObject_ClearInstanceAttributes(PyObject *self);
|
||||
extern void _PyObject_FreeInstanceAttributes(PyObject *self);
|
||||
extern PyObject ** _PyObject_ComputedDictPointer(PyObject *);
|
||||
extern void _PyObject_FreeInstanceAttributes(PyObject *obj);
|
||||
extern int _PyObject_IsInstanceDictEmpty(PyObject *);
|
||||
extern PyObject* _PyType_GetSubclasses(PyTypeObject *);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue