Ignore:
Timestamp:
Jun 7, 1999, 10:58:22 PM (26 years ago)
Author:
sandervl
Message:

* empty log message *

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/heap.cpp

    r37 r46  
    1 /* $Id: heap.cpp,v 1.5 1999-06-06 12:25:49 cbratschi Exp $ */
    2 
    31/*
    42 *
     
    1513#include <stdlib.h>
    1614#include <string.h>
    17 #include <builtin.h>
    18 #include "misc.h"
    19 
     15#include <misc.h>
    2016#define  _WIN32
    2117#include "os2heap.h"
     
    7167  curheap = new OS2Heap(hHeap, flOptions, dwInitialSize, dwMaximumSize);
    7268  if(curheap == NULL) {
    73         O32_HeapDestroy(hHeap);
     69        O32_HeapDestroy(hHeap);
    7470        return(NULL);
    7571  }
    7672  if(curheap->getHeapHandle() == NULL) {
    77         O32_HeapDestroy(hHeap);
     73        O32_HeapDestroy(hHeap);
    7874        delete curheap;
    7975        return(NULL);
     
    9692//******************************************************************************
    9793//******************************************************************************
    98 /* PH: Though "HeapSize" is a reserved word for the linker, ILINK can be
    99    tricked by placing the word HEAPSIZE in quotes. It then exports it properly
    100    to the target DLL.
    101  */
    10294DWORD WIN32API HeapSize(HANDLE hHeap, DWORD arg2, PVOID  arg3)
    10395{
     
    154146    //SvL: Only one process heap per process
    155147    if(processheap == NULL) {
    156         //TODO: I haven't thought real hard about this.  I added it just to make "hdr.exe" happy.
    157         hHeap = O32_HeapCreate(HEAP_GENERATE_EXCEPTIONS, 1, 0x4000);
    158         OS2ProcessHeap = new OS2Heap(hHeap, HEAP_GENERATE_EXCEPTIONS, 0x4000, 0);
    159         if(OS2ProcessHeap == NULL) {
    160                 O32_HeapDestroy(hHeap);
    161                 return(NULL);
    162         }
    163         processheap = hHeap;
     148        //TODO: I haven't thought real hard about this.  I added it just to make "hdr.exe" happy.
     149        hHeap = O32_HeapCreate(HEAP_GENERATE_EXCEPTIONS, 1, 0x4000);
     150        OS2ProcessHeap = new OS2Heap(hHeap, HEAP_GENERATE_EXCEPTIONS, 0x4000, 0);
     151        if(OS2ProcessHeap == NULL) {
     152                O32_HeapDestroy(hHeap);
     153                return(NULL);
     154        }
     155        processheap = hHeap;
    164156    }
    165157    return(processheap);
     
    173165
    174166  if(processheap == NULL) {
    175         if(GetProcessHeap() == NULL)
    176                 return(NULL);
     167        if(GetProcessHeap() == NULL)
     168                return(NULL);
    177169  }
    178170  if(fuFlags & LMEM_ZEROINIT)
     
    209201
    210202    if(OS2ProcessHeap->GetLockCnt((LPVOID)hMem) != 0) {
    211         dprintf(("LocalFree, lock count != 0\n"));
    212         return(hMem);   //TODO: SetLastError
     203        dprintf(("LocalFree, lock count != 0\n"));
     204        return(hMem);   //TODO: SetLastError
    213205    }
    214206    if(OS2ProcessHeap->Free(0, (LPVOID)hMem) == FALSE) {
    215         return(hMem);   //TODO: SetLastError
     207        return(hMem);   //TODO: SetLastError
    216208    }
    217209    return NULL; //success
     
    238230HLOCAL WIN32API LocalReAlloc(HLOCAL hMem, DWORD cbBytes, UINT fuFlags)
    239231{
    240  HLOCAL lpMem;
     232 LPVOID lpMem;
    241233
    242234    dprintf(("KERNEL32: LocalReAlloc %X %d %X\n", hMem, cbBytes, fuFlags));
    243235    //SvL: 8-8-'98: Notepad bugfix (assumes address is identical when new size < old size)
    244     if(OS2ProcessHeap->Size(0, (LPVOID)hMem) >= cbBytes)
    245     {
    246         dprintf(("KERNEL32:  LocalReAlloc returned %X\n", hMem));
    247         return hMem;
    248     }
    249 
    250     lpMem = LocalAlloc(fuFlags, cbBytes);
    251     memcpy((LPVOID)lpMem, (LPVOID)hMem, min(cbBytes, OS2ProcessHeap->Size(0, (LPVOID)hMem)));
     236    if(OS2ProcessHeap->Size(0, (LPVOID)hMem) > cbBytes)
     237        return hMem;
     238
     239    lpMem = (LPVOID)O32_LocalAlloc(fuFlags, cbBytes);
     240    memcpy(lpMem, (LPVOID)hMem, min(cbBytes, OS2ProcessHeap->Size(0, (LPVOID)hMem)));
    252241    OS2ProcessHeap->Free(0, (LPVOID)hMem);
    253 
    254     dprintf(("KERNEL32:  LocalReAlloc returned %X\n", lpMem));
    255242    return((HLOCAL)lpMem);
    256243}
Note: See TracChangeset for help on using the changeset viewer.