home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / unix / sys5 / r3 / 78 < prev    next >
Encoding:
Internet Message Format  |  1992-11-08  |  2.6 KB

  1. Xref: sparky comp.unix.sys5.r3:78 comp.sys.sun.misc:5135 comp.editors:2688 comp.lang.c:16112
  2. Newsgroups: comp.unix.sys5.r3,comp.sys.sun.misc,comp.editors,comp.lang.c
  3. Path: sparky!uunet!charon.amdahl.com!pacbell.com!ames!saimiri.primate.wisc.edu!zaphod.mps.ohio-state.edu!cs.utexas.edu!wotan.compaq.com!moxie!sugar!ficc!peter
  4. From: peter@ferranti.com (peter da silva)
  5. Subject: compiling SAM with non-ANSI compilers
  6. Message-ID: <id.N1RU.TAB@ferranti.com>
  7. Followup-To: comp.unix.sys5.r3,comp.sys.sun.misc
  8. Organization: Xenix Support, FICC
  9. Date: Fri, 6 Nov 1992 17:06:50 GMT
  10. Lines: 90
  11.  
  12. [If you change the followups, please leave one of the groups I've got followups
  13.  to in the Newsgroups line, as I don't follow the other groups]
  14.  
  15. OK, I've got SAM, but it's for ANSI compilers only. My System V.3.2 and
  16. Sun 4.x systems only have K&R compilers. I can get it all to compile
  17. pretty cleanly with "unproto", but I get a weird memory allocation
  18. failure in erealloc. It looks like this:
  19.  
  20.     void *erealloc(void *p, unsigned long n)
  21.     {
  22.         p = realloc(p, n);
  23.         if(!p)
  24.             fatal error code
  25.         return p
  26.     }
  27.  
  28. It barfed when the regular expression code was compiling a character
  29. class. The character class code calls erealloc() with a null pointer.
  30. No problem, just create srealloc that special-cases the null pointer:
  31.  
  32.     void *srealloc(void *p, unsigned long n)
  33.     {
  34.         if(p)
  35.             p = realloc(p, n);
  36.         else
  37.             p = malloc(n);
  38.         return p;
  39.     }
  40.  
  41. Now erealloc is failing on the call to srealloc(), but the stack trace
  42. says it's in free(). I can't figure out what's going on here. I'm using
  43. a compiler with 32 bit ints and the standard promotion rules, so I can't
  44. imagine that it's stack bashing.
  45.  
  46. Is anyone else so demented as to try this? Has anyone had better success?
  47.  
  48. For reference, the "ansi cc" I'm using looks like this:
  49.  
  50. :
  51. SAMDIR=/usr1/xds/src/sam
  52. BIN=$SAMDIR/bin
  53.  
  54. ECHO=:
  55. CPPARGS="-E"
  56. for i
  57. do
  58.   case $i in
  59.     -I*|-D*) CPPARGS="$CPPARGS $i";;
  60.     -v) ECHO=echo
  61.   esac
  62. done
  63.  
  64. ARGS=
  65. MV=
  66. for i
  67. do
  68.   case $i in
  69.     -I*|-D*) ;;
  70.     *.c)
  71.       $ECHO "- /lib/cpp $CPPARGS $i"
  72.       if /lib/cpp $CPPARGS $i |
  73.     $BIN/unproto > _$i
  74.       then
  75.         ARGS="$ARGS _$i"
  76.         o="`echo $i | sed 's/\.c$/.o/'`"
  77.         MV="$MV mv _$o $o;"
  78.       else exit 2
  79.       fi
  80.       ;;
  81.     *)
  82.       ARGS="$ARGS $i"
  83.       ;;
  84.   esac
  85. done
  86. $ECHO - cc $ARGS
  87. if cc $ARGS
  88. then
  89.   if [ "$MV" ]
  90.   then
  91.     $ECHO "-$MV"
  92.     eval $MV
  93.   else true
  94.   fi
  95. else false
  96. fi
  97. -- 
  98. % Peter da Silva % 77487-5012 % +1 713 274 5180 %
  99. true(<<VV$@\\$'&O 9$O%'$LT$&$"V6"$&$<4$?'&$ #I&&?$=$<<@)24 24 scale 3 21 moveto
  100. {dup 36 eq{pop not}{dup 7 and 4 sub exch 56 and 8 div 4 sub 2 index{rlineto}{
  101. rmoveto}ifelse}ifelse}forall stroke pop showpage % Har du kramat din varg idag?
  102.