Archived issue #0032920

Coding - fix checking of std::stringstream buffer size on VS2019/C++20

Open CASCADEOCCT:Codingclosed12 public notes

Search issues

Description

Microsoft Visual Studio Professional 2019
Version 16.11.11
std=c++20

Replace `strange` method of defining available character count by simple one.
    
test bugs fclasses bug31189 fails because of method
std::stringstream::rdbuf::in_avail() returned 0 for not empty string.
When test on gcc/c++20, some case has next result:
     - For string "123456789012345" it gets 1.
     - For string "1234567890123456" it gets 16.
On MSVS 2019/c++20 for string "Sender message 2" it gets 0 for particular case.
This is the reason of test failure.

Description of `in_avail` method is some misty, so
change it to convenient one std::string::empty().

Steps to reproduce

Not required

Public activity

12 archived notes

Participants are labeled by their role within this record.

01Commenter 1
The objective of this 'strange' method is to check if buffer is empty or not and to avoid extra steps in this case.

As far as I understand, std::stringstream::str() will create a new string each time, and Message buffer is trying to skip it when it is not necessary.
std::stringstream is further passed to the messenger, which also calls std::stringstream::str() under the hood, but might skip this call if message has too low gravity.

While fixing this method, it is desired to update further calls as well (for instance, it doesn't make sense calling str() multiple times; it is still desired to consider avoiding string builder if it is not going to pass gravity filter).
02Commenter 2
Branch [archived branch] has been created by Author.

[revision removed]


Detailed log of new commits:

Author: Dmitry DZAMA
Date: Mon Apr 4 07:29:42 2022 +0300

    0032920: Fix an error of incorrect checking of std::stringstream buffer size, available for reading
    
    Microsoft Visual Studio Professional 2019
    Version 16.11.11
    std=c++20
    
    Replace `strange` method of defining available character count by simple one.
    
    test bugs fclasses bug31189 fails because of method
    std::stringstream::rdbuf::in_avail() returned 0 for not empty string.
    When test on gcc/c++20, some case has next result:
         - For string "123456789012345" it gets 1.
         - For string "1234567890123456" it gets 16.
    On MSVS 2019/c++20 for string "Sender message 2" it gets 0 for particular case.
    This is the reason of test failure.
    
    Description of `in_avail` method is some misty, so
    change it to convenient one std::string::empty().
03Commenter 2
Branch [archived branch] has been updated forcibly by Author.

[revision removed]
04Commenter 2
Branch [archived branch] has been updated forcibly by Author.

[revision removed]
05Commenter 2
Branch [archived branch] has been updated forcibly by Author.

[revision removed]
06Commenter 2
Branch [archived branch] has been updated forcibly by Author.

[revision removed]
07Commenter 1
Commenter 3,

> Kirill's Gavrilov review comment:
> The objective of this 'strange' method is to check if buffer is
> empty or not and to avoid extra steps in this case.

Git commit description is not a personal notebook, it should provide meaningful description to the change, not the history of discussions from a bug tracker.
08Commenter 2
Branch [archived branch] has been created by Commenter 1.

[revision removed]


Detailed log of new commits:

Author: Dmitry DZAMA
Date: Mon Apr 4 07:29:42 2022 +0300

    0032920: Coding - fix checking of std::stringstream buffer size on VS2019/C++20
    
    Use tellp() instead of in_avail() for testing non-empty std::stringstream state.
09Commenter 1
Commenter 3, please check if patch in branch CR32920_1 solves the problem.
10Commenter 10
Combination -
OCCT branch : [archived branch]
master SHA - [revision removed]
[revision removed]
Products branch : [archived branch] SHA - [revision removed]
was compiled on Linux, MacOS and Windows platforms and tested in optimize mode.

Number of compiler warnings:
No new/fixed warnings

Regressions/Differences/Improvements:
No regressions/differences

CPU differences:
Debian80-64:
OCCT
Total CPU difference: 18668.100000000675 / 18636.43000000061 [+0.17%]
Products
Total CPU difference: 11742.710000000114 / 11717.180000000135 [+0.22%]
Windows-64-VC14:
OCCT
Total CPU difference: 20733.796875 / 20693.28125 [+0.20%]
Products
Total CPU difference: 13272.875 / 13248.015625 [+0.19%]


Image differences :
No differences that require special attention

Memory differences :
No differences that require special attention
11Commenter 2
Branch [archived branch] has been deleted by Participant.

[revision removed]
12Commenter 2
Branch [archived branch] has been deleted by Participant.

[revision removed]

Related records