[comp.sys.amiga] where the hell is realloc on Manx?

mike@ames.arpa (Mike Smithwick) (05/04/88)

[only my line eater knows for sure]

Ok, I give up, where the hell is realloc in Manx (3.4, 3.6, etc.). It 
taint' in the library, it taint' in the lib source, it tis' is the manual.

What gives?



-- 
			   *** mike (Cyberpunk in training) smithwick ***
"Use an Atari, go to jail!"
[disclaimer : nope, I don't work for NASA, I take full blame for my ideas]

giao@infmx.UUCP (Giao TienVu) (05/04/88)

In article <8234@ames.arpa>, mike@ames.arpa (Mike Smithwick) writes:
> Ok, I give up, where the hell is realloc in Manx (3.4, 3.6, etc.). It 
> taint' in the library, it taint' in the lib source, it tis' is the manual.
> 

realloc() is in the file heapmem.o distributed in lib.  However,
small model realloc() is broken because of an argument was passed as long
instead of int to movmem() in the function.  Therefore, chances are high
that you'll lose the content of the reallocated buffer.  I tried a patch
and things appear to work fine.

giao

mrr@amanpt1.zone1.com (Mark Rinfret) (05/05/88)

In article <8234@ames.arpa>, mike@ames.arpa (Mike Smithwick) writes:
> [only my line eater knows for sure]
> 
> Ok, I give up, where the hell is realloc in Manx (3.4, 3.6, etc.). It 
> taint' in the library, it taint' in the lib source, it tis' is the manual.
> 
> What gives?
> 
It was omitted (as part of a test, I'm sure :-).  I picked up the source
from the Manx BBS some time ago.  You can compile it and either explicity
include realloc.o in your link or add it to your object libraries.  If you
add it to the library, you're going to have to make sure it gets placed
in the right position or its dependents won't be happy.  I've forgotten
exactly where I inserted it, but If you list the library and add it after
all of the other memory allocation stuff (malloc, calloc, etc.) I think
you'll be safe.

By the way...I've moved up to 3.6a with SDB.  SDB is terrific and well
worth the price (or more!).  


/***********************************************************************
The following is the source code for realloc.  Compile it with the
appropriate memory model options, and insert in the c libraries.
***********************************************************************/
/* Copyright (C) 1987 by Manx Software Systems, Inc. */
unsigned long _Heapsize = 40 * 1024L;
typedef long size_t;
#define bump(p,i) ((l_t *)((char *)(p)+(i)))
#define ptrdiff(p1,p2) (unsigned long)((char *)(p1)-(char *)(p2))
typedef struct list {
	struct list *next;
} l_t;
static l_t first, *current;
static l_t *endmarker = &first, *restart = &first;
static size_t keep;
#define INUSE	1
#define inuse(p) (*(size_t *)(p)&INUSE)
#define markblk(p) (*(size_t *)(p) |= INUSE)
#define unmark(p) (*(size_t *)(p) &= ~INUSE)
#define chain(p)	((l_t *)(*(size_t *)(p) & ~INUSE))
#define BLOCK	(512*sizeof(l_t))	/* # of bytes to ask sbrk for */
char *
realloc(area, size)
register char *area; unsigned size;
{
	register char *cp, *end;
	size_t osize;
	char *malloc();
	end = (char *)chain((l_t *)area-1);
	if ((osize = ptrdiff(end, area)) > size) {
		osize = size;
		end = (char *)bump(area, osize);
	}
	free(area);
	if ((cp = malloc(size)) != 0 && cp != area) {
		movmem(area, cp, osize);
		if ((char *)current >= area && (char *)current < end)
			*(size_t *)bump(cp, ptrdiff(current,area)) = keep;
	}
	return cp;
}
/* Th-th-th-that's all, folks! */
-- 
< Mark R. Rinfret,  mrr@amanpt1.ZONE1.COM | ...rayssd!galaxia!amanpt1!mrr    >
< Aquidneck Management Associates       Home: 401-846-7639                   >
< 6 John Clarke Road                    Work: 401-849-8900 x56               >
< Middletown, RI 02840          	"If I just had a little more time...">