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

Commit6febecc

Browse files
committed
Clean up att_align calculations so that XXXALIGN macros
need not be bogus.
1 parentd471f80 commit6febecc

File tree

5 files changed

+117
-136
lines changed

5 files changed

+117
-136
lines changed

‎src/backend/bootstrap/bootstrap.c

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Copyright (c) 1994, Regents of the University of California
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.56 1999/03/17 22:52:45 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.57 1999/03/25 03:49:25 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -605,8 +605,28 @@ DefineAttr(char *name, char *type, int attnum)
605605
printf("<%s %s> ",attrtypes[attnum]->attname.data,type);
606606
attrtypes[attnum]->attnum=1+attnum;/* fillatt */
607607
attlen=attrtypes[attnum]->attlen=Procid[typeoid].len;
608-
attrtypes[attnum]->attbyval= (attlen==1)|| (attlen==2)|| (attlen==4);
609-
attrtypes[attnum]->attalign='i';
608+
/* Cheat like mad to fill in these items from the length only.
609+
* This only has to work for types used in the system catalogs...
610+
*/
611+
switch (attlen)
612+
{
613+
case1:
614+
attrtypes[attnum]->attbyval= true;
615+
attrtypes[attnum]->attalign='c';
616+
break;
617+
case2:
618+
attrtypes[attnum]->attbyval= true;
619+
attrtypes[attnum]->attalign='s';
620+
break;
621+
case4:
622+
attrtypes[attnum]->attbyval= true;
623+
attrtypes[attnum]->attalign='i';
624+
break;
625+
default:
626+
attrtypes[attnum]->attbyval= false;
627+
attrtypes[attnum]->attalign='i';
628+
break;
629+
}
610630
}
611631
attrtypes[attnum]->attcacheoff=-1;
612632
attrtypes[attnum]->atttypmod=-1;

‎src/include/access/tupmacs.h

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: tupmacs.h,v 1.8 1999/02/13 23:20:59 momjian Exp $
9+
* $Id: tupmacs.h,v 1.9 1999/03/25 03:49:26 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -62,43 +62,22 @@
6262
(char *) (T) \
6363
)
6464

65+
/* att_align aligns the given offset as needed for a datum of length attlen
66+
* and alignment requirement attalign. In practice we don't need the length.
67+
* The attalign cases are tested in what is hopefully something like their
68+
* frequency of occurrence.
69+
*/
6570
#defineatt_align(cur_offset,attlen,attalign) \
6671
( \
67-
((attlen) < sizeof(int32)) ? \
68-
( \
69-
((attlen) == -1) ? \
70-
( \
71-
((attalign) == 'd') ? DOUBLEALIGN(cur_offset) : \
72-
INTALIGN(cur_offset) \
73-
) \
74-
: \
75-
( \
76-
((attlen) == sizeof(char)) ? \
77-
( \
78-
(long)(cur_offset) \
79-
) \
80-
: \
81-
( \
82-
AssertMacro((attlen) == sizeof(short)), \
83-
SHORTALIGN(cur_offset) \
84-
) \
85-
) \
86-
) \
87-
: \
88-
( \
89-
((attlen) == sizeof(int32)) ? \
90-
( \
91-
INTALIGN(cur_offset) \
92-
) \
93-
: \
72+
((attalign) == 'i') ? INTALIGN(cur_offset) : \
73+
(((attalign) == 'c') ? ((long)(cur_offset)) : \
74+
(((attalign) == 'd') ? DOUBLEALIGN(cur_offset) : \
9475
( \
95-
AssertMacro((attlen) > sizeof(int32)), \
96-
((attalign) == 'd') ? DOUBLEALIGN(cur_offset) : \
97-
LONGALIGN(cur_offset) \
98-
) \
99-
) \
76+
AssertMacro((attalign) == 's'), \
77+
SHORTALIGN(cur_offset) \
78+
))) \
10079
)
101-
80+
10281
#defineatt_addlength(cur_offset,attlen,attval) \
10382
( \
10483
((attlen) != -1) ? \

‎src/include/catalog/pg_type.h

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: pg_type.h,v 1.55 1999/03/10 05:02:34 tgl Exp $
10+
* $Id: pg_type.h,v 1.56 1999/03/25 03:49:25 tgl Exp $
1111
*
1212
* NOTES
1313
* the genbki.sh script reads this file and generates .bki
@@ -21,7 +21,7 @@
2121
#include<utils/rel.h>
2222

2323
/* ----------------
24-
*postgres.h contains the system typedefinintions and the
24+
*postgres.h contains the system typedefinitions and the
2525
*CATALOG(), BOOTSTRAP and DATA() sugar words so this file
2626
*can be read by both genbki.sh and the C compiler.
2727
* ----------------
@@ -53,44 +53,38 @@ CATALOG(pg_type) BOOTSTRAP
5353

5454
/*
5555
* typbyval determines whether internal Postgres routines pass a value
56-
* of this type by value or by reference. Postgres uses a 4 byte area
57-
* for passing a field value info, so if the value is not 1, 2, or 4
58-
* bytes long, Postgres does not have the option of passing by value
59-
* and ignores typbyval.
60-
*
61-
* (I don't understand why this column exists. The above description may
62-
* be an oversimplification. Also, there appear to be bugs in which
63-
* Postgres doesn't ignore typbyval when it should, but I'm afraid to
64-
* change them until I see proof of damage. -BRYANH 96.08).
65-
*
66-
* (Postgres crashes if typbyval is true, the declared length is 8, and
67-
* the I/O routines are written to expect pass by reference. Note that
68-
* float4 is written for pass by reference and has a declared length
69-
* of 4 bytes, so it looks like pass by reference must be consistant
70-
* with the declared length, and typbyval is used somewhere. - tgl
71-
* 1997-03-20).
56+
* of this type by value or by reference. Only char, short, and int-
57+
* equivalent items can be passed by value, so if the type is not
58+
* 1, 2, or 4 bytes long, Postgres does not have the option of passing
59+
* by value and so typbyval had better be FALSE. Variable-length types
60+
* are always passed by reference.
61+
* Note that typbyval can be false even if the length would allow
62+
* pass-by-value; this is currently true for type float4, for example.
7263
*/
7364
chartyptype;
65+
66+
/*
67+
* typtype is 'b' for a basic type and 'c' for a catalog type (ie a class).
68+
* If typtype is 'c', typrelid is the OID of the class' entry in pg_class.
69+
* (Why do we need an entry in pg_type for classes, anyway?)
70+
*/
7471
booltypisdefined;
7572
chartypdelim;
76-
Oidtyprelid;
73+
Oidtyprelid;/* 0 if not a class type */
7774
Oidtypelem;
7875

7976
/*
80-
* typelem isNULL if this is not an array type. If this is an array
77+
* typelem is0 if this is not an array type. If this is an array
8178
* type, typelem is the OID of the type of the elements of the array
8279
* (it identifies another row in Table pg_type).
83-
*
84-
* (Note that zero ("0") rather than _null_ is used in the declarations.
85-
* - tgl 97/03/20)
8680
*/
8781
regproctypinput;
8882
regproctypoutput;
8983
regproctypreceive;
9084
regproctypsend;
9185
chartypalign;
9286

93-
/*
87+
/* ----------------
9488
* typalign is the alignment required when storing a value of this
9589
* type. It applies to storage on disk as well as most
9690
* representations of the value inside Postgres. When multiple values
@@ -99,11 +93,18 @@ CATALOG(pg_type) BOOTSTRAP
9993
* type so that it begins on the specified boundary. The alignment
10094
* reference is the beginning of the first datum in the sequence.
10195
*
102-
* 'c' = 1 byte alignment. 's' = 2 byte alignment. 'i' = 4 byte
103-
* alignment. 'd' = 8 byte alignment.
96+
* 'c' = CHAR alignment, ie no alignment needed.
97+
* 's' = SHORT alignment (2 bytes on most machines).
98+
* 'i' = INT alignment (4 bytes on most machines).
99+
* 'd' = DOUBLE alignment (8 bytes on many machines, but by no means all).
100+
*
101+
* See include/utils/memutils.h for the macros that compute these
102+
* alignment requirements.
104103
*
105-
* (This might actually be flexible depending on machine architecture,
106-
* but I doubt it - BRYANH 96.08).
104+
* NOTE: for types used in system tables, it is critical that the
105+
* size and alignment defined in pg_type agree with the way that the
106+
* compiler will lay out the field in a struct representing a table row.
107+
* ----------------
107108
*/
108109
texttypdefault;/* VARIABLE LENGTH FIELD */
109110
}FormData_pg_type;
@@ -218,21 +219,21 @@ DESCR("array of 8 oid, used in system tables");
218219
DATA(insertOID=32 (SETPGUID-1-1frt \0540-1textintextouttextintextouti_null_ ));
219220
DESCR("set of tuples");
220221

221-
DATA(insertOID=71 (pg_typePGUID-1-1tbt \05412470foobarfoobarc_null_));
222-
DATA(insertOID=75 (pg_attributePGUID-1-1tbt \05412490foobarfoobarc_null_));
223-
DATA(insertOID=81 (pg_procPGUID-1-1tbt \05412550foobarfoobarc_null_));
224-
DATA(insertOID=83 (pg_classPGUID-1-1tbt \05412590foobarfoobarc_null_));
225-
DATA(insertOID=86 (pg_shadowPGUID-1-1tbt \05412600foobarfoobarc_null_));
226-
DATA(insertOID=87 (pg_groupPGUID-1-1tbt \05412610foobarfoobarc_null_));
227-
DATA(insertOID=88 (pg_databasePGUID-1-1tbt \05412620foobarfoobarc_null_));
228-
DATA(insertOID=90 (pg_variablePGUID-1-1tbt \05412640foobarfoobarc_null_));
229-
DATA(insertOID=99 (pg_logPGUID-1-1tbt \05412690foobarfoobarc_null_));
222+
DATA(insertOID=71 (pg_typePGUID44tct \05412470foobarfoobari_null_));
223+
DATA(insertOID=75 (pg_attributePGUID44tct \05412490foobarfoobari_null_));
224+
DATA(insertOID=81 (pg_procPGUID44tct \05412550foobarfoobari_null_));
225+
DATA(insertOID=83 (pg_classPGUID44tct \05412590foobarfoobari_null_));
226+
DATA(insertOID=86 (pg_shadowPGUID44tct \05412600foobarfoobari_null_));
227+
DATA(insertOID=87 (pg_groupPGUID44tct \05412610foobarfoobari_null_));
228+
DATA(insertOID=88 (pg_databasePGUID44tct \05412620foobarfoobari_null_));
229+
DATA(insertOID=90 (pg_variablePGUID44tct \05412640foobarfoobari_null_));
230+
DATA(insertOID=99 (pg_logPGUID44tct \05412690foobarfoobari_null_));
230231

231232
/* OIDS 100 - 199 */
232233

233-
DATA(insertOID=109 (pg_attrdefPGUID-1-1tbt \05412150foobarfoobarc_null_));
234-
DATA(insertOID=110 (pg_relcheckPGUID-1-1tbt \05412160foobarfoobarc_null_));
235-
DATA(insertOID=111 (pg_triggerPGUID-1-1tbt \05412190foobarfoobarc_null_));
234+
DATA(insertOID=109 (pg_attrdefPGUID44tct \05412150foobarfoobari_null_));
235+
DATA(insertOID=110 (pg_relcheckPGUID44tct \05412160foobarfoobari_null_));
236+
DATA(insertOID=111 (pg_triggerPGUID44tct \05412190foobarfoobari_null_));
236237

237238
/* OIDS 200 - 299 */
238239

‎src/include/postgres.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1995, Regents of the University of California
88
*
9-
* $Id: postgres.h,v 1.20 1999/02/13 23:20:46 momjian Exp $
9+
* $Id: postgres.h,v 1.21 1999/03/25 03:49:28 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -92,9 +92,14 @@ typedef struct varlena text;
9292
typedefint2int28[8];
9393
typedefOidoid8[8];
9494

95-
typedefstructnameData
95+
/* We want NameData to have length NAMEDATALEN and int alignment,
96+
* because that's how the data type 'name' is defined in pg_type.
97+
* Use a union to make sure the compiler agrees.
98+
*/
99+
typedefunionnameData
96100
{
97101
chardata[NAMEDATALEN];
102+
intalignmentDummy;
98103
}NameData;
99104
typedefNameData*Name;
100105

‎src/include/utils/memutils.h

Lines changed: 33 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
* Copyright (c) 1994, Regents of the University of California
1717
*
18-
* $Id: memutils.h,v 1.21 1999/02/13 23:22:25 momjian Exp $
18+
* $Id: memutils.h,v 1.22 1999/03/25 03:49:34 tgl Exp $
1919
*
2020
* NOTES
2121
* some of the information in this file will be moved to
@@ -27,76 +27,52 @@
2727
#defineMEMUTILS_H
2828

2929

30-
#ifdefNOT_USED
31-
/*****************************************************************************
32-
*align.h- alignment macros *
33-
****************************************************************************
34-
[TRH] Let the compiler decide what alignment it uses instead of
35-
tending
36-
we know better.
37-
GCC (at least v2.5.8 and up) has an __alignof__ keyword.
38-
However, we cannot use it here since on some architectures it reports
39-
just a _recommended_ alignment instead of the actual alignment used in
40-
padding structures (or at least, this is how I understand gcc).
41-
So define a macro that gives us the _actual_ alignment inside a struct.
42-
{{note: assumes that alignment size is always a power of 2.}}
30+
/* ----------------
31+
* Alignment macros: align a length or address appropriately for a given type.
32+
*
33+
* It'd be best to use offsetof to check how the compiler aligns stuff,
34+
* but not all compilers support that (still true)? So we make the
35+
* conservative assumption that a type must be aligned on a boundary equal
36+
* to its own size, except on a few architectures where we know better.
37+
*
38+
* CAUTION: for the system tables, the struct declarations found in
39+
* src/include/pg_*.h had better be interpreted by the compiler in a way
40+
* that agrees with the workings of these macros. In practice that means
41+
* being careful to lay out the columns of a system table in a way that avoids
42+
* wasted pad space.
43+
*
44+
* CAUTION: _ALIGN will not work if sizeof(TYPE) is not a power of 2.
45+
* There are machines where sizeof(double) is not, for example.
46+
* But such a size is almost certainly not an alignment boundary anyway.
47+
* ----------------
4348
*/
44-
#define_ALIGNSIZE(TYPE)offsetof(struct { char __c; TYPE __t;}, __t)
45-
#define_ALIGN(TYPE,LEN) \
46-
(((long)(LEN) + (_ALIGNSIZE(TYPE) - 1)) & ~(_ALIGNSIZE(TYPE) - 1))
47-
#defineSHORTALIGN(LEN)_ALIGN(short, (LEN))
48-
#defineINTALIGN(LEN)_ALIGN(int, (LEN))
49-
#defineLONGALIGN(LEN)_ALIGN(long, (LEN))
50-
#defineDOUBLEALIGN(LEN)_ALIGN(double, (LEN))
51-
#defineMAXALIGN(LEN)_ALIGN(double, (LEN))
5249

53-
#endif/* 0 */
50+
#define_ALIGN(TYPE,LEN) \
51+
(((long)(LEN) + (sizeof(TYPE) - 1)) & ~(sizeof(TYPE) - 1))
5452

55-
/*
56-
*SHORTALIGN(LEN) - length (or address) aligned for shorts
57-
*/
58-
#defineSHORTALIGN(LEN)\
59-
(((long)(LEN) + (sizeof (short) - 1)) & ~(sizeof (short) - 1))
53+
#defineSHORTALIGN(LEN)_ALIGN(short, (LEN))
6054

6155
#if defined(m68k)
62-
#defineINTALIGN(LEN) SHORTALIGN(LEN)
56+
#defineINTALIGN(LEN)_ALIGN(short,(LEN))
6357
#else
64-
#defineINTALIGN(LEN)\
65-
(((long)(LEN) + (sizeof (int) - 1)) & ~(sizeof (int) -1))
58+
#defineINTALIGN(LEN)_ALIGN(int, (LEN))
6659
#endif
6760

68-
/*
69-
*LONGALIGN(LEN)- length (or address) aligned for longs
70-
*/
7161
#if (defined(sun)&& ! defined(sparc))|| defined(m68k)
72-
#defineLONGALIGN(LEN)SHORTALIGN(LEN)
73-
#elif defined (__alpha)
74-
75-
/*
76-
* even though "long alignment" should really be on 8-byte boundaries for
77-
* linuxalpha, we want the strictest alignment to be on 4-byte (int)
78-
* boundaries, because otherwise things break when they try to use the
79-
* FormData_pg_* structures. --djm 12/12/96
80-
*/
81-
#defineLONGALIGN(LEN)\
82-
(((long)(LEN) + (sizeof (int) - 1)) & ~(sizeof (int) -1))
62+
#defineLONGALIGN(LEN)_ALIGN(short, (LEN))
8363
#else
84-
#defineLONGALIGN(LEN)\
85-
(((long)(LEN) + (sizeof (long) - 1)) & ~(sizeof (long) -1))
64+
#defineLONGALIGN(LEN)_ALIGN(long, (LEN))
8665
#endif
8766

8867
#if defined(m68k)
89-
#defineDOUBLEALIGN(LEN) SHORTALIGN(LEN)
90-
#defineMAXALIGN(LEN) SHORTALIGN(LEN)
91-
#elif ! defined(sco)
92-
#defineDOUBLEALIGN(LEN)\
93-
(((long)(LEN) + (sizeof (double) - 1)) & ~(sizeof (double) -1))
94-
95-
#defineMAXALIGN(LEN)\
96-
(((long)(LEN) + (sizeof (double) - 1)) & ~(sizeof (double) -1))
68+
#defineDOUBLEALIGN(LEN)_ALIGN(short, (LEN))
69+
#defineMAXALIGN(LEN)_ALIGN(short, (LEN))
70+
#elif defined(sco)
71+
#defineDOUBLEALIGN(LEN)_ALIGN(int, (LEN))
72+
#defineMAXALIGN(LEN)_ALIGN(int, (LEN))
9773
#else
98-
#defineDOUBLEALIGN(LEN) INTALIGN(LEN)
99-
#defineMAXALIGN(LEN) INTALIGN(LEN)
74+
#defineDOUBLEALIGN(LEN)_ALIGN(double,(LEN))
75+
#defineMAXALIGN(LEN)_ALIGN(double,(LEN))
10076
#endif
10177

10278
/*****************************************************************************

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp