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
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
19 @@ -1621,28 +1621,37 @@ libxml_xmlErrorFuncHandler(ATTRIBUTE_UNUSED void *ctx, const char *msg,
23 + unsigned char *ptr = (unsigned char *)str;
26 printf("libxml_xmlErrorFuncHandler(%p, %s, ...) called\n", ctx, msg);
30 if (libxml_xmlPythonErrorFuncHandler == NULL) {
32 vfprintf(stderr, msg, ap);
36 if (vsnprintf(str, 999, msg, ap) >= 998)
40 +#if PY_MAJOR_VERSION >= 3
41 + /* Ensure the error string doesn't start at UTF8 continuation. */
42 + while (*ptr && (*ptr & 0xc0) == 0x80)
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. */