public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/11705] New: Bad interaction between cin and wcin after sync_with_stdio(false)
@ 2003-07-29 10:12 peturr02 at ru dot is
  2003-07-29 10:14 ` [Bug libstdc++/11705] " peturr02 at ru dot is
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: peturr02 at ru dot is @ 2003-07-29 10:12 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11705

           Summary: Bad interaction between cin and wcin after
                    sync_with_stdio(false)
           Product: gcc
           Version: 3.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: libstdc++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: peturr02 at ru dot is
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu

If sync_with_stdio(false) is called, it is possible to mix calls to
cin and wcin. This violates 27.3:

  Mixing operations on corresponding wide- and narrow-character streams
  follows the same semantics as mixing such operations on FILEs, as
  specified in Amendment 1 of the ISO C standard.

I don't have Amendment 1, but on my system (glibc-2.3) it is not
possible to mix wide and narrow input operations on the same FILE.

It also violates 22.2.1.5.2:

  Preconditions: [...] state initialized, if at the beginning of a
  sequence, or else equal to the result of converting the preceding
  characters in the sequence.

wcin uses codecvt, but the bytes read through cin never pass through
wcin, so state can never be the result of converting those bytes, and
any attempt to convert later bytes is a precondition violation
(undefined behaviour).

Even for stateless conversions, cin may not leave the file pointer
at a character boundary; any attempt to convert a sequence of bytes
that doesn't begin at a character boundary will either fail or give
meaningless results.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug libstdc++/11705] Bad interaction between cin and wcin after sync_with_stdio(false)
  2003-07-29 10:12 [Bug libstdc++/11705] New: Bad interaction between cin and wcin after sync_with_stdio(false) peturr02 at ru dot is
@ 2003-07-29 10:14 ` peturr02 at ru dot is
  2003-08-04  2:24 ` pinskia at physics dot uc dot edu
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: peturr02 at ru dot is @ 2003-07-29 10:14 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11705



------- Additional Comments From peturr02 at ru dot is  2003-07-29 10:14 -------
Created an attachment (id=4502)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=4502&action=view)
Test case

This test case shows that it is possible to read from wcin after reading
from cin, if ios::sync_with_stdio(false) has been called.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug libstdc++/11705] Bad interaction between cin and wcin after sync_with_stdio(false)
  2003-07-29 10:12 [Bug libstdc++/11705] New: Bad interaction between cin and wcin after sync_with_stdio(false) peturr02 at ru dot is
  2003-07-29 10:14 ` [Bug libstdc++/11705] " peturr02 at ru dot is
@ 2003-08-04  2:24 ` pinskia at physics dot uc dot edu
  2003-08-23  1:01 ` dhazeghi at yahoo dot com
  2003-12-05 23:44 ` bkoz at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at physics dot uc dot edu @ 2003-08-04  2:24 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11705


pinskia at physics dot uc dot edu changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
   Last reconfirmed|0000-00-00 00:00:00         |2003-08-04 02:24:17
               date|                            |


------- Additional Comments From pinskia at physics dot uc dot edu  2003-08-04 02:24 -------
I can confirm this on the mainline (20030803).


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug libstdc++/11705] Bad interaction between cin and wcin after sync_with_stdio(false)
  2003-07-29 10:12 [Bug libstdc++/11705] New: Bad interaction between cin and wcin after sync_with_stdio(false) peturr02 at ru dot is
  2003-07-29 10:14 ` [Bug libstdc++/11705] " peturr02 at ru dot is
  2003-08-04  2:24 ` pinskia at physics dot uc dot edu
@ 2003-08-23  1:01 ` dhazeghi at yahoo dot com
  2003-12-05 23:44 ` bkoz at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: dhazeghi at yahoo dot com @ 2003-08-23  1:01 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11705


dhazeghi at yahoo dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|3.4                         |---


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug libstdc++/11705] Bad interaction between cin and wcin after sync_with_stdio(false)
  2003-07-29 10:12 [Bug libstdc++/11705] New: Bad interaction between cin and wcin after sync_with_stdio(false) peturr02 at ru dot is
                   ` (2 preceding siblings ...)
  2003-08-23  1:01 ` dhazeghi at yahoo dot com
@ 2003-12-05 23:44 ` bkoz at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: bkoz at gcc dot gnu dot org @ 2003-12-05 23:44 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bkoz at gcc dot gnu dot org  2003-12-05 23:44 -------

I think the bool argument can just be removed: it was put in to deal with the
std streams (cin, cout, etc), and don't really apply to people using
stdio_filebuf for other work.

Or, I can keep the argument but have it do nothing (less impressive, but keeps
the same API). Here's a patch for the first idea, please let me know what you think.

best,
benjamin

2003-12-05  Benjamin Kosnik  <bkoz@redhat.com>

	PR libstdc++/11691 
	* include/ext/stdio_filebuf.h (stdio_filebuf::stdio_filebuf):
	Remove __del argument to file descriptor constructor.
	* config/io/basic_file_stdio.h (__basic_file::sys_open): Remove
	bool argument.
	* config/io/basic_file_stdio.cc: Same.

Index: config/io/basic_file_stdio.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/config/io/basic_file_stdio.cc,v
retrieving revision 1.23
diff -c -p -r1.23 basic_file_stdio.cc
*** config/io/basic_file_stdio.cc	22 Oct 2003 15:51:55 -0000	1.23
--- config/io/basic_file_stdio.cc	5 Dec 2003 23:43:21 -0000
*************** namespace std 
*** 140,147 ****
    }
    
    __basic_file<char>*
!   __basic_file<char>::sys_open(int __fd, ios_base::openmode __mode, 
! 			       bool __del) 
    {
      __basic_file* __ret = NULL;
      int __p_mode = 0;
--- 140,146 ----
    }
    
    __basic_file<char>*
!   __basic_file<char>::sys_open(int __fd, ios_base::openmode __mode)
    {
      __basic_file* __ret = NULL;
      int __p_mode = 0;
*************** namespace std 
*** 151,162 ****
      _M_open_mode(__mode, __p_mode, __rw_mode, __c_mode);
      if (!this->is_open() && (_M_cfile = fdopen(__fd, __c_mode)))
        {
! 	// Iff __del is true, then close will fclose the fd.
! 	_M_cfile_created = __del;
! 
  	if (__fd == 0)
  	  setvbuf(_M_cfile, reinterpret_cast<char*>(NULL), _IONBF, 0);
- 
  	__ret = this;
        }
      return __ret;
--- 150,158 ----
      _M_open_mode(__mode, __p_mode, __rw_mode, __c_mode);
      if (!this->is_open() && (_M_cfile = fdopen(__fd, __c_mode)))
        {
! 	_M_cfile_created = true;
  	if (__fd == 0)
  	  setvbuf(_M_cfile, reinterpret_cast<char*>(NULL), _IONBF, 0);
  	__ret = this;
        }
      return __ret;
*************** namespace std 
*** 199,205 ****
    __basic_file<char>* 
    __basic_file<char>::close()
    { 
!     __basic_file* __retval = static_cast<__basic_file*>(NULL);
      if (this->is_open())
        {
  	if (_M_cfile_created)
--- 195,201 ----
    __basic_file<char>* 
    __basic_file<char>::close()
    { 
!     __basic_file* __ret = static_cast<__basic_file*>(NULL);
      if (this->is_open())
        {
  	if (_M_cfile_created)
*************** namespace std 
*** 207,215 ****
  	else
  	  fflush(_M_cfile);
  	_M_cfile = 0;
! 	__retval = this;
        }
!     return __retval;
    }
   
    streamsize 
--- 203,211 ----
  	else
  	  fflush(_M_cfile);
  	_M_cfile = 0;
! 	__ret = this;
        }
!     return __ret;
    }
   
    streamsize 
Index: config/io/basic_file_stdio.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/config/io/basic_file_stdio.h,v
retrieving revision 1.15
diff -c -p -r1.15 basic_file_stdio.h
*** config/io/basic_file_stdio.h	16 Oct 2003 22:37:48 -0000	1.15
--- config/io/basic_file_stdio.h	5 Dec 2003 23:43:21 -0000
***************
*** 1,6 ****
  // Wrapper of C-language FILE struct -*- C++ -*-
  
! // Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
  //
  // This file is part of the GNU ISO C++ Library.  This library is free
  // software; you can redistribute it and/or modify it under the
--- 1,6 ----
  // Wrapper of C-language FILE struct -*- C++ -*-
  
! // Copyright (C) 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
  //
  // This file is part of the GNU ISO C++ Library.  This library is free
  // software; you can redistribute it and/or modify it under the
*************** namespace std 
*** 74,80 ****
        sys_open(__c_file* __file, ios_base::openmode);
  
        __basic_file*
!       sys_open(int __fd, ios_base::openmode __mode, bool __del);
  
        __basic_file* 
        close(); 
--- 74,80 ----
        sys_open(__c_file* __file, ios_base::openmode);
  
        __basic_file*
!       sys_open(int __fd, ios_base::openmode __mode);
  
        __basic_file* 
        close(); 
Index: include/ext/stdio_filebuf.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/ext/stdio_filebuf.h,v
retrieving revision 1.14
diff -c -p -r1.14 stdio_filebuf.h
*** include/ext/stdio_filebuf.h	12 Nov 2003 01:14:34 -0000	1.14
--- include/ext/stdio_filebuf.h	5 Dec 2003 23:43:22 -0000
*************** namespace __gnu_cxx
*** 65,78 ****
        /**
         *  @param  fd  An open file descriptor.
         *  @param  mode  Same meaning as in a standard filebuf.
-        *  @param  del  Whether to close the file on destruction.
         *  @param  size  Optimal or preferred size of internal buffer, in chars.
         *
         *  This constructor associates a file stream buffer with an open
!        *  POSIX file descriptor.  Iff @a del is true, then the associated
!        *  file will be closed when the stdio_filebuf is closed/destroyed.
        */
!       stdio_filebuf(int __fd, std::ios_base::openmode __mode, bool __del, 
  		    size_t __size = static_cast<size_t>(BUFSIZ));
  
        /**
--- 65,76 ----
        /**
         *  @param  fd  An open file descriptor.
         *  @param  mode  Same meaning as in a standard filebuf.
         *  @param  size  Optimal or preferred size of internal buffer, in chars.
         *
         *  This constructor associates a file stream buffer with an open
!        *  POSIX file descriptor.
        */
!       stdio_filebuf(int __fd, std::ios_base::openmode __mode, 
  		    size_t __size = static_cast<size_t>(BUFSIZ));
  
        /**
*************** namespace __gnu_cxx
*** 114,123 ****
  
    template<typename _CharT, typename _Traits>
      stdio_filebuf<_CharT, _Traits>::
!     stdio_filebuf(int __fd, std::ios_base::openmode __mode, bool __del, 
! 		  size_t __size)
      {
!       this->_M_file.sys_open(__fd, __mode, __del);
        if (this->is_open())
  	{
  	  this->_M_mode = __mode;
--- 112,120 ----
  
    template<typename _CharT, typename _Traits>
      stdio_filebuf<_CharT, _Traits>::
!     stdio_filebuf(int __fd, std::ios_base::openmode __mode, size_t __size)
      {
!       this->_M_file.sys_open(__fd, __mode);
        if (this->is_open())
  	{
  	  this->_M_mode = __mode;


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11705


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2003-12-05 23:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-07-29 10:12 [Bug libstdc++/11705] New: Bad interaction between cin and wcin after sync_with_stdio(false) peturr02 at ru dot is
2003-07-29 10:14 ` [Bug libstdc++/11705] " peturr02 at ru dot is
2003-08-04  2:24 ` pinskia at physics dot uc dot edu
2003-08-23  1:01 ` dhazeghi at yahoo dot com
2003-12-05 23:44 ` bkoz at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).