]> granicus.if.org Git - php/commitdiff
after rereading the documentation about preg_grep(), lets match the behavior in HEAD...
authorNuno Lopes <nlopess@php.net>
Thu, 14 Aug 2008 14:37:39 +0000 (14:37 +0000)
committerNuno Lopes <nlopess@php.net>
Thu, 14 Aug 2008 14:37:39 +0000 (14:37 +0000)
tune the test accordingly

ext/pcre/php_pcre.c
ext/pcre/tests/bug44925.phpt

index 8d6b2eaffd2471c6374c69a4568045cc23a14caf..ee25c3a0cfb8b72718e1bf6e5982fec5fb561f39 100644 (file)
@@ -1744,29 +1744,16 @@ PHPAPI void  php_pcre_grep_impl(pcre_cache_entry *pce, zval *input, zval *return
        /* Go through the input array */
        zend_hash_internal_pointer_reset(Z_ARRVAL_P(input));
        while (zend_hash_get_current_data(Z_ARRVAL_P(input), (void **)&entry) == SUCCESS) {
-               zend_bool is_copy;
-               zval *str;
+               zval subject = **entry;
 
-               switch (Z_TYPE_PP(entry)) {
-                       case IS_STRING:
-                               is_copy = 0;
-                               str = *entry;
-                               break;
-
-                       default:
-                               is_copy = 1;
-
-                               ALLOC_ZVAL(str);
-                               Z_ADDREF_PP(entry); /* the function below decreases the ref counting */
-                               COPY_PZVAL_TO_ZVAL(*str, *entry);
-
-                               convert_to_string(str);
-                               break;
+               if (Z_TYPE_PP(entry) != IS_STRING) {
+                       zval_copy_ctor(&subject);
+                       convert_to_string(&subject);
                }
 
                /* Perform the match */
-               count = pcre_exec(pce->re, extra, Z_STRVAL_P(str),
-                                                 Z_STRLEN_P(str), 0,
+               count = pcre_exec(pce->re, extra, Z_STRVAL(subject),
+                                                 Z_STRLEN(subject), 0,
                                                  0, offsets, size_offsets);
 
                /* Check for too many substrings condition. */
@@ -1781,26 +1768,25 @@ PHPAPI void  php_pcre_grep_impl(pcre_cache_entry *pce, zval *input, zval *return
                /* If the entry fits our requirements */
                if ((count > 0 && !invert) || (count == PCRE_ERROR_NOMATCH && invert)) {
 
-                       if (!is_copy) {
-                               SEPARATE_ARG_IF_REF(str);
-                       }
+                       Z_ADDREF_PP(entry);
 
                        /* Add to return array */
                        switch (zend_hash_get_current_key(Z_ARRVAL_P(input), &string_key, &num_key, 0))
                        {
                                case HASH_KEY_IS_STRING:
                                        zend_hash_update(Z_ARRVAL_P(return_value), string_key,
-                                                                        strlen(string_key)+1, &str, sizeof(zval *), NULL);
+                                                                        strlen(string_key)+1, entry, sizeof(zval *), NULL);
                                        break;
 
                                case HASH_KEY_IS_LONG:
-                                       zend_hash_index_update(Z_ARRVAL_P(return_value), num_key, &str,
+                                       zend_hash_index_update(Z_ARRVAL_P(return_value), num_key, entry,
                                                                                   sizeof(zval *), NULL);
                                        break;
                        }
-               } else if (is_copy) {
-                       zval_dtor(str);
-                       FREE_ZVAL(str);
+               }
+
+               if (Z_TYPE_PP(entry) != IS_STRING) {
+                       zval_dtor(&subject);
                }
 
                zend_hash_move_forward(Z_ARRVAL_P(input));
index 828d2459dc0d26e51db25d126371a76d6728a84f..f6e0db425305e815ebb9dff4c8c3e0dcd2747e63 100644 (file)
@@ -54,33 +54,35 @@ array(7) {
   [0]=>
   string(1) "1"
   [1]=>
-  string(1) "2"
+  int(2)
   [2]=>
-  string(1) "3"
+  int(3)
   [3]=>
-  string(3) "1.1"
+  float(1.1)
   [6]=>
-  string(5) "Array"
+  array(0) {
+  }
   [7]=>
   string(1) "a"
   [8]=>
-  string(1) "b"
+  &string(1) "b"
 }
 array(7) {
   [0]=>
   string(1) "1"
   [1]=>
-  string(1) "2"
+  int(2)
   [2]=>
-  string(1) "3"
+  int(3)
   [3]=>
-  string(3) "1.1"
+  float(1.1)
   [6]=>
-  string(5) "Array"
+  array(0) {
+  }
   [7]=>
   string(1) "a"
   [8]=>
-  string(1) "b"
+  &string(1) "y"
 }
 array(9) {
   [0]=>