andrey          Sun Jul 11 15:20:05 2004 EDT

  Added files:                 
    /php-src/ext/standard/tests/array   bug28739.phpt 

  Modified files:              
    /php-src/ext/standard       array.c 
  Log:
  fixing bug #28739
  array_*diff() and array_*intersect() not clearing the fci cache before work.
  FCI call cache was introduced in HEAD. All functions that perform sorting
  of arrays clear the fci cache before work. array_*diff() and\ array_*intersect()
  were somehow missed to be updated.
  
  
http://cvs.php.net/diff.php/php-src/ext/standard/array.c?r1=1.264&r2=1.265&ty=u
Index: php-src/ext/standard/array.c
diff -u php-src/ext/standard/array.c:1.264 php-src/ext/standard/array.c:1.265
--- php-src/ext/standard/array.c:1.264  Sun Jul 11 14:18:05 2004
+++ php-src/ext/standard/array.c        Sun Jul 11 15:20:05 2004
@@ -21,7 +21,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: array.c,v 1.264 2004/07/11 18:18:05 andrey Exp $ */
+/* $Id: array.c,v 1.265 2004/07/11 19:20:05 andrey Exp $ */
 
 #include "php.h"
 #include "php_ini.h"
@@ -2758,6 +2758,12 @@
        }
 
        old_compare_func = BG(user_compare_func_name);
+       /* clear FCI cache otherwise : for example the same or other array with 
+          (partly) the same key values has been sorted with uasort() or
+          other sorting function the comparison is cached, however the the name
+          of the function for comparison is not respected. see bug #28739
+       */
+       BG(user_compare_fci_cache) = empty_fcall_info_cache;
 
        if (behavior == INTERSECT_NORMAL) {
                intersect_key_compare_func = array_key_compare;
@@ -2785,7 +2791,7 @@
                                return;
                        }
                        efree(callback_name);
-                       
+
                        BG(user_compare_func_name) = args[arr_argc];
                } else {
                        php_error_docref(NULL TSRMLS_CC, E_WARNING, "data_compare_type 
is %d. This should never happen. Please report as a bug", data_compare_type);
@@ -3106,6 +3112,12 @@
        }
 
        old_compare_func = BG(user_compare_func_name);
+       /* clear FCI cache otherwise : for example the same or other array with 
+          (partly) the same key values has been sorted with uasort() or
+          other sorting function the comparison is cached, however the the name
+          of the function for comparison is not respected. see bug #28739
+       */
+       BG(user_compare_fci_cache) = empty_fcall_info_cache;
 
        if (behavior == DIFF_NORMAL) {
                diff_key_compare_func = array_key_compare;

http://cvs.php.net/co.php/php-src/ext/standard/tests/array/bug28739.phpt?r=1.1&p=1
Index: php-src/ext/standard/tests/array/bug28739.phpt
+++ php-src/ext/standard/tests/array/bug28739.phpt
--TEST--
Bug #28739 (*diff() and *intersect() not clearing the fci cache before work)
--FILE--
<?php
class p {
   public $x;
   function __construct($x){$this->x=$x;}
}
function a(&$a, &$b){var_dump(__FUNCTION__);return $a->x - $b->x;}
function b(&$a, &$b){var_dump(__FUNCTION__);return $a->x - $b->x;}

$p1 = array(new p(2), new p(1), new p(0));
$p2 = array(new p(0), new p(2), new p(3));

uasort($p1, 'a');
print_r($p1);
echo "Now diffing:\n";
print_r(array_udiff($p1,$p2, 'b'));
?>
--EXPECT--
string(1) "a"
string(1) "a"
Array
(
    [2] => p Object
        (
            [x] => 0
        )

    [1] => p Object
        (
            [x] => 1
        )

    [0] => p Object
        (
            [x] => 2
        )

)
Now diffing:
string(1) "b"
string(1) "b"
string(1) "b"
string(1) "b"
string(1) "b"
string(1) "b"
string(1) "b"
string(1) "b"
string(1) "b"
Array
(
    [1] => p Object
        (
            [x] => 1
        )

)

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

Reply via email to