g++ on the UnixPC (Actually a general SystemV bug + fix)

Ron Guilmette rfg at ics.uci.edu
Sun Dec 31 10:34:14 AEST 1989


In article <JEFFL.89Dec29225441 at berick.uucp> jeffl at berick.uucp writes:
>I am attempting to port g++ 1.36.1 to the UnixPC.  I have gotten
>it to compile, but when I feed it the following source, it gives
>me error messages.  (The same version of g++ running on a sun
>gives the correct results.)
>
>
>	class x {
>		public:
>			x() {}
>			~x() {}
>	};
>
>	int main(int argc, char *argv[])
>	{	
>		x y;
>
>		return(0);
>	}
>
>When I run g++, I get the following results:
>
>berick!jeffl(users) 141> g++ -v testit.cc
>gcc version 1.36.1- (based on GCC 1.36)
> /usr/local/lib/gcc-cpp -+ -v -undef -D__GNUC__ -D__GNUG__ -D__cplusplus -Dmc68k -Dunix -Dunixpc -D__mc68k__ -D__unix__ -D__unixpc__ testit.cc /usr/tmp/cca13036.cpp
>GNU CPP version 1.36
> /usr/local/lib/gcc-cc1plus /usr/tmp/cca13036.cpp -quiet -dumpbase testit.cc -version -o /usr/tmp/cca13036.s
>GNU C++ version 1.36.1- (based on GCC 1.36) (68k, SGS/AT&T unixpc syntax) compiled by GNU C version 1.36.
>default target switches:
>testit.cc: In method x::x ():
>testit.cc:4: parse error at null character
...

First let me point out that gnu.g++ is *not* the right place to be posting
bug reports!  Please post bug reports (or questions about possible bugs)
to gnu.g++.bug instead.

Now on to your problem.

There is a general problem with SystemV-based systems which tends to
result in error messages of the form `parse error at null character'.
The problem is that the standard SystemV setvbuf() routine is brain-
dammaged.  This *only* causes problems when the compiler is attempting
to inline-expand very small function bodies (such as the constructor
for class x shown above, which is being quietly inlined at the point at
which the object `y' is declared).

I have tried to fix-up the code in cplus-lex.c in a general way that should
prevent this problem from arising on most types of SystemV-based systems.
The following patches implement my fixes for a hacked-up version of g++
1.36.1.  (Your line numbers may vary).

I hope that these patches will be incorporated into g++ 1.36.2.  This is
fairly important because right now, g++ is broken for most SystemV's.
Somebody should check however to see that I didn't break the code for
hp9000's (which appear to be a special case).

Thanks to Andrew Klossner @ Tektronix for pointing out the brain-dammage
in setvbuf() on USG.  Comments in the patches describe the nature of the
brain-dammage in more detail.

Enjoy,

// rfg

diff -rc2 1.36.1-/cplus-lex.c 1.36.1+/cplus-lex.c
*** 1.36.1-/cplus-lex.c	Thu Nov  2 23:14:34 1989
--- 1.36.1+/cplus-lex.c	Fri Nov 24 17:53:57 1989
***************
*** 980,1000 ****
        pending_inlines = pending_inlines->next;
        finput = finput2;
! #if defined(i386) && !defined(sequent) && !defined(sun386)
!       finput2->_ptr = finput2->_base = t->buf;
!       _bufend(finput2) = t->buf + t->len;
!       finput2->_flag = _IOFBF | _IOREAD;
!       finput2->_cnt = t->len - 1;
! #else
! #ifndef hp9000s300
! #ifdef USG_STDIO
        setvbuf(finput2,t->buf,_IOFBF,t->len);
        finput2->_cnt = t->len-1;
  #else
        setbuffer (finput2, t->buf, t->len);
        finput2->_cnt = finput2->_bufsiz - 1;
- #endif				/* USG_STDIO */
- #else
-       setvbuf(finput2,t->buf,_IOFBF,t->len);
-       finput2->_cnt = t->len-1;
  #endif
  #endif
--- 980,1003 ----
        pending_inlines = pending_inlines->next;
        finput = finput2;
! 
! #if defined(hp9000s300)
!       /* The hp9000 has a working setvbuf() routine.  */
        setvbuf(finput2,t->buf,_IOFBF,t->len);
        finput2->_cnt = t->len-1;
  #else
+ #if defined(USG) || defined(DGUX)
+       /* The standard SystemV code has a broken version of the setvbuf()
+          routine.  IF you try to setvbuf to a buffer which is shorter
+          than 8 bytes, then the standard USG setvbuf() will ignore the
+          request and malloc its own buffer.  This totally screws up things
+          for g++, so don't use setvbuf() on USG systems.  */
+       finput2->_ptr = finput2->_base = (unsigned char *) t->buf;
+       _bufend(finput2) = (unsigned char *) t->buf + t->len;
+       finput2->_flag = _IOFBF | _IOREAD;
+       finput2->_cnt = t->len - 1;
+ #else
+       /* Typical BSD systems can use setbuffer.  */
        setbuffer (finput2, t->buf, t->len);
        finput2->_cnt = finput2->_bufsiz - 1;
  #endif
  #endif
***************
*** 2078,2098 ****
  		 end of this function.  */
  	      pending_inlines = pending_inlines->next;
! #if defined(i386) && !defined(sequent) && !defined(sun386)
! 	      finput2->_ptr = finput2->_base = t->buf;
! 	      _bufend(finput2) = t->buf + t->len;
! 	      finput2->_flag = _IOFBF | _IOREAD;
! 	      finput2->_cnt = t->len - 1;
! #else
! #ifndef hp9000s300
! #ifdef USG_STDIO
        	      setvbuf(finput2,t->buf,_IOFBF,t->len);
         	      finput2->_cnt = t->len-1;
  #else
    	      setbuffer (finput2, t->buf, t->len);
    	      finput2->_cnt = finput2->_bufsiz - 1;
- #endif				/* USG_STDIO */
- #else
-       	      setvbuf(finput2,t->buf,_IOFBF,t->len);
-        	      finput2->_cnt = t->len-1;
  #endif
  #endif
--- 2081,2100 ----
  		 end of this function.  */
  	      pending_inlines = pending_inlines->next;
! #if defined(hp9000s300)
!               /* The hp900s300 has a working setvbuf() routine.  */
        	      setvbuf(finput2,t->buf,_IOFBF,t->len);
         	      finput2->_cnt = t->len-1;
  #else
+ #if defined(USG) || defined (DGUX)
+               /* The standard USG setvbuf() routine screws up if the buffer
+                  you give it is smaller that 8 bytes, so don't use it.  */
+ 	      finput2->_ptr = finput2->_base = (unsigned char *) t->buf;
+ 	      _bufend(finput2) = (unsigned char *) t->buf + t->len;
+ 	      finput2->_flag = _IOFBF | _IOREAD;
+ 	      finput2->_cnt = t->len - 1;
+ #else
+               /* The typical BSD system can use setbuffer */
    	      setbuffer (finput2, t->buf, t->len);
    	      finput2->_cnt = finput2->_bufsiz - 1;
  #endif
  #endif



More information about the Comp.sys.att mailing list