Skip to content

Commit

Permalink
Open files in binary mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
mdboom committed Jan 11, 2013
1 parent c3d39b5 commit dda9b7a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/_backend_agg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2034,7 +2034,7 @@ RendererAgg::write_rgba(const Py::Tuple& args)

if (py_fileobj.isString())
{
if ((py_file = npy_PyFile_OpenFile(py_fileobj.ptr(), (char *)"w")) == NULL) {
if ((py_file = npy_PyFile_OpenFile(py_fileobj.ptr(), (char *)"wb")) == NULL) {
throw Py::Exception();
}
close_file = true;
Expand All @@ -2044,7 +2044,7 @@ RendererAgg::write_rgba(const Py::Tuple& args)
py_file = py_fileobj.ptr();
}

if ((fp = npy_PyFile_Dup(py_file, (char *)"w")))
if ((fp = npy_PyFile_Dup(py_file, (char *)"wb")))
{
if (fwrite(pixBuffer, 1, NUMBYTES, fp) != NUMBYTES)
{
Expand Down
8 changes: 4 additions & 4 deletions src/_png.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ Py::Object _png_module::write_png(const Py::Tuple& args)
PyObject* py_file = NULL;
if (py_fileobj.isString())
{
if ((py_file = npy_PyFile_OpenFile(py_fileobj.ptr(), (char *)"w")) == NULL) {
if ((py_file = npy_PyFile_OpenFile(py_fileobj.ptr(), (char *)"wb")) == NULL) {
throw Py::Exception();
}
close_file = true;
Expand All @@ -143,7 +143,7 @@ Py::Object _png_module::write_png(const Py::Tuple& args)
py_file = py_fileobj.ptr();
}

if ((fp = npy_PyFile_Dup(py_file, (char *)"w")))
if ((fp = npy_PyFile_Dup(py_file, (char *)"wb")))
{
close_dup_file = true;
}
Expand Down Expand Up @@ -313,15 +313,15 @@ _png_module::_read_png(const Py::Object& py_fileobj, const bool float_result,

if (py_fileobj.isString())
{
if ((py_file = npy_PyFile_OpenFile(py_fileobj.ptr(), (char *)"r")) == NULL) {
if ((py_file = npy_PyFile_OpenFile(py_fileobj.ptr(), (char *)"rb")) == NULL) {
throw Py::Exception();
}
close_file = true;
} else {
py_file = py_fileobj.ptr();
}

if ((fp = npy_PyFile_Dup(py_file, "r")))
if ((fp = npy_PyFile_Dup(py_file, "rb")))
{
close_dup_file = true;
}
Expand Down

0 comments on commit dda9b7a

Please sign in to comment.