]> git.sesse.net Git - xml-template/commitdiff
Do weird dances to get php5-swig garbage collection going. Something tells me this...
authorsgunderson@bigfoot.com <>
Fri, 23 Sep 2011 00:10:07 +0000 (02:10 +0200)
committersgunderson@bigfoot.com <>
Fri, 23 Sep 2011 00:10:07 +0000 (02:10 +0200)
12 files changed:
php5-swig/attribute-empty.php
php5-swig/attribute.php
php5-swig/attribute2.php
php5-swig/attribute3.php
php5-swig/clone.php
php5-swig/include.php
php5-swig/namespace.php
php5-swig/namespace2.php
php5-swig/passthru.php
php5-swig/simple.php
php5-swig/structure.php
php5-swig/xml-template.swig

index 3886e7d5316cfdcdc4421574f333b9a8fed62685..98555a24909ac8ee7c8c1e1070581f03a49ae9c4 100644 (file)
@@ -9,5 +9,5 @@ $doc = XML_Template_process_file('../xml/clone.xml', array(
        'color' => 'blue',
        '#things' => array(NULL)
 ), true);
-output_to_fd_and_free($doc, 1);
+output_to_fd($doc, 1);
 ?>
index d63cf69c23ab1ac0c5ec4fe059cf272314f0e774..003cf2b68b5c7e19792eb749e55449b21ab0d30a 100644 (file)
@@ -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_and_free($doc, 1);
+output_to_fd($doc, 1);
 ?>
index 4b33237e2a9bd96740c79def77ec5f11b5837961..020288525849776491dd9a5be688936b2ba75445 100644 (file)
@@ -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_and_free($doc, 1);
+output_to_fd($doc, 1);
 ?>
index f3afc60f13cf6471da9d9bc97230aee4c3a10e91..215621536aab1f335cb388a5033e87b3b10a1abf 100644 (file)
@@ -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_and_free($doc, 1);
+output_to_fd($doc, 1);
 ?>
index a0f98a7de1dce8f8832445fdf80b93e5f36af5d6..1193ea08e482c88b58ab060caaf80cbe670252c1 100644 (file)
@@ -10,7 +10,7 @@ $doc = XML_Template_process_file('../xml/clone.xml', array(
                array( 'li' => 'Warm, woolen mittens' ) 
        )
 ), true);
-output_to_fd_and_free($doc, 1);
+output_to_fd($doc, 1);
 
 ?>
 
index b24e59f866543911da1e853abf88aeec8984275c..92b71d6dca4c07e897251b7f7b49df290bfdf24b 100644 (file)
@@ -9,5 +9,5 @@ $master = XML_Template_process_file('../xml/master.xml', array(
        'h1' => 'Nice heading here',
        'contents' => $doc
 ), true);
-output_to_fd_and_free($master, 1);
+output_to_fd($master, 1);
 ?>
index f17fb7460926488b5a71c4201945e9b0bd92608a..9a653dc3b4adb85a4d188d3ff5799173197267c9 100644 (file)
@@ -8,5 +8,5 @@ $doc = XML_Template_process_file('../xml/namespace.xml', array(
        'tagname' => 'foo',
        '#moretest' => 'bar'
 ), true);
-output_to_fd_and_free($doc, 1);
+output_to_fd($doc, 1);
 ?>
index 06c7bd628137b61507634729710df6c17d33d971..04622cf99ee036a339c6e349579c748fdf6e1d20 100644 (file)
@@ -5,5 +5,5 @@ $doc = XML_Template_process_file('../xml/namespace2.xml', array(
        'title' => 'Namespace tests',
        '#hello' => 'Replaced.',
 ), true);
-output_to_fd_and_free($doc, 1);
+output_to_fd($doc, 1);
 ?>
index 3b3822b196b88649348618120c362b5f79740475..2496b18c8759ec5e682dd75775c11a498fc93d1d 100644 (file)
@@ -2,7 +2,7 @@
 
 dl("XML_Template_SWIG.so");
 $doc = XML_Template_process_file('../xml/passthru.xml', array(), true);
-output_to_fd_and_free($doc, 1);
+output_to_fd($doc, 1);
 
 ?>
 
index 2f29d51d52863ead46eb99c73461dc7f973c32dd..a5b7f04ff1a7ea5092166cb77da785dbcae1e294 100644 (file)
@@ -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_and_free($doc, 1);
+output_to_fd($doc, 1);
 
 ?>
 
index 2bc8c442dfb9441edb57c0922dbd00c7d1d62e8a..b27a040d7697a4001df18fabcd7db32f89b3d186 100644 (file)
@@ -8,5 +8,5 @@ $doc = XML_Template_process_file('../xml/structure.xml', array(
                array( '#inner' => 'Three' ),
        )
 ), true);
-output_to_fd_and_free($doc, 1);
+output_to_fd($doc, 1);
 ?>
index a2dd2d1926c6925149c9d41e05c327bab3a8684e..225f8bbd2e2d9a4c17df0d3937bef0721a15beff 100644 (file)
@@ -1,9 +1,21 @@
 %module XML_Template_SWIG
 
+struct XmlDocPtrWrapper {
+       ~XmlDocPtrWrapper();
+};
+
 %{
 
+#include <memory>
+
 #include "../c++11/xml-template.h"
-               
+
+struct XmlDocWrapper {
+       ~XmlDocWrapper() { xmlFreeDoc(ptr); }
+       xmlDocPtr ptr;
+};
+typedef std::shared_ptr<XmlDocWrapper> XmlDocPtrWrapper;
+
 bool is_associative_array(HashTable *ht)
 {
        if (ht->nNumOfElements == 0) {
@@ -59,11 +71,11 @@ Directive* convert_php_objects_to_directive(zval *obj)
                return new Replace(str);
        }
        case IS_RESOURCE: {
-               xmlDocPtr *doc;
-               if (SWIG_ConvertPtr(obj, (void **)&doc, SWIGTYPE_p_xmlDocPtr, 0) < 0 || doc == NULL) {
+               XmlDocPtrWrapper *doc;
+               if (SWIG_ConvertPtr(obj, (void **)&doc, SWIGTYPE_p_XmlDocPtrWrapper, 0) < 0 || doc == NULL) {
                        return NULL;
                }
-               return new ReplaceInclude(xmlCopyDoc(*doc, 1));
+               return new ReplaceInclude(xmlCopyDoc(doc->get()->ptr, 1));
        }
        case IS_NULL:
                return NULL;
@@ -75,11 +87,17 @@ Directive* convert_php_objects_to_directive(zval *obj)
        return NULL;
 }
 
-xmlDocPtr XML_Template_process_file(const char *input_filename, Directive *root_directive, bool clean)
+XmlDocPtrWrapper XML_Template_process_file(const char *input_filename, Directive *root_directive, bool clean)
 {
        xmlDocPtr ret = process_file(input_filename, root_directive, clean);
        delete root_directive;
-       return ret;
+       return XmlDocPtrWrapper(new XmlDocWrapper { ret });
+}
+       
+void output_to_fd(XmlDocPtrWrapper doc, int fd)
+{
+       xmlOutputBufferPtr buf = xmlOutputBufferCreateFd(fd, NULL);
+       xmlSaveFileTo(buf, doc->ptr, NULL);
 }
 
 %}
@@ -88,6 +106,6 @@ xmlDocPtr XML_Template_process_file(const char *input_filename, Directive *root_
        $1 = convert_php_objects_to_directive(*$input);
 }
 
-xmlDocPtr XML_Template_process_file(const char *input_filename, Directive *root_directive, bool clean);
-void output_to_fd_and_free(xmlDocPtr 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);