Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix animation errors #2898

Merged
merged 2 commits into from May 13, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/_backend_agg.cpp
Expand Up @@ -2168,6 +2168,7 @@ RendererAgg::write_rgba(const Py::Tuple& args)
}
else
{
PyErr_Clear();
PyObject* write_method = PyObject_GetAttrString(py_fileobj.ptr(),
"write");
if (!(write_method && PyCallable_Check(write_method)))
Expand All @@ -2177,7 +2178,11 @@ RendererAgg::write_rgba(const Py::Tuple& args)
"Object does not appear to be a 8-bit string path or a Python file-like object");
}

#if PY3K
PyObject_CallFunction(write_method, (char *)"y#", pixBuffer, NUMBYTES);
#else
PyObject_CallFunction(write_method, (char *)"s#", pixBuffer, NUMBYTES);
#endif
Copy link
Member

Choose a reason for hiding this comment

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

Good catch.


Py_XDECREF(write_method);
}
Expand Down
29 changes: 13 additions & 16 deletions src/file_compat.h
Expand Up @@ -101,8 +101,8 @@ mpl_PyFile_Dup(PyObject *file, char *mode, mpl_off_t *orig_pos)
/* Record the original raw file handle position */
*orig_pos = npy_ftell(handle);
if (*orig_pos == -1) {
PyErr_SetString(PyExc_IOError, "obtaining file position failed");
return NULL;
// handle is a stream, so we don't have to worry about this
return handle;
}

/* Seek raw handle to the Python-side position */
Expand Down Expand Up @@ -145,22 +145,19 @@ mpl_PyFile_DupClose(PyObject *file, FILE* handle, mpl_off_t orig_pos)
if (fd == -1) {
return -1;
}
if (npy_lseek(fd, orig_pos, SEEK_SET) == -1) {
PyErr_SetString(PyExc_IOError, "seeking file failed");
return -1;
}

if (position == -1) {
PyErr_SetString(PyExc_IOError, "obtaining file position failed");
return -1;
}
if (npy_lseek(fd, orig_pos, SEEK_SET) != -1) {
if (position == -1) {
PyErr_SetString(PyExc_IOError, "obtaining file position failed");
return -1;
}

/* Seek Python-side handle to the FILE* handle position */
ret = PyObject_CallMethod(file, "seek", MPL_OFF_T_PYFMT "i", position, 0);
if (ret == NULL) {
return -1;
/* Seek Python-side handle to the FILE* handle position */
ret = PyObject_CallMethod(file, "seek", MPL_OFF_T_PYFMT "i", position, 0);
if (ret == NULL) {
return -1;
}
Copy link
Member

Choose a reason for hiding this comment

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

This all makes sense. This code was obtained from Numpy (we used to just use it in Numpy, but this was declared a "private" API in Numpy 1.9, so we were forced to copy it here). We probably should report the bug to them as well.

Py_DECREF(ret);
}
Py_DECREF(ret);
return 0;
}

Expand Down