Skip to content

Commit 2b74cb5

Browse files
committed
Merge pull request #2898 from bytbox/v1.3.x
Fix animation errors
2 parents 4d05931 + b79541d commit 2b74cb5

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

src/_backend_agg.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2168,6 +2168,7 @@ RendererAgg::write_rgba(const Py::Tuple& args)
21682168
}
21692169
else
21702170
{
2171+
PyErr_Clear();
21712172
PyObject* write_method = PyObject_GetAttrString(py_fileobj.ptr(),
21722173
"write");
21732174
if (!(write_method && PyCallable_Check(write_method)))
@@ -2177,7 +2178,11 @@ RendererAgg::write_rgba(const Py::Tuple& args)
21772178
"Object does not appear to be a 8-bit string path or a Python file-like object");
21782179
}
21792180

2181+
#if PY3K
2182+
PyObject_CallFunction(write_method, (char *)"y#", pixBuffer, NUMBYTES);
2183+
#else
21802184
PyObject_CallFunction(write_method, (char *)"s#", pixBuffer, NUMBYTES);
2185+
#endif
21812186

21822187
Py_XDECREF(write_method);
21832188
}

src/file_compat.h

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ mpl_PyFile_Dup(PyObject *file, char *mode, mpl_off_t *orig_pos)
101101
/* Record the original raw file handle position */
102102
*orig_pos = npy_ftell(handle);
103103
if (*orig_pos == -1) {
104-
PyErr_SetString(PyExc_IOError, "obtaining file position failed");
105-
return NULL;
104+
// handle is a stream, so we don't have to worry about this
105+
return handle;
106106
}
107107

108108
/* Seek raw handle to the Python-side position */
@@ -145,22 +145,19 @@ mpl_PyFile_DupClose(PyObject *file, FILE* handle, mpl_off_t orig_pos)
145145
if (fd == -1) {
146146
return -1;
147147
}
148-
if (npy_lseek(fd, orig_pos, SEEK_SET) == -1) {
149-
PyErr_SetString(PyExc_IOError, "seeking file failed");
150-
return -1;
151-
}
152-
153-
if (position == -1) {
154-
PyErr_SetString(PyExc_IOError, "obtaining file position failed");
155-
return -1;
156-
}
148+
if (npy_lseek(fd, orig_pos, SEEK_SET) != -1) {
149+
if (position == -1) {
150+
PyErr_SetString(PyExc_IOError, "obtaining file position failed");
151+
return -1;
152+
}
157153

158-
/* Seek Python-side handle to the FILE* handle position */
159-
ret = PyObject_CallMethod(file, "seek", MPL_OFF_T_PYFMT "i", position, 0);
160-
if (ret == NULL) {
161-
return -1;
154+
/* Seek Python-side handle to the FILE* handle position */
155+
ret = PyObject_CallMethod(file, "seek", MPL_OFF_T_PYFMT "i", position, 0);
156+
if (ret == NULL) {
157+
return -1;
158+
}
159+
Py_DECREF(ret);
162160
}
163-
Py_DECREF(ret);
164161
return 0;
165162
}
166163

0 commit comments

Comments
 (0)