Several fixes
authorceriel <none@none>
Thu, 1 Nov 1990 09:33:51 +0000 (09:33 +0000)
committerceriel <none@none>
Thu, 1 Nov 1990 09:33:51 +0000 (09:33 +0000)
modules/src/malloc/check.c
modules/src/malloc/impl.h
modules/src/malloc/log.c
modules/src/malloc/mal.c
modules/src/malloc/phys.h

index 1611b08..c77d016 100644 (file)
@@ -15,7 +15,7 @@
 private acquire_malout(), check_ml_last();
 private dump_all_mallinks(), dump_free_list(), dump_mallink(), print_loop();
 private working_on();
-private unsigned int checksum();
+private size_type checksum();
 static FILE *malout;
 
 public mallink *free_list_entry();
@@ -91,7 +91,7 @@ dump_free_list(i)     {
        for_free_list(i, ml)    {
                if (print_loop(ml))
                        return;
-               fprintf(malout, "%ld ", ml);
+               fprintf(malout, "%ld ", (long) ml);
        }
        fprintf(malout, "<\n");
 }
@@ -148,7 +148,7 @@ dump_mallink(s, ml) char *s; mallink *ml;   {
 public
 check_mallinks(s) char *s;     {
        mallink *ml;
-       unsigned int size;
+       size_type size;
        int i;
        char stat;
        
@@ -218,16 +218,16 @@ check_ml_last(s) char *s; {
                Error("size of ml_last == 0, at %ld", s, ml_last);
 }
 
-private unsigned int
+private size_type
 checksum(ml) mallink *ml;      {
-       unsigned int sum = 0;
+       size_type sum = 0;
        
        if (free_of(ml))        {
-               sum += (unsigned int)_log_prev_of(ml);
-               sum += (unsigned int)_log_next_of(ml);
+               sum += (size_type)_log_prev_of(ml);
+               sum += (size_type)_log_next_of(ml);
        }
-       sum += (unsigned int)prev_size_of(ml);
-       sum += (unsigned int)_this_size_of(ml);
+       sum += (size_type)prev_size_of(ml);
+       sum += (size_type)_this_size_of(ml);
        return sum;
 }
 
@@ -287,6 +287,9 @@ check_work_empty(s) char *s;        {
 
 public int
 Error(fmt, s, ml) char *fmt, *s; mallink *ml;  {
+       static int already_called = 0;
+
+       if (already_called++) return 0;
        setbuf(stdout, (char *) 0);
        printf("%s: ", s);
        printf(fmt, (long)ml);
index 6276239..b0d96ef 100644 (file)
@@ -28,7 +28,7 @@ ALIGNMENT must be a dividor of MIN_SIZE
 
 union _inf {
        union _inf *ptr;
-       unsigned int ui;
+       size_type ui;
 };
 
 typedef union _inf mallink;
index f8dee7d..7af6e63 100644 (file)
@@ -22,7 +22,7 @@ link_free_chunk(ml)
                chain.
        */
        register mallink **mlp = &free_list[-1];
-       register unsigned int n = size_of(ml);
+       register size_type n = size_of(ml);
        register mallink *ml1;
 
        assert(n < (1L << LOG_MAX_SIZE));
@@ -59,7 +59,7 @@ unlink_free_chunk(ml)
        if (!prev)      {
                /* it is the first in the chain */
                register mallink **mlp = &free_list[-1];
-               register unsigned int n = size_of(ml);
+               register size_type n = size_of(ml);
 
                assert(n < (1L << LOG_MAX_SIZE));
                do {
index 568d69e..8ffbfa1 100644 (file)
@@ -96,10 +96,16 @@ malloc(n)
                        SBRK((int) (align((size_type) p) - (size_type) p));
                }
 
-               p = SBRK((int)req);
+               /* SBRK takes an int; sorry ... */
+               if ((int) req < 0) {
+                       p = ILL_BREAK;
+               }
+               else {
+                       p = SBRK((int)req);
+               }
                if (p == ILL_BREAK) {
                        req = n + mallink_size();
-                       p = SBRK((int)req);
+                       if ((int) req >= 0) p = SBRK((int)req);
                }
                if (p == ILL_BREAK)     {
                        /*      Now this is bad.  The system will not give us
@@ -238,7 +244,7 @@ realloc(addr, n)
        register unsigned int n;
 {check_mallinks("realloc entry");{
        register mallink *ml, *ph_next;
-       register unsigned int size;
+       register size_type size;
 
        if (addr == 0) {
                /*      Behave like most Unix realloc's when handed a
index e5dc277..82e5e61 100644 (file)
@@ -16,9 +16,9 @@ publicdata mallink *ml_last;
 #define BITS                   (FREE_BIT)
 #endif
 
-#define __bits(ml)             ((size_type)_phys_prev_of(ml) & BITS)
-#define        __free_of(ml)           ((size_type)_phys_prev_of(ml) & FREE_BIT)
-#define __phys_prev_of(ml)     (mallink *)((size_type)_phys_prev_of(ml) & ~BITS)
+#define __bits(ml)             ((int)((size_type)_phys_prev_of(ml) & BITS))
+#define        __free_of(ml)           ((int)((size_type)_phys_prev_of(ml) & FREE_BIT))
+#define __phys_prev_of(ml)     ((mallink *)((size_type)_phys_prev_of(ml) & ~BITS))
 #define prev_size_of(ml)       ((char *)(ml) - \
                                 (char *)__phys_prev_of(ml) - \
                                 mallink_size() \
@@ -49,7 +49,7 @@ public Error();
 */
 #define size_of(ml)            (_this_size_of(ml) - mallink_size())
 #define        set_phys_next(ml,e) \
-       (_this_size_of(ml) = (unsigned int)((char *)(e) - (char *)(ml)))
+       (_this_size_of(ml) = (size_type)((char *)(e) - (char *)(ml)))
 #define        phys_next_of(ml)        (mallink *) ((char *)(ml) + _this_size_of(ml))
 
 #define        set_free(ml,e) \