cvs: ZendEngine2(PHP_5_3) / zend_alloc.c

[email protected] ("Dmitry Stogov")
Newsgroups php.zend-engine.cvs
Message-ID <cvsdmitry1225356920@cvsserver>
dmitry		Thu Oct 30 08:55:20 2008 UTC

  Modified files:              (Branch: PHP_5_3)
    /ZendEngine2	zend_alloc.c 
  Log:
  Fixed ability to use "internal" heaps in extensions.
  
  
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_alloc.c?r1=1.144.2.3.2.43.2.16&r2=1.144.2.3.2.43.2.17&diff_format=u
Index: ZendEngine2/zend_alloc.c
diff -u ZendEngine2/zend_alloc.c:1.144.2.3.2.43.2.16 ZendEngine2/zend_alloc.c:1.144.2.3.2.43.2.17
--- ZendEngine2/zend_alloc.c:1.144.2.3.2.43.2.16	Fri Aug 15 19:47:23 2008
+++ ZendEngine2/zend_alloc.c	Thu Oct 30 08:55:20 2008
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: zend_alloc.c,v 1.144.2.3.2.43.2.16 2008/08/15 19:47:23 felipe Exp $ */
+/* $Id: zend_alloc.c,v 1.144.2.3.2.43.2.17 2008/10/30 08:55:20 dmitry Exp $ */
 
 #include "zend.h"
 #include "zend_alloc.h"
@@ -1068,16 +1068,26 @@
 	}
 	if (internal) {
 		int i;
-		zend_mm_free_block *p;
+		zend_mm_free_block *p, *q, *orig;
 		zend_mm_heap *mm_heap = _zend_mm_alloc_int(heap, sizeof(zend_mm_heap)  ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC);
 
 		*mm_heap = *heap;
 
 		p = ZEND_MM_SMALL_FREE_BUCKET(mm_heap, 0);
+		orig = ZEND_MM_SMALL_FREE_BUCKET(heap, 0);
 		for (i = 0; i < ZEND_MM_NUM_BUCKETS; i++) {
-			p->prev_free_block->next_free_block = p;
-			p->next_free_block->prev_free_block = p;
+			q = p;
+			while (q->prev_free_block != orig) {
+				q = q->prev_free_block;
+			}
+			q->prev_free_block = p;
+			q = p;
+			while (q->next_free_block != orig) {
+				q = q->next_free_block;
+			}
+			q->next_free_block = p;
 			p = (zend_mm_free_block*)((char*)p + sizeof(zend_mm_free_block*) * 2);
+			orig = (zend_mm_free_block*)((char*)orig + sizeof(zend_mm_free_block*) * 2);
 			if (mm_heap->large_free_buckets[i]) {
 				mm_heap->large_free_buckets[i]->parent = &mm_heap->large_free_buckets[i];
 			}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.