Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5962519

Browse files
committed
TYPEALIGN doesn't work on int64 on 32-bit platforms.
The TYPEALIGN macro, and the related ones like MAXALIGN, don't work withvalues larger than intptr_t, because TYPEALIGN casts the argument tointptr_t to do the arithmetic. That's not a problem when dealing withpointers or lengths or offsets related to pointers, but the XLogInsertscaling patch added a call to MAXALIGN with an XLogRecPtr argument.To fix, add wider variants of the macros, called TYPEALIGN64 and MAXALIGN64,which are just like the existing variants but work with uint64 instead ofintptr_t.Report and patch by David Rowley, analysis by Andres Freund.
1 parent81fbbfe commit5962519

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

‎src/backend/access/transam/xlog.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1482,7 +1482,7 @@ CopyXLogRecordToWAL(int write_len, bool isLogSwitch, XLogRecData *rdata,
14821482
Assert(written==write_len);
14831483

14841484
/* Align the end position, so that the next record starts aligned */
1485-
CurrPos=MAXALIGN(CurrPos);
1485+
CurrPos=MAXALIGN64(CurrPos);
14861486

14871487
/*
14881488
* If this was an xlog-switch, it's not enough to write the switch record,

‎src/include/c.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,18 @@ typedef NameData *Name;
551551
#defineDOUBLEALIGN_DOWN(LEN)TYPEALIGN_DOWN(ALIGNOF_DOUBLE, (LEN))
552552
#defineMAXALIGN_DOWN(LEN)TYPEALIGN_DOWN(MAXIMUM_ALIGNOF, (LEN))
553553

554+
/*
555+
* The above macros will not work with types wider than intptr_t, like with
556+
* uint64 on 32-bit platforms. That's not problem for the usual use where a
557+
* pointer or a length is aligned, but for the odd case that you need to
558+
* align something (potentially) wider, use TYPEALIGN64.
559+
*/
560+
#defineTYPEALIGN64(ALIGNVAL,LEN) \
561+
(((uint64) (LEN) + ((ALIGNVAL) - 1)) & ~((uint64) ((ALIGNVAL) - 1)))
562+
563+
/* we don't currently need wider versions of the other ALIGN macros */
564+
#defineMAXALIGN64(LEN)TYPEALIGN64(MAXIMUM_ALIGNOF, (LEN))
565+
554566
/* ----------------------------------------------------------------
555567
*Section 6:assertions
556568
* ----------------------------------------------------------------

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp