xzyang / rpms / libxml2

Forked from rpms/libxml2 3 years ago
Clone

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

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