From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 105745 invoked by alias); 29 Aug 2017 20:02:21 -0000 Mailing-List: contact libstdc++-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libstdc++-owner@gcc.gnu.org Received: (qmail 105631 invoked by uid 89); 29 Aug 2017 20:02:21 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.5 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM,SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-wm0-f48.google.com Received: from mail-wm0-f48.google.com (HELO mail-wm0-f48.google.com) (74.125.82.48) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 29 Aug 2017 20:02:19 +0000 Received: by mail-wm0-f48.google.com with SMTP id u26so4397130wma.0 for ; Tue, 29 Aug 2017 13:02:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:references:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=kBm6EjmLHfT/wBad0ye0f9dsdpTnruFxGaGdyYPQYaI=; b=AwnctEzMNTlCXvVxYmodUHBRONczr+4ZFY5pnvhFCfOLeQyHuk6EUGpmFex73lehwO Ndamf/GAOOorZOONbOwIuKIdONiRrC1I1flGfuDUlNETd2DSEDoRnNA843CA91uzgGoB FMhM+HnRWVEqxu3bjL2UzNl8cJZBsIJly2aY2XRIKwiBIPZ6dzHtOuCFPuseZ3DTGCAZ AUY4DB0n0hrV3nkFgieWw+qAJChvP5/vUKTd6hhh+kI6gsnbpj2PykihnFupKgFHY2qP 2FNWwvmZhNvpEaUr4zlHBKzzJgHw1Cey4q0I8g5VZnGySXxMbUqga2RDUuPCZGZzsmee 8pqg== X-Gm-Message-State: AHYfb5hWFjikvOwtg0DvpmbCzA4h3vfY3wJ93Rjz/qkcI5UPoHJ7GZAS YBFKzJCZQnrvgqbe X-Received: by 10.28.181.143 with SMTP id e137mr436288wmf.68.1504036937140; Tue, 29 Aug 2017 13:02:17 -0700 (PDT) Received: from [192.168.0.23] (arf62-1-82-237-250-248.fbx.proxad.net. [82.237.250.248]) by smtp.googlemail.com with ESMTPSA id 6sm2973242wre.0.2017.08.29.13.02.15 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Aug 2017 13:02:16 -0700 (PDT) From: =?UTF-8?Q?Fran=c3=a7ois_Dumont?= Subject: Re: [PATCH] streambuf_iterator: avoid debug-dependent behaviour To: libstdc++@gcc.gnu.org References: Message-ID: Date: Tue, 29 Aug 2017 20:02:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/mixed; boundary="------------C88E5B199C1BDD7A1AA6EDDE" X-IsSubscribed: yes X-SW-Source: 2017-08/txt/msg00043.txt.bz2 This is a multi-part message in MIME format. --------------C88E5B199C1BDD7A1AA6EDDE Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-length: 1335 Hi You should perhaps justify why you want to do those changes. On 24/08/2017 11:57, Petr Ovtchenkov wrote: > Explicit do sgetc from associated streambuf. Avoid debug-dependent > sgetc (within _M_at_eof()): > > __glibcxx_requires_cond(!_M_at_eof(), > _M_message(__gnu_debug::__msg_inc_istreambuf) > ._M_iterator(*this)); > > Increment operators not require not-eof precoditions. > > Don't unlink associated streambuf if eof detected (in _M_get). Why ? Are you working with a streambuf_type implementation that can return eof at some moment and later return something else ? I don't think istreambuf_iterator has been designed to work with such a streambuf_type implementation. Your streambuf_type should block until it fetches data, just do it in a background thread if you don't want to block all your application while waiting for it. However your request made me consider this implementation, I wonder why it is done this way. Especially why the mutable keywords ? I would have expected an implementation more consistent with the istream_iterator implementation reading current character on construction like in the attached patch. Is it because of the _GLIBCXX_USE_NOEXCEPT constraint on the constructors ? Can sgetc() throw ? François --------------C88E5B199C1BDD7A1AA6EDDE Content-Type: text/x-patch; name="istreambuf_iterator.h.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="istreambuf_iterator.h.patch" Content-length: 3102 diff --git a/libstdc++-v3/include/bits/streambuf_iterator.h b/libstdc++-v3/include/bits/streambuf_iterator.h index f0451b1..d73fedf 100644 --- a/libstdc++-v3/include/bits/streambuf_iterator.h +++ b/libstdc++-v3/include/bits/streambuf_iterator.h @@ -94,8 +94,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // the "end of stream" iterator value. // NB: This implementation assumes the "end of stream" value // is EOF, or -1. - mutable streambuf_type* _M_sbuf; - mutable int_type _M_c; + streambuf_type* _M_sbuf; + int_type _M_c; public: /// Construct end of input stream iterator. @@ -103,18 +103,26 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : _M_sbuf(0), _M_c(traits_type::eof()) { } #if __cplusplus >= 201103L - istreambuf_iterator(const istreambuf_iterator&) noexcept = default; + istreambuf_iterator(const istreambuf_iterator&) = default; ~istreambuf_iterator() = default; #endif /// Construct start of input stream iterator. istreambuf_iterator(istream_type& __s) _GLIBCXX_USE_NOEXCEPT - : _M_sbuf(__s.rdbuf()), _M_c(traits_type::eof()) { } + : _M_sbuf(__s.rdbuf()), _M_c(traits_type::eof()) + { + if (_M_sbuf) + _M_get(); + } /// Construct start of streambuf iterator. istreambuf_iterator(streambuf_type* __s) _GLIBCXX_USE_NOEXCEPT - : _M_sbuf(__s), _M_c(traits_type::eof()) { } + : _M_sbuf(__s), _M_c(traits_type::eof()) + { + if (_M_sbuf) + _M_get(); + } /// Return the current character pointed to by iterator. This returns /// streambuf.sgetc(). It cannot be assigned. NB: The result of @@ -129,7 +137,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _M_message(__gnu_debug::__msg_deref_istreambuf) ._M_iterator(*this)); #endif - return traits_type::to_char_type(_M_get()); + return traits_type::to_char_type(_M_c); } /// Advance the iterator. Calls streambuf.sbumpc(). @@ -142,7 +150,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION if (_M_sbuf) { _M_sbuf->sbumpc(); - _M_c = traits_type::eof(); + _M_get(); } return *this; } @@ -159,7 +167,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION if (_M_sbuf) { __old._M_c = _M_sbuf->sbumpc(); - _M_c = traits_type::eof(); + _M_get(); } return __old; } @@ -174,28 +182,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION private: int_type - _M_get() const + _M_get() { - const int_type __eof = traits_type::eof(); - int_type __ret = __eof; - if (_M_sbuf) - { - if (!traits_type::eq_int_type(_M_c, __eof)) - __ret = _M_c; - else if (!traits_type::eq_int_type((__ret = _M_sbuf->sgetc()), - __eof)) - _M_c = __ret; - else - _M_sbuf = 0; - } - return __ret; + _M_c = _M_sbuf->sgetc(); + if (_M_at_eof()) + _M_sbuf = 0; + return _M_c; } bool _M_at_eof() const { const int_type __eof = traits_type::eof(); - return traits_type::eq_int_type(_M_get(), __eof); + return traits_type::eq_int_type(_M_c, __eof); } }; --------------C88E5B199C1BDD7A1AA6EDDE--