Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dda9b7a

Browse files
committed
Open files in binary mode.
1 parent c3d39b5 commit dda9b7a

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

src/_backend_agg.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2034,7 +2034,7 @@ RendererAgg::write_rgba(const Py::Tuple& args)
20342034

20352035
if (py_fileobj.isString())
20362036
{
2037-
if ((py_file = npy_PyFile_OpenFile(py_fileobj.ptr(), (char *)"w")) == NULL) {
2037+
if ((py_file = npy_PyFile_OpenFile(py_fileobj.ptr(), (char *)"wb")) == NULL) {
20382038
throw Py::Exception();
20392039
}
20402040
close_file = true;
@@ -2044,7 +2044,7 @@ RendererAgg::write_rgba(const Py::Tuple& args)
20442044
py_file = py_fileobj.ptr();
20452045
}
20462046

2047-
if ((fp = npy_PyFile_Dup(py_file, (char *)"w")))
2047+
if ((fp = npy_PyFile_Dup(py_file, (char *)"wb")))
20482048
{
20492049
if (fwrite(pixBuffer, 1, NUMBYTES, fp) != NUMBYTES)
20502050
{

src/_png.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ Py::Object _png_module::write_png(const Py::Tuple& args)
133133
PyObject* py_file = NULL;
134134
if (py_fileobj.isString())
135135
{
136-
if ((py_file = npy_PyFile_OpenFile(py_fileobj.ptr(), (char *)"w")) == NULL) {
136+
if ((py_file = npy_PyFile_OpenFile(py_fileobj.ptr(), (char *)"wb")) == NULL) {
137137
throw Py::Exception();
138138
}
139139
close_file = true;
@@ -143,7 +143,7 @@ Py::Object _png_module::write_png(const Py::Tuple& args)
143143
py_file = py_fileobj.ptr();
144144
}
145145

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

314314
if (py_fileobj.isString())
315315
{
316-
if ((py_file = npy_PyFile_OpenFile(py_fileobj.ptr(), (char *)"r")) == NULL) {
316+
if ((py_file = npy_PyFile_OpenFile(py_fileobj.ptr(), (char *)"rb")) == NULL) {
317317
throw Py::Exception();
318318
}
319319
close_file = true;
320320
} else {
321321
py_file = py_fileobj.ptr();
322322
}
323323

324-
if ((fp = npy_PyFile_Dup(py_file, "r")))
324+
if ((fp = npy_PyFile_Dup(py_file, "rb")))
325325
{
326326
close_dup_file = true;
327327
}

0 commit comments

Comments
 (0)