colder          Sun Aug  3 19:07:31 2008 UTC

  Added files:                 (Branch: PHP_5_3)
    /php-src/ext/spl/tests      heap_011.phpt 

  Modified files:              
    /php-src/ext/spl    spl_heap.c 
    /php-src/ext/spl/tests      heap_001.phpt 
  Log:
  MFH: Fix clone + add tests
  
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/spl_heap.c?r1=1.1.2.7&r2=1.1.2.8&diff_format=u
Index: php-src/ext/spl/spl_heap.c
diff -u php-src/ext/spl/spl_heap.c:1.1.2.7 php-src/ext/spl/spl_heap.c:1.1.2.8
--- php-src/ext/spl/spl_heap.c:1.1.2.7  Sun Aug  3 18:16:10 2008
+++ php-src/ext/spl/spl_heap.c  Sun Aug  3 19:07:31 2008
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: spl_heap.c,v 1.1.2.7 2008/08/03 18:16:10 colder Exp $ */
+/* $Id: spl_heap.c,v 1.1.2.8 2008/08/03 19:07:31 colder Exp $ */
 
 #ifdef HAVE_CONFIG_H
 # include "config.h"
@@ -397,7 +397,13 @@
                intern->ce_get_iterator = other->ce_get_iterator;
 
                if (clone_orig) {
+                       int i;
                        intern->heap = spl_ptr_heap_clone(other->heap 
TSRMLS_CC);
+                       for (i = 0; i < intern->heap->count; ++i) {
+                               if (intern->heap->elements[i]) {
+                                       Z_ADDREF_P((zval 
*)intern->heap->elements[i]);
+                               }
+                       }
                } else {
                        intern->heap = other->heap;
                }
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/tests/heap_001.phpt?r1=1.1.2.3&r2=1.1.2.4&diff_format=u
Index: php-src/ext/spl/tests/heap_001.phpt
diff -u php-src/ext/spl/tests/heap_001.phpt:1.1.2.3 
php-src/ext/spl/tests/heap_001.phpt:1.1.2.4
--- php-src/ext/spl/tests/heap_001.phpt:1.1.2.3 Sat May 24 14:10:44 2008
+++ php-src/ext/spl/tests/heap_001.phpt Sun Aug  3 19:07:31 2008
@@ -32,7 +32,9 @@
 $h->insert($b);
 $b = 5;
 
+$h2 = clone $h;
 echo $h->extract()."\n";
+echo $h2->extract()."\n";
 ?>
 ===DONE===
 <?php exit(0); ?>
@@ -47,4 +49,5 @@
 0
 --
 4
+4
 ===DONE===

http://cvs.php.net/viewvc.cgi/php-src/ext/spl/tests/heap_011.phpt?view=markup&rev=1.1
Index: php-src/ext/spl/tests/heap_011.phpt
+++ php-src/ext/spl/tests/heap_011.phpt
--TEST--
SPL: SplHeap with overriden compare()
--FILE--
<?php
class SplMinHeap2 extends SplMinHeap {
    public function compare($a, $b) {
        return -parent::compare($a,$b);
    }
}
$h = new SplMinHeap2();
$h->insert(1);
$h->insert(6);
$h->insert(5);
$h->insert(2);
var_dump($h->top());

class SplMaxHeap2 extends SplMaxHeap {
    public function compare($a, $b) {
        return -parent::compare($a,$b);
    }
}
$h = new SplMaxHeap2();
$h->insert(1);
$h->insert(6);
$h->insert(5);
$h->insert(2);
var_dump($h->top());
?>
--EXPECT--
int(6)
int(1)



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

Reply via email to