mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-06 22:15:31 +00:00
ICU-20048 Remove use of std::align() for compat with g++ 4.9.
This commit is contained in:
parent
c2a56df68d
commit
3ac2da2044
1 changed files with 7 additions and 4 deletions
|
@ -225,13 +225,16 @@ ucnv_safeClone(const UConverter* cnv, void *stackBuffer, int32_t *pBufferSize, U
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/* Adjust (if necessary) the stackBuffer pointer to be aligned correctly for a UConverter.
|
||||
* TODO(Jira ICU-20736) Redo this using std::align() once g++4.9 compatibility is no longer needed.
|
||||
*/
|
||||
size_t altStackBufferSize = stackBufferSize; // Incompatible types for passing by reference.
|
||||
if (stackBuffer) {
|
||||
if (std::align(alignof(UConverter), bufferSizeNeeded, stackBuffer, altStackBufferSize)) {
|
||||
stackBufferSize = static_cast<int32_t>(altStackBufferSize);
|
||||
uintptr_t p = reinterpret_cast<uintptr_t>(stackBuffer);
|
||||
uintptr_t aligned_p = (p + alignof(UConverter) - 1) & ~(alignof(UConverter) - 1);
|
||||
ptrdiff_t pointerAdjustment = aligned_p - p;
|
||||
if (bufferSizeNeeded + pointerAdjustment <= stackBufferSize) {
|
||||
stackBuffer = reinterpret_cast<void *>(aligned_p);
|
||||
stackBufferSize -= pointerAdjustment;
|
||||
} else {
|
||||
/* prevent using the stack buffer but keep the size > 0 so that we do not just preflight */
|
||||
stackBufferSize = 1;
|
||||
|
|
Loading…
Add table
Reference in a new issue