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

Commit6816577

Browse files
committed
Change the PageGetContents() macro to guarantee its result is maxalign'd,
thereby forestalling any problems with alignment of the data structure placedthere. Since SizeOfPageHeaderData is maxalign'd anyway in 8.3 and HEAD, thisdoes not actually change anything right now, but it is foreseeable that theheader size will change again someday. I had to fix a couple of places thatwere assuming that the content offset is just SizeOfPageHeaderData rather thanMAXALIGN(SizeOfPageHeaderData). Per discussion of Zdenek's page-macros patch.
1 parent9d035f4 commit6816577

File tree

3 files changed

+21
-18
lines changed

3 files changed

+21
-18
lines changed

‎src/backend/storage/page/bufpage.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/storage/page/bufpage.c,v 1.79 2008/05/1315:44:08 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/storage/page/bufpage.c,v 1.80 2008/07/1321:50:04 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -260,7 +260,6 @@ Page
260260
PageGetTempPage(Pagepage,SizespecialSize)
261261
{
262262
SizepageSize;
263-
Sizesize;
264263
Pagetemp;
265264
PageHeaderthdr;
266265

@@ -271,15 +270,13 @@ PageGetTempPage(Page page, Size specialSize)
271270
/* copy old page in */
272271
memcpy(temp,page,pageSize);
273272

274-
/* clear out the middle */
275-
size=pageSize-SizeOfPageHeaderData;
276-
size-=MAXALIGN(specialSize);
277-
MemSet(PageGetContents(thdr),0,size);
278-
279273
/* set high, low water marks */
280274
thdr->pd_lower=SizeOfPageHeaderData;
281275
thdr->pd_upper=pageSize-MAXALIGN(specialSize);
282276

277+
/* clear out the middle */
278+
MemSet((char*)temp+thdr->pd_lower,0,thdr->pd_upper-thdr->pd_lower);
279+
283280
returntemp;
284281
}
285282

‎src/include/access/gin.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
*Copyright (c) 2006-2008, PostgreSQL Global Development Group
66
*
7-
*$PostgreSQL: pgsql/src/include/access/gin.h,v 1.23 2008/07/11 21:06:29 tgl Exp $
7+
*$PostgreSQL: pgsql/src/include/access/gin.h,v 1.24 2008/07/13 21:50:04 tgl Exp $
88
*--------------------------------------------------------------------------
99
*/
1010

@@ -121,17 +121,19 @@ typedef struct
121121
/*
122122
* Data (posting tree) pages
123123
*/
124+
#defineGinDataPageGetRightBound(page)((ItemPointer) PageGetContents(page))
124125
#defineGinDataPageGetData(page)\
125-
(PageGetContents(page)+MAXALIGN(sizeof(ItemPointerData)))
126-
#defineGinDataPageGetRightBound(page)((ItemPointer)PageGetContents(page))
127-
#defineGinSizeOfItem(page) ( (GinPageIsLeaf(page)) ? sizeof(ItemPointerData) : sizeof(PostingItem) )
128-
#defineGinDataPageGetItem(page,i) ( GinDataPageGetData(page) + ((i)-1) * GinSizeOfItem(page) )
126+
(PageGetContents(page) + MAXALIGN(sizeof(ItemPointerData)))
127+
#defineGinSizeOfItem(page)\
128+
(GinPageIsLeaf(page) ? sizeof(ItemPointerData) : sizeof(PostingItem))
129+
#defineGinDataPageGetItem(page,i)\
130+
(GinDataPageGetData(page) + ((i)-1) * GinSizeOfItem(page))
129131

130132
#defineGinDataPageGetFreeSpace(page)\
131-
(BLCKSZ -SizeOfPageHeaderData -MAXALIGN(sizeof(GinPageOpaqueData)) - \
132-
GinPageGetOpaque(page)->maxoff * GinSizeOfItem(page) - \
133-
MAXALIGN(sizeof(ItemPointerData)))
134-
133+
(BLCKSZ - MAXALIGN(SizeOfPageHeaderData) \
134+
- MAXALIGN(sizeof(ItemPointerData)) \
135+
- GinPageGetOpaque(page)->maxoff * GinSizeOfItem(page) \
136+
- MAXALIGN(sizeof(GinPageOpaqueData)))
135137

136138

137139
#defineGIN_UNLOCKBUFFER_LOCK_UNLOCK

‎src/include/storage/bufpage.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/storage/bufpage.h,v 1.81 2008/06/08 22:00:48 alvherre Exp $
10+
* $PostgreSQL: pgsql/src/include/storage/bufpage.h,v 1.82 2008/07/13 21:50:04 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -206,9 +206,13 @@ typedef PageHeaderData *PageHeader;
206206
/*
207207
* PageGetContents
208208
*To be used in case the page does not contain item pointers.
209+
*
210+
* Note: prior to 8.3 this was not guaranteed to yield a MAXALIGN'd result.
211+
* Now it is. Beware of old code that might think the offset to the contents
212+
* is just SizeOfPageHeaderData rather than MAXALIGN(SizeOfPageHeaderData).
209213
*/
210214
#definePageGetContents(page) \
211-
((char *) (&((PageHeader) (page))->pd_linp[0]))
215+
((char *) (page) + MAXALIGN(SizeOfPageHeaderData))
212216

213217
/* ----------------
214218
*macros to access page size info

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp