Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
R
rapidjson
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
rapidjson
Commits
311b4822
Commit
311b4822
authored
Sep 01, 2015
by
Milo Yip
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Try to fix incorrect 64-bit alignment
Added unit tests for alignment macros. Fixes #418
parent
3ede21c3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
3 deletions
+23
-3
rapidjson.h
include/rapidjson/rapidjson.h
+3
-3
allocatorstest.cpp
test/unittest/allocatorstest.cpp
+20
-0
No files found.
include/rapidjson/rapidjson.h
View file @
311b4822
...
...
@@ -238,13 +238,13 @@
\param x pointer to align
Some machines require strict data alignment. Currently the default uses 4 bytes
alignment. User can customize by defining the RAPIDJSON_ALIGN function macro.
,
alignment. User can customize by defining the RAPIDJSON_ALIGN function macro.
*/
#ifndef RAPIDJSON_ALIGN
#if RAPIDJSON_64BIT == 1
#define RAPIDJSON_ALIGN(x) ((
x + 7u) & ~7u
)
#define RAPIDJSON_ALIGN(x) ((
(x) + static_cast<uint64_t>(7u)) & ~static_cast<uint64_t>(7u)
)
#else
#define RAPIDJSON_ALIGN(x) ((
x
+ 3u) & ~3u)
#define RAPIDJSON_ALIGN(x) ((
(x)
+ 3u) & ~3u)
#endif
#endif
...
...
test/unittest/allocatorstest.cpp
View file @
311b4822
...
...
@@ -61,3 +61,23 @@ TEST(Allocator, MemoryPoolAllocator) {
EXPECT_LE
(
a
.
Size
(),
a
.
Capacity
());
}
}
TEST
(
Allocator
,
Alignment
)
{
#if RAPIDJSON_64BIT == 1
EXPECT_EQ
(
RAPIDJSON_UINT64_C2
(
0x00000000
,
0x00000000
),
RAPIDJSON_ALIGN
(
0
));
for
(
uint64_t
i
=
1
;
i
<
8
;
i
++
)
{
EXPECT_EQ
(
RAPIDJSON_UINT64_C2
(
0x00000000
,
0x00000008
),
RAPIDJSON_ALIGN
(
i
));
EXPECT_EQ
(
RAPIDJSON_UINT64_C2
(
0x00000000
,
0x00000010
),
RAPIDJSON_ALIGN
(
RAPIDJSON_UINT64_C2
(
0x00000000
,
0x00000008
)
+
i
));
EXPECT_EQ
(
RAPIDJSON_UINT64_C2
(
0x00000001
,
0x00000000
),
RAPIDJSON_ALIGN
(
RAPIDJSON_UINT64_C2
(
0x00000000
,
0xFFFFFFF8
)
+
i
));
EXPECT_EQ
(
RAPIDJSON_UINT64_C2
(
0xFFFFFFFF
,
0xFFFFFFF8
),
RAPIDJSON_ALIGN
(
RAPIDJSON_UINT64_C2
(
0xFFFFFFFF
,
0xFFFFFFF0
)
+
i
));
}
#else
EXPECT_EQ
(
0u
,
RAPIDJSON_ALIGN
(
0u
));
for
(
uint32_t
i
=
1
;
i
<
4
;
i
++
)
{
EXPECT_EQ
(
4u
,
RAPIDJSON_ALIGN
(
i
));
EXPECT_EQ
(
8u
,
RAPIDJSON_ALIGN
(
4u
+
i
));
EXPECT_EQ
(
0xFFFFFFF8u
,
RAPIDJSON_ALIGN
(
0xFFFFFFF4u
+
i
));
EXPECT_EQ
(
0xFFFFFFFCu
,
RAPIDJSON_ALIGN
(
0xFFFFFFF8u
+
i
));
}
#endif
}
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