Content-Length: 229903 | pFad | http://github.com/NOAA-ORR-ERD/py_gd/commit/29cb87f55afcb575c8a7ac2a31f62ffd778fe8a8

46 Free our wchar strings after opening our file. · NOAA-ORR-ERD/py_gd@29cb87f · GitHub
Skip to content

Commit

Permalink
Free our wchar strings after opening our file.
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesMakela-NOAA committed Mar 13, 2024
1 parent 049444d commit 29cb87f
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions py_gd/py_gd.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ from cython cimport view

from py_gd cimport *

from cpython.mem cimport PyMem_Free
from libc.stdio cimport FILE, fopen, fclose
from libc.string cimport memcpy, strlen
from libc.stdlib cimport malloc, free
Expand Down Expand Up @@ -73,12 +74,10 @@ cdef FILE* open_file(file_path) except *:
Note: On Windows, it uses a wchar, UTC-16 encoded
On other platforms (Mac and Linux), it assumes utf-8
"""
cdef FILE* fp
cdef FILE* fp = NULL

file_path = os.fspath(file_path)

fp = NULL

IF UNAME_SYSNAME == 'Windows':
#cdef bytes bytes_flag = "wb".encode('utf-16')
#cdef bytes bytes_filepath = file_path.encode('utf-16').bytes
Expand All @@ -87,6 +86,9 @@ cdef FILE* open_file(file_path) except *:
cdef wchar_t *wchar_filepath = PyUnicode_AsWideCharString(file_path, &length)

fp = _wfopen(wchar_filepath, wchar_flag)

PyMem_Free(<void *>wchar_filepath)
PyMem_Free(<void *>wchar_flag)
ELSE:
cdef bytes bytes_flag = "wb".encode('ascii')
fp = fopen(file_path.encode('utf-8'), bytes_flag)
Expand Down

0 comments on commit 29cb87f

Please sign in to comment.








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/NOAA-ORR-ERD/py_gd/commit/29cb87f55afcb575c8a7ac2a31f62ffd778fe8a8

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy