11cimport qoi.qoi as qoi
22import numpy as np
33cimport numpy as np
4- from cpython.mem cimport PyMem_Free
4+ from cpython.mem cimport PyMem_RawFree
55import enum
66from 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
3131cpdef 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
8686cpdef 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
111111cpdef 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