]> git.sesse.net Git - xml-template/blobdiff - php7-swig/xml-template.swig
Update the PHP SWIG version to PHP 7, with various crash fixes, too.
[xml-template] / php7-swig / xml-template.swig
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);