stdcxx-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject svn commit: r960407 - in /stdcxx/branches/4.2.x: include/fstream src/iostream.cpp tests/iostream/27.filebuf.cpp tests/regress/27.filebuf.members.stdcxx-308.cpp
Date Sun, 04 Jul 2010 23:09:25 GMT
Author: sebor
Date: Sun Jul  4 23:09:25 2010
New Revision: 960407

URL: http://svn.apache.org/viewvc?rev=960407&view=rev
Log:
2010-07-04  Martin Sebor  <sebor@apache.org>

	STDCXX-1049
	* include/fstream (basic_filebuf::basic_filebuf, basic_filebuf::open,
	basic_filebuf::fd, basic_filebuf::attach, basic_filebuf::detach):
	Guarded POSIX extensions using _RWSTD_NO_NATIVE_IO.
	(basic_ifstream, basic_ofstream, basic_fstream): Same.
	* src/iostream.cpp (<unistd.h>): Included only if _RWSTD_NO_NATIVE_IO
	is not defined.
	(_RWSTD_DEFINE_STREAM_OBJECT): Modified to use stdin, stdout, and
	stderr when _RWSTD_NO_NATIVE_IO is defined, otherwise STDIN_FILENO,
	STDOUT_FILENO, STDERR_FILENO.
	(ios_base::Init::Init): Adjusted.
	* tests/iostream/27.filebuf.cpp (test_ctors, test_attach): Avoided
	testing POSIX extensions above when _RWSTD_NO_NATIVE_IO is defined.
	* tests/regress/27.filebuf.members.stdcxx-308.cpp: Same.

Modified:
    stdcxx/branches/4.2.x/include/fstream
    stdcxx/branches/4.2.x/src/iostream.cpp
    stdcxx/branches/4.2.x/tests/iostream/27.filebuf.cpp
    stdcxx/branches/4.2.x/tests/regress/27.filebuf.members.stdcxx-308.cpp

Modified: stdcxx/branches/4.2.x/include/fstream
URL: http://svn.apache.org/viewvc/stdcxx/branches/4.2.x/include/fstream?rev=960407&r1=960406&r2=960407&view=diff
==============================================================================
--- stdcxx/branches/4.2.x/include/fstream (original)
+++ stdcxx/branches/4.2.x/include/fstream Sun Jul  4 23:09:25 2010
@@ -128,6 +128,9 @@ private:
     // ctor extensions - associate this with an open file and
     // optionally set buffer size and caller-allocated buffer
     // NOTE: passed in buffer will NOT be deallocated
+
+#ifndef _RWSTD_NO_NATIVE_IO
+
     _EXPLICIT
     basic_filebuf (int __fd, char_type* __buf   = 0,
                    _RWSTD_STREAMSIZE __bufsz = _RWSTD_DEFAULT_BUFSIZE)
@@ -136,9 +139,11 @@ private:
         _C_open (__fd, 0, __buf, __bufsz);
     }
 
+#endif   // _RWSTD_NO_NATIVE_IO
+
 public:
 
-#ifndef _RWSTD_NO_EXT_FILEBUF
+#if !defined(_RWSTD_NO_EXT_FILEBUF) || defined(_RWSTD_NO_NATIVE_IO)
 
     // extension enabled only if the macro stdin is also #defined
     // i.e., if the header <cstdio> or <stdio.h> has been #included
@@ -154,7 +159,7 @@ public:
     }
 
 #  endif   // stdin
-#endif   // _RWSTD_NO_EXT_FILEBUF
+#endif   // !_RWSTD_NO_EXT_FILEBUF || _RWSTD_NO_NATIVE_IO
 
     // 27.8.1.2, p3
     virtual ~basic_filebuf ();
@@ -168,11 +173,15 @@ public:
     // and optionally set buffer size and caller-allocated buffer
     // NOTE: passed in buffer will NOT be deallocated
 
+#  ifndef _RWSTD_NO_NATIVE_IO
+
     basic_filebuf* open (int __fd, char_type *__buf = 0,
           _RWSTD_STREAMSIZE __bufsz = _RWSTD_DEFAULT_BUFSIZE) {
         return _C_open (__fd, 0, __buf, __bufsz);
     }
 
+#  endif   // _RWSTD_NO_NATIVE_IO
+
 #  ifdef stdin
 
     // extension enabled only if the macro stdin is also #defined
@@ -184,7 +193,9 @@ public:
     }
 
 #  endif   // stdin
-    
+
+#  ifndef _RWSTD_NO_NATIVE_IO
+
     // extension - return the associated file descriptor
     int fd () const {
         return _RW::__rw_fileno (_C_file, this->_C_state);
@@ -201,6 +212,7 @@ public:
         return close (false) ? __fd : -1;
     }
 
+#  endif   // _RWSTD_NO_NATIVE_IO
 #endif   // _RWSTD_NO_EXT_FILEBUF
 
     // 27.8.1.3, p6, argument is an extension
@@ -387,6 +399,9 @@ public:
 #ifndef  _RWSTD_NO_EXT_FILEBUF
 
     // extensions - associate this with an open file and set buffer
+
+#  ifndef _RWSTD_NO_NATIVE_IO
+
     _EXPLICIT
     basic_ifstream (int __fd, char_type *__buf = 0,
                     _RWSTD_STREAMSIZE __n = _RWSTD_DEFAULT_BUFSIZE)
@@ -394,6 +409,8 @@ public:
         open (__fd, __buf, __n);
     }
 
+#  endif   // _RWSTD_NO_NATIVE_IO
+
 #  ifdef stdin
 
     _EXPLICIT
@@ -430,12 +447,17 @@ public:
 #ifndef  _RWSTD_NO_EXT_FILEBUF
 
     // extensions - associate this with an open file and set buffer
+
+#  ifndef _RWSTD_NO_NATIVE_IO
+
     void open (int __fd, char_type *__buf=0,
                _RWSTD_STREAMSIZE __n = _RWSTD_DEFAULT_BUFSIZE) {
         this->clear (rdbuf ()->open (__fd, __buf, __n) ?
                      ios_base::goodbit : ios_base::failbit);
     }
 
+#  endif   // _RWSTD_NO_NATIVE_IO
+
 #  ifdef stdin
 
     void open (FILE *__fptr, char_type *__buf=0,
@@ -487,12 +509,17 @@ public:
 #ifndef _RWSTD_NO_EXT_FILEBUF
 
     // extensions - associate this with an open file and set buffer
+
+#  ifndef _RWSTD_NO_NATIVE_IO
+
     _EXPLICIT
     basic_ofstream (int __fd, char_type *__buf = 0,
                     _RWSTD_STREAMSIZE __n = _RWSTD_DEFAULT_BUFSIZE)
         : basic_ostream<char_type, traits_type> (rdbuf ()) {
         open (__fd, __buf, __n);
     }
+
+#  endif   // _RWSTD_NO_NATIVE_IO
     
 #  ifdef stdin
 
@@ -530,12 +557,17 @@ public:
 #ifndef _RWSTD_NO_EXT_FILEBUF
 
     // extensions - associate this with an open file and set buffer
+
+#  ifndef _RWSTD_NO_NATIVE_IO
+
     void open (int  __fd, char_type *__buf=0,
                _RWSTD_STREAMSIZE __n = _RWSTD_DEFAULT_BUFSIZE) {
         this->clear (rdbuf ()->open (__fd, __buf, __n) ?
                      ios_base::goodbit : ios_base::failbit);
     }
 
+#  endif   // _RWSTD_NO_NATIVE_IO
+
 #  ifdef stdin
 
     void open (FILE *__fp, char_type *__buf=0,
@@ -588,6 +620,9 @@ public:
 #ifndef _RWSTD_NO_EXT_FILEBUF
 
     // extensions - associate this with an open file and set buffer
+
+#  ifndef _RWSTD_NO_NATIVE_IO
+
     _EXPLICIT
     basic_fstream (int __fd, char_type *__buf = 0,
                    _RWSTD_STREAMSIZE __n = _RWSTD_DEFAULT_BUFSIZE)
@@ -595,6 +630,8 @@ public:
         open (__fd, __buf, __n);
     }
 
+#  endif // _RWSTD_NO_NATIVE_IO
+
 #  ifdef stdin
 
     _EXPLICIT
@@ -631,12 +668,17 @@ public:
 #ifndef _RWSTD_NO_EXT_FILEBUF
 
     // extensions - associate this with an open file and set buffer"
+
+#  ifndef _RWSTD_NO_NATIVE_IO
+
     void open (int __fd, char_type *__buf=0,
                _RWSTD_STREAMSIZE __n = _RWSTD_DEFAULT_BUFSIZE) {
         this->clear (rdbuf ()->open (__fd, __buf, __n) ?
                      ios_base::goodbit : ios_base::failbit);
     }
 
+#  endif   // _RWSTD_NO_NATIVE_IO
+
 #  ifdef stdin
 
     void open (FILE *__fptr, char_type *__buf=0,

Modified: stdcxx/branches/4.2.x/src/iostream.cpp
URL: http://svn.apache.org/viewvc/stdcxx/branches/4.2.x/src/iostream.cpp?rev=960407&r1=960406&r2=960407&view=diff
==============================================================================
--- stdcxx/branches/4.2.x/src/iostream.cpp (original)
+++ stdcxx/branches/4.2.x/src/iostream.cpp Sun Jul  4 23:09:25 2010
@@ -40,18 +40,25 @@
 
 #include <rw/_defs.h>
 
-#ifdef _WIN32
-#  include <io.h>
-#  ifndef STDIN_FILENO
-#    define STDIN_FILENO  0
-#    define STDOUT_FILENO 1
-#    define STDERR_FILENO 2
-#  endif   // STDIN_FILENO
-#else
-   // unistd.h must preceed other headers to avoid a namespace issue
-   // ("time_t" vrs "std::time_t") on SunPro 5.3/SunOS 5.8
-#  include <unistd.h>
-#endif 
+#ifndef _RWSTD_NO_NATIVE_IO
+#  ifdef _WIN32
+#    include <io.h>
+#    ifndef STDIN_FILENO
+#      define STDIN_FILENO  0
+#      define STDOUT_FILENO 1
+#      define STDERR_FILENO 2
+#    endif   // STDIN_FILENO
+#  else   // if !defined _WIN32
+     // <unistd.h> must preceed other headers to avoid a namespace
+     // issue ("time_t" vrs "std::time_t") on SunPro 5.3/SunOS 5.8
+#    include <unistd.h>
+#  endif   // _WIN32
+#else   // if defined _RWSTD_NO_NATIVE_IO
+   // <stdio.h> must be included before <fstream> so that the FILE*
+   // basic_filebuf ctor extensions get declared (they depend on the
+   // stdin macro being declared)
+#  include <stdio.h>
+#endif   // _RWSTD_NO_NATIVE_IO
 
 #include <iosfwd>
 #include <istream>
@@ -100,6 +107,10 @@
 // for destruction prior to any other objects with static storage duration
 // and is undetectable
 
+// buftype: basic_filebuf specialization
+// stream:  [w]istream or [w]ostream
+// name:    name of the standard iostream object
+// ignN:    ignored
 #define _RWSTD_DEFINE_STREAM_OBJECT(buftype, stream, name, ign1, ign2)        \
   _RWSTD_NAMESPACE (__rw) {                                                   \
     /* static character buffer to prevent dynamic allocation */               \
@@ -127,6 +138,10 @@
 // lie is transparent to the compiler/linker as neither ever sees both
 // declarations
 
+// buftype: basic_filebuf specialization
+// stream:  [w]istream or [w]ostream
+// name:    name of the standard iostream object
+// ignN:    ignored
 #define _RWSTD_DEFINE_STREAM_OBJECT(buftype, stream, name, ign1, ign2)      \
   _RWSTD_NAMESPACE (__rw) {                                                 \
     /* static character buffer to prevent dynamic allocation */             \
@@ -155,7 +170,7 @@
   /* backed by a static characater array                           */         \
   new (&_RW::__rw_indestructible_##name) stream                               \
           (new (&_RW::__rw_##name##_buffer) buftype                           \
-              (f, _RW::__rw_##name##_databuf,                                 \
+           (FILEREF (f), _RW::__rw_##name##_databuf,                          \
      sizeof _RW::__rw_##name##_databuf / sizeof *_RW::__rw_##name##_databuf)) \
 
 
@@ -163,12 +178,17 @@
 
 // iostream objects and buffers are constructed at definition time
 
+// buftype: basic_filebuf specialization
+// stream:  [w]istream or [w]ostream
+// name:    name of the standard iostream object
+// buf:     tied indestructible buffer
+// f:       associated file descriptor or FILE pointer
 #define _RWSTD_DEFINE_STREAM_OBJECT(buftype, stream, name, buf, f)           \
   _RWSTD_NAMESPACE (__rw) {                                                  \
     /* static character buffer to prevent dynamic allocation */              \
     static _STD::stream::char_type __rw_##name##_databuf [512];              \
     /* static `basic_filebuf<>' object, destroyed at program termination */  \
-    static _STD::buftype __rw_##name##_buffer (f,                            \
+    static _STD::buftype __rw_##name##_buffer (FILEREF (f),                  \
         __rw_##name##_databuf,                                               \
         sizeof __rw_##name##_databuf / sizeof *__rw_##name##_databuf);       \
   }   /* namespace __rw */                                                   \
@@ -182,19 +202,30 @@
 
 #endif   // _RWSTD_NO_STATIC_IOSTREAM_INIT
 
+#ifndef _RWSTD_NO_NATIVE_IO
+   // use STDIN_FILENO etc. to initialize basic_filebuf
+#  define FILEREF(name)   name ##_FILENO
+#else
+   // use stdin etc. to initialize basic_filebuf
+#  define STDIN_FILEPTR   stdin
+#  define STDOUT_FILEPTR  stdout
+#  define STDERR_FILEPTR  stderr
+#  define FILEREF(name)   name ##_FILEPTR
+#endif   // _RWSTD_NO_NATIVE_IO
+
 
 // define iostream objects and their corresponding "buffers"
-_RWSTD_DEFINE_STREAM_OBJECT (filebuf, istream, cin,  cin,  STDIN_FILENO);
-_RWSTD_DEFINE_STREAM_OBJECT (filebuf, ostream, cout, cout, STDOUT_FILENO);
-_RWSTD_DEFINE_STREAM_OBJECT (filebuf, ostream, cerr, cerr, STDERR_FILENO);
-_RWSTD_DEFINE_STREAM_OBJECT (filebuf, ostream, clog, cerr, STDERR_FILENO);
+_RWSTD_DEFINE_STREAM_OBJECT (filebuf, istream, cin,  cin,  STDIN);
+_RWSTD_DEFINE_STREAM_OBJECT (filebuf, ostream, cout, cout, STDOUT);
+_RWSTD_DEFINE_STREAM_OBJECT (filebuf, ostream, cerr, cerr, STDERR);
+_RWSTD_DEFINE_STREAM_OBJECT (filebuf, ostream, clog, cerr, STDERR);
 
 #ifndef _RWSTD_NO_WCHAR_T
 
-_RWSTD_DEFINE_STREAM_OBJECT (wfilebuf, wistream, wcin,  wcin,  STDIN_FILENO);
-_RWSTD_DEFINE_STREAM_OBJECT (wfilebuf, wostream, wcout, wcout, STDOUT_FILENO);
-_RWSTD_DEFINE_STREAM_OBJECT (wfilebuf, wostream, wcerr, wcerr, STDERR_FILENO);
-_RWSTD_DEFINE_STREAM_OBJECT (wfilebuf, wostream, wclog, wcerr, STDERR_FILENO);
+_RWSTD_DEFINE_STREAM_OBJECT (wfilebuf, wistream, wcin,  wcin,  STDIN);
+_RWSTD_DEFINE_STREAM_OBJECT (wfilebuf, wostream, wcout, wcout, STDOUT);
+_RWSTD_DEFINE_STREAM_OBJECT (wfilebuf, wostream, wcerr, wcerr, STDERR);
+_RWSTD_DEFINE_STREAM_OBJECT (wfilebuf, wostream, wclog, wcerr, STDERR);
 
 #endif   // _RWSTD_NO_WCHAR_T
 
@@ -238,10 +269,10 @@ ios_base::Init::Init ()
     // since references need not be initialzied statically, cin, et al
     // may not be initialized at this time (i.e., &cin == 0 may hold,
     // and does with MSVC 6.0), obtain and use pointers to the objects
-    istream *pcin =  _INIT (filebuf, istream, cin,  cin,  STDIN_FILENO);
-    ostream *pcout = _INIT (filebuf, ostream, cout, cout, STDOUT_FILENO);
-    ostream *pcerr = _INIT (filebuf, ostream, cerr, cerr, STDERR_FILENO);
-    ostream *pclog = _INIT (filebuf, ostream, clog, cerr, STDERR_FILENO);
+    istream* const pcin  = _INIT (filebuf, istream, cin,  cin,  STDIN);
+    ostream* const pcout = _INIT (filebuf, ostream, cout, cout, STDOUT);
+    ostream* const pcerr = _INIT (filebuf, ostream, cerr, cerr, STDERR);
+    ostream* const pclog = _INIT (filebuf, ostream, clog, cerr, STDERR);
 
     // stream objects expected to be arranged in this order
     // must be initialized dynamically (as opposed to statically)
@@ -277,10 +308,10 @@ ios_base::Init::Init ()
 
 #ifndef _RWSTD_NO_WCHAR_T
 
-    wistream *pwcin =  _INIT (wfilebuf, wistream, wcin,  wcin,  STDIN_FILENO);
-    wostream *pwcout = _INIT (wfilebuf, wostream, wcout, wcout, STDOUT_FILENO);
-    wostream *pwcerr = _INIT (wfilebuf, wostream, wcerr, wcerr, STDERR_FILENO);
-    wostream *pwclog = _INIT (wfilebuf, wostream, wclog, wcerr, STDERR_FILENO);
+    wistream* const pwcin  = _INIT (wfilebuf, wistream, wcin,  wcin,  STDIN);
+    wostream* const pwcout = _INIT (wfilebuf, wostream, wcout, wcout, STDOUT);
+    wostream* const pwcerr = _INIT (wfilebuf, wostream, wcerr, wcerr, STDERR);
+    wostream* const pwclog = _INIT (wfilebuf, wostream, wclog, wcerr, STDERR);
 
     // stream objects expected to be arranged in this order
     // must be initialized dynamically (as opposed to statically)

Modified: stdcxx/branches/4.2.x/tests/iostream/27.filebuf.cpp
URL: http://svn.apache.org/viewvc/stdcxx/branches/4.2.x/tests/iostream/27.filebuf.cpp?rev=960407&r1=960406&r2=960407&view=diff
==============================================================================
--- stdcxx/branches/4.2.x/tests/iostream/27.filebuf.cpp (original)
+++ stdcxx/branches/4.2.x/tests/iostream/27.filebuf.cpp Sun Jul  4 23:09:25 2010
@@ -192,6 +192,8 @@ test_ctors (const char* tname)
 
 #  endif   // stdin
 
+#  ifndef _RWSTD_NO_NATIVE_IO
+
     //////////////////////////////////////////////////////////////////
     rw_info (0, __FILE__, __LINE__,
              "std::basic_filebuf<%s>::basic_filebuf(int) "
@@ -231,6 +233,8 @@ test_ctors (const char* tname)
 
     delete pfb;
 
+#  endif   // _RWSTD_NO_NATIVE_IO
+
 #endif   // _RWSTD_NO_EXT_FILEBUF
 
     REMOVE_FILE (tmpfname);
@@ -1280,7 +1284,7 @@ template <class charT>
 static void
 test_attach (const char* tname)
 {
-#ifndef _RWSTD_NO_EXT_FILEBUF
+#if !defined _RWSTD_NO_EXT_FILEBUF && !defined _RWSTD_NO_NATIVE_IO
 
     //////////////////////////////////////////////////////////////////
     // exercise attach(int) and fd()
@@ -1686,11 +1690,11 @@ test_attach (const char* tname)
         REMOVE_FILE (tmpfname);
     }
 
-#else   // if defined (_RWSTD_NO_EXT_FILEBUF)
+#else   // if !_RWSTD_NO_EXT_FILEBUF && !_RWSTD_NO_NATIVE_IO
 
     _RWSTD_UNUSED (tname);
 
-#endif   // _RWSTD_NO_EXT_FILEBUF
+#endif   // _RWSTD_NO_EXT_FILEBUF || _RWSTD_NO_NATIVE_IO
 
 }
 

Modified: stdcxx/branches/4.2.x/tests/regress/27.filebuf.members.stdcxx-308.cpp
URL: http://svn.apache.org/viewvc/stdcxx/branches/4.2.x/tests/regress/27.filebuf.members.stdcxx-308.cpp?rev=960407&r1=960406&r2=960407&view=diff
==============================================================================
--- stdcxx/branches/4.2.x/tests/regress/27.filebuf.members.stdcxx-308.cpp (original)
+++ stdcxx/branches/4.2.x/tests/regress/27.filebuf.members.stdcxx-308.cpp Sun Jul  4 23:09:25
2010
@@ -46,7 +46,7 @@
 #endif   // !_WIN32 || __CYGWIN__
 
 
-int write_bytes (const char *fname, std::size_t nbytes)
+static int write_bytes (const char *fname, std::size_t nbytes)
 {
     std::filebuf fb;
 
@@ -54,19 +54,22 @@ int write_bytes (const char *fname, std:
         || 0 == fb.open (fname, std::ios::out))
         return -1;
 
-#if defined (_RWSTD_VER) && !defined (_RWSTD_NO_EXT_FILEBUF)
+#if     defined _RWSTD_VER              \
+    && !defined _RWSTD_NO_EXT_FILEBUF   \
+    && !defined _RWSTD_NO_NATIVE_IO
+
 
     // use the filebuf::fd() extension to get the filebuf's
     // associated file descriptor
     const int fd = fb.fd ();
 
-#else   // if defined (RWSTD_NO_EXT_FILEBUF)
+#else   // if !RWSTD_NO_EXT_FILEBUF && !_RWSTD_NO_NATIVE_IO
 
     // assume fd is the next available file descriptor after
     // STDIN_FILENO, _FILENO_STDOUT, and STDERR_FILENO
     const int fd = 3;
 
-#endif   // RWSTD_NO_EXT_FILEBUF
+#endif   // _RWSTD_NO_EXT_FILEBUF || _RWSTD_NO_NATIVE_IO
 
     if (0 < fd) {
         // fill up the filebuf's character buffer without



Mime
View raw message