Skip to content

Commit 6a2cc9d

Browse files
committed
Stash exceptions when FT2Font closes the underlying stream.
Previously, PyErr_Occurred could also catch exceptions that have been set earlier, and have nothing to do with file closing.
1 parent 8a8dd90 commit 6a2cc9d

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/ft2font_wrapper.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,8 @@ static unsigned long read_from_file_callback(FT_Stream stream,
297297

298298
static void close_file_callback(FT_Stream stream)
299299
{
300+
PyObject *type, *value, *traceback;
301+
PyErr_Fetch(&type, &value, &traceback);
300302
PyFT2Font *self = (PyFT2Font *)stream->descriptor.pointer;
301303
PyObject *close_result = NULL;
302304
if (!(close_result = PyObject_CallMethod(self->py_file, "close", ""))) {
@@ -308,6 +310,7 @@ static void close_file_callback(FT_Stream stream)
308310
if (PyErr_Occurred()) {
309311
PyErr_WriteUnraisable((PyObject*)self);
310312
}
313+
PyErr_Restore(type, value, traceback);
311314
}
312315

313316
static PyTypeObject PyFT2FontType;

0 commit comments

Comments
 (0)