Skip to content

Commit

Permalink
added conditional compilation, _wfopen
Browse files Browse the repository at this point in the history
  • Loading branch information
jay-hennen committed Dec 3, 2021
1 parent dd64edf commit b472b57
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
4 changes: 4 additions & 0 deletions py_gd/py_gd.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ declarations for the cython wrapper around the gd drawing lib
import cython

from libc.stdio cimport FILE
IF UNAME_SYSNAME == "Windows":
cdef extern from "<windows.h>":
ctypedef Py_UNICODE wchar_t
FILE *_wfopen(const wchar_t *filename,const wchar_t *mode)

## access the gd header files:
cdef extern from "gd.h":
Expand Down
15 changes: 8 additions & 7 deletions py_gd/py_gd.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ from py_gd cimport *
from libc.stdio cimport FILE, fopen, fclose
from libc.string cimport memcpy, strlen
from libc.stdlib cimport malloc, free
# from libc.stdint cimport uint8_t, uint32_t

import os
import sys
Expand Down Expand Up @@ -489,7 +488,10 @@ cdef class Image:
.format(file_type_codes))

# open the file here:
fp = fopen(file_path, "wb")
IF UNAME_SYSNAME == 'Windows':
fp = _wfopen(file_path.decode('utf-8'), u"wb")
ELSE:
fp = fopen(file_path, 'wb')
if fp is NULL:
raise IOError('could not open the file: {}'.format(file_path))

Expand Down Expand Up @@ -1158,11 +1160,10 @@ cdef class Animation:
if self._has_closed == 1:
raise RuntimeError('Cannot re-begin closed animation')

self._fp = fopen(self._file_path, "wb")

if self._fp is NULL:
raise IOError('could not open the file: {}'
.format(self._file_path))
IF UNAME_SYSNAME == 'Windows':
self._fp = _wfopen(self._file_path.decode('utf-8'), u"wb")
ELSE:
self._fp = fopen(self._file_path, 'wb')

self.cur_frame = Image(first.width, first.height)
self.cur_frame.copy(first)
Expand Down

0 comments on commit b472b57

Please sign in to comment.