Blame SOURCES/libxml2-2.9.8-python3-unicode-errors.patch

8bf870
Index: libxml2-2.9.5/python/libxml.c
8bf870
===================================================================
8bf870
--- libxml2-2.9.5.orig/python/libxml.c
8bf870
+++ libxml2-2.9.5/python/libxml.c
8bf870
@@ -1620,6 +1620,7 @@ libxml_xmlErrorFuncHandler(ATTRIBUTE_UNU
8bf870
     PyObject *message;
8bf870
     PyObject *result;
8bf870
     char str[1000];
8bf870
+    unsigned char *ptr = (unsigned char *)str;
8bf870
 
8bf870
 #ifdef DEBUG_ERROR
8bf870
     printf("libxml_xmlErrorFuncHandler(%p, %s, ...) called\n", ctx, msg);
8bf870
@@ -1636,12 +1637,20 @@ libxml_xmlErrorFuncHandler(ATTRIBUTE_UNU
8bf870
 	    str[999] = 0;
8bf870
         va_end(ap);
8bf870
 
8bf870
+#if PY_MAJOR_VERSION >= 3
8bf870
+        /* Ensure the error string doesn't start at UTF8 continuation. */
8bf870
+        while (*ptr && (*ptr & 0xc0) == 0x80)
8bf870
+            ptr++;
8bf870
+#endif
8bf870
+
8bf870
         list = PyTuple_New(2);
8bf870
         PyTuple_SetItem(list, 0, libxml_xmlPythonErrorFuncCtxt);
8bf870
         Py_XINCREF(libxml_xmlPythonErrorFuncCtxt);
8bf870
-        message = libxml_charPtrConstWrap(str);
8bf870
+        message = libxml_charPtrConstWrap(ptr);
8bf870
         PyTuple_SetItem(list, 1, message);
8bf870
         result = PyEval_CallObject(libxml_xmlPythonErrorFuncHandler, list);
8bf870
+        /* Forget any errors caused in the error handler. */
8bf870
+        PyErr_Clear();
8bf870
         Py_XDECREF(list);
8bf870
         Py_XDECREF(result);
8bf870
     }