- Timestamp:
- Nov 16, 2001, 1:57:01 PM (24 years ago)
- Location:
- trunk/src/kernel32
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/heap.cpp
r7067 r7358 1 /* $Id: heap.cpp,v 1.39 2001-10-15 17:17:48 sandervl Exp $ */2 1 3 2 /* … … 32 31 OS2Heap *OS2ProcessHeap = NULL; 33 32 34 //****************************************************************************** 35 //****************************************************************************** 36 ODINFUNCTIONNODBG3(LPVOID, HeapAlloc, HANDLE, hHeap, DWORD, dwFlags, 37 DWORD, dwBytes) 38 { 39 OS2Heap *curheap = OS2Heap::find(hHeap); 40 LPVOID rc; 33 34 35 //****************************************************************************** 36 // Fast Heap Handle Management 37 //****************************************************************************** 38 39 extern HANDLE fhhm_lastHandle; 40 extern OS2Heap* fhhm_lastHeap; 41 42 #define FINDHEAP(curheap, hHeap) \ 43 if (fhhm_lastHeap && \ 44 hHeap == fhhm_lastHandle) \ 45 curheap = fhhm_lastHeap; \ 46 else \ 47 curheap = OS2Heap::find(hHeap); \ 48 49 50 //****************************************************************************** 51 //****************************************************************************** 52 LPVOID WIN32API HeapAlloc(HANDLE hHeap, 53 DWORD dwFlags, 54 DWORD dwBytes) 55 { 56 OS2Heap *curheap; 57 FINDHEAP(curheap,hHeap) 58 LPVOID rc; 41 59 42 60 if(curheap == NULL) … … 49 67 //****************************************************************************** 50 68 //****************************************************************************** 51 ODINFUNCTIONNODBG4(LPVOID, HeapReAlloc, HANDLE, hHeap, DWORD, dwFlags, LPVOID, 52 lpMem, DWORD, dwBytes) 53 { 54 OS2Heap *curheap = OS2Heap::find(hHeap); 69 LPVOID HeapReAlloc(HANDLE hHeap, 70 DWORD dwFlags, 71 LPVOID lpMem, 72 DWORD dwBytes) 73 { 74 OS2Heap *curheap; 75 FINDHEAP(curheap,hHeap) 55 76 56 77 dprintf2(("HeapReAlloc %x %x %x %X bytes", hHeap, dwFlags, lpMem, dwBytes)); … … 66 87 //****************************************************************************** 67 88 //****************************************************************************** 68 ODINFUNCTIONNODBG3(BOOL, HeapFree, HANDLE, hHeap, DWORD, dwFlags, LPVOID, lpMem) 69 { 70 OS2Heap *curheap = OS2Heap::find(hHeap); 89 BOOL WIN32API HeapFree(HANDLE hHeap, 90 DWORD dwFlags, 91 LPVOID lpMem) 92 { 93 OS2Heap *curheap; 94 FINDHEAP(curheap,hHeap) 71 95 72 96 dprintf2(("HeapFree %X", lpMem)); 73 97 if(curheap == NULL) 74 return(FALSE); 75 76 return(curheap->Free(dwFlags, lpMem)); 98 return(FALSE); 99 100 BOOL fResult = curheap->Free(dwFlags, lpMem); 101 if (fResult == FALSE) 102 SetLastError(ERROR_INVALID_HANDLE); /// @@@PH possibly wrong return code! 103 104 return fResult; 77 105 } 78 106 //****************************************************************************** … … 104 132 ODINFUNCTIONNODBG1(BOOL, HeapDestroy, HANDLE, hHeap) 105 133 { 106 OS2Heap *curheap = OS2Heap::find(hHeap); 134 OS2Heap *curheap; 135 FINDHEAP(curheap,hHeap) 107 136 108 137 dprintf2(("HeapDestroy %X", hHeap)); … … 117 146 ODINFUNCTIONNODBG3(DWORD, HeapSize, HANDLE, hHeap, DWORD, arg2, PVOID, lpMem) 118 147 { 119 OS2Heap *curheap = OS2Heap::find(hHeap); 148 OS2Heap *curheap; 149 FINDHEAP(curheap,hHeap) 120 150 121 151 dprintf2(("HeapSize %X %x %x", hHeap, arg2, lpMem)); … … 136 166 ODINFUNCTIONNODBG3(BOOL, HeapValidate, HANDLE, hHeap, DWORD, dwFlags, LPCVOID, lpMem) 137 167 { 138 OS2Heap *curheap = OS2Heap::find(hHeap); 168 OS2Heap *curheap; 169 FINDHEAP(curheap,hHeap) 139 170 140 171 dprintf2(("KERNEL32: HeapValidate %x %x %x", hHeap, dwFlags, lpMem)); … … 168 199 //****************************************************************************** 169 200 //****************************************************************************** 170 ODINFUNCTIONNODBG0(HANDLE, GetProcessHeap) 171 { 172 HANDLE hHeap; 173 201 HANDLE WIN32API GetProcessHeap() 202 { 174 203 // dprintf2(("KERNEL32: GetProcessHeap\n")); 175 204 //SvL: Only one process heap per process … … 242 271 { 243 272 palloc=HeapAlloc(GetProcessHeap(), hpflags, size); 244 dprintf(("KERNEL32: GlobalAlloc %x %d returned %x", flags, size, palloc));245 273 return (HGLOBAL) palloc; 246 274 } … … 270 298 /* HeapUnlock(heap); */ 271 299 272 dprintf(("KERNEL32: GlobalAlloc %x %d returned %x", flags, size, INTERN_TO_HANDLE(pintern)));273 300 return INTERN_TO_HANDLE(pintern); 274 301 } … … 477 504 478 505 #ifdef __WIN32OS2__ 479 hmem = GlobalHandle((LPCVOID)hmem); 506 /* @@@PH 20011017 507 convert a handle to a handle ??? 508 hmem = GlobalHandle((LPCVOID)hmem); 509 */ 480 510 #endif 481 511 … … 581 611 PGLOBAL32_INTERN pintern; 582 612 HGLOBAL hreturned = 0; 583 613 614 // 2001-10-17 PH 615 // Note: we do have a *HANDLE* here still ... 616 // any may not terminate w/o setting SetLastError() 617 // plus returning 0 means "OK"! 618 #if 0 584 619 /* verify lpMem address */ 585 620 if (hmem >= (HGLOBAL)ulMaxAddr || hmem < (HGLOBAL)0x10000) … … 589 624 return 0; 590 625 } 591 626 #endif 627 592 628 if(ISPOINTER(hmem)) /* POINTER */ 593 629 { 594 if(!HeapFree(GetProcessHeap(), 0, (LPVOID) hmem)) hmem = 0; 630 if(HeapFree(GetProcessHeap(), 0, (LPVOID) hmem) == TRUE) 631 hreturned = 0; // success 632 else 633 hreturned = hmem; // failure 595 634 } 596 635 else /* HANDLE */ … … 613 652 hreturned=hmem; 614 653 } 654 else 655 { 656 // this was not a heap handle! 657 SetLastError(ERROR_INVALID_HANDLE); 658 hreturned = hmem; 659 } 660 615 661 /* HeapUnlock(heap); */ 616 662 } 663 617 664 return hreturned; 618 665 } -
trunk/src/kernel32/os2heap.cpp
r7156 r7358 1 /* $Id: os2heap.cpp,v 1. 29 2001-10-22 23:28:11phaller Exp $ */1 /* $Id: os2heap.cpp,v 1.30 2001-11-16 12:57:00 phaller Exp $ */ 2 2 3 3 /* … … 50 50 //****************************************************************************** 51 51 52 //static int fhhm_hit = 0; 53 //static int fhhm_miss = 0; 54 static HANDLE fhhm_lastHandle = 0; 55 static OS2Heap* fhhm_lastHeap = NULL; 52 HANDLE fhhm_lastHandle = 0; 53 OS2Heap* fhhm_lastHeap = NULL; 56 54 57 55 … … 237 235 HEAPELEM *helem = GET_HEAPOBJ(lpMem); 238 236 239 if(lpMem == NULL) {240 dprintf(("OS2Heap::Free lpMem == NULL\n"));241 return(FALSE);242 }243 237 /* verify lpMem address */ 244 238 if (lpMem >= (LPVOID)ulMaxAddr || lpMem < (LPVOID)0x10000) … … 307 301 OS2Heap *OS2Heap::find(HANDLE hHeap) 308 302 { 309 // check against cache first 310 if (fhhm_lastHeap)311 if (hHeap == fhhm_lastHandle)312 {313 // fhhm_hit++; 314 return fhhm_lastHeap;315 }316 317 // fhhm_miss++; 318 303 /* PH moved to inlineable macro ... 304 * // check against cache first 305 * if (fhhm_lastHeap) 306 * if (hHeap == fhhm_lastHandle) 307 * { 308 * return fhhm_lastHeap; 309 * } 310 * 311 */ 312 319 313 OS2Heap *curheap = OS2Heap::heap; 320 314
Note:
See TracChangeset
for help on using the changeset viewer.