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