Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
d1eae33f
Commit
d1eae33f
authored
Apr 12, 2017
by
Matthias Vallentin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Workaround bug in standard
Turns out gpbump/pbump are not 64-bit safe in the C++ standard.
parent
027d2735
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
11 deletions
+51
-11
libcaf_core/caf/streambuf.hpp
libcaf_core/caf/streambuf.hpp
+51
-11
No files found.
libcaf_core/caf/streambuf.hpp
View file @
d1eae33f
...
@@ -23,7 +23,9 @@
...
@@ -23,7 +23,9 @@
#include <algorithm>
#include <algorithm>
#include <cstddef>
#include <cstddef>
#include <cstring>
#include <cstring>
#include <limits>
#include <streambuf>
#include <streambuf>
#include <type_traits>
#include <vector>
#include <vector>
#include "caf/config.hpp"
#include "caf/config.hpp"
...
@@ -31,11 +33,53 @@
...
@@ -31,11 +33,53 @@
namespace
caf
{
namespace
caf
{
/// The base class for all stream buffer implementations.
template
<
class
CharT
=
char
,
class
Traits
=
std
::
char_traits
<
CharT
>
>
class
stream_buffer
:
public
std
::
basic_streambuf
<
CharT
,
Traits
>
{
protected:
/// The standard only defines pbump(int), which can overflow on 64-bit
/// architectures. All stream buffer implementations should therefore use
/// these function instead. For a detailed discussion, see:
/// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47921
template
<
class
T
=
int
>
typename
std
::
enable_if
<
sizeof
(
T
)
==
4
>::
type
safe_pbump
(
std
::
streamsize
n
)
{
while
(
n
>
std
::
numeric_limits
<
int
>::
max
())
{
this
->
pbump
(
std
::
numeric_limits
<
int
>::
max
());
n
-=
std
::
numeric_limits
<
int
>::
max
();
}
this
->
pbump
(
static_cast
<
int
>
(
n
));
}
template
<
class
T
=
int
>
typename
std
::
enable_if
<
sizeof
(
T
)
==
8
>::
type
safe_pbump
(
std
::
streamsize
n
)
{
this
->
pbump
(
static_cast
<
int
>
(
n
));
}
// As above, but for the get area.
template
<
class
T
=
int
>
typename
std
::
enable_if
<
sizeof
(
T
)
==
4
>::
type
safe_gbump
(
std
::
streamsize
n
)
{
while
(
n
>
std
::
numeric_limits
<
int
>::
max
())
{
this
->
gbump
(
std
::
numeric_limits
<
int
>::
max
());
n
-=
std
::
numeric_limits
<
int
>::
max
();
}
this
->
gbump
(
static_cast
<
int
>
(
n
));
}
template
<
class
T
=
int
>
typename
std
::
enable_if
<
sizeof
(
T
)
==
8
>::
type
safe_gbump
(
std
::
streamsize
n
)
{
this
->
gbump
(
static_cast
<
int
>
(
n
));
}
};
/// A streambuffer abstraction over a fixed array of bytes. This streambuffer
/// A streambuffer abstraction over a fixed array of bytes. This streambuffer
/// cannot overflow/underflow. Once it has reached its end, attempts to read
/// cannot overflow/underflow. Once it has reached its end, attempts to read
/// characters will return `trait_type::eof`.
/// characters will return `trait_type::eof`.
template
<
class
CharT
=
char
,
class
Traits
=
std
::
char_traits
<
CharT
>
>
template
<
class
CharT
=
char
,
class
Traits
=
std
::
char_traits
<
CharT
>
>
class
arraybuf
:
public
st
d
::
basic_streambuf
<
CharT
,
Traits
>
{
class
arraybuf
:
public
st
ream_buffer
<
CharT
,
Traits
>
{
public:
public:
using
base
=
std
::
basic_streambuf
<
CharT
,
Traits
>
;
using
base
=
std
::
basic_streambuf
<
CharT
,
Traits
>
;
using
char_type
=
typename
base
::
char_type
;
using
char_type
=
typename
base
::
char_type
;
...
@@ -108,9 +152,7 @@ protected:
...
@@ -108,9 +152,7 @@ protected:
this
->
setg
(
this
->
eback
(),
this
->
eback
()
+
pos
,
this
->
egptr
());
this
->
setg
(
this
->
eback
(),
this
->
eback
()
+
pos
,
this
->
egptr
());
if
(
put
)
{
if
(
put
)
{
this
->
setp
(
this
->
pbase
(),
this
->
epptr
());
this
->
setp
(
this
->
pbase
(),
this
->
epptr
());
CAF_ASSERT
(
pos
>=
std
::
numeric_limits
<
int
>::
min
());
this
->
safe_pbump
(
pos
);
CAF_ASSERT
(
pos
<=
std
::
numeric_limits
<
int
>::
max
());
this
->
pbump
(
static_cast
<
int
>
(
pos
));
}
}
return
pos
;
return
pos
;
}
}
...
@@ -152,9 +194,7 @@ protected:
...
@@ -152,9 +194,7 @@ protected:
}
}
new_off
+=
off
;
new_off
+=
off
;
this
->
setp
(
this
->
pbase
(),
this
->
epptr
());
this
->
setp
(
this
->
pbase
(),
this
->
epptr
());
CAF_ASSERT
(
new_off
>=
std
::
numeric_limits
<
int
>::
min
());
this
->
safe_pbump
(
new_off
);
CAF_ASSERT
(
new_off
<=
std
::
numeric_limits
<
int
>::
max
());
this
->
pbump
(
static_cast
<
int
>
(
new_off
));
}
}
return
new_off
;
return
new_off
;
}
}
...
@@ -166,7 +206,7 @@ protected:
...
@@ -166,7 +206,7 @@ protected:
auto
actual
=
std
::
min
(
n
,
static_cast
<
std
::
streamsize
>
(
available
));
auto
actual
=
std
::
min
(
n
,
static_cast
<
std
::
streamsize
>
(
available
));
std
::
memcpy
(
this
->
pptr
(),
s
,
std
::
memcpy
(
this
->
pptr
(),
s
,
static_cast
<
size_t
>
(
actual
)
*
sizeof
(
char_type
));
static_cast
<
size_t
>
(
actual
)
*
sizeof
(
char_type
));
this
->
pbump
(
static_cast
<
int
>
(
actual
)
);
this
->
safe_pbump
(
actual
);
return
actual
;
return
actual
;
}
}
...
@@ -177,7 +217,7 @@ protected:
...
@@ -177,7 +217,7 @@ protected:
auto
actual
=
std
::
min
(
n
,
static_cast
<
std
::
streamsize
>
(
available
));
auto
actual
=
std
::
min
(
n
,
static_cast
<
std
::
streamsize
>
(
available
));
std
::
memcpy
(
s
,
this
->
gptr
(),
std
::
memcpy
(
s
,
this
->
gptr
(),
static_cast
<
size_t
>
(
actual
)
*
sizeof
(
char_type
));
static_cast
<
size_t
>
(
actual
)
*
sizeof
(
char_type
));
this
->
gbump
(
static_cast
<
int
>
(
actual
)
);
this
->
safe_gbump
(
actual
);
return
actual
;
return
actual
;
}
}
};
};
...
@@ -186,7 +226,7 @@ protected:
...
@@ -186,7 +226,7 @@ protected:
/// reading in the same style as `arraybuf`, but is unbounded for output.
/// reading in the same style as `arraybuf`, but is unbounded for output.
template
<
class
Container
>
template
<
class
Container
>
class
containerbuf
class
containerbuf
:
public
st
d
::
basic_streambuf
<
:
public
st
ream_buffer
<
typename
Container
::
value_type
,
typename
Container
::
value_type
,
std
::
char_traits
<
typename
Container
::
value_type
>
std
::
char_traits
<
typename
Container
::
value_type
>
>
{
>
{
...
@@ -251,7 +291,7 @@ protected:
...
@@ -251,7 +291,7 @@ protected:
auto
actual
=
std
::
min
(
n
,
static_cast
<
std
::
streamsize
>
(
available
));
auto
actual
=
std
::
min
(
n
,
static_cast
<
std
::
streamsize
>
(
available
));
std
::
memcpy
(
s
,
this
->
gptr
(),
std
::
memcpy
(
s
,
this
->
gptr
(),
static_cast
<
size_t
>
(
actual
)
*
sizeof
(
char_type
));
static_cast
<
size_t
>
(
actual
)
*
sizeof
(
char_type
));
this
->
gbump
(
static_cast
<
int
>
(
actual
)
);
this
->
safe_gbump
(
actual
);
return
actual
;
return
actual
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment