@@ -5254,11 +5254,15 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
5254
5254
assert (call_shape .kwnames == NULL );
5255
5255
int is_meth = is_method (stack_pointer , oparg );
5256
5256
int total_args = oparg + is_meth ;
5257
- PyObject * callable = PEEK (total_args + 1 );
5257
+ PyMethodDescrObject * callable =
5258
+ (PyMethodDescrObject * )PEEK (total_args + 1 );
5258
5259
DEOPT_IF (total_args != 2 , PRECALL );
5259
5260
DEOPT_IF (!Py_IS_TYPE (callable , & PyMethodDescr_Type ), PRECALL );
5260
- PyMethodDef * meth = (( PyMethodDescrObject * ) callable ) -> d_method ;
5261
+ PyMethodDef * meth = callable -> d_method ;
5261
5262
DEOPT_IF (meth -> ml_flags != METH_O , PRECALL );
5263
+ PyObject * arg = TOP ();
5264
+ PyObject * self = SECOND ();
5265
+ DEOPT_IF (!Py_IS_TYPE (self , callable -> d_common .d_type ), PRECALL );
5262
5266
STAT_INC (PRECALL , hit );
5263
5267
SKIP_CALL ();
5264
5268
PyCFunction cfunc = meth -> ml_meth ;
@@ -5267,8 +5271,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
5267
5271
if (_Py_EnterRecursiveCall (tstate , " while calling a Python object" )) {
5268
5272
goto error ;
5269
5273
}
5270
- PyObject * arg = TOP ();
5271
- PyObject * self = SECOND ();
5272
5274
PyObject * res = cfunc (self , arg );
5273
5275
_Py_LeaveRecursiveCall (tstate );
5274
5276
assert ((res != NULL ) ^ (_PyErr_Occurred (tstate ) != NULL ));
@@ -5287,17 +5289,22 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
5287
5289
TARGET (PRECALL_METHOD_DESCRIPTOR_FAST_WITH_KEYWORDS ) {
5288
5290
int is_meth = is_method (stack_pointer , oparg );
5289
5291
int total_args = oparg + is_meth ;
5290
- PyObject * callable = PEEK (total_args + 1 );
5292
+ PyMethodDescrObject * callable =
5293
+ (PyMethodDescrObject * )PEEK (total_args + 1 );
5291
5294
DEOPT_IF (!Py_IS_TYPE (callable , & PyMethodDescr_Type ), PRECALL );
5292
- PyMethodDef * meth = (( PyMethodDescrObject * ) callable ) -> d_method ;
5295
+ PyMethodDef * meth = callable -> d_method ;
5293
5296
DEOPT_IF (meth -> ml_flags != (METH_FASTCALL |METH_KEYWORDS ), PRECALL );
5297
+ PyTypeObject * d_type = callable -> d_common .d_type ;
5298
+ PyObject * self = PEEK (total_args );
5299
+ DEOPT_IF (!Py_IS_TYPE (self , d_type ), PRECALL );
5294
5300
STAT_INC (PRECALL , hit );
5295
5301
SKIP_CALL ();
5296
5302
int nargs = total_args - 1 ;
5297
5303
STACK_SHRINK (nargs );
5298
- _PyCFunctionFastWithKeywords cfunc = (_PyCFunctionFastWithKeywords )(void (* )(void ))meth -> ml_meth ;
5299
- PyObject * self = TOP ();
5300
- PyObject * res = cfunc (self , stack_pointer , nargs - KWNAMES_LEN (), call_shape .kwnames );
5304
+ _PyCFunctionFastWithKeywords cfunc =
5305
+ (_PyCFunctionFastWithKeywords )(void (* )(void ))meth -> ml_meth ;
5306
+ PyObject * res = cfunc (self , stack_pointer , nargs - KWNAMES_LEN (),
5307
+ call_shape .kwnames );
5301
5308
assert ((res != NULL ) ^ (_PyErr_Occurred (tstate ) != NULL ));
5302
5309
call_shape .kwnames = NULL ;
5303
5310
@@ -5322,9 +5329,11 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
5322
5329
int is_meth = is_method (stack_pointer , oparg );
5323
5330
int total_args = oparg + is_meth ;
5324
5331
DEOPT_IF (total_args != 1 , PRECALL );
5325
- PyObject * callable = SECOND ();
5332
+ PyMethodDescrObject * callable = ( PyMethodDescrObject * ) SECOND ();
5326
5333
DEOPT_IF (!Py_IS_TYPE (callable , & PyMethodDescr_Type ), PRECALL );
5327
- PyMethodDef * meth = ((PyMethodDescrObject * )callable )-> d_method ;
5334
+ PyMethodDef * meth = callable -> d_method ;
5335
+ PyObject * self = TOP ();
5336
+ DEOPT_IF (!Py_IS_TYPE (self , callable -> d_common .d_type ), PRECALL );
5328
5337
DEOPT_IF (meth -> ml_flags != METH_NOARGS , PRECALL );
5329
5338
STAT_INC (PRECALL , hit );
5330
5339
SKIP_CALL ();
@@ -5334,7 +5343,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
5334
5343
if (_Py_EnterRecursiveCall (tstate , " while calling a Python object" )) {
5335
5344
goto error ;
5336
5345
}
5337
- PyObject * self = TOP ();
5338
5346
PyObject * res = cfunc (self , NULL );
5339
5347
_Py_LeaveRecursiveCall (tstate );
5340
5348
assert ((res != NULL ) ^ (_PyErr_Occurred (tstate ) != NULL ));
@@ -5353,17 +5361,20 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
5353
5361
assert (call_shape .kwnames == NULL );
5354
5362
int is_meth = is_method (stack_pointer , oparg );
5355
5363
int total_args = oparg + is_meth ;
5356
- PyObject * callable = PEEK (total_args + 1 );
5364
+ PyMethodDescrObject * callable =
5365
+ (PyMethodDescrObject * )PEEK (total_args + 1 );
5357
5366
/* Builtin METH_FASTCALL methods, without keywords */
5358
5367
DEOPT_IF (!Py_IS_TYPE (callable , & PyMethodDescr_Type ), PRECALL );
5359
- PyMethodDef * meth = (( PyMethodDescrObject * ) callable ) -> d_method ;
5368
+ PyMethodDef * meth = callable -> d_method ;
5360
5369
DEOPT_IF (meth -> ml_flags != METH_FASTCALL , PRECALL );
5370
+ PyObject * self = PEEK (total_args );
5371
+ DEOPT_IF (!Py_IS_TYPE (self , callable -> d_common .d_type ), PRECALL );
5361
5372
STAT_INC (PRECALL , hit );
5362
5373
SKIP_CALL ();
5363
- _PyCFunctionFast cfunc = (_PyCFunctionFast )(void (* )(void ))meth -> ml_meth ;
5374
+ _PyCFunctionFast cfunc =
5375
+ (_PyCFunctionFast )(void (* )(void ))meth -> ml_meth ;
5364
5376
int nargs = total_args - 1 ;
5365
5377
STACK_SHRINK (nargs );
5366
- PyObject * self = TOP ();
5367
5378
PyObject * res = cfunc (self , stack_pointer , nargs );
5368
5379
assert ((res != NULL ) ^ (_PyErr_Occurred (tstate ) != NULL ));
5369
5380
/* Clear the stack of the arguments. */
0 commit comments