Skip to content

Commit 0145fd4

Browse files
committed
Take care of differences between PyPy and CPython
1 parent fd7c8ca commit 0145fd4

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/isal/isal_zlibmodule.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,17 @@ Changes compared to CPython:
4747

4848
#define DEF_MEM_LEVEL 8
4949

50-
/* Py_UNREACHABLE not defined on PyPy platforms apparently. */
51-
#ifndef Py_UNREACHABLE
50+
/* PyPy quirks: no Py_UNREACHABLE and requires PyBUF_READ and PyBUF_WRITE set
51+
in memoryviews that enter a "readinto" call. CPython requires that only
52+
PyBUF_WRITE is set.
53+
(Both implementations are wrong because the state of the READ bit should
54+
not matter.)
55+
*/
56+
#ifdef PYPY_VERSION
5257
#define Py_UNREACHABLE() Py_FatalError("Reached unreachable state")
58+
#define MEMORYVIEW_READINTO_FLAGS (PyBUF_READ | PyBUF_WRITE)
59+
#else
60+
#define MEMORYVIEW_READINTO_FLAGS PyBUF_WRITE
5361
#endif
5462

5563
static PyTypeObject IsalZlibCompType;
@@ -1348,7 +1356,7 @@ static inline ssize_t GzipReader_read_from_file(GzipReader *self)
13481356
return -1;
13491357
}
13501358
PyObject *bufview = PyMemoryView_FromMemory(
1351-
(char *)buffer_end, read_in_size, PyBUF_READ | PyBUF_WRITE);
1359+
(char *)buffer_end, read_in_size, MEMORYVIEW_READINTO_FLAGS);
13521360
if (bufview == NULL) {
13531361
return -1;
13541362
}

0 commit comments

Comments
 (0)