Skip to content

Commit 99d7383

Browse files
authored
Merge pull request #23 from synodriver/main
match PyMem_RawMalloc
2 parents 9a058a9 + ad10793 commit 99d7383

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

src/qoi/qoi.pyx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cimport qoi.qoi as qoi
22
import numpy as np
33
cimport numpy as np
4-
from cpython.mem cimport PyMem_Free
4+
from cpython.mem cimport PyMem_RawFree
55
import enum
66
from pathlib import Path
77

@@ -26,7 +26,7 @@ cdef class PixelWrapper:
2626
return ndarray
2727

2828
def __dealloc__(self):
29-
PyMem_Free(self.pixels)
29+
PyMem_RawFree(self.pixels)
3030

3131
cpdef int write(filename, unsigned char[:,:,::1] rgb, colorspace: QOIColorSpace = QOIColorSpace.SRGB) except? -1:
3232
cdef bytes filename_bytes
@@ -81,7 +81,7 @@ cpdef np.ndarray[DTYPE_t, ndim=3] read(filename, int channels = 0, unsigned char
8181
return PixelWrapper().as_ndarray(desc.height, desc.width, desc.channels if channels == 0 else channels, pixels)
8282
except:
8383
if pixels is not NULL:
84-
PyMem_Free(pixels)
84+
PyMem_RawFree(pixels)
8585

8686
cpdef bytes encode(unsigned char[:,:,::1] rgb, colorspace: QOIColorSpace = QOIColorSpace.SRGB):
8787
cdef qoi.qoi_desc desc
@@ -106,7 +106,7 @@ cpdef bytes encode(unsigned char[:,:,::1] rgb, colorspace: QOIColorSpace = QOICo
106106
# TODO: does this create a copy? A: Yes, this equivalent to PyBytes_FromStringAndSize
107107
return encoded[:size] # :size is important here - tells cython about size, and handles null bytes
108108
finally:
109-
PyMem_Free(encoded)
109+
PyMem_RawFree(encoded)
110110

111111
cpdef np.ndarray[DTYPE_t, ndim=3] decode(const unsigned char[::1] data, int channels = 0, unsigned char[::1] colorspace = bytearray(1)):
112112
# TODO: what to do about desc.colorspace? A: How about return a tuple of ndarray and a wrapper around struct qoi_desc? or we can add another param like char[:] to simulate pointer
@@ -122,4 +122,4 @@ cpdef np.ndarray[DTYPE_t, ndim=3] decode(const unsigned char[::1] data, int chan
122122
return PixelWrapper().as_ndarray(desc.height, desc.width, desc.channels if channels == 0 else channels, pixels)
123123
except:
124124
if pixels is not NULL:
125-
PyMem_Free(pixels)
125+
PyMem_RawFree(pixels)

0 commit comments

Comments
 (0)