PostgreSQL Source Code git master
oid.c File Reference
#include "postgres.h"
#include <ctype.h>
#include <limits.h>
#include "catalog/pg_type.h"
#include "common/int.h"
#include "libpq/pqformat.h"
#include "nodes/miscnodes.h"
#include "nodes/value.h"
#include "utils/array.h"
#include "utils/builtins.h"
Include dependency graph for oid.c:

Go to the source code of this file.

Macros

#define OidVectorSize(n)   (offsetof(oidvector, values) + (n) * sizeof(Oid))
 

Functions

Datum oidin (PG_FUNCTION_ARGS)
 
Datum oidout (PG_FUNCTION_ARGS)
 
Datum oidrecv (PG_FUNCTION_ARGS)
 
Datum oidsend (PG_FUNCTION_ARGS)
 
oidvectorbuildoidvector (const Oid *oids, int n)
 
Datum oidvectorin (PG_FUNCTION_ARGS)
 
Datum oidvectorout (PG_FUNCTION_ARGS)
 
Datum oidvectorrecv (PG_FUNCTION_ARGS)
 
Datum oidvectorsend (PG_FUNCTION_ARGS)
 
Oid oidparse (Node *node)
 
int oid_cmp (const void *p1, const void *p2)
 
Datum oideq (PG_FUNCTION_ARGS)
 
Datum oidne (PG_FUNCTION_ARGS)
 
Datum oidlt (PG_FUNCTION_ARGS)
 
Datum oidle (PG_FUNCTION_ARGS)
 
Datum oidge (PG_FUNCTION_ARGS)
 
Datum oidgt (PG_FUNCTION_ARGS)
 
Datum oidlarger (PG_FUNCTION_ARGS)
 
Datum oidsmaller (PG_FUNCTION_ARGS)
 
Datum oidvectoreq (PG_FUNCTION_ARGS)
 
Datum oidvectorne (PG_FUNCTION_ARGS)
 
Datum oidvectorlt (PG_FUNCTION_ARGS)
 
Datum oidvectorle (PG_FUNCTION_ARGS)
 
Datum oidvectorge (PG_FUNCTION_ARGS)
 
Datum oidvectorgt (PG_FUNCTION_ARGS)
 

Macro Definition Documentation

◆ OidVectorSize

#define OidVectorSize (   n)    (offsetof(oidvector, values) + (n) * sizeof(Oid))

Definition at line 29 of file oid.c.

Function Documentation

◆ buildoidvector()

oidvector * buildoidvector ( const Oid oids,
int  n 
)

Definition at line 87 of file oid.c.

88{
89 oidvector *result;
90
91 result = (oidvector *) palloc0(OidVectorSize(n));
92
93 if (n > 0 && oids)
94 memcpy(result->values, oids, n * sizeof(Oid));
95
96 /*
97 * Attach standard array header. For historical reasons, we set the index
98 * lower bound to 0 not 1.
99 */
100 SET_VARSIZE(result, OidVectorSize(n));
101 result->ndim = 1;
102 result->dataoffset = 0; /* never any nulls */
103 result->elemtype = OIDOID;
104 result->dim1 = n;
105 result->lbound1 = 0;
106
107 return result;
108}
void * palloc0(Size size)
Definition: mcxt.c:1347
#define OidVectorSize(n)
Definition: oid.c:29
unsigned int Oid
Definition: postgres_ext.h:32
Definition: c.h:683
int dim1
Definition: c.h:688
int32 dataoffset
Definition: c.h:686
Oid elemtype
Definition: c.h:687
int lbound1
Definition: c.h:689
int ndim
Definition: c.h:685
Oid values[FLEXIBLE_ARRAY_MEMBER]
Definition: c.h:690
#define SET_VARSIZE(PTR, len)
Definition: varatt.h:305

References oidvector::dataoffset, oidvector::dim1, oidvector::elemtype, oidvector::lbound1, oidvector::ndim, OidVectorSize, palloc0(), SET_VARSIZE, and oidvector::values.

Referenced by DefineAggregate(), interpret_function_parameter_list(), makeMultirangeConstructors(), makeRangeConstructors(), StorePartitionKey(), and UpdateIndexRelation().

◆ oid_cmp()

int oid_cmp ( const void *  p1,
const void *  p2 
)

Definition at line 258 of file oid.c.

259{
260 Oid v1 = *((const Oid *) p1);
261 Oid v2 = *((const Oid *) p2);
262
263 return pg_cmp_u32(v1, v2);
264}
static int pg_cmp_u32(uint32 a, uint32 b)
Definition: int.h:652

References p2, and pg_cmp_u32().

Referenced by aclmembers(), AlterSubscription_refresh(), EnumValuesCreate(), and find_inheritance_children_extended().

◆ oideq()

Datum oideq ( PG_FUNCTION_ARGS  )

Definition at line 272 of file oid.c.

273{
274 Oid arg1 = PG_GETARG_OID(0);
275 Oid arg2 = PG_GETARG_OID(1);
276
277 PG_RETURN_BOOL(arg1 == arg2);
278}
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359

References PG_GETARG_OID, and PG_RETURN_BOOL.

◆ oidge()

Datum oidge ( PG_FUNCTION_ARGS  )

Definition at line 308 of file oid.c.

309{
310 Oid arg1 = PG_GETARG_OID(0);
311 Oid arg2 = PG_GETARG_OID(1);
312
313 PG_RETURN_BOOL(arg1 >= arg2);
314}

References PG_GETARG_OID, and PG_RETURN_BOOL.

◆ oidgt()

Datum oidgt ( PG_FUNCTION_ARGS  )

Definition at line 317 of file oid.c.

318{
319 Oid arg1 = PG_GETARG_OID(0);
320 Oid arg2 = PG_GETARG_OID(1);
321
322 PG_RETURN_BOOL(arg1 > arg2);
323}

References PG_GETARG_OID, and PG_RETURN_BOOL.

◆ oidin()

Datum oidin ( PG_FUNCTION_ARGS  )

Definition at line 37 of file oid.c.

38{
39 char *s = PG_GETARG_CSTRING(0);
40 Oid result;
41
42 result = uint32in_subr(s, NULL, "oid", fcinfo->context);
43 PG_RETURN_OID(result);
44}
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:277
#define PG_RETURN_OID(x)
Definition: fmgr.h:360
uint32 uint32in_subr(const char *s, char **endloc, const char *typname, Node *escontext)
Definition: numutils.c:898

References PG_GETARG_CSTRING, PG_RETURN_OID, and uint32in_subr().

Referenced by defGetObjectId(), and parseNumericOid().

◆ oidlarger()

Datum oidlarger ( PG_FUNCTION_ARGS  )

Definition at line 326 of file oid.c.

327{
328 Oid arg1 = PG_GETARG_OID(0);
329 Oid arg2 = PG_GETARG_OID(1);
330
331 PG_RETURN_OID((arg1 > arg2) ? arg1 : arg2);
332}

References PG_GETARG_OID, and PG_RETURN_OID.

◆ oidle()

Datum oidle ( PG_FUNCTION_ARGS  )

Definition at line 299 of file oid.c.

300{
301 Oid arg1 = PG_GETARG_OID(0);
302 Oid arg2 = PG_GETARG_OID(1);
303
304 PG_RETURN_BOOL(arg1 <= arg2);
305}

References PG_GETARG_OID, and PG_RETURN_BOOL.

◆ oidlt()

Datum oidlt ( PG_FUNCTION_ARGS  )

Definition at line 290 of file oid.c.

291{
292 Oid arg1 = PG_GETARG_OID(0);
293 Oid arg2 = PG_GETARG_OID(1);
294
295 PG_RETURN_BOOL(arg1 < arg2);
296}

References PG_GETARG_OID, and PG_RETURN_BOOL.

◆ oidne()

Datum oidne ( PG_FUNCTION_ARGS  )

Definition at line 281 of file oid.c.

282{
283 Oid arg1 = PG_GETARG_OID(0);
284 Oid arg2 = PG_GETARG_OID(1);
285
286 PG_RETURN_BOOL(arg1 != arg2);
287}

References PG_GETARG_OID, and PG_RETURN_BOOL.

◆ oidout()

Datum oidout ( PG_FUNCTION_ARGS  )

Definition at line 47 of file oid.c.

48{
49 Oid o = PG_GETARG_OID(0);
50 char *result = (char *) palloc(12);
51
52 snprintf(result, 12, "%u", o);
53 PG_RETURN_CSTRING(result);
54}
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:362
void * palloc(Size size)
Definition: mcxt.c:1317
#define snprintf
Definition: port.h:239

References palloc(), PG_GETARG_OID, PG_RETURN_CSTRING, and snprintf.

Referenced by plperl_trigger_build_args(), pltcl_trigger_handler(), and PLy_trigger_build_args().

◆ oidparse()

Oid oidparse ( Node node)

Definition at line 235 of file oid.c.

236{
237 switch (nodeTag(node))
238 {
239 case T_Integer:
240 return intVal(node);
241 case T_Float:
242
243 /*
244 * Values too large for int4 will be represented as Float
245 * constants by the lexer. Accept these if they are valid OID
246 * strings.
247 */
248 return uint32in_subr(castNode(Float, node)->fval, NULL,
249 "oid", NULL);
250 default:
251 elog(ERROR, "unrecognized node type: %d", (int) nodeTag(node));
252 }
253 return InvalidOid; /* keep compiler quiet */
254}
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:225
#define nodeTag(nodeptr)
Definition: nodes.h:133
#define castNode(_type_, nodeptr)
Definition: nodes.h:176
#define InvalidOid
Definition: postgres_ext.h:37
Definition: value.h:48
#define intVal(v)
Definition: value.h:79

References castNode, elog, ERROR, intVal, InvalidOid, nodeTag, and uint32in_subr().

Referenced by get_object_address().

◆ oidrecv()

Datum oidrecv ( PG_FUNCTION_ARGS  )

Definition at line 60 of file oid.c.

61{
63
65}
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
static char * buf
Definition: pg_test_fsync.c:72
unsigned int pq_getmsgint(StringInfo msg, int b)
Definition: pqformat.c:415
StringInfoData * StringInfo
Definition: stringinfo.h:54

References buf, PG_GETARG_POINTER, PG_RETURN_OID, and pq_getmsgint().

Referenced by regclassrecv(), regcollationrecv(), regconfigrecv(), regdictionaryrecv(), regnamespacerecv(), regoperatorrecv(), regoperrecv(), regprocedurerecv(), regprocrecv(), regrolerecv(), and regtyperecv().

◆ oidsend()

Datum oidsend ( PG_FUNCTION_ARGS  )

Definition at line 71 of file oid.c.

72{
73 Oid arg1 = PG_GETARG_OID(0);
75
77 pq_sendint32(&buf, arg1);
79}
#define PG_RETURN_BYTEA_P(x)
Definition: fmgr.h:371
void pq_begintypsend(StringInfo buf)
Definition: pqformat.c:326
bytea * pq_endtypsend(StringInfo buf)
Definition: pqformat.c:346
static void pq_sendint32(StringInfo buf, uint32 i)
Definition: pqformat.h:144

References buf, PG_GETARG_OID, PG_RETURN_BYTEA_P, pq_begintypsend(), pq_endtypsend(), and pq_sendint32().

Referenced by regclasssend(), regcollationsend(), regconfigsend(), regdictionarysend(), regnamespacesend(), regoperatorsend(), regopersend(), regproceduresend(), regprocsend(), regrolesend(), and regtypesend().

◆ oidsmaller()

Datum oidsmaller ( PG_FUNCTION_ARGS  )

Definition at line 335 of file oid.c.

336{
337 Oid arg1 = PG_GETARG_OID(0);
338 Oid arg2 = PG_GETARG_OID(1);
339
340 PG_RETURN_OID((arg1 < arg2) ? arg1 : arg2);
341}

References PG_GETARG_OID, and PG_RETURN_OID.

◆ oidvectoreq()

Datum oidvectoreq ( PG_FUNCTION_ARGS  )

Definition at line 344 of file oid.c.

345{
347
348 PG_RETURN_BOOL(cmp == 0);
349}
int32_t int32
Definition: c.h:484
Datum btoidvectorcmp(PG_FUNCTION_ARGS)
Definition: nbtcompare.c:296
static int32 DatumGetInt32(Datum X)
Definition: postgres.h:207
static int cmp(const chr *x, const chr *y, size_t len)
Definition: regc_locale.c:743

References btoidvectorcmp(), cmp(), DatumGetInt32(), and PG_RETURN_BOOL.

Referenced by oidvectoreqfast().

◆ oidvectorge()

Datum oidvectorge ( PG_FUNCTION_ARGS  )

Definition at line 376 of file oid.c.

377{
379
380 PG_RETURN_BOOL(cmp >= 0);
381}

References btoidvectorcmp(), cmp(), DatumGetInt32(), and PG_RETURN_BOOL.

◆ oidvectorgt()

Datum oidvectorgt ( PG_FUNCTION_ARGS  )

Definition at line 384 of file oid.c.

385{
387
388 PG_RETURN_BOOL(cmp > 0);
389}

References btoidvectorcmp(), cmp(), DatumGetInt32(), and PG_RETURN_BOOL.

◆ oidvectorin()

Datum oidvectorin ( PG_FUNCTION_ARGS  )

Definition at line 114 of file oid.c.

115{
116 char *oidString = PG_GETARG_CSTRING(0);
117 Node *escontext = fcinfo->context;
118 oidvector *result;
119 int nalloc;
120 int n;
121
122 nalloc = 32; /* arbitrary initial size guess */
123 result = (oidvector *) palloc0(OidVectorSize(nalloc));
124
125 for (n = 0;; n++)
126 {
127 while (*oidString && isspace((unsigned char) *oidString))
128 oidString++;
129 if (*oidString == '\0')
130 break;
131
132 if (n >= nalloc)
133 {
134 nalloc *= 2;
135 result = (oidvector *) repalloc(result, OidVectorSize(nalloc));
136 }
137
138 result->values[n] = uint32in_subr(oidString, &oidString,
139 "oid", escontext);
140 if (SOFT_ERROR_OCCURRED(escontext))
142 }
143
144 SET_VARSIZE(result, OidVectorSize(n));
145 result->ndim = 1;
146 result->dataoffset = 0; /* never any nulls */
147 result->elemtype = OIDOID;
148 result->dim1 = n;
149 result->lbound1 = 0;
150
151 PG_RETURN_POINTER(result);
152}
#define PG_RETURN_NULL()
Definition: fmgr.h:345
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:361
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:1541
#define SOFT_ERROR_OCCURRED(escontext)
Definition: miscnodes.h:53
Definition: nodes.h:129

References oidvector::dataoffset, oidvector::dim1, oidvector::elemtype, oidvector::lbound1, oidvector::ndim, OidVectorSize, palloc0(), PG_GETARG_CSTRING, PG_RETURN_NULL, PG_RETURN_POINTER, repalloc(), SET_VARSIZE, SOFT_ERROR_OCCURRED, uint32in_subr(), and oidvector::values.

◆ oidvectorle()

Datum oidvectorle ( PG_FUNCTION_ARGS  )

Definition at line 368 of file oid.c.

369{
371
372 PG_RETURN_BOOL(cmp <= 0);
373}

References btoidvectorcmp(), cmp(), DatumGetInt32(), and PG_RETURN_BOOL.

◆ oidvectorlt()

Datum oidvectorlt ( PG_FUNCTION_ARGS  )

Definition at line 360 of file oid.c.

361{
363
364 PG_RETURN_BOOL(cmp < 0);
365}

References btoidvectorcmp(), cmp(), DatumGetInt32(), and PG_RETURN_BOOL.

◆ oidvectorne()

Datum oidvectorne ( PG_FUNCTION_ARGS  )

Definition at line 352 of file oid.c.

353{
355
356 PG_RETURN_BOOL(cmp != 0);
357}

References btoidvectorcmp(), cmp(), DatumGetInt32(), and PG_RETURN_BOOL.

◆ oidvectorout()

Datum oidvectorout ( PG_FUNCTION_ARGS  )

Definition at line 158 of file oid.c.

159{
160 oidvector *oidArray = (oidvector *) PG_GETARG_POINTER(0);
161 int num,
162 nnums = oidArray->dim1;
163 char *rp;
164 char *result;
165
166 /* assumes sign, 10 digits, ' ' */
167 rp = result = (char *) palloc(nnums * 12 + 1);
168 for (num = 0; num < nnums; num++)
169 {
170 if (num != 0)
171 *rp++ = ' ';
172 sprintf(rp, "%u", oidArray->values[num]);
173 while (*++rp != '\0')
174 ;
175 }
176 *rp = '\0';
177 PG_RETURN_CSTRING(result);
178}
#define sprintf
Definition: port.h:241

References oidvector::dim1, palloc(), PG_GETARG_POINTER, PG_RETURN_CSTRING, sprintf, and oidvector::values.

◆ oidvectorrecv()

Datum oidvectorrecv ( PG_FUNCTION_ARGS  )

Definition at line 184 of file oid.c.

185{
186 LOCAL_FCINFO(locfcinfo, 3);
188 oidvector *result;
189
190 /*
191 * Normally one would call array_recv() using DirectFunctionCall3, but
192 * that does not work since array_recv wants to cache some data using
193 * fcinfo->flinfo->fn_extra. So we need to pass it our own flinfo
194 * parameter.
195 */
196 InitFunctionCallInfoData(*locfcinfo, fcinfo->flinfo, 3,
197 InvalidOid, NULL, NULL);
198
199 locfcinfo->args[0].value = PointerGetDatum(buf);
200 locfcinfo->args[0].isnull = false;
201 locfcinfo->args[1].value = ObjectIdGetDatum(OIDOID);
202 locfcinfo->args[1].isnull = false;
203 locfcinfo->args[2].value = Int32GetDatum(-1);
204 locfcinfo->args[2].isnull = false;
205
206 result = (oidvector *) DatumGetPointer(array_recv(locfcinfo));
207
208 Assert(!locfcinfo->isnull);
209
210 /* sanity checks: oidvector must be 1-D, 0-based, no nulls */
211 if (ARR_NDIM(result) != 1 ||
212 ARR_HASNULL(result) ||
213 ARR_ELEMTYPE(result) != OIDOID ||
214 ARR_LBOUND(result)[0] != 0)
216 (errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
217 errmsg("invalid oidvector data")));
218
219 PG_RETURN_POINTER(result);
220}
#define ARR_NDIM(a)
Definition: array.h:290
#define ARR_ELEMTYPE(a)
Definition: array.h:292
#define ARR_HASNULL(a)
Definition: array.h:291
#define ARR_LBOUND(a)
Definition: array.h:296
Datum array_recv(PG_FUNCTION_ARGS)
Definition: arrayfuncs.c:1271
#define Assert(condition)
Definition: c.h:815
int errcode(int sqlerrcode)
Definition: elog.c:853
int errmsg(const char *fmt,...)
Definition: elog.c:1070
#define ereport(elevel,...)
Definition: elog.h:149
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
#define LOCAL_FCINFO(name, nargs)
Definition: fmgr.h:110
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:327
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:257
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:317
static Datum Int32GetDatum(int32 X)
Definition: postgres.h:217

References ARR_ELEMTYPE, ARR_HASNULL, ARR_LBOUND, ARR_NDIM, array_recv(), Assert, buf, DatumGetPointer(), ereport, errcode(), errmsg(), ERROR, InitFunctionCallInfoData, Int32GetDatum(), InvalidOid, LOCAL_FCINFO, ObjectIdGetDatum(), PG_GETARG_POINTER, PG_RETURN_POINTER, and PointerGetDatum().

◆ oidvectorsend()

Datum oidvectorsend ( PG_FUNCTION_ARGS  )

Definition at line 226 of file oid.c.

227{
228 return array_send(fcinfo);
229}
Datum array_send(PG_FUNCTION_ARGS)
Definition: arrayfuncs.c:1548

References array_send().