mirror of
https://github.com/python/cpython.git
synced 2025-08-01 07:33:08 +00:00
GH-115776: Embed the values array into the object, for "normal" Python objects. (GH-116115)
This commit is contained in:
parent
c97d3af239
commit
c32dc47aca
35 changed files with 787 additions and 537 deletions
|
@ -265,9 +265,8 @@ _PyObject_Init(PyObject *op, PyTypeObject *typeobj)
|
|||
{
|
||||
assert(op != NULL);
|
||||
Py_SET_TYPE(op, typeobj);
|
||||
if (_PyType_HasFeature(typeobj, Py_TPFLAGS_HEAPTYPE)) {
|
||||
Py_INCREF(typeobj);
|
||||
}
|
||||
assert(_PyType_HasFeature(typeobj, Py_TPFLAGS_HEAPTYPE) || _Py_IsImmortal(typeobj));
|
||||
Py_INCREF(typeobj);
|
||||
_Py_NewReference(op);
|
||||
}
|
||||
|
||||
|
@ -611,8 +610,7 @@ extern PyTypeObject* _PyType_CalculateMetaclass(PyTypeObject *, PyObject *);
|
|||
extern PyObject* _PyType_GetDocFromInternalDoc(const char *, const char *);
|
||||
extern PyObject* _PyType_GetTextSignatureFromInternalDoc(const char *, const char *, int);
|
||||
|
||||
extern int _PyObject_InitializeDict(PyObject *obj);
|
||||
int _PyObject_InitInlineValues(PyObject *obj, PyTypeObject *tp);
|
||||
void _PyObject_InitInlineValues(PyObject *obj, PyTypeObject *tp);
|
||||
extern int _PyObject_StoreInstanceAttribute(PyObject *obj, PyDictValues *values,
|
||||
PyObject *name, PyObject *value);
|
||||
PyObject * _PyObject_GetInstanceAttribute(PyObject *obj, PyDictValues *values,
|
||||
|
@ -627,46 +625,26 @@ PyObject * _PyObject_GetInstanceAttribute(PyObject *obj, PyDictValues *values,
|
|||
#endif
|
||||
|
||||
typedef union {
|
||||
PyObject *dict;
|
||||
/* Use a char* to generate a warning if directly assigning a PyDictValues */
|
||||
char *values;
|
||||
} PyDictOrValues;
|
||||
PyDictObject *dict;
|
||||
} PyManagedDictPointer;
|
||||
|
||||
static inline PyDictOrValues *
|
||||
_PyObject_DictOrValuesPointer(PyObject *obj)
|
||||
static inline PyManagedDictPointer *
|
||||
_PyObject_ManagedDictPointer(PyObject *obj)
|
||||
{
|
||||
assert(Py_TYPE(obj)->tp_flags & Py_TPFLAGS_MANAGED_DICT);
|
||||
return (PyDictOrValues *)((char *)obj + MANAGED_DICT_OFFSET);
|
||||
}
|
||||
|
||||
static inline int
|
||||
_PyDictOrValues_IsValues(PyDictOrValues dorv)
|
||||
{
|
||||
return ((uintptr_t)dorv.values) & 1;
|
||||
return (PyManagedDictPointer *)((char *)obj + MANAGED_DICT_OFFSET);
|
||||
}
|
||||
|
||||
static inline PyDictValues *
|
||||
_PyDictOrValues_GetValues(PyDictOrValues dorv)
|
||||
_PyObject_InlineValues(PyObject *obj)
|
||||
{
|
||||
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;
|
||||
assert(Py_TYPE(obj)->tp_flags & Py_TPFLAGS_INLINE_VALUES);
|
||||
assert(Py_TYPE(obj)->tp_flags & Py_TPFLAGS_MANAGED_DICT);
|
||||
assert(Py_TYPE(obj)->tp_basicsize == sizeof(PyObject));
|
||||
return (PyDictValues *)((char *)obj + sizeof(PyObject));
|
||||
}
|
||||
|
||||
extern PyObject ** _PyObject_ComputedDictPointer(PyObject *);
|
||||
extern void _PyObject_FreeInstanceAttributes(PyObject *obj);
|
||||
extern int _PyObject_IsInstanceDictEmpty(PyObject *);
|
||||
|
||||
// Export for 'math' shared extension
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue