1 /*-------------------------------------------------------------------------
4 * definition of (and support for) postgres system types.
5 * this file is included by almost every .c in the system
7 * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
8 * Portions Copyright (c) 1995, Regents of the University of California
10 * $Id: postgres.h,v 1.38 2000/04/12 17:16:24 momjian Exp $
12 *-------------------------------------------------------------------------
16 * this file will eventually contain the definitions for the
17 * following (and perhaps other) system types:
19 * int2 int4 float4 float8
20 * Oid regproc RegProcedure
23 * int2vector oidvector
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
34 * ----------------------------------------------------------------
39 #include "postgres_ext.h"
41 #include "utils/elog.h"
42 #include "utils/mcxt.h"
43 #include "utils/palloc.h"
45 /* ----------------------------------------------------------------
46 * Section 1: simple type definitions
47 * ----------------------------------------------------------------
53 typedef double float8;
58 #define OidIsValid(objectId) ((bool) ((objectId) != InvalidOid))
60 /* unfortunately, both regproc and RegProcedure are used */
62 typedef Oid RegProcedure;
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...
76 typedef int32 ((*func_ptr) ());
79 typedef char *((*func_ptr) ());
84 #define RegProcedureIsValid(p) OidIsValid(p)
86 /* ----------------------------------------------------------------
87 * Section 2: variable length and array types
88 * ----------------------------------------------------------------
100 #define VARSIZE(PTR) (((struct varlena *)(PTR))->vl_len)
101 #define VARDATA(PTR) (((struct varlena *)(PTR))->vl_dat)
102 #define VARHDRSZ ((int32) sizeof(int32))
104 typedef struct varlena bytea;
105 typedef struct varlena text;
107 typedef int2 int2vector[INDEX_MAX_KEYS];
108 typedef Oid oidvector[INDEX_MAX_KEYS];
112 * Proposed new layout for variable length attributes
113 * DO NOT USE YET - Jan
115 #undef TUPLE_TOASTER_ACTIVE
116 #undef TUPLE_TOASTER_ALL_TYPES
118 #ifdef TUPLE_TOASTER_ACTIVE
119 typedef struct varattrib
121 int32 va_header; /* External/compressed storage */
122 /* flags and item size */
127 int32 va_rawsize; /* Plain data size */
128 } va_compressed; /* Compressed stored attribute */
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 */
139 char va_data[1]; /* Plain stored attribute */
143 #define VARATT_FLAG_EXTERNAL 0x8000
144 #define VARATT_FLAG_COMPRESSED 0x4000
145 #define VARATT_MASK_FLAGS 0xc000
146 #define VARATT_MASK_SIZE 0x3fff
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)
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)
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.
165 extern varattrib *heap_tuple_untoast_attr(varattrib * attr);
167 #define VARATT_GETPLAIN(_ARG,_VAR) { \
168 if (VARATTR_IS_EXTENDED(_ARG)) \
169 (_VAR) = (void *)heap_tuple_untoast_attr(_ARG); \
173 #define VARATT_FREE(_ARG,VAR) do { \
174 if ((void *)(_VAR) != (void *)(_ARG)) \
175 pfree((void *)(_VAR)); \
177 #else /* TUPLE_TOASTER_ACTIVE */
178 #define VARATT_SIZE(__PTR) VARSIZE(__PTR)
179 #define VARATT_SIZEP(__PTR) VARSIZE(__PTR)
180 #endif /* TUPLE_TOASTER_ACTIVE */
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.
187 typedef union nameData
189 char data[NAMEDATALEN];
192 typedef NameData *Name;
194 #define NameStr(name) ((name).data)
196 /* ----------------------------------------------------------------
197 * Section 3: TransactionId and CommandId
198 * ----------------------------------------------------------------
201 typedef uint32 TransactionId;
203 #define InvalidTransactionId 0
204 typedef uint32 CommandId;
206 #define FirstCommandId 0
208 /* ----------------------------------------------------------------
209 * Section 4: genbki macros used by the
210 * catalog/pg_xxx.h files
211 * ----------------------------------------------------------------
214 typedef struct CppConcat(FormData_,x)
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
222 #define BUILD_INDICES
228 /* ----------------------------------------------------------------
229 * Section 5: random stuff
230 * CSIGNBIT, STATUS...
231 * ----------------------------------------------------------------
234 /* msb for int/unsigned */
235 #define ISIGNBIT (0x80000000)
236 #define WSIGNBIT (0x8000)
239 #define CSIGNBIT (0x80)
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)
252 * Cyrillic on the fly charsets recode
256 extern void SetCharSet();
258 #endif /* CYR_RECODE */
260 #endif /* POSTGRES_H */