Skip to content

Commit dcaa1b6

Browse files
committed
Let cython handle errors for getting buffer
1 parent 986b077 commit dcaa1b6

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/isal/isal_zlib.pyx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ def adler32(data, value = 1):
9696
cdef unsigned long init = PyLong_AsUnsignedLongMask(value)
9797
cdef Py_buffer buffer_data
9898
cdef Py_buffer* buffer = &buffer_data
99-
if PyObject_GetBuffer(data, buffer, PyBUF_SIMPLE) != 0:
100-
raise TypeError("Failed to get buffer")
99+
# Cython makes sure error is handled when acquiring buffer fails.
100+
PyObject_GetBuffer(data, buffer, PyBUF_SIMPLE)
101101
try:
102102
if buffer.len > UINT64_MAX:
103103
raise ValueError("Data too big for adler32")
@@ -116,8 +116,8 @@ def crc32(data, value = 0):
116116
cdef unsigned long init = PyLong_AsUnsignedLongMask(value)
117117
cdef Py_buffer buffer_data
118118
cdef Py_buffer* buffer = &buffer_data
119-
if PyObject_GetBuffer(data, buffer, PyBUF_SIMPLE) != 0:
120-
raise TypeError("Failed to get buffer")
119+
# Cython makes sure error is handled when acquiring buffer fails.
120+
PyObject_GetBuffer(data, buffer, PyBUF_SIMPLE)
121121
try:
122122
if buffer.len > UINT64_MAX:
123123
raise ValueError("Data too big for adler32")
@@ -217,8 +217,8 @@ def compress(data,
217217
# initialise input
218218
cdef Py_buffer buffer_data
219219
cdef Py_buffer* buffer = &buffer_data
220-
if PyObject_GetBuffer(data, buffer, PyBUF_SIMPLE) != 0:
221-
raise TypeError("Failed to get buffer")
220+
# Cython makes sure error is handled when acquiring buffer fails.
221+
PyObject_GetBuffer(data, buffer, PyBUF_SIMPLE)
222222
cdef Py_ssize_t ibuflen = buffer.len
223223
cdef unsigned char * ibuf = <unsigned char*>buffer.buf
224224
stream.next_in = ibuf
@@ -294,8 +294,8 @@ def decompress(data,
294294
# initialise input
295295
cdef Py_buffer buffer_data
296296
cdef Py_buffer* buffer = &buffer_data
297-
if PyObject_GetBuffer(data, buffer, PyBUF_SIMPLE) != 0:
298-
raise TypeError("Failed to get buffer")
297+
# Cython makes sure error is handled when acquiring buffer fails.
298+
PyObject_GetBuffer(data, buffer, PyBUF_SIMPLE)
299299
cdef Py_ssize_t ibuflen = buffer.len
300300
cdef unsigned char * ibuf = <unsigned char*>buffer.buf
301301
stream.next_in = ibuf
@@ -438,8 +438,8 @@ cdef class Compress:
438438
# initialise input
439439
cdef Py_buffer buffer_data
440440
cdef Py_buffer* buffer = &buffer_data
441-
if PyObject_GetBuffer(data, buffer, PyBUF_SIMPLE) != 0:
442-
raise TypeError("Failed to get buffer")
441+
# Cython makes sure error is handled when acquiring buffer fails.
442+
PyObject_GetBuffer(data, buffer, PyBUF_SIMPLE)
443443
cdef Py_ssize_t ibuflen = buffer.len
444444
cdef unsigned char * ibuf = <unsigned char*>buffer.buf
445445
self.stream.next_in = ibuf
@@ -617,8 +617,8 @@ cdef class Decompress:
617617
# initialise input
618618
cdef Py_buffer buffer_data
619619
cdef Py_buffer* buffer = &buffer_data
620-
if PyObject_GetBuffer(data, buffer, PyBUF_SIMPLE) != 0:
621-
raise TypeError("Failed to get buffer")
620+
# Cython makes sure error is handled when acquiring buffer fails.
621+
PyObject_GetBuffer(data, buffer, PyBUF_SIMPLE)
622622
cdef Py_ssize_t ibuflen = buffer.len
623623
cdef unsigned char * ibuf = <unsigned char*>buffer.buf
624624
self.stream.next_in = ibuf
@@ -673,8 +673,8 @@ cdef class Decompress:
673673

674674
cdef Py_buffer buffer_data
675675
cdef Py_buffer* buffer = &buffer_data
676-
if PyObject_GetBuffer(self.unconsumed_tail, buffer, PyBUF_SIMPLE) != 0:
677-
raise TypeError("Failed to get buffer")
676+
# Cython makes sure error is handled when acquiring buffer fails.
677+
PyObject_GetBuffer(self.unconsumed_tail, buffer, PyBUF_SIMPLE)
678678
cdef Py_ssize_t ibuflen = buffer.len
679679
cdef unsigned char * ibuf = <unsigned char*>buffer.buf
680680
self.stream.next_in = ibuf

0 commit comments

Comments
 (0)