| 1 |
Fromscip-debian debian crossfire 1.75.0-9.1 crossfire/patches/`0005-Fix-build-with-Python-3.12.patch`#From.: Boyuan Yang <[email protected]scip-debian . . . identity/`[email protected]`.> |
| 2 |
Datescip-debian debian crossfire 1.75.0-9.1 crossfire/patches/`0005-Fix-build-with-Python-3.12.patch`#Date.: Tue, 2 Jul 2024 15:38:46 -0400 |
| 3 |
Subjectscip-debian debian crossfire 1.75.0-9.1 crossfire/patches/`0005-Fix-build-with-Python-3.12.patch`#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.cscip-debian debian crossfire 1.75.0-9.1 crossfire/upstream/`plugins/cfpython/cjson.c`: b/plugins/cfpython/cjson.cscip-debian debian crossfire 1.75.0-9.1 crossfire/upstream/`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 |
|
| 19 |
|
| 20 |
+ Py_ssize_t size, pos; |
| 21 |
char *p; |
| 22 |
static const char *hexdigit = "0123456789abcdef"; |
| 23 |
|
| 24 |
static const Py_ssize_t expandsize = 10; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 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 |
|
| 44 |
|
| 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 |
|
| 53 |
+ if ((ch == quote || ch == '\\')) { |
| 54 |
*p++ = '\\'; |
| 55 |
*p++ = (char)ch; |
| 56 |
continue; |
| 57 |
} |
| 58 |
|
| 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 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
/* Map 16-bit characters to '\uxxxx' */ |
| 95 |
if (ch >= 256) { |
| 96 |
*p++ = '\\'; |