@@ -2437,7 +2437,6 @@ einsum_list_to_subscripts(PyObject *obj, char *subscripts, int subsize)
2437
2437
}
2438
2438
size = PySequence_Size (obj );
2439
2439
2440
-
2441
2440
for (i = 0 ; i < size ; ++ i ) {
2442
2441
item = PySequence_Fast_GET_ITEM (obj , i );
2443
2442
/* Ellipsis */
@@ -2459,46 +2458,48 @@ einsum_list_to_subscripts(PyObject *obj, char *subscripts, int subsize)
2459
2458
subscripts [subindex ++ ] = '.' ;
2460
2459
ellipsis = 1 ;
2461
2460
}
2462
- /* Subscript */
2463
- else if (PyInt_Check (item ) || PyLong_Check (item )) {
2464
- long s = PyInt_AsLong (item );
2465
- npy_bool bad_input = 0 ;
2461
+ else {
2462
+ long s = PyLong_AsLong (item );
2463
+ /* Subscript */
2464
+ if (!PyErr_Occurred ()) {
2465
+ npy_bool bad_input = 0 ;
2466
2466
2467
- if (subindex + 1 >= subsize ) {
2468
- PyErr_SetString (PyExc_ValueError ,
2469
- "subscripts list is too long" );
2470
- Py_DECREF (obj );
2471
- return -1 ;
2472
- }
2467
+ if (subindex + 1 >= subsize ) {
2468
+ PyErr_SetString (PyExc_ValueError ,
2469
+ "subscripts list is too long" );
2470
+ Py_DECREF (obj );
2471
+ return -1 ;
2472
+ }
2473
2473
2474
- if ( s < 0 ) {
2475
- bad_input = 1 ;
2476
- }
2477
- else if (s < 26 ) {
2478
- subscripts [subindex ++ ] = 'A' + (char )s ;
2479
- }
2480
- else if (s < 2 * 26 ) {
2481
- subscripts [subindex ++ ] = 'a' + (char )s - 26 ;
2474
+ if ( s < 0 ) {
2475
+ bad_input = 1 ;
2476
+ }
2477
+ else if (s < 26 ) {
2478
+ subscripts [subindex ++ ] = 'A' + (char )s ;
2479
+ }
2480
+ else if (s < 2 * 26 ) {
2481
+ subscripts [subindex ++ ] = 'a' + (char )s - 26 ;
2482
+ }
2483
+ else {
2484
+ bad_input = 1 ;
2485
+ }
2486
+
2487
+ if (bad_input ) {
2488
+ PyErr_SetString (PyExc_ValueError ,
2489
+ "subscript is not within the valid range [0, 52)" );
2490
+ Py_DECREF (obj );
2491
+ return -1 ;
2492
+ }
2482
2493
}
2494
+ /* Invalid */
2483
2495
else {
2484
- bad_input = 1 ;
2485
- }
2486
-
2487
- if (bad_input ) {
2488
2496
PyErr_SetString (PyExc_ValueError ,
2489
- "subscript is not within the valid range [0, 52)" );
2497
+ "each subscript must be either an integer "
2498
+ "or an ellipsis" );
2490
2499
Py_DECREF (obj );
2491
2500
return -1 ;
2492
2501
}
2493
- }
2494
- /* Invalid */
2495
- else {
2496
- PyErr_SetString (PyExc_ValueError ,
2497
- "each subscript must be either an integer "
2498
- "or an ellipsis" );
2499
- Py_DECREF (obj );
2500
- return -1 ;
2501
- }
2502
+ }
2502
2503
}
2503
2504
2504
2505
Py_DECREF (obj );
0 commit comments