File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -135,6 +135,14 @@ PyObject *StrType::proxifyString(JSContext *cx, JS::HandleValue strVal) {
135
135
136
136
if (JS::LinearStringHasLatin1Chars (lstr)) { // latin1 spidermonkey, latin1 python
137
137
const JS::Latin1Char *chars = JS::GetLatin1LinearStringChars (nogc, lstr);
138
+ if ((PY_VERSION_HEX) >= 0x030d0000 ) { // Python version is greater than 3.13
139
+ // Short path to temporarily fix the issue with Python 3.13+ compact unicode representation.
140
+ // It would error with `ValueError: embedded null character`, which is caused by the fact that
141
+ // most Python C APIs assume the string buffer is null-terminated, so we need to create a copy.
142
+ PyObject *copied = PyUnicode_FromKindAndData (PyUnicode_1BYTE_KIND, chars, length);
143
+ Py_DECREF (pyString);
144
+ return copied;
145
+ }
138
146
139
147
PY_UNICODE_OBJECT_DATA_ANY (pyString) = (void *)chars;
140
148
PY_UNICODE_OBJECT_KIND (pyString) = PyUnicode_1BYTE_KIND;
@@ -189,6 +197,11 @@ PyObject *StrType::proxifyString(JSContext *cx, JS::HandleValue strVal) {
189
197
Py_DECREF (pyString);
190
198
return ucs4Obj;
191
199
}
200
+ if ((PY_VERSION_HEX) >= 0x030d0000 ) { // Python 3.13+, fix `ValueError: embedded null character`
201
+ PyObject *copied = PyUnicode_FromKindAndData (PyUnicode_2BYTE_KIND, chars, length); // create a copy of the string buffer
202
+ Py_DECREF (pyString);
203
+ return copied;
204
+ }
192
205
}
193
206
194
207
return (PyObject *)pyString;
You can’t perform that action at this time.
0 commit comments