102.11.0-1
[arch-packages.git] / libxml2 / trunk / 0001-Fix-python3-unicode-errors.patch
blob92a0c115625740f98f367db5a193aeedeed50fdd
1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: "Jan Alexander Steffens (heftig)" <heftig@archlinux.org>
3 Date: Tue, 11 Apr 2023 21:55:36 +0000
4 Subject: [PATCH] Fix python3 unicode errors
6 Patch taken from Fedora at
7 https://src.fedoraproject.org/rpms/libxml2/raw/c1fa5c85e9d3a0b7340aaf34d2e5134cf47f5d66/f/libxml2-2.9.8-python3-unicode-errors.patch
9 Works around https://bugzilla.gnome.org/show_bug.cgi?id=789714
10 and https://gitlab.gnome.org/GNOME/libxml2/-/issues/64
11 ---
12 python/libxml.c | 11 ++++++++++-
13 1 file changed, 10 insertions(+), 1 deletion(-)
15 diff --git a/python/libxml.c b/python/libxml.c
16 index e071e824ca39..9d476f4fcd92 100644
17 --- a/python/libxml.c
18 +++ b/python/libxml.c
19 @@ -1621,28 +1621,37 @@ libxml_xmlErrorFuncHandler(ATTRIBUTE_UNUSED void *ctx, const char *msg,
20 PyObject *message;
21 PyObject *result;
22 char str[1000];
23 + unsigned char *ptr = (unsigned char *)str;
25 #ifdef DEBUG_ERROR
26 printf("libxml_xmlErrorFuncHandler(%p, %s, ...) called\n", ctx, msg);
27 #endif
30 if (libxml_xmlPythonErrorFuncHandler == NULL) {
31 va_start(ap, msg);
32 vfprintf(stderr, msg, ap);
33 va_end(ap);
34 } else {
35 va_start(ap, msg);
36 if (vsnprintf(str, 999, msg, ap) >= 998)
37 str[999] = 0;
38 va_end(ap);
40 +#if PY_MAJOR_VERSION >= 3
41 + /* Ensure the error string doesn't start at UTF8 continuation. */
42 + while (*ptr && (*ptr & 0xc0) == 0x80)
43 + ptr++;
44 +#endif
46 list = PyTuple_New(2);
47 PyTuple_SetItem(list, 0, libxml_xmlPythonErrorFuncCtxt);
48 Py_XINCREF(libxml_xmlPythonErrorFuncCtxt);
49 - message = libxml_charPtrConstWrap(str);
50 + message = libxml_charPtrConstWrap(ptr);
51 PyTuple_SetItem(list, 1, message);
52 result = PyEval_CallObject(libxml_xmlPythonErrorFuncHandler, list);
53 + /* Forget any errors caused in the error handler. */
54 + PyErr_Clear();
55 Py_XDECREF(list);
56 Py_XDECREF(result);