PostgreSQL Source Code  git master
oid.c File Reference
#include "postgres.h"
#include <ctype.h>
#include <limits.h>
#include "catalog/pg_type.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 28 of file oid.c.

Function Documentation

◆ buildoidvector()

oidvector* buildoidvector ( const Oid oids,
int  n 
)

Definition at line 86 of file oid.c.

87 {
88  oidvector *result;
89 
90  result = (oidvector *) palloc0(OidVectorSize(n));
91 
92  if (n > 0 && oids)
93  memcpy(result->values, oids, n * sizeof(Oid));
94 
95  /*
96  * Attach standard array header. For historical reasons, we set the index
97  * lower bound to 0 not 1.
98  */
99  SET_VARSIZE(result, OidVectorSize(n));
100  result->ndim = 1;
101  result->dataoffset = 0; /* never any nulls */
102  result->elemtype = OIDOID;
103  result->dim1 = n;
104  result->lbound1 = 0;
105 
106  return result;
107 }
void * palloc0(Size size)
Definition: mcxt.c:1257
#define OidVectorSize(n)
Definition: oid.c:28
unsigned int Oid
Definition: postgres_ext.h:31
Definition: c.h:715
int dim1
Definition: c.h:720
int32 dataoffset
Definition: c.h:718
Oid elemtype
Definition: c.h:719
int lbound1
Definition: c.h:721
int ndim
Definition: c.h:717
Oid values[FLEXIBLE_ARRAY_MEMBER]
Definition: c.h:722
#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 257 of file oid.c.

258 {
259  Oid v1 = *((const Oid *) p1);
260  Oid v2 = *((const Oid *) p2);
261 
262  if (v1 < v2)
263  return -1;
264  if (v1 > v2)
265  return 1;
266  return 0;
267 }

References p2.

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

◆ oideq()

Datum oideq ( PG_FUNCTION_ARGS  )

Definition at line 275 of file oid.c.

276 {
277  Oid arg1 = PG_GETARG_OID(0);
278  Oid arg2 = PG_GETARG_OID(1);
279 
280  PG_RETURN_BOOL(arg1 == arg2);
281 }
#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 311 of file oid.c.

312 {
313  Oid arg1 = PG_GETARG_OID(0);
314  Oid arg2 = PG_GETARG_OID(1);
315 
316  PG_RETURN_BOOL(arg1 >= arg2);
317 }

References PG_GETARG_OID, and PG_RETURN_BOOL.

◆ oidgt()

Datum oidgt ( PG_FUNCTION_ARGS  )

Definition at line 320 of file oid.c.

321 {
322  Oid arg1 = PG_GETARG_OID(0);
323  Oid arg2 = PG_GETARG_OID(1);
324 
325  PG_RETURN_BOOL(arg1 > arg2);
326 }

References PG_GETARG_OID, and PG_RETURN_BOOL.

◆ oidin()

Datum oidin ( PG_FUNCTION_ARGS  )

Definition at line 36 of file oid.c.

37 {
38  char *s = PG_GETARG_CSTRING(0);
39  Oid result;
40 
41  result = uint32in_subr(s, NULL, "oid", fcinfo->context);
42  PG_RETURN_OID(result);
43 }
#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:901

References PG_GETARG_CSTRING, PG_RETURN_OID, and uint32in_subr().

Referenced by defGetObjectId(), and parseNumericOid().

◆ oidlarger()

Datum oidlarger ( PG_FUNCTION_ARGS  )

Definition at line 329 of file oid.c.

330 {
331  Oid arg1 = PG_GETARG_OID(0);
332  Oid arg2 = PG_GETARG_OID(1);
333 
334  PG_RETURN_OID((arg1 > arg2) ? arg1 : arg2);
335 }

References PG_GETARG_OID, and PG_RETURN_OID.

◆ oidle()

Datum oidle ( PG_FUNCTION_ARGS  )

Definition at line 302 of file oid.c.

303 {
304  Oid arg1 = PG_GETARG_OID(0);
305  Oid arg2 = PG_GETARG_OID(1);
306 
307  PG_RETURN_BOOL(arg1 <= arg2);
308 }

References PG_GETARG_OID, and PG_RETURN_BOOL.

◆ oidlt()

Datum oidlt ( PG_FUNCTION_ARGS  )

Definition at line 293 of file oid.c.

294 {
295  Oid arg1 = PG_GETARG_OID(0);
296  Oid arg2 = PG_GETARG_OID(1);
297 
298  PG_RETURN_BOOL(arg1 < arg2);
299 }

References PG_GETARG_OID, and PG_RETURN_BOOL.

◆ oidne()

Datum oidne ( PG_FUNCTION_ARGS  )

Definition at line 284 of file oid.c.

285 {
286  Oid arg1 = PG_GETARG_OID(0);
287  Oid arg2 = PG_GETARG_OID(1);
288 
289  PG_RETURN_BOOL(arg1 != arg2);
290 }

References PG_GETARG_OID, and PG_RETURN_BOOL.

◆ oidout()

Datum oidout ( PG_FUNCTION_ARGS  )

Definition at line 46 of file oid.c.

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

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 234 of file oid.c.

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

◆ oidrecv()

Datum oidrecv ( PG_FUNCTION_ARGS  )

Definition at line 59 of file oid.c.

60 {
62 
63  PG_RETURN_OID((Oid) pq_getmsgint(buf, sizeof(Oid)));
64 }
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
static char * buf
Definition: pg_test_fsync.c:73
unsigned int pq_getmsgint(StringInfo msg, int b)
Definition: pqformat.c:418
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 70 of file oid.c.

71 {
72  Oid arg1 = PG_GETARG_OID(0);
74 
76  pq_sendint32(&buf, arg1);
78 }
#define PG_RETURN_BYTEA_P(x)
Definition: fmgr.h:371
void pq_begintypsend(StringInfo buf)
Definition: pqformat.c:329
bytea * pq_endtypsend(StringInfo buf)
Definition: pqformat.c:349
static void pq_sendint32(StringInfo buf, uint32 i)
Definition: pqformat.h:145

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 338 of file oid.c.

339 {
340  Oid arg1 = PG_GETARG_OID(0);
341  Oid arg2 = PG_GETARG_OID(1);
342 
343  PG_RETURN_OID((arg1 < arg2) ? arg1 : arg2);
344 }

References PG_GETARG_OID, and PG_RETURN_OID.

◆ oidvectoreq()

Datum oidvectoreq ( PG_FUNCTION_ARGS  )

Definition at line 347 of file oid.c.

348 {
350 
351  PG_RETURN_BOOL(cmp == 0);
352 }
signed int int32
Definition: c.h:483
Datum btoidvectorcmp(PG_FUNCTION_ARGS)
Definition: nbtcompare.c:296
static int32 DatumGetInt32(Datum X)
Definition: postgres.h:202
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 379 of file oid.c.

380 {
382 
383  PG_RETURN_BOOL(cmp >= 0);
384 }

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

◆ oidvectorgt()

Datum oidvectorgt ( PG_FUNCTION_ARGS  )

Definition at line 387 of file oid.c.

388 {
390 
391  PG_RETURN_BOOL(cmp > 0);
392 }

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

◆ oidvectorin()

Datum oidvectorin ( PG_FUNCTION_ARGS  )

Definition at line 113 of file oid.c.

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

372 {
374 
375  PG_RETURN_BOOL(cmp <= 0);
376 }

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

◆ oidvectorlt()

Datum oidvectorlt ( PG_FUNCTION_ARGS  )

Definition at line 363 of file oid.c.

364 {
366 
367  PG_RETURN_BOOL(cmp < 0);
368 }

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

◆ oidvectorne()

Datum oidvectorne ( PG_FUNCTION_ARGS  )

Definition at line 355 of file oid.c.

356 {
358 
359  PG_RETURN_BOOL(cmp != 0);
360 }

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

◆ oidvectorout()

Datum oidvectorout ( PG_FUNCTION_ARGS  )

Definition at line 157 of file oid.c.

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

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

◆ oidvectorrecv()

Datum oidvectorrecv ( PG_FUNCTION_ARGS  )

Definition at line 183 of file oid.c.

184 {
185  LOCAL_FCINFO(locfcinfo, 3);
187  oidvector *result;
188 
189  /*
190  * Normally one would call array_recv() using DirectFunctionCall3, but
191  * that does not work since array_recv wants to cache some data using
192  * fcinfo->flinfo->fn_extra. So we need to pass it our own flinfo
193  * parameter.
194  */
195  InitFunctionCallInfoData(*locfcinfo, fcinfo->flinfo, 3,
196  InvalidOid, NULL, NULL);
197 
198  locfcinfo->args[0].value = PointerGetDatum(buf);
199  locfcinfo->args[0].isnull = false;
200  locfcinfo->args[1].value = ObjectIdGetDatum(OIDOID);
201  locfcinfo->args[1].isnull = false;
202  locfcinfo->args[2].value = Int32GetDatum(-1);
203  locfcinfo->args[2].isnull = false;
204 
205  result = (oidvector *) DatumGetPointer(array_recv(locfcinfo));
206 
207  Assert(!locfcinfo->isnull);
208 
209  /* sanity checks: oidvector must be 1-D, 0-based, no nulls */
210  if (ARR_NDIM(result) != 1 ||
211  ARR_HASNULL(result) ||
212  ARR_ELEMTYPE(result) != OIDOID ||
213  ARR_LBOUND(result)[0] != 0)
214  ereport(ERROR,
215  (errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
216  errmsg("invalid oidvector data")));
217 
218  PG_RETURN_POINTER(result);
219 }
#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:1272
int errcode(int sqlerrcode)
Definition: elog.c:858
int errmsg(const char *fmt,...)
Definition: elog.c:1069
#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
Assert(fmt[strlen(fmt) - 1] !='\n')
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:322
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:252
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:312
static Datum Int32GetDatum(int32 X)
Definition: postgres.h:212

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 225 of file oid.c.

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

References array_send().