summaryrefslogtreecommitdiff
path: root/dev-python/regex/files/regex-2021.4.4-pypy3-fix-test_empty_array.patch
blob: 706b41b746886f02e828ec538bef9b003474d409 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
From: Arthur Zamarin <arthurzam@gmail.com>
Date: Fri, 30 Jul 2021 11:13:41 +0300
[PATCH] PyPy3: fix test_empty_array

As an optimization, PyPy sets empty array.array to use a NULL buffer
pointer, while CPython uses empty buffer (but not NULL).
Add a very specially crafted fix for PyPy3

Signed-off-by: Arthur Zamarin <arthurzam@gmail.com>
---
 regex_3/_regex.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

--- a/regex_3/_regex.c
+++ b/regex_3/_regex.c
@@ -18062,9 +18062,19 @@ Py_LOCAL_INLINE(BOOL) get_string(PyObject* string, RE_StringInfo* str_info) {
     }
 
     if (!str_info->view.buf) {
+#if defined(PYPY_VERSION)
+        /* In PyPy3, when the array.array is empty, it's buffer is NULL */
+        str_info->characters = NULL;
+        str_info->length = 0;
+        str_info->charsize = 1;
+        str_info->is_unicode = FALSE;
+        str_info->should_release = FALSE;
+        return TRUE;
+#else
         PyBuffer_Release(&str_info->view);
         PyErr_SetString(PyExc_ValueError, "buffer is NULL");
         return FALSE;
+#endif
     }
 
     str_info->should_release = TRUE;