nlopess         Thu Aug 14 14:37:39 2008 UTC

  Modified files:              (Branch: PHP_5_3)
    /php-src/ext/pcre   php_pcre.c 
    /php-src/ext/pcre/tests     bug44925.phpt 
  Log:
  after rereading the documentation about preg_grep(), lets match the behavior 
in HEAD (return the original array elements instead of the new string).
  tune the test accordingly
  
http://cvs.php.net/viewvc.cgi/php-src/ext/pcre/php_pcre.c?r1=1.168.2.9.2.21.2.20&r2=1.168.2.9.2.21.2.21&diff_format=u
Index: php-src/ext/pcre/php_pcre.c
diff -u php-src/ext/pcre/php_pcre.c:1.168.2.9.2.21.2.20 
php-src/ext/pcre/php_pcre.c:1.168.2.9.2.21.2.21
--- php-src/ext/pcre/php_pcre.c:1.168.2.9.2.21.2.20     Thu Aug 14 13:12:42 2008
+++ php-src/ext/pcre/php_pcre.c Thu Aug 14 14:37:39 2008
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: php_pcre.c,v 1.168.2.9.2.21.2.20 2008/08/14 13:12:42 nlopess Exp $ */
+/* $Id: php_pcre.c,v 1.168.2.9.2.21.2.21 2008/08/14 14:37:39 nlopess Exp $ */
 
 #include "php.h"
 #include "php_ini.h"
@@ -1744,29 +1744,16 @@
        /* 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 @@
                /* 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));
http://cvs.php.net/viewvc.cgi/php-src/ext/pcre/tests/bug44925.phpt?r1=1.1.2.1&r2=1.1.2.2&diff_format=u
Index: php-src/ext/pcre/tests/bug44925.phpt
diff -u php-src/ext/pcre/tests/bug44925.phpt:1.1.2.1 
php-src/ext/pcre/tests/bug44925.phpt:1.1.2.2
--- php-src/ext/pcre/tests/bug44925.phpt:1.1.2.1        Thu Aug 14 13:12:42 2008
+++ php-src/ext/pcre/tests/bug44925.phpt        Thu Aug 14 14:37:39 2008
@@ -54,33 +54,35 @@
   [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]=>



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

Reply via email to