bjori                                    Mon, 12 Sep 2011 13:21:57 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=316536

Log:
Allow replacement to be any scalar value

Changed paths:
    U   php/php-src/branches/PHP_5_3/ext/spl/spl_iterators.c
    U   php/php-src/branches/PHP_5_4/ext/spl/spl_iterators.c
    U   php/php-src/trunk/ext/spl/spl_iterators.c

Modified: php/php-src/branches/PHP_5_3/ext/spl/spl_iterators.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/spl/spl_iterators.c        2011-09-12 
13:20:27 UTC (rev 316535)
+++ php/php-src/branches/PHP_5_3/ext/spl/spl_iterators.c        2011-09-12 
13:21:57 UTC (rev 316536)
@@ -1868,7 +1868,7 @@
        spl_dual_it_object *intern;
        char       *subject, tmp[32], *result;
        int        subject_len, use_copy, count = 0, result_len;
-       zval       subject_copy, zcount, *replacement;
+       zval       subject_copy, zcount, *replacement, tmp_replacement;

        if (zend_parse_parameters_none() == FAILURE) {
                return;
@@ -1937,6 +1937,12 @@

        case REGIT_MODE_REPLACE:
                replacement = zend_read_property(intern->std.ce, getThis(), 
"replacement", sizeof("replacement")-1, 1 TSRMLS_CC);
+               if (Z_TYPE_P(replacement) != IS_STRING) {
+                       tmp_replacement = *replacement;
+                       zval_copy_ctor(&tmp_replacement);
+                       convert_to_string(&tmp_replacement);
+                       replacement = &tmp_replacement;
+               }
                result = php_pcre_replace_impl(intern->u.regex.pce, subject, 
subject_len, replacement, 0, &result_len, -1, &count TSRMLS_CC);

                if (intern->u.regex.flags & REGIT_USE_KEY) {
@@ -1951,6 +1957,10 @@
                        MAKE_STD_ZVAL(intern->current.data);
                        ZVAL_STRINGL(intern->current.data, result, result_len, 
0);
                }
+
+               if (replacement == &tmp_replacement) {
+                       zval_dtor(replacement);
+               }
                RETVAL_BOOL(count > 0);
        }


Modified: php/php-src/branches/PHP_5_4/ext/spl/spl_iterators.c
===================================================================
--- php/php-src/branches/PHP_5_4/ext/spl/spl_iterators.c        2011-09-12 
13:20:27 UTC (rev 316535)
+++ php/php-src/branches/PHP_5_4/ext/spl/spl_iterators.c        2011-09-12 
13:21:57 UTC (rev 316536)
@@ -1975,7 +1975,7 @@
        spl_dual_it_object *intern = 
(spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
        char       *subject, tmp[32], *result;
        int        subject_len, use_copy, count = 0, result_len;
-       zval       subject_copy, zcount, *replacement;
+       zval       subject_copy, zcount, *replacement, tmp_replacement;

        if (zend_parse_parameters_none() == FAILURE) {
                return;
@@ -2042,6 +2042,12 @@

        case REGIT_MODE_REPLACE:
                replacement = zend_read_property(intern->std.ce, getThis(), 
"replacement", sizeof("replacement")-1, 1 TSRMLS_CC);
+               if (Z_TYPE_P(replacement) != IS_STRING) {
+                       tmp_replacement = *replacement;
+                       zval_copy_ctor(&tmp_replacement);
+                       convert_to_string(&tmp_replacement);
+                       replacement = &tmp_replacement;
+               }
                result = php_pcre_replace_impl(intern->u.regex.pce, subject, 
subject_len, replacement, 0, &result_len, -1, &count TSRMLS_CC);

                if (intern->u.regex.flags & REGIT_USE_KEY) {
@@ -2056,6 +2062,10 @@
                        MAKE_STD_ZVAL(intern->current.data);
                        ZVAL_STRINGL(intern->current.data, result, result_len, 
0);
                }
+
+               if (replacement == &tmp_replacement) {
+                       zval_dtor(replacement);
+               }
                RETVAL_BOOL(count > 0);
        }


Modified: php/php-src/trunk/ext/spl/spl_iterators.c
===================================================================
--- php/php-src/trunk/ext/spl/spl_iterators.c   2011-09-12 13:20:27 UTC (rev 
316535)
+++ php/php-src/trunk/ext/spl/spl_iterators.c   2011-09-12 13:21:57 UTC (rev 
316536)
@@ -1975,7 +1975,7 @@
        spl_dual_it_object *intern = 
(spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
        char       *subject, tmp[32], *result;
        int        subject_len, use_copy, count = 0, result_len;
-       zval       subject_copy, zcount, *replacement;
+       zval       subject_copy, zcount, *replacement, tmp_replacement;

        if (zend_parse_parameters_none() == FAILURE) {
                return;
@@ -2042,6 +2042,12 @@

        case REGIT_MODE_REPLACE:
                replacement = zend_read_property(intern->std.ce, getThis(), 
"replacement", sizeof("replacement")-1, 1 TSRMLS_CC);
+               if (Z_TYPE_P(replacement) != IS_STRING) {
+                       tmp_replacement = *replacement;
+                       zval_copy_ctor(&tmp_replacement);
+                       convert_to_string(&tmp_replacement);
+                       replacement = &tmp_replacement;
+               }
                result = php_pcre_replace_impl(intern->u.regex.pce, subject, 
subject_len, replacement, 0, &result_len, -1, &count TSRMLS_CC);

                if (intern->u.regex.flags & REGIT_USE_KEY) {
@@ -2056,6 +2062,10 @@
                        MAKE_STD_ZVAL(intern->current.data);
                        ZVAL_STRINGL(intern->current.data, result, result_len, 
0);
                }
+
+               if (replacement == &tmp_replacement) {
+                       zval_dtor(replacement);
+               }
                RETVAL_BOOL(count > 0);
        }


-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to