OSDN Git Service

Revert last patch
[pf3gnuchains/gcc-fork.git] / libio / iostream.cc
index 217b2e2..31fafcb 100644 (file)
@@ -42,6 +42,10 @@ extern "C" int __printf_fp (_IO_FILE *, const struct printf_info *,
                            const void *const *);
 #else
 #include "floatio.h"
+# ifndef _IO_USE_DTOA
+int __cvt_double(double number, register int prec, int flags, int *signp,
+                 int fmtch, char *startp, char *endp);
+# endif
 #endif
 
 #define        BUF             (MAXEXP+MAXFRACT+1)     /* + decimal point */
@@ -67,6 +71,8 @@ int skip_ws(streambuf* sb)
 istream& istream::get(char& c)
 {
     if (ipfx1()) {
+       _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile,
+                                 _strbuf);
        int ch = _strbuf->sbumpc();
        if (ch == EOF) {
          set(ios::eofbit|ios::failbit);
@@ -76,6 +82,8 @@ istream& istream::get(char& c)
          c = (char)ch;
          _gcount = 1;
        }
+       isfx();
+       _IO_cleanup_region_end (0);
     }
     else
       _gcount = 0;
@@ -98,10 +106,12 @@ istream& istream::ignore(int n /* = 1 */, int delim /* = EOF */)
 {
     _gcount = 0;
     if (ipfx1()) {
+       _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile,
+                                 _strbuf);
        register streambuf* sb = _strbuf;
        if (delim == EOF) {
            _gcount = sb->ignore(n);
-           return *this;
+           goto unlock;
        }
        for (;;) {
 #if 0
@@ -118,6 +128,9 @@ istream& istream::ignore(int n /* = 1 */, int delim /* = EOF */)
            if (ch == delim)
                break;
        }
+    unlock:
+       isfx();
+       _IO_cleanup_region_end (0);
     }
     return *this;
 }
@@ -125,9 +138,13 @@ istream& istream::ignore(int n /* = 1 */, int delim /* = EOF */)
 istream& istream::read(char *s, streamsize n)
 {
     if (ipfx1()) {
+       _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile,
+                                 _strbuf);
        _gcount = _strbuf->sgetn(s, n);
        if (_gcount != n)
            set(ios::failbit|ios::eofbit);
+       isfx();
+       _IO_cleanup_region_end (0);
     }
     else
       _gcount = 0;
@@ -180,11 +197,15 @@ streampos istream::tellg()
 istream& istream::operator>>(char& c)
 {
     if (ipfx0()) {
+       _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile,
+                                 _strbuf);
        int ch = _strbuf->sbumpc();
        if (ch == EOF)
            set(ios::eofbit|ios::failbit);
        else
            c = (char)ch;
+       isfx();
+       _IO_cleanup_region_end (0);
     }
     return *this;
 }
@@ -196,6 +217,8 @@ istream::operator>> (char* ptr)
   int w = width(0);
   if (ipfx0())
     {
+      _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile,
+                               _strbuf);
       register streambuf* sb = _strbuf;
       for (;;)
        {
@@ -215,6 +238,8 @@ istream::operator>> (char* ptr)
        }
       if (p == ptr)
        set(ios::failbit);
+      isfx();
+      _IO_cleanup_region_end (0);
     }
   *p = '\0';
   return *this;
@@ -230,6 +255,9 @@ static int read_int(istream& stream, unsigned LONGEST& val, int& neg)
 {
     if (!stream.ipfx0())
       return 0;
+    int retval;
+    _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile,
+                             stream._strbuf);
     register streambuf* sb = stream.rdbuf();
     int base = 10;
     int ndigits = 0;
@@ -250,7 +278,7 @@ static int read_int(istream& stream, unsigned LONGEST& val, int& neg)
            ch = sb->sbumpc();
            if (ch == EOF) {
                val = 0;
-               return 1;
+               goto unlock;
            }
            if (ch == 'x' || ch == 'X') {
                base = 16;
@@ -286,19 +314,26 @@ static int read_int(istream& stream, unsigned LONGEST& val, int& neg)
            if (ndigits == 0)
                goto fail;
            else
-               return 1;
+               goto unlock;
        }
        ndigits++;
        val = base * val + digit;
        ch = sb->sbumpc();
     }
-    return 1;
+  unlock:
+    retval = 1;
+    goto out;
   fail:
     stream.set(ios::failbit);
-    return 0;
+    retval = 0;
+    goto out;
   eof_fail:
     stream.set(ios::failbit|ios::eofbit);
-    return 0;
+    retval = 0;
+  out:
+    stream.isfx();
+    _IO_cleanup_region_end (0);
+    return retval;
 }
 
 #define READ_INT(TYPE) \
@@ -329,31 +364,53 @@ READ_INT(bool)
 istream& istream::operator>>(long double& x)
 {
     if (ipfx0())
+      {
+       _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile,
+                                 _strbuf);
 #if _G_HAVE_LONG_DOUBLE_IO
        scan("%Lg", &x);
 #else
-       scan("%lg", &x);
+       double y;
+       scan("%lg", &y);
+       x = y;
 #endif
+       isfx();
+       _IO_cleanup_region_end (0);
+      }
     return *this;
 }
 
 istream& istream::operator>>(double& x)
 {
     if (ipfx0())
+      {
+       _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile,
+                                 _strbuf);
        scan("%lg", &x);
+       isfx();
+       _IO_cleanup_region_end (0);
+      }
     return *this;
 }
 
 istream& istream::operator>>(float& x)
 {
     if (ipfx0())
+      {
+       _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile,
+                                 _strbuf);
        scan("%g", &x);
+       isfx();
+       _IO_cleanup_region_end (0);
+      }
     return *this;
 }
 
 istream& istream::operator>>(register streambuf* sbuf)
 {
     if (ipfx0()) {
+       _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile,
+                                 _strbuf);
        register streambuf* inbuf = rdbuf();
        // FIXME: Should optimize!
        for (;;) {
@@ -367,6 +424,8 @@ istream& istream::operator>>(register streambuf* sbuf)
                break;
            }
        }
+       isfx();
+       _IO_cleanup_region_end (0);
     }
     return *this;
 }
@@ -611,22 +670,28 @@ ostream& ostream::operator<<(double n)
          prec = 6; /* default */
 
        // Do actual conversion.
-#ifdef _G_HAVE_PRINTF_FP
+#if _G_HAVE_PRINTF_FP
        {
-         struct printf_info info = { prec: prec,
-                                     width: width(0),
-                                     spec: format_char,
-                                     is_long_double: 0,
-                                     is_short: 0,
-                                     is_long: 0,
-                                     alt: flags() & ios::showpoint,
-                                     space: 0,
-                                     left: ios::left,
-                                     showsign: flags() & ios::showpos,
-                                     group: 0,
-                                     pad: fill(),
-                                     extra: 0};
-         const void *ptr = &n;
+         struct printf_info info = { /* prec: */ prec,
+                                     /* width: */ width(0),
+                                     /* spec: */ format_char,
+                                     /* is_long_double: */ 0,
+                                     /* is_short: */ 0,
+                                     /* is_long: */ 0,
+                                     /* alt: */ (flags() & ios::showpoint) != 0,
+                                     /* space: */ 0,
+                                     /* left: */ (flags() & ios::left) != 0,
+                                     /* showsign: */ (flags() & ios::showpos) != 0,
+                                     /* group: */ 0,
+#if defined __GLIBC__ && __GLIBC__ >= 2
+                                     /* extra: */ 0,
+#if __GLIBC_MINOR__ >= 1
+                                     /* is_char: */ 0,
+#endif
+#endif
+                                     /* pad: */ fill()
+         };
+         const void *ptr = (const void *) &n;
          if (__printf_fp (rdbuf(), &info, &ptr) < 0)
            set(ios::badbit|ios::failbit);
        }
@@ -711,23 +776,29 @@ ostream& ostream::operator<<(long double n)
       if (prec <= 0 && !(flags() & ios::fixed))
        prec = 6; /* default */
 
-#ifdef _G_HAVE_PRINTF_FP
+#if _G_HAVE_PRINTF_FP
       // Do actual conversion.
-      struct printf_info info = { prec: prec,
-                                 width: width(0),
-                                 spec: format_char,
-                                 is_long_double: 1,
-                                 is_short: 0,
-                                 is_long: 0,
-                                 alt: flags() & ios::showpoint,
-                                 space: 0,
-                                 left: ios::left,
-                                 showsign: flags() & ios::showpos,
-                                 group: 0,
-                                 pad: fill(),
-                                 extra: 0};
-
-      const void *ptr = &n;
+      struct printf_info info = { /* prec: */ prec,
+                                 /* width: */ width(0),
+                                 /* spec: */ format_char,
+                                 /* is_long_double: */ 1,
+                                 /* is_short: */ 0,
+                                 /* is_long: */ 0,
+                                 /* alt: */ (flags() & ios::showpoint) != 0,
+                                 /* space: */ 0,
+                                 /* left: */ (flags() & ios::left) != 0,
+                                 /* showsign: */ (flags() & ios::showpos) != 0,
+                                 /* group: */ 0,
+#if defined __GLIBC__ && __GLIBC__ >= 2
+                                 /* extra: */ 0,
+#if __GLIBC_MINOR__ >= 1
+                                 /* is_char: */ 0,
+#endif
+#endif
+                                 /* pad: */ fill()
+      };
+
+      const void *ptr = (const void *) &n;
 
       if (__printf_fp (rdbuf(), &info, &ptr) < 0)
        set (ios::badbit|ios::failbit);
@@ -769,8 +840,8 @@ ostream& ostream::operator<<(const char *s)
       if (flags() & ios::left && padding > 0) // Left adjustment.
        if (_IO_padn(sbuf, fill_char, padding) != padding)
          set(ios::badbit);
-      osfx();
      failed:
+      osfx();
       _IO_cleanup_region_end (0);
     }
   return *this;
@@ -886,13 +957,16 @@ int istream::_skip_ws()
 
 ostream& ends(ostream& outs)
 {
-    outs.put('\0');
+    if (outs.opfx())
+       outs.put('\0');
     return outs;
 }
 
 ostream& endl(ostream& outs)
 {
-    return flush(outs.put('\n'));
+    if (outs.opfx())
+        flush(outs.put('\n'));
+    return outs;
 }
 
 istream& lock(istream& ins)