Skip to content

Commit 62a45ef

Browse files
committed
feat(python): only use custom Py_buffer if limited api is below 3.11
1 parent cc15149 commit 62a45ef

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

python/_brotli.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616
#define PyList_GET_ITEM PyList_GetItem
1717
#define PyList_SET_ITEM PyList_SetItem
1818
#define PyBytes_AS_STRING PyBytes_AsString
19-
// Py_buffer is only available in stable api 3.10+
2019
// as we want to support 3.6+ we need to define a dummy struct
2120
// to not break compatibility with Python 2
2221
// len is of type int, as Py_ssize_t clean is 3.7+
22+
#ifdef Py_LIMITED_API && PY_VERSION_HEX < 0x030B0000
23+
// Py_buffer is only available in stable api 3.11+
2324
typedef struct {
2425
void *buf;
2526
int len;
@@ -29,6 +30,7 @@ static void PyBuffer_Release(Py_buffer *view) {
2930
view->len = -1;
3031
}
3132
#endif
33+
#endif
3234
#else
3335
#define Py_ARRAY_LENGTH(array) (sizeof(array) / sizeof((array)[0]))
3436
#endif
@@ -460,7 +462,7 @@ static PyObject* brotli_Compressor_process(brotli_Compressor *self, PyObject *ar
460462
int ok;
461463

462464
#if PY_MAJOR_VERSION >= 3
463-
#ifdef Py_LIMITED_API
465+
#ifdef Py_LIMITED_API && PY_VERSION_HEX < 0x030B0000
464466
ok = PyArg_ParseTuple(args, "y#:process", &input.buf, &input.len);
465467
#else
466468
ok = PyArg_ParseTuple(args, "y*:process", &input);
@@ -780,7 +782,7 @@ static PyObject* brotli_Decompressor_process(brotli_Decompressor *self, PyObject
780782
int ok;
781783

782784
#if PY_MAJOR_VERSION >= 3
783-
#ifdef Py_LIMITED_API
785+
#ifdef Py_LIMITED_API && PY_VERSION_HEX < 0x030B0000
784786
ok = PyArg_ParseTuple(args, "y#:process", &input.buf, &input.len);
785787
#else
786788
ok = PyArg_ParseTuple(args, "y*:process", &input);
@@ -947,7 +949,7 @@ static PyObject* brotli_decompress(PyObject *self, PyObject *args, PyObject *key
947949
int ok;
948950

949951
#if PY_MAJOR_VERSION >= 3
950-
#ifdef Py_LIMITED_API
952+
#ifdef Py_LIMITED_API && PY_VERSION_HEX < 0x030B0000
951953
ok = PyArg_ParseTupleAndKeywords(args, keywds, "y#|:decompress",
952954
(char**) kwlist, &input.buf, &input.len);
953955
#else

0 commit comments

Comments
 (0)