]> 4ch.mooo.com Git - 16.git/blobdiff - src/lib/16_hc.c
the near malloc is messy!! wwww
[16.git] / src / lib / 16_hc.c
index af747fc470b3a7f8122b2fc557a6dadb92e6600c..a904560abae3e5c8f15dd9c056c80a2d81057463 100644 (file)
 
 #include "src/lib/16_hc.h"
 
+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;
@@ -66,7 +103,12 @@ size_t _coreleft(void)
                if (largest < sizeof(void __near*))
                {
                        if (p != NULL)
+#ifdef __BORLANDC__
+                       free(p);
+#endif
+#ifdef __WATCOMC__
                        _nfree(p);
+#endif
                        break;
                }
                *(void __near* __near*)p = NULL;
@@ -82,7 +124,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;
@@ -151,6 +198,7 @@ size_t _farcoreleft(void)
        return total;
 }
 
+#ifdef __WATCOMC__
 void huge* LargestHugeFreeBlock(size_t* Size)
 {
        size_t s0, s1;
@@ -358,15 +406,14 @@ void heapdump(void)
        for(;;) {
                heap_status = _heapwalk( &h_info );
                if( heap_status != _HEAPOK ) break;
-
-               strcpy(scratch,"  "); strcat(scratch,(h_info._useflag == _USEDENTRY ? "USED" : "FREE")); strcat(scratch," block at "); ultoa((dword)h_info._pentry,str,16); strcat(scratch,str); strcat(scratch," of size "); ultoa(h_info._size,str,16); strcat(scratch,str); strcat(scratch,"\n");
+               strcpy(scratch,"  "); strcat(scratch,(h_info._useflag == _USEDENTRY ? "USED" : "FREE")); strcat(scratch," block at "); ultoa((dword)h_info._pentry,str,16); strcat(scratch,str); strcat(scratch," of size "); ultoa(h_info._size,str,10); strcat(scratch,str); strcat(scratch,"\n");
                if((h_info._useflag == _USEDENTRY ? "USED" : "FREE")=="FREE") h_free += h_info._size;
                if((h_info._useflag == _USEDENTRY ? "USED" : "FREE")=="USED") h_used += h_info._size;
                h_total += h_info._size;
                write(heaphandle,scratch,strlen(scratch));
        }
        heapstat(heap_status, &scratch);
-       
+
        //near
        strcpy(scratch,"\n      == near ==\n\n");
        write(heaphandle,scratch,strlen(scratch));
@@ -375,8 +422,7 @@ void heapdump(void)
        for(;;) {
                heap_status = _nheapwalk( &nh_info );
                if( heap_status != _HEAPOK ) break;
-               
-               strcpy(scratch,"  "); strcat(scratch,(h_info._useflag == _USEDENTRY ? "USED" : "FREE")); strcat(scratch," block at "); ultoa((dword)h_info._pentry,str,16); strcat(scratch,str); strcat(scratch," of size "); ultoa(h_info._size,str,16); strcat(scratch,str); strcat(scratch,"\n");
+               strcpy(scratch,"  "); strcat(scratch,(h_info._useflag == _USEDENTRY ? "USED" : "FREE")); strcat(scratch," block at "); ultoa((dword)h_info._pentry,str,16); strcat(scratch,str); strcat(scratch," of size "); ultoa(h_info._size,str,10); strcat(scratch,str); strcat(scratch,"\n");
 /*             printf( "  %s block at %Fp of size %4.4X\n",
 (nh_info._useflag == _USEDENTRY ? "USED" : "FREE"),
 nh_info._pentry, nh_info._size );*/
@@ -395,8 +441,7 @@ nh_info._pentry, nh_info._size );*/
        for(;;) {
                heap_status = _fheapwalk( &fh_info );
                if( heap_status != _HEAPOK ) break;
-
-               strcpy(scratch,"  "); strcat(scratch,(h_info._useflag == _USEDENTRY ? "USED" : "FREE")); strcat(scratch," block at "); ultoa((dword)h_info._pentry,str,16); strcat(scratch,str); strcat(scratch," of size "); ultoa(h_info._size,str,16); strcat(scratch,str); strcat(scratch,"\n");
+               strcpy(scratch,"  "); strcat(scratch,(h_info._useflag == _USEDENTRY ? "USED" : "FREE")); strcat(scratch," block at "); ultoa((dword)h_info._pentry,str,16); strcat(scratch,str); strcat(scratch," of size "); ultoa(h_info._size,str,10); strcat(scratch,str); strcat(scratch,"\n");
                /*printf( "  %s block at %Fp of size %4.4X\n",
 (fh_info._useflag == _USEDENTRY ? "USED" : "FREE"),
 fh_info._pentry, fh_info._size );*/
@@ -433,7 +478,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");
@@ -455,7 +500,7 @@ void heapstat0(int heap_status)
                break;
                case _HEAPEMPTY:
                        //printf("OK - heap is empty\n");
-                       
+
                break;
                case _HEAPBADBEGIN:
                        printf("ERROR - heap is damaged\n");
@@ -467,7 +512,7 @@ void heapstat0(int heap_status)
                        printf("ERROR - bad node in heap\n");
        }
 }
-
+#endif
 /*
 ============================
 =