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.36 2000/01/26 05:57:46 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) ());
78 typedef char *((*func_ptr) ());
82 #define RegProcedureIsValid(p) OidIsValid(p)
84 /* ----------------------------------------------------------------
85 * Section 2: variable length and array types
86 * ----------------------------------------------------------------
98 #define VARSIZE(PTR) (((struct varlena *)(PTR))->vl_len)
99 #define VARDATA(PTR) (((struct varlena *)(PTR))->vl_dat)
100 #define VARHDRSZ sizeof(int32)
102 typedef struct varlena bytea;
103 typedef struct varlena text;
105 typedef int2 int2vector[INDEX_MAX_KEYS];
106 typedef Oid oidvector[INDEX_MAX_KEYS];
110 * Proposed new layout for variable length attributes
111 * DO NOT USE YET - Jan
113 #undef TUPLE_TOASTER_ACTIVE
114 #undef TUPLE_TOASTER_ALL_TYPES
116 #ifdef TUPLE_TOASTER_ACTIVE
117 typedef struct varattrib
119 int32 va_header; /* External/compressed storage */
120 /* flags and item size */
125 int32 va_rawsize; /* Plain data size */
126 } va_compressed; /* Compressed stored attribute */
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 */
137 char va_data[1]; /* Plain stored attribute */
141 #define VARATT_FLAG_EXTERNAL 0x8000
142 #define VARATT_FLAG_COMPRESSED 0x4000
143 #define VARATT_MASK_FLAGS 0xc000
144 #define VARATT_MASK_SIZE 0x3fff
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)
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)
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.
163 extern varattrib *heap_tuple_untoast_attr(varattrib *attr);
165 #define VARATT_GETPLAIN(_ARG,_VAR) { \
166 if (VARATTR_IS_EXTENDED(_ARG)) \
167 (_VAR) = (void *)heap_tuple_untoast_attr(_ARG); \
171 #define VARATT_FREE(_ARG,VAR) { \
172 if ((void *)(_VAR) != (void *)(_ARG)) \
173 pfree((void *)(_VAR)); \
175 #else /* TUPLE_TOASTER_ACTIVE */
176 #define VARATT_SIZE(__PTR) VARSIZE(__PTR)
177 #define VARATT_SIZEP(__PTR) VARSIZE(__PTR)
178 #endif /* TUPLE_TOASTER_ACTIVE */
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.
185 typedef union nameData
187 char data[NAMEDATALEN];
190 typedef NameData *Name;
192 #define NameStr(name) ((name).data)
194 /* ----------------------------------------------------------------
195 * Section 3: TransactionId and CommandId
196 * ----------------------------------------------------------------
199 typedef uint32 TransactionId;
201 #define InvalidTransactionId 0
202 typedef uint32 CommandId;
204 #define FirstCommandId 0
206 /* ----------------------------------------------------------------
207 * Section 4: genbki macros used by the
208 * catalog/pg_xxx.h files
209 * ----------------------------------------------------------------
212 typedef struct CppConcat(FormData_,x)
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
220 #define BUILD_INDICES
226 /* ----------------------------------------------------------------
227 * Section 5: random stuff
228 * CSIGNBIT, STATUS...
229 * ----------------------------------------------------------------
232 /* msb for int/unsigned */
233 #define ISIGNBIT (0x80000000)
234 #define WSIGNBIT (0x8000)
237 #define CSIGNBIT (0x80)
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)
250 * Cyrillic on the fly charsets recode
254 extern void SetCharSet();
255 #endif /* CYR_RECODE */
257 #endif /* POSTGRES_H */