FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Don't abort on FT2Font weakref. by anntzer · Pull Request #9074 · matplotlib/matplotlib · GitHub

Repository navigation

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .h  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
30 changes: 25 additions & 5 deletions src/file_compat.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ static NPY_INLINE FILE *mpl_PyFile_Dup(PyObject *file, char *mode, mpl_off_t *or
*/
static NPY_INLINE int mpl_PyFile_DupClose(PyObject *file, FILE *handle, mpl_off_t orig_pos)
{
PyObject *exc_type = NULL, *exc_value = NULL, *exc_tb = NULL;
PyErr_Fetch(&exc_type, &exc_value, &exc_tb);

int fd;
PyObject *ret;
mpl_off_t position;
Expand All @@ -136,25 +139,33 @@ static NPY_INLINE int mpl_PyFile_DupClose(PyObject *file, FILE *handle, mpl_off_
fclose(handle);

/* Restore original file handle position, in order to not confuse
Python-side data structures */
Python-side data structures. Note that this would fail if an exception
is currently set, which can happen as this function is called in cleanup
code, so we need to carefully fetch and restore the exception state. */
fd = PyObject_AsFileDescriptor(file);
if (fd == -1) {
return -1;
goto fail;
}
if (mpl_lseek(fd, orig_pos, SEEK_SET) != -1) {
if (position == -1) {
PyErr_SetString(PyExc_IOError, "obtaining file position failed");
return -1;
goto fail;
}

/* Seek Python-side handle to the FILE* handle position */
ret = PyObject_CallMethod(file, (char *)"seek", (char *)(MPL_OFF_T_PYFMT "i"), position, 0);
if (ret == NULL) {
return -1;
goto fail;
}
Py_DECREF(ret);
}
PyErr_Restore(exc_type, exc_value, exc_tb);
return 0;
fail:
Py_XDECREF(exc_type);
Py_XDECREF(exc_value);
Py_XDECREF(exc_tb);
return -1;
}

static NPY_INLINE int mpl_PyFile_Check(PyObject *file)
Expand Down Expand Up @@ -200,14 +211,23 @@ static NPY_INLINE PyObject *mpl_PyFile_OpenFile(PyObject *filename, const char *

static NPY_INLINE int mpl_PyFile_CloseFile(PyObject *file)
{
PyObject *type, *value, *tb;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

... and here too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

as above

PyErr_Fetch(&type, &value, &tb);

PyObject *ret;

ret = PyObject_CallMethod(file, (char *)"close", NULL);
if (ret == NULL) {
return -1;
goto fail;
}
Py_DECREF(ret);
PyErr_Restore(type, value, tb);
return 0;
fail:
Py_XDECREF(type);
Py_XDECREF(value);
Py_XDECREF(tb);
return -1;
}

#ifdef __cplusplus
Expand Down

Back | FazBrowse Home | New Git URL