cvs: ZendEngine2 / zend_alloc.c

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

  Modified files:              
    /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.217&r2=1.218&diff_format=u
Index: ZendEngine2/zend_alloc.c
diff -u ZendEngine2/zend_alloc.c:1.217 ZendEngine2/zend_alloc.c:1.218
--- ZendEngine2/zend_alloc.c:1.217	Fri Aug 15 19:45:24 2008
+++ ZendEngine2/zend_alloc.c	Thu Oct 30 08:55:31 2008
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: zend_alloc.c,v 1.217 2008/08/15 19:45:24 felipe Exp $ */
+/* $Id: zend_alloc.c,v 1.218 2008/10/30 08:55:31 dmitry Exp $ */
 
 #include "zend.h"
 #include "zend_alloc.h"
@@ -1095,16 +1095,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.