8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.112 2001/03/22 06:16:07 momjian Exp $
11
+ * $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.113 2001/03/25 23:23:58 tgl Exp $
12
12
*
13
13
*
14
14
* INTERFACE ROUTINES
@@ -2126,10 +2126,19 @@ static XLogRecPtr
2126
2126
log_heap_update (Relation reln , Buffer oldbuf , ItemPointerData from ,
2127
2127
Buffer newbuf , HeapTuple newtup , bool move )
2128
2128
{
2129
- char tbuf [MAXALIGN (sizeof (xl_heap_header )) + 2 * sizeof (TransactionId )];
2130
- xl_heap_update xlrec ;
2131
- xl_heap_header * xlhdr = (xl_heap_header * ) tbuf ;
2129
+ /*
2130
+ * Note: xlhdr is declared to have adequate size and correct alignment
2131
+ * for an xl_heap_header. However the two tids, if present at all,
2132
+ * will be packed in with no wasted space after the xl_heap_header;
2133
+ * they aren't necessarily aligned as implied by this struct declaration.
2134
+ */
2135
+ struct {
2136
+ xl_heap_header hdr ;
2137
+ TransactionId tid1 ;
2138
+ TransactionId tid2 ;
2139
+ } xlhdr ;
2132
2140
int hsize = SizeOfHeapHeader ;
2141
+ xl_heap_update xlrec ;
2133
2142
XLogRecPtr recptr ;
2134
2143
XLogRecData rdata [4 ];
2135
2144
Page page = BufferGetPage (newbuf );
@@ -2148,10 +2157,10 @@ log_heap_update(Relation reln, Buffer oldbuf, ItemPointerData from,
2148
2157
rdata [1 ].len = 0 ;
2149
2158
rdata [1 ].next = & (rdata [2 ]);
2150
2159
2151
- xlhdr -> t_oid = newtup -> t_data -> t_oid ;
2152
- xlhdr -> t_natts = newtup -> t_data -> t_natts ;
2153
- xlhdr -> t_hoff = newtup -> t_data -> t_hoff ;
2154
- xlhdr -> mask = newtup -> t_data -> t_infomask ;
2160
+ xlhdr . hdr . t_oid = newtup -> t_data -> t_oid ;
2161
+ xlhdr . hdr . t_natts = newtup -> t_data -> t_natts ;
2162
+ xlhdr . hdr . t_hoff = newtup -> t_data -> t_hoff ;
2163
+ xlhdr . hdr . mask = newtup -> t_data -> t_infomask ;
2155
2164
if (move ) /* remember xmin & xmax */
2156
2165
{
2157
2166
TransactionId xmax ;
@@ -2161,13 +2170,13 @@ log_heap_update(Relation reln, Buffer oldbuf, ItemPointerData from,
2161
2170
xmax = InvalidTransactionId ;
2162
2171
else
2163
2172
xmax = newtup -> t_data -> t_xmax ;
2164
- memcpy (tbuf + hsize , & xmax , sizeof (TransactionId ));
2165
- memcpy (tbuf + hsize + sizeof (TransactionId ),
2173
+ memcpy (( char * ) & xlhdr + hsize , & xmax , sizeof (TransactionId ));
2174
+ memcpy (( char * ) & xlhdr + hsize + sizeof (TransactionId ),
2166
2175
& (newtup -> t_data -> t_xmin ), sizeof (TransactionId ));
2167
- hsize += ( 2 * sizeof (TransactionId ) );
2176
+ hsize += 2 * sizeof (TransactionId );
2168
2177
}
2169
2178
rdata [2 ].buffer = newbuf ;
2170
- rdata [2 ].data = (char * ) xlhdr ;
2179
+ rdata [2 ].data = (char * ) & xlhdr ;
2171
2180
rdata [2 ].len = hsize ;
2172
2181
rdata [2 ].next = & (rdata [3 ]);
2173
2182
@@ -2228,13 +2237,16 @@ heap_xlog_clean(bool redo, XLogRecPtr lsn, XLogRecord *record)
2228
2237
2229
2238
if (record -> xl_len > SizeOfHeapClean )
2230
2239
{
2231
- char unbuf [BLCKSZ ];
2232
- OffsetNumber * unused = ( OffsetNumber * ) unbuf ;
2240
+ OffsetNumber unbuf [BLCKSZ / sizeof ( OffsetNumber ) ];
2241
+ OffsetNumber * unused = unbuf ;
2233
2242
char * unend ;
2234
2243
ItemId lp ;
2235
2244
2236
- memcpy (unbuf , (char * ) xlrec + SizeOfHeapClean , record -> xl_len - SizeOfHeapClean );
2237
- unend = unbuf + (record -> xl_len - SizeOfHeapClean );
2245
+ Assert ((record -> xl_len - SizeOfHeapClean ) <= BLCKSZ );
2246
+ memcpy ((char * ) unbuf ,
2247
+ (char * ) xlrec + SizeOfHeapClean ,
2248
+ record -> xl_len - SizeOfHeapClean );
2249
+ unend = (char * ) unbuf + (record -> xl_len - SizeOfHeapClean );
2238
2250
2239
2251
while ((char * ) unused < unend )
2240
2252
{
@@ -2318,7 +2330,6 @@ heap_xlog_insert(bool redo, XLogRecPtr lsn, XLogRecord *record)
2318
2330
Buffer buffer ;
2319
2331
Page page ;
2320
2332
OffsetNumber offnum ;
2321
- HeapTupleHeader htup ;
2322
2333
2323
2334
if (redo && (record -> xl_info & XLR_BKP_BLOCK_1 ))
2324
2335
return ;
@@ -2338,7 +2349,11 @@ heap_xlog_insert(bool redo, XLogRecPtr lsn, XLogRecord *record)
2338
2349
2339
2350
if (redo )
2340
2351
{
2341
- char tbuf [MaxTupleSize ];
2352
+ struct {
2353
+ HeapTupleHeaderData hdr ;
2354
+ char data [MaxTupleSize ];
2355
+ } tbuf ;
2356
+ HeapTupleHeader htup ;
2342
2357
xl_heap_header xlhdr ;
2343
2358
uint32 newlen ;
2344
2359
@@ -2359,11 +2374,15 @@ heap_xlog_insert(bool redo, XLogRecPtr lsn, XLogRecord *record)
2359
2374
elog (STOP , "heap_insert_redo: invalid max offset number" );
2360
2375
2361
2376
newlen = record -> xl_len - SizeOfHeapInsert - SizeOfHeapHeader ;
2362
- memcpy ((char * ) & xlhdr , (char * ) xlrec + SizeOfHeapInsert , SizeOfHeapHeader );
2363
- memcpy (tbuf + offsetof(HeapTupleHeaderData , t_bits ),
2364
- (char * ) xlrec + SizeOfHeapInsert + SizeOfHeapHeader , newlen );
2377
+ Assert (newlen <= MaxTupleSize );
2378
+ memcpy ((char * ) & xlhdr ,
2379
+ (char * ) xlrec + SizeOfHeapInsert ,
2380
+ SizeOfHeapHeader );
2381
+ memcpy ((char * ) & tbuf + offsetof(HeapTupleHeaderData , t_bits ),
2382
+ (char * ) xlrec + SizeOfHeapInsert + SizeOfHeapHeader ,
2383
+ newlen );
2365
2384
newlen += offsetof(HeapTupleHeaderData , t_bits );
2366
- htup = ( HeapTupleHeader ) tbuf ;
2385
+ htup = & tbuf . hdr ;
2367
2386
htup -> t_oid = xlhdr .t_oid ;
2368
2387
htup -> t_natts = xlhdr .t_natts ;
2369
2388
htup -> t_hoff = xlhdr .t_hoff ;
@@ -2496,7 +2515,10 @@ newsame:;
2496
2515
2497
2516
if (redo )
2498
2517
{
2499
- char tbuf [MaxTupleSize ];
2518
+ struct {
2519
+ HeapTupleHeaderData hdr ;
2520
+ char data [MaxTupleSize ];
2521
+ } tbuf ;
2500
2522
xl_heap_header xlhdr ;
2501
2523
int hsize ;
2502
2524
uint32 newlen ;
@@ -2522,20 +2544,27 @@ newsame:;
2522
2544
hsize += (2 * sizeof (TransactionId ));
2523
2545
2524
2546
newlen = record -> xl_len - hsize ;
2525
- memcpy ((char * ) & xlhdr , (char * ) xlrec + SizeOfHeapUpdate , SizeOfHeapHeader );
2526
- memcpy (tbuf + offsetof(HeapTupleHeaderData , t_bits ),
2527
- (char * ) xlrec + hsize , newlen );
2547
+ Assert (newlen <= MaxTupleSize );
2548
+ memcpy ((char * ) & xlhdr ,
2549
+ (char * ) xlrec + SizeOfHeapUpdate ,
2550
+ SizeOfHeapHeader );
2551
+ memcpy ((char * ) & tbuf + offsetof(HeapTupleHeaderData , t_bits ),
2552
+ (char * ) xlrec + hsize ,
2553
+ newlen );
2528
2554
newlen += offsetof(HeapTupleHeaderData , t_bits );
2529
- htup = ( HeapTupleHeader ) tbuf ;
2555
+ htup = & tbuf . hdr ;
2530
2556
htup -> t_oid = xlhdr .t_oid ;
2531
2557
htup -> t_natts = xlhdr .t_natts ;
2532
2558
htup -> t_hoff = xlhdr .t_hoff ;
2533
2559
if (move )
2534
2560
{
2535
2561
hsize = SizeOfHeapUpdate + SizeOfHeapHeader ;
2536
- memcpy (& (htup -> t_xmax ), (char * ) xlrec + hsize , sizeof (TransactionId ));
2562
+ memcpy (& (htup -> t_xmax ),
2563
+ (char * ) xlrec + hsize ,
2564
+ sizeof (TransactionId ));
2537
2565
memcpy (& (htup -> t_xmin ),
2538
- (char * ) xlrec + hsize + sizeof (TransactionId ), sizeof (TransactionId ));
2566
+ (char * ) xlrec + hsize + sizeof (TransactionId ),
2567
+ sizeof (TransactionId ));
2539
2568
TransactionIdStore (record -> xl_xid , (TransactionId * ) & (htup -> t_cmin ));
2540
2569
htup -> t_infomask = xlhdr .mask ;
2541
2570
htup -> t_infomask &= ~(HEAP_XMIN_COMMITTED |
0 commit comments