mirror of
https://github.com/postgres/postgres.git
synced 2025-06-06 00:02:36 -04:00
Change the PageGetContents() macro to guarantee its result is maxalign'd,
thereby forestalling any problems with alignment of the data structure placed there. Since SizeOfPageHeaderData is maxalign'd anyway in 8.3 and HEAD, this does not actually change anything right now, but it is foreseeable that the header size will change again someday. I had to fix a couple of places that were assuming that the content offset is just SizeOfPageHeaderData rather than MAXALIGN(SizeOfPageHeaderData). Per discussion of Zdenek's page-macros patch.
This commit is contained in:
parent
9d035f4254
commit
6816577a78
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/storage/page/bufpage.c,v 1.79 2008/05/13 15:44:08 momjian Exp $
|
* $PostgreSQL: pgsql/src/backend/storage/page/bufpage.c,v 1.80 2008/07/13 21:50:04 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -260,7 +260,6 @@ Page
|
|||||||
PageGetTempPage(Page page, Size specialSize)
|
PageGetTempPage(Page page, Size specialSize)
|
||||||
{
|
{
|
||||||
Size pageSize;
|
Size pageSize;
|
||||||
Size size;
|
|
||||||
Page temp;
|
Page temp;
|
||||||
PageHeader thdr;
|
PageHeader thdr;
|
||||||
|
|
||||||
@ -271,15 +270,13 @@ PageGetTempPage(Page page, Size specialSize)
|
|||||||
/* copy old page in */
|
/* copy old page in */
|
||||||
memcpy(temp, page, pageSize);
|
memcpy(temp, page, pageSize);
|
||||||
|
|
||||||
/* clear out the middle */
|
|
||||||
size = pageSize - SizeOfPageHeaderData;
|
|
||||||
size -= MAXALIGN(specialSize);
|
|
||||||
MemSet(PageGetContents(thdr), 0, size);
|
|
||||||
|
|
||||||
/* set high, low water marks */
|
/* set high, low water marks */
|
||||||
thdr->pd_lower = SizeOfPageHeaderData;
|
thdr->pd_lower = SizeOfPageHeaderData;
|
||||||
thdr->pd_upper = pageSize - MAXALIGN(specialSize);
|
thdr->pd_upper = pageSize - MAXALIGN(specialSize);
|
||||||
|
|
||||||
|
/* clear out the middle */
|
||||||
|
MemSet((char *) temp + thdr->pd_lower, 0, thdr->pd_upper - thdr->pd_lower);
|
||||||
|
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright (c) 2006-2008, PostgreSQL Global Development Group
|
* Copyright (c) 2006-2008, PostgreSQL Global Development Group
|
||||||
*
|
*
|
||||||
* $PostgreSQL: pgsql/src/include/access/gin.h,v 1.23 2008/07/11 21:06:29 tgl Exp $
|
* $PostgreSQL: pgsql/src/include/access/gin.h,v 1.24 2008/07/13 21:50:04 tgl Exp $
|
||||||
*--------------------------------------------------------------------------
|
*--------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -121,17 +121,19 @@ typedef struct
|
|||||||
/*
|
/*
|
||||||
* Data (posting tree) pages
|
* Data (posting tree) pages
|
||||||
*/
|
*/
|
||||||
|
#define GinDataPageGetRightBound(page) ((ItemPointer) PageGetContents(page))
|
||||||
#define GinDataPageGetData(page) \
|
#define GinDataPageGetData(page) \
|
||||||
(PageGetContents(page)+MAXALIGN(sizeof(ItemPointerData)))
|
(PageGetContents(page) + MAXALIGN(sizeof(ItemPointerData)))
|
||||||
#define GinDataPageGetRightBound(page) ((ItemPointer)PageGetContents(page))
|
#define GinSizeOfItem(page) \
|
||||||
#define GinSizeOfItem(page) ( (GinPageIsLeaf(page)) ? sizeof(ItemPointerData) : sizeof(PostingItem) )
|
(GinPageIsLeaf(page) ? sizeof(ItemPointerData) : sizeof(PostingItem))
|
||||||
#define GinDataPageGetItem(page,i) ( GinDataPageGetData(page) + ((i)-1) * GinSizeOfItem(page) )
|
#define GinDataPageGetItem(page,i) \
|
||||||
|
(GinDataPageGetData(page) + ((i)-1) * GinSizeOfItem(page))
|
||||||
|
|
||||||
#define GinDataPageGetFreeSpace(page) \
|
#define GinDataPageGetFreeSpace(page) \
|
||||||
( BLCKSZ - SizeOfPageHeaderData - MAXALIGN(sizeof(GinPageOpaqueData)) - \
|
(BLCKSZ - MAXALIGN(SizeOfPageHeaderData) \
|
||||||
GinPageGetOpaque(page)->maxoff * GinSizeOfItem(page) - \
|
- MAXALIGN(sizeof(ItemPointerData)) \
|
||||||
MAXALIGN(sizeof(ItemPointerData)))
|
- GinPageGetOpaque(page)->maxoff * GinSizeOfItem(page) \
|
||||||
|
- MAXALIGN(sizeof(GinPageOpaqueData)))
|
||||||
|
|
||||||
|
|
||||||
#define GIN_UNLOCK BUFFER_LOCK_UNLOCK
|
#define GIN_UNLOCK BUFFER_LOCK_UNLOCK
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $PostgreSQL: pgsql/src/include/storage/bufpage.h,v 1.81 2008/06/08 22:00:48 alvherre Exp $
|
* $PostgreSQL: pgsql/src/include/storage/bufpage.h,v 1.82 2008/07/13 21:50:04 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -206,9 +206,13 @@ typedef PageHeaderData *PageHeader;
|
|||||||
/*
|
/*
|
||||||
* PageGetContents
|
* PageGetContents
|
||||||
* To be used in case the page does not contain item pointers.
|
* To be used in case the page does not contain item pointers.
|
||||||
|
*
|
||||||
|
* Note: prior to 8.3 this was not guaranteed to yield a MAXALIGN'd result.
|
||||||
|
* Now it is. Beware of old code that might think the offset to the contents
|
||||||
|
* is just SizeOfPageHeaderData rather than MAXALIGN(SizeOfPageHeaderData).
|
||||||
*/
|
*/
|
||||||
#define PageGetContents(page) \
|
#define PageGetContents(page) \
|
||||||
((char *) (&((PageHeader) (page))->pd_linp[0]))
|
((char *) (page) + MAXALIGN(SizeOfPageHeaderData))
|
||||||
|
|
||||||
/* ----------------
|
/* ----------------
|
||||||
* macros to access page size info
|
* macros to access page size info
|
||||||
|
Loading…
x
Reference in New Issue
Block a user