Commit in reactos on MAIN
include/ntos/rtl.h+2-21.39 -> 1.40
lib/kernel32/mem/heap.c+9-21.27 -> 1.28
lib/rtl/heap.c+51-371.5 -> 1.6
+62-41
3 modified files
-link heaps together instead of using stupid table past peb
-RtlValidateProcessHeaps/RtlGetProcessHeaps/RtlEnumProcessHeaps  didn't process all heaps
-correct RtlDestroyHeap proto. / return value
All changes based on Wine

reactos/include/ntos
rtl.h 1.39 -> 1.40
diff -u -r1.39 -r1.40
--- rtl.h	25 Nov 2004 19:22:07 -0000	1.39
+++ rtl.h	16 Dec 2004 15:10:00 -0000	1.40
@@ -1,4 +1,4 @@
-/* $Id: rtl.h,v 1.39 2004/11/25 19:22:07 ekohl Exp $
+/* $Id: rtl.h,v 1.40 2004/12/16 15:10:00 gdalsnes Exp $
  * 
  */
 #ifndef __DDK_RTL_H
@@ -960,7 +960,7 @@
 NTSTATUS STDCALL
 RtlDestroyAtomTable (IN PRTL_ATOM_TABLE AtomTable);
 
-BOOLEAN STDCALL
+HANDLE STDCALL
 RtlDestroyHeap (HANDLE hheap);
 
 NTSTATUS

reactos/lib/kernel32/mem
heap.c 1.27 -> 1.28
diff -u -r1.27 -r1.28
--- heap.c	13 Jun 2004 20:04:55 -0000	1.27
+++ heap.c	16 Dec 2004 15:10:00 -0000	1.28
@@ -1,4 +1,4 @@
-/* $Id: heap.c,v 1.27 2004/06/13 20:04:55 navaraf Exp $
+/* $Id: heap.c,v 1.28 2004/12/16 15:10:00 gdalsnes Exp $
  *
  * kernel/heap.c
  * Copyright (C) 1996, Onno Hovers, All rights reserved
@@ -53,7 +53,14 @@
  */
 BOOL WINAPI HeapDestroy(HANDLE hheap)
 {
-   return(RtlDestroyHeap(hheap));
+   if (hheap == RtlGetProcessHeap())
+   {
+      return FALSE;
+   }
+
+   if (RtlDestroyHeap( hheap )==NULL) return TRUE;
+   SetLastError( ERROR_INVALID_HANDLE );
+   return FALSE;
 }
 
 /*********************************************************************

reactos/lib/rtl
heap.c 1.5 -> 1.6
diff -u -r1.5 -r1.6
--- heap.c	11 Dec 2004 00:13:37 -0000	1.5
+++ heap.c	16 Dec 2004 15:10:01 -0000	1.6
@@ -1077,7 +1077,7 @@
               PRTL_HEAP_DEFINITION Definition)
 {
    SUBHEAP *subheap;
-   ULONG i;
+   HEAP *heapPtr;
 
    /* Allocate the heap block */
 
@@ -1091,15 +1091,14 @@
       return 0;
    }
 
+   /* link it into the per-process heap list */
    RtlEnterCriticalSection (&RtlpProcessHeapsListLock);
-   for (i = 0; i < NtCurrentPeb ()->NumberOfHeaps; i++)
-   {
-      if (NtCurrentPeb ()->ProcessHeaps[i] == NULL)
-      {
-         NtCurrentPeb()->ProcessHeaps[i] = (PVOID)subheap;
-         break;
-      }
-   }
+   
+   heapPtr = subheap->heap;
+   heapPtr->next = (HEAP*)NtCurrentPeb()->ProcessHeaps;
+   NtCurrentPeb()->ProcessHeaps = (HANDLE)heapPtr;
+   NtCurrentPeb()->NumberOfHeaps++;
+   
    RtlLeaveCriticalSection (&RtlpProcessHeapsListLock);
 
    return (HANDLE)subheap;
@@ -1112,27 +1111,34 @@
  * FALSE: Failure
  *
  * @implemented
+ * 
+ * RETURNS
+ *  Success: A NULL HANDLE, if heap is NULL or it was destroyed
+ *  Failure: The Heap handle, if heap is the process heap.
  */
-BOOLEAN STDCALL
+HANDLE STDCALL
 RtlDestroyHeap(HANDLE heap) /* [in] Handle of heap */
 {
    HEAP *heapPtr = HEAP_GetPtr( heap );
    SUBHEAP *subheap;
-   ULONG i, flags;
+   ULONG flags;
+   HEAP **pptr;
 
    DPRINT("%08x\n", heap );
    if (!heapPtr)
-      return FALSE;
+      return heap;
 
+   if (heap == NtCurrentPeb()->ProcessHeap) 
+      return heap; /* cannot delete the main process heap */
+ 
+   /* remove it from the per-process list */
    RtlEnterCriticalSection (&RtlpProcessHeapsListLock);
-   for (i = 0; i < NtCurrentPeb ()->NumberOfHeaps; i++)
-   {
-      if (NtCurrentPeb ()->ProcessHeaps[i] == heap)
-      {
-         NtCurrentPeb()->ProcessHeaps[i] = NULL;
-         break;
-      }
-   }
+   
+   pptr = (HEAP**)&NtCurrentPeb()->ProcessHeaps;
+   while (*pptr && *pptr != heapPtr) pptr = &(*pptr)->next;
+   if (*pptr) *pptr = (*pptr)->next;
+   NtCurrentPeb()->NumberOfHeaps--;
+   
    RtlLeaveCriticalSection (&RtlpProcessHeapsListLock);
 
    RtlDeleteCriticalSection( &heapPtr->critSection );
@@ -1155,7 +1161,7 @@
       }
       subheap = next;
    }
-   return TRUE;
+   return (HANDLE)NULL;
 }
 
 
@@ -1713,8 +1719,8 @@
    Peb = NtCurrentPeb();
 
    Peb->NumberOfHeaps = 0;
-   Peb->MaximumNumberOfHeaps = (PAGE_SIZE - sizeof(PEB)) / sizeof(HANDLE);
-   Peb->ProcessHeaps = (PVOID)Peb + sizeof(PEB);
+   Peb->MaximumNumberOfHeaps = -1; /* no limit */
+   Peb->ProcessHeaps = NULL;
 
    RtlInitializeCriticalSection(&RtlpProcessHeapsListLock);
 }
@@ -1728,13 +1734,13 @@
                     LONG lParam)
 {
    NTSTATUS Status = STATUS_SUCCESS;
-   ULONG i;
-
+   HEAP** pptr;
+   
    RtlEnterCriticalSection(&RtlpProcessHeapsListLock);
 
-   for (i = 0; i < NtCurrentPeb()->NumberOfHeaps; i++)
+   for (pptr = (HEAP**)&NtCurrentPeb()->ProcessHeaps; *pptr; pptr = &(*pptr)->next)
    {
-      Status = func(NtCurrentPeb()->ProcessHeaps[i],lParam);
+      Status = func(*pptr,lParam);
       if (!NT_SUCCESS(Status))
          break;
    }
@@ -1753,15 +1759,19 @@
                    HANDLE *HeapArray)
 {
    ULONG Result = 0;
+   HEAP ** pptr;
 
    RtlEnterCriticalSection(&RtlpProcessHeapsListLock);
 
+   Result = NtCurrentPeb()->NumberOfHeaps;
+   
    if (NtCurrentPeb()->NumberOfHeaps <= HeapCount)
    {
-      Result = NtCurrentPeb()->NumberOfHeaps;
-      memmove(HeapArray,
-              NtCurrentPeb()->ProcessHeaps,
-              Result * sizeof(HANDLE));
+      int i = 0;
+      for (pptr = (HEAP**)&NtCurrentPeb()->ProcessHeaps; *pptr; pptr = &(*pptr)->next)
+      {
+         HeapArray[i++] = *pptr;
+      }
    }
 
    RtlLeaveCriticalSection (&RtlpProcessHeapsListLock);
@@ -1776,18 +1786,22 @@
 BOOLEAN STDCALL
 RtlValidateProcessHeaps(VOID)
 {
-   HANDLE Heaps[128];
    BOOLEAN Result = TRUE;
-   ULONG HeapCount;
-   ULONG i;
+   HEAP ** pptr;
+
+   RtlEnterCriticalSection(&RtlpProcessHeapsListLock);
 
-   HeapCount = RtlGetProcessHeaps(128, Heaps);
-   for (i = 0; i < HeapCount; i++)
+   for (pptr = (HEAP**)&NtCurrentPeb()->ProcessHeaps; *pptr; pptr = &(*pptr)->next)
    {
-      if (!RtlValidateHeap(Heaps[i], 0, NULL))
+      if (!RtlValidateHeap(*pptr, 0, NULL))
+      {
          Result = FALSE;
+         break;
+      }
    }
 
+   RtlLeaveCriticalSection (&RtlpProcessHeapsListLock);
+
    return Result;
 }
 
CVSspam 0.2.8