PostgreSQL Source Code  git master
regress.c File Reference
#include "postgres.h"
#include <math.h>
#include <signal.h>
#include "access/detoast.h"
#include "access/htup_details.h"
#include "catalog/namespace.h"
#include "catalog/pg_operator.h"
#include "catalog/pg_type.h"
#include "commands/sequence.h"
#include "commands/trigger.h"
#include "executor/executor.h"
#include "executor/spi.h"
#include "funcapi.h"
#include "mb/pg_wchar.h"
#include "miscadmin.h"
#include "nodes/supportnodes.h"
#include "optimizer/optimizer.h"
#include "optimizer/plancat.h"
#include "parser/parse_coerce.h"
#include "port/atomics.h"
#include "storage/spin.h"
#include "utils/array.h"
#include "utils/builtins.h"
#include "utils/geo_decls.h"
#include "utils/memutils.h"
#include "utils/rel.h"
#include "utils/typcache.h"
Include dependency graph for regress.c:

Go to the source code of this file.

Data Structures

struct  WIDGET
 

Macros

#define EXPECT_TRUE(expr)
 
#define EXPECT_EQ_U32(result_expr, expected_expr)
 
#define EXPECT_EQ_U64(result_expr, expected_expr)
 
#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 (test_canonicalize_path)
 
Datum test_canonicalize_path (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (make_tuple_indirect)
 
Datum make_tuple_indirect (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (get_environ)
 
Datum get_environ (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (regress_setenv)
 
Datum regress_setenv (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)
 
static void test_spinlock (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)
 
 PG_FUNCTION_INFO_V1 (test_support_func)
 
Datum test_support_func (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (test_opclass_options_func)
 
Datum test_opclass_options_func (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (test_enc_conversion)
 
Datum test_enc_conversion (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (binary_coercible)
 
Datum binary_coercible (PG_FUNCTION_ARGS)
 

Variables

 PG_MODULE_MAGIC
 
static SPIPlanPtr splan = NULL
 
static bool ttoff = false
 

Macro Definition Documentation

◆ DELIM

#define DELIM   ','

Definition at line 77 of file regress.c.

◆ EXPECT_EQ_U32

#define EXPECT_EQ_U32 (   result_expr,
  expected_expr 
)
Value:
do { \
uint32 actual_result = (result_expr); \
uint32 expected_result = (expected_expr); \
if (actual_result != expected_result) \
elog(ERROR, \
"%s yielded %u, expected %s in file \"%s\" line %u", \
#result_expr, actual_result, #expected_expr, __FILE__, __LINE__); \
} while (0)
#define ERROR
Definition: elog.h:39

Definition at line 55 of file regress.c.

◆ EXPECT_EQ_U64

#define EXPECT_EQ_U64 (   result_expr,
  expected_expr 
)
Value:
do { \
uint64 actual_result = (result_expr); \
uint64 expected_result = (expected_expr); \
if (actual_result != expected_result) \
elog(ERROR, \
"%s yielded " UINT64_FORMAT ", expected %s in file \"%s\" line %u", \
#result_expr, actual_result, #expected_expr, __FILE__, __LINE__); \
} while (0)
#define UINT64_FORMAT
Definition: c.h:504

Definition at line 65 of file regress.c.

◆ EXPECT_TRUE

#define EXPECT_TRUE (   expr)
Value:
do { \
if (!(expr)) \
elog(ERROR, \
"%s was unexpectedly false in file \"%s\" line %u", \
#expr, __FILE__, __LINE__); \
} while (0)

Definition at line 47 of file regress.c.

◆ LDELIM

#define LDELIM   '('

Definition at line 75 of file regress.c.

◆ NARGS

#define NARGS   3

Definition at line 166 of file regress.c.

◆ RDELIM

#define RDELIM   ')'

Definition at line 76 of file regress.c.

◆ TTDUMMY_INFINITY

#define TTDUMMY_INFINITY   999999

Definition at line 265 of file regress.c.

Function Documentation

◆ binary_coercible()

Datum binary_coercible ( PG_FUNCTION_ARGS  )

Definition at line 1152 of file regress.c.

1153 {
1154  Oid srctype = PG_GETARG_OID(0);
1155  Oid targettype = PG_GETARG_OID(1);
1156 
1157  PG_RETURN_BOOL(IsBinaryCoercible(srctype, targettype));
1158 }
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
bool IsBinaryCoercible(Oid srctype, Oid targettype)
unsigned int Oid
Definition: postgres_ext.h:31

References IsBinaryCoercible(), PG_GETARG_OID, and PG_RETURN_BOOL.

◆ get_environ()

Datum get_environ ( PG_FUNCTION_ARGS  )

Definition at line 648 of file regress.c.

649 {
650  extern char **environ;
651  int nvals = 0;
652  ArrayType *result;
653  Datum *env;
654 
655  for (char **s = environ; *s; s++)
656  nvals++;
657 
658  env = palloc(nvals * sizeof(Datum));
659 
660  for (int i = 0; i < nvals; i++)
661  env[i] = CStringGetTextDatum(environ[i]);
662 
663  result = construct_array_builtin(env, nvals, TEXTOID);
664 
665  PG_RETURN_POINTER(result);
666 }
ArrayType * construct_array_builtin(Datum *elems, int nelems, Oid elmtype)
Definition: arrayfuncs.c:3381
#define CStringGetTextDatum(s)
Definition: builtins.h:97
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:361
int i
Definition: isn.c:72
void * palloc(Size size)
Definition: mcxt.c:1317
uintptr_t Datum
Definition: postgres.h:64
char ** environ

References construct_array_builtin(), CStringGetTextDatum, environ, i, palloc(), and PG_RETURN_POINTER.

◆ int44in()

Datum int44in ( PG_FUNCTION_ARGS  )

Definition at line 499 of file regress.c.

500 {
501  char *input_string = PG_GETARG_CSTRING(0);
502  int32 *result = (int32 *) palloc(4 * sizeof(int32));
503  int i;
504 
505  i = sscanf(input_string,
506  "%d, %d, %d, %d",
507  &result[0],
508  &result[1],
509  &result[2],
510  &result[3]);
511  while (i < 4)
512  result[i++] = 0;
513 
514  PG_RETURN_POINTER(result);
515 }
int32_t int32
Definition: c.h:481
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:277

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

◆ int44out()

Datum int44out ( PG_FUNCTION_ARGS  )

Definition at line 523 of file regress.c.

524 {
525  int32 *an_array = (int32 *) PG_GETARG_POINTER(0);
526  char *result = (char *) palloc(16 * 4);
527 
528  snprintf(result, 16 * 4, "%d,%d,%d,%d",
529  an_array[0],
530  an_array[1],
531  an_array[2],
532  an_array[3]);
533 
534  PG_RETURN_CSTRING(result);
535 }
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:362
#define snprintf
Definition: port.h:238

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

◆ interpt_pp()

Datum interpt_pp ( PG_FUNCTION_ARGS  )

Definition at line 88 of file regress.c.

89 {
90  PATH *p1 = PG_GETARG_PATH_P(0);
91  PATH *p2 = PG_GETARG_PATH_P(1);
92  int i,
93  j;
94  LSEG seg1,
95  seg2;
96  bool found; /* We've found the intersection */
97 
98  found = false; /* Haven't found it yet */
99 
100  for (i = 0; i < p1->npts - 1 && !found; i++)
101  {
102  regress_lseg_construct(&seg1, &p1->p[i], &p1->p[i + 1]);
103  for (j = 0; j < p2->npts - 1 && !found; j++)
104  {
105  regress_lseg_construct(&seg2, &p2->p[j], &p2->p[j + 1]);
107  LsegPGetDatum(&seg1),
108  LsegPGetDatum(&seg2))))
109  found = true;
110  }
111  }
112 
113  if (!found)
114  PG_RETURN_NULL();
115 
116  /*
117  * Note: DirectFunctionCall2 will kick out an error if lseg_interpt()
118  * returns NULL, but that should be impossible since we know the two
119  * segments intersect.
120  */
122  LsegPGetDatum(&seg1),
123  LsegPGetDatum(&seg2)));
124 }
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:643
#define PG_RETURN_NULL()
Definition: fmgr.h:345
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:353
static Datum LsegPGetDatum(const LSEG *X)
Definition: geo_decls.h:194
#define PG_GETARG_PATH_P(n)
Definition: geo_decls.h:216
Datum lseg_intersect(PG_FUNCTION_ARGS)
Definition: geo_ops.c:2188
Datum lseg_interpt(PG_FUNCTION_ARGS)
Definition: geo_ops.c:2361
int j
Definition: isn.c:73
static bool DatumGetBool(Datum X)
Definition: postgres.h:90
static void regress_lseg_construct(LSEG *lseg, Point *pt1, Point *pt2)
Definition: regress.c:129
Point p[FLEXIBLE_ARRAY_MEMBER]
Definition: geo_decls.h:121
int32 npts
Definition: geo_decls.h:118

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

◆ make_tuple_indirect()

Datum make_tuple_indirect ( PG_FUNCTION_ARGS  )

Definition at line 549 of file regress.c.

550 {
552  HeapTupleData tuple;
553  int ncolumns;
554  Datum *values;
555  bool *nulls;
556 
557  Oid tupType;
558  int32 tupTypmod;
559  TupleDesc tupdesc;
560 
561  HeapTuple newtup;
562 
563  int i;
564 
565  MemoryContext old_context;
566 
567  /* Extract type info from the tuple itself */
568  tupType = HeapTupleHeaderGetTypeId(rec);
569  tupTypmod = HeapTupleHeaderGetTypMod(rec);
570  tupdesc = lookup_rowtype_tupdesc(tupType, tupTypmod);
571  ncolumns = tupdesc->natts;
572 
573  /* Build a temporary HeapTuple control structure */
575  ItemPointerSetInvalid(&(tuple.t_self));
576  tuple.t_tableOid = InvalidOid;
577  tuple.t_data = rec;
578 
579  values = (Datum *) palloc(ncolumns * sizeof(Datum));
580  nulls = (bool *) palloc(ncolumns * sizeof(bool));
581 
582  heap_deform_tuple(&tuple, tupdesc, values, nulls);
583 
585 
586  for (i = 0; i < ncolumns; i++)
587  {
588  struct varlena *attr;
589  struct varlena *new_attr;
590  struct varatt_indirect redirect_pointer;
591 
592  /* only work on existing, not-null varlenas */
593  if (TupleDescAttr(tupdesc, i)->attisdropped ||
594  nulls[i] ||
595  TupleDescAttr(tupdesc, i)->attlen != -1 ||
596  TupleDescAttr(tupdesc, i)->attstorage == TYPSTORAGE_PLAIN)
597  continue;
598 
599  attr = (struct varlena *) DatumGetPointer(values[i]);
600 
601  /* don't recursively indirect */
602  if (VARATT_IS_EXTERNAL_INDIRECT(attr))
603  continue;
604 
605  /* copy datum, so it still lives later */
606  if (VARATT_IS_EXTERNAL_ONDISK(attr))
607  attr = detoast_external_attr(attr);
608  else
609  {
610  struct varlena *oldattr = attr;
611 
612  attr = palloc0(VARSIZE_ANY(oldattr));
613  memcpy(attr, oldattr, VARSIZE_ANY(oldattr));
614  }
615 
616  /* build indirection Datum */
617  new_attr = (struct varlena *) palloc0(INDIRECT_POINTER_SIZE);
618  redirect_pointer.pointer = attr;
620  memcpy(VARDATA_EXTERNAL(new_attr), &redirect_pointer,
621  sizeof(redirect_pointer));
622 
623  values[i] = PointerGetDatum(new_attr);
624  }
625 
626  newtup = heap_form_tuple(tupdesc, values, nulls);
627  pfree(values);
628  pfree(nulls);
629  ReleaseTupleDesc(tupdesc);
630 
631  MemoryContextSwitchTo(old_context);
632 
633  /*
634  * We intentionally don't use PG_RETURN_HEAPTUPLEHEADER here, because that
635  * would cause the indirect toast pointers to be flattened out of the
636  * tuple immediately, rendering subsequent testing irrelevant. So just
637  * return the HeapTupleHeader pointer as-is. This violates the general
638  * rule that composite Datums shouldn't contain toast pointers, but so
639  * long as the regression test scripts don't insert the result of this
640  * function into a container type (record, array, etc) it should be OK.
641  */
642  PG_RETURN_POINTER(newtup->t_data);
643 }
static Datum values[MAXATTR]
Definition: bootstrap.c:151
struct varlena * detoast_external_attr(struct varlena *attr)
Definition: detoast.c:45
#define INDIRECT_POINTER_SIZE
Definition: detoast.h:34
#define PG_GETARG_HEAPTUPLEHEADER(n)
Definition: fmgr.h:312
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
Definition: heaptuple.c:1116
void heap_deform_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *values, bool *isnull)
Definition: heaptuple.c:1345
#define HeapTupleHeaderGetTypMod(tup)
Definition: htup_details.h:466
#define HeapTupleHeaderGetTypeId(tup)
Definition: htup_details.h:456
#define HeapTupleHeaderGetDatumLength(tup)
Definition: htup_details.h:450
static void ItemPointerSetInvalid(ItemPointerData *pointer)
Definition: itemptr.h:184
MemoryContext TopTransactionContext
Definition: mcxt.c:154
void pfree(void *pointer)
Definition: mcxt.c:1521
void * palloc0(Size size)
Definition: mcxt.c:1347
char attstorage
Definition: pg_attribute.h:117
int16 attlen
Definition: pg_attribute.h:59
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:322
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:312
#define InvalidOid
Definition: postgres_ext.h:36
MemoryContextSwitchTo(old_ctx)
ItemPointerData t_self
Definition: htup.h:65
uint32 t_len
Definition: htup.h:64
HeapTupleHeader t_data
Definition: htup.h:68
Oid t_tableOid
Definition: htup.h:66
Definition: c.h:641
#define ReleaseTupleDesc(tupdesc)
Definition: tupdesc.h:122
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
TupleDesc lookup_rowtype_tupdesc(Oid type_id, int32 typmod)
Definition: typcache.c:1920
#define VARATT_IS_EXTERNAL_ONDISK(PTR)
Definition: varatt.h:290
#define VARATT_IS_EXTERNAL_INDIRECT(PTR)
Definition: varatt.h:292
#define VARSIZE_ANY(PTR)
Definition: varatt.h:311
#define SET_VARTAG_EXTERNAL(PTR, tag)
Definition: varatt.h:309
#define VARDATA_EXTERNAL(PTR)
Definition: varatt.h:286
@ VARTAG_INDIRECT
Definition: varatt.h:86

References attlen, attstorage, DatumGetPointer(), detoast_external_attr(), heap_deform_tuple(), heap_form_tuple(), HeapTupleHeaderGetDatumLength, HeapTupleHeaderGetTypeId, HeapTupleHeaderGetTypMod, i, INDIRECT_POINTER_SIZE, InvalidOid, ItemPointerSetInvalid(), lookup_rowtype_tupdesc(), MemoryContextSwitchTo(), TupleDescData::natts, palloc(), palloc0(), pfree(), PG_GETARG_HEAPTUPLEHEADER, PG_RETURN_POINTER, varatt_indirect::pointer, PointerGetDatum(), 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.

◆ overpaid()

Datum overpaid ( PG_FUNCTION_ARGS  )

Definition at line 140 of file regress.c.

141 {
143  bool isnull;
144  int32 salary;
145 
146  salary = DatumGetInt32(GetAttributeByName(tuple, "salary", &isnull));
147  if (isnull)
148  PG_RETURN_NULL();
149  PG_RETURN_BOOL(salary > 699);
150 }
Datum GetAttributeByName(HeapTupleHeader tuple, const char *attname, bool *isNull)
Definition: execUtils.c:997
static int32 DatumGetInt32(Datum X)
Definition: postgres.h:202

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

◆ PG_FUNCTION_INFO_V1() [1/22]

PG_FUNCTION_INFO_V1 ( binary_coercible  )

◆ PG_FUNCTION_INFO_V1() [2/22]

PG_FUNCTION_INFO_V1 ( get_environ  )

◆ PG_FUNCTION_INFO_V1() [3/22]

PG_FUNCTION_INFO_V1 ( int44in  )

◆ PG_FUNCTION_INFO_V1() [4/22]

PG_FUNCTION_INFO_V1 ( int44out  )

◆ PG_FUNCTION_INFO_V1() [5/22]

PG_FUNCTION_INFO_V1 ( interpt_pp  )

◆ PG_FUNCTION_INFO_V1() [6/22]

PG_FUNCTION_INFO_V1 ( make_tuple_indirect  )

◆ PG_FUNCTION_INFO_V1() [7/22]

PG_FUNCTION_INFO_V1 ( overpaid  )

◆ PG_FUNCTION_INFO_V1() [8/22]

PG_FUNCTION_INFO_V1 ( pt_in_widget  )

◆ PG_FUNCTION_INFO_V1() [9/22]

PG_FUNCTION_INFO_V1 ( regress_setenv  )

◆ PG_FUNCTION_INFO_V1() [10/22]

PG_FUNCTION_INFO_V1 ( reverse_name  )

◆ PG_FUNCTION_INFO_V1() [11/22]

PG_FUNCTION_INFO_V1 ( set_ttdummy  )

◆ PG_FUNCTION_INFO_V1() [12/22]

PG_FUNCTION_INFO_V1 ( test_atomic_ops  )

◆ PG_FUNCTION_INFO_V1() [13/22]

PG_FUNCTION_INFO_V1 ( test_canonicalize_path  )

◆ PG_FUNCTION_INFO_V1() [14/22]

PG_FUNCTION_INFO_V1 ( test_enc_conversion  )

◆ PG_FUNCTION_INFO_V1() [15/22]

PG_FUNCTION_INFO_V1 ( test_fdw_handler  )

◆ PG_FUNCTION_INFO_V1() [16/22]

PG_FUNCTION_INFO_V1 ( test_opclass_options_func  )

◆ PG_FUNCTION_INFO_V1() [17/22]

PG_FUNCTION_INFO_V1 ( test_support_func  )

◆ PG_FUNCTION_INFO_V1() [18/22]

PG_FUNCTION_INFO_V1 ( trigger_return_old  )

◆ PG_FUNCTION_INFO_V1() [19/22]

PG_FUNCTION_INFO_V1 ( ttdummy  )

◆ PG_FUNCTION_INFO_V1() [20/22]

PG_FUNCTION_INFO_V1 ( wait_pid  )

◆ PG_FUNCTION_INFO_V1() [21/22]

PG_FUNCTION_INFO_V1 ( widget_in  )

◆ PG_FUNCTION_INFO_V1() [22/22]

PG_FUNCTION_INFO_V1 ( widget_out  )

◆ pt_in_widget()

Datum pt_in_widget ( PG_FUNCTION_ARGS  )

Definition at line 215 of file regress.c.

216 {
217  Point *point = PG_GETARG_POINT_P(0);
218  WIDGET *widget = (WIDGET *) PG_GETARG_POINTER(1);
219  float8 distance;
220 
222  PointPGetDatum(point),
223  PointPGetDatum(&widget->center)));
224 
225  PG_RETURN_BOOL(distance < widget->radius);
226 }
double float8
Definition: c.h:584
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:185
static Datum PointPGetDatum(const Point *X)
Definition: geo_decls.h:181
Datum point_distance(PG_FUNCTION_ARGS)
Definition: geo_ops.c:1993
static float8 DatumGetFloat8(Datum X)
Definition: postgres.h:494
Point center
Definition: regress.c:159

References WIDGET::center, DatumGetFloat8(), DirectFunctionCall2, PG_GETARG_POINT_P, PG_GETARG_POINTER, PG_RETURN_BOOL, point_distance(), and PointPGetDatum().

◆ regress_lseg_construct()

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

Definition at line 129 of file regress.c.

130 {
131  lseg->p[0].x = pt1->x;
132  lseg->p[0].y = pt1->y;
133  lseg->p[1].x = pt2->x;
134  lseg->p[1].y = pt2->y;
135 }
Point p[2]
Definition: geo_decls.h:108
float8 y
Definition: geo_decls.h:99
float8 x
Definition: geo_decls.h:98

References LSEG::p, Point::x, and Point::y.

Referenced by interpt_pp().

◆ regress_setenv()

Datum regress_setenv ( PG_FUNCTION_ARGS  )

Definition at line 671 of file regress.c.

672 {
673  char *envvar = text_to_cstring(PG_GETARG_TEXT_PP(0));
674  char *envval = text_to_cstring(PG_GETARG_TEXT_PP(1));
675 
676  if (!superuser())
677  elog(ERROR, "must be superuser to change environment variables");
678 
679  if (setenv(envvar, envval, 1) != 0)
680  elog(ERROR, "could not set environment variable: %m");
681 
682  PG_RETURN_VOID();
683 }
#define elog(elevel,...)
Definition: elog.h:225
#define PG_RETURN_VOID()
Definition: fmgr.h:349
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:309
bool superuser(void)
Definition: superuser.c:46
char * text_to_cstring(const text *t)
Definition: varlena.c:217
#define setenv(x, y, z)
Definition: win32_port.h:555

References elog, ERROR, PG_GETARG_TEXT_PP, PG_RETURN_VOID, setenv, superuser(), and text_to_cstring().

◆ reverse_name()

Datum reverse_name ( PG_FUNCTION_ARGS  )

Definition at line 231 of file regress.c.

232 {
233  char *string = PG_GETARG_CSTRING(0);
234  int i;
235  int len;
236  char *new_string;
237 
238  new_string = palloc0(NAMEDATALEN);
239  for (i = 0; i < NAMEDATALEN && string[i]; ++i)
240  ;
241  if (i == NAMEDATALEN || !string[i])
242  --i;
243  len = i;
244  for (; i >= 0; --i)
245  new_string[len - i] = string[i];
246  PG_RETURN_CSTRING(new_string);
247 }
#define NAMEDATALEN
const void size_t len

References i, len, NAMEDATALEN, palloc0(), PG_GETARG_CSTRING, and PG_RETURN_CSTRING.

◆ set_ttdummy()

Datum set_ttdummy ( PG_FUNCTION_ARGS  )

Definition at line 461 of file regress.c.

462 {
463  int32 on = PG_GETARG_INT32(0);
464 
465  if (ttoff) /* OFF currently */
466  {
467  if (on == 0)
468  PG_RETURN_INT32(0);
469 
470  /* turn ON */
471  ttoff = false;
472  PG_RETURN_INT32(0);
473  }
474 
475  /* ON currently */
476  if (on != 0)
477  PG_RETURN_INT32(1);
478 
479  /* turn OFF */
480  ttoff = true;
481 
482  PG_RETURN_INT32(1);
483 }
#define PG_RETURN_INT32(x)
Definition: fmgr.h:354
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
static bool ttoff
Definition: regress.c:268

References PG_GETARG_INT32, PG_RETURN_INT32, and ttoff.

◆ test_atomic_flag()

static void test_atomic_flag ( void  )
static

Definition at line 709 of file regress.c.

710 {
711  pg_atomic_flag flag;
712 
722 }
static void pg_atomic_clear_flag(volatile pg_atomic_flag *ptr)
Definition: atomics.h:207
static bool pg_atomic_test_set_flag(volatile pg_atomic_flag *ptr)
Definition: atomics.h:183
static bool pg_atomic_unlocked_test_flag(volatile pg_atomic_flag *ptr)
Definition: atomics.h:196
static void pg_atomic_init_flag(volatile pg_atomic_flag *ptr)
Definition: atomics.h:170
#define EXPECT_TRUE(expr)
Definition: regress.c:47
char * flag(int b)
Definition: test-ctype.c:33

References EXPECT_TRUE, 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().

◆ test_atomic_ops()

Datum test_atomic_ops ( PG_FUNCTION_ARGS  )

Definition at line 914 of file regress.c.

915 {
917 
919 
921 
922  /*
923  * Arguably this shouldn't be tested as part of this function, but it's
924  * closely enough related that that seems ok for now.
925  */
926  test_spinlock();
927 
928  PG_RETURN_BOOL(true);
929 }
static void test_spinlock(void)
Definition: regress.c:850
static void test_atomic_uint32(void)
Definition: regress.c:725
static void test_atomic_flag(void)
Definition: regress.c:709
static void test_atomic_uint64(void)
Definition: regress.c:797

References PG_RETURN_BOOL, test_atomic_flag(), test_atomic_uint32(), test_atomic_uint64(), and test_spinlock().

◆ test_atomic_uint32()

static void test_atomic_uint32 ( void  )
static

Definition at line 725 of file regress.c.

726 {
727  pg_atomic_uint32 var;
728  uint32 expected;
729  int i;
730 
731  pg_atomic_init_u32(&var, 0);
733  pg_atomic_write_u32(&var, 3);
736  3);
739  EXPECT_EQ_U32(pg_atomic_add_fetch_u32(&var, 10), 10);
742 
743  /* test around numerical limits */
744  EXPECT_EQ_U32(pg_atomic_fetch_add_u32(&var, INT_MAX), 0);
745  EXPECT_EQ_U32(pg_atomic_fetch_add_u32(&var, INT_MAX), INT_MAX);
746  pg_atomic_fetch_add_u32(&var, 2); /* wrap to 0 */
749  PG_INT16_MAX);
751  2 * PG_INT16_MAX + 1);
753  PG_INT16_MAX);
754  pg_atomic_fetch_add_u32(&var, 1); /* top up to UINT_MAX */
755  EXPECT_EQ_U32(pg_atomic_read_u32(&var), UINT_MAX);
756  EXPECT_EQ_U32(pg_atomic_fetch_sub_u32(&var, INT_MAX), UINT_MAX);
757  EXPECT_EQ_U32(pg_atomic_read_u32(&var), (uint32) INT_MAX + 1);
758  EXPECT_EQ_U32(pg_atomic_sub_fetch_u32(&var, INT_MAX), 1);
759  pg_atomic_sub_fetch_u32(&var, 1);
760  expected = PG_INT16_MAX;
761  EXPECT_TRUE(!pg_atomic_compare_exchange_u32(&var, &expected, 1));
762  expected = PG_INT16_MAX + 1;
763  EXPECT_TRUE(!pg_atomic_compare_exchange_u32(&var, &expected, 1));
764  expected = PG_INT16_MIN;
765  EXPECT_TRUE(!pg_atomic_compare_exchange_u32(&var, &expected, 1));
766  expected = PG_INT16_MIN - 1;
767  EXPECT_TRUE(!pg_atomic_compare_exchange_u32(&var, &expected, 1));
768 
769  /* fail exchange because of old expected */
770  expected = 10;
771  EXPECT_TRUE(!pg_atomic_compare_exchange_u32(&var, &expected, 1));
772 
773  /* CAS is allowed to fail due to interrupts, try a couple of times */
774  for (i = 0; i < 1000; i++)
775  {
776  expected = 0;
777  if (!pg_atomic_compare_exchange_u32(&var, &expected, 1))
778  break;
779  }
780  if (i == 1000)
781  elog(ERROR, "atomic_compare_exchange_u32() never succeeded");
783  pg_atomic_write_u32(&var, 0);
784 
785  /* try setting flagbits */
786  EXPECT_TRUE(!(pg_atomic_fetch_or_u32(&var, 1) & 1));
787  EXPECT_TRUE(pg_atomic_fetch_or_u32(&var, 2) & 1);
789  /* try clearing flagbits */
790  EXPECT_EQ_U32(pg_atomic_fetch_and_u32(&var, ~2) & 3, 3);
792  /* no bits set anymore */
794 }
static uint32 pg_atomic_fetch_and_u32(volatile pg_atomic_uint32 *ptr, uint32 and_)
Definition: atomics.h:396
static bool pg_atomic_compare_exchange_u32(volatile pg_atomic_uint32 *ptr, uint32 *expected, uint32 newval)
Definition: atomics.h:349
static uint32 pg_atomic_fetch_or_u32(volatile pg_atomic_uint32 *ptr, uint32 or_)
Definition: atomics.h:410
static uint32 pg_atomic_sub_fetch_u32(volatile pg_atomic_uint32 *ptr, int32 sub_)
Definition: atomics.h:439
static uint32 pg_atomic_fetch_sub_u32(volatile pg_atomic_uint32 *ptr, int32 sub_)
Definition: atomics.h:381
static void pg_atomic_init_u32(volatile pg_atomic_uint32 *ptr, uint32 val)
Definition: atomics.h:221
static uint32 pg_atomic_fetch_add_u32(volatile pg_atomic_uint32 *ptr, int32 add_)
Definition: atomics.h:366
static uint32 pg_atomic_add_fetch_u32(volatile pg_atomic_uint32 *ptr, int32 add_)
Definition: atomics.h:424
static void pg_atomic_write_u32(volatile pg_atomic_uint32 *ptr, uint32 val)
Definition: atomics.h:276
static uint32 pg_atomic_read_u32(volatile pg_atomic_uint32 *ptr)
Definition: atomics.h:239
static uint32 pg_atomic_exchange_u32(volatile pg_atomic_uint32 *ptr, uint32 newval)
Definition: atomics.h:330
#define PG_INT16_MIN
Definition: c.h:539
uint32_t uint32
Definition: c.h:485
#define PG_INT16_MAX
Definition: c.h:540
#define EXPECT_EQ_U32(result_expr, expected_expr)
Definition: regress.c:55

References elog, ERROR, EXPECT_EQ_U32, EXPECT_TRUE, 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(), pg_atomic_write_u32(), PG_INT16_MAX, and PG_INT16_MIN.

Referenced by test_atomic_ops().

◆ test_atomic_uint64()

static void test_atomic_uint64 ( void  )
static

Definition at line 797 of file regress.c.

798 {
799  pg_atomic_uint64 var;
800  uint64 expected;
801  int i;
802 
803  pg_atomic_init_u64(&var, 0);
805  pg_atomic_write_u64(&var, 3);
808  3);
811  EXPECT_EQ_U64(pg_atomic_add_fetch_u64(&var, 10), 10);
814 
815  /* fail exchange because of old expected */
816  expected = 10;
817  EXPECT_TRUE(!pg_atomic_compare_exchange_u64(&var, &expected, 1));
818 
819  /* CAS is allowed to fail due to interrupts, try a couple of times */
820  for (i = 0; i < 100; i++)
821  {
822  expected = 0;
823  if (!pg_atomic_compare_exchange_u64(&var, &expected, 1))
824  break;
825  }
826  if (i == 100)
827  elog(ERROR, "atomic_compare_exchange_u64() never succeeded");
829 
830  pg_atomic_write_u64(&var, 0);
831 
832  /* try setting flagbits */
833  EXPECT_TRUE(!(pg_atomic_fetch_or_u64(&var, 1) & 1));
834  EXPECT_TRUE(pg_atomic_fetch_or_u64(&var, 2) & 1);
836  /* try clearing flagbits */
837  EXPECT_EQ_U64((pg_atomic_fetch_and_u64(&var, ~2) & 3), 3);
839  /* no bits set anymore */
841 }
static void pg_atomic_write_u64(volatile pg_atomic_uint64 *ptr, uint64 val)
Definition: atomics.h:485
static bool pg_atomic_compare_exchange_u64(volatile pg_atomic_uint64 *ptr, uint64 *expected, uint64 newval)
Definition: atomics.h:512
static uint64 pg_atomic_fetch_add_u64(volatile pg_atomic_uint64 *ptr, int64 add_)
Definition: atomics.h:522
static uint64 pg_atomic_sub_fetch_u64(volatile pg_atomic_uint64 *ptr, int64 sub_)
Definition: atomics.h:568
static uint64 pg_atomic_fetch_and_u64(volatile pg_atomic_uint64 *ptr, uint64 and_)
Definition: atomics.h:541
static uint64 pg_atomic_fetch_or_u64(volatile pg_atomic_uint64 *ptr, uint64 or_)
Definition: atomics.h:550
static uint64 pg_atomic_add_fetch_u64(volatile pg_atomic_uint64 *ptr, int64 add_)
Definition: atomics.h:559
static void pg_atomic_init_u64(volatile pg_atomic_uint64 *ptr, uint64 val)
Definition: atomics.h:453
static uint64 pg_atomic_read_u64(volatile pg_atomic_uint64 *ptr)
Definition: atomics.h:467
static uint64 pg_atomic_fetch_sub_u64(volatile pg_atomic_uint64 *ptr, int64 sub_)
Definition: atomics.h:531
static uint64 pg_atomic_exchange_u64(volatile pg_atomic_uint64 *ptr, uint64 newval)
Definition: atomics.h:503
uint64_t uint64
Definition: c.h:486
#define EXPECT_EQ_U64(result_expr, expected_expr)
Definition: regress.c:65

References elog, ERROR, EXPECT_EQ_U64, EXPECT_TRUE, 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(), and pg_atomic_write_u64().

Referenced by test_atomic_ops().

◆ test_canonicalize_path()

Datum test_canonicalize_path ( PG_FUNCTION_ARGS  )

Definition at line 539 of file regress.c.

540 {
541  char *path = text_to_cstring(PG_GETARG_TEXT_PP(0));
542 
543  canonicalize_path(path);
545 }
#define PG_RETURN_TEXT_P(x)
Definition: fmgr.h:372
void canonicalize_path(char *path)
Definition: path.c:265
text * cstring_to_text(const char *s)
Definition: varlena.c:184

References canonicalize_path(), cstring_to_text(), PG_GETARG_TEXT_PP, PG_RETURN_TEXT_P, and text_to_cstring().

◆ test_enc_conversion()

Datum test_enc_conversion ( PG_FUNCTION_ARGS  )

Definition at line 1035 of file regress.c.

1036 {
1037  bytea *string = PG_GETARG_BYTEA_PP(0);
1038  char *src_encoding_name = NameStr(*PG_GETARG_NAME(1));
1039  int src_encoding = pg_char_to_encoding(src_encoding_name);
1040  char *dest_encoding_name = NameStr(*PG_GETARG_NAME(2));
1041  int dest_encoding = pg_char_to_encoding(dest_encoding_name);
1042  bool noError = PG_GETARG_BOOL(3);
1043  TupleDesc tupdesc;
1044  char *src;
1045  char *dst;
1046  bytea *retval;
1047  Size srclen;
1048  Size dstsize;
1049  Oid proc;
1050  int convertedbytes;
1051  int dstlen;
1052  Datum values[2];
1053  bool nulls[2] = {0};
1054  HeapTuple tuple;
1055 
1056  if (src_encoding < 0)
1057  ereport(ERROR,
1058  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1059  errmsg("invalid source encoding name \"%s\"",
1060  src_encoding_name)));
1061  if (dest_encoding < 0)
1062  ereport(ERROR,
1063  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1064  errmsg("invalid destination encoding name \"%s\"",
1065  dest_encoding_name)));
1066 
1067  /* Build a tuple descriptor for our result type */
1068  if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
1069  elog(ERROR, "return type must be a row type");
1070  tupdesc = BlessTupleDesc(tupdesc);
1071 
1072  srclen = VARSIZE_ANY_EXHDR(string);
1073  src = VARDATA_ANY(string);
1074 
1075  if (src_encoding == dest_encoding)
1076  {
1077  /* just check that the source string is valid */
1078  int oklen;
1079 
1080  oklen = pg_encoding_verifymbstr(src_encoding, src, srclen);
1081 
1082  if (oklen == srclen)
1083  {
1084  convertedbytes = oklen;
1085  retval = string;
1086  }
1087  else if (!noError)
1088  {
1089  report_invalid_encoding(src_encoding, src + oklen, srclen - oklen);
1090  }
1091  else
1092  {
1093  /*
1094  * build bytea data type structure.
1095  */
1096  Assert(oklen < srclen);
1097  convertedbytes = oklen;
1098  retval = (bytea *) palloc(oklen + VARHDRSZ);
1099  SET_VARSIZE(retval, oklen + VARHDRSZ);
1100  memcpy(VARDATA(retval), src, oklen);
1101  }
1102  }
1103  else
1104  {
1105  proc = FindDefaultConversionProc(src_encoding, dest_encoding);
1106  if (!OidIsValid(proc))
1107  ereport(ERROR,
1108  (errcode(ERRCODE_UNDEFINED_FUNCTION),
1109  errmsg("default conversion function for encoding \"%s\" to \"%s\" does not exist",
1110  pg_encoding_to_char(src_encoding),
1111  pg_encoding_to_char(dest_encoding))));
1112 
1113  if (srclen >= (MaxAllocSize / (Size) MAX_CONVERSION_GROWTH))
1114  ereport(ERROR,
1115  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
1116  errmsg("out of memory"),
1117  errdetail("String of %d bytes is too long for encoding conversion.",
1118  (int) srclen)));
1119 
1120  dstsize = (Size) srclen * MAX_CONVERSION_GROWTH + 1;
1121  dst = MemoryContextAlloc(CurrentMemoryContext, dstsize);
1122 
1123  /* perform conversion */
1124  convertedbytes = pg_do_encoding_conversion_buf(proc,
1125  src_encoding,
1126  dest_encoding,
1127  (unsigned char *) src, srclen,
1128  (unsigned char *) dst, dstsize,
1129  noError);
1130  dstlen = strlen(dst);
1131 
1132  /*
1133  * build bytea data type structure.
1134  */
1135  retval = (bytea *) palloc(dstlen + VARHDRSZ);
1136  SET_VARSIZE(retval, dstlen + VARHDRSZ);
1137  memcpy(VARDATA(retval), dst, dstlen);
1138 
1139  pfree(dst);
1140  }
1141 
1142  values[0] = Int32GetDatum(convertedbytes);
1143  values[1] = PointerGetDatum(retval);
1144  tuple = heap_form_tuple(tupdesc, values, nulls);
1145 
1147 }
#define NameStr(name)
Definition: c.h:700
#define VARHDRSZ
Definition: c.h:646
#define Assert(condition)
Definition: c.h:812
#define OidIsValid(objectId)
Definition: c.h:729
size_t Size
Definition: c.h:559
int errdetail(const char *fmt,...)
Definition: elog.c:1203
int errcode(int sqlerrcode)
Definition: elog.c:853
int errmsg(const char *fmt,...)
Definition: elog.c:1070
#define ereport(elevel,...)
Definition: elog.h:149
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:2158
#define MaxAllocSize
Definition: fe_memutils.h:22
#define PG_GETARG_BYTEA_PP(n)
Definition: fmgr.h:308
#define PG_GETARG_NAME(n)
Definition: fmgr.h:278
#define PG_GETARG_BOOL(n)
Definition: fmgr.h:274
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
Definition: funcapi.c:276
@ TYPEFUNC_COMPOSITE
Definition: funcapi.h:149
static Datum HeapTupleGetDatum(const HeapTupleData *tuple)
Definition: funcapi.h:230
int pg_do_encoding_conversion_buf(Oid proc, int src_encoding, int dest_encoding, unsigned char *src, int srclen, unsigned char *dest, int destlen, bool noError)
Definition: mbutils.c:469
void report_invalid_encoding(int encoding, const char *mbstr, int len)
Definition: mbutils.c:1698
MemoryContext CurrentMemoryContext
Definition: mcxt.c:143
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:1181
Oid FindDefaultConversionProc(int32 for_encoding, int32 to_encoding)
Definition: namespace.c:4080
#define MAX_CONVERSION_GROWTH
Definition: pg_wchar.h:302
#define pg_encoding_to_char
Definition: pg_wchar.h:630
#define pg_char_to_encoding
Definition: pg_wchar.h:629
static Datum Int32GetDatum(int32 X)
Definition: postgres.h:212
char string[11]
Definition: preproc-type.c:52
#define VARDATA(PTR)
Definition: varatt.h:278
#define VARDATA_ANY(PTR)
Definition: varatt.h:324
#define SET_VARSIZE(PTR, len)
Definition: varatt.h:305
#define VARSIZE_ANY_EXHDR(PTR)
Definition: varatt.h:317
int pg_encoding_verifymbstr(int encoding, const char *mbstr, int len)
Definition: wchar.c:2116

References Assert, BlessTupleDesc(), CurrentMemoryContext, elog, ereport, errcode(), errdetail(), errmsg(), ERROR, FindDefaultConversionProc(), get_call_result_type(), heap_form_tuple(), HeapTupleGetDatum(), Int32GetDatum(), MAX_CONVERSION_GROWTH, MaxAllocSize, MemoryContextAlloc(), NameStr, OidIsValid, palloc(), pfree(), pg_char_to_encoding, pg_do_encoding_conversion_buf(), pg_encoding_to_char, pg_encoding_verifymbstr(), PG_GETARG_BOOL, PG_GETARG_BYTEA_PP, PG_GETARG_NAME, PG_RETURN_DATUM, PointerGetDatum(), report_invalid_encoding(), SET_VARSIZE, TYPEFUNC_COMPOSITE, values, VARDATA, VARDATA_ANY, VARHDRSZ, and VARSIZE_ANY_EXHDR.

◆ test_fdw_handler()

Datum test_fdw_handler ( PG_FUNCTION_ARGS  )

Definition at line 933 of file regress.c.

934 {
935  elog(ERROR, "test_fdw_handler is not implemented");
936  PG_RETURN_NULL();
937 }

References elog, ERROR, and PG_RETURN_NULL.

◆ test_opclass_options_func()

Datum test_opclass_options_func ( PG_FUNCTION_ARGS  )

Definition at line 1014 of file regress.c.

1015 {
1016  PG_RETURN_NULL();
1017 }

References PG_RETURN_NULL.

◆ test_spinlock()

static void test_spinlock ( void  )
static

Definition at line 850 of file regress.c.

851 {
852  /*
853  * Basic tests for spinlocks, as well as the underlying operations.
854  *
855  * We embed the spinlock in a struct with other members to test that the
856  * spinlock operations don't perform too wide writes.
857  */
858  {
859  struct test_lock_struct
860  {
861  char data_before[4];
862  slock_t lock;
863  char data_after[4];
864  } struct_w_lock;
865 
866  memcpy(struct_w_lock.data_before, "abcd", 4);
867  memcpy(struct_w_lock.data_after, "ef12", 4);
868 
869  /* test basic operations via the SpinLock* API */
870  SpinLockInit(&struct_w_lock.lock);
871  SpinLockAcquire(&struct_w_lock.lock);
872  SpinLockRelease(&struct_w_lock.lock);
873 
874  /* test basic operations via underlying S_* API */
875  S_INIT_LOCK(&struct_w_lock.lock);
876  S_LOCK(&struct_w_lock.lock);
877  S_UNLOCK(&struct_w_lock.lock);
878 
879  /* and that "contended" acquisition works */
880  s_lock(&struct_w_lock.lock, "testfile", 17, "testfunc");
881  S_UNLOCK(&struct_w_lock.lock);
882 
883  /*
884  * Check, using TAS directly, that a single spin cycle doesn't block
885  * when acquiring an already acquired lock.
886  */
887 #ifdef TAS
888  S_LOCK(&struct_w_lock.lock);
889 
890  if (!TAS(&struct_w_lock.lock))
891  elog(ERROR, "acquired already held spinlock");
892 
893 #ifdef TAS_SPIN
894  if (!TAS_SPIN(&struct_w_lock.lock))
895  elog(ERROR, "acquired already held spinlock");
896 #endif /* defined(TAS_SPIN) */
897 
898  S_UNLOCK(&struct_w_lock.lock);
899 #endif /* defined(TAS) */
900 
901  /*
902  * Verify that after all of this the non-lock contents are still
903  * correct.
904  */
905  if (memcmp(struct_w_lock.data_before, "abcd", 4) != 0)
906  elog(ERROR, "padding before spinlock modified");
907  if (memcmp(struct_w_lock.data_after, "ef12", 4) != 0)
908  elog(ERROR, "padding after spinlock modified");
909  }
910 }
int s_lock(volatile slock_t *lock, const char *file, int line, const char *func)
Definition: s_lock.c:98
#define TAS(lock)
Definition: s_lock.h:700
#define S_UNLOCK(lock)
Definition: s_lock.h:685
#define TAS_SPIN(lock)
Definition: s_lock.h:704
#define S_INIT_LOCK(lock)
Definition: s_lock.h:689
#define S_LOCK(lock)
Definition: s_lock.h:658
#define SpinLockInit(lock)
Definition: spin.h:57
#define SpinLockRelease(lock)
Definition: spin.h:61
#define SpinLockAcquire(lock)
Definition: spin.h:59

References elog, ERROR, S_INIT_LOCK, S_LOCK, s_lock(), S_UNLOCK, SpinLockAcquire, SpinLockInit, SpinLockRelease, TAS, and TAS_SPIN.

Referenced by test_atomic_ops().

◆ test_support_func()

Datum test_support_func ( PG_FUNCTION_ARGS  )

Definition at line 941 of file regress.c.

942 {
943  Node *rawreq = (Node *) PG_GETARG_POINTER(0);
944  Node *ret = NULL;
945 
946  if (IsA(rawreq, SupportRequestSelectivity))
947  {
948  /*
949  * Assume that the target is int4eq; that's safe as long as we don't
950  * attach this to any other boolean-returning function.
951  */
953  Selectivity s1;
954 
955  if (req->is_join)
956  s1 = join_selectivity(req->root, Int4EqualOperator,
957  req->args,
958  req->inputcollid,
959  req->jointype,
960  req->sjinfo);
961  else
962  s1 = restriction_selectivity(req->root, Int4EqualOperator,
963  req->args,
964  req->inputcollid,
965  req->varRelid);
966 
967  req->selectivity = s1;
968  ret = (Node *) req;
969  }
970 
971  if (IsA(rawreq, SupportRequestCost))
972  {
973  /* Provide some generic estimate */
974  SupportRequestCost *req = (SupportRequestCost *) rawreq;
975 
976  req->startup = 0;
977  req->per_tuple = 2 * cpu_operator_cost;
978  ret = (Node *) req;
979  }
980 
981  if (IsA(rawreq, SupportRequestRows))
982  {
983  /*
984  * Assume that the target is generate_series_int4; that's safe as long
985  * as we don't attach this to any other set-returning function.
986  */
987  SupportRequestRows *req = (SupportRequestRows *) rawreq;
988 
989  if (req->node && IsA(req->node, FuncExpr)) /* be paranoid */
990  {
991  List *args = ((FuncExpr *) req->node)->args;
992  Node *arg1 = linitial(args);
993  Node *arg2 = lsecond(args);
994 
995  if (IsA(arg1, Const) &&
996  !((Const *) arg1)->constisnull &&
997  IsA(arg2, Const) &&
998  !((Const *) arg2)->constisnull)
999  {
1000  int32 val1 = DatumGetInt32(((Const *) arg1)->constvalue);
1001  int32 val2 = DatumGetInt32(((Const *) arg2)->constvalue);
1002 
1003  req->rows = val2 - val1 + 1;
1004  ret = (Node *) req;
1005  }
1006  }
1007  }
1008 
1009  PG_RETURN_POINTER(ret);
1010 }
double cpu_operator_cost
Definition: costsize.c:134
#define IsA(nodeptr, _type_)
Definition: nodes.h:158
double Selectivity
Definition: nodes.h:250
#define linitial(l)
Definition: pg_list.h:178
#define lsecond(l)
Definition: pg_list.h:183
Selectivity restriction_selectivity(PlannerInfo *root, Oid operatorid, List *args, Oid inputcollid, int varRelid)
Definition: plancat.c:1955
Selectivity join_selectivity(PlannerInfo *root, Oid operatorid, List *args, Oid inputcollid, JoinType jointype, SpecialJoinInfo *sjinfo)
Definition: plancat.c:1994
char * s1
Definition: pg_list.h:54
Definition: nodes.h:129
struct PlannerInfo * root
Definition: supportnodes.h:96
struct SpecialJoinInfo * sjinfo
Definition: supportnodes.h:103

References generate_unaccent_rules::args, SupportRequestSelectivity::args, cpu_operator_cost, DatumGetInt32(), SupportRequestSelectivity::inputcollid, SupportRequestSelectivity::is_join, IsA, join_selectivity(), SupportRequestSelectivity::jointype, linitial, lsecond, SupportRequestRows::node, SupportRequestCost::per_tuple, PG_GETARG_POINTER, PG_RETURN_POINTER, restriction_selectivity(), SupportRequestSelectivity::root, SupportRequestRows::rows, s1, SupportRequestSelectivity::selectivity, SupportRequestSelectivity::sjinfo, SupportRequestCost::startup, and SupportRequestSelectivity::varRelid.

◆ trigger_return_old()

Datum trigger_return_old ( PG_FUNCTION_ARGS  )

Definition at line 252 of file regress.c.

253 {
254  TriggerData *trigdata = (TriggerData *) fcinfo->context;
255  HeapTuple tuple;
256 
257  if (!CALLED_AS_TRIGGER(fcinfo))
258  elog(ERROR, "trigger_return_old: not fired by trigger manager");
259 
260  tuple = trigdata->tg_trigtuple;
261 
262  return PointerGetDatum(tuple);
263 }
if(TABLE==NULL||TABLE_index==NULL)
Definition: isn.c:76
HeapTuple tg_trigtuple
Definition: trigger.h:36
#define CALLED_AS_TRIGGER(fcinfo)
Definition: trigger.h:26

References CALLED_AS_TRIGGER, elog, ERROR, if(), PointerGetDatum(), and TriggerData::tg_trigtuple.

◆ ttdummy()

Datum ttdummy ( PG_FUNCTION_ARGS  )

Definition at line 273 of file regress.c.

274 {
275  TriggerData *trigdata = (TriggerData *) fcinfo->context;
276  Trigger *trigger; /* to get trigger name */
277  char **args; /* arguments */
278  int attnum[2]; /* fnumbers of start/stop columns */
279  Datum oldon,
280  oldoff;
281  Datum newon,
282  newoff;
283  Datum *cvals; /* column values */
284  char *cnulls; /* column nulls */
285  char *relname; /* triggered relation name */
286  Relation rel; /* triggered relation */
287  HeapTuple trigtuple;
288  HeapTuple newtuple = NULL;
289  HeapTuple rettuple;
290  TupleDesc tupdesc; /* tuple description */
291  int natts; /* # of attributes */
292  bool isnull; /* to know is some column NULL or not */
293  int ret;
294  int i;
295 
296  if (!CALLED_AS_TRIGGER(fcinfo))
297  elog(ERROR, "ttdummy: not fired by trigger manager");
298  if (!TRIGGER_FIRED_FOR_ROW(trigdata->tg_event))
299  elog(ERROR, "ttdummy: must be fired for row");
300  if (!TRIGGER_FIRED_BEFORE(trigdata->tg_event))
301  elog(ERROR, "ttdummy: must be fired before event");
302  if (TRIGGER_FIRED_BY_INSERT(trigdata->tg_event))
303  elog(ERROR, "ttdummy: cannot process INSERT event");
304  if (TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event))
305  newtuple = trigdata->tg_newtuple;
306 
307  trigtuple = trigdata->tg_trigtuple;
308 
309  rel = trigdata->tg_relation;
310  relname = SPI_getrelname(rel);
311 
312  /* check if TT is OFF for this relation */
313  if (ttoff) /* OFF - nothing to do */
314  {
315  pfree(relname);
316  return PointerGetDatum((newtuple != NULL) ? newtuple : trigtuple);
317  }
318 
319  trigger = trigdata->tg_trigger;
320 
321  if (trigger->tgnargs != 2)
322  elog(ERROR, "ttdummy (%s): invalid (!= 2) number of arguments %d",
323  relname, trigger->tgnargs);
324 
325  args = trigger->tgargs;
326  tupdesc = rel->rd_att;
327  natts = tupdesc->natts;
328 
329  for (i = 0; i < 2; i++)
330  {
331  attnum[i] = SPI_fnumber(tupdesc, args[i]);
332  if (attnum[i] <= 0)
333  elog(ERROR, "ttdummy (%s): there is no attribute %s",
334  relname, args[i]);
335  if (SPI_gettypeid(tupdesc, attnum[i]) != INT4OID)
336  elog(ERROR, "ttdummy (%s): attribute %s must be of integer type",
337  relname, args[i]);
338  }
339 
340  oldon = SPI_getbinval(trigtuple, tupdesc, attnum[0], &isnull);
341  if (isnull)
342  elog(ERROR, "ttdummy (%s): %s must be NOT NULL", relname, args[0]);
343 
344  oldoff = SPI_getbinval(trigtuple, tupdesc, attnum[1], &isnull);
345  if (isnull)
346  elog(ERROR, "ttdummy (%s): %s must be NOT NULL", relname, args[1]);
347 
348  if (newtuple != NULL) /* UPDATE */
349  {
350  newon = SPI_getbinval(newtuple, tupdesc, attnum[0], &isnull);
351  if (isnull)
352  elog(ERROR, "ttdummy (%s): %s must be NOT NULL", relname, args[0]);
353  newoff = SPI_getbinval(newtuple, tupdesc, attnum[1], &isnull);
354  if (isnull)
355  elog(ERROR, "ttdummy (%s): %s must be NOT NULL", relname, args[1]);
356 
357  if (oldon != newon || oldoff != newoff)
358  ereport(ERROR,
359  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
360  errmsg("ttdummy (%s): you cannot change %s and/or %s columns (use set_ttdummy)",
361  relname, args[0], args[1])));
362 
363  if (newoff != TTDUMMY_INFINITY)
364  {
365  pfree(relname); /* allocated in upper executor context */
366  return PointerGetDatum(NULL);
367  }
368  }
369  else if (oldoff != TTDUMMY_INFINITY) /* DELETE */
370  {
371  pfree(relname);
372  return PointerGetDatum(NULL);
373  }
374 
375  newoff = DirectFunctionCall1(nextval, CStringGetTextDatum("ttdummy_seq"));
376  /* nextval now returns int64; coerce down to int32 */
377  newoff = Int32GetDatum((int32) DatumGetInt64(newoff));
378 
379  /* Connect to SPI manager */
380  SPI_connect();
381 
382  /* Fetch tuple values and nulls */
383  cvals = (Datum *) palloc(natts * sizeof(Datum));
384  cnulls = (char *) palloc(natts * sizeof(char));
385  for (i = 0; i < natts; i++)
386  {
387  cvals[i] = SPI_getbinval((newtuple != NULL) ? newtuple : trigtuple,
388  tupdesc, i + 1, &isnull);
389  cnulls[i] = (isnull) ? 'n' : ' ';
390  }
391 
392  /* change date column(s) */
393  if (newtuple) /* UPDATE */
394  {
395  cvals[attnum[0] - 1] = newoff; /* start_date eq current date */
396  cnulls[attnum[0] - 1] = ' ';
397  cvals[attnum[1] - 1] = TTDUMMY_INFINITY; /* stop_date eq INFINITY */
398  cnulls[attnum[1] - 1] = ' ';
399  }
400  else
401  /* DELETE */
402  {
403  cvals[attnum[1] - 1] = newoff; /* stop_date eq current date */
404  cnulls[attnum[1] - 1] = ' ';
405  }
406 
407  /* if there is no plan ... */
408  if (splan == NULL)
409  {
410  SPIPlanPtr pplan;
411  Oid *ctypes;
412  char *query;
413 
414  /* allocate space in preparation */
415  ctypes = (Oid *) palloc(natts * sizeof(Oid));
416  query = (char *) palloc(100 + 16 * natts);
417 
418  /*
419  * Construct query: INSERT INTO _relation_ VALUES ($1, ...)
420  */
421  sprintf(query, "INSERT INTO %s VALUES (", relname);
422  for (i = 1; i <= natts; i++)
423  {
424  sprintf(query + strlen(query), "$%d%s",
425  i, (i < natts) ? ", " : ")");
426  ctypes[i - 1] = SPI_gettypeid(tupdesc, i);
427  }
428 
429  /* Prepare plan for query */
430  pplan = SPI_prepare(query, natts, ctypes);
431  if (pplan == NULL)
432  elog(ERROR, "ttdummy (%s): SPI_prepare returned %s", relname, SPI_result_code_string(SPI_result));
433 
434  if (SPI_keepplan(pplan))
435  elog(ERROR, "ttdummy (%s): SPI_keepplan failed", relname);
436 
437  splan = pplan;
438  }
439 
440  ret = SPI_execp(splan, cvals, cnulls, 0);
441 
442  if (ret < 0)
443  elog(ERROR, "ttdummy (%s): SPI_execp returned %d", relname, ret);
444 
445  /* Tuple to return to upper Executor ... */
446  if (newtuple) /* UPDATE */
447  rettuple = SPI_modifytuple(rel, trigtuple, 1, &(attnum[1]), &newoff, NULL);
448  else /* DELETE */
449  rettuple = trigtuple;
450 
451  SPI_finish(); /* don't forget say Bye to SPI mgr */
452 
453  pfree(relname);
454 
455  return PointerGetDatum(rettuple);
456 }
Datum nextval(PG_FUNCTION_ARGS)
Definition: sequence.c:593
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:641
int16 attnum
Definition: pg_attribute.h:74
NameData relname
Definition: pg_class.h:38
#define sprintf
Definition: port.h:240
static int64 DatumGetInt64(Datum X)
Definition: postgres.h:385
static SPIPlanPtr splan
Definition: regress.c:267
#define TTDUMMY_INFINITY
Definition: regress.c:265
char * SPI_getrelname(Relation rel)
Definition: spi.c:1326
int SPI_fnumber(TupleDesc tupdesc, const char *fname)
Definition: spi.c:1175
Oid SPI_gettypeid(TupleDesc tupdesc, int fnumber)
Definition: spi.c:1308
int SPI_connect(void)
Definition: spi.c:94
int SPI_result
Definition: spi.c:46
const char * SPI_result_code_string(int code)
Definition: spi.c:1972
int SPI_finish(void)
Definition: spi.c:182
HeapTuple SPI_modifytuple(Relation rel, HeapTuple tuple, int natts, int *attnum, Datum *Values, const char *Nulls)
Definition: spi.c:1106
SPIPlanPtr SPI_prepare(const char *src, int nargs, Oid *argtypes)
Definition: spi.c:860
int SPI_keepplan(SPIPlanPtr plan)
Definition: spi.c:976
int SPI_execp(SPIPlanPtr plan, Datum *Values, const char *Nulls, long tcount)
Definition: spi.c:704
Datum SPI_getbinval(HeapTuple tuple, TupleDesc tupdesc, int fnumber, bool *isnull)
Definition: spi.c:1252
Relation tg_relation
Definition: trigger.h:35
TriggerEvent tg_event
Definition: trigger.h:34
HeapTuple tg_newtuple
Definition: trigger.h:37
Trigger * tg_trigger
Definition: trigger.h:38
#define TRIGGER_FIRED_BEFORE(event)
Definition: trigger.h:128
#define TRIGGER_FIRED_FOR_ROW(event)
Definition: trigger.h:122
#define TRIGGER_FIRED_BY_INSERT(event)
Definition: trigger.h:110
#define TRIGGER_FIRED_BY_UPDATE(event)
Definition: trigger.h:116

References generate_unaccent_rules::args, attnum, CALLED_AS_TRIGGER, CStringGetTextDatum, DatumGetInt64(), DirectFunctionCall1, elog, ereport, errcode(), errmsg(), ERROR, i, if(), Int32GetDatum(), nextval(), palloc(), pfree(), PointerGetDatum(), relname, 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(), splan, sprintf, 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.

◆ wait_pid()

Datum wait_pid ( PG_FUNCTION_ARGS  )

Definition at line 689 of file regress.c.

690 {
691  int pid = PG_GETARG_INT32(0);
692 
693  if (!superuser())
694  elog(ERROR, "must be superuser to check PID liveness");
695 
696  while (kill(pid, 0) == 0)
697  {
699  pg_usleep(50000);
700  }
701 
702  if (errno != ESRCH)
703  elog(ERROR, "could not check PID %d liveness: %m", pid);
704 
705  PG_RETURN_VOID();
706 }
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:122
void pg_usleep(long microsec)
Definition: signal.c:53
#define kill(pid, sig)
Definition: win32_port.h:503

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

◆ widget_in()

Datum widget_in ( PG_FUNCTION_ARGS  )

Definition at line 169 of file regress.c.

170 {
171  char *str = PG_GETARG_CSTRING(0);
172  char *p,
173  *coord[NARGS];
174  int i;
175  WIDGET *result;
176 
177  for (i = 0, p = str; *p && i < NARGS && *p != RDELIM; p++)
178  {
179  if (*p == DELIM || (*p == LDELIM && i == 0))
180  coord[i++] = p + 1;
181  }
182 
183  /*
184  * Note: DON'T convert this error to "soft" style (errsave/ereturn). We
185  * want this data type to stay permanently in the hard-error world so that
186  * it can be used for testing that such cases still work reasonably.
187  */
188  if (i < NARGS)
189  ereport(ERROR,
190  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
191  errmsg("invalid input syntax for type %s: \"%s\"",
192  "widget", str)));
193 
194  result = (WIDGET *) palloc(sizeof(WIDGET));
195  result->center.x = atof(coord[0]);
196  result->center.y = atof(coord[1]);
197  result->radius = atof(coord[2]);
198 
199  PG_RETURN_POINTER(result);
200 }
const char * str
#define DELIM
Definition: regress.c:77
#define RDELIM
Definition: regress.c:76
#define LDELIM
Definition: regress.c:75
#define NARGS
Definition: regress.c:166
double radius
Definition: regress.c:160

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

◆ widget_out()

Datum widget_out ( PG_FUNCTION_ARGS  )

Definition at line 203 of file regress.c.

204 {
205  WIDGET *widget = (WIDGET *) PG_GETARG_POINTER(0);
206  char *str = psprintf("(%g,%g,%g)",
207  widget->center.x, widget->center.y, widget->radius);
208 
210 }
char * psprintf(const char *fmt,...)
Definition: psprintf.c:43

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

Variable Documentation

◆ PG_MODULE_MAGIC

PG_MODULE_MAGIC

Definition at line 81 of file regress.c.

◆ splan

◆ ttoff

bool ttoff = false
static

Definition at line 268 of file regress.c.

Referenced by set_ttdummy(), and ttdummy().