PostgreSQL Source Code git master
Loading...
Searching...
No Matches
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)
 
void check_valid_oidvector (const oidvector *oidArray)
 
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:1417
#define OidVectorSize(n)
Definition oid.c:29
unsigned int Oid
static int fb(int x)
Definition c.h:745
int dim1
Definition c.h:750
int32 dataoffset
Definition c.h:748
Oid elemtype
Definition c.h:749
int lbound1
Definition c.h:751
int ndim
Definition c.h:747
Oid values[FLEXIBLE_ARRAY_MEMBER]
Definition c.h:752
static void SET_VARSIZE(void *PTR, Size len)
Definition varatt.h:432

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

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

◆ check_valid_oidvector()

void check_valid_oidvector ( const oidvector oidArray)

Definition at line 118 of file oid.c.

119{
120 /*
121 * We insist on ndim == 1 and dataoffset == 0 (that is, no nulls) because
122 * otherwise the array's layout will not be what calling code expects. We
123 * needn't be picky about the index lower bound though. Checking elemtype
124 * is just paranoia.
125 */
126 if (oidArray->ndim != 1 ||
127 oidArray->dataoffset != 0 ||
128 oidArray->elemtype != OIDOID)
131 errmsg("array is not a valid oidvector")));
132}
int errcode(int sqlerrcode)
Definition elog.c:864
int errmsg(const char *fmt,...)
Definition elog.c:1081
#define ERROR
Definition elog.h:39
#define ereport(elevel,...)
Definition elog.h:150

References ereport, errcode(), errmsg(), ERROR, and fb().

Referenced by btoidvectorcmp(), hashoidvector(), hashoidvectorextended(), oidvectorout(), and oidvectortypes().

◆ oid_cmp()

int oid_cmp ( const void p1,
const void p2 
)

Definition at line 287 of file oid.c.

288{
289 Oid v1 = *((const Oid *) p1);
290 Oid v2 = *((const Oid *) p2);
291
292 return pg_cmp_u32(v1, v2);
293}
static int pg_cmp_u32(uint32 a, uint32 b)
Definition int.h:719

References fb(), and pg_cmp_u32().

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

◆ oideq()

Datum oideq ( PG_FUNCTION_ARGS  )

Definition at line 301 of file oid.c.

302{
305
307}
#define PG_GETARG_OID(n)
Definition fmgr.h:275
#define PG_RETURN_BOOL(x)
Definition fmgr.h:360

References fb(), PG_GETARG_OID, and PG_RETURN_BOOL.

◆ oidge()

Datum oidge ( PG_FUNCTION_ARGS  )

Definition at line 337 of file oid.c.

338{
341
343}

References fb(), PG_GETARG_OID, and PG_RETURN_BOOL.

◆ oidgt()

Datum oidgt ( PG_FUNCTION_ARGS  )

Definition at line 346 of file oid.c.

347{
350
352}

References fb(), 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:278
#define PG_RETURN_OID(x)
Definition fmgr.h:361
uint32 uint32in_subr(const char *s, char **endloc, const char *typname, Node *escontext)
Definition numutils.c:897

References fb(), PG_GETARG_CSTRING, PG_RETURN_OID, and uint32in_subr().

Referenced by defGetObjectId(), and parseNumericOid().

◆ oidlarger()

Datum oidlarger ( PG_FUNCTION_ARGS  )

Definition at line 355 of file oid.c.

356{
359
361}

References fb(), PG_GETARG_OID, and PG_RETURN_OID.

◆ oidle()

Datum oidle ( PG_FUNCTION_ARGS  )

Definition at line 328 of file oid.c.

329{
332
334}

References fb(), PG_GETARG_OID, and PG_RETURN_BOOL.

◆ oidlt()

Datum oidlt ( PG_FUNCTION_ARGS  )

Definition at line 319 of file oid.c.

320{
323
325}

References fb(), PG_GETARG_OID, and PG_RETURN_BOOL.

◆ oidne()

Datum oidne ( PG_FUNCTION_ARGS  )

Definition at line 310 of file oid.c.

311{
314
316}

References fb(), 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:364
void * palloc(Size size)
Definition mcxt.c:1387
#define snprintf
Definition port.h:260

References fb(), 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 264 of file oid.c.

265{
266 switch (nodeTag(node))
267 {
268 case T_Integer:
269 return intVal(node);
270 case T_Float:
271
272 /*
273 * Values too large for int4 will be represented as Float
274 * constants by the lexer. Accept these if they are valid OID
275 * strings.
276 */
277 return uint32in_subr(castNode(Float, node)->fval, NULL,
278 "oid", NULL);
279 default:
280 elog(ERROR, "unrecognized node type: %d", (int) nodeTag(node));
281 }
282 return InvalidOid; /* keep compiler quiet */
283}
#define elog(elevel,...)
Definition elog.h:226
#define nodeTag(nodeptr)
Definition nodes.h:139
#define castNode(_type_, nodeptr)
Definition nodes.h:182
#define InvalidOid
Definition value.h:48
#define intVal(v)
Definition value.h:79

References castNode, elog, ERROR, fb(), 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:277
static char buf[DEFAULT_XLOG_SEG_SIZE]
unsigned int pq_getmsgint(StringInfo msg, int b)
Definition pqformat.c:414
struct StringInfoData * StringInfo
Definition string.h:15

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

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

◆ oidsend()

Datum oidsend ( PG_FUNCTION_ARGS  )

Definition at line 71 of file oid.c.

72{
75
79}
#define PG_RETURN_BYTEA_P(x)
Definition fmgr.h:373
void pq_begintypsend(StringInfo buf)
Definition pqformat.c:325
bytea * pq_endtypsend(StringInfo buf)
Definition pqformat.c:345
static void pq_sendint32(StringInfo buf, uint32 i)
Definition pqformat.h:144

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

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

◆ oidsmaller()

Datum oidsmaller ( PG_FUNCTION_ARGS  )

Definition at line 364 of file oid.c.

365{
368
370}

References fb(), PG_GETARG_OID, and PG_RETURN_OID.

◆ oidvectoreq()

Datum oidvectoreq ( PG_FUNCTION_ARGS  )

Definition at line 373 of file oid.c.

374{
376
377 PG_RETURN_BOOL(cmp == 0);
378}
int32_t int32
Definition c.h:542
Datum btoidvectorcmp(PG_FUNCTION_ARGS)
Definition nbtcompare.c:585
static int32 DatumGetInt32(Datum X)
Definition postgres.h:212
static int cmp(const chr *x, const chr *y, size_t len)

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

Referenced by oidvectoreqfast().

◆ oidvectorge()

Datum oidvectorge ( PG_FUNCTION_ARGS  )

Definition at line 405 of file oid.c.

406{
408
409 PG_RETURN_BOOL(cmp >= 0);
410}

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

◆ oidvectorgt()

Datum oidvectorgt ( PG_FUNCTION_ARGS  )

Definition at line 413 of file oid.c.

414{
416
417 PG_RETURN_BOOL(cmp > 0);
418}

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

◆ oidvectorin()

Datum oidvectorin ( PG_FUNCTION_ARGS  )

Definition at line 138 of file oid.c.

139{
140 char *oidString = PG_GETARG_CSTRING(0);
141 Node *escontext = fcinfo->context;
142 oidvector *result;
143 int nalloc;
144 int n;
145
146 nalloc = 32; /* arbitrary initial size guess */
147 result = (oidvector *) palloc0(OidVectorSize(nalloc));
148
149 for (n = 0;; n++)
150 {
151 while (*oidString && isspace((unsigned char) *oidString))
152 oidString++;
153 if (*oidString == '\0')
154 break;
155
156 if (n >= nalloc)
157 {
158 nalloc *= 2;
159 result = (oidvector *) repalloc(result, OidVectorSize(nalloc));
160 }
161
163 "oid", escontext);
164 if (SOFT_ERROR_OCCURRED(escontext))
166 }
167
168 SET_VARSIZE(result, OidVectorSize(n));
169 result->ndim = 1;
170 result->dataoffset = 0; /* never any nulls */
171 result->elemtype = OIDOID;
172 result->dim1 = n;
173 result->lbound1 = 0;
174
175 PG_RETURN_POINTER(result);
176}
#define PG_RETURN_NULL()
Definition fmgr.h:346
#define PG_RETURN_POINTER(x)
Definition fmgr.h:363
void * repalloc(void *pointer, Size size)
Definition mcxt.c:1632
#define SOFT_ERROR_OCCURRED(escontext)
Definition miscnodes.h:53
Definition nodes.h:135

References oidvector::dataoffset, oidvector::dim1, oidvector::elemtype, fb(), 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 397 of file oid.c.

398{
400
401 PG_RETURN_BOOL(cmp <= 0);
402}

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

◆ oidvectorlt()

Datum oidvectorlt ( PG_FUNCTION_ARGS  )

Definition at line 389 of file oid.c.

390{
392
393 PG_RETURN_BOOL(cmp < 0);
394}

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

◆ oidvectorne()

Datum oidvectorne ( PG_FUNCTION_ARGS  )

Definition at line 381 of file oid.c.

382{
384
385 PG_RETURN_BOOL(cmp != 0);
386}

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

◆ oidvectorout()

Datum oidvectorout ( PG_FUNCTION_ARGS  )

Definition at line 182 of file oid.c.

183{
185 int num,
186 nnums;
187 char *rp;
188 char *result;
189
190 /* validate input before fetching dim1 */
192 nnums = oidArray->dim1;
193
194 /* assumes sign, 10 digits, ' ' */
195 rp = result = (char *) palloc(nnums * 12 + 1);
196 for (num = 0; num < nnums; num++)
197 {
198 if (num != 0)
199 *rp++ = ' ';
200 sprintf(rp, "%u", oidArray->values[num]);
201 while (*++rp != '\0')
202 ;
203 }
204 *rp = '\0';
205 PG_RETURN_CSTRING(result);
206}
void check_valid_oidvector(const oidvector *oidArray)
Definition oid.c:118
#define sprintf
Definition port.h:262

References check_valid_oidvector(), fb(), palloc(), PG_GETARG_POINTER, PG_RETURN_CSTRING, and sprintf.

◆ oidvectorrecv()

Datum oidvectorrecv ( PG_FUNCTION_ARGS  )

Definition at line 212 of file oid.c.

213{
216 oidvector *result;
217
218 /*
219 * Normally one would call array_recv() using DirectFunctionCall3, but
220 * that does not work since array_recv wants to cache some data using
221 * fcinfo->flinfo->fn_extra. So we need to pass it our own flinfo
222 * parameter.
223 */
224 InitFunctionCallInfoData(*locfcinfo, fcinfo->flinfo, 3,
226
227 locfcinfo->args[0].value = PointerGetDatum(buf);
228 locfcinfo->args[0].isnull = false;
229 locfcinfo->args[1].value = ObjectIdGetDatum(OIDOID);
230 locfcinfo->args[1].isnull = false;
231 locfcinfo->args[2].value = Int32GetDatum(-1);
232 locfcinfo->args[2].isnull = false;
233
235
236 Assert(!locfcinfo->isnull);
237
238 /* sanity checks: oidvector must be 1-D, 0-based, no nulls */
239 if (ARR_NDIM(result) != 1 ||
240 ARR_HASNULL(result) ||
241 ARR_ELEMTYPE(result) != OIDOID ||
242 ARR_LBOUND(result)[0] != 0)
245 errmsg("invalid oidvector data")));
246
247 PG_RETURN_POINTER(result);
248}
#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)
#define Assert(condition)
Definition c.h:873
#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:352
static Datum ObjectIdGetDatum(Oid X)
Definition postgres.h:262
static Pointer DatumGetPointer(Datum X)
Definition postgres.h:342
static Datum Int32GetDatum(int32 X)
Definition postgres.h:222

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

◆ oidvectorsend()

Datum oidvectorsend ( PG_FUNCTION_ARGS  )

Definition at line 254 of file oid.c.

255{
256 /* We don't do check_valid_oidvector, since array_send won't care */
257 return array_send(fcinfo);
258}
Datum array_send(PG_FUNCTION_ARGS)

References array_send().