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