Thread View: comp.unix.sys5.r3
2 messages
2 total messages
Started by peter da silva
Fri, 06 Nov 1992 17:06
compiling SAM with non-ANSI compilers
Author: peter da silva
Date: Fri, 06 Nov 1992 17:06
Date: Fri, 06 Nov 1992 17:06
90 lines
2703 bytes
2703 bytes
[If you change the followups, please leave one of the groups I've got followups
to in the Newsgroups line, as I don't follow the other groups]
OK, I've got SAM, but it's for ANSI compilers only. My System V.3.2 and
Sun 4.x systems only have K&R compilers. I can get it all to compile
pretty cleanly with "unproto", but I get a weird memory allocation
failure in erealloc. It looks like this:
void *erealloc(void *p, unsigned long n)
{
p = realloc(p, n);
if(!p)
fatal error code
return p
}
It barfed when the regular expression code was compiling a character
class. The character class code calls erealloc() with a null pointer.
No problem, just create srealloc that special-cases the null pointer:
void *srealloc(void *p, unsigned long n)
{
if(p)
p = realloc(p, n);
else
p = malloc(n);
return p;
}
Now erealloc is failing on the call to srealloc(), but the stack trace
says it's in free(). I can't figure out what's going on here. I'm using
a compiler with 32 bit ints and the standard promotion rules, so I can't
imagine that it's stack bashing.
Is anyone else so demented as to try this? Has anyone had better success?
For reference, the "ansi cc" I'm using looks like this:
:
SAMDIR=/usr1/xds/src/sam
BIN=$SAMDIR/bin
ECHO=:
CPPARGS="-E"
for i
do
case $i in
-I*|-D*) CPPARGS="$CPPARGS $i";;
-v) ECHO=echo
esac
done
ARGS=
MV=
for i
do
case $i in
-I*|-D*) ;;
*.c)
$ECHO "- /lib/cpp $CPPARGS $i"
if /lib/cpp $CPPARGS $i |
$BIN/unproto > _$i
then
ARGS="$ARGS _$i"
o="`echo $i | sed 's/\.c$/.o/'`"
MV="$MV mv _$o $o;"
else exit 2
fi
;;
*)
ARGS="$ARGS $i"
;;
esac
done
$ECHO - cc $ARGS
if cc $ARGS
then
if [ "$MV" ]
then
$ECHO "-$MV"
eval $MV
else true
fi
else false
fi
--
% Peter da Silva % 77487-5012 % +1 713 274 5180 %
true(<<VV$@\\$'&O 9$O%'$LT$&$"V6"$&$<4$?'&$ #I&&?$=$<<@)24 24 scale 3 21 moveto
{dup 36 eq{pop not}{dup 7 and 4 sub exch 56 and 8 div 4 sub 2 index{rlineto}{
rmoveto}ifelse}ifelse}forall stroke pop showpage % Har du kramat din varg idag?
Re: compiling SAM with non-ANSI compilers
Author: Alex Martelli
Date: Tue, 10 Nov 1992 07:29
Date: Tue, 10 Nov 1992 07:29
30 lines
2069 bytes
2069 bytes
peter@ferranti.com (peter da silva) writes: ... :OK, I've got SAM, but it's for ANSI compilers only. My System V.3.2 and :Sun 4.x systems only have K&R compilers. I can get it all to compile :pretty cleanly with "unproto", but I get a weird memory allocation :failure in erealloc. It looks like this: ... :Now erealloc is failing on the call to srealloc(), but the stack trace :says it's in free(). I can't figure out what's going on here. I'm using :a compiler with 32 bit ints and the standard promotion rules, so I can't :imagine that it's stack bashing. : :Is anyone else so demented as to try this? Has anyone had better success? My suggestion: get Conor Cahill's precious "dbmalloc" package and compile and link your code with that. It will help *mightily* in diagnosing whatever it is that it's happening to clobber your memory allocation! Some pointer is probably being freed twice, or overwritten accidentally with garbage from elsewhere, and dbmalloc will point it out fast. (It might be even better to use the commercial enhanced version of dbmalloc, "sentinel" - I haven't tried that yet, but it should have advantahes - however, that costs some $$$ - I think $195 for 386 Unix and $395 for Sun - so since you're working on a free program I assume you may not want to invest in that). dbmalloc has appeared in comp.sources.? in the recent past, so it should be VERY widely available, from any site that archives that. -- Email: martelli@cadlab.sublink.org Phone: ++39 (51) 6130360 CAD.LAB s.p.a., v. Ronzani 7/29, Casalecchio, Italia Fax: ++39 (51) 6130294
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads