]> granicus.if.org Git - postgresql/blob - src/include/postgres.h
Add:
[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.36 2000/01/26 05:57:46 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 #else 
78 typedef char *((*func_ptr) ());
79 #endif
80
81
82 #define RegProcedureIsValid(p)  OidIsValid(p)
83
84 /* ----------------------------------------------------------------
85  *                              Section 2:      variable length and array types
86  * ----------------------------------------------------------------
87  */
88 /* ----------------
89  *              struct varlena
90  * ----------------
91  */
92 struct varlena
93 {
94         int32           vl_len;
95         char            vl_dat[1];
96 };
97
98 #define VARSIZE(PTR)    (((struct varlena *)(PTR))->vl_len)
99 #define VARDATA(PTR)    (((struct varlena *)(PTR))->vl_dat)
100 #define VARHDRSZ                sizeof(int32)
101
102 typedef struct varlena bytea;
103 typedef struct varlena text;
104
105 typedef int2 int2vector[INDEX_MAX_KEYS];
106 typedef Oid oidvector[INDEX_MAX_KEYS];
107
108
109 /*
110  * Proposed new layout for variable length attributes
111  * DO NOT USE YET - Jan
112  */
113 #undef TUPLE_TOASTER_ACTIVE
114 #undef TUPLE_TOASTER_ALL_TYPES
115
116 #ifdef TUPLE_TOASTER_ACTIVE
117 typedef struct varattrib
118 {
119         int32                           va_header;                      /* External/compressed storage */
120                                                                                         /* flags and item size */
121         union
122         {
123                 struct
124                 {
125                         int32           va_rawsize;                     /* Plain data size */
126                 }                               va_compressed;          /* Compressed stored attribute */
127
128                 struct
129                 {
130                         int32           va_rawsize;                     /* Plain data size */
131                         Oid                     va_valueid;                     /* Unique identifier of value */
132                         Oid                     va_longrelid;           /* RelID where to find chunks */
133                         Oid                     va_rowid;                       /* Main tables row Oid */
134                         int16           va_attno;                       /* Main tables attno */
135                 }                               va_external;            /* External stored attribute */
136
137                 char                    va_data[1];                     /* Plain stored attribute */
138         }                                       va_content;
139 } varattrib;
140
141 #define VARATT_FLAG_EXTERNAL    0x8000
142 #define VARATT_FLAG_COMPRESSED  0x4000
143 #define VARATT_MASK_FLAGS               0xc000
144 #define VARATT_MASK_SIZE                0x3fff
145
146 #define VARATT_SIZEP(_PTR)      (((varattrib *)(_PTR))->va_header)
147 #define VARATT_SIZE(PTR)        (VARATT_SIZEP(PTR) & VARATT_MASK_SIZE) 
148 #define VARATT_DATA(PTR)        (((varattrib *)(PTR))->va_content.va_data)
149
150 #define VARATT_IS_EXTENDED(PTR)         \
151                                 ((VARATT_SIZEP(PTR) & VARATT_MASK_FLAGS) != 0)
152 #define VARATT_IS_EXTERNAL(PTR)         \
153                                 ((VARATT_SIZEP(PTR) & VARATT_FLAG_EXTERNAL) != 0)
154 #define VARATT_IS_COMPRESSED(PTR)       \
155                                 ((VARATT_SIZEP(PTR) & VARATT_FLAG_COMPRESSED) != 0)
156
157 /* ----------
158  * This is regularly declared in access/tuptoaster.h,
159  * but we don't want to include that into every source,
160  * so we (evil evil evil) declare it here once more.
161  * ----------
162  */
163 extern varattrib *heap_tuple_untoast_attr(varattrib *attr);
164
165 #define VARATT_GETPLAIN(_ARG,_VAR) {                                                            \
166                                 if (VARATTR_IS_EXTENDED(_ARG))                                          \
167                                         (_VAR) = (void *)heap_tuple_untoast_attr(_ARG); \
168                                 else                                                                                            \
169                                         (_VAR) = (_ARG);                                                                \
170                         }
171 #define VARATT_FREE(_ARG,VAR) {                                                                         \
172                                 if ((void *)(_VAR) != (void *)(_ARG))                           \
173                                         pfree((void *)(_VAR));                                                  \
174                         }
175 #else /* TUPLE_TOASTER_ACTIVE */
176 #define VARATT_SIZE(__PTR) VARSIZE(__PTR)
177 #define VARATT_SIZEP(__PTR) VARSIZE(__PTR)
178 #endif /* TUPLE_TOASTER_ACTIVE */
179
180
181 /* We want NameData to have length NAMEDATALEN and int alignment,
182  * because that's how the data type 'name' is defined in pg_type.
183  * Use a union to make sure the compiler agrees.
184  */
185 typedef union nameData
186 {
187         char            data[NAMEDATALEN];
188         int                     alignmentDummy;
189 } NameData;
190 typedef NameData *Name;
191
192 #define NameStr(name)   ((name).data)
193
194 /* ----------------------------------------------------------------
195  *                              Section 3: TransactionId and CommandId
196  * ----------------------------------------------------------------
197  */
198
199 typedef uint32 TransactionId;
200
201 #define InvalidTransactionId    0
202 typedef uint32 CommandId;
203
204 #define FirstCommandId  0
205
206 /* ----------------------------------------------------------------
207  *                              Section 4: genbki macros used by the
208  *                                                 catalog/pg_xxx.h files
209  * ----------------------------------------------------------------
210  */
211 #define CATALOG(x) \
212         typedef struct CppConcat(FormData_,x)
213
214 /* Huh? */
215 #define DATA(x) extern int errno
216 #define DESCR(x) extern int errno
217 #define DECLARE_INDEX(x) extern int errno
218 #define DECLARE_UNIQUE_INDEX(x) extern int errno
219
220 #define BUILD_INDICES
221 #define BOOTSTRAP
222
223 #define BKI_BEGIN
224 #define BKI_END
225
226 /* ----------------------------------------------------------------
227  *                              Section 5:      random stuff
228  *                                                      CSIGNBIT, STATUS...
229  * ----------------------------------------------------------------
230  */
231
232 /* msb for int/unsigned */
233 #define ISIGNBIT (0x80000000)
234 #define WSIGNBIT (0x8000)
235
236 /* msb for char */
237 #define CSIGNBIT (0x80)
238
239 #define STATUS_OK                               (0)
240 #define STATUS_ERROR                    (-1)
241 #define STATUS_NOT_FOUND                (-2)
242 #define STATUS_INVALID                  (-3)
243 #define STATUS_UNCATALOGUED             (-4)
244 #define STATUS_REPLACED                 (-5)
245 #define STATUS_NOT_DONE                 (-6)
246 #define STATUS_BAD_PACKET               (-7)
247 #define STATUS_FOUND                    (1)
248
249 /* ---------------
250  * Cyrillic on the fly charsets recode
251  * ---------------
252  */
253 #ifdef CYR_RECODE
254 extern void             SetCharSet();
255 #endif   /* CYR_RECODE */
256
257 #endif   /* POSTGRES_H */