]> granicus.if.org Git - postgresql/blob - src/include/postgres.h
Ye-old pgindent run. Same 4-space tabs.
[postgresql] / src / include / postgres.h
1 /*-------------------------------------------------------------------------
2  *
3  * postgres.h
4  *        definition of (and support for) postgres system types.
5  * this file is included by almost every .c in the system
6  *
7  * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
8  * Portions Copyright (c) 1995, Regents of the University of California
9  *
10  * $Id: postgres.h,v 1.38 2000/04/12 17:16:24 momjian Exp $
11  *
12  *-------------------------------------------------------------------------
13  */
14 /*
15  *       NOTES
16  *              this file will eventually contain the definitions for the
17  *              following (and perhaps other) system types:
18  *
19  *                              int2       int4           float4           float8
20  *                              Oid                regproc        RegProcedure
21  *                              aclitem
22  *                              struct varlena
23  *                              int2vector        oidvector
24  *                              bytea      text
25  *                              NameData   Name
26  *
27  *       TABLE OF CONTENTS
28  *              1)              simple type definitions
29  *              2)              varlena and array types
30  *              3)              TransactionId and CommandId
31  *              4)              genbki macros used by catalog/pg_xxx.h files
32  *              5)              random stuff
33  *
34  * ----------------------------------------------------------------
35  */
36 #ifndef POSTGRES_H
37 #define POSTGRES_H
38
39 #include "postgres_ext.h"
40 #include "c.h"
41 #include "utils/elog.h"
42 #include "utils/mcxt.h"
43 #include "utils/palloc.h"
44
45 /* ----------------------------------------------------------------
46  *                              Section 1:      simple type definitions
47  * ----------------------------------------------------------------
48  */
49
50 typedef int16 int2;
51 typedef int32 int4;
52 typedef float float4;
53 typedef double float8;
54
55 typedef int4 aclitem;
56
57 #define InvalidOid              0
58 #define OidIsValid(objectId)  ((bool) ((objectId) != InvalidOid))
59
60 /* unfortunately, both regproc and RegProcedure are used */
61 typedef Oid regproc;
62 typedef Oid RegProcedure;
63
64 /* ptr to func returning (char *) */
65 #if defined(__mc68000__) && defined(__ELF__)
66 /* The m68k SVR4 ABI defines that pointers are returned in %a0 instead of
67  * %d0. So if a function pointer is declared to return a pointer, the
68  * compiler may look only into %a0, but if the called function was declared
69  * to return return an integer type, it puts its value only into %d0. So the
70  * caller doesn't pink up the correct return value. The solution is to
71  * declare the function pointer to return int, so the compiler picks up the
72  * return value from %d0. (Functions returning pointers put their value
73  * *additionally* into %d0 for compability.) The price is that there are
74  * some warnings about int->pointer conversions...
75  */
76 typedef int32 ((*func_ptr) ());
77
78 #else
79 typedef char *((*func_ptr) ());
80
81 #endif
82
83
84 #define RegProcedureIsValid(p)  OidIsValid(p)
85
86 /* ----------------------------------------------------------------
87  *                              Section 2:      variable length and array types
88  * ----------------------------------------------------------------
89  */
90 /* ----------------
91  *              struct varlena
92  * ----------------
93  */
94 struct varlena
95 {
96         int32           vl_len;
97         char            vl_dat[1];
98 };
99
100 #define VARSIZE(PTR)    (((struct varlena *)(PTR))->vl_len)
101 #define VARDATA(PTR)    (((struct varlena *)(PTR))->vl_dat)
102 #define VARHDRSZ                ((int32) sizeof(int32))
103
104 typedef struct varlena bytea;
105 typedef struct varlena text;
106
107 typedef int2 int2vector[INDEX_MAX_KEYS];
108 typedef Oid oidvector[INDEX_MAX_KEYS];
109
110
111 /*
112  * Proposed new layout for variable length attributes
113  * DO NOT USE YET - Jan
114  */
115 #undef TUPLE_TOASTER_ACTIVE
116 #undef TUPLE_TOASTER_ALL_TYPES
117
118 #ifdef TUPLE_TOASTER_ACTIVE
119 typedef struct varattrib
120 {
121         int32           va_header;              /* External/compressed storage */
122         /* flags and item size */
123         union
124         {
125                 struct
126                 {
127                         int32           va_rawsize;             /* Plain data size */
128                 }                       va_compressed;          /* Compressed stored attribute */
129
130                 struct
131                 {
132                         int32           va_rawsize;             /* Plain data size */
133                         Oid                     va_valueid;             /* Unique identifier of value */
134                         Oid                     va_longrelid;   /* RelID where to find chunks */
135                         Oid                     va_rowid;               /* Main tables row Oid */
136                         int16           va_attno;               /* Main tables attno */
137                 }                       va_external;/* External stored attribute */
138
139                 char            va_data[1]; /* Plain stored attribute */
140         }                       va_content;
141 }                       varattrib;
142
143 #define VARATT_FLAG_EXTERNAL    0x8000
144 #define VARATT_FLAG_COMPRESSED  0x4000
145 #define VARATT_MASK_FLAGS               0xc000
146 #define VARATT_MASK_SIZE                0x3fff
147
148 #define VARATT_SIZEP(_PTR)      (((varattrib *)(_PTR))->va_header)
149 #define VARATT_SIZE(PTR)        (VARATT_SIZEP(PTR) & VARATT_MASK_SIZE)
150 #define VARATT_DATA(PTR)        (((varattrib *)(PTR))->va_content.va_data)
151
152 #define VARATT_IS_EXTENDED(PTR)         \
153                                 ((VARATT_SIZEP(PTR) & VARATT_MASK_FLAGS) != 0)
154 #define VARATT_IS_EXTERNAL(PTR)         \
155                                 ((VARATT_SIZEP(PTR) & VARATT_FLAG_EXTERNAL) != 0)
156 #define VARATT_IS_COMPRESSED(PTR)       \
157                                 ((VARATT_SIZEP(PTR) & VARATT_FLAG_COMPRESSED) != 0)
158
159 /* ----------
160  * This is regularly declared in access/tuptoaster.h,
161  * but we don't want to include that into every source,
162  * so we (evil evil evil) declare it here once more.
163  * ----------
164  */
165 extern varattrib *heap_tuple_untoast_attr(varattrib * attr);
166
167 #define VARATT_GETPLAIN(_ARG,_VAR) {                                                            \
168                                 if (VARATTR_IS_EXTENDED(_ARG))                                          \
169                                         (_VAR) = (void *)heap_tuple_untoast_attr(_ARG); \
170                                 else                                                                                            \
171                                         (_VAR) = (_ARG);                                                                \
172                         }
173 #define VARATT_FREE(_ARG,VAR) do {                                                                      \
174                                 if ((void *)(_VAR) != (void *)(_ARG))                           \
175                                         pfree((void *)(_VAR));                                                  \
176                         } while (0)
177 #else                                                   /* TUPLE_TOASTER_ACTIVE */
178 #define VARATT_SIZE(__PTR) VARSIZE(__PTR)
179 #define VARATT_SIZEP(__PTR) VARSIZE(__PTR)
180 #endif   /* TUPLE_TOASTER_ACTIVE */
181
182
183 /* We want NameData to have length NAMEDATALEN and int alignment,
184  * because that's how the data type 'name' is defined in pg_type.
185  * Use a union to make sure the compiler agrees.
186  */
187 typedef union nameData
188 {
189         char            data[NAMEDATALEN];
190         int                     alignmentDummy;
191 } NameData;
192 typedef NameData *Name;
193
194 #define NameStr(name)   ((name).data)
195
196 /* ----------------------------------------------------------------
197  *                              Section 3: TransactionId and CommandId
198  * ----------------------------------------------------------------
199  */
200
201 typedef uint32 TransactionId;
202
203 #define InvalidTransactionId    0
204 typedef uint32 CommandId;
205
206 #define FirstCommandId  0
207
208 /* ----------------------------------------------------------------
209  *                              Section 4: genbki macros used by the
210  *                                                 catalog/pg_xxx.h files
211  * ----------------------------------------------------------------
212  */
213 #define CATALOG(x) \
214         typedef struct CppConcat(FormData_,x)
215
216 /* Huh? */
217 #define DATA(x) extern int errno
218 #define DESCR(x) extern int errno
219 #define DECLARE_INDEX(x) extern int errno
220 #define DECLARE_UNIQUE_INDEX(x) extern int errno
221
222 #define BUILD_INDICES
223 #define BOOTSTRAP
224
225 #define BKI_BEGIN
226 #define BKI_END
227
228 /* ----------------------------------------------------------------
229  *                              Section 5:      random stuff
230  *                                                      CSIGNBIT, STATUS...
231  * ----------------------------------------------------------------
232  */
233
234 /* msb for int/unsigned */
235 #define ISIGNBIT (0x80000000)
236 #define WSIGNBIT (0x8000)
237
238 /* msb for char */
239 #define CSIGNBIT (0x80)
240
241 #define STATUS_OK                               (0)
242 #define STATUS_ERROR                    (-1)
243 #define STATUS_NOT_FOUND                (-2)
244 #define STATUS_INVALID                  (-3)
245 #define STATUS_UNCATALOGUED             (-4)
246 #define STATUS_REPLACED                 (-5)
247 #define STATUS_NOT_DONE                 (-6)
248 #define STATUS_BAD_PACKET               (-7)
249 #define STATUS_FOUND                    (1)
250
251 /* ---------------
252  * Cyrillic on the fly charsets recode
253  * ---------------
254  */
255 #ifdef CYR_RECODE
256 extern void SetCharSet();
257
258 #endif   /* CYR_RECODE */
259
260 #endif   /* POSTGRES_H */