private dump_all_mallinks(void), dump_free_list(int i);
private dump_mallink(const char *s, mallink *ml), print_loop(mallink *ml);
private working_on(mallink *ml);
-private unsigned int checksum(mallink *ml);
+private size_type checksum(mallink *ml);
static FILE *malout;
private mallink *free_list_entry(int i);
}
fprintf(malout, " p_s: %p;", prev_size_of(ml));
fprintf(malout, " t_s: %p;", _this_size_of(ml));
- fprintf(malout, " sz: %p;", size_of(ml));
+ fprintf(malout, " sz: %lu;", (unsigned long) size_of(ml));
fprintf(malout, " fr: %d;", free_of(ml));
fprintf(malout, "\n");
}
private
check_mallinks(const char *s) {
mallink *ml;
- unsigned int size;
+ size_type size;
int i;
char stat;
Error("size of ml_last == 0, at %p", s, ml_last);
}
-private unsigned int
+private size_type
checksum(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;
}
private int
Error(const char *fmt, const char *s, mallink *ml) {
+ static int already_called = 0;
+
+ if (already_called++) return 0;
setbuf(stdout, (char *) 0);
printf("%s: ", s);
printf(fmt, (long)ml);
union _inf {
union _inf *ptr;
- unsigned int ui;
+ size_type ui;
};
typedef union _inf mallink;
#define N_WORDS 7
#endif /* CHECK */
-#define mallink_size() (unsigned int) \
+#define mallink_size() (size_t) \
align((N_WORDS - OFF_SET) * sizeof (mallink))
#ifdef CHECK
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));
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 {
SBRK((int) (align((size_type) p) - (size_type) p));
}
- p = SBRK((int)req);
- assert((size_type)p == align((size_type)p));
+ /* 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
#endif /* STORE */
}
else {
+ assert((size_type)p == align((size_type)p));
ml = create_chunk(p, req);
}
check_mallinks("suitable_chunk, extended");
realloc(void *addr, register size_t n)
{check_mallinks("realloc entry");{
register mallink *ml, *ph_next;
- register size_t size;
+ register size_type size;
if (addr == NULL) {
/* Behave like most Unix realloc's when handed a
#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() \
*/
#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) \