Skip to content

Commit a77e8cf

Browse files
committed
Move PyBytes_RESIZE macro to compat_ext
Provide this macro in one place and `cimport` it everywhere else.
1 parent eac4ef1 commit a77e8cf

File tree

4 files changed

+10
-24
lines changed

4 files changed

+10
-24
lines changed

numcodecs/blosc.pyx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,12 @@ from cpython.bytes cimport (
1515
)
1616
from cpython.memoryview cimport PyMemoryView_GET_BUFFER
1717

18-
from .compat_ext cimport ensure_continguous_memoryview
18+
from .compat_ext cimport PyBytes_RESIZE, ensure_continguous_memoryview
1919

2020
from .compat import ensure_contiguous_ndarray
2121
from .abc import Codec
2222

2323

24-
cdef extern from *:
25-
"""
26-
#define PyBytes_RESIZE(b, n) _PyBytes_Resize(&b, n)
27-
"""
28-
int PyBytes_RESIZE(object b, Py_ssize_t n) except -1
29-
30-
3124
cdef extern from "blosc.h":
3225
cdef enum:
3326
BLOSC_MAX_OVERHEAD,

numcodecs/compat_ext.pxd

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
# cython: language_level=3
22

33

4+
cdef extern from *:
5+
"""
6+
#define PyBytes_RESIZE(b, n) _PyBytes_Resize(&b, n)
7+
"""
8+
int PyBytes_RESIZE(object b, Py_ssize_t n) except -1
9+
10+
411
cpdef memoryview ensure_continguous_memoryview(obj)

numcodecs/lz4.pyx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,13 @@ from cpython.bytes cimport (
1313
)
1414
from cpython.memoryview cimport PyMemoryView_GET_BUFFER
1515

16-
from .compat_ext cimport ensure_continguous_memoryview
16+
from .compat_ext cimport PyBytes_RESIZE, ensure_continguous_memoryview
1717
from ._utils cimport store_le32, load_le32
1818

1919
from .compat import ensure_contiguous_ndarray
2020
from .abc import Codec
2121

2222

23-
cdef extern from *:
24-
"""
25-
#define PyBytes_RESIZE(b, n) _PyBytes_Resize(&b, n)
26-
"""
27-
int PyBytes_RESIZE(object b, Py_ssize_t n) except -1
28-
29-
3023
cdef extern from "lz4.h":
3124

3225
const char* LZ4_versionString() nogil

numcodecs/zstd.pyx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,12 @@ from cpython.bytes cimport (
1111
)
1212
from cpython.memoryview cimport PyMemoryView_GET_BUFFER
1313

14-
from .compat_ext cimport ensure_continguous_memoryview
14+
from .compat_ext cimport PyBytes_RESIZE, ensure_continguous_memoryview
1515

1616
from .compat import ensure_contiguous_ndarray
1717
from .abc import Codec
1818

1919

20-
cdef extern from *:
21-
"""
22-
#define PyBytes_RESIZE(b, n) _PyBytes_Resize(&b, n)
23-
"""
24-
int PyBytes_RESIZE(object b, Py_ssize_t n) except -1
25-
26-
2720
cdef extern from "zstd.h":
2821

2922
unsigned ZSTD_versionNumber() nogil

0 commit comments

Comments
 (0)