]> git.sesse.net Git - xml-template/commitdiff
Update the PHP SWIG version to PHP 7, with various crash fixes, too. master
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 17 Aug 2017 22:15:02 +0000 (00:15 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 17 Aug 2017 22:15:02 +0000 (00:15 +0200)
15 files changed:
php7-swig/Makefile [moved from php5-swig/Makefile with 53% similarity]
php7-swig/attribute-empty.php [moved from php5-swig/attribute-empty.php with 100% similarity]
php7-swig/attribute.php [moved from php5-swig/attribute.php with 100% similarity]
php7-swig/attribute2.php [moved from php5-swig/attribute2.php with 100% similarity]
php7-swig/attribute3.php [moved from php5-swig/attribute3.php with 88% similarity]
php7-swig/clone.php [moved from php5-swig/clone.php with 100% similarity]
php7-swig/include.php [moved from php5-swig/include.php with 100% similarity]
php7-swig/namespace.php [moved from php5-swig/namespace.php with 100% similarity]
php7-swig/namespace2.php [moved from php5-swig/namespace2.php with 100% similarity]
php7-swig/passthru.php [moved from php5-swig/passthru.php with 100% similarity]
php7-swig/simple.php [moved from php5-swig/simple.php with 100% similarity]
php7-swig/structure.php [moved from php5-swig/structure.php with 100% similarity]
php7-swig/xml-template.php [moved from php5-swig/xml-template.php with 100% similarity]
php7-swig/xml-template.swig [moved from php5-swig/xml-template.swig with 91% similarity]
tests/test.sh

similarity index 53%
rename from php5-swig/Makefile
rename to php7-swig/Makefile
index cc90f0adbb62dfdac5c3a2991793e2c56a85e280..5bf3c017595ef2388ceb62440e3a4137eb68f5ec 100644 (file)
@@ -6,10 +6,12 @@ LIBS=../c++11/xml-template.o
 XML_Template_SWIG.so: xml-template_wrap.o $(LIBS)
        $(CXX) $(LDFLAGS) -o $@ $< $(LIBS)
 
-xml-template_wrap.cpp XML_Template_SWIG.php php_XML_Template_SWIG.h : xml-template.swig
-       swig -c++ -php $<
+xml-template_wrap.cxx XML_Template_SWIG.php php_XML_Template_SWIG.h : xml-template.swig
+       swig -c++ -php7 $<
 
 clean:
        $(RM) XML_Template_SWIG.so xml-template_wrap.o
-       $(RM) xml-template_wrap.cpp XML_Template_SWIG.php php_XML_Template_SWIG.h 
+       $(RM) xml-template_wrap.cxx xml-template_wrap.cpp XML_Template_SWIG.php php_XML_Template_SWIG.h 
 
+xml-template_wrap.cpp: xml-template_wrap.cxx
+       cp xml-template_wrap.cxx xml-template_wrap.cpp
similarity index 88%
rename from php5-swig/attribute3.php
rename to php7-swig/attribute3.php
index 1262a906b897aa8f82b3b5830f25cb559ae546e6..b8ce7ea499fa8212b41d2c0038f9305e6070fad9 100644 (file)
@@ -11,5 +11,5 @@ $doc = XML_Template_process_file('../xml/clone.xml', array(
                array( 'li' => 'Warm, woolen mittens' ),
        ), array('odd', 'even'))
 ), true);
-print XML_Template_convert_doc_to_string($doc);
+print XML_Template_convert_doc_to_string($doc, 0);
 ?>
similarity index 100%
rename from php5-swig/clone.php
rename to php7-swig/clone.php
similarity index 100%
rename from php5-swig/include.php
rename to php7-swig/include.php
similarity index 100%
rename from php5-swig/simple.php
rename to php7-swig/simple.php
similarity index 91%
rename from php5-swig/xml-template.swig
rename to php7-swig/xml-template.swig
index 458296ef994e6d782a6f854854d57c921816298d..f31df588c266ddb02251203c167ead01618fe4c4 100644 (file)
@@ -38,38 +38,34 @@ Directive* convert_php_objects_to_directive(zval *obj)
                HashTable *ht = Z_ARRVAL_P(obj);
                if (is_associative_array(ht)) {
                        std::unordered_map<std::string, Directive *> my_map;
-                       for (zend_hash_internal_pointer_reset(ht); zend_hash_has_more_elements(ht) == SUCCESS; zend_hash_move_forward(ht)) {
-                               char *str_key;
-                               ulong num_key;
-                               zend_hash_get_current_key(ht, &str_key, &num_key, 0);
-
+                       zend_string *str_key;
+                       zval *zv;
+                       ulong num_key;
+                       ZEND_HASH_FOREACH_KEY_VAL(ht, num_key, str_key, zv) {
                                std::string key;
-                               if (zend_hash_get_current_key_type(ht) == HASH_KEY_IS_STRING) {
-                                       key = str_key;
+                               if (str_key) {
+                                       key.assign(str_key->val, str_key->len);
                                } else {
                                        char buf[32];
                                        sprintf(buf, "%lu", num_key);
                                        key = buf;
                                }
 
-                               zval **data;
-                               zend_hash_get_current_data(ht, (void **)&data);
-                               my_map.insert(make_pair(key, convert_php_objects_to_directive(*data)));
-                       }
+                               my_map.insert(make_pair(key, convert_php_objects_to_directive(zv)));
+                       } ZEND_HASH_FOREACH_END();
                        return new Substitute(my_map);
                } else {
                        std::vector<Directive *> subdirectives;
                        for (unsigned i = 0; i < ht->nNumOfElements; ++i) {
-                               zval **data;
-                               zend_hash_index_find(ht, i, (void **)&data);
-                               subdirectives.push_back(convert_php_objects_to_directive(*data));
+                               zval *data = zend_hash_index_find(ht, i);
+                               subdirectives.push_back(convert_php_objects_to_directive(data));
                        }
                        return new Clone(subdirectives);
                }
                break;
        }
        case IS_STRING: {
-               char *str = Z_STRVAL_P(obj);
+               std::string str(Z_STRVAL_P(obj), Z_STRLEN_P(obj));
                return new Replace(str);
        }
        case IS_LONG: {
@@ -89,6 +85,8 @@ Directive* convert_php_objects_to_directive(zval *obj)
                }
                return new ReplaceInclude(xmlCopyDoc((*doc)->ptr, 1));
        }
+       case IS_REFERENCE:
+               return convert_php_objects_to_directive(&Z_REF_P(obj)->val);
        case IS_NULL:
                return new Replace { "" };
        default:
@@ -243,7 +241,7 @@ void XML_Template_clean_whitespace(XmlDocPtrWrapper doc, bool aggressive)
 %}
 
 %typemap(in) Directive* {
-       $1 = convert_php_objects_to_directive(*$input);
+       $1 = convert_php_objects_to_directive(&$input);
 }
 
 XmlDocPtrWrapper XML_Template_process_file(const std::string &input_filename, Directive *root_directive, bool clean);
index 1b66e17498ad17243d196a41a99c155e8ca81e0e..bf92fca9f74ed15c64322361eb3208cca3724024 100755 (executable)
@@ -24,8 +24,8 @@ for L in $LANGUAGES; do
                if [ "$L" = "php5" ]; then
                        php5-cgi -q ../php5/$T.php > $TEMPFILE
                fi
-               if [ "$L" = "php5-swig" ]; then
-                       ( cd ../c++11 && make -s && cd ../php5-swig && make -s && sudo cp XML_Template_SWIG.so /usr/lib/php5/20090626+lfs ) && php5-cgi -q ../php5-swig/$T.php > $TEMPFILE
+               if [ "$L" = "php7-swig" ]; then
+                       ( cd ../c++11 && make -s && cd ../php7-swig && make -s && sudo cp XML_Template_SWIG.so /usr/lib/php/20151012 ) && php7-cgi -q ../php7-swig/$T.php > $TEMPFILE
                fi
                if [ "$L" = "python" ]; then
                        python2 ../python/$T.py > $TEMPFILE