PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 "postmaster/postmaster.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_setup)
 
Datum test_enc_setup (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)
 
 PG_FUNCTION_INFO_V1 (test_relpath)
 
Datum test_relpath (PG_FUNCTION_ARGS)
 

Variables

 PG_MODULE_MAGIC
 
static SPIPlanPtr splan = NULL
 
static bool ttoff = false
 

Macro Definition Documentation

◆ DELIM

#define DELIM   ','

Definition at line 78 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 56 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:521

Definition at line 66 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 48 of file regress.c.

◆ LDELIM

#define LDELIM   '('

Definition at line 76 of file regress.c.

◆ NARGS

#define NARGS   3

Definition at line 167 of file regress.c.

◆ RDELIM

#define RDELIM   ')'

Definition at line 77 of file regress.c.

◆ TTDUMMY_INFINITY

#define TTDUMMY_INFINITY   999999

Definition at line 266 of file regress.c.

Function Documentation

◆ binary_coercible()

Datum binary_coercible ( PG_FUNCTION_ARGS  )

Definition at line 1205 of file regress.c.

1206{
1207 Oid srctype = PG_GETARG_OID(0);
1208 Oid targettype = PG_GETARG_OID(1);
1209
1210 PG_RETURN_BOOL(IsBinaryCoercible(srctype, targettype));
1211}
#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:30

References IsBinaryCoercible(), PG_GETARG_OID, and PG_RETURN_BOOL.

◆ get_environ()

Datum get_environ ( PG_FUNCTION_ARGS  )

Definition at line 649 of file regress.c.

650{
651#if !defined(WIN32) || defined(_MSC_VER)
652 extern char **environ;
653#endif
654 int nvals = 0;
655 ArrayType *result;
656 Datum *env;
657
658 for (char **s = environ; *s; s++)
659 nvals++;
660
661 env = palloc(nvals * sizeof(Datum));
662
663 for (int i = 0; i < nvals; i++)
665
666 result = construct_array_builtin(env, nvals, TEXTOID);
667
668 PG_RETURN_POINTER(result);
669}
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:74
void * palloc(Size size)
Definition: mcxt.c:1317
uintptr_t Datum
Definition: postgres.h:69
char ** environ

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

◆ int44in()

Datum int44in ( PG_FUNCTION_ARGS  )

Definition at line 500 of file regress.c.

501{
502 char *input_string = PG_GETARG_CSTRING(0);
503 int32 *result = (int32 *) palloc(4 * sizeof(int32));
504 int i;
505
506 i = sscanf(input_string,
507 "%d, %d, %d, %d",
508 &result[0],
509 &result[1],
510 &result[2],
511 &result[3]);
512 while (i < 4)
513 result[i++] = 0;
514
515 PG_RETURN_POINTER(result);
516}
int32_t int32
Definition: c.h:498
#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 524 of file regress.c.

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

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

◆ interpt_pp()

Datum interpt_pp ( PG_FUNCTION_ARGS  )

Definition at line 89 of file regress.c.

90{
91 PATH *p1 = PG_GETARG_PATH_P(0);
92 PATH *p2 = PG_GETARG_PATH_P(1);
93 int i,
94 j;
95 LSEG seg1,
96 seg2;
97 bool found; /* We've found the intersection */
98
99 found = false; /* Haven't found it yet */
100
101 for (i = 0; i < p1->npts - 1 && !found; i++)
102 {
103 regress_lseg_construct(&seg1, &p1->p[i], &p1->p[i + 1]);
104 for (j = 0; j < p2->npts - 1 && !found; j++)
105 {
106 regress_lseg_construct(&seg2, &p2->p[j], &p2->p[j + 1]);
108 LsegPGetDatum(&seg1),
109 LsegPGetDatum(&seg2))))
110 found = true;
111 }
112 }
113
114 if (!found)
116
117 /*
118 * Note: DirectFunctionCall2 will kick out an error if lseg_interpt()
119 * returns NULL, but that should be impossible since we know the two
120 * segments intersect.
121 */
123 LsegPGetDatum(&seg1),
124 LsegPGetDatum(&seg2)));
125}
#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:75
static bool DatumGetBool(Datum X)
Definition: postgres.h:95
static void regress_lseg_construct(LSEG *lseg, Point *pt1, Point *pt2)
Definition: regress.c:130
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, 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 550 of file regress.c.

551{
553 HeapTupleData tuple;
554 int ncolumns;
555 Datum *values;
556 bool *nulls;
557
558 Oid tupType;
559 int32 tupTypmod;
560 TupleDesc tupdesc;
561
562 HeapTuple newtup;
563
564 int i;
565
566 MemoryContext old_context;
567
568 /* Extract type info from the tuple itself */
569 tupType = HeapTupleHeaderGetTypeId(rec);
570 tupTypmod = HeapTupleHeaderGetTypMod(rec);
571 tupdesc = lookup_rowtype_tupdesc(tupType, tupTypmod);
572 ncolumns = tupdesc->natts;
573
574 /* Build a temporary HeapTuple control structure */
577 tuple.t_tableOid = InvalidOid;
578 tuple.t_data = rec;
579
580 values = (Datum *) palloc(ncolumns * sizeof(Datum));
581 nulls = (bool *) palloc(ncolumns * sizeof(bool));
582
583 heap_deform_tuple(&tuple, tupdesc, values, nulls);
584
586
587 for (i = 0; i < ncolumns; i++)
588 {
589 struct varlena *attr;
590 struct varlena *new_attr;
591 struct varatt_indirect redirect_pointer;
592
593 /* only work on existing, not-null varlenas */
594 if (TupleDescAttr(tupdesc, i)->attisdropped ||
595 nulls[i] ||
596 TupleDescAttr(tupdesc, i)->attlen != -1 ||
597 TupleDescAttr(tupdesc, i)->attstorage == TYPSTORAGE_PLAIN)
598 continue;
599
600 attr = (struct varlena *) DatumGetPointer(values[i]);
601
602 /* don't recursively indirect */
604 continue;
605
606 /* copy datum, so it still lives later */
608 attr = detoast_external_attr(attr);
609 else
610 {
611 struct varlena *oldattr = attr;
612
613 attr = palloc0(VARSIZE_ANY(oldattr));
614 memcpy(attr, oldattr, VARSIZE_ANY(oldattr));
615 }
616
617 /* build indirection Datum */
618 new_attr = (struct varlena *) palloc0(INDIRECT_POINTER_SIZE);
619 redirect_pointer.pointer = attr;
621 memcpy(VARDATA_EXTERNAL(new_attr), &redirect_pointer,
622 sizeof(redirect_pointer));
623
624 values[i] = PointerGetDatum(new_attr);
625 }
626
627 newtup = heap_form_tuple(tupdesc, values, nulls);
628 pfree(values);
629 pfree(nulls);
630 ReleaseTupleDesc(tupdesc);
631
632 MemoryContextSwitchTo(old_context);
633
634 /*
635 * We intentionally don't use PG_RETURN_HEAPTUPLEHEADER here, because that
636 * would cause the indirect toast pointers to be flattened out of the
637 * tuple immediately, rendering subsequent testing irrelevant. So just
638 * return the HeapTupleHeader pointer as-is. This violates the general
639 * rule that composite Datums shouldn't contain toast pointers, but so
640 * long as the regression test scripts don't insert the result of this
641 * function into a container type (record, array, etc) it should be OK.
642 */
643 PG_RETURN_POINTER(newtup->t_data);
644}
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:1117
void heap_deform_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *values, bool *isnull)
Definition: heaptuple.c:1346
static int32 HeapTupleHeaderGetTypMod(const HeapTupleHeaderData *tup)
Definition: htup_details.h:516
static uint32 HeapTupleHeaderGetDatumLength(const HeapTupleHeaderData *tup)
Definition: htup_details.h:492
static Oid HeapTupleHeaderGetTypeId(const HeapTupleHeaderData *tup)
Definition: htup_details.h:504
static void ItemPointerSetInvalid(ItemPointerData *pointer)
Definition: itemptr.h:184
MemoryContext TopTransactionContext
Definition: mcxt.c:154
void pfree(void *pointer)
Definition: mcxt.c:1524
void * palloc0(Size size)
Definition: mcxt.c:1347
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:124
char attstorage
Definition: pg_attribute.h:108
int16 attlen
Definition: pg_attribute.h:59
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:327
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:317
#define InvalidOid
Definition: postgres_ext.h:35
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:658
#define ReleaseTupleDesc(tupdesc)
Definition: tupdesc.h:213
static FormData_pg_attribute * TupleDescAttr(TupleDesc tupdesc, int i)
Definition: tupdesc.h:154
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 141 of file regress.c.

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

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

◆ PG_FUNCTION_INFO_V1() [1/24]

PG_FUNCTION_INFO_V1 ( binary_coercible  )

◆ PG_FUNCTION_INFO_V1() [2/24]

PG_FUNCTION_INFO_V1 ( get_environ  )

◆ PG_FUNCTION_INFO_V1() [3/24]

PG_FUNCTION_INFO_V1 ( int44in  )

◆ PG_FUNCTION_INFO_V1() [4/24]

PG_FUNCTION_INFO_V1 ( int44out  )

◆ PG_FUNCTION_INFO_V1() [5/24]

PG_FUNCTION_INFO_V1 ( interpt_pp  )

◆ PG_FUNCTION_INFO_V1() [6/24]

PG_FUNCTION_INFO_V1 ( make_tuple_indirect  )

◆ PG_FUNCTION_INFO_V1() [7/24]

PG_FUNCTION_INFO_V1 ( overpaid  )

◆ PG_FUNCTION_INFO_V1() [8/24]

PG_FUNCTION_INFO_V1 ( pt_in_widget  )

◆ PG_FUNCTION_INFO_V1() [9/24]

PG_FUNCTION_INFO_V1 ( regress_setenv  )

◆ PG_FUNCTION_INFO_V1() [10/24]

PG_FUNCTION_INFO_V1 ( reverse_name  )

◆ PG_FUNCTION_INFO_V1() [11/24]

PG_FUNCTION_INFO_V1 ( set_ttdummy  )

◆ PG_FUNCTION_INFO_V1() [12/24]

PG_FUNCTION_INFO_V1 ( test_atomic_ops  )

◆ PG_FUNCTION_INFO_V1() [13/24]

PG_FUNCTION_INFO_V1 ( test_canonicalize_path  )

◆ PG_FUNCTION_INFO_V1() [14/24]

PG_FUNCTION_INFO_V1 ( test_enc_conversion  )

◆ PG_FUNCTION_INFO_V1() [15/24]

PG_FUNCTION_INFO_V1 ( test_enc_setup  )

◆ PG_FUNCTION_INFO_V1() [16/24]

PG_FUNCTION_INFO_V1 ( test_fdw_handler  )

◆ PG_FUNCTION_INFO_V1() [17/24]

PG_FUNCTION_INFO_V1 ( test_opclass_options_func  )

◆ PG_FUNCTION_INFO_V1() [18/24]

PG_FUNCTION_INFO_V1 ( test_relpath  )

◆ PG_FUNCTION_INFO_V1() [19/24]

PG_FUNCTION_INFO_V1 ( test_support_func  )

◆ PG_FUNCTION_INFO_V1() [20/24]

PG_FUNCTION_INFO_V1 ( trigger_return_old  )

◆ PG_FUNCTION_INFO_V1() [21/24]

PG_FUNCTION_INFO_V1 ( ttdummy  )

◆ PG_FUNCTION_INFO_V1() [22/24]

PG_FUNCTION_INFO_V1 ( wait_pid  )

◆ PG_FUNCTION_INFO_V1() [23/24]

PG_FUNCTION_INFO_V1 ( widget_in  )

◆ PG_FUNCTION_INFO_V1() [24/24]

PG_FUNCTION_INFO_V1 ( widget_out  )

◆ pt_in_widget()

Datum pt_in_widget ( PG_FUNCTION_ARGS  )

Definition at line 216 of file regress.c.

217{
218 Point *point = PG_GETARG_POINT_P(0);
219 WIDGET *widget = (WIDGET *) PG_GETARG_POINTER(1);
220 float8 distance;
221
223 PointPGetDatum(point),
224 PointPGetDatum(&widget->center)));
225
226 PG_RETURN_BOOL(distance < widget->radius);
227}
double float8
Definition: c.h:601
#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:499
Point center
Definition: regress.c:160

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 130 of file regress.c.

131{
132 lseg->p[0].x = pt1->x;
133 lseg->p[0].y = pt1->y;
134 lseg->p[1].x = pt2->x;
135 lseg->p[1].y = pt2->y;
136}
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 674 of file regress.c.

675{
676 char *envvar = text_to_cstring(PG_GETARG_TEXT_PP(0));
677 char *envval = text_to_cstring(PG_GETARG_TEXT_PP(1));
678
679 if (!superuser())
680 elog(ERROR, "must be superuser to change environment variables");
681
682 if (setenv(envvar, envval, 1) != 0)
683 elog(ERROR, "could not set environment variable: %m");
684
686}
#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:225
#define setenv(x, y, z)
Definition: win32_port.h:545

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 232 of file regress.c.

233{
234 char *string = PG_GETARG_CSTRING(0);
235 int i;
236 int len;
237 char *new_string;
238
239 new_string = palloc0(NAMEDATALEN);
240 for (i = 0; i < NAMEDATALEN && string[i]; ++i)
241 ;
242 if (i == NAMEDATALEN || !string[i])
243 --i;
244 len = i;
245 for (; i >= 0; --i)
246 new_string[len - i] = string[i];
247 PG_RETURN_CSTRING(new_string);
248}
#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 462 of file regress.c.

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

References PG_GETARG_INT32, PG_RETURN_INT32, and ttoff.

◆ test_atomic_flag()

static void test_atomic_flag ( void  )
static

Definition at line 712 of file regress.c.

713{
714 pg_atomic_flag flag;
715
725}
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:48
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 917 of file regress.c.

918{
920
922
924
925 /*
926 * Arguably this shouldn't be tested as part of this function, but it's
927 * closely enough related that that seems ok for now.
928 */
930
931 PG_RETURN_BOOL(true);
932}
static void test_spinlock(void)
Definition: regress.c:853
static void test_atomic_uint32(void)
Definition: regress.c:728
static void test_atomic_flag(void)
Definition: regress.c:712
static void test_atomic_uint64(void)
Definition: regress.c:800

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 728 of file regress.c.

729{
731 uint32 expected;
732 int i;
733
734 pg_atomic_init_u32(&var, 0);
736 pg_atomic_write_u32(&var, 3);
739 3);
745
746 /* test around numerical limits */
747 EXPECT_EQ_U32(pg_atomic_fetch_add_u32(&var, INT_MAX), 0);
748 EXPECT_EQ_U32(pg_atomic_fetch_add_u32(&var, INT_MAX), INT_MAX);
749 pg_atomic_fetch_add_u32(&var, 2); /* wrap to 0 */
754 2 * PG_INT16_MAX + 1);
757 pg_atomic_fetch_add_u32(&var, 1); /* top up to UINT_MAX */
758 EXPECT_EQ_U32(pg_atomic_read_u32(&var), UINT_MAX);
759 EXPECT_EQ_U32(pg_atomic_fetch_sub_u32(&var, INT_MAX), UINT_MAX);
760 EXPECT_EQ_U32(pg_atomic_read_u32(&var), (uint32) INT_MAX + 1);
761 EXPECT_EQ_U32(pg_atomic_sub_fetch_u32(&var, INT_MAX), 1);
763 expected = PG_INT16_MAX;
764 EXPECT_TRUE(!pg_atomic_compare_exchange_u32(&var, &expected, 1));
765 expected = PG_INT16_MAX + 1;
766 EXPECT_TRUE(!pg_atomic_compare_exchange_u32(&var, &expected, 1));
767 expected = PG_INT16_MIN;
768 EXPECT_TRUE(!pg_atomic_compare_exchange_u32(&var, &expected, 1));
769 expected = PG_INT16_MIN - 1;
770 EXPECT_TRUE(!pg_atomic_compare_exchange_u32(&var, &expected, 1));
771
772 /* fail exchange because of old expected */
773 expected = 10;
774 EXPECT_TRUE(!pg_atomic_compare_exchange_u32(&var, &expected, 1));
775
776 /* CAS is allowed to fail due to interrupts, try a couple of times */
777 for (i = 0; i < 1000; i++)
778 {
779 expected = 0;
780 if (!pg_atomic_compare_exchange_u32(&var, &expected, 1))
781 break;
782 }
783 if (i == 1000)
784 elog(ERROR, "atomic_compare_exchange_u32() never succeeded");
786 pg_atomic_write_u32(&var, 0);
787
788 /* try setting flagbits */
789 EXPECT_TRUE(!(pg_atomic_fetch_or_u32(&var, 1) & 1));
792 /* try clearing flagbits */
793 EXPECT_EQ_U32(pg_atomic_fetch_and_u32(&var, ~2) & 3, 3);
795 /* no bits set anymore */
797}
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:556
uint32_t uint32
Definition: c.h:502
#define PG_INT16_MAX
Definition: c.h:557
#define EXPECT_EQ_U32(result_expr, expected_expr)
Definition: regress.c:56

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 800 of file regress.c.

801{
803 uint64 expected;
804 int i;
805
806 pg_atomic_init_u64(&var, 0);
808 pg_atomic_write_u64(&var, 3);
811 3);
817
818 /* fail exchange because of old expected */
819 expected = 10;
820 EXPECT_TRUE(!pg_atomic_compare_exchange_u64(&var, &expected, 1));
821
822 /* CAS is allowed to fail due to interrupts, try a couple of times */
823 for (i = 0; i < 100; i++)
824 {
825 expected = 0;
826 if (!pg_atomic_compare_exchange_u64(&var, &expected, 1))
827 break;
828 }
829 if (i == 100)
830 elog(ERROR, "atomic_compare_exchange_u64() never succeeded");
832
833 pg_atomic_write_u64(&var, 0);
834
835 /* try setting flagbits */
836 EXPECT_TRUE(!(pg_atomic_fetch_or_u64(&var, 1) & 1));
839 /* try clearing flagbits */
840 EXPECT_EQ_U64((pg_atomic_fetch_and_u64(&var, ~2) & 3), 3);
842 /* no bits set anymore */
844}
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:503
#define EXPECT_EQ_U64(result_expr, expected_expr)
Definition: regress.c:66

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 540 of file regress.c.

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

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 1088 of file regress.c.

1089{
1090 bytea *string = PG_GETARG_BYTEA_PP(0);
1091 char *src_encoding_name = NameStr(*PG_GETARG_NAME(1));
1092 int src_encoding = pg_char_to_encoding(src_encoding_name);
1093 char *dest_encoding_name = NameStr(*PG_GETARG_NAME(2));
1094 int dest_encoding = pg_char_to_encoding(dest_encoding_name);
1095 bool noError = PG_GETARG_BOOL(3);
1096 TupleDesc tupdesc;
1097 char *src;
1098 char *dst;
1099 bytea *retval;
1100 Size srclen;
1101 Size dstsize;
1102 Oid proc;
1103 int convertedbytes;
1104 int dstlen;
1105 Datum values[2];
1106 bool nulls[2] = {0};
1107 HeapTuple tuple;
1108
1109 if (src_encoding < 0)
1110 ereport(ERROR,
1111 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1112 errmsg("invalid source encoding name \"%s\"",
1113 src_encoding_name)));
1114 if (dest_encoding < 0)
1115 ereport(ERROR,
1116 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1117 errmsg("invalid destination encoding name \"%s\"",
1118 dest_encoding_name)));
1119
1120 /* Build a tuple descriptor for our result type */
1121 if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
1122 elog(ERROR, "return type must be a row type");
1123 tupdesc = BlessTupleDesc(tupdesc);
1124
1125 srclen = VARSIZE_ANY_EXHDR(string);
1126 src = VARDATA_ANY(string);
1127
1128 if (src_encoding == dest_encoding)
1129 {
1130 /* just check that the source string is valid */
1131 int oklen;
1132
1133 oklen = pg_encoding_verifymbstr(src_encoding, src, srclen);
1134
1135 if (oklen == srclen)
1136 {
1137 convertedbytes = oklen;
1138 retval = string;
1139 }
1140 else if (!noError)
1141 {
1142 report_invalid_encoding(src_encoding, src + oklen, srclen - oklen);
1143 }
1144 else
1145 {
1146 /*
1147 * build bytea data type structure.
1148 */
1149 Assert(oklen < srclen);
1150 convertedbytes = oklen;
1151 retval = (bytea *) palloc(oklen + VARHDRSZ);
1152 SET_VARSIZE(retval, oklen + VARHDRSZ);
1153 memcpy(VARDATA(retval), src, oklen);
1154 }
1155 }
1156 else
1157 {
1158 proc = FindDefaultConversionProc(src_encoding, dest_encoding);
1159 if (!OidIsValid(proc))
1160 ereport(ERROR,
1161 (errcode(ERRCODE_UNDEFINED_FUNCTION),
1162 errmsg("default conversion function for encoding \"%s\" to \"%s\" does not exist",
1163 pg_encoding_to_char(src_encoding),
1164 pg_encoding_to_char(dest_encoding))));
1165
1166 if (srclen >= (MaxAllocSize / (Size) MAX_CONVERSION_GROWTH))
1167 ereport(ERROR,
1168 (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
1169 errmsg("out of memory"),
1170 errdetail("String of %d bytes is too long for encoding conversion.",
1171 (int) srclen)));
1172
1173 dstsize = (Size) srclen * MAX_CONVERSION_GROWTH + 1;
1175
1176 /* perform conversion */
1177 convertedbytes = pg_do_encoding_conversion_buf(proc,
1178 src_encoding,
1179 dest_encoding,
1180 (unsigned char *) src, srclen,
1181 (unsigned char *) dst, dstsize,
1182 noError);
1183 dstlen = strlen(dst);
1184
1185 /*
1186 * build bytea data type structure.
1187 */
1188 retval = (bytea *) palloc(dstlen + VARHDRSZ);
1189 SET_VARSIZE(retval, dstlen + VARHDRSZ);
1190 memcpy(VARDATA(retval), dst, dstlen);
1191
1192 pfree(dst);
1193 }
1194
1195 values[0] = Int32GetDatum(convertedbytes);
1196 values[1] = PointerGetDatum(retval);
1197 tuple = heap_form_tuple(tupdesc, values, nulls);
1198
1200}
#define NameStr(name)
Definition: c.h:717
#define VARHDRSZ
Definition: c.h:663
#define OidIsValid(objectId)
Definition: c.h:746
size_t Size
Definition: c.h:576
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:2260
#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
Assert(PointerIsAligned(start, uint64))
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
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:1181
MemoryContext CurrentMemoryContext
Definition: mcxt.c:143
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:217
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:2163

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_enc_setup()

Datum test_enc_setup ( PG_FUNCTION_ARGS  )

Definition at line 1025 of file regress.c.

1026{
1027 /* Test pg_encoding_set_invalid() */
1028 for (int i = 0; i < _PG_LAST_ENCODING_; i++)
1029 {
1030 char buf[2],
1031 bigbuf[16];
1032 int len,
1033 mblen,
1034 valid;
1035
1036 if (pg_encoding_max_length(i) == 1)
1037 continue;
1039 len = strnlen(buf, 2);
1040 if (len != 2)
1041 elog(WARNING,
1042 "official invalid string for encoding \"%s\" has length %d",
1044 mblen = pg_encoding_mblen(i, buf);
1045 if (mblen != 2)
1046 elog(WARNING,
1047 "official invalid string for encoding \"%s\" has mblen %d",
1048 pg_enc2name_tbl[i].name, mblen);
1049 valid = pg_encoding_verifymbstr(i, buf, len);
1050 if (valid != 0)
1051 elog(WARNING,
1052 "official invalid string for encoding \"%s\" has valid prefix of length %d",
1053 pg_enc2name_tbl[i].name, valid);
1054 valid = pg_encoding_verifymbstr(i, buf, 1);
1055 if (valid != 0)
1056 elog(WARNING,
1057 "first byte of official invalid string for encoding \"%s\" has valid prefix of length %d",
1058 pg_enc2name_tbl[i].name, valid);
1059 memset(bigbuf, ' ', sizeof(bigbuf));
1060 bigbuf[0] = buf[0];
1061 bigbuf[1] = buf[1];
1062 valid = pg_encoding_verifymbstr(i, bigbuf, sizeof(bigbuf));
1063 if (valid != 0)
1064 elog(WARNING,
1065 "trailing data changed official invalid string for encoding \"%s\" to have valid prefix of length %d",
1066 pg_enc2name_tbl[i].name, valid);
1067 }
1068
1070}
#define WARNING
Definition: elog.h:36
const pg_enc2name pg_enc2name_tbl[]
Definition: encnames.c:308
static char * buf
Definition: pg_test_fsync.c:72
@ _PG_LAST_ENCODING_
Definition: pg_wchar.h:271
size_t strnlen(const char *str, size_t maxlen)
Definition: strnlen.c:26
const char * name
void pg_encoding_set_invalid(int encoding, char *dst)
Definition: wchar.c:2049
int pg_encoding_max_length(int encoding)
Definition: wchar.c:2174
int pg_encoding_mblen(int encoding, const char *mbstr)
Definition: wchar.c:2116

References _PG_LAST_ENCODING_, buf, elog, i, len, name, pg_enc2name_tbl, pg_encoding_max_length(), pg_encoding_mblen(), pg_encoding_set_invalid(), pg_encoding_verifymbstr(), PG_RETURN_VOID, strnlen(), and WARNING.

◆ test_fdw_handler()

Datum test_fdw_handler ( PG_FUNCTION_ARGS  )

Definition at line 936 of file regress.c.

937{
938 elog(ERROR, "test_fdw_handler is not implemented");
940}

References elog, ERROR, and PG_RETURN_NULL.

◆ test_opclass_options_func()

Datum test_opclass_options_func ( PG_FUNCTION_ARGS  )

Definition at line 1017 of file regress.c.

1018{
1020}

References PG_RETURN_NULL.

◆ test_relpath()

Datum test_relpath ( PG_FUNCTION_ARGS  )

Definition at line 1218 of file regress.c.

1219{
1220 RelPathStr rpath;
1221
1222 /*
1223 * Verify that PROCNUMBER_CHARS and MAX_BACKENDS stay in sync.
1224 * Unfortunately I don't know how to express that in a way suitable for a
1225 * static assert.
1226 */
1227 if ((int) ceil(log10(MAX_BACKENDS)) != PROCNUMBER_CHARS)
1228 elog(WARNING, "mismatch between MAX_BACKENDS and PROCNUMBER_CHARS");
1229
1230 /* verify that the max-length relpath is generated ok */
1232 INIT_FORKNUM);
1233
1234 if (strlen(rpath.str) != REL_PATH_STR_MAXLEN)
1235 elog(WARNING, "maximum length relpath is if length %zu instead of %zu",
1236 strlen(rpath.str), REL_PATH_STR_MAXLEN);
1237
1239}
#define OID_MAX
Definition: postgres_ext.h:38
#define MAX_BACKENDS
Definition: procnumber.h:39
RelPathStr GetRelationPath(Oid dbOid, Oid spcOid, RelFileNumber relNumber, int procNumber, ForkNumber forkNumber)
Definition: relpath.c:143
#define REL_PATH_STR_MAXLEN
Definition: relpath.h:96
@ INIT_FORKNUM
Definition: relpath.h:61
#define PROCNUMBER_CHARS
Definition: relpath.h:84
char str[REL_PATH_STR_MAXLEN+1]
Definition: relpath.h:123

References elog, GetRelationPath(), INIT_FORKNUM, MAX_BACKENDS, OID_MAX, PG_RETURN_VOID, PROCNUMBER_CHARS, REL_PATH_STR_MAXLEN, RelPathStr::str, and WARNING.

◆ test_spinlock()

static void test_spinlock ( void  )
static

Definition at line 853 of file regress.c.

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

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

254{
255 TriggerData *trigdata = (TriggerData *) fcinfo->context;
256 HeapTuple tuple;
257
258 if (!CALLED_AS_TRIGGER(fcinfo))
259 elog(ERROR, "trigger_return_old: not fired by trigger manager");
260
261 tuple = trigdata->tg_trigtuple;
262
263 return PointerGetDatum(tuple);
264}
if(TABLE==NULL||TABLE_index==NULL)
Definition: isn.c:78
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 274 of file regress.c.

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

693{
694 int pid = PG_GETARG_INT32(0);
695
696 if (!superuser())
697 elog(ERROR, "must be superuser to check PID liveness");
698
699 while (kill(pid, 0) == 0)
700 {
702 pg_usleep(50000);
703 }
704
705 if (errno != ESRCH)
706 elog(ERROR, "could not check PID %d liveness: %m", pid);
707
709}
#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:493

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 170 of file regress.c.

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

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 204 of file regress.c.

205{
206 WIDGET *widget = (WIDGET *) PG_GETARG_POINTER(0);
207 char *str = psprintf("(%g,%g,%g)",
208 widget->center.x, widget->center.y, widget->radius);
209
211}
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 82 of file regress.c.

◆ splan

◆ ttoff

bool ttoff = false
static

Definition at line 269 of file regress.c.

Referenced by set_ttdummy(), and ttdummy().