~dragora/dragora/trunk

« back to all changes in this revision

Viewing changes to patches/libxml2/libxml2-2.9.8-python3_hack-1.patch

  • Committer: Matias Fonzo
  • Date: 2018-06-21 15:23:07 UTC
  • Revision ID: git-v1:0e01374f71be1cb232db976c824dcd4ff39bb564
recipes: update libxml2 adding support for python 2 and 3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
Submitted By: Pierre Labastie <pierre dot labastie at neuf dot fr>
 
2
Date: 2017-11-23
 
3
Initial Package Version: 2.9.7
 
4
Upstream Status: Bug reported (https://bugzilla.gnome.org/show_bug.cgi?id=789714)
 
5
Origin: Jan Majetek/OpenSuse (https://bugzilla.opensuse.org/show_bug.cgi?id=1065270)
 
6
Description: Fix a segfault in the Python 3 module. It is only a hack.
 
7
 
 
8
Index: libxml2-2.9.5/python/libxml.c
 
9
===================================================================
 
10
--- libxml2-2.9.5.orig/python/libxml.c
 
11
+++ libxml2-2.9.5/python/libxml.c
 
12
@@ -1620,6 +1620,7 @@ libxml_xmlErrorFuncHandler(ATTRIBUTE_UNU
 
13
     PyObject *message;
 
14
     PyObject *result;
 
15
     char str[1000];
 
16
+    unsigned char *ptr = (unsigned char *)str;
 
17
 
 
18
 #ifdef DEBUG_ERROR
 
19
     printf("libxml_xmlErrorFuncHandler(%p, %s, ...) called\n", ctx, msg);
 
20
@@ -1636,12 +1637,20 @@ libxml_xmlErrorFuncHandler(ATTRIBUTE_UNU
 
21
            str[999] = 0;
 
22
         va_end(ap);
 
23
 
 
24
+#if PY_MAJOR_VERSION >= 3
 
25
+        /* Ensure the error string doesn't start at UTF8 continuation. */
 
26
+        while (*ptr && (*ptr & 0xc0) == 0x80)
 
27
+            ptr++;
 
28
+#endif
 
29
+
 
30
         list = PyTuple_New(2);
 
31
         PyTuple_SetItem(list, 0, libxml_xmlPythonErrorFuncCtxt);
 
32
         Py_XINCREF(libxml_xmlPythonErrorFuncCtxt);
 
33
-        message = libxml_charPtrConstWrap(str);
 
34
+        message = libxml_charPtrConstWrap(ptr);
 
35
         PyTuple_SetItem(list, 1, message);
 
36
         result = PyEval_CallObject(libxml_xmlPythonErrorFuncHandler, list);
 
37
+        /* Forget any errors caused in the error handler. */
 
38
+        PyErr_Clear();
 
39
         Py_XDECREF(list);
 
40
         Py_XDECREF(result);
 
41
     }