X-Git-Url: http://4ch.mooo.com/gitweb/?a=blobdiff_plain;f=src%2Flib%2F16_hc.c;h=005244479b016aae5116a522307bc135253213d2;hb=d89b4d35446e64b0b8fd7c8fdcff32bcd0845e32;hp=f9f4948c08c4d987e8e926f87affd1c78d7f27d2;hpb=fad5fd480cf00e701a6a78a7c7693538ca700fc5;p=16.git diff --git a/src/lib/16_hc.c b/src/lib/16_hc.c index f9f4948c..00524447 100644 --- a/src/lib/16_hc.c +++ b/src/lib/16_hc.c @@ -24,32 +24,71 @@ */ #include "src/lib/16_hc.h" +#pragma hdrstop + +#pragma warn -pro +#pragma warn -use int heaphandle; +#ifdef __BORLANDC__ +void * LargestFreeBlock(size_t* Size) +#endif +#ifdef __WATCOMC__ void __near* LargestFreeBlock(size_t* Size) +#endif { size_t s0, s1; +#ifdef __BORLANDC__ + void * p; +#endif +#ifdef __WATCOMC__ void __near* p; +#endif s0 = ~(size_t)0 ^ (~(size_t)0 >> 1); +#ifdef __BORLANDC__ + while (s0 && (p = malloc(s0)) == NULL) +#endif +#ifdef __WATCOMC__ while (s0 && (p = _nmalloc(s0)) == NULL) +#endif s0 >>= 1; if (p) +#ifdef __BORLANDC__ + free(p); +#endif +#ifdef __WATCOMC__ _nfree(p); +#endif s1 = s0 >> 1; while (s1) { +#ifdef __BORLANDC__ + if ((p = malloc(s0 + s1)) != NULL) +#endif +#ifdef __WATCOMC__ if ((p = _nmalloc(s0 + s1)) != NULL) +#endif { s0 += s1; +#ifdef __BORLANDC__ + free(p); +#endif +#ifdef __WATCOMC__ _nfree(p); +#endif } s1 >>= 1; } +#ifdef __BORLANDC__ + while (s0 && (p = malloc(s0)) == NULL) +#endif +#ifdef __WATCOMC__ while (s0 && (p = _nmalloc(s0)) == NULL) +#endif s0 ^= s0 & -s0; *Size = s0; @@ -64,11 +103,16 @@ size_t _coreleft(void) for(;;) { size_t largest; - void __near* p = LargestFreeBlock(&largest); + void __near* p = (void __near *)LargestFreeBlock(&largest); if (largest < sizeof(void __near*)) { if (p != NULL) +#ifdef __BORLANDC__ + free(p); +#endif +#ifdef __WATCOMC__ _nfree(p); +#endif break; } *(void __near* __near*)p = NULL; @@ -84,7 +128,12 @@ size_t _coreleft(void) while (pFirst != NULL) { void __near* p = *(void __near* __near*)pFirst; +#ifdef __BORLANDC__ + free(pFirst); +#endif +#ifdef __WATCOMC__ _nfree(pFirst); +#endif pFirst = p; } return total; @@ -153,6 +202,7 @@ size_t _farcoreleft(void) return total; } +#ifdef __WATCOMC__ void huge* LargestHugeFreeBlock(size_t* Size) { size_t s0, s1; @@ -367,7 +417,7 @@ void heapdump(void) write(heaphandle,scratch,strlen(scratch)); } heapstat(heap_status, &scratch); - + //near strcpy(scratch,"\n == near ==\n\n"); write(heaphandle,scratch,strlen(scratch)); @@ -432,7 +482,7 @@ void heapstat(int heap_status, byte *str) break; case _HEAPEMPTY: strcpy((str),"OK - heap is empty\n"); - + break; case _HEAPBADBEGIN: strcpy((str),"ERROR - heap is damaged\n"); @@ -454,7 +504,7 @@ void heapstat0(int heap_status) break; case _HEAPEMPTY: //printf("OK - heap is empty\n"); - + break; case _HEAPBADBEGIN: printf("ERROR - heap is damaged\n"); @@ -466,7 +516,7 @@ void heapstat0(int heap_status) printf("ERROR - bad node in heap\n"); } } - +#endif /* ============================ =