Article View: comp.sys.amiga.tech
Article #2835Re: realloc() missing from Manx c.lib ?
From: Andrew Heybey
Date: Fri, 19 Jan 1990 14:11
Date: Fri, 19 Jan 1990 14:11
95 lines
4343 bytes
4343 bytes
Realloc is indeed missing, at least from the earlier versions of Manx.
Here is a fairly old posting that contains the source to realloc().
As mentioned in the post, it is also available from Manx's bulletin
board.
UID: 8374
Path: bloom-beacon!husc6!linus!raybed2!rayssd!galaxia!amanpt1!mrr
From: mrr@amanpt1.UUCP (Mark Rinfret)
Newsgroups: comp.sys.amiga
Subject: Aztec realloc() for 3.4b
Date: 22 Jan 88 18:56:18 GMT
Organization: Aquidneck Management Associates
Lines: 84
[Note: I made an error in the example portion of a previous posting.
Hopefully, I cancelled that message and you'll only see this one.
If you did get the first posting, please discard it and save this
one. Realloc() must be positioned BEFORE movmem in order for
dependencies to be resolved correctly. ]
I just "rediscovered" that realloc() was missing from my Aztec libraries
(3.4b) when I tried to compile and link the "subst" (substitute strings)
program posted recently to comp.misc.sources. I guess, somewhere back in
my mental archives, there's a wisp of a memory of a discussion about that
problem, but, since it didn't affect me at the time, I didn't take the time
to make note of it. All that aside, I just got the missing function from the
Manx bulletin board and thought I'd post it for those who might need it.
I recommend putting it in your "lib" directory. Compile it for each
memory model that you use and add it to your existing libraries. The
following example installs realloc() before movmem() in c.lib and c32.lib:
cc realloc.c
lb c.lib -a movmem realloc.o
cc +L realloc.c
lb c32.lib -a movmem realloc.o
If you're working on floppy disks, be sure that there's enough room for
two copies of the library being modified (during the modification). LB
will delete the original and replace it with the new version if it is
successful.
/***********************************************************************
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 *movmem();
end = (char *)chain((l_t *)area-1);
if ((osize = ptrdiff(end, area)) > size) {
osize = size;
end = (char *)bump(area, osize);
}
free(area);
if ((cp = movmem(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;
}
/*EOF*/
--
< 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...">
--
Andrew Heybey, atheybey@ptt.lcs.mit.edu, uunet!ptt.lcs.mit.edu!atheybey
Technical Details
Message-ID:
<ATHEYBEY.90Jan19091152@allspice.lcs.mit.edu>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!yale!think!mintaka!mintaka.lcs.mit.edu!atheybeyReferences:
<1990Jan19.005944.5971@aucs.uucp> <19974@watdragon.waterloo.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!yale!think!mintaka!mintaka.lcs.mit.edu!atheybey From: atheybey@lcs.mit.edu (Andrew Heybey) Newsgroups: comp.sys.amiga.tech Subject: Re: realloc() missing from Manx c.lib ? Message-ID: <ATHEYBEY.90Jan19091152@allspice.lcs.mit.edu> Date: 19 Jan 90 14:11:52 GMT References: <1990Jan19.005944.5971@aucs.uucp> <19974@watdragon.waterloo.edu> Sender: news@mintaka.lcs.mit.edu Distribution: na Organization: MIT Laboratory for Computer Science Lines: 95 In-Reply-To: tdesjardins@lion.waterloo.edu's message of 19 Jan 90 08:16:18 GMT