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

Go to the source code of this file.

Data Structures

struct  generate_series_fctx
 

Macros

#define Int2VectorSize(n)   (offsetof(int2vector, values) + (n) * sizeof(int16))
 

Functions

Datum int2in (PG_FUNCTION_ARGS)
 
Datum int2out (PG_FUNCTION_ARGS)
 
Datum int2recv (PG_FUNCTION_ARGS)
 
Datum int2send (PG_FUNCTION_ARGS)
 
int2vectorbuildint2vector (const int16 *int2s, int n)
 
Datum int2vectorin (PG_FUNCTION_ARGS)
 
Datum int2vectorout (PG_FUNCTION_ARGS)
 
Datum int2vectorrecv (PG_FUNCTION_ARGS)
 
Datum int2vectorsend (PG_FUNCTION_ARGS)
 
Datum int4in (PG_FUNCTION_ARGS)
 
Datum int4out (PG_FUNCTION_ARGS)
 
Datum int4recv (PG_FUNCTION_ARGS)
 
Datum int4send (PG_FUNCTION_ARGS)
 
Datum i2toi4 (PG_FUNCTION_ARGS)
 
Datum i4toi2 (PG_FUNCTION_ARGS)
 
Datum int4_bool (PG_FUNCTION_ARGS)
 
Datum bool_int4 (PG_FUNCTION_ARGS)
 
Datum int4eq (PG_FUNCTION_ARGS)
 
Datum int4ne (PG_FUNCTION_ARGS)
 
Datum int4lt (PG_FUNCTION_ARGS)
 
Datum int4le (PG_FUNCTION_ARGS)
 
Datum int4gt (PG_FUNCTION_ARGS)
 
Datum int4ge (PG_FUNCTION_ARGS)
 
Datum int2eq (PG_FUNCTION_ARGS)
 
Datum int2ne (PG_FUNCTION_ARGS)
 
Datum int2lt (PG_FUNCTION_ARGS)
 
Datum int2le (PG_FUNCTION_ARGS)
 
Datum int2gt (PG_FUNCTION_ARGS)
 
Datum int2ge (PG_FUNCTION_ARGS)
 
Datum int24eq (PG_FUNCTION_ARGS)
 
Datum int24ne (PG_FUNCTION_ARGS)
 
Datum int24lt (PG_FUNCTION_ARGS)
 
Datum int24le (PG_FUNCTION_ARGS)
 
Datum int24gt (PG_FUNCTION_ARGS)
 
Datum int24ge (PG_FUNCTION_ARGS)
 
Datum int42eq (PG_FUNCTION_ARGS)
 
Datum int42ne (PG_FUNCTION_ARGS)
 
Datum int42lt (PG_FUNCTION_ARGS)
 
Datum int42le (PG_FUNCTION_ARGS)
 
Datum int42gt (PG_FUNCTION_ARGS)
 
Datum int42ge (PG_FUNCTION_ARGS)
 
Datum in_range_int4_int4 (PG_FUNCTION_ARGS)
 
Datum in_range_int4_int2 (PG_FUNCTION_ARGS)
 
Datum in_range_int4_int8 (PG_FUNCTION_ARGS)
 
Datum in_range_int2_int4 (PG_FUNCTION_ARGS)
 
Datum in_range_int2_int2 (PG_FUNCTION_ARGS)
 
Datum in_range_int2_int8 (PG_FUNCTION_ARGS)
 
Datum int4um (PG_FUNCTION_ARGS)
 
Datum int4up (PG_FUNCTION_ARGS)
 
Datum int4pl (PG_FUNCTION_ARGS)
 
Datum int4mi (PG_FUNCTION_ARGS)
 
Datum int4mul (PG_FUNCTION_ARGS)
 
Datum int4div (PG_FUNCTION_ARGS)
 
Datum int4inc (PG_FUNCTION_ARGS)
 
Datum int2um (PG_FUNCTION_ARGS)
 
Datum int2up (PG_FUNCTION_ARGS)
 
Datum int2pl (PG_FUNCTION_ARGS)
 
Datum int2mi (PG_FUNCTION_ARGS)
 
Datum int2mul (PG_FUNCTION_ARGS)
 
Datum int2div (PG_FUNCTION_ARGS)
 
Datum int24pl (PG_FUNCTION_ARGS)
 
Datum int24mi (PG_FUNCTION_ARGS)
 
Datum int24mul (PG_FUNCTION_ARGS)
 
Datum int24div (PG_FUNCTION_ARGS)
 
Datum int42pl (PG_FUNCTION_ARGS)
 
Datum int42mi (PG_FUNCTION_ARGS)
 
Datum int42mul (PG_FUNCTION_ARGS)
 
Datum int42div (PG_FUNCTION_ARGS)
 
Datum int4mod (PG_FUNCTION_ARGS)
 
Datum int2mod (PG_FUNCTION_ARGS)
 
Datum int4abs (PG_FUNCTION_ARGS)
 
Datum int2abs (PG_FUNCTION_ARGS)
 
static int32 int4gcd_internal (int32 arg1, int32 arg2)
 
Datum int4gcd (PG_FUNCTION_ARGS)
 
Datum int4lcm (PG_FUNCTION_ARGS)
 
Datum int2larger (PG_FUNCTION_ARGS)
 
Datum int2smaller (PG_FUNCTION_ARGS)
 
Datum int4larger (PG_FUNCTION_ARGS)
 
Datum int4smaller (PG_FUNCTION_ARGS)
 
Datum int4and (PG_FUNCTION_ARGS)
 
Datum int4or (PG_FUNCTION_ARGS)
 
Datum int4xor (PG_FUNCTION_ARGS)
 
Datum int4shl (PG_FUNCTION_ARGS)
 
Datum int4shr (PG_FUNCTION_ARGS)
 
Datum int4not (PG_FUNCTION_ARGS)
 
Datum int2and (PG_FUNCTION_ARGS)
 
Datum int2or (PG_FUNCTION_ARGS)
 
Datum int2xor (PG_FUNCTION_ARGS)
 
Datum int2not (PG_FUNCTION_ARGS)
 
Datum int2shl (PG_FUNCTION_ARGS)
 
Datum int2shr (PG_FUNCTION_ARGS)
 
Datum generate_series_int4 (PG_FUNCTION_ARGS)
 
Datum generate_series_step_int4 (PG_FUNCTION_ARGS)
 
Datum generate_series_int4_support (PG_FUNCTION_ARGS)
 

Macro Definition Documentation

◆ Int2VectorSize

#define Int2VectorSize (   n)    (offsetof(int2vector, values) + (n) * sizeof(int16))

Definition at line 45 of file int.c.

Function Documentation

◆ bool_int4()

Datum bool_int4 ( PG_FUNCTION_ARGS  )

Definition at line 375 of file int.c.

376 {
377  if (PG_GETARG_BOOL(0) == false)
378  PG_RETURN_INT32(0);
379  else
380  PG_RETURN_INT32(1);
381 }
#define PG_RETURN_INT32(x)
Definition: fmgr.h:354
#define PG_GETARG_BOOL(n)
Definition: fmgr.h:274

References PG_GETARG_BOOL, and PG_RETURN_INT32.

◆ buildint2vector()

int2vector* buildint2vector ( const int16 int2s,
int  n 
)

Definition at line 114 of file int.c.

115 {
116  int2vector *result;
117 
118  result = (int2vector *) palloc0(Int2VectorSize(n));
119 
120  if (n > 0 && int2s)
121  memcpy(result->values, int2s, n * sizeof(int16));
122 
123  /*
124  * Attach standard array header. For historical reasons, we set the index
125  * lower bound to 0 not 1.
126  */
127  SET_VARSIZE(result, Int2VectorSize(n));
128  result->ndim = 1;
129  result->dataoffset = 0; /* never any nulls */
130  result->elemtype = INT2OID;
131  result->dim1 = n;
132  result->lbound1 = 0;
133 
134  return result;
135 }
signed short int16
Definition: c.h:428
#define Int2VectorSize(n)
Definition: int.c:45
void * palloc0(Size size)
Definition: mcxt.c:1099
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:342
Definition: c.h:650
int ndim
Definition: c.h:652
int dim1
Definition: c.h:655
Oid elemtype
Definition: c.h:654
int16 values[FLEXIBLE_ARRAY_MEMBER]
Definition: c.h:657
int32 dataoffset
Definition: c.h:653
int lbound1
Definition: c.h:656

References int2vector::dataoffset, int2vector::dim1, int2vector::elemtype, Int2VectorSize, int2vector::lbound1, int2vector::ndim, palloc0(), SET_VARSIZE, and int2vector::values.

Referenced by CreateStatistics(), CreateTriggerFiringOn(), publication_add_relation(), StorePartitionKey(), and UpdateIndexRelation().

◆ generate_series_int4()

Datum generate_series_int4 ( PG_FUNCTION_ARGS  )

Definition at line 1506 of file int.c.

1507 {
1508  return generate_series_step_int4(fcinfo);
1509 }
Datum generate_series_step_int4(PG_FUNCTION_ARGS)
Definition: int.c:1512

References generate_series_step_int4().

◆ generate_series_int4_support()

Datum generate_series_int4_support ( PG_FUNCTION_ARGS  )

Definition at line 1588 of file int.c.

1589 {
1590  Node *rawreq = (Node *) PG_GETARG_POINTER(0);
1591  Node *ret = NULL;
1592 
1593  if (IsA(rawreq, SupportRequestRows))
1594  {
1595  /* Try to estimate the number of rows returned */
1596  SupportRequestRows *req = (SupportRequestRows *) rawreq;
1597 
1598  if (is_funcclause(req->node)) /* be paranoid */
1599  {
1600  List *args = ((FuncExpr *) req->node)->args;
1601  Node *arg1,
1602  *arg2,
1603  *arg3;
1604 
1605  /* We can use estimated argument values here */
1607  arg2 = estimate_expression_value(req->root, lsecond(args));
1608  if (list_length(args) >= 3)
1609  arg3 = estimate_expression_value(req->root, lthird(args));
1610  else
1611  arg3 = NULL;
1612 
1613  /*
1614  * If any argument is constant NULL, we can safely assume that
1615  * zero rows are returned. Otherwise, if they're all non-NULL
1616  * constants, we can calculate the number of rows that will be
1617  * returned. Use double arithmetic to avoid overflow hazards.
1618  */
1619  if ((IsA(arg1, Const) &&
1620  ((Const *) arg1)->constisnull) ||
1621  (IsA(arg2, Const) &&
1622  ((Const *) arg2)->constisnull) ||
1623  (arg3 != NULL && IsA(arg3, Const) &&
1624  ((Const *) arg3)->constisnull))
1625  {
1626  req->rows = 0;
1627  ret = (Node *) req;
1628  }
1629  else if (IsA(arg1, Const) &&
1630  IsA(arg2, Const) &&
1631  (arg3 == NULL || IsA(arg3, Const)))
1632  {
1633  double start,
1634  finish,
1635  step;
1636 
1637  start = DatumGetInt32(((Const *) arg1)->constvalue);
1638  finish = DatumGetInt32(((Const *) arg2)->constvalue);
1639  step = arg3 ? DatumGetInt32(((Const *) arg3)->constvalue) : 1;
1640 
1641  /* This equation works for either sign of step */
1642  if (step != 0)
1643  {
1644  req->rows = floor((finish - start + step) / step);
1645  ret = (Node *) req;
1646  }
1647  }
1648  }
1649  }
1650 
1651  PG_RETURN_POINTER(ret);
1652 }
Node * estimate_expression_value(PlannerInfo *root, Node *node)
Definition: clauses.c:2290
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:361
static bool is_funcclause(const void *clause)
Definition: nodeFuncs.h:57
#define IsA(nodeptr, _type_)
Definition: nodes.h:624
static int list_length(const List *l)
Definition: pg_list.h:149
#define lthird(l)
Definition: pg_list.h:184
#define linitial(l)
Definition: pg_list.h:174
#define lsecond(l)
Definition: pg_list.h:179
#define DatumGetInt32(X)
Definition: postgres.h:516
Definition: pg_list.h:51
Definition: nodes.h:574
struct PlannerInfo * root
Definition: supportnodes.h:163

References generate_unaccent_rules::args, DatumGetInt32, estimate_expression_value(), is_funcclause(), IsA, linitial, list_length(), lsecond, lthird, SupportRequestRows::node, PG_GETARG_POINTER, PG_RETURN_POINTER, SupportRequestRows::root, and SupportRequestRows::rows.

◆ generate_series_step_int4()

Datum generate_series_step_int4 ( PG_FUNCTION_ARGS  )

Definition at line 1512 of file int.c.

1513 {
1514  FuncCallContext *funcctx;
1515  generate_series_fctx *fctx;
1516  int32 result;
1517  MemoryContext oldcontext;
1518 
1519  /* stuff done only on the first call of the function */
1520  if (SRF_IS_FIRSTCALL())
1521  {
1522  int32 start = PG_GETARG_INT32(0);
1523  int32 finish = PG_GETARG_INT32(1);
1524  int32 step = 1;
1525 
1526  /* see if we were given an explicit step size */
1527  if (PG_NARGS() == 3)
1528  step = PG_GETARG_INT32(2);
1529  if (step == 0)
1530  ereport(ERROR,
1531  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1532  errmsg("step size cannot equal zero")));
1533 
1534  /* create a function context for cross-call persistence */
1535  funcctx = SRF_FIRSTCALL_INIT();
1536 
1537  /*
1538  * switch to memory context appropriate for multiple function calls
1539  */
1540  oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
1541 
1542  /* allocate memory for user context */
1543  fctx = (generate_series_fctx *) palloc(sizeof(generate_series_fctx));
1544 
1545  /*
1546  * Use fctx to keep state from call to call. Seed current with the
1547  * original start value
1548  */
1549  fctx->current = start;
1550  fctx->finish = finish;
1551  fctx->step = step;
1552 
1553  funcctx->user_fctx = fctx;
1554  MemoryContextSwitchTo(oldcontext);
1555  }
1556 
1557  /* stuff done on every call of the function */
1558  funcctx = SRF_PERCALL_SETUP();
1559 
1560  /*
1561  * get the saved state and use current as the result for this iteration
1562  */
1563  fctx = funcctx->user_fctx;
1564  result = fctx->current;
1565 
1566  if ((fctx->step > 0 && fctx->current <= fctx->finish) ||
1567  (fctx->step < 0 && fctx->current >= fctx->finish))
1568  {
1569  /*
1570  * Increment current in preparation for next iteration. If next-value
1571  * computation overflows, this is the final result.
1572  */
1573  if (pg_add_s32_overflow(fctx->current, fctx->step, &fctx->current))
1574  fctx->step = 0;
1575 
1576  /* do when there is more left to send */
1577  SRF_RETURN_NEXT(funcctx, Int32GetDatum(result));
1578  }
1579  else
1580  /* do when there is no more left */
1581  SRF_RETURN_DONE(funcctx);
1582 }
signed int int32
Definition: c.h:429
int errcode(int sqlerrcode)
Definition: elog.c:693
int errmsg(const char *fmt,...)
Definition: elog.c:904
#define ERROR
Definition: elog.h:33
#define ereport(elevel,...)
Definition: elog.h:143
#define PG_NARGS()
Definition: fmgr.h:203
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
#define SRF_IS_FIRSTCALL()
Definition: funcapi.h:299
#define SRF_PERCALL_SETUP()
Definition: funcapi.h:303
#define SRF_RETURN_NEXT(_funcctx, _result)
Definition: funcapi.h:305
#define SRF_FIRSTCALL_INIT()
Definition: funcapi.h:301
#define SRF_RETURN_DONE(_funcctx)
Definition: funcapi.h:323
static bool pg_add_s32_overflow(int32 a, int32 b, int32 *result)
Definition: int.h:104
void * palloc(Size size)
Definition: mcxt.c:1068
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
#define Int32GetDatum(X)
Definition: postgres.h:523
void * user_fctx
Definition: funcapi.h:82
MemoryContext multi_call_memory_ctx
Definition: funcapi.h:101
int32 current
Definition: int.c:49
int32 finish
Definition: int.c:50

References generate_series_fctx::current, ereport, errcode(), errmsg(), ERROR, generate_series_fctx::finish, Int32GetDatum, MemoryContextSwitchTo(), FuncCallContext::multi_call_memory_ctx, palloc(), pg_add_s32_overflow(), PG_GETARG_INT32, PG_NARGS, SRF_FIRSTCALL_INIT, SRF_IS_FIRSTCALL, SRF_PERCALL_SETUP, SRF_RETURN_DONE, SRF_RETURN_NEXT, generate_series_fctx::step, and FuncCallContext::user_fctx.

Referenced by generate_series_int4().

◆ i2toi4()

Datum i2toi4 ( PG_FUNCTION_ARGS  )

Definition at line 343 of file int.c.

344 {
345  int16 arg1 = PG_GETARG_INT16(0);
346 
347  PG_RETURN_INT32((int32) arg1);
348 }
#define PG_GETARG_INT16(n)
Definition: fmgr.h:271

References PG_GETARG_INT16, and PG_RETURN_INT32.

◆ i4toi2()

Datum i4toi2 ( PG_FUNCTION_ARGS  )

Definition at line 351 of file int.c.

352 {
353  int32 arg1 = PG_GETARG_INT32(0);
354 
355  if (unlikely(arg1 < SHRT_MIN) || unlikely(arg1 > SHRT_MAX))
356  ereport(ERROR,
357  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
358  errmsg("smallint out of range")));
359 
360  PG_RETURN_INT16((int16) arg1);
361 }
#define unlikely(x)
Definition: c.h:273
#define PG_RETURN_INT16(x)
Definition: fmgr.h:356

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT32, PG_RETURN_INT16, and unlikely.

◆ in_range_int2_int2()

Datum in_range_int2_int2 ( PG_FUNCTION_ARGS  )

Definition at line 742 of file int.c.

743 {
744  /* Doesn't seem worth duplicating code for, so just invoke int2_int4 */
746  PG_GETARG_DATUM(0),
747  PG_GETARG_DATUM(1),
749  PG_GETARG_DATUM(3),
750  PG_GETARG_DATUM(4));
751 }
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:268
#define DirectFunctionCall5(func, arg1, arg2, arg3, arg4, arg5)
Definition: fmgr.h:639
Datum in_range_int2_int4(PG_FUNCTION_ARGS)
Definition: int.c:707

References DirectFunctionCall5, in_range_int2_int4(), Int32GetDatum, PG_GETARG_DATUM, and PG_GETARG_INT16.

◆ in_range_int2_int4()

Datum in_range_int2_int4 ( PG_FUNCTION_ARGS  )

Definition at line 707 of file int.c.

708 {
709  /* We must do all the math in int32 */
711  int32 base = (int32) PG_GETARG_INT16(1);
712  int32 offset = PG_GETARG_INT32(2);
713  bool sub = PG_GETARG_BOOL(3);
714  bool less = PG_GETARG_BOOL(4);
715  int32 sum;
716 
717  if (offset < 0)
718  ereport(ERROR,
719  (errcode(ERRCODE_INVALID_PRECEDING_OR_FOLLOWING_SIZE),
720  errmsg("invalid preceding or following size in window function")));
721 
722  if (sub)
723  offset = -offset; /* cannot overflow */
724 
725  if (unlikely(pg_add_s32_overflow(base, offset, &sum)))
726  {
727  /*
728  * If sub is false, the true sum is surely more than val, so correct
729  * answer is the same as "less". If sub is true, the true sum is
730  * surely less than val, so the answer is "!less".
731  */
732  PG_RETURN_BOOL(sub ? !less : less);
733  }
734 
735  if (less)
736  PG_RETURN_BOOL(val <= sum);
737  else
738  PG_RETURN_BOOL(val >= sum);
739 }
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
long val
Definition: informix.c:664

References ereport, errcode(), errmsg(), ERROR, pg_add_s32_overflow(), PG_GETARG_BOOL, PG_GETARG_INT16, PG_GETARG_INT32, PG_RETURN_BOOL, unlikely, and val.

Referenced by in_range_int2_int2().

◆ in_range_int2_int8()

Datum in_range_int2_int8 ( PG_FUNCTION_ARGS  )

Definition at line 754 of file int.c.

755 {
756  /* Doesn't seem worth duplicating code for, so just invoke int4_int8 */
760  PG_GETARG_DATUM(2),
761  PG_GETARG_DATUM(3),
762  PG_GETARG_DATUM(4));
763 }
Datum in_range_int4_int8(PG_FUNCTION_ARGS)
Definition: int.c:672

References DirectFunctionCall5, in_range_int4_int8(), Int32GetDatum, PG_GETARG_DATUM, and PG_GETARG_INT16.

◆ in_range_int4_int2()

Datum in_range_int4_int2 ( PG_FUNCTION_ARGS  )

Definition at line 660 of file int.c.

661 {
662  /* Doesn't seem worth duplicating code for, so just invoke int4_int4 */
664  PG_GETARG_DATUM(0),
665  PG_GETARG_DATUM(1),
667  PG_GETARG_DATUM(3),
668  PG_GETARG_DATUM(4));
669 }
Datum in_range_int4_int4(PG_FUNCTION_ARGS)
Definition: int.c:626

References DirectFunctionCall5, in_range_int4_int4(), Int32GetDatum, PG_GETARG_DATUM, and PG_GETARG_INT16.

◆ in_range_int4_int4()

Datum in_range_int4_int4 ( PG_FUNCTION_ARGS  )

Definition at line 626 of file int.c.

627 {
629  int32 base = PG_GETARG_INT32(1);
630  int32 offset = PG_GETARG_INT32(2);
631  bool sub = PG_GETARG_BOOL(3);
632  bool less = PG_GETARG_BOOL(4);
633  int32 sum;
634 
635  if (offset < 0)
636  ereport(ERROR,
637  (errcode(ERRCODE_INVALID_PRECEDING_OR_FOLLOWING_SIZE),
638  errmsg("invalid preceding or following size in window function")));
639 
640  if (sub)
641  offset = -offset; /* cannot overflow */
642 
643  if (unlikely(pg_add_s32_overflow(base, offset, &sum)))
644  {
645  /*
646  * If sub is false, the true sum is surely more than val, so correct
647  * answer is the same as "less". If sub is true, the true sum is
648  * surely less than val, so the answer is "!less".
649  */
650  PG_RETURN_BOOL(sub ? !less : less);
651  }
652 
653  if (less)
654  PG_RETURN_BOOL(val <= sum);
655  else
656  PG_RETURN_BOOL(val >= sum);
657 }

References ereport, errcode(), errmsg(), ERROR, pg_add_s32_overflow(), PG_GETARG_BOOL, PG_GETARG_INT32, PG_RETURN_BOOL, unlikely, and val.

Referenced by in_range_int4_int2().

◆ in_range_int4_int8()

Datum in_range_int4_int8 ( PG_FUNCTION_ARGS  )

Definition at line 672 of file int.c.

673 {
674  /* We must do all the math in int64 */
675  int64 val = (int64) PG_GETARG_INT32(0);
676  int64 base = (int64) PG_GETARG_INT32(1);
677  int64 offset = PG_GETARG_INT64(2);
678  bool sub = PG_GETARG_BOOL(3);
679  bool less = PG_GETARG_BOOL(4);
680  int64 sum;
681 
682  if (offset < 0)
683  ereport(ERROR,
684  (errcode(ERRCODE_INVALID_PRECEDING_OR_FOLLOWING_SIZE),
685  errmsg("invalid preceding or following size in window function")));
686 
687  if (sub)
688  offset = -offset; /* cannot overflow */
689 
690  if (unlikely(pg_add_s64_overflow(base, offset, &sum)))
691  {
692  /*
693  * If sub is false, the true sum is surely more than val, so correct
694  * answer is the same as "less". If sub is true, the true sum is
695  * surely less than val, so the answer is "!less".
696  */
697  PG_RETURN_BOOL(sub ? !less : less);
698  }
699 
700  if (less)
701  PG_RETURN_BOOL(val <= sum);
702  else
703  PG_RETURN_BOOL(val >= sum);
704 }
#define PG_GETARG_INT64(n)
Definition: fmgr.h:283
static bool pg_add_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:161

References ereport, errcode(), errmsg(), ERROR, pg_add_s64_overflow(), PG_GETARG_BOOL, PG_GETARG_INT32, PG_GETARG_INT64, PG_RETURN_BOOL, unlikely, and val.

Referenced by in_range_int2_int8().

◆ int24div()

Datum int24div ( PG_FUNCTION_ARGS  )

Definition at line 1033 of file int.c.

1034 {
1035  int16 arg1 = PG_GETARG_INT16(0);
1036  int32 arg2 = PG_GETARG_INT32(1);
1037 
1038  if (unlikely(arg2 == 0))
1039  {
1040  ereport(ERROR,
1041  (errcode(ERRCODE_DIVISION_BY_ZERO),
1042  errmsg("division by zero")));
1043  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
1044  PG_RETURN_NULL();
1045  }
1046 
1047  /* No overflow is possible */
1048  PG_RETURN_INT32((int32) arg1 / arg2);
1049 }
#define PG_RETURN_NULL()
Definition: fmgr.h:345

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, PG_GETARG_INT32, PG_RETURN_INT32, PG_RETURN_NULL, and unlikely.

◆ int24eq()

Datum int24eq ( PG_FUNCTION_ARGS  )

Definition at line 507 of file int.c.

508 {
509  int16 arg1 = PG_GETARG_INT16(0);
510  int32 arg2 = PG_GETARG_INT32(1);
511 
512  PG_RETURN_BOOL(arg1 == arg2);
513 }

References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.

◆ int24ge()

Datum int24ge ( PG_FUNCTION_ARGS  )

Definition at line 552 of file int.c.

553 {
554  int16 arg1 = PG_GETARG_INT16(0);
555  int32 arg2 = PG_GETARG_INT32(1);
556 
557  PG_RETURN_BOOL(arg1 >= arg2);
558 }

References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.

◆ int24gt()

Datum int24gt ( PG_FUNCTION_ARGS  )

Definition at line 543 of file int.c.

544 {
545  int16 arg1 = PG_GETARG_INT16(0);
546  int32 arg2 = PG_GETARG_INT32(1);
547 
548  PG_RETURN_BOOL(arg1 > arg2);
549 }

References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.

◆ int24le()

Datum int24le ( PG_FUNCTION_ARGS  )

Definition at line 534 of file int.c.

535 {
536  int16 arg1 = PG_GETARG_INT16(0);
537  int32 arg2 = PG_GETARG_INT32(1);
538 
539  PG_RETURN_BOOL(arg1 <= arg2);
540 }

References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.

◆ int24lt()

Datum int24lt ( PG_FUNCTION_ARGS  )

Definition at line 525 of file int.c.

526 {
527  int16 arg1 = PG_GETARG_INT16(0);
528  int32 arg2 = PG_GETARG_INT32(1);
529 
530  PG_RETURN_BOOL(arg1 < arg2);
531 }

References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.

◆ int24mi()

Datum int24mi ( PG_FUNCTION_ARGS  )

Definition at line 1005 of file int.c.

1006 {
1007  int16 arg1 = PG_GETARG_INT16(0);
1008  int32 arg2 = PG_GETARG_INT32(1);
1009  int32 result;
1010 
1011  if (unlikely(pg_sub_s32_overflow((int32) arg1, arg2, &result)))
1012  ereport(ERROR,
1013  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1014  errmsg("integer out of range")));
1015  PG_RETURN_INT32(result);
1016 }
static bool pg_sub_s32_overflow(int32 a, int32 b, int32 *result)
Definition: int.h:122

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, PG_GETARG_INT32, PG_RETURN_INT32, pg_sub_s32_overflow(), and unlikely.

◆ int24mul()

Datum int24mul ( PG_FUNCTION_ARGS  )

Definition at line 1019 of file int.c.

1020 {
1021  int16 arg1 = PG_GETARG_INT16(0);
1022  int32 arg2 = PG_GETARG_INT32(1);
1023  int32 result;
1024 
1025  if (unlikely(pg_mul_s32_overflow((int32) arg1, arg2, &result)))
1026  ereport(ERROR,
1027  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1028  errmsg("integer out of range")));
1029  PG_RETURN_INT32(result);
1030 }
static bool pg_mul_s32_overflow(int32 a, int32 b, int32 *result)
Definition: int.h:140

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, PG_GETARG_INT32, pg_mul_s32_overflow(), PG_RETURN_INT32, and unlikely.

◆ int24ne()

Datum int24ne ( PG_FUNCTION_ARGS  )

Definition at line 516 of file int.c.

517 {
518  int16 arg1 = PG_GETARG_INT16(0);
519  int32 arg2 = PG_GETARG_INT32(1);
520 
521  PG_RETURN_BOOL(arg1 != arg2);
522 }

References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.

◆ int24pl()

Datum int24pl ( PG_FUNCTION_ARGS  )

Definition at line 991 of file int.c.

992 {
993  int16 arg1 = PG_GETARG_INT16(0);
994  int32 arg2 = PG_GETARG_INT32(1);
995  int32 result;
996 
997  if (unlikely(pg_add_s32_overflow((int32) arg1, arg2, &result)))
998  ereport(ERROR,
999  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1000  errmsg("integer out of range")));
1001  PG_RETURN_INT32(result);
1002 }

References ereport, errcode(), errmsg(), ERROR, pg_add_s32_overflow(), PG_GETARG_INT16, PG_GETARG_INT32, PG_RETURN_INT32, and unlikely.

◆ int2abs()

Datum int2abs ( PG_FUNCTION_ARGS  )

Definition at line 1208 of file int.c.

1209 {
1210  int16 arg1 = PG_GETARG_INT16(0);
1211  int16 result;
1212 
1213  if (unlikely(arg1 == PG_INT16_MIN))
1214  ereport(ERROR,
1215  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1216  errmsg("smallint out of range")));
1217  result = (arg1 < 0) ? -arg1 : arg1;
1218  PG_RETURN_INT16(result);
1219 }
#define PG_INT16_MIN
Definition: c.h:520

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, PG_INT16_MIN, PG_RETURN_INT16, and unlikely.

◆ int2and()

Datum int2and ( PG_FUNCTION_ARGS  )

Definition at line 1449 of file int.c.

1450 {
1451  int16 arg1 = PG_GETARG_INT16(0);
1452  int16 arg2 = PG_GETARG_INT16(1);
1453 
1454  PG_RETURN_INT16(arg1 & arg2);
1455 }

References PG_GETARG_INT16, and PG_RETURN_INT16.

◆ int2div()

Datum int2div ( PG_FUNCTION_ARGS  )

Definition at line 952 of file int.c.

953 {
954  int16 arg1 = PG_GETARG_INT16(0);
955  int16 arg2 = PG_GETARG_INT16(1);
956  int16 result;
957 
958  if (arg2 == 0)
959  {
960  ereport(ERROR,
961  (errcode(ERRCODE_DIVISION_BY_ZERO),
962  errmsg("division by zero")));
963  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
964  PG_RETURN_NULL();
965  }
966 
967  /*
968  * SHRT_MIN / -1 is problematic, since the result can't be represented on
969  * a two's-complement machine. Some machines produce SHRT_MIN, some
970  * produce zero, some throw an exception. We can dodge the problem by
971  * recognizing that division by -1 is the same as negation.
972  */
973  if (arg2 == -1)
974  {
975  if (unlikely(arg1 == PG_INT16_MIN))
976  ereport(ERROR,
977  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
978  errmsg("smallint out of range")));
979  result = -arg1;
980  PG_RETURN_INT16(result);
981  }
982 
983  /* No overflow is possible */
984 
985  result = arg1 / arg2;
986 
987  PG_RETURN_INT16(result);
988 }

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, PG_INT16_MIN, PG_RETURN_INT16, PG_RETURN_NULL, and unlikely.

◆ int2eq()

Datum int2eq ( PG_FUNCTION_ARGS  )

Definition at line 453 of file int.c.

454 {
455  int16 arg1 = PG_GETARG_INT16(0);
456  int16 arg2 = PG_GETARG_INT16(1);
457 
458  PG_RETURN_BOOL(arg1 == arg2);
459 }

References PG_GETARG_INT16, and PG_RETURN_BOOL.

◆ int2ge()

Datum int2ge ( PG_FUNCTION_ARGS  )

Definition at line 498 of file int.c.

499 {
500  int16 arg1 = PG_GETARG_INT16(0);
501  int16 arg2 = PG_GETARG_INT16(1);
502 
503  PG_RETURN_BOOL(arg1 >= arg2);
504 }

References PG_GETARG_INT16, and PG_RETURN_BOOL.

◆ int2gt()

Datum int2gt ( PG_FUNCTION_ARGS  )

Definition at line 489 of file int.c.

490 {
491  int16 arg1 = PG_GETARG_INT16(0);
492  int16 arg2 = PG_GETARG_INT16(1);
493 
494  PG_RETURN_BOOL(arg1 > arg2);
495 }

References PG_GETARG_INT16, and PG_RETURN_BOOL.

◆ int2in()

Datum int2in ( PG_FUNCTION_ARGS  )

Definition at line 63 of file int.c.

64 {
65  char *num = PG_GETARG_CSTRING(0);
66 
68 }
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:277
int16 pg_strtoint16(const char *s)
Definition: numutils.c:99

References PG_GETARG_CSTRING, PG_RETURN_INT16, and pg_strtoint16().

◆ int2larger()

Datum int2larger ( PG_FUNCTION_ARGS  )

Definition at line 1349 of file int.c.

1350 {
1351  int16 arg1 = PG_GETARG_INT16(0);
1352  int16 arg2 = PG_GETARG_INT16(1);
1353 
1354  PG_RETURN_INT16((arg1 > arg2) ? arg1 : arg2);
1355 }

References PG_GETARG_INT16, and PG_RETURN_INT16.

◆ int2le()

Datum int2le ( PG_FUNCTION_ARGS  )

Definition at line 480 of file int.c.

481 {
482  int16 arg1 = PG_GETARG_INT16(0);
483  int16 arg2 = PG_GETARG_INT16(1);
484 
485  PG_RETURN_BOOL(arg1 <= arg2);
486 }

References PG_GETARG_INT16, and PG_RETURN_BOOL.

◆ int2lt()

Datum int2lt ( PG_FUNCTION_ARGS  )

Definition at line 471 of file int.c.

472 {
473  int16 arg1 = PG_GETARG_INT16(0);
474  int16 arg2 = PG_GETARG_INT16(1);
475 
476  PG_RETURN_BOOL(arg1 < arg2);
477 }

References PG_GETARG_INT16, and PG_RETURN_BOOL.

◆ int2mi()

Datum int2mi ( PG_FUNCTION_ARGS  )

Definition at line 923 of file int.c.

924 {
925  int16 arg1 = PG_GETARG_INT16(0);
926  int16 arg2 = PG_GETARG_INT16(1);
927  int16 result;
928 
929  if (unlikely(pg_sub_s16_overflow(arg1, arg2, &result)))
930  ereport(ERROR,
931  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
932  errmsg("smallint out of range")));
933  PG_RETURN_INT16(result);
934 }
static bool pg_sub_s16_overflow(int16 a, int16 b, int16 *result)
Definition: int.h:65

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, PG_RETURN_INT16, pg_sub_s16_overflow(), and unlikely.

◆ int2mod()

Datum int2mod ( PG_FUNCTION_ARGS  )

Definition at line 1161 of file int.c.

1162 {
1163  int16 arg1 = PG_GETARG_INT16(0);
1164  int16 arg2 = PG_GETARG_INT16(1);
1165 
1166  if (unlikely(arg2 == 0))
1167  {
1168  ereport(ERROR,
1169  (errcode(ERRCODE_DIVISION_BY_ZERO),
1170  errmsg("division by zero")));
1171  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
1172  PG_RETURN_NULL();
1173  }
1174 
1175  /*
1176  * Some machines throw a floating-point exception for INT_MIN % -1, which
1177  * is a bit silly since the correct answer is perfectly well-defined,
1178  * namely zero. (It's not clear this ever happens when dealing with
1179  * int16, but we might as well have the test for safety.)
1180  */
1181  if (arg2 == -1)
1182  PG_RETURN_INT16(0);
1183 
1184  /* No overflow is possible */
1185 
1186  PG_RETURN_INT16(arg1 % arg2);
1187 }

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, PG_RETURN_INT16, PG_RETURN_NULL, and unlikely.

◆ int2mul()

Datum int2mul ( PG_FUNCTION_ARGS  )

Definition at line 937 of file int.c.

938 {
939  int16 arg1 = PG_GETARG_INT16(0);
940  int16 arg2 = PG_GETARG_INT16(1);
941  int16 result;
942 
943  if (unlikely(pg_mul_s16_overflow(arg1, arg2, &result)))
944  ereport(ERROR,
945  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
946  errmsg("smallint out of range")));
947 
948  PG_RETURN_INT16(result);
949 }
static bool pg_mul_s16_overflow(int16 a, int16 b, int16 *result)
Definition: int.h:83

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, pg_mul_s16_overflow(), PG_RETURN_INT16, and unlikely.

◆ int2ne()

Datum int2ne ( PG_FUNCTION_ARGS  )

Definition at line 462 of file int.c.

463 {
464  int16 arg1 = PG_GETARG_INT16(0);
465  int16 arg2 = PG_GETARG_INT16(1);
466 
467  PG_RETURN_BOOL(arg1 != arg2);
468 }

References PG_GETARG_INT16, and PG_RETURN_BOOL.

◆ int2not()

Datum int2not ( PG_FUNCTION_ARGS  )

Definition at line 1476 of file int.c.

1477 {
1478  int16 arg1 = PG_GETARG_INT16(0);
1479 
1480  PG_RETURN_INT16(~arg1);
1481 }

References PG_GETARG_INT16, and PG_RETURN_INT16.

◆ int2or()

Datum int2or ( PG_FUNCTION_ARGS  )

Definition at line 1458 of file int.c.

1459 {
1460  int16 arg1 = PG_GETARG_INT16(0);
1461  int16 arg2 = PG_GETARG_INT16(1);
1462 
1463  PG_RETURN_INT16(arg1 | arg2);
1464 }

References PG_GETARG_INT16, and PG_RETURN_INT16.

◆ int2out()

Datum int2out ( PG_FUNCTION_ARGS  )

Definition at line 74 of file int.c.

75 {
76  int16 arg1 = PG_GETARG_INT16(0);
77  char *result = (char *) palloc(7); /* sign, 5 digits, '\0' */
78 
79  pg_itoa(arg1, result);
80  PG_RETURN_CSTRING(result);
81 }
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:362
int pg_itoa(int16 i, char *a)
Definition: numutils.c:334

References palloc(), PG_GETARG_INT16, pg_itoa(), and PG_RETURN_CSTRING.

◆ int2pl()

Datum int2pl ( PG_FUNCTION_ARGS  )

Definition at line 909 of file int.c.

910 {
911  int16 arg1 = PG_GETARG_INT16(0);
912  int16 arg2 = PG_GETARG_INT16(1);
913  int16 result;
914 
915  if (unlikely(pg_add_s16_overflow(arg1, arg2, &result)))
916  ereport(ERROR,
917  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
918  errmsg("smallint out of range")));
919  PG_RETURN_INT16(result);
920 }
static bool pg_add_s16_overflow(int16 a, int16 b, int16 *result)
Definition: int.h:47

References ereport, errcode(), errmsg(), ERROR, pg_add_s16_overflow(), PG_GETARG_INT16, PG_RETURN_INT16, and unlikely.

◆ int2recv()

Datum int2recv ( PG_FUNCTION_ARGS  )

Definition at line 87 of file int.c.

88 {
90 
92 }
static char * buf
Definition: pg_test_fsync.c:67
unsigned int pq_getmsgint(StringInfo msg, int b)
Definition: pqformat.c:417
StringInfoData * StringInfo
Definition: stringinfo.h:44

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

◆ int2send()

Datum int2send ( PG_FUNCTION_ARGS  )

Definition at line 98 of file int.c.

99 {
100  int16 arg1 = PG_GETARG_INT16(0);
102 
104  pq_sendint16(&buf, arg1);
106 }
#define PG_RETURN_BYTEA_P(x)
Definition: fmgr.h:371
void pq_begintypsend(StringInfo buf)
Definition: pqformat.c:328
bytea * pq_endtypsend(StringInfo buf)
Definition: pqformat.c:348
static void pq_sendint16(StringInfo buf, uint16 i)
Definition: pqformat.h:137

References buf, PG_GETARG_INT16, PG_RETURN_BYTEA_P, pq_begintypsend(), pq_endtypsend(), and pq_sendint16().

◆ int2shl()

Datum int2shl ( PG_FUNCTION_ARGS  )

Definition at line 1485 of file int.c.

1486 {
1487  int16 arg1 = PG_GETARG_INT16(0);
1488  int32 arg2 = PG_GETARG_INT32(1);
1489 
1490  PG_RETURN_INT16(arg1 << arg2);
1491 }

References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_INT16.

◆ int2shr()

Datum int2shr ( PG_FUNCTION_ARGS  )

Definition at line 1494 of file int.c.

1495 {
1496  int16 arg1 = PG_GETARG_INT16(0);
1497  int32 arg2 = PG_GETARG_INT32(1);
1498 
1499  PG_RETURN_INT16(arg1 >> arg2);
1500 }

References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_INT16.

◆ int2smaller()

Datum int2smaller ( PG_FUNCTION_ARGS  )

Definition at line 1358 of file int.c.

1359 {
1360  int16 arg1 = PG_GETARG_INT16(0);
1361  int16 arg2 = PG_GETARG_INT16(1);
1362 
1363  PG_RETURN_INT16((arg1 < arg2) ? arg1 : arg2);
1364 }

References PG_GETARG_INT16, and PG_RETURN_INT16.

◆ int2um()

Datum int2um ( PG_FUNCTION_ARGS  )

Definition at line 889 of file int.c.

890 {
892 
893  if (unlikely(arg == PG_INT16_MIN))
894  ereport(ERROR,
895  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
896  errmsg("smallint out of range")));
898 }
void * arg

References arg, ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, PG_INT16_MIN, PG_RETURN_INT16, and unlikely.

◆ int2up()

Datum int2up ( PG_FUNCTION_ARGS  )

Definition at line 901 of file int.c.

902 {
904 
906 }

References arg, PG_GETARG_INT16, and PG_RETURN_INT16.

◆ int2vectorin()

Datum int2vectorin ( PG_FUNCTION_ARGS  )

Definition at line 141 of file int.c.

142 {
143  char *intString = PG_GETARG_CSTRING(0);
144  int2vector *result;
145  int n;
146 
148 
149  for (n = 0; n < FUNC_MAX_ARGS; n++)
150  {
151  long l;
152  char *endp;
153 
154  while (*intString && isspace((unsigned char) *intString))
155  intString++;
156  if (*intString == '\0')
157  break;
158 
159  errno = 0;
160  l = strtol(intString, &endp, 10);
161 
162  if (intString == endp)
163  ereport(ERROR,
164  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
165  errmsg("invalid input syntax for type %s: \"%s\"",
166  "smallint", intString)));
167 
168  if (errno == ERANGE || l < SHRT_MIN || l > SHRT_MAX)
169  ereport(ERROR,
170  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
171  errmsg("value \"%s\" is out of range for type %s", intString,
172  "smallint")));
173 
174  if (*endp && *endp != ' ')
175  ereport(ERROR,
176  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
177  errmsg("invalid input syntax for type %s: \"%s\"",
178  "integer", intString)));
179 
180  result->values[n] = l;
181  intString = endp;
182  }
183  while (*intString && isspace((unsigned char) *intString))
184  intString++;
185  if (*intString)
186  ereport(ERROR,
187  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
188  errmsg("int2vector has too many elements")));
189 
190  SET_VARSIZE(result, Int2VectorSize(n));
191  result->ndim = 1;
192  result->dataoffset = 0; /* never any nulls */
193  result->elemtype = INT2OID;
194  result->dim1 = n;
195  result->lbound1 = 0;
196 
197  PG_RETURN_POINTER(result);
198 }
#define FUNC_MAX_ARGS

References int2vector::dataoffset, int2vector::dim1, int2vector::elemtype, ereport, errcode(), errmsg(), ERROR, FUNC_MAX_ARGS, Int2VectorSize, int2vector::lbound1, int2vector::ndim, palloc0(), PG_GETARG_CSTRING, PG_RETURN_POINTER, SET_VARSIZE, and int2vector::values.

◆ int2vectorout()

Datum int2vectorout ( PG_FUNCTION_ARGS  )

Definition at line 204 of file int.c.

205 {
206  int2vector *int2Array = (int2vector *) PG_GETARG_POINTER(0);
207  int num,
208  nnums = int2Array->dim1;
209  char *rp;
210  char *result;
211 
212  /* assumes sign, 5 digits, ' ' */
213  rp = result = (char *) palloc(nnums * 7 + 1);
214  for (num = 0; num < nnums; num++)
215  {
216  if (num != 0)
217  *rp++ = ' ';
218  rp += pg_itoa(int2Array->values[num], rp);
219  }
220  *rp = '\0';
221  PG_RETURN_CSTRING(result);
222 }

References int2vector::dim1, palloc(), PG_GETARG_POINTER, pg_itoa(), PG_RETURN_CSTRING, and int2vector::values.

◆ int2vectorrecv()

Datum int2vectorrecv ( PG_FUNCTION_ARGS  )

Definition at line 228 of file int.c.

229 {
230  LOCAL_FCINFO(locfcinfo, 3);
232  int2vector *result;
233 
234  /*
235  * Normally one would call array_recv() using DirectFunctionCall3, but
236  * that does not work since array_recv wants to cache some data using
237  * fcinfo->flinfo->fn_extra. So we need to pass it our own flinfo
238  * parameter.
239  */
240  InitFunctionCallInfoData(*locfcinfo, fcinfo->flinfo, 3,
241  InvalidOid, NULL, NULL);
242 
243  locfcinfo->args[0].value = PointerGetDatum(buf);
244  locfcinfo->args[0].isnull = false;
245  locfcinfo->args[1].value = ObjectIdGetDatum(INT2OID);
246  locfcinfo->args[1].isnull = false;
247  locfcinfo->args[2].value = Int32GetDatum(-1);
248  locfcinfo->args[2].isnull = false;
249 
250  result = (int2vector *) DatumGetPointer(array_recv(locfcinfo));
251 
252  Assert(!locfcinfo->isnull);
253 
254  /* sanity checks: int2vector must be 1-D, 0-based, no nulls */
255  if (ARR_NDIM(result) != 1 ||
256  ARR_HASNULL(result) ||
257  ARR_ELEMTYPE(result) != INT2OID ||
258  ARR_LBOUND(result)[0] != 0)
259  ereport(ERROR,
260  (errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
261  errmsg("invalid int2vector data")));
262 
263  /* check length for consistency with int2vectorin() */
264  if (ARR_DIMS(result)[0] > FUNC_MAX_ARGS)
265  ereport(ERROR,
266  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
267  errmsg("oidvector has too many elements")));
268 
269  PG_RETURN_POINTER(result);
270 }
#define ARR_NDIM(a)
Definition: array.h:283
#define ARR_ELEMTYPE(a)
Definition: array.h:285
#define ARR_DIMS(a)
Definition: array.h:287
#define ARR_HASNULL(a)
Definition: array.h:284
#define ARR_LBOUND(a)
Definition: array.h:289
Datum array_recv(PG_FUNCTION_ARGS)
Definition: arrayfuncs.c:1271
#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')
#define DatumGetPointer(X)
Definition: postgres.h:593
#define ObjectIdGetDatum(X)
Definition: postgres.h:551
#define PointerGetDatum(X)
Definition: postgres.h:600
#define InvalidOid
Definition: postgres_ext.h:36

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

◆ int2vectorsend()

Datum int2vectorsend ( PG_FUNCTION_ARGS  )

Definition at line 276 of file int.c.

277 {
278  return array_send(fcinfo);
279 }
Datum array_send(PG_FUNCTION_ARGS)
Definition: arrayfuncs.c:1559

References array_send().

◆ int2xor()

Datum int2xor ( PG_FUNCTION_ARGS  )

Definition at line 1467 of file int.c.

1468 {
1469  int16 arg1 = PG_GETARG_INT16(0);
1470  int16 arg2 = PG_GETARG_INT16(1);
1471 
1472  PG_RETURN_INT16(arg1 ^ arg2);
1473 }

References PG_GETARG_INT16, and PG_RETURN_INT16.

◆ int42div()

Datum int42div ( PG_FUNCTION_ARGS  )

Definition at line 1094 of file int.c.

1095 {
1096  int32 arg1 = PG_GETARG_INT32(0);
1097  int16 arg2 = PG_GETARG_INT16(1);
1098  int32 result;
1099 
1100  if (unlikely(arg2 == 0))
1101  {
1102  ereport(ERROR,
1103  (errcode(ERRCODE_DIVISION_BY_ZERO),
1104  errmsg("division by zero")));
1105  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
1106  PG_RETURN_NULL();
1107  }
1108 
1109  /*
1110  * INT_MIN / -1 is problematic, since the result can't be represented on a
1111  * two's-complement machine. Some machines produce INT_MIN, some produce
1112  * zero, some throw an exception. We can dodge the problem by recognizing
1113  * that division by -1 is the same as negation.
1114  */
1115  if (arg2 == -1)
1116  {
1117  if (unlikely(arg1 == PG_INT32_MIN))
1118  ereport(ERROR,
1119  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1120  errmsg("integer out of range")));
1121  result = -arg1;
1122  PG_RETURN_INT32(result);
1123  }
1124 
1125  /* No overflow is possible */
1126 
1127  result = arg1 / arg2;
1128 
1129  PG_RETURN_INT32(result);
1130 }
#define PG_INT32_MIN
Definition: c.h:523

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, PG_GETARG_INT32, PG_INT32_MIN, PG_RETURN_INT32, PG_RETURN_NULL, and unlikely.

◆ int42eq()

Datum int42eq ( PG_FUNCTION_ARGS  )

Definition at line 561 of file int.c.

562 {
563  int32 arg1 = PG_GETARG_INT32(0);
564  int16 arg2 = PG_GETARG_INT16(1);
565 
566  PG_RETURN_BOOL(arg1 == arg2);
567 }

References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.

◆ int42ge()

Datum int42ge ( PG_FUNCTION_ARGS  )

Definition at line 606 of file int.c.

607 {
608  int32 arg1 = PG_GETARG_INT32(0);
609  int16 arg2 = PG_GETARG_INT16(1);
610 
611  PG_RETURN_BOOL(arg1 >= arg2);
612 }

References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.

◆ int42gt()

Datum int42gt ( PG_FUNCTION_ARGS  )

Definition at line 597 of file int.c.

598 {
599  int32 arg1 = PG_GETARG_INT32(0);
600  int16 arg2 = PG_GETARG_INT16(1);
601 
602  PG_RETURN_BOOL(arg1 > arg2);
603 }

References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.

◆ int42le()

Datum int42le ( PG_FUNCTION_ARGS  )

Definition at line 588 of file int.c.

589 {
590  int32 arg1 = PG_GETARG_INT32(0);
591  int16 arg2 = PG_GETARG_INT16(1);
592 
593  PG_RETURN_BOOL(arg1 <= arg2);
594 }

References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.

◆ int42lt()

Datum int42lt ( PG_FUNCTION_ARGS  )

Definition at line 579 of file int.c.

580 {
581  int32 arg1 = PG_GETARG_INT32(0);
582  int16 arg2 = PG_GETARG_INT16(1);
583 
584  PG_RETURN_BOOL(arg1 < arg2);
585 }

References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.

◆ int42mi()

Datum int42mi ( PG_FUNCTION_ARGS  )

Definition at line 1066 of file int.c.

1067 {
1068  int32 arg1 = PG_GETARG_INT32(0);
1069  int16 arg2 = PG_GETARG_INT16(1);
1070  int32 result;
1071 
1072  if (unlikely(pg_sub_s32_overflow(arg1, (int32) arg2, &result)))
1073  ereport(ERROR,
1074  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1075  errmsg("integer out of range")));
1076  PG_RETURN_INT32(result);
1077 }

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, PG_GETARG_INT32, PG_RETURN_INT32, pg_sub_s32_overflow(), and unlikely.

◆ int42mul()

Datum int42mul ( PG_FUNCTION_ARGS  )

Definition at line 1080 of file int.c.

1081 {
1082  int32 arg1 = PG_GETARG_INT32(0);
1083  int16 arg2 = PG_GETARG_INT16(1);
1084  int32 result;
1085 
1086  if (unlikely(pg_mul_s32_overflow(arg1, (int32) arg2, &result)))
1087  ereport(ERROR,
1088  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1089  errmsg("integer out of range")));
1090  PG_RETURN_INT32(result);
1091 }

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, PG_GETARG_INT32, pg_mul_s32_overflow(), PG_RETURN_INT32, and unlikely.

◆ int42ne()

Datum int42ne ( PG_FUNCTION_ARGS  )

Definition at line 570 of file int.c.

571 {
572  int32 arg1 = PG_GETARG_INT32(0);
573  int16 arg2 = PG_GETARG_INT16(1);
574 
575  PG_RETURN_BOOL(arg1 != arg2);
576 }

References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.

◆ int42pl()

Datum int42pl ( PG_FUNCTION_ARGS  )

Definition at line 1052 of file int.c.

1053 {
1054  int32 arg1 = PG_GETARG_INT32(0);
1055  int16 arg2 = PG_GETARG_INT16(1);
1056  int32 result;
1057 
1058  if (unlikely(pg_add_s32_overflow(arg1, (int32) arg2, &result)))
1059  ereport(ERROR,
1060  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1061  errmsg("integer out of range")));
1062  PG_RETURN_INT32(result);
1063 }

References ereport, errcode(), errmsg(), ERROR, pg_add_s32_overflow(), PG_GETARG_INT16, PG_GETARG_INT32, PG_RETURN_INT32, and unlikely.

◆ int4_bool()

Datum int4_bool ( PG_FUNCTION_ARGS  )

Definition at line 365 of file int.c.

366 {
367  if (PG_GETARG_INT32(0) == 0)
368  PG_RETURN_BOOL(false);
369  else
370  PG_RETURN_BOOL(true);
371 }

References PG_GETARG_INT32, and PG_RETURN_BOOL.

◆ int4abs()

Datum int4abs ( PG_FUNCTION_ARGS  )

Definition at line 1194 of file int.c.

1195 {
1196  int32 arg1 = PG_GETARG_INT32(0);
1197  int32 result;
1198 
1199  if (unlikely(arg1 == PG_INT32_MIN))
1200  ereport(ERROR,
1201  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1202  errmsg("integer out of range")));
1203  result = (arg1 < 0) ? -arg1 : arg1;
1204  PG_RETURN_INT32(result);
1205 }

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT32, PG_INT32_MIN, PG_RETURN_INT32, and unlikely.

◆ int4and()

Datum int4and ( PG_FUNCTION_ARGS  )

Definition at line 1396 of file int.c.

1397 {
1398  int32 arg1 = PG_GETARG_INT32(0);
1399  int32 arg2 = PG_GETARG_INT32(1);
1400 
1401  PG_RETURN_INT32(arg1 & arg2);
1402 }

References PG_GETARG_INT32, and PG_RETURN_INT32.

◆ int4div()

Datum int4div ( PG_FUNCTION_ARGS  )

Definition at line 836 of file int.c.

837 {
838  int32 arg1 = PG_GETARG_INT32(0);
839  int32 arg2 = PG_GETARG_INT32(1);
840  int32 result;
841 
842  if (arg2 == 0)
843  {
844  ereport(ERROR,
845  (errcode(ERRCODE_DIVISION_BY_ZERO),
846  errmsg("division by zero")));
847  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
848  PG_RETURN_NULL();
849  }
850 
851  /*
852  * INT_MIN / -1 is problematic, since the result can't be represented on a
853  * two's-complement machine. Some machines produce INT_MIN, some produce
854  * zero, some throw an exception. We can dodge the problem by recognizing
855  * that division by -1 is the same as negation.
856  */
857  if (arg2 == -1)
858  {
859  if (unlikely(arg1 == PG_INT32_MIN))
860  ereport(ERROR,
861  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
862  errmsg("integer out of range")));
863  result = -arg1;
864  PG_RETURN_INT32(result);
865  }
866 
867  /* No overflow is possible */
868 
869  result = arg1 / arg2;
870 
871  PG_RETURN_INT32(result);
872 }

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT32, PG_INT32_MIN, PG_RETURN_INT32, PG_RETURN_NULL, and unlikely.

◆ int4eq()

Datum int4eq ( PG_FUNCTION_ARGS  )

Definition at line 399 of file int.c.

400 {
401  int32 arg1 = PG_GETARG_INT32(0);
402  int32 arg2 = PG_GETARG_INT32(1);
403 
404  PG_RETURN_BOOL(arg1 == arg2);
405 }

References PG_GETARG_INT32, and PG_RETURN_BOOL.

◆ int4gcd()

Datum int4gcd ( PG_FUNCTION_ARGS  )

Definition at line 1297 of file int.c.

1298 {
1299  int32 arg1 = PG_GETARG_INT32(0);
1300  int32 arg2 = PG_GETARG_INT32(1);
1301  int32 result;
1302 
1303  result = int4gcd_internal(arg1, arg2);
1304 
1305  PG_RETURN_INT32(result);
1306 }
static int32 int4gcd_internal(int32 arg1, int32 arg2)
Definition: int.c:1236

References int4gcd_internal(), PG_GETARG_INT32, and PG_RETURN_INT32.

◆ int4gcd_internal()

static int32 int4gcd_internal ( int32  arg1,
int32  arg2 
)
static

Definition at line 1236 of file int.c.

1237 {
1238  int32 swap;
1239  int32 a1,
1240  a2;
1241 
1242  /*
1243  * Put the greater absolute value in arg1.
1244  *
1245  * This would happen automatically in the loop below, but avoids an
1246  * expensive modulo operation, and simplifies the special-case handling
1247  * for INT_MIN below.
1248  *
1249  * We do this in negative space in order to handle INT_MIN.
1250  */
1251  a1 = (arg1 < 0) ? arg1 : -arg1;
1252  a2 = (arg2 < 0) ? arg2 : -arg2;
1253  if (a1 > a2)
1254  {
1255  swap = arg1;
1256  arg1 = arg2;
1257  arg2 = swap;
1258  }
1259 
1260  /* Special care needs to be taken with INT_MIN. See comments above. */
1261  if (arg1 == PG_INT32_MIN)
1262  {
1263  if (arg2 == 0 || arg2 == PG_INT32_MIN)
1264  ereport(ERROR,
1265  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1266  errmsg("integer out of range")));
1267 
1268  /*
1269  * Some machines throw a floating-point exception for INT_MIN % -1,
1270  * which is a bit silly since the correct answer is perfectly
1271  * well-defined, namely zero. Guard against this and just return the
1272  * result, gcd(INT_MIN, -1) = 1.
1273  */
1274  if (arg2 == -1)
1275  return 1;
1276  }
1277 
1278  /* Use the Euclidean algorithm to find the GCD */
1279  while (arg2 != 0)
1280  {
1281  swap = arg2;
1282  arg2 = arg1 % arg2;
1283  arg1 = swap;
1284  }
1285 
1286  /*
1287  * Make sure the result is positive. (We know we don't have INT_MIN
1288  * anymore).
1289  */
1290  if (arg1 < 0)
1291  arg1 = -arg1;
1292 
1293  return arg1;
1294 }
static const FormData_pg_attribute a1
Definition: heap.c:141
static const FormData_pg_attribute a2
Definition: heap.c:155

References a1, a2, ereport, errcode(), errmsg(), ERROR, and PG_INT32_MIN.

Referenced by int4gcd(), and int4lcm().

◆ int4ge()

Datum int4ge ( PG_FUNCTION_ARGS  )

Definition at line 444 of file int.c.

445 {
446  int32 arg1 = PG_GETARG_INT32(0);
447  int32 arg2 = PG_GETARG_INT32(1);
448 
449  PG_RETURN_BOOL(arg1 >= arg2);
450 }

References PG_GETARG_INT32, and PG_RETURN_BOOL.

◆ int4gt()

Datum int4gt ( PG_FUNCTION_ARGS  )

Definition at line 435 of file int.c.

436 {
437  int32 arg1 = PG_GETARG_INT32(0);
438  int32 arg2 = PG_GETARG_INT32(1);
439 
440  PG_RETURN_BOOL(arg1 > arg2);
441 }

References PG_GETARG_INT32, and PG_RETURN_BOOL.

◆ int4in()

Datum int4in ( PG_FUNCTION_ARGS  )

Definition at line 290 of file int.c.

291 {
292  char *num = PG_GETARG_CSTRING(0);
293 
295 }
int32 pg_strtoint32(const char *s)
Definition: numutils.c:175

References PG_GETARG_CSTRING, PG_RETURN_INT32, and pg_strtoint32().

Referenced by inet_client_port(), inet_server_port(), and pg_stat_get_backend_client_port().

◆ int4inc()

Datum int4inc ( PG_FUNCTION_ARGS  )

Definition at line 875 of file int.c.

876 {
878  int32 result;
879 
880  if (unlikely(pg_add_s32_overflow(arg, 1, &result)))
881  ereport(ERROR,
882  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
883  errmsg("integer out of range")));
884 
885  PG_RETURN_INT32(result);
886 }

References arg, ereport, errcode(), errmsg(), ERROR, pg_add_s32_overflow(), PG_GETARG_INT32, PG_RETURN_INT32, and unlikely.

◆ int4larger()

Datum int4larger ( PG_FUNCTION_ARGS  )

Definition at line 1367 of file int.c.

1368 {
1369  int32 arg1 = PG_GETARG_INT32(0);
1370  int32 arg2 = PG_GETARG_INT32(1);
1371 
1372  PG_RETURN_INT32((arg1 > arg2) ? arg1 : arg2);
1373 }

References PG_GETARG_INT32, and PG_RETURN_INT32.

◆ int4lcm()

Datum int4lcm ( PG_FUNCTION_ARGS  )

Definition at line 1312 of file int.c.

1313 {
1314  int32 arg1 = PG_GETARG_INT32(0);
1315  int32 arg2 = PG_GETARG_INT32(1);
1316  int32 gcd;
1317  int32 result;
1318 
1319  /*
1320  * Handle lcm(x, 0) = lcm(0, x) = 0 as a special case. This prevents a
1321  * division-by-zero error below when x is zero, and an overflow error from
1322  * the GCD computation when x = INT_MIN.
1323  */
1324  if (arg1 == 0 || arg2 == 0)
1325  PG_RETURN_INT32(0);
1326 
1327  /* lcm(x, y) = abs(x / gcd(x, y) * y) */
1328  gcd = int4gcd_internal(arg1, arg2);
1329  arg1 = arg1 / gcd;
1330 
1331  if (unlikely(pg_mul_s32_overflow(arg1, arg2, &result)))
1332  ereport(ERROR,
1333  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1334  errmsg("integer out of range")));
1335 
1336  /* If the result is INT_MIN, it cannot be represented. */
1337  if (unlikely(result == PG_INT32_MIN))
1338  ereport(ERROR,
1339  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1340  errmsg("integer out of range")));
1341 
1342  if (result < 0)
1343  result = -result;
1344 
1345  PG_RETURN_INT32(result);
1346 }
static uint32 gcd(uint32 a, uint32 b)

References ereport, errcode(), errmsg(), ERROR, gcd(), int4gcd_internal(), PG_GETARG_INT32, PG_INT32_MIN, pg_mul_s32_overflow(), PG_RETURN_INT32, and unlikely.

◆ int4le()

Datum int4le ( PG_FUNCTION_ARGS  )

Definition at line 426 of file int.c.

427 {
428  int32 arg1 = PG_GETARG_INT32(0);
429  int32 arg2 = PG_GETARG_INT32(1);
430 
431  PG_RETURN_BOOL(arg1 <= arg2);
432 }

References PG_GETARG_INT32, and PG_RETURN_BOOL.

◆ int4lt()

Datum int4lt ( PG_FUNCTION_ARGS  )

Definition at line 417 of file int.c.

418 {
419  int32 arg1 = PG_GETARG_INT32(0);
420  int32 arg2 = PG_GETARG_INT32(1);
421 
422  PG_RETURN_BOOL(arg1 < arg2);
423 }

References PG_GETARG_INT32, and PG_RETURN_BOOL.

◆ int4mi()

Datum int4mi ( PG_FUNCTION_ARGS  )

Definition at line 808 of file int.c.

809 {
810  int32 arg1 = PG_GETARG_INT32(0);
811  int32 arg2 = PG_GETARG_INT32(1);
812  int32 result;
813 
814  if (unlikely(pg_sub_s32_overflow(arg1, arg2, &result)))
815  ereport(ERROR,
816  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
817  errmsg("integer out of range")));
818  PG_RETURN_INT32(result);
819 }

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT32, PG_RETURN_INT32, pg_sub_s32_overflow(), and unlikely.

◆ int4mod()

Datum int4mod ( PG_FUNCTION_ARGS  )

Definition at line 1133 of file int.c.

1134 {
1135  int32 arg1 = PG_GETARG_INT32(0);
1136  int32 arg2 = PG_GETARG_INT32(1);
1137 
1138  if (unlikely(arg2 == 0))
1139  {
1140  ereport(ERROR,
1141  (errcode(ERRCODE_DIVISION_BY_ZERO),
1142  errmsg("division by zero")));
1143  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
1144  PG_RETURN_NULL();
1145  }
1146 
1147  /*
1148  * Some machines throw a floating-point exception for INT_MIN % -1, which
1149  * is a bit silly since the correct answer is perfectly well-defined,
1150  * namely zero.
1151  */
1152  if (arg2 == -1)
1153  PG_RETURN_INT32(0);
1154 
1155  /* No overflow is possible */
1156 
1157  PG_RETURN_INT32(arg1 % arg2);
1158 }

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT32, PG_RETURN_INT32, PG_RETURN_NULL, and unlikely.

◆ int4mul()

Datum int4mul ( PG_FUNCTION_ARGS  )

Definition at line 822 of file int.c.

823 {
824  int32 arg1 = PG_GETARG_INT32(0);
825  int32 arg2 = PG_GETARG_INT32(1);
826  int32 result;
827 
828  if (unlikely(pg_mul_s32_overflow(arg1, arg2, &result)))
829  ereport(ERROR,
830  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
831  errmsg("integer out of range")));
832  PG_RETURN_INT32(result);
833 }

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT32, pg_mul_s32_overflow(), PG_RETURN_INT32, and unlikely.

◆ int4ne()

Datum int4ne ( PG_FUNCTION_ARGS  )

Definition at line 408 of file int.c.

409 {
410  int32 arg1 = PG_GETARG_INT32(0);
411  int32 arg2 = PG_GETARG_INT32(1);
412 
413  PG_RETURN_BOOL(arg1 != arg2);
414 }

References PG_GETARG_INT32, and PG_RETURN_BOOL.

◆ int4not()

Datum int4not ( PG_FUNCTION_ARGS  )

Definition at line 1441 of file int.c.

1442 {
1443  int32 arg1 = PG_GETARG_INT32(0);
1444 
1445  PG_RETURN_INT32(~arg1);
1446 }

References PG_GETARG_INT32, and PG_RETURN_INT32.

◆ int4or()

Datum int4or ( PG_FUNCTION_ARGS  )

Definition at line 1405 of file int.c.

1406 {
1407  int32 arg1 = PG_GETARG_INT32(0);
1408  int32 arg2 = PG_GETARG_INT32(1);
1409 
1410  PG_RETURN_INT32(arg1 | arg2);
1411 }

References PG_GETARG_INT32, and PG_RETURN_INT32.

◆ int4out()

Datum int4out ( PG_FUNCTION_ARGS  )

Definition at line 301 of file int.c.

302 {
303  int32 arg1 = PG_GETARG_INT32(0);
304  char *result = (char *) palloc(12); /* sign, 10 digits, '\0' */
305 
306  pg_ltoa(arg1, result);
307  PG_RETURN_CSTRING(result);
308 }
int pg_ltoa(int32 value, char *a)
Definition: numutils.c:412

References palloc(), PG_GETARG_INT32, pg_ltoa(), and PG_RETURN_CSTRING.

Referenced by int4_to_char(), and jsonb_subscript_check_subscripts().

◆ int4pl()

Datum int4pl ( PG_FUNCTION_ARGS  )

Definition at line 794 of file int.c.

795 {
796  int32 arg1 = PG_GETARG_INT32(0);
797  int32 arg2 = PG_GETARG_INT32(1);
798  int32 result;
799 
800  if (unlikely(pg_add_s32_overflow(arg1, arg2, &result)))
801  ereport(ERROR,
802  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
803  errmsg("integer out of range")));
804  PG_RETURN_INT32(result);
805 }

References ereport, errcode(), errmsg(), ERROR, pg_add_s32_overflow(), PG_GETARG_INT32, PG_RETURN_INT32, and unlikely.

Referenced by int4range_canonical().

◆ int4recv()

Datum int4recv ( PG_FUNCTION_ARGS  )

Definition at line 314 of file int.c.

315 {
317 
319 }

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

◆ int4send()

Datum int4send ( PG_FUNCTION_ARGS  )

Definition at line 325 of file int.c.

326 {
327  int32 arg1 = PG_GETARG_INT32(0);
329 
331  pq_sendint32(&buf, arg1);
333 }
static void pq_sendint32(StringInfo buf, uint32 i)
Definition: pqformat.h:145

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

◆ int4shl()

Datum int4shl ( PG_FUNCTION_ARGS  )

Definition at line 1423 of file int.c.

1424 {
1425  int32 arg1 = PG_GETARG_INT32(0);
1426  int32 arg2 = PG_GETARG_INT32(1);
1427 
1428  PG_RETURN_INT32(arg1 << arg2);
1429 }

References PG_GETARG_INT32, and PG_RETURN_INT32.

◆ int4shr()

Datum int4shr ( PG_FUNCTION_ARGS  )

Definition at line 1432 of file int.c.

1433 {
1434  int32 arg1 = PG_GETARG_INT32(0);
1435  int32 arg2 = PG_GETARG_INT32(1);
1436 
1437  PG_RETURN_INT32(arg1 >> arg2);
1438 }

References PG_GETARG_INT32, and PG_RETURN_INT32.

◆ int4smaller()

Datum int4smaller ( PG_FUNCTION_ARGS  )

Definition at line 1376 of file int.c.

1377 {
1378  int32 arg1 = PG_GETARG_INT32(0);
1379  int32 arg2 = PG_GETARG_INT32(1);
1380 
1381  PG_RETURN_INT32((arg1 < arg2) ? arg1 : arg2);
1382 }

References PG_GETARG_INT32, and PG_RETURN_INT32.

◆ int4um()

Datum int4um ( PG_FUNCTION_ARGS  )

Definition at line 774 of file int.c.

775 {
777 
778  if (unlikely(arg == PG_INT32_MIN))
779  ereport(ERROR,
780  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
781  errmsg("integer out of range")));
783 }

References arg, ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT32, PG_INT32_MIN, PG_RETURN_INT32, and unlikely.

◆ int4up()

Datum int4up ( PG_FUNCTION_ARGS  )

Definition at line 786 of file int.c.

787 {
789 
791 }

References arg, PG_GETARG_INT32, and PG_RETURN_INT32.

◆ int4xor()

Datum int4xor ( PG_FUNCTION_ARGS  )

Definition at line 1414 of file int.c.

1415 {
1416  int32 arg1 = PG_GETARG_INT32(0);
1417  int32 arg2 = PG_GETARG_INT32(1);
1418 
1419  PG_RETURN_INT32(arg1 ^ arg2);
1420 }

References PG_GETARG_INT32, and PG_RETURN_INT32.