LCS-XS

 view release on metacpan or  search on metacpan

mba/suba.c  view on Meta::CPAN

int
suba_print_cell(struct allocator *suba, const char *msg, struct cell *c)
{
	ref_t ref = suba_ref(suba, c);
	if (ref >= ALIGNM(sizeof *suba) && (ref + POFF + c->size) <= 10000000) {
		//fprintf(stderr, "%s: %8u-%-8lu %8u %-8u\n", msg, ref, ref + POFF + c->size, c->size, c->next);
	} else {
		//fprintf(stderr, "%s: %8u-err %8u %-8u\n", msg, ref, c->size, c->next);
		return 0;
	}
	return 1;
}
/*
int
suba_print_alloc_list(struct allocator *suba, FILE *stream)
{
	struct cell *c, *tail = SADR(suba, suba->tail);

	c = (struct cell *)((char *)suba + ALIGNM(sizeof *suba));
	while (c < tail) {
		if (c->stk[0]) {
			unsigned char buf[1024], *blim = buf + 1024;
			unsigned char msg[16];
			sprintf((char *)msg, "%d", c->size);
			dbug_sprint_stacktrace(buf, blim, c->stk, 4, msg);
			fputs((const char *)buf, stream);
			fflush(stream);
		}
		c = (struct cell *)((char *)c + POFF + c->size);
	}

	return 0;
}
*/
int
suba_print_free_list(struct allocator *suba)
{
	struct cell *c;
	char buf[10];
	int count = 0;
	int ret = 1;

	c = suba_addr(suba, suba->tail);
	while (c->next < suba->tail) {
		if (c->next < POFF) {
			PMNF(errno = EINVAL, ": next ref corrupted: %d", c->next);
			return -1;
		}
		c = suba_addr(suba, c->next);
		sprintf(buf, "%d", count++);
		if (!suba_print_cell(suba, buf, c)) {
			ret = 0;
		}
	}
	c = suba_addr(suba, c->next);
	sprintf(buf, "%d", count++);
	if (!suba_print_cell(suba, buf, c)) {
		ret = 0;
	}

	//fprintf(stderr, "count: start-end         size next\n");

	return ret;
}

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 0.353 second using v1.00-cache-2.02-grep-82fe00e-cpan-9e6bc14194b )