1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
$NetBSD: patch-bindings-python-wrapper_top.c,v 1.1 2012/10/23 18:16:15 manu Exp $
Patch from upstream to support libxml >= 2.9.0. From commit message:
Libxml stopped exposing the internal of the xmlOutputBuffer structure;
it was replace by proper use of the API and of the xmlBuffer structure.
There could be regression for older version of libxml as some functions
appeared in recent version of libxml; but the reference API document
does not give any introduction date for functions so it's hard to be
sure.
diff --git a/bindings/python/wrapper_top.c b/bindings/python/wrapper_top.c
index 7879bb1..2c68437 100644
--- bindings/python/wrapper_top.c
+++ bindings/python/wrapper_top.c
@@ -103,28 +103,40 @@ get_dict_from_hashtable_of_strings(GHashTable *value)
return proxy;
}
+static xmlBuffer*
+xmlnode_to_xmlbuffer(xmlNode *node)
+{
+ xmlOutputBufferPtr output_buffer;
+ xmlBuffer *buffer;
+
+ if (! node)
+ return NULL;
+
+ buffer = xmlBufferCreate();
+ output_buffer = xmlOutputBufferCreateBuffer(buffer, NULL);
+ xmlNodeDumpOutput(output_buffer, NULL, node, 0, 0, NULL);
+ xmlOutputBufferClose(output_buffer);
+ xmlBufferAdd(buffer, BAD_CAST "", 1);
+
+ return buffer;
+}
+
static PyObject*
get_pystring_from_xml_node(xmlNode *xmlnode)
{
- xmlOutputBufferPtr buf;
PyObject *pystring = NULL;
+ xmlBuffer *buffer;
if (xmlnode == NULL) {
return NULL;
}
+ buffer = xmlnode_to_xmlbuffer(xmlnode);
- buf = xmlAllocOutputBuffer(NULL);
- if (buf == NULL) {
+ if (buffer == NULL) {
pystring = NULL;
} else {
- xmlNodeDumpOutput(buf, NULL, xmlnode, 0, 1, NULL);
- xmlOutputBufferFlush(buf);
- if (buf->conv == NULL) {
- pystring = PyString_FromString((char*)buf->buffer->content);
- } else {
- pystring = PyString_FromString((char*)buf->conv->content);
- }
- xmlOutputBufferClose(buf);
+ pystring = PyString_FromString((char*)xmlBufferContent(buffer));
+ xmlBufferFree(buffer);
}
return pystring;
|