home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / gnu / g / bug / 2096 < prev    next >
Encoding:
Text File  |  1992-12-30  |  12.8 KB  |  368 lines

  1. Newsgroups: gnu.g++.bug
  2. Path: sparky!uunet!cis.ohio-state.edu!fubar.UUCP!dap
  3. From: dap@fubar.UUCP
  4. Subject: compiler goes recursive, eats up all stack space, then quits
  5. Message-ID: <9212291946.AA06956@fubar>
  6. Sender: gnulists@ai.mit.edu
  7. Organization: GNUs Not Usenet
  8. Distribution: gnu
  9. Date: Tue, 29 Dec 1992 07:46:46 GMT
  10. Approved: bug-g++@prep.ai.mit.edu
  11. Lines: 355
  12.  
  13. Using gcc 2.3.2 on a BSDI system, attempting to compile the
  14. uunet:networking/leffler/v2.0beta22*.Z(util/Path.c++) file.
  15. This is an extraction of the salient portions thereof.
  16. Please note that this bug report is copyrighted, and preserve the copyright
  17. notices :-)
  18.  
  19. =-= bug.list =-=
  20. cd /u/dap/
  21. /usr/local/bin/g++ -v -D__ANSI_CPP__ bug.cc
  22. Reading specs from /usr/local/lib/gcc-lib/i386-bsdi/2.3.2/specs
  23. gcc version 2.3.2
  24.  /usr/local/lib/gcc-lib/i386-bsdi/2.3.2/cpp -lang-c++ -v -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -Dunix -Di386 -D__bsdi__ -Dbsdi -DBSD_NET2 -D__unix__ -D__i386__ -D__bsdi__ -D__bsdi__ -D__BSD_NET2__ -D__unix -D__i386 -D__bsdi__ -D__bsdi -D__BSD_NET2 -D__ANSI_CPP__ bug.cc /var/tmp/cc009208.i
  25. GNU CPP version 2.3.2 (80386, BSD syntax)
  26.  /usr/local/lib/gcc-lib/i386-bsdi/2.3.2/cc1plus /var/tmp/cc009208.i -quiet -dumpbase bug.cc -version -o /var/tmp/cc009208.s
  27. GNU C++ version 2.3.2 (80386, BSD syntax) compiled by GNU C version 2.3.2.
  28. bug.cc:29: undefined or invalid # directive
  29. bug.cc: In method `void  fxObj::dec ()':
  30. bug.cc:55: warning: implicit declaration of function `fxAssert'
  31. bug.cc: In method `fxTempStr::operator int ()const ':
  32. bug.cc:102: warning: implicit declaration of function `atoi'
  33. bug.cc: In method `fxTempStr::operator float ()const ':
  34. bug.cc:103: warning: implicit declaration of function `atof'
  35. bug.cc: In method `int  Path::findFile (const class fxStr&, class fxStr&)':
  36. bug.cc:292: warning: implicit declaration of function `access'
  37. bug.cc:300: virtual memory exhausted
  38.  
  39. Compilation exited abnormally with code 1 at Tue Dec 29 12:40:48
  40. =-= bug.cc =-=
  41. /*
  42.  * Copyright (c) 1990, 1991, 1992 Sam Leffler
  43.  * Copyright (c) 1991, 1992 Silicon Graphics, Inc.
  44.  *
  45.  * Permission to use, copy, modify, distribute, and sell this software and 
  46.  * its documentation for any purpose is hereby granted without fee, provided
  47.  * that (i) the above copyright notices and this permission notice appear in
  48.  * all copies of the software and related documentation, and (ii) the names of
  49.  * Sam Leffler and Silicon Graphics may not be used in any advertising or
  50.  * publicity relating to the software without the specific, prior written
  51.  * permission of Sam Leffler and Silicon Graphics.
  52.  * 
  53.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
  54.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
  55.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  56.  * 
  57.  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  58.  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  59.  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  60.  * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
  61.  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
  62.  * OF THIS SOFTWARE.
  63.  */
  64.  
  65. typedef unsigned fxBool;
  66. #define FALSE    0
  67. #define TRUE    1
  68.  
  69. #incclude <stdlib>
  70. #include <sys/types.h>
  71.  
  72. // Reference counted objects.  Subclasses of this can use Ptr's.
  73.  
  74. class fxObj {
  75. public:
  76.     fxObj();
  77.     virtual ~fxObj();
  78. // Memory management
  79.     void inc();
  80.     void dec();
  81.     u_long getReferenceCount();
  82.  
  83. // Misc
  84.     virtual const char* className() const;
  85.     int compare(const fxObj *) const;
  86.     virtual void subClassMustDefine(const char* method) const;
  87. protected:
  88.     u_long    referenceCount;
  89. };
  90.  
  91. inline fxObj::fxObj()                { referenceCount = 0; }
  92. inline fxObj::~fxObj()                { }
  93. inline void fxObj::inc()            { ++referenceCount; }
  94. inline void fxObj::dec() {
  95.     fxAssert(referenceCount>0,"Bogus object reference count");
  96.     if (0 >= --referenceCount) delete this;
  97. }
  98. inline u_long fxObj::getReferenceCount()    { return referenceCount; }
  99.  
  100. // Temporary strings are generated by the concatenation operators.
  101. // They are designed to avoid calls to malloc, and as such are not
  102. // meant to be used directly.
  103. class fxStr;
  104.  
  105. class fxTempStr {
  106. public:
  107.     fxTempStr(fxTempStr const &other);
  108.     ~fxTempStr();
  109.  
  110.     // C++ uses these operators to perform the first concatenation
  111.     friend fxTempStr operator|(fxStr const&, fxStr const&);
  112.     friend fxTempStr operator|(fxStr const&, char const*);
  113.     friend fxTempStr operator|(char const*, fxStr const&);
  114.  
  115.     // Susequent concatenations use these operators.  These operators
  116.     // just append the argument data to the temporary, avoiding malloc
  117.     // when possible.
  118.     // XXX these aren't really const, although they are declared as such
  119.     // XXX to avoid warnings. In a land of very advanced compilers, this
  120.     // XXX strategy may backfire.
  121.     friend fxTempStr& operator|(const fxTempStr&, fxStr const& b);
  122.     friend fxTempStr& operator|(const fxTempStr&, char const* b);
  123.  
  124.     operator char*() const;
  125.     operator int() const;
  126.     operator float() const;
  127.     operator double() const;
  128.  
  129.     u_int length() const;
  130. protected:
  131.     char    indata[100];        // inline data, avoiding malloc
  132.     char*    data;            // points at indata or heap
  133.     u_int    slength;        // same rules as fxStr::slength
  134.  
  135.     friend class fxStr;
  136.  
  137.     fxTempStr(char const *, u_int, char const *, u_int);
  138.     fxTempStr& concat(char const* b, u_int bl);
  139. };
  140.  
  141. inline fxTempStr::operator char*() const    { return data; }
  142. inline fxTempStr::operator int() const        { return atoi(data); }
  143. inline fxTempStr::operator float() const    { return float(atof(data)); }
  144. inline fxTempStr::operator double() const    { return double(atof(data)); }
  145. inline u_int fxTempStr::length() const        { return slength - 1; }
  146.  
  147. //----------------------------------------------------------------------
  148.  
  149. class fxStr {
  150.     friend class fxTempStr;
  151. public:
  152.     fxStr(u_int l=0);
  153.     fxStr(char const *s);
  154.     fxStr(char const *s, u_int len);
  155.     fxStr(fxStr const&);
  156.     fxStr(int, char const* format);
  157.     fxStr(float, char const* format);
  158.     fxStr(double, char const* format);
  159.     fxStr(const fxTempStr&);
  160.     ~fxStr();
  161.  
  162.     /////////////////////////////////////////////////////
  163.     u_long hash() const;
  164.  
  165.     operator char*() const
  166.     { return data; }
  167.     operator int() const
  168.     { return atoi(data); }
  169.     operator float() const
  170.     { return float(atof(data)); }
  171.     operator double() const
  172.     { return double(atof(data)); }
  173.  
  174.     u_int length() const { return slength-1; }
  175.  
  176.     char& operator[](u_int i) const
  177.     {   fxAssert(i<slength-1,"Invalid Str[] index");
  178.     return data[i]; }
  179.  
  180.     void operator=(const fxTempStr& s);
  181.     void operator=(fxStr const& s);
  182.     void operator=(char const *s);
  183.  
  184.     /////////////////////////////////////////////////////
  185.     // Comparison
  186.     friend fxBool operator==(fxStr const&, fxStr const&);
  187.     friend fxBool operator==(fxStr const&, char const*);
  188.     friend fxBool operator==(char const*, fxStr const&);
  189.  
  190.     friend fxBool operator!=(fxStr const&, fxStr const&);
  191.     friend fxBool operator!=(fxStr const&, char const*);
  192.     friend fxBool operator!=(char const*, fxStr const&);
  193.  
  194.     friend fxBool operator>=(fxStr const&, fxStr const&);
  195.     friend fxBool operator>=(fxStr const&, char const*);
  196.     friend fxBool operator>=(char const*, fxStr const&);
  197.  
  198.     friend fxBool operator<=(fxStr const&, fxStr const&);
  199.     friend fxBool operator<=(fxStr const&, char const*);
  200.     friend fxBool operator<=(char const*, fxStr const&);
  201.  
  202.     friend fxBool operator>(fxStr const&, fxStr const&);
  203.     friend fxBool operator>(fxStr const&, char const*);
  204.     friend fxBool operator>(char const*, fxStr const&);
  205.  
  206.     friend fxBool operator<(fxStr const&, fxStr const&);
  207.     friend fxBool operator<(fxStr const&, char const*);
  208.     friend fxBool operator<(char const*, fxStr const&);
  209.  
  210.     int compare(fxStr const *a) const { return ::compare(*this, *a); }
  211.     friend int compare(fxStr const&, fxStr const&);
  212.     friend int compare(fxStr const&, char const*);
  213.     friend int compare(char const*, fxStr const&);
  214.  
  215.     /////////////////////////////////////////////////////
  216.     // Concatenation
  217.     friend fxTempStr& operator|(const fxTempStr&, fxStr const&);
  218.     friend fxTempStr& operator|(const fxTempStr&, char const*);
  219.  
  220.     friend fxTempStr operator|(fxStr const&, fxStr const&);
  221.     friend fxTempStr operator|(fxStr const&, char const*);
  222.     friend fxTempStr operator|(char const*, fxStr const&);
  223.  
  224.     /////////////////////////////////////////////////////
  225.     // Misc
  226.     fxStr copy() const;
  227.     fxStr extract(u_int start,u_int len) const;
  228.     fxStr cut(u_int start,u_int len);
  229.     fxStr head(u_int) const;
  230.     fxStr tail(u_int) const;
  231.     void lower();
  232.     void raise();
  233.  
  234.     void remove(u_int posn,u_int len=1);
  235.  
  236.     void resize(u_int len, fxBool reallocate = FALSE);
  237.     void setMaxLength(u_int maxlen);
  238.  
  239.     void append(char a);
  240.     void append(char const *s, u_int len=0);
  241.     void append(const fxTempStr& s)
  242.     { append((char*)s, s.slength-1); }
  243.     void append(fxStr const& s)
  244.     { append((char*)s, s.slength-1); }
  245.  
  246.     void insert(char a, u_int posn=0);
  247.     void insert(char const *, u_int posn=0, u_int len=0);
  248.     void insert(const fxTempStr& s, u_int posn=0)
  249.     { insert((char*)s, posn, s.slength-1); }
  250.     void insert(fxStr const& s, u_int posn=0)
  251.     { insert((char*)s, posn, s.slength-1); }
  252.  
  253.     /////////////////////////////////////////////////////
  254.     // Parsing
  255.     u_int next(u_int posn, char delimiter) const;
  256.     u_int next(u_int posn, char const *delimiters, u_int len=0) const;
  257.     u_int next(u_int posn, fxStr const& delimiters) const
  258.     { return next(posn, (char*)delimiters, delimiters.slength-1); }
  259.                 
  260.     u_int nextR(u_int posn, char delimiter) const;
  261.     u_int nextR(u_int posn, char const*, u_int len=0) const;
  262.     u_int nextR(u_int posn, fxStr const& delimiters) const
  263.     { return nextR(posn, (char*)delimiters, delimiters.slength-1); }
  264.                       
  265.     u_int skip(u_int posn, char a) const; 
  266.     u_int skip(u_int posn, char const *, u_int len=0) const;
  267.     u_int skip(u_int posn, fxStr const& delimiters) const
  268.     { return skip(posn, (char*)delimiters, delimiters.slength-1); }
  269.  
  270.     u_int skipR(u_int posn, char a) const;
  271.     u_int skipR(u_int posn, char const *, u_int len=0) const;
  272.     u_int skipR(u_int posn, fxStr const& delimiters) const
  273.     { return skipR(posn, (char*)delimiters, delimiters.slength-1); }
  274.  
  275.     fxStr token(u_int & posn, char delimiter) const;
  276.     fxStr token(u_int & posn, char const * delimiters,
  277.     u_int delimiters_len = 0) const;
  278.     fxStr token(u_int & posn, fxStr const & delimiters) const
  279.     { return token(posn, delimiters.data, delimiters.slength-1); }
  280.  
  281.     fxStr tokenR(u_int & posn, char delimiter) const;
  282.     fxStr tokenR(u_int & posn, char const * delimiters,
  283.     u_int delimiters_len = 0) const;
  284.     fxStr tokenR(u_int & posn, fxStr const & delimiters) const
  285.     { return tokenR(posn, delimiters.data, delimiters.slength-1); }
  286.  
  287. protected:
  288.     // slength is one greater than the true length of the data.
  289.     // This is because the data is null-terminated. However, the
  290.     // data may contain nulls; they will be ignored. This is to
  291.     // provide compatibility with ordinary C-style strings, and
  292.     // with arbitrary data. slength is always positive.
  293.     u_int slength;
  294.  
  295.     // data points to the actual data. It is always a valid pointer.
  296.     char * data; 
  297.  
  298.     // zero-length string support
  299.     // resizeInternal doesn't update slength or handle null termination
  300.     static char emptyString;
  301.     void fxStr::resizeInternal(u_int);
  302.  
  303.     int findEndBuffer(const char *, u_int buflen) const;
  304.     int findBuffer(const char *buf, u_int buflen) const;
  305.     void bracketBuffer(const char *, u_int buflen, int &, int &) const;
  306. };
  307. class Path : public fxStr {
  308.     protected:
  309.     char    sep;
  310.     friend class PathIterator;
  311.     public:
  312.     Path(const char *envVar, char *defPath, const char separator = ':');
  313.     virtual ~Path();
  314.  
  315.     // search for file name and return pathname in result
  316.         virtual findFile(const fxStr& name, fxStr& result);
  317. };
  318.  
  319. class PathIterator {
  320.     protected:
  321.     Path&    path;
  322.     short    off;
  323.     public:
  324.     PathIterator(Path& p) : path(p)    { off = 0; }
  325.     notDone()        { return (off < path.slength); }
  326.     void operator++();
  327.     operator fxStr();
  328. };
  329.  
  330. Path::findFile(const fxStr& name, fxStr& result)
  331. {
  332.     if (name[0] == '/' && access((char*) name, 0) == 0) {
  333.     result = name;
  334.     return (1);
  335.     }
  336.     for (PathIterator it(*this); it.notDone(); it++) {
  337. #ifdef __bsdi__
  338. //
  339. // Note:  the bug is evident if __bsdi__ or not __bsdi__.  I was mucking
  340. // around here trying to figure out a workaround, but gave up.
  341. //
  342. // However, the compiler will coredump on the following if it manages
  343. // to get past the ``gxx_bug = it''.
  344. //
  345.  
  346.     fxStr gxx_bug;
  347.  
  348.     gxx_bug = it;        // compiler goes infinite here
  349.  
  350.     gxx_bug |= "/";        // then, after an infinite amount of time&space,
  351.                 //   dumps core here. (fast CPUs are wonderful)
  352.     gxx_bug |= name;
  353.  
  354.     char* pathname = gxx_bug;
  355. #else
  356.     char* pathname = it | "/" | name;
  357. #endif
  358.     if (access(pathname, 0) == 0) {
  359.         result = pathname;
  360.         return 1;
  361.     }
  362.     }
  363.     return 0;
  364. }
  365.  
  366.  
  367.  
  368.