File tree Expand file tree Collapse file tree 1 file changed +25
-2
lines changed
numpy/_core/include/numpy Expand file tree Collapse file tree 1 file changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -245,9 +245,32 @@ npy_PyFile_CloseFile(PyObject *file)
245
245
return 0 ;
246
246
}
247
247
248
+ /* This is a copy of _PyErr_ChainExceptions, which
249
+ * is no longer exported from Python3.12
250
+ */
251
+ static inline void
252
+ npy_PyErr_ChainExceptions (PyObject * exc , PyObject * val , PyObject * tb )
253
+ {
254
+ if (exc == NULL )
255
+ return ;
248
256
249
- #define npy_PyErr_ChainExceptions _PyErr_ChainExceptions
250
-
257
+ if (PyErr_Occurred ()) {
258
+ PyObject * exc2 , * val2 , * tb2 ;
259
+ PyErr_Fetch (& exc2 , & val2 , & tb2 );
260
+ PyErr_NormalizeException (& exc , & val , & tb );
261
+ if (tb != NULL ) {
262
+ PyException_SetTraceback (val , tb );
263
+ Py_DECREF (tb );
264
+ }
265
+ Py_DECREF (exc );
266
+ PyErr_NormalizeException (& exc2 , & val2 , & tb2 );
267
+ PyException_SetContext (val2 , val );
268
+ PyErr_Restore (exc2 , val2 , tb2 );
269
+ }
270
+ else {
271
+ PyErr_Restore (exc , val , tb );
272
+ }
273
+ }
251
274
252
275
/* This is a copy of _PyErr_ChainExceptions, with:
253
276
* __cause__ used instead of __context__
You can’t perform that action at this time.
0 commit comments