@@ -1092,7 +1092,6 @@ match_class(PyThreadState *tstate, PyObject *subject, PyObject *type,
1092
1092
1093
1093
1094
1094
static int do_raise (PyThreadState * tstate , PyObject * exc , PyObject * cause );
1095
- static PyObject * do_reraise_star (PyObject * excs , PyObject * orig );
1096
1095
static int exception_group_match (
1097
1096
PyObject * exc_value , PyObject * match_type ,
1098
1097
PyObject * * match , PyObject * * rest );
@@ -2777,16 +2776,14 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
2777
2776
assert (PyList_Check (excs ));
2778
2777
PyObject * orig = POP ();
2779
2778
2780
- PyObject * val = do_reraise_star ( excs , orig );
2779
+ PyObject * val = _PyExc_PrepReraiseStar ( orig , excs );
2781
2780
Py_DECREF (excs );
2782
2781
Py_DECREF (orig );
2783
2782
2784
2783
if (val == NULL ) {
2785
2784
goto error ;
2786
2785
}
2787
2786
2788
- PyObject * lasti_unused = Py_NewRef (_PyLong_GetZero ());
2789
- PUSH (lasti_unused );
2790
2787
PUSH (val );
2791
2788
DISPATCH ();
2792
2789
}
@@ -6313,134 +6310,6 @@ exception_group_match(PyObject* exc_value, PyObject *match_type,
6313
6310
return 0 ;
6314
6311
}
6315
6312
6316
- /* Logic for the final raise/reraise of a try-except* contruct
6317
- (too complicated for inlining).
6318
- */
6319
-
6320
- static bool
6321
- is_same_exception_metadata (PyObject * exc1 , PyObject * exc2 )
6322
- {
6323
- assert (PyExceptionInstance_Check (exc1 ));
6324
- assert (PyExceptionInstance_Check (exc2 ));
6325
-
6326
- PyObject * tb1 = PyException_GetTraceback (exc1 );
6327
- PyObject * ctx1 = PyException_GetContext (exc1 );
6328
- PyObject * cause1 = PyException_GetCause (exc1 );
6329
- PyObject * tb2 = PyException_GetTraceback (exc2 );
6330
- PyObject * ctx2 = PyException_GetContext (exc2 );
6331
- PyObject * cause2 = PyException_GetCause (exc2 );
6332
-
6333
- bool result = (Py_Is (tb1 , tb2 ) &&
6334
- Py_Is (ctx1 , ctx2 ) &&
6335
- Py_Is (cause1 , cause2 ));
6336
-
6337
- Py_XDECREF (tb1 );
6338
- Py_XDECREF (ctx1 );
6339
- Py_XDECREF (cause1 );
6340
- Py_XDECREF (tb2 );
6341
- Py_XDECREF (ctx2 );
6342
- Py_XDECREF (cause2 );
6343
- return result ;
6344
- }
6345
-
6346
- /*
6347
- excs: a list of exceptions to raise/reraise
6348
- orig: the original except that was caught
6349
-
6350
- Calculates an exception group to raise. It contains
6351
- all exceptions in excs, where those that were reraised
6352
- have same nesting structure as in orig, and those that
6353
- were raised (if any) are added as siblings in a new EG.
6354
-
6355
- Returns NULL and sets an exception on failure.
6356
- */
6357
- static PyObject *
6358
- do_reraise_star (PyObject * excs , PyObject * orig )
6359
- {
6360
- assert (PyList_Check (excs ));
6361
- assert (PyExceptionInstance_Check (orig ));
6362
-
6363
- Py_ssize_t numexcs = PyList_GET_SIZE (excs );
6364
-
6365
- if (numexcs == 0 ) {
6366
- return Py_NewRef (Py_None );
6367
- }
6368
-
6369
- if (!_PyBaseExceptionGroup_Check (orig )) {
6370
- /* a naked exception was caught and wrapped. Only one except* clause
6371
- * could have executed,so there is at most one exception to raise.
6372
- */
6373
-
6374
- assert (numexcs == 1 || (numexcs == 2 && PyList_GET_ITEM (excs , 1 ) == Py_None ));
6375
-
6376
- PyObject * e = PyList_GET_ITEM (excs , 0 );
6377
- assert (e != NULL );
6378
- return Py_NewRef (e );
6379
- }
6380
-
6381
-
6382
- PyObject * raised_list = PyList_New (0 );
6383
- if (raised_list == NULL ) {
6384
- return NULL ;
6385
- }
6386
- PyObject * reraised_list = PyList_New (0 );
6387
- if (reraised_list == NULL ) {
6388
- Py_DECREF (raised_list );
6389
- return NULL ;
6390
- }
6391
-
6392
- /* Now we are holding refs to raised_list and reraised_list */
6393
-
6394
- PyObject * result = NULL ;
6395
-
6396
- /* Split excs into raised and reraised by comparing metadata with orig */
6397
- for (Py_ssize_t i = 0 ; i < numexcs ; i ++ ) {
6398
- PyObject * e = PyList_GET_ITEM (excs , i );
6399
- assert (e != NULL );
6400
- if (Py_IsNone (e )) {
6401
- continue ;
6402
- }
6403
- bool is_reraise = is_same_exception_metadata (e , orig );
6404
- PyObject * append_list = is_reraise ? reraised_list : raised_list ;
6405
- if (PyList_Append (append_list , e ) < 0 ) {
6406
- goto done ;
6407
- }
6408
- }
6409
-
6410
- PyObject * reraised_eg = _PyExc_ExceptionGroupProjection (orig , reraised_list );
6411
- if (reraised_eg == NULL ) {
6412
- goto done ;
6413
- }
6414
-
6415
- if (!Py_IsNone (reraised_eg )) {
6416
- assert (is_same_exception_metadata (reraised_eg , orig ));
6417
- }
6418
-
6419
- Py_ssize_t num_raised = PyList_GET_SIZE (raised_list );
6420
- if (num_raised == 0 ) {
6421
- result = reraised_eg ;
6422
- }
6423
- else if (num_raised > 0 ) {
6424
- int res = 0 ;
6425
- if (!Py_IsNone (reraised_eg )) {
6426
- res = PyList_Append (raised_list , reraised_eg );
6427
- }
6428
- Py_DECREF (reraised_eg );
6429
- if (res < 0 ) {
6430
- goto done ;
6431
- }
6432
- result = _PyExc_CreateExceptionGroup ("" , raised_list );
6433
- if (result == NULL ) {
6434
- goto done ;
6435
- }
6436
- }
6437
-
6438
- done :
6439
- Py_XDECREF (raised_list );
6440
- Py_XDECREF (reraised_list );
6441
- return result ;
6442
- }
6443
-
6444
6313
/* Iterate v argcnt times and store the results on the stack (via decreasing
6445
6314
sp). Return 1 for success, 0 if error.
6446
6315
0 commit comments