Debian Codegraph @

debian/patches/0005-Fix-build-with-Python-3.12.patch

raw symbols SCIP
1 From: Boyuan Yang <[email protected]>
2 Date: Tue, 2 Jul 2024 15:38:46 -0400
3 Subject: Fix build with Python 3.12
4
5 Applied-Upstream: https://sourceforge.net/p/crossfire/crossfire-server/ci/472dd26ac74419baa0e6373cb04e095437e994c6/
6 ---
7 plugins/cfpython/cjson.c | 51 ++++++++++++------------------------------------
8 1 file changed, 12 insertions(+), 39 deletions(-)
9
10 diff --git a/plugins/cfpython/cjson.c b/plugins/cfpython/cjson.c
11 index 1483d8f..da1547d 100644
12 --- a/plugins/cfpython/cjson.c
13 +++ b/plugins/cfpython/cjson.c
14 @@ -687,18 +687,14 @@ static PyObject *encode_string(PyObject *string) {
15 #if defined(IS_PY26) || defined(IS_PY3K)
16 static PyObject *encode_unicode(PyObject *unicode) {
17 PyObject *repr;
18 - Py_UNICODE *s;
19 - Py_ssize_t size;
20 + Py_ssize_t size, pos;
21 char *p;
22 static const char *hexdigit = "0123456789abcdef";
23 -#ifdef Py_UNICODE_WIDE
24 static const Py_ssize_t expandsize = 10;
25 -#else
26 - static const Py_ssize_t expandsize = 6;
27 -#endif
28
29 - s = PyUnicode_AS_UNICODE(unicode);
30 - size = PyUnicode_GET_SIZE(unicode);
31 + int kind = PyUnicode_KIND(unicode);
32 + void *data = PyUnicode_DATA(unicode);
33 + size = PyUnicode_GET_LENGTH(unicode);
34
35 if (size > (PY_SSIZE_T_MAX-2-1)/expandsize) {
36 PyErr_SetString(PyExc_OverflowError, "unicode object is too large to make repr");
37 @@ -715,17 +711,21 @@ static PyObject *encode_unicode(PyObject *unicode) {
38 p = PyByteArray_AS_STRING(repr);
39
40 *p++ = '"';
41 + pos = 0;
42
43 - while (size-- > 0) {
44 - Py_UNICODE ch = *s++;
45 + const Py_UCS4 quote = PyByteArray_AS_STRING(repr)[0];
46 +
47 + while (pos < size) {
48 + Py_UCS4 ch = PyUnicode_READ(kind, data, pos);
49 + pos++;
50
51 /* Escape quotes */
52 - if ((ch == (Py_UNICODE)PyByteArray_AS_STRING(repr)[0] || ch == '\\')) {
53 + if ((ch == quote || ch == '\\')) {
54 *p++ = '\\';
55 *p++ = (char)ch;
56 continue;
57 }
58 -#ifdef Py_UNICODE_WIDE
59 +
60 /* Map 21-bit characters to '\U00xxxxxx' */
61 else if (ch >= 0x10000) {
62 *p++ = '\\';
63 @@ -740,33 +740,6 @@ static PyObject *encode_unicode(PyObject *unicode) {
64 *p++ = hexdigit[ch&0x0000000F];
65 continue;
66 }
67 -#else
68 - /* Map UTF-16 surrogate pairs to Unicode \UXXXXXXXX escapes */
69 - else if (ch >= 0xD800 && ch < 0xDC00) {
70 - Py_UNICODE ch2;
71 - Py_UCS4 ucs;
72 -
73 - ch2 = *s++;
74 - size--;
75 - if (ch2 >= 0xDC00 && ch2 <= 0xDFFF) {
76 - ucs = (((ch&0x03FF)<<10)|(ch2&0x03FF))+0x00010000;
77 - *p++ = '\\';
78 - *p++ = 'U';
79 - *p++ = hexdigit[(ucs>>28)&0x0000000F];
80 - *p++ = hexdigit[(ucs>>24)&0x0000000F];
81 - *p++ = hexdigit[(ucs>>20)&0x0000000F];
82 - *p++ = hexdigit[(ucs>>16)&0x0000000F];
83 - *p++ = hexdigit[(ucs>>12)&0x0000000F];
84 - *p++ = hexdigit[(ucs>>8)&0x0000000F];
85 - *p++ = hexdigit[(ucs>>4)&0x0000000F];
86 - *p++ = hexdigit[ucs&0x0000000F];
87 - continue;
88 - }
89 - /* Fall through: isolated surrogates are copied as-is */
90 - s--;
91 - size++;
92 - }
93 -#endif
94 /* Map 16-bit characters to '\uxxxx' */
95 if (ch >= 256) {
96 *p++ = '\\';