1 /*-------------------------------------------------------------------------
4 * definition of (and support for) postgres system types.
5 * this file is included by almost every .c in the system
7 * Copyright (c) 1995, Regents of the University of California
9 * $Id: postgres.h,v 1.33 2000/01/10 05:20:26 momjian Exp $
11 *-------------------------------------------------------------------------
15 * this file will eventually contain the definitions for the
16 * following (and perhaps other) system types:
18 * int2 int4 float4 float8
19 * Oid regproc RegProcedure
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
33 * ----------------------------------------------------------------
38 #include "postgres_ext.h"
40 #include "utils/elog.h"
41 #include "utils/mcxt.h"
42 #include "utils/palloc.h"
44 /* ----------------------------------------------------------------
45 * Section 1: simple type definitions
46 * ----------------------------------------------------------------
52 typedef double float8;
57 #define OidIsValid(objectId) ((bool) ((objectId) != InvalidOid))
59 /* unfortunately, both regproc and RegProcedure are used */
61 typedef Oid RegProcedure;
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...
75 typedef int32 ((*func_ptr) ());
77 typedef char *((*func_ptr) ());
81 #define RegProcedureIsValid(p) OidIsValid(p)
83 /* ----------------------------------------------------------------
84 * Section 2: variable length and array types
85 * ----------------------------------------------------------------
97 #define VARSIZE(PTR) (((struct varlena *)(PTR))->vl_len)
98 #define VARDATA(PTR) (((struct varlena *)(PTR))->vl_dat)
99 #define VARHDRSZ sizeof(int32)
101 typedef struct varlena bytea;
102 typedef struct varlena text;
104 typedef int2 int28[INDEX_MAX_KEYS];
105 typedef Oid oid8[INDEX_MAX_KEYS];
109 * Proposed new layout for variable length attributes
110 * DO NOT USE YET - Jan
112 #undef TUPLE_TOASTER_ACTIVE
113 #undef TUPLE_TOASTER_ALL_TYPES
115 #ifdef TUPLE_TOASTER_ACTIVE
116 typedef struct varattrib
118 int32 va_header; /* External/compressed storage */
119 /* flags and item size */
124 int32 va_rawsize; /* Plain data size */
125 } va_compressed; /* Compressed stored attribute */
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 */
136 char va_data[1]; /* Plain stored attribute */
140 #define VARATT_FLAG_EXTERNAL 0x8000
141 #define VARATT_FLAG_COMPRESSED 0x4000
142 #define VARATT_MASK_FLAGS 0xc000
143 #define VARATT_MASK_SIZE 0x3fff
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)
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)
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.
162 extern varattrib *heap_tuple_untoast_attr(varattrib *attr);
164 #define VARATT_GETPLAIN(_ARG,_VAR) { \
165 if (VARATTR_IS_EXTENDED(_ARG)) \
166 (_VAR) = (void *)heap_tuple_untoast_attr(_ARG); \
170 #define VARATT_FREE(_ARG,VAR) { \
171 if ((void *)(_VAR) != (void *)(_ARG)) \
172 pfree((void *)(_VAR)); \
174 #else /* TUPLE_TOASTER_ACTIVE */
175 #define VARATT_SIZE(__PTR) VARSIZE(__PTR)
176 #define VARATT_SIZEP(__PTR) VARSIZE(__PTR)
177 #endif /* TUPLE_TOASTER_ACTIVE */
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.
184 typedef union nameData
186 char data[NAMEDATALEN];
189 typedef NameData *Name;
191 #define NameStr(name) ((name).data)
193 /* ----------------------------------------------------------------
194 * Section 3: TransactionId and CommandId
195 * ----------------------------------------------------------------
198 typedef uint32 TransactionId;
200 #define InvalidTransactionId 0
201 typedef uint32 CommandId;
203 #define FirstCommandId 0
205 /* ----------------------------------------------------------------
206 * Section 4: genbki macros used by the
207 * catalog/pg_xxx.h files
208 * ----------------------------------------------------------------
211 typedef struct CppConcat(FormData_,x)
213 #define DATA(x) extern int errno
214 #define DESCR(x) extern int errno
215 #define DECLARE_INDEX(x) extern int errno
216 #define DECLARE_UNIQUE_INDEX(x) extern int errno
218 #define BUILD_INDICES
224 /* ----------------------------------------------------------------
225 * Section 5: random stuff
226 * CSIGNBIT, STATUS...
227 * ----------------------------------------------------------------
230 /* msb for int/unsigned */
231 #define ISIGNBIT (0x80000000)
232 #define WSIGNBIT (0x8000)
235 #define CSIGNBIT (0x80)
237 #define STATUS_OK (0)
238 #define STATUS_ERROR (-1)
239 #define STATUS_NOT_FOUND (-2)
240 #define STATUS_INVALID (-3)
241 #define STATUS_UNCATALOGUED (-4)
242 #define STATUS_REPLACED (-5)
243 #define STATUS_NOT_DONE (-6)
244 #define STATUS_BAD_PACKET (-7)
245 #define STATUS_FOUND (1)
248 * Cyrillic on the fly charsets recode
252 extern void SetCharSet();
253 #endif /* CYR_RECODE */
255 #endif /* POSTGRES_H */