From f5af96eb727899f04c322640ee36028441c29ec9 Mon Sep 17 00:00:00 2001 From: "sgunderson@bigfoot.com" <> Date: Fri, 23 Sep 2011 23:39:30 +0200 Subject: [PATCH] In php5-swig, replace the output_by_fd() hack with a function that allows conversion to string. --- php5-swig/attribute-empty.php | 2 +- php5-swig/attribute.php | 2 +- php5-swig/attribute2.php | 2 +- php5-swig/attribute3.php | 2 +- php5-swig/clone.php | 2 +- php5-swig/include.php | 2 +- php5-swig/namespace.php | 2 +- php5-swig/namespace2.php | 2 +- php5-swig/passthru.php | 2 +- php5-swig/simple.php | 2 +- php5-swig/structure.php | 2 +- php5-swig/xml-template.swig | 29 ++++++++++++++++++++++++----- 12 files changed, 35 insertions(+), 16 deletions(-) diff --git a/php5-swig/attribute-empty.php b/php5-swig/attribute-empty.php index ba4941e..ce4e532 100644 --- a/php5-swig/attribute-empty.php +++ b/php5-swig/attribute-empty.php @@ -8,5 +8,5 @@ $doc = XML_Template_process_file('../xml/clone.xml', array( 'color' => 'blue', '#things' => array(NULL) ), true); -output_to_fd($doc, 1); +print XML_Template_convert_doc_to_string($doc); ?> diff --git a/php5-swig/attribute.php b/php5-swig/attribute.php index cc06561..8087dc7 100644 --- a/php5-swig/attribute.php +++ b/php5-swig/attribute.php @@ -10,5 +10,5 @@ $doc = XML_Template_process_file('../xml/clone.xml', array( array( 'li' => 'Warm, woolen mittens', 'li/class' => 'even' ) ) ), true); -output_to_fd($doc, 1); +print XML_Template_convert_doc_to_string($doc); ?> diff --git a/php5-swig/attribute2.php b/php5-swig/attribute2.php index 95a6970..8d6c99b 100644 --- a/php5-swig/attribute2.php +++ b/php5-swig/attribute2.php @@ -10,5 +10,5 @@ $doc = XML_Template_process_file('../xml/clone.xml', array( array( 'li' => 'Warm, woolen mittens' ), ), array('odd', 'even')) ), true); -output_to_fd($doc, 1); +print XML_Template_convert_doc_to_string($doc); ?> diff --git a/php5-swig/attribute3.php b/php5-swig/attribute3.php index 74920fd..1262a90 100644 --- a/php5-swig/attribute3.php +++ b/php5-swig/attribute3.php @@ -11,5 +11,5 @@ $doc = XML_Template_process_file('../xml/clone.xml', array( array( 'li' => 'Warm, woolen mittens' ), ), array('odd', 'even')) ), true); -output_to_fd($doc, 1); +print XML_Template_convert_doc_to_string($doc); ?> diff --git a/php5-swig/clone.php b/php5-swig/clone.php index ab0ed7a..20444db 100644 --- a/php5-swig/clone.php +++ b/php5-swig/clone.php @@ -10,7 +10,7 @@ $doc = XML_Template_process_file('../xml/clone.xml', array( array( 'li' => 'Warm, woolen mittens' ) ) ), true); -output_to_fd($doc, 1); +print XML_Template_convert_doc_to_string($doc); ?> diff --git a/php5-swig/include.php b/php5-swig/include.php index cc98dde..69ee513 100644 --- a/php5-swig/include.php +++ b/php5-swig/include.php @@ -9,5 +9,5 @@ $master = XML_Template_process_file('../xml/master.xml', array( 'h1' => 'Nice heading here', 'contents' => $doc ), true); -output_to_fd($master, 1); +print XML_Template_convert_doc_to_string($master); ?> diff --git a/php5-swig/namespace.php b/php5-swig/namespace.php index b5c8547..04d2fac 100644 --- a/php5-swig/namespace.php +++ b/php5-swig/namespace.php @@ -8,5 +8,5 @@ $doc = XML_Template_process_file('../xml/namespace.xml', array( 'tagname' => 'foo', '#moretest' => 'bar' ), true); -output_to_fd($doc, 1); +print XML_Template_convert_doc_to_string($doc); ?> diff --git a/php5-swig/namespace2.php b/php5-swig/namespace2.php index 3111890..998cf66 100644 --- a/php5-swig/namespace2.php +++ b/php5-swig/namespace2.php @@ -5,5 +5,5 @@ $doc = XML_Template_process_file('../xml/namespace2.xml', array( 'title' => 'Namespace tests', '#hello' => 'Replaced.', ), true); -output_to_fd($doc, 1); +print XML_Template_convert_doc_to_string($doc); ?> diff --git a/php5-swig/passthru.php b/php5-swig/passthru.php index c51e1e1..91f1f56 100644 --- a/php5-swig/passthru.php +++ b/php5-swig/passthru.php @@ -2,7 +2,7 @@ include("xml-template.php"); $doc = XML_Template_process_file('../xml/passthru.xml', array(), true); -output_to_fd($doc, 1); +print XML_Template_convert_doc_to_string($doc); ?> diff --git a/php5-swig/simple.php b/php5-swig/simple.php index 33a512d..7e6ce84 100644 --- a/php5-swig/simple.php +++ b/php5-swig/simple.php @@ -5,7 +5,7 @@ $doc = XML_Template_process_file('../xml/simple.xml', array( 'title' => 'A very basic example', '#hello' => 'Hello world!' ), true); -output_to_fd($doc, 1); +print XML_Template_convert_doc_to_string($doc); ?> diff --git a/php5-swig/structure.php b/php5-swig/structure.php index 32399dd..de2e3ab 100644 --- a/php5-swig/structure.php +++ b/php5-swig/structure.php @@ -8,5 +8,5 @@ $doc = XML_Template_process_file('../xml/structure.xml', array( array( '#inner' => 'Three' ), ) ), true); -output_to_fd($doc, 1); +print XML_Template_convert_doc_to_string($doc); ?> diff --git a/php5-swig/xml-template.swig b/php5-swig/xml-template.swig index 225f8bb..02314f0 100644 --- a/php5-swig/xml-template.swig +++ b/php5-swig/xml-template.swig @@ -1,4 +1,5 @@ %module XML_Template_SWIG +%include struct XmlDocPtrWrapper { ~XmlDocPtrWrapper(); @@ -93,13 +94,31 @@ XmlDocPtrWrapper XML_Template_process_file(const char *input_filename, Directive delete root_directive; return XmlDocPtrWrapper(new XmlDocWrapper { ret }); } - -void output_to_fd(XmlDocPtrWrapper doc, int fd) + +namespace { + +int write_to_string(void *context, const char *buffer, int len) { - xmlOutputBufferPtr buf = xmlOutputBufferCreateFd(fd, NULL); - xmlSaveFileTo(buf, doc->ptr, NULL); + std::string *str = reinterpret_cast(context); + str->append(buffer, len); + return len; +} + +int close_string(void *context) +{ + return 0; } +} // namespace + +std::string XML_Template_convert_doc_to_string(XmlDocPtrWrapper doc) +{ + std::string ret; + xmlOutputBufferPtr buf = xmlOutputBufferCreateIO(write_to_string, close_string, &ret, NULL); + xmlSaveFileTo(buf, doc->ptr, NULL); + return ret; +} + %} %typemap(in) Directive* { @@ -107,5 +126,5 @@ void output_to_fd(XmlDocPtrWrapper doc, int fd) } XmlDocPtrWrapper XML_Template_process_file(const char *input_filename, Directive *root_directive, bool clean); -void output_to_fd(XmlDocPtrWrapper doc, int fd); +std::string XML_Template_convert_doc_to_string(XmlDocPtrWrapper doc); -- 2.39.2