summaryrefslogtreecommitdiff
path: root/python/libxml.c
diff options
context:
space:
mode:
authorDaniel Veillard <veillard@src.gnome.org>2004-10-04 10:26:54 +0000
committerDaniel Veillard <veillard@src.gnome.org>2004-10-04 10:26:54 +0000
commit263ec86a75f7b5ec2d37dbb89356bf7fca11cff3 (patch)
tree1fd27981e59572018609d3b24fd23c81e924d142 /python/libxml.c
parent2c22844057be33925a44f0962f712e45b932ebb6 (diff)
downloadlibxml2-263ec86a75f7b5ec2d37dbb89356bf7fca11cff3.tar.gz
applied patch from Malcolm Tredinnick fixing bug #154294 related to saving
* python/generator.py python/libxml.c python/tests/outbuf.py: applied patch from Malcolm Tredinnick fixing bug #154294 related to saving to python file objects. Daniel
Diffstat (limited to 'python/libxml.c')
-rw-r--r--python/libxml.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/python/libxml.c b/python/libxml.c
index 9e243146..99d9ac3e 100644
--- a/python/libxml.c
+++ b/python/libxml.c
@@ -512,6 +512,11 @@ libxml_xmlOutputBufferClose(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
if (!PyArg_ParseTuple(args, (char *)"O:xmlOutputBufferClose", &pyobj_out))
return(NULL);
out = (xmlOutputBufferPtr) PyoutputBuffer_Get(pyobj_out);
+ /* Buffer may already have been destroyed elsewhere. This is harmless. */
+ if (out == NULL) {
+ Py_INCREF(Py_None);
+ return(Py_None);
+ }
c_retval = xmlOutputBufferClose(out);
py_retval = libxml_intWrap((int) c_retval);
@@ -533,6 +538,53 @@ libxml_xmlOutputBufferFlush(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
py_retval = libxml_intWrap((int) c_retval);
return(py_retval);
}
+
+static PyObject *
+libxml_xmlSaveFileTo(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
+ PyObject *py_retval;
+ int c_retval;
+ xmlOutputBufferPtr buf;
+ PyObject *pyobj_buf;
+ xmlDocPtr cur;
+ PyObject *pyobj_cur;
+ char * encoding;
+
+ if (!PyArg_ParseTuple(args, (char *)"OOz:xmlSaveFileTo", &pyobj_buf, &pyobj_cur, &encoding))
+ return(NULL);
+ buf = (xmlOutputBufferPtr) PyoutputBuffer_Get(pyobj_buf);
+ cur = (xmlDocPtr) PyxmlNode_Get(pyobj_cur);
+
+ c_retval = xmlSaveFileTo(buf, cur, encoding);
+ /* xmlSaveTo() freed the memory pointed to by buf, so record that in the
+ * Python object. */
+ ((PyoutputBuffer_Object *)(pyobj_buf))->obj = NULL;
+ py_retval = libxml_intWrap((int) c_retval);
+ return(py_retval);
+}
+
+static PyObject *
+libxml_xmlSaveFormatFileTo(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
+ PyObject *py_retval;
+ int c_retval;
+ xmlOutputBufferPtr buf;
+ PyObject *pyobj_buf;
+ xmlDocPtr cur;
+ PyObject *pyobj_cur;
+ char * encoding;
+ int format;
+
+ if (!PyArg_ParseTuple(args, (char *)"OOzi:xmlSaveFormatFileTo", &pyobj_buf, &pyobj_cur, &encoding, &format))
+ return(NULL);
+ buf = (xmlOutputBufferPtr) PyoutputBuffer_Get(pyobj_buf);
+ cur = (xmlDocPtr) PyxmlNode_Get(pyobj_cur);
+
+ c_retval = xmlSaveFormatFileTo(buf, cur, encoding, format);
+ /* xmlSaveFormatFileTo() freed the memory pointed to by buf, so record that
+ * in the Python object */
+ ((PyoutputBuffer_Object *)(pyobj_buf))->obj = NULL;
+ py_retval = libxml_intWrap((int) c_retval);
+ return(py_retval);
+}
#endif /* LIBXML_OUTPUT_ENABLED */
@@ -3446,6 +3498,8 @@ static PyMethodDef libxmlMethods[] = {
{(char *) "outputBufferGetPythonFile", libxml_outputBufferGetPythonFile, METH_VARARGS, NULL},
{(char *) "xmlOutputBufferClose", libxml_xmlOutputBufferClose, METH_VARARGS, NULL},
{ (char *)"xmlOutputBufferFlush", libxml_xmlOutputBufferFlush, METH_VARARGS, NULL },
+ { (char *)"xmlSaveFileTo", libxml_xmlSaveFileTo, METH_VARARGS, NULL },
+ { (char *)"xmlSaveFormatFileTo", libxml_xmlSaveFormatFileTo, METH_VARARGS, NULL },
#endif /* LIBXML_OUTPUT_ENABLED */
{(char *) "inputBufferCreate", libxml_xmlCreateInputBuffer, METH_VARARGS, NULL},
{(char *) "setEntityLoader", libxml_xmlSetEntityLoader, METH_VARARGS, NULL},