@@ -1540,6 +1540,28 @@ _PyObject_ComputedDictPointer(PyObject *obj)
15401540 return (PyObject * * ) ((char * )obj + dictoffset );
15411541}
15421542
1543+ static int
1544+ object_getdictptr (PyObject * obj , PyObject * * * dict_ptr )
1545+ {
1546+ if ((Py_TYPE (obj )-> tp_flags & Py_TPFLAGS_MANAGED_DICT ) == 0 ) {
1547+ * dict_ptr = _PyObject_ComputedDictPointer (obj );
1548+ return (* dict_ptr != NULL );
1549+ }
1550+
1551+ PyDictObject * dict = _PyObject_GetManagedDict (obj );
1552+ if (dict == NULL && Py_TYPE (obj )-> tp_flags & Py_TPFLAGS_INLINE_VALUES ) {
1553+ dict = _PyObject_MaterializeManagedDict (obj );
1554+ if (dict == NULL ) {
1555+ * dict_ptr = NULL ;
1556+ return -1 ;
1557+ }
1558+ }
1559+ * dict_ptr = (PyObject * * )& _PyObject_ManagedDictPointer (obj )-> dict ;
1560+ assert (* dict_ptr != NULL );
1561+ return 1 ;
1562+ }
1563+
1564+
15431565/* Helper to get a pointer to an object's __dict__ slot, if any.
15441566 * Creates the dict from inline attributes if necessary.
15451567 * Does not set an exception.
@@ -1550,20 +1572,31 @@ _PyObject_ComputedDictPointer(PyObject *obj)
15501572PyObject * *
15511573_PyObject_GetDictPtr (PyObject * obj )
15521574{
1553- if ((Py_TYPE (obj )-> tp_flags & Py_TPFLAGS_MANAGED_DICT ) == 0 ) {
1554- return _PyObject_ComputedDictPointer (obj );
1575+ PyObject * * dict_ptr ;
1576+ if (object_getdictptr (obj , & dict_ptr ) < 0 ) {
1577+ PyErr_Clear ();
15551578 }
1556- PyDictObject * dict = _PyObject_GetManagedDict (obj );
1557- if (dict == NULL && Py_TYPE (obj )-> tp_flags & Py_TPFLAGS_INLINE_VALUES ) {
1558- dict = _PyObject_MaterializeManagedDict (obj );
1559- if (dict == NULL ) {
1560- PyErr_Clear ();
1561- return NULL ;
1562- }
1579+ return dict_ptr ;
1580+ }
1581+
1582+
1583+ int
1584+ PyObject_GetDict (PyObject * obj , PyObject * * dict )
1585+ {
1586+ PyObject * * dict_ptr ;
1587+ int res = object_getdictptr (obj , & dict_ptr );
1588+ if (res == 1 ) {
1589+ assert (* dict_ptr != NULL );
1590+ * dict = Py_NewRef (* dict_ptr );
15631591 }
1564- return (PyObject * * )& _PyObject_ManagedDictPointer (obj )-> dict ;
1592+ else {
1593+ assert (dict_ptr == NULL );
1594+ * dict = NULL ;
1595+ }
1596+ return res ;
15651597}
15661598
1599+
15671600PyObject *
15681601PyObject_SelfIter (PyObject * obj )
15691602{
0 commit comments