PostgreSQL Source Code  git master
regress.c File Reference
#include "postgres.h"
#include <float.h>
#include <math.h>
#include <signal.h>
#include "access/htup_details.h"
#include "access/transam.h"
#include "access/tuptoaster.h"
#include "access/xact.h"
#include "catalog/pg_type.h"
#include "commands/sequence.h"
#include "commands/trigger.h"
#include "executor/executor.h"
#include "executor/spi.h"
#include "miscadmin.h"
#include "port/atomics.h"
#include "utils/builtins.h"
#include "utils/geo_decls.h"
#include "utils/rel.h"
#include "utils/typcache.h"
#include "utils/memutils.h"
Include dependency graph for regress.c:

Go to the source code of this file.

Data Structures

struct  WIDGET
 

Macros

#define P_MAXDIG   12
 
#define LDELIM   '('
 
#define RDELIM   ')'
 
#define DELIM   ','
 
#define NARGS   3
 
#define TTDUMMY_INFINITY   999999
 

Functions

static void regress_lseg_construct (LSEG *lseg, Point *pt1, Point *pt2)
 
 PG_FUNCTION_INFO_V1 (interpt_pp)
 
Datum interpt_pp (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (overpaid)
 
Datum overpaid (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (widget_in)
 
 PG_FUNCTION_INFO_V1 (widget_out)
 
Datum widget_in (PG_FUNCTION_ARGS)
 
Datum widget_out (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (pt_in_widget)
 
Datum pt_in_widget (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (reverse_name)
 
Datum reverse_name (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (trigger_return_old)
 
Datum trigger_return_old (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (ttdummy)
 
Datum ttdummy (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (set_ttdummy)
 
Datum set_ttdummy (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (int44in)
 
Datum int44in (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (int44out)
 
Datum int44out (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (make_tuple_indirect)
 
Datum make_tuple_indirect (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (regress_putenv)
 
Datum regress_putenv (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (wait_pid)
 
Datum wait_pid (PG_FUNCTION_ARGS)
 
static void test_atomic_flag (void)
 
static void test_atomic_uint32 (void)
 
static void test_atomic_uint64 (void)
 
 PG_FUNCTION_INFO_V1 (test_atomic_ops)
 
Datum test_atomic_ops (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (test_fdw_handler)
 
Datum test_fdw_handler (PG_FUNCTION_ARGS)
 

Variables

 PG_MODULE_MAGIC
 
static SPIPlanPtr splan = NULL
 
static bool ttoff = false
 

Macro Definition Documentation

◆ DELIM

#define DELIM   ','

Definition at line 44 of file regress.c.

Referenced by widget_in().

◆ LDELIM

#define LDELIM   '('

Definition at line 42 of file regress.c.

Referenced by widget_in().

◆ NARGS

#define NARGS   3

Definition at line 133 of file regress.c.

Referenced by widget_in().

◆ P_MAXDIG

#define P_MAXDIG   12

Definition at line 41 of file regress.c.

◆ RDELIM

#define RDELIM   ')'

Definition at line 43 of file regress.c.

Referenced by widget_in().

◆ TTDUMMY_INFINITY

#define TTDUMMY_INFINITY   999999

Definition at line 222 of file regress.c.

Referenced by ttdummy().

Function Documentation

◆ int44in()

Datum int44in ( PG_FUNCTION_ARGS  )

Definition at line 457 of file regress.c.

References i, int44out(), palloc(), PG_FUNCTION_INFO_V1(), PG_GETARG_CSTRING, and PG_RETURN_POINTER.

Referenced by set_ttdummy().

458 {
459  char *input_string = PG_GETARG_CSTRING(0);
460  int32 *result = (int32 *) palloc(4 * sizeof(int32));
461  int i;
462 
463  i = sscanf(input_string,
464  "%d, %d, %d, %d",
465  &result[0],
466  &result[1],
467  &result[2],
468  &result[3]);
469  while (i < 4)
470  result[i++] = 0;
471 
472  PG_RETURN_POINTER(result);
473 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:326
signed int int32
Definition: c.h:313
void * palloc(Size size)
Definition: mcxt.c:924
int i
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:247

◆ int44out()

Datum int44out ( PG_FUNCTION_ARGS  )

Definition at line 481 of file regress.c.

References make_tuple_indirect(), palloc(), PG_FUNCTION_INFO_V1(), PG_GETARG_POINTER, PG_RETURN_CSTRING, and snprintf().

Referenced by int44in().

482 {
483  int32 *an_array = (int32 *) PG_GETARG_POINTER(0);
484  char *result = (char *) palloc(16 * 4);
485 
486  snprintf(result, 16 * 4, "%d,%d,%d,%d",
487  an_array[0],
488  an_array[1],
489  an_array[2],
490  an_array[3]);
491 
492  PG_RETURN_CSTRING(result);
493 }
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:246
signed int int32
Definition: c.h:313
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:327
void * palloc(Size size)
Definition: mcxt.c:924

◆ interpt_pp()

Datum interpt_pp ( PG_FUNCTION_ARGS  )

Definition at line 55 of file regress.c.

References DatumGetBool, DirectFunctionCall2, i, lseg_interpt(), lseg_intersect(), LsegPGetDatum, PATH::npts, PATH::p, PG_GETARG_PATH_P, PG_RETURN_DATUM, PG_RETURN_NULL, and regress_lseg_construct().

56 {
57  PATH *p1 = PG_GETARG_PATH_P(0);
58  PATH *p2 = PG_GETARG_PATH_P(1);
59  int i,
60  j;
61  LSEG seg1,
62  seg2;
63  bool found; /* We've found the intersection */
64 
65  found = false; /* Haven't found it yet */
66 
67  for (i = 0; i < p1->npts - 1 && !found; i++)
68  {
69  regress_lseg_construct(&seg1, &p1->p[i], &p1->p[i + 1]);
70  for (j = 0; j < p2->npts - 1 && !found; j++)
71  {
72  regress_lseg_construct(&seg2, &p2->p[j], &p2->p[j + 1]);
74  LsegPGetDatum(&seg1),
75  LsegPGetDatum(&seg2))))
76  found = true;
77  }
78  }
79 
80  if (!found)
82 
83  /*
84  * Note: DirectFunctionCall2 will kick out an error if lseg_interpt()
85  * returns NULL, but that should be impossible since we know the two
86  * segments intersect.
87  */
89  LsegPGetDatum(&seg1),
90  LsegPGetDatum(&seg2)));
91 }
Definition: geo_decls.h:68
Datum lseg_interpt(PG_FUNCTION_ARGS)
Definition: geo_ops.c:2309
#define LsegPGetDatum(X)
Definition: geo_decls.h:143
Point p[FLEXIBLE_ARRAY_MEMBER]
Definition: geo_decls.h:83
int32 npts
Definition: geo_decls.h:80
#define DatumGetBool(X)
Definition: postgres.h:376
#define PG_GETARG_PATH_P(n)
Definition: geo_decls.h:150
static void regress_lseg_construct(LSEG *lseg, Point *pt1, Point *pt2)
Definition: regress.c:96
Datum lseg_intersect(PG_FUNCTION_ARGS)
Definition: geo_ops.c:2050
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:318
Definition: geo_decls.h:77
int i
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:592
#define PG_RETURN_NULL()
Definition: fmgr.h:310

◆ make_tuple_indirect()

Datum make_tuple_indirect ( PG_FUNCTION_ARGS  )

Definition at line 497 of file regress.c.

References attlen, DatumGetPointer, heap_deform_tuple(), heap_form_tuple(), heap_tuple_fetch_attr(), HeapTupleHeaderGetDatumLength, HeapTupleHeaderGetTypeId, HeapTupleHeaderGetTypMod, i, INDIRECT_POINTER_SIZE, InvalidOid, ItemPointerSetInvalid, lookup_rowtype_tupdesc(), MemoryContextSwitchTo(), tupleDesc::natts, palloc(), palloc0(), pfree(), PG_FUNCTION_INFO_V1(), PG_GETARG_HEAPTUPLEHEADER, PG_RETURN_POINTER, varatt_indirect::pointer, PointerGetDatum, regress_putenv(), ReleaseTupleDesc, SET_VARTAG_EXTERNAL, HeapTupleData::t_data, HeapTupleData::t_len, HeapTupleData::t_self, HeapTupleData::t_tableOid, TopTransactionContext, TupleDescAttr, values, VARATT_IS_EXTERNAL_INDIRECT, VARATT_IS_EXTERNAL_ONDISK, VARDATA_EXTERNAL, VARSIZE_ANY, and VARTAG_INDIRECT.

Referenced by int44out().

498 {
500  HeapTupleData tuple;
501  int ncolumns;
502  Datum *values;
503  bool *nulls;
504 
505  Oid tupType;
506  int32 tupTypmod;
507  TupleDesc tupdesc;
508 
509  HeapTuple newtup;
510 
511  int i;
512 
513  MemoryContext old_context;
514 
515  /* Extract type info from the tuple itself */
516  tupType = HeapTupleHeaderGetTypeId(rec);
517  tupTypmod = HeapTupleHeaderGetTypMod(rec);
518  tupdesc = lookup_rowtype_tupdesc(tupType, tupTypmod);
519  ncolumns = tupdesc->natts;
520 
521  /* Build a temporary HeapTuple control structure */
523  ItemPointerSetInvalid(&(tuple.t_self));
524  tuple.t_tableOid = InvalidOid;
525  tuple.t_data = rec;
526 
527  values = (Datum *) palloc(ncolumns * sizeof(Datum));
528  nulls = (bool *) palloc(ncolumns * sizeof(bool));
529 
530  heap_deform_tuple(&tuple, tupdesc, values, nulls);
531 
533 
534  for (i = 0; i < ncolumns; i++)
535  {
536  struct varlena *attr;
537  struct varlena *new_attr;
538  struct varatt_indirect redirect_pointer;
539 
540  /* only work on existing, not-null varlenas */
541  if (TupleDescAttr(tupdesc, i)->attisdropped ||
542  nulls[i] ||
543  TupleDescAttr(tupdesc, i)->attlen != -1)
544  continue;
545 
546  attr = (struct varlena *) DatumGetPointer(values[i]);
547 
548  /* don't recursively indirect */
549  if (VARATT_IS_EXTERNAL_INDIRECT(attr))
550  continue;
551 
552  /* copy datum, so it still lives later */
553  if (VARATT_IS_EXTERNAL_ONDISK(attr))
554  attr = heap_tuple_fetch_attr(attr);
555  else
556  {
557  struct varlena *oldattr = attr;
558 
559  attr = palloc0(VARSIZE_ANY(oldattr));
560  memcpy(attr, oldattr, VARSIZE_ANY(oldattr));
561  }
562 
563  /* build indirection Datum */
564  new_attr = (struct varlena *) palloc0(INDIRECT_POINTER_SIZE);
565  redirect_pointer.pointer = attr;
567  memcpy(VARDATA_EXTERNAL(new_attr), &redirect_pointer,
568  sizeof(redirect_pointer));
569 
570  values[i] = PointerGetDatum(new_attr);
571  }
572 
573  newtup = heap_form_tuple(tupdesc, values, nulls);
574  pfree(values);
575  pfree(nulls);
576  ReleaseTupleDesc(tupdesc);
577 
578  MemoryContextSwitchTo(old_context);
579 
580  /*
581  * We intentionally don't use PG_RETURN_HEAPTUPLEHEADER here, because that
582  * would cause the indirect toast pointers to be flattened out of the
583  * tuple immediately, rendering subsequent testing irrelevant. So just
584  * return the HeapTupleHeader pointer as-is. This violates the general
585  * rule that composite Datums shouldn't contain toast pointers, but so
586  * long as the regression test scripts don't insert the result of this
587  * function into a container type (record, array, etc) it should be OK.
588  */
589  PG_RETURN_POINTER(newtup->t_data);
590 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:326
#define VARATT_IS_EXTERNAL_ONDISK(PTR)
Definition: postgres.h:314
MemoryContext TopTransactionContext
Definition: mcxt.c:49
TupleDesc lookup_rowtype_tupdesc(Oid type_id, int32 typmod)
Definition: typcache.c:1641
#define PointerGetDatum(X)
Definition: postgres.h:539
struct varlena * heap_tuple_fetch_attr(struct varlena *attr)
Definition: tuptoaster.c:101
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:93
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:1074
#define PG_GETARG_HEAPTUPLEHEADER(n)
Definition: fmgr.h:281
unsigned int Oid
Definition: postgres_ext.h:31
#define VARDATA_EXTERNAL(PTR)
Definition: postgres.h:310
int natts
Definition: tupdesc.h:82
signed int int32
Definition: c.h:313
HeapTupleHeader t_data
Definition: htup.h:68
#define HeapTupleHeaderGetTypMod(tup)
Definition: htup_details.h:472
void pfree(void *pointer)
Definition: mcxt.c:1031
#define VARATT_IS_EXTERNAL_INDIRECT(PTR)
Definition: postgres.h:316
ItemPointerData t_self
Definition: htup.h:65
uint32 t_len
Definition: htup.h:64
#define SET_VARTAG_EXTERNAL(PTR, tag)
Definition: postgres.h:331
Oid t_tableOid
Definition: htup.h:66
int16 attlen
Definition: pg_attribute.h:64
#define INDIRECT_POINTER_SIZE
Definition: tuptoaster.h:102
void * palloc0(Size size)
Definition: mcxt.c:955
uintptr_t Datum
Definition: postgres.h:365
#define HeapTupleHeaderGetTypeId(tup)
Definition: htup_details.h:462
#define VARSIZE_ANY(PTR)
Definition: postgres.h:333
#define InvalidOid
Definition: postgres_ext.h:36
#define DatumGetPointer(X)
Definition: postgres.h:532
void heap_deform_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *values, bool *isnull)
Definition: heaptuple.c:1315
static Datum values[MAXATTR]
Definition: bootstrap.c:164
#define ItemPointerSetInvalid(pointer)
Definition: itemptr.h:150
void * palloc(Size size)
Definition: mcxt.c:924
int i
Definition: c.h:516
#define ReleaseTupleDesc(tupdesc)
Definition: tupdesc.h:124
#define HeapTupleHeaderGetDatumLength(tup)
Definition: htup_details.h:456

◆ overpaid()

Datum overpaid ( PG_FUNCTION_ARGS  )

Definition at line 107 of file regress.c.

References DatumGetInt32, GetAttributeByName(), PG_GETARG_HEAPTUPLEHEADER, PG_RETURN_BOOL, and PG_RETURN_NULL.

Referenced by regress_lseg_construct().

108 {
110  bool isnull;
111  int32 salary;
112 
113  salary = DatumGetInt32(GetAttributeByName(tuple, "salary", &isnull));
114  if (isnull)
115  PG_RETURN_NULL();
116  PG_RETURN_BOOL(salary > 699);
117 }
#define DatumGetInt32(X)
Definition: postgres.h:455
Datum GetAttributeByName(HeapTupleHeader tuple, const char *attname, bool *isNull)
Definition: execUtils.c:925
#define PG_GETARG_HEAPTUPLEHEADER(n)
Definition: fmgr.h:281
signed int int32
Definition: c.h:313
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_RETURN_NULL()
Definition: fmgr.h:310

◆ PG_FUNCTION_INFO_V1() [1/16]

◆ PG_FUNCTION_INFO_V1() [2/16]

PG_FUNCTION_INFO_V1 ( overpaid  )

◆ PG_FUNCTION_INFO_V1() [3/16]

PG_FUNCTION_INFO_V1 ( widget_in  )

◆ PG_FUNCTION_INFO_V1() [4/16]

PG_FUNCTION_INFO_V1 ( widget_out  )

◆ PG_FUNCTION_INFO_V1() [5/16]

PG_FUNCTION_INFO_V1 ( pt_in_widget  )

◆ PG_FUNCTION_INFO_V1() [6/16]

PG_FUNCTION_INFO_V1 ( reverse_name  )

◆ PG_FUNCTION_INFO_V1() [7/16]

PG_FUNCTION_INFO_V1 ( trigger_return_old  )

◆ PG_FUNCTION_INFO_V1() [8/16]

PG_FUNCTION_INFO_V1 ( ttdummy  )

◆ PG_FUNCTION_INFO_V1() [9/16]

PG_FUNCTION_INFO_V1 ( set_ttdummy  )

◆ PG_FUNCTION_INFO_V1() [10/16]

PG_FUNCTION_INFO_V1 ( int44in  )

◆ PG_FUNCTION_INFO_V1() [11/16]

PG_FUNCTION_INFO_V1 ( int44out  )

◆ PG_FUNCTION_INFO_V1() [12/16]

PG_FUNCTION_INFO_V1 ( make_tuple_indirect  )

◆ PG_FUNCTION_INFO_V1() [13/16]

PG_FUNCTION_INFO_V1 ( regress_putenv  )

◆ PG_FUNCTION_INFO_V1() [14/16]

PG_FUNCTION_INFO_V1 ( wait_pid  )

◆ PG_FUNCTION_INFO_V1() [15/16]

PG_FUNCTION_INFO_V1 ( test_atomic_ops  )

◆ PG_FUNCTION_INFO_V1() [16/16]

PG_FUNCTION_INFO_V1 ( test_fdw_handler  )

◆ pt_in_widget()

Datum pt_in_widget ( PG_FUNCTION_ARGS  )

Definition at line 177 of file regress.c.

References WIDGET::center, PG_FUNCTION_INFO_V1(), PG_GETARG_POINT_P, PG_GETARG_POINTER, PG_RETURN_BOOL, point_dt(), WIDGET::radius, and reverse_name().

Referenced by widget_out().

178 {
179  Point *point = PG_GETARG_POINT_P(0);
180  WIDGET *widget = (WIDGET *) PG_GETARG_POINTER(1);
181 
182  PG_RETURN_BOOL(point_dt(point, &widget->center) < widget->radius);
183 }
double radius
Definition: regress.c:127
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:246
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:139
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
double point_dt(Point *pt1, Point *pt2)
Definition: geo_ops.c:1905
Point center
Definition: regress.c:126

◆ regress_lseg_construct()

static void regress_lseg_construct ( LSEG lseg,
Point pt1,
Point pt2 
)
static

Definition at line 96 of file regress.c.

References overpaid(), LSEG::p, PG_FUNCTION_INFO_V1(), Point::x, and Point::y.

Referenced by interpt_pp().

97 {
98  lseg->p[0].x = pt1->x;
99  lseg->p[0].y = pt1->y;
100  lseg->p[1].x = pt2->x;
101  lseg->p[1].y = pt2->y;
102 }
double y
Definition: geo_decls.h:60
double x
Definition: geo_decls.h:60
Point p[2]
Definition: geo_decls.h:70

◆ regress_putenv()

Datum regress_putenv ( PG_FUNCTION_ARGS  )

Definition at line 595 of file regress.c.

References elog, ERROR, MemoryContextSwitchTo(), PG_FUNCTION_INFO_V1(), PG_GETARG_POINTER, PG_RETURN_VOID, putenv, superuser(), text_to_cstring(), TopMemoryContext, and wait_pid().

Referenced by make_tuple_indirect().

596 {
597  MemoryContext oldcontext;
598  char *envbuf;
599 
600  if (!superuser())
601  elog(ERROR, "must be superuser to change environment variables");
602 
604  envbuf = text_to_cstring((text *) PG_GETARG_POINTER(0));
605  MemoryContextSwitchTo(oldcontext);
606 
607  if (putenv(envbuf) != 0)
608  elog(ERROR, "could not set environment variable: %m");
609 
610  PG_RETURN_VOID();
611 }
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
bool superuser(void)
Definition: superuser.c:47
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:246
#define ERROR
Definition: elog.h:43
MemoryContext TopMemoryContext
Definition: mcxt.c:44
#define PG_RETURN_VOID()
Definition: fmgr.h:314
#define putenv(x)
Definition: win32_port.h:487
char * text_to_cstring(const text *t)
Definition: varlena.c:182
Definition: c.h:516
#define elog
Definition: elog.h:219

◆ reverse_name()

Datum reverse_name ( PG_FUNCTION_ARGS  )

Definition at line 188 of file regress.c.

References i, NAMEDATALEN, palloc0(), PG_FUNCTION_INFO_V1(), PG_GETARG_CSTRING, PG_RETURN_CSTRING, and trigger_return_old().

Referenced by pt_in_widget().

189 {
190  char *string = PG_GETARG_CSTRING(0);
191  int i;
192  int len;
193  char *new_string;
194 
195  new_string = palloc0(NAMEDATALEN);
196  for (i = 0; i < NAMEDATALEN && string[i]; ++i)
197  ;
198  if (i == NAMEDATALEN || !string[i])
199  --i;
200  len = i;
201  for (; i >= 0; --i)
202  new_string[len - i] = string[i];
203  PG_RETURN_CSTRING(new_string);
204 }
#define NAMEDATALEN
void * palloc0(Size size)
Definition: mcxt.c:955
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:327
int i
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:247

◆ set_ttdummy()

Datum set_ttdummy ( PG_FUNCTION_ARGS  )

Definition at line 419 of file regress.c.

References int44in(), PG_FUNCTION_INFO_V1(), PG_GETARG_INT32, PG_RETURN_INT32, and ttoff.

Referenced by ttdummy().

420 {
421  int32 on = PG_GETARG_INT32(0);
422 
423  if (ttoff) /* OFF currently */
424  {
425  if (on == 0)
426  PG_RETURN_INT32(0);
427 
428  /* turn ON */
429  ttoff = false;
430  PG_RETURN_INT32(0);
431  }
432 
433  /* ON currently */
434  if (on != 0)
435  PG_RETURN_INT32(1);
436 
437  /* turn OFF */
438  ttoff = true;
439 
440  PG_RETURN_INT32(1);
441 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
#define PG_RETURN_INT32(x)
Definition: fmgr.h:319
signed int int32
Definition: c.h:313
static bool ttoff
Definition: regress.c:225

◆ test_atomic_flag()

static void test_atomic_flag ( void  )
static

Definition at line 637 of file regress.c.

References elog, ERROR, flag(), pg_atomic_clear_flag(), pg_atomic_init_flag(), pg_atomic_test_set_flag(), and pg_atomic_unlocked_test_flag().

Referenced by test_atomic_ops().

638 {
640 
641  pg_atomic_init_flag(&flag);
642 
643  if (!pg_atomic_unlocked_test_flag(&flag))
644  elog(ERROR, "flag: unexpectedly set");
645 
646  if (!pg_atomic_test_set_flag(&flag))
647  elog(ERROR, "flag: couldn't set");
648 
649  if (pg_atomic_unlocked_test_flag(&flag))
650  elog(ERROR, "flag: unexpectedly unset");
651 
652  if (pg_atomic_test_set_flag(&flag))
653  elog(ERROR, "flag: set spuriously #2");
654 
655  pg_atomic_clear_flag(&flag);
656 
657  if (!pg_atomic_unlocked_test_flag(&flag))
658  elog(ERROR, "flag: unexpectedly set #2");
659 
660  if (!pg_atomic_test_set_flag(&flag))
661  elog(ERROR, "flag: couldn't set");
662 
663  pg_atomic_clear_flag(&flag);
664 }
static void pg_atomic_clear_flag(volatile pg_atomic_flag *ptr)
Definition: atomics.h:212
#define ERROR
Definition: elog.h:43
static bool pg_atomic_test_set_flag(volatile pg_atomic_flag *ptr)
Definition: atomics.h:188
char * flag(int b)
Definition: test-ctype.c:33
static bool pg_atomic_unlocked_test_flag(volatile pg_atomic_flag *ptr)
Definition: atomics.h:201
#define elog
Definition: elog.h:219
static void pg_atomic_init_flag(volatile pg_atomic_flag *ptr)
Definition: atomics.h:175

◆ test_atomic_ops()

Datum test_atomic_ops ( PG_FUNCTION_ARGS  )

Definition at line 845 of file regress.c.

References PG_FUNCTION_INFO_V1(), PG_RETURN_BOOL, test_atomic_flag(), test_atomic_uint32(), test_atomic_uint64(), and test_fdw_handler().

Referenced by test_atomic_uint64().

846 {
848 
850 
852 
853  PG_RETURN_BOOL(true);
854 }
static void test_atomic_uint32(void)
Definition: regress.c:667
static void test_atomic_flag(void)
Definition: regress.c:637
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
static void test_atomic_uint64(void)
Definition: regress.c:767

◆ test_atomic_uint32()

static void test_atomic_uint32 ( void  )
static

Definition at line 667 of file regress.c.

References elog, ERROR, i, pg_atomic_add_fetch_u32(), pg_atomic_compare_exchange_u32(), pg_atomic_exchange_u32(), pg_atomic_fetch_add_u32(), pg_atomic_fetch_and_u32(), pg_atomic_fetch_or_u32(), pg_atomic_fetch_sub_u32(), pg_atomic_init_u32(), pg_atomic_read_u32(), pg_atomic_sub_fetch_u32(), and pg_atomic_write_u32().

Referenced by test_atomic_ops().

668 {
669  pg_atomic_uint32 var;
670  uint32 expected;
671  int i;
672 
673  pg_atomic_init_u32(&var, 0);
674 
675  if (pg_atomic_read_u32(&var) != 0)
676  elog(ERROR, "atomic_read_u32() #1 wrong");
677 
678  pg_atomic_write_u32(&var, 3);
679 
680  if (pg_atomic_read_u32(&var) != 3)
681  elog(ERROR, "atomic_read_u32() #2 wrong");
682 
683  if (pg_atomic_fetch_add_u32(&var, 1) != 3)
684  elog(ERROR, "atomic_fetch_add_u32() #1 wrong");
685 
686  if (pg_atomic_fetch_sub_u32(&var, 1) != 4)
687  elog(ERROR, "atomic_fetch_sub_u32() #1 wrong");
688 
689  if (pg_atomic_sub_fetch_u32(&var, 3) != 0)
690  elog(ERROR, "atomic_sub_fetch_u32() #1 wrong");
691 
692  if (pg_atomic_add_fetch_u32(&var, 10) != 10)
693  elog(ERROR, "atomic_add_fetch_u32() #1 wrong");
694 
695  if (pg_atomic_exchange_u32(&var, 5) != 10)
696  elog(ERROR, "pg_atomic_exchange_u32() #1 wrong");
697 
698  if (pg_atomic_exchange_u32(&var, 0) != 5)
699  elog(ERROR, "pg_atomic_exchange_u32() #0 wrong");
700 
701  /* test around numerical limits */
702  if (pg_atomic_fetch_add_u32(&var, INT_MAX) != 0)
703  elog(ERROR, "pg_atomic_fetch_add_u32() #2 wrong");
704 
705  if (pg_atomic_fetch_add_u32(&var, INT_MAX) != INT_MAX)
706  elog(ERROR, "pg_atomic_add_fetch_u32() #3 wrong");
707 
708  pg_atomic_fetch_add_u32(&var, 1); /* top up to UINT_MAX */
709 
710  if (pg_atomic_read_u32(&var) != UINT_MAX)
711  elog(ERROR, "atomic_read_u32() #2 wrong");
712 
713  if (pg_atomic_fetch_sub_u32(&var, INT_MAX) != UINT_MAX)
714  elog(ERROR, "pg_atomic_fetch_sub_u32() #2 wrong");
715 
716  if (pg_atomic_read_u32(&var) != (uint32) INT_MAX + 1)
717  elog(ERROR, "atomic_read_u32() #3 wrong: %u", pg_atomic_read_u32(&var));
718 
719  expected = pg_atomic_sub_fetch_u32(&var, INT_MAX);
720  if (expected != 1)
721  elog(ERROR, "pg_atomic_sub_fetch_u32() #3 wrong: %u", expected);
722 
723  pg_atomic_sub_fetch_u32(&var, 1);
724 
725  /* fail exchange because of old expected */
726  expected = 10;
727  if (pg_atomic_compare_exchange_u32(&var, &expected, 1))
728  elog(ERROR, "atomic_compare_exchange_u32() changed value spuriously");
729 
730  /* CAS is allowed to fail due to interrupts, try a couple of times */
731  for (i = 0; i < 1000; i++)
732  {
733  expected = 0;
734  if (!pg_atomic_compare_exchange_u32(&var, &expected, 1))
735  break;
736  }
737  if (i == 1000)
738  elog(ERROR, "atomic_compare_exchange_u32() never succeeded");
739  if (pg_atomic_read_u32(&var) != 1)
740  elog(ERROR, "atomic_compare_exchange_u32() didn't set value properly");
741 
742  pg_atomic_write_u32(&var, 0);
743 
744  /* try setting flagbits */
745  if (pg_atomic_fetch_or_u32(&var, 1) & 1)
746  elog(ERROR, "pg_atomic_fetch_or_u32() #1 wrong");
747 
748  if (!(pg_atomic_fetch_or_u32(&var, 2) & 1))
749  elog(ERROR, "pg_atomic_fetch_or_u32() #2 wrong");
750 
751  if (pg_atomic_read_u32(&var) != 3)
752  elog(ERROR, "invalid result after pg_atomic_fetch_or_u32()");
753 
754  /* try clearing flagbits */
755  if ((pg_atomic_fetch_and_u32(&var, ~2) & 3) != 3)
756  elog(ERROR, "pg_atomic_fetch_and_u32() #1 wrong");
757 
758  if (pg_atomic_fetch_and_u32(&var, ~1) != 1)
759  elog(ERROR, "pg_atomic_fetch_and_u32() #2 wrong: is %u",
760  pg_atomic_read_u32(&var));
761  /* no bits set anymore */
762  if (pg_atomic_fetch_and_u32(&var, ~0) != 0)
763  elog(ERROR, "pg_atomic_fetch_and_u32() #3 wrong");
764 }
static uint32 pg_atomic_fetch_sub_u32(volatile pg_atomic_uint32 *ptr, int32 sub_)
Definition: atomics.h:346
static bool pg_atomic_compare_exchange_u32(volatile pg_atomic_uint32 *ptr, uint32 *expected, uint32 newval)
Definition: atomics.h:314
static uint32 pg_atomic_sub_fetch_u32(volatile pg_atomic_uint32 *ptr, int32 sub_)
Definition: atomics.h:404
static uint32 pg_atomic_add_fetch_u32(volatile pg_atomic_uint32 *ptr, int32 add_)
Definition: atomics.h:389
static uint32 pg_atomic_exchange_u32(volatile pg_atomic_uint32 *ptr, uint32 newval)
Definition: atomics.h:295
#define ERROR
Definition: elog.h:43
static uint32 pg_atomic_fetch_and_u32(volatile pg_atomic_uint32 *ptr, uint32 and_)
Definition: atomics.h:361
unsigned int uint32
Definition: c.h:325
static uint32 pg_atomic_fetch_add_u32(volatile pg_atomic_uint32 *ptr, int32 add_)
Definition: atomics.h:331
int i
static uint32 pg_atomic_fetch_or_u32(volatile pg_atomic_uint32 *ptr, uint32 or_)
Definition: atomics.h:375
static void pg_atomic_init_u32(volatile pg_atomic_uint32 *ptr, uint32 val)
Definition: atomics.h:226
#define elog
Definition: elog.h:219
static void pg_atomic_write_u32(volatile pg_atomic_uint32 *ptr, uint32 val)
Definition: atomics.h:261
static uint32 pg_atomic_read_u32(volatile pg_atomic_uint32 *ptr)
Definition: atomics.h:244

◆ test_atomic_uint64()

static void test_atomic_uint64 ( void  )
static

Definition at line 767 of file regress.c.

References elog, ERROR, i, pg_atomic_add_fetch_u64(), pg_atomic_compare_exchange_u64(), pg_atomic_exchange_u64(), pg_atomic_fetch_add_u64(), pg_atomic_fetch_and_u64(), pg_atomic_fetch_or_u64(), pg_atomic_fetch_sub_u64(), pg_atomic_init_u64(), pg_atomic_read_u64(), pg_atomic_sub_fetch_u64(), pg_atomic_write_u64(), PG_FUNCTION_INFO_V1(), test_atomic_ops(), and UINT64_FORMAT.

Referenced by test_atomic_ops().

768 {
769  pg_atomic_uint64 var;
770  uint64 expected;
771  int i;
772 
773  pg_atomic_init_u64(&var, 0);
774 
775  if (pg_atomic_read_u64(&var) != 0)
776  elog(ERROR, "atomic_read_u64() #1 wrong");
777 
778  pg_atomic_write_u64(&var, 3);
779 
780  if (pg_atomic_read_u64(&var) != 3)
781  elog(ERROR, "atomic_read_u64() #2 wrong");
782 
783  if (pg_atomic_fetch_add_u64(&var, 1) != 3)
784  elog(ERROR, "atomic_fetch_add_u64() #1 wrong");
785 
786  if (pg_atomic_fetch_sub_u64(&var, 1) != 4)
787  elog(ERROR, "atomic_fetch_sub_u64() #1 wrong");
788 
789  if (pg_atomic_sub_fetch_u64(&var, 3) != 0)
790  elog(ERROR, "atomic_sub_fetch_u64() #1 wrong");
791 
792  if (pg_atomic_add_fetch_u64(&var, 10) != 10)
793  elog(ERROR, "atomic_add_fetch_u64() #1 wrong");
794 
795  if (pg_atomic_exchange_u64(&var, 5) != 10)
796  elog(ERROR, "pg_atomic_exchange_u64() #1 wrong");
797 
798  if (pg_atomic_exchange_u64(&var, 0) != 5)
799  elog(ERROR, "pg_atomic_exchange_u64() #0 wrong");
800 
801  /* fail exchange because of old expected */
802  expected = 10;
803  if (pg_atomic_compare_exchange_u64(&var, &expected, 1))
804  elog(ERROR, "atomic_compare_exchange_u64() changed value spuriously");
805 
806  /* CAS is allowed to fail due to interrupts, try a couple of times */
807  for (i = 0; i < 100; i++)
808  {
809  expected = 0;
810  if (!pg_atomic_compare_exchange_u64(&var, &expected, 1))
811  break;
812  }
813  if (i == 100)
814  elog(ERROR, "atomic_compare_exchange_u64() never succeeded");
815  if (pg_atomic_read_u64(&var) != 1)
816  elog(ERROR, "atomic_compare_exchange_u64() didn't set value properly");
817 
818  pg_atomic_write_u64(&var, 0);
819 
820  /* try setting flagbits */
821  if (pg_atomic_fetch_or_u64(&var, 1) & 1)
822  elog(ERROR, "pg_atomic_fetch_or_u64() #1 wrong");
823 
824  if (!(pg_atomic_fetch_or_u64(&var, 2) & 1))
825  elog(ERROR, "pg_atomic_fetch_or_u64() #2 wrong");
826 
827  if (pg_atomic_read_u64(&var) != 3)
828  elog(ERROR, "invalid result after pg_atomic_fetch_or_u64()");
829 
830  /* try clearing flagbits */
831  if ((pg_atomic_fetch_and_u64(&var, ~2) & 3) != 3)
832  elog(ERROR, "pg_atomic_fetch_and_u64() #1 wrong");
833 
834  if (pg_atomic_fetch_and_u64(&var, ~1) != 1)
835  elog(ERROR, "pg_atomic_fetch_and_u64() #2 wrong: is " UINT64_FORMAT,
836  pg_atomic_read_u64(&var));
837  /* no bits set anymore */
838  if (pg_atomic_fetch_and_u64(&var, ~0) != 0)
839  elog(ERROR, "pg_atomic_fetch_and_u64() #3 wrong");
840 }
static uint64 pg_atomic_fetch_add_u64(volatile pg_atomic_uint64 *ptr, int64 add_)
Definition: atomics.h:470
static uint64 pg_atomic_sub_fetch_u64(volatile pg_atomic_uint64 *ptr, int64 sub_)
Definition: atomics.h:516
static uint64 pg_atomic_fetch_sub_u64(volatile pg_atomic_uint64 *ptr, int64 sub_)
Definition: atomics.h:479
static void pg_atomic_write_u64(volatile pg_atomic_uint64 *ptr, uint64 val)
Definition: atomics.h:441
static bool pg_atomic_compare_exchange_u64(volatile pg_atomic_uint64 *ptr, uint64 *expected, uint64 newval)
Definition: atomics.h:459
static uint64 pg_atomic_exchange_u64(volatile pg_atomic_uint64 *ptr, uint64 newval)
Definition: atomics.h:450
static void pg_atomic_init_u64(volatile pg_atomic_uint64 *ptr, uint64 val)
Definition: atomics.h:418
#define ERROR
Definition: elog.h:43
static uint64 pg_atomic_fetch_or_u64(volatile pg_atomic_uint64 *ptr, uint64 or_)
Definition: atomics.h:498
static uint64 pg_atomic_fetch_and_u64(volatile pg_atomic_uint64 *ptr, uint64 and_)
Definition: atomics.h:489
static uint64 pg_atomic_add_fetch_u64(volatile pg_atomic_uint64 *ptr, int64 add_)
Definition: atomics.h:507
static uint64 pg_atomic_read_u64(volatile pg_atomic_uint64 *ptr)
Definition: atomics.h:432
int i
#define elog
Definition: elog.h:219
#define UINT64_FORMAT
Definition: c.h:368

◆ test_fdw_handler()

Datum test_fdw_handler ( PG_FUNCTION_ARGS  )

Definition at line 858 of file regress.c.

References elog, ERROR, and PG_RETURN_NULL.

Referenced by test_atomic_ops().

859 {
860  elog(ERROR, "test_fdw_handler is not implemented");
861  PG_RETURN_NULL();
862 }
#define ERROR
Definition: elog.h:43
#define elog
Definition: elog.h:219
#define PG_RETURN_NULL()
Definition: fmgr.h:310

◆ trigger_return_old()

Datum trigger_return_old ( PG_FUNCTION_ARGS  )

Definition at line 209 of file regress.c.

References CALLED_AS_TRIGGER, elog, ERROR, PointerGetDatum, and TriggerData::tg_trigtuple.

Referenced by reverse_name().

210 {
211  TriggerData *trigdata = (TriggerData *) fcinfo->context;
212  HeapTuple tuple;
213 
214  if (!CALLED_AS_TRIGGER(fcinfo))
215  elog(ERROR, "trigger_return_old: not fired by trigger manager");
216 
217  tuple = trigdata->tg_trigtuple;
218 
219  return PointerGetDatum(tuple);
220 }
#define PointerGetDatum(X)
Definition: postgres.h:539
HeapTuple tg_trigtuple
Definition: trigger.h:35
#define ERROR
Definition: elog.h:43
#define CALLED_AS_TRIGGER(fcinfo)
Definition: trigger.h:25
#define elog
Definition: elog.h:219

◆ ttdummy()

Datum ttdummy ( PG_FUNCTION_ARGS  )

Definition at line 230 of file regress.c.

References generate_unaccent_rules::args, attnum, CALLED_AS_TRIGGER, CStringGetTextDatum, DatumGetInt64, DirectFunctionCall1, elog, ereport, errcode(), errmsg(), ERROR, i, Int32GetDatum, nextval(), palloc(), pfree(), PG_FUNCTION_INFO_V1(), PointerGetDatum, set_ttdummy(), SPI_connect(), SPI_execp(), SPI_finish(), SPI_fnumber(), SPI_getbinval(), SPI_getrelname(), SPI_gettypeid(), SPI_keepplan(), SPI_modifytuple(), SPI_prepare(), SPI_result, SPI_result_code_string(), TriggerData::tg_event, TriggerData::tg_newtuple, TriggerData::tg_relation, TriggerData::tg_trigger, TriggerData::tg_trigtuple, TRIGGER_FIRED_BEFORE, TRIGGER_FIRED_BY_INSERT, TRIGGER_FIRED_BY_UPDATE, TRIGGER_FIRED_FOR_ROW, TTDUMMY_INFINITY, and ttoff.

231 {
232  TriggerData *trigdata = (TriggerData *) fcinfo->context;
233  Trigger *trigger; /* to get trigger name */
234  char **args; /* arguments */
235  int attnum[2]; /* fnumbers of start/stop columns */
236  Datum oldon,
237  oldoff;
238  Datum newon,
239  newoff;
240  Datum *cvals; /* column values */
241  char *cnulls; /* column nulls */
242  char *relname; /* triggered relation name */
243  Relation rel; /* triggered relation */
244  HeapTuple trigtuple;
245  HeapTuple newtuple = NULL;
246  HeapTuple rettuple;
247  TupleDesc tupdesc; /* tuple description */
248  int natts; /* # of attributes */
249  bool isnull; /* to know is some column NULL or not */
250  int ret;
251  int i;
252 
253  if (!CALLED_AS_TRIGGER(fcinfo))
254  elog(ERROR, "ttdummy: not fired by trigger manager");
255  if (!TRIGGER_FIRED_FOR_ROW(trigdata->tg_event))
256  elog(ERROR, "ttdummy: must be fired for row");
257  if (!TRIGGER_FIRED_BEFORE(trigdata->tg_event))
258  elog(ERROR, "ttdummy: must be fired before event");
259  if (TRIGGER_FIRED_BY_INSERT(trigdata->tg_event))
260  elog(ERROR, "ttdummy: cannot process INSERT event");
261  if (TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event))
262  newtuple = trigdata->tg_newtuple;
263 
264  trigtuple = trigdata->tg_trigtuple;
265 
266  rel = trigdata->tg_relation;
267  relname = SPI_getrelname(rel);
268 
269  /* check if TT is OFF for this relation */
270  if (ttoff) /* OFF - nothing to do */
271  {
272  pfree(relname);
273  return PointerGetDatum((newtuple != NULL) ? newtuple : trigtuple);
274  }
275 
276  trigger = trigdata->tg_trigger;
277 
278  if (trigger->tgnargs != 2)
279  elog(ERROR, "ttdummy (%s): invalid (!= 2) number of arguments %d",
280  relname, trigger->tgnargs);
281 
282  args = trigger->tgargs;
283  tupdesc = rel->rd_att;
284  natts = tupdesc->natts;
285 
286  for (i = 0; i < 2; i++)
287  {
288  attnum[i] = SPI_fnumber(tupdesc, args[i]);
289  if (attnum[i] <= 0)
290  elog(ERROR, "ttdummy (%s): there is no attribute %s",
291  relname, args[i]);
292  if (SPI_gettypeid(tupdesc, attnum[i]) != INT4OID)
293  elog(ERROR, "ttdummy (%s): attribute %s must be of integer type",
294  relname, args[i]);
295  }
296 
297  oldon = SPI_getbinval(trigtuple, tupdesc, attnum[0], &isnull);
298  if (isnull)
299  elog(ERROR, "ttdummy (%s): %s must be NOT NULL", relname, args[0]);
300 
301  oldoff = SPI_getbinval(trigtuple, tupdesc, attnum[1], &isnull);
302  if (isnull)
303  elog(ERROR, "ttdummy (%s): %s must be NOT NULL", relname, args[1]);
304 
305  if (newtuple != NULL) /* UPDATE */
306  {
307  newon = SPI_getbinval(newtuple, tupdesc, attnum[0], &isnull);
308  if (isnull)
309  elog(ERROR, "ttdummy (%s): %s must be NOT NULL", relname, args[0]);
310  newoff = SPI_getbinval(newtuple, tupdesc, attnum[1], &isnull);
311  if (isnull)
312  elog(ERROR, "ttdummy (%s): %s must be NOT NULL", relname, args[1]);
313 
314  if (oldon != newon || oldoff != newoff)
315  ereport(ERROR,
316  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
317  errmsg("ttdummy (%s): you cannot change %s and/or %s columns (use set_ttdummy)",
318  relname, args[0], args[1])));
319 
320  if (newoff != TTDUMMY_INFINITY)
321  {
322  pfree(relname); /* allocated in upper executor context */
323  return PointerGetDatum(NULL);
324  }
325  }
326  else if (oldoff != TTDUMMY_INFINITY) /* DELETE */
327  {
328  pfree(relname);
329  return PointerGetDatum(NULL);
330  }
331 
332  newoff = DirectFunctionCall1(nextval, CStringGetTextDatum("ttdummy_seq"));
333  /* nextval now returns int64; coerce down to int32 */
334  newoff = Int32GetDatum((int32) DatumGetInt64(newoff));
335 
336  /* Connect to SPI manager */
337  if ((ret = SPI_connect()) < 0)
338  elog(ERROR, "ttdummy (%s): SPI_connect returned %d", relname, ret);
339 
340  /* Fetch tuple values and nulls */
341  cvals = (Datum *) palloc(natts * sizeof(Datum));
342  cnulls = (char *) palloc(natts * sizeof(char));
343  for (i = 0; i < natts; i++)
344  {
345  cvals[i] = SPI_getbinval((newtuple != NULL) ? newtuple : trigtuple,
346  tupdesc, i + 1, &isnull);
347  cnulls[i] = (isnull) ? 'n' : ' ';
348  }
349 
350  /* change date column(s) */
351  if (newtuple) /* UPDATE */
352  {
353  cvals[attnum[0] - 1] = newoff; /* start_date eq current date */
354  cnulls[attnum[0] - 1] = ' ';
355  cvals[attnum[1] - 1] = TTDUMMY_INFINITY; /* stop_date eq INFINITY */
356  cnulls[attnum[1] - 1] = ' ';
357  }
358  else
359  /* DELETE */
360  {
361  cvals[attnum[1] - 1] = newoff; /* stop_date eq current date */
362  cnulls[attnum[1] - 1] = ' ';
363  }
364 
365  /* if there is no plan ... */
366  if (splan == NULL)
367  {
368  SPIPlanPtr pplan;
369  Oid *ctypes;
370  char *query;
371 
372  /* allocate space in preparation */
373  ctypes = (Oid *) palloc(natts * sizeof(Oid));
374  query = (char *) palloc(100 + 16 * natts);
375 
376  /*
377  * Construct query: INSERT INTO _relation_ VALUES ($1, ...)
378  */
379  sprintf(query, "INSERT INTO %s VALUES (", relname);
380  for (i = 1; i <= natts; i++)
381  {
382  sprintf(query + strlen(query), "$%d%s",
383  i, (i < natts) ? ", " : ")");
384  ctypes[i - 1] = SPI_gettypeid(tupdesc, i);
385  }
386 
387  /* Prepare plan for query */
388  pplan = SPI_prepare(query, natts, ctypes);
389  if (pplan == NULL)
390  elog(ERROR, "ttdummy (%s): SPI_prepare returned %s", relname, SPI_result_code_string(SPI_result));
391 
392  if (SPI_keepplan(pplan))
393  elog(ERROR, "ttdummy (%s): SPI_keepplan failed", relname);
394 
395  splan = pplan;
396  }
397 
398  ret = SPI_execp(splan, cvals, cnulls, 0);
399 
400  if (ret < 0)
401  elog(ERROR, "ttdummy (%s): SPI_execp returned %d", relname, ret);
402 
403  /* Tuple to return to upper Executor ... */
404  if (newtuple) /* UPDATE */
405  rettuple = SPI_modifytuple(rel, trigtuple, 1, &(attnum[1]), &newoff, NULL);
406  else /* DELETE */
407  rettuple = trigtuple;
408 
409  SPI_finish(); /* don't forget say Bye to SPI mgr */
410 
411  pfree(relname);
412 
413  return PointerGetDatum(rettuple);
414 }
int SPI_fnumber(TupleDesc tupdesc, const char *fname)
Definition: spi.c:855
Oid SPI_gettypeid(TupleDesc tupdesc, int fnumber)
Definition: spi.c:988
int SPI_connect(void)
Definition: spi.c:84
#define PointerGetDatum(X)
Definition: postgres.h:539
SPIPlanPtr SPI_prepare(const char *src, int nargs, Oid *argtypes)
Definition: spi.c:576
int SPI_finish(void)
Definition: spi.c:161
Datum nextval(PG_FUNCTION_ARGS)
Definition: sequence.c:538
int errcode(int sqlerrcode)
Definition: elog.c:575
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:590
unsigned int Oid
Definition: postgres_ext.h:31
HeapTuple tg_trigtuple
Definition: trigger.h:35
signed int int32
Definition: c.h:313
static bool ttoff
Definition: regress.c:225
int SPI_result
Definition: spi.c:42
void pfree(void *pointer)
Definition: mcxt.c:1031
#define ERROR
Definition: elog.h:43
Datum SPI_getbinval(HeapTuple tuple, TupleDesc tupdesc, int fnumber, bool *isnull)
Definition: spi.c:932
#define DatumGetInt64(X)
Definition: postgres.h:590
const char * SPI_result_code_string(int code)
Definition: spi.c:1609
int SPI_keepplan(SPIPlanPtr plan)
Definition: spi.c:654
static SPIPlanPtr splan
Definition: regress.c:224
HeapTuple SPI_modifytuple(Relation rel, HeapTuple tuple, int natts, int *attnum, Datum *Values, const char *Nulls)
Definition: spi.c:784
#define ereport(elevel, rest)
Definition: elog.h:122
#define TTDUMMY_INFINITY
Definition: regress.c:222
uintptr_t Datum
Definition: postgres.h:365
Trigger * tg_trigger
Definition: trigger.h:37
HeapTuple tg_newtuple
Definition: trigger.h:36
char * SPI_getrelname(Relation rel)
Definition: spi.c:1006
int16 attnum
Definition: pg_attribute.h:79
#define CALLED_AS_TRIGGER(fcinfo)
Definition: trigger.h:25
TriggerEvent tg_event
Definition: trigger.h:33
#define TRIGGER_FIRED_BEFORE(event)
Definition: trigger.h:134
#define Int32GetDatum(X)
Definition: postgres.h:462
#define TRIGGER_FIRED_BY_INSERT(event)
Definition: trigger.h:116
void * palloc(Size size)
Definition: mcxt.c:924
int errmsg(const char *fmt,...)
Definition: elog.c:797
int i
int SPI_execp(SPIPlanPtr plan, Datum *Values, const char *Nulls, long tcount)
Definition: spi.c:460
#define CStringGetTextDatum(s)
Definition: builtins.h:95
#define elog
Definition: elog.h:219
#define TRIGGER_FIRED_FOR_ROW(event)
Definition: trigger.h:128
#define TRIGGER_FIRED_BY_UPDATE(event)
Definition: trigger.h:122
Relation tg_relation
Definition: trigger.h:34

◆ wait_pid()

Datum wait_pid ( PG_FUNCTION_ARGS  )

Definition at line 617 of file regress.c.

References CHECK_FOR_INTERRUPTS, elog, ERROR, kill, PG_GETARG_INT32, PG_RETURN_VOID, pg_usleep(), and superuser().

Referenced by regress_putenv().

618 {
619  int pid = PG_GETARG_INT32(0);
620 
621  if (!superuser())
622  elog(ERROR, "must be superuser to check PID liveness");
623 
624  while (kill(pid, 0) == 0)
625  {
627  pg_usleep(50000);
628  }
629 
630  if (errno != ESRCH)
631  elog(ERROR, "could not check PID %d liveness: %m", pid);
632 
633  PG_RETURN_VOID();
634 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
bool superuser(void)
Definition: superuser.c:47
#define kill(pid, sig)
Definition: win32_port.h:437
void pg_usleep(long microsec)
Definition: signal.c:53
#define ERROR
Definition: elog.h:43
#define PG_RETURN_VOID()
Definition: fmgr.h:314
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:98
#define elog
Definition: elog.h:219

◆ widget_in()

Datum widget_in ( PG_FUNCTION_ARGS  )

Definition at line 136 of file regress.c.

References WIDGET::center, DELIM, ereport, errcode(), errmsg(), ERROR, i, LDELIM, NARGS, palloc(), PG_GETARG_CSTRING, PG_RETURN_POINTER, WIDGET::radius, RDELIM, generate_unaccent_rules::str, Point::x, and Point::y.

137 {
138  char *str = PG_GETARG_CSTRING(0);
139  char *p,
140  *coord[NARGS];
141  int i;
142  WIDGET *result;
143 
144  for (i = 0, p = str; *p && i < NARGS && *p != RDELIM; p++)
145  {
146  if (*p == DELIM || (*p == LDELIM && i == 0))
147  coord[i++] = p + 1;
148  }
149 
150  if (i < NARGS)
151  ereport(ERROR,
152  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
153  errmsg("invalid input syntax for type widget: \"%s\"",
154  str)));
155 
156  result = (WIDGET *) palloc(sizeof(WIDGET));
157  result->center.x = atof(coord[0]);
158  result->center.y = atof(coord[1]);
159  result->radius = atof(coord[2]);
160 
161  PG_RETURN_POINTER(result);
162 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:326
double radius
Definition: regress.c:127
#define RDELIM
Definition: regress.c:43
double y
Definition: geo_decls.h:60
int errcode(int sqlerrcode)
Definition: elog.c:575
double x
Definition: geo_decls.h:60
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
#define DELIM
Definition: regress.c:44
#define NARGS
Definition: regress.c:133
void * palloc(Size size)
Definition: mcxt.c:924
int errmsg(const char *fmt,...)
Definition: elog.c:797
Point center
Definition: regress.c:126
int i
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:247
#define LDELIM
Definition: regress.c:42

◆ widget_out()

Datum widget_out ( PG_FUNCTION_ARGS  )

Definition at line 165 of file regress.c.

References WIDGET::center, PG_FUNCTION_INFO_V1(), PG_GETARG_POINTER, PG_RETURN_CSTRING, psprintf(), pt_in_widget(), WIDGET::radius, generate_unaccent_rules::str, Point::x, and Point::y.

166 {
167  WIDGET *widget = (WIDGET *) PG_GETARG_POINTER(0);
168  char *str = psprintf("(%g,%g,%g)",
169  widget->center.x, widget->center.y, widget->radius);
170 
171  PG_RETURN_CSTRING(str);
172 }
double radius
Definition: regress.c:127
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
double y
Definition: geo_decls.h:60
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:246
double x
Definition: geo_decls.h:60
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:327
Point center
Definition: regress.c:126

Variable Documentation

◆ PG_MODULE_MAGIC

PG_MODULE_MAGIC

Definition at line 48 of file regress.c.

◆ splan

SPIPlanPtr splan = NULL
static

Definition at line 224 of file regress.c.

Referenced by build_subplan(), ExecReScan(), get_rule_expr(), set_plan_refs(), and SS_process_ctes().

◆ ttoff

bool ttoff = false
static

Definition at line 225 of file regress.c.

Referenced by set_ttdummy(), and ttdummy().