1919#include "pycore_typeobject.h" // struct type_cache
2020#include "pycore_unionobject.h" // _Py_union_type_or
2121#include "pycore_weakref.h" // _PyWeakref_GET_REF()
22+ #include "pycore_cell.h" // PyCell_GetRef()
2223#include "opcode.h" // MAKE_CELL
2324
2425#include <stddef.h> // ptrdiff_t
@@ -11676,23 +11677,28 @@ super_init_without_args(_PyInterpreterFrame *cframe, PyTypeObject **type_p,
1167611677
1167711678 assert (_PyFrame_GetCode (cframe )-> co_nlocalsplus > 0 );
1167811679 PyObject * firstarg = PyStackRef_AsPyObjectBorrow (_PyFrame_GetLocalsArray (cframe )[0 ]);
11680+ if (firstarg == NULL ) {
11681+ PyErr_SetString (PyExc_RuntimeError , "super(): arg[0] deleted" );
11682+ return -1 ;
11683+ }
1167911684 // The first argument might be a cell.
11680- if (firstarg != NULL && (_PyLocals_GetKind (co -> co_localspluskinds , 0 ) & CO_FAST_CELL )) {
11681- // "firstarg" is a cell here unless (very unlikely) super()
11682- // was called from the C-API before the first MAKE_CELL op.
11683- if (_PyInterpreterFrame_LASTI (cframe ) >= 0 ) {
11684- // MAKE_CELL and COPY_FREE_VARS have no quickened forms, so no need
11685- // to use _PyOpcode_Deopt here:
11686- assert (_PyCode_CODE (co )[0 ].op .code == MAKE_CELL ||
11687- _PyCode_CODE (co )[0 ].op .code == COPY_FREE_VARS );
11688- assert (PyCell_Check (firstarg ));
11689- firstarg = PyCell_GET (firstarg );
11685+ // "firstarg" is a cell here unless (very unlikely) super()
11686+ // was called from the C-API before the first MAKE_CELL op.
11687+ if ((_PyLocals_GetKind (co -> co_localspluskinds , 0 ) & CO_FAST_CELL ) &&
11688+ (_PyInterpreterFrame_LASTI (cframe ) >= 0 )) {
11689+ // MAKE_CELL and COPY_FREE_VARS have no quickened forms, so no need
11690+ // to use _PyOpcode_Deopt here:
11691+ assert (_PyCode_CODE (co )[0 ].op .code == MAKE_CELL ||
11692+ _PyCode_CODE (co )[0 ].op .code == COPY_FREE_VARS );
11693+ assert (PyCell_Check (firstarg ));
11694+ firstarg = PyCell_GetRef ((PyCellObject * )firstarg );
11695+ if (firstarg == NULL ) {
11696+ PyErr_SetString (PyExc_RuntimeError , "super(): arg[0] deleted" );
11697+ return -1 ;
1169011698 }
1169111699 }
11692- if (firstarg == NULL ) {
11693- PyErr_SetString (PyExc_RuntimeError ,
11694- "super(): arg[0] deleted" );
11695- return -1 ;
11700+ else {
11701+ Py_INCREF (firstarg );
1169611702 }
1169711703
1169811704 // Look for __class__ in the free vars.
@@ -11707,18 +11713,22 @@ super_init_without_args(_PyInterpreterFrame *cframe, PyTypeObject **type_p,
1170711713 if (cell == NULL || !PyCell_Check (cell )) {
1170811714 PyErr_SetString (PyExc_RuntimeError ,
1170911715 "super(): bad __class__ cell" );
11716+ Py_DECREF (firstarg );
1171011717 return -1 ;
1171111718 }
11712- type = (PyTypeObject * ) PyCell_GET ( cell );
11719+ type = (PyTypeObject * ) PyCell_GetRef (( PyCellObject * ) cell );
1171311720 if (type == NULL ) {
1171411721 PyErr_SetString (PyExc_RuntimeError ,
1171511722 "super(): empty __class__ cell" );
11723+ Py_DECREF (firstarg );
1171611724 return -1 ;
1171711725 }
1171811726 if (!PyType_Check (type )) {
1171911727 PyErr_Format (PyExc_RuntimeError ,
1172011728 "super(): __class__ is not a type (%s)" ,
1172111729 Py_TYPE (type )-> tp_name );
11730+ Py_DECREF (type );
11731+ Py_DECREF (firstarg );
1172211732 return -1 ;
1172311733 }
1172411734 break ;
@@ -11727,6 +11737,7 @@ super_init_without_args(_PyInterpreterFrame *cframe, PyTypeObject **type_p,
1172711737 if (type == NULL ) {
1172811738 PyErr_SetString (PyExc_RuntimeError ,
1172911739 "super(): __class__ cell not found" );
11740+ Py_DECREF (firstarg );
1173011741 return -1 ;
1173111742 }
1173211743
@@ -11773,16 +11784,24 @@ super_init_impl(PyObject *self, PyTypeObject *type, PyObject *obj) {
1177311784 return -1 ;
1177411785 }
1177511786 }
11787+ else {
11788+ Py_INCREF (type );
11789+ Py_XINCREF (obj );
11790+ }
1177611791
11777- if (obj == Py_None )
11792+ if (obj == Py_None ) {
11793+ Py_DECREF (obj );
1177811794 obj = NULL ;
11795+ }
1177911796 if (obj != NULL ) {
1178011797 obj_type = supercheck (type , obj );
11781- if (obj_type == NULL )
11798+ if (obj_type == NULL ) {
11799+ Py_DECREF (type );
11800+ Py_DECREF (obj );
1178211801 return -1 ;
11783- Py_INCREF ( obj );
11802+ }
1178411803 }
11785- Py_XSETREF (su -> type , (PyTypeObject * )Py_NewRef ( type ) );
11804+ Py_XSETREF (su -> type , (PyTypeObject * )type );
1178611805 Py_XSETREF (su -> obj , obj );
1178711806 Py_XSETREF (su -> obj_type , obj_type );
1178811807 return 0 ;
0 commit comments