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/catalog.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/functions.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 "tcop/tcopprot.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
 

Functions

static void regress_lseg_construct (LSEG *lseg, Point *pt1, Point *pt2)
 
 PG_MODULE_MAGIC_EXT (.name="regress",.version=PG_VERSION)
 
 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 (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 (is_catalog_text_unique_index_oid)
 
Datum is_catalog_text_unique_index_oid (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (test_support_func)
 
Datum test_support_func (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (test_inline_in_from_support_func)
 
Datum test_inline_in_from_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)
 

Macro Definition Documentation

◆ DELIM

#define DELIM   ','

Definition at line 81 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 59 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:560

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

◆ LDELIM

#define LDELIM   '('

Definition at line 79 of file regress.c.

◆ NARGS

#define NARGS   3

Definition at line 173 of file regress.c.

◆ RDELIM

#define RDELIM   ')'

Definition at line 80 of file regress.c.

Function Documentation

◆ binary_coercible()

Datum binary_coercible ( PG_FUNCTION_ARGS  )

Definition at line 1117 of file regress.c.

1118{
1119 Oid srctype = PG_GETARG_OID(0);
1120 Oid targettype = PG_GETARG_OID(1);
1121
1122 PG_RETURN_BOOL(IsBinaryCoercible(srctype, targettype));
1123}
#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:32

References IsBinaryCoercible(), PG_GETARG_OID, and PG_RETURN_BOOL.

◆ get_environ()

Datum get_environ ( PG_FUNCTION_ARGS  )

Definition at line 435 of file regress.c.

436{
437#if !defined(WIN32)
438 extern char **environ;
439#endif
440 int nvals = 0;
441 ArrayType *result;
442 Datum *env;
443
444 for (char **s = environ; *s; s++)
445 nvals++;
446
447 env = palloc(nvals * sizeof(Datum));
448
449 for (int i = 0; i < nvals; i++)
451
452 result = construct_array_builtin(env, nvals, TEXTOID);
453
454 PG_RETURN_POINTER(result);
455}
ArrayType * construct_array_builtin(Datum *elems, int nelems, Oid elmtype)
Definition: arrayfuncs.c:3382
#define CStringGetTextDatum(s)
Definition: builtins.h:97
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:361
int i
Definition: isn.c:77
void * palloc(Size size)
Definition: mcxt.c:1365
uint64_t Datum
Definition: postgres.h:70
char ** environ

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

◆ int44in()

Datum int44in ( PG_FUNCTION_ARGS  )

Definition at line 286 of file regress.c.

287{
288 char *input_string = PG_GETARG_CSTRING(0);
289 int32 *result = (int32 *) palloc(4 * sizeof(int32));
290 int i;
291
292 i = sscanf(input_string,
293 "%d, %d, %d, %d",
294 &result[0],
295 &result[1],
296 &result[2],
297 &result[3]);
298 while (i < 4)
299 result[i++] = 0;
300
301 PG_RETURN_POINTER(result);
302}
int32_t int32
Definition: c.h:537
#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 310 of file regress.c.

311{
312 int32 *an_array = (int32 *) PG_GETARG_POINTER(0);
313 char *result = (char *) palloc(16 * 4);
314
315 snprintf(result, 16 * 4, "%d,%d,%d,%d",
316 an_array[0],
317 an_array[1],
318 an_array[2],
319 an_array[3]);
320
321 PG_RETURN_CSTRING(result);
322}
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:362
#define snprintf
Definition: port.h:260

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

◆ interpt_pp()

Datum interpt_pp ( PG_FUNCTION_ARGS  )

Definition at line 95 of file regress.c.

96{
97 PATH *p1 = PG_GETARG_PATH_P(0);
98 PATH *p2 = PG_GETARG_PATH_P(1);
99 int i,
100 j;
101 LSEG seg1,
102 seg2;
103 bool found; /* We've found the intersection */
104
105 found = false; /* Haven't found it yet */
106
107 for (i = 0; i < p1->npts - 1 && !found; i++)
108 {
109 regress_lseg_construct(&seg1, &p1->p[i], &p1->p[i + 1]);
110 for (j = 0; j < p2->npts - 1 && !found; j++)
111 {
112 regress_lseg_construct(&seg2, &p2->p[j], &p2->p[j + 1]);
114 LsegPGetDatum(&seg1),
115 LsegPGetDatum(&seg2))))
116 found = true;
117 }
118 }
119
120 if (!found)
122
123 /*
124 * Note: DirectFunctionCall2 will kick out an error if lseg_interpt()
125 * returns NULL, but that should be impossible since we know the two
126 * segments intersect.
127 */
129 LsegPGetDatum(&seg1),
130 LsegPGetDatum(&seg2)));
131}
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:684
#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:193
#define PG_GETARG_PATH_P(n)
Definition: geo_decls.h:215
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:78
static bool DatumGetBool(Datum X)
Definition: postgres.h:100
static void regress_lseg_construct(LSEG *lseg, Point *pt1, Point *pt2)
Definition: regress.c:136
Point p[FLEXIBLE_ARRAY_MEMBER]
Definition: geo_decls.h:120
int32 npts
Definition: geo_decls.h:117

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

◆ is_catalog_text_unique_index_oid()

Datum is_catalog_text_unique_index_oid ( PG_FUNCTION_ARGS  )

Definition at line 730 of file regress.c.

731{
733}
bool IsCatalogTextUniqueIndexOid(Oid relid)
Definition: catalog.c:156
static Datum BoolGetDatum(bool X)
Definition: postgres.h:112

References BoolGetDatum(), IsCatalogTextUniqueIndexOid(), and PG_GETARG_OID.

◆ make_tuple_indirect()

Datum make_tuple_indirect ( PG_FUNCTION_ARGS  )

Definition at line 336 of file regress.c.

337{
339 HeapTupleData tuple;
340 int ncolumns;
341 Datum *values;
342 bool *nulls;
343
344 Oid tupType;
345 int32 tupTypmod;
346 TupleDesc tupdesc;
347
348 HeapTuple newtup;
349
350 int i;
351
352 MemoryContext old_context;
353
354 /* Extract type info from the tuple itself */
355 tupType = HeapTupleHeaderGetTypeId(rec);
356 tupTypmod = HeapTupleHeaderGetTypMod(rec);
357 tupdesc = lookup_rowtype_tupdesc(tupType, tupTypmod);
358 ncolumns = tupdesc->natts;
359
360 /* Build a temporary HeapTuple control structure */
363 tuple.t_tableOid = InvalidOid;
364 tuple.t_data = rec;
365
366 values = (Datum *) palloc(ncolumns * sizeof(Datum));
367 nulls = (bool *) palloc(ncolumns * sizeof(bool));
368
369 heap_deform_tuple(&tuple, tupdesc, values, nulls);
370
372
373 for (i = 0; i < ncolumns; i++)
374 {
375 struct varlena *attr;
376 struct varlena *new_attr;
377 struct varatt_indirect redirect_pointer;
378
379 /* only work on existing, not-null varlenas */
380 if (TupleDescAttr(tupdesc, i)->attisdropped ||
381 nulls[i] ||
382 TupleDescAttr(tupdesc, i)->attlen != -1 ||
383 TupleDescAttr(tupdesc, i)->attstorage == TYPSTORAGE_PLAIN)
384 continue;
385
386 attr = (struct varlena *) DatumGetPointer(values[i]);
387
388 /* don't recursively indirect */
390 continue;
391
392 /* copy datum, so it still lives later */
394 attr = detoast_external_attr(attr);
395 else
396 {
397 struct varlena *oldattr = attr;
398
399 attr = palloc0(VARSIZE_ANY(oldattr));
400 memcpy(attr, oldattr, VARSIZE_ANY(oldattr));
401 }
402
403 /* build indirection Datum */
404 new_attr = (struct varlena *) palloc0(INDIRECT_POINTER_SIZE);
405 redirect_pointer.pointer = attr;
407 memcpy(VARDATA_EXTERNAL(new_attr), &redirect_pointer,
408 sizeof(redirect_pointer));
409
410 values[i] = PointerGetDatum(new_attr);
411 }
412
413 newtup = heap_form_tuple(tupdesc, values, nulls);
414 pfree(values);
415 pfree(nulls);
416 ReleaseTupleDesc(tupdesc);
417
418 MemoryContextSwitchTo(old_context);
419
420 /*
421 * We intentionally don't use PG_RETURN_HEAPTUPLEHEADER here, because that
422 * would cause the indirect toast pointers to be flattened out of the
423 * tuple immediately, rendering subsequent testing irrelevant. So just
424 * return the HeapTupleHeader pointer as-is. This violates the general
425 * rule that composite Datums shouldn't contain toast pointers, but so
426 * long as the regression test scripts don't insert the result of this
427 * function into a container type (record, array, etc) it should be OK.
428 */
429 PG_RETURN_POINTER(newtup->t_data);
430}
static Datum values[MAXATTR]
Definition: bootstrap.c:153
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:171
void pfree(void *pointer)
Definition: mcxt.c:1594
void * palloc0(Size size)
Definition: mcxt.c:1395
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:332
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:322
#define InvalidOid
Definition: postgres_ext.h:37
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:695
#define ReleaseTupleDesc(tupdesc)
Definition: tupdesc.h:219
static FormData_pg_attribute * TupleDescAttr(TupleDesc tupdesc, int i)
Definition: tupdesc.h:160
TupleDesc lookup_rowtype_tupdesc(Oid type_id, int32 typmod)
Definition: typcache.c:1921
static bool VARATT_IS_EXTERNAL_ONDISK(const void *PTR)
Definition: varatt.h:361
static Size VARSIZE_ANY(const void *PTR)
Definition: varatt.h:460
static char * VARDATA_EXTERNAL(const void *PTR)
Definition: varatt.h:340
static bool VARATT_IS_EXTERNAL_INDIRECT(const void *PTR)
Definition: varatt.h:368
static void SET_VARTAG_EXTERNAL(void *PTR, vartag_external tag)
Definition: varatt.h:453
@ 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 147 of file regress.c.

148{
150 bool isnull;
151 int32 salary;
152
153 salary = DatumGetInt32(GetAttributeByName(tuple, "salary", &isnull));
154 if (isnull)
156 PG_RETURN_BOOL(salary > 699);
157}
Datum GetAttributeByName(HeapTupleHeader tuple, const char *attname, bool *isNull)
Definition: execUtils.c:1061
static int32 DatumGetInt32(Datum X)
Definition: postgres.h:212

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

◆ PG_FUNCTION_INFO_V1() [7/24]

PG_FUNCTION_INFO_V1 ( make_tuple_indirect  )

◆ PG_FUNCTION_INFO_V1() [8/24]

PG_FUNCTION_INFO_V1 ( overpaid  )

◆ PG_FUNCTION_INFO_V1() [9/24]

PG_FUNCTION_INFO_V1 ( pt_in_widget  )

◆ PG_FUNCTION_INFO_V1() [10/24]

PG_FUNCTION_INFO_V1 ( regress_setenv  )

◆ PG_FUNCTION_INFO_V1() [11/24]

PG_FUNCTION_INFO_V1 ( reverse_name  )

◆ 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_inline_in_from_support_func  )

◆ PG_FUNCTION_INFO_V1() [18/24]

PG_FUNCTION_INFO_V1 ( test_opclass_options_func  )

◆ PG_FUNCTION_INFO_V1() [19/24]

PG_FUNCTION_INFO_V1 ( test_relpath  )

◆ PG_FUNCTION_INFO_V1() [20/24]

PG_FUNCTION_INFO_V1 ( test_support_func  )

◆ PG_FUNCTION_INFO_V1() [21/24]

PG_FUNCTION_INFO_V1 ( trigger_return_old  )

◆ 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  )

◆ PG_MODULE_MAGIC_EXT()

PG_MODULE_MAGIC_EXT ( name = "regress",
version = PG_VERSION 
)

◆ pt_in_widget()

Datum pt_in_widget ( PG_FUNCTION_ARGS  )

Definition at line 222 of file regress.c.

223{
224 Point *point = PG_GETARG_POINT_P(0);
225 WIDGET *widget = (WIDGET *) PG_GETARG_POINTER(1);
226 float8 distance;
227
229 PointPGetDatum(point),
230 PointPGetDatum(&widget->center)));
231
232 PG_RETURN_BOOL(distance < widget->radius);
233}
double float8
Definition: c.h:638
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:184
static Datum PointPGetDatum(const Point *X)
Definition: geo_decls.h:180
Datum point_distance(PG_FUNCTION_ARGS)
Definition: geo_ops.c:1993
static float8 DatumGetFloat8(Datum X)
Definition: postgres.h:475
Point center
Definition: regress.c:166

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

137{
138 lseg->p[0].x = pt1->x;
139 lseg->p[0].y = pt1->y;
140 lseg->p[1].x = pt2->x;
141 lseg->p[1].y = pt2->y;
142}
Point p[2]
Definition: geo_decls.h:107
float8 y
Definition: geo_decls.h:98
float8 x
Definition: geo_decls.h:97

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

Referenced by interpt_pp().

◆ regress_setenv()

Datum regress_setenv ( PG_FUNCTION_ARGS  )

Definition at line 460 of file regress.c.

461{
462 char *envvar = text_to_cstring(PG_GETARG_TEXT_PP(0));
463 char *envval = text_to_cstring(PG_GETARG_TEXT_PP(1));
464
465 if (!superuser())
466 elog(ERROR, "must be superuser to change environment variables");
467
468 if (setenv(envvar, envval, 1) != 0)
469 elog(ERROR, "could not set environment variable: %m");
470
472}
#define elog(elevel,...)
Definition: elog.h:226
#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:214
#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 238 of file regress.c.

239{
240 char *string = PG_GETARG_CSTRING(0);
241 int i;
242 int len;
243 char *new_string;
244
245 new_string = palloc0(NAMEDATALEN);
246 for (i = 0; i < NAMEDATALEN && string[i]; ++i)
247 ;
248 if (i == NAMEDATALEN || !string[i])
249 --i;
250 len = i;
251 for (; i >= 0; --i)
252 new_string[len - i] = string[i];
253 PG_RETURN_CSTRING(new_string);
254}
#define NAMEDATALEN
const void size_t len

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

◆ test_atomic_flag()

static void test_atomic_flag ( void  )
static

Definition at line 498 of file regress.c.

499{
500 pg_atomic_flag flag;
501
511}
static void pg_atomic_clear_flag(volatile pg_atomic_flag *ptr)
Definition: atomics.h:205
static bool pg_atomic_test_set_flag(volatile pg_atomic_flag *ptr)
Definition: atomics.h:181
static bool pg_atomic_unlocked_test_flag(volatile pg_atomic_flag *ptr)
Definition: atomics.h:194
static void pg_atomic_init_flag(volatile pg_atomic_flag *ptr)
Definition: atomics.h:168
#define EXPECT_TRUE(expr)
Definition: regress.c:51
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 703 of file regress.c.

704{
706
708
710
711 /*
712 * Arguably this shouldn't be tested as part of this function, but it's
713 * closely enough related that that seems ok for now.
714 */
716
717 PG_RETURN_BOOL(true);
718}
static void test_spinlock(void)
Definition: regress.c:639
static void test_atomic_uint32(void)
Definition: regress.c:514
static void test_atomic_flag(void)
Definition: regress.c:498
static void test_atomic_uint64(void)
Definition: regress.c:586

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

515{
517 uint32 expected;
518 int i;
519
520 pg_atomic_init_u32(&var, 0);
522 pg_atomic_write_u32(&var, 3);
525 3);
531
532 /* test around numerical limits */
533 EXPECT_EQ_U32(pg_atomic_fetch_add_u32(&var, INT_MAX), 0);
534 EXPECT_EQ_U32(pg_atomic_fetch_add_u32(&var, INT_MAX), INT_MAX);
535 pg_atomic_fetch_add_u32(&var, 2); /* wrap to 0 */
540 2 * PG_INT16_MAX + 1);
543 pg_atomic_fetch_add_u32(&var, 1); /* top up to UINT_MAX */
544 EXPECT_EQ_U32(pg_atomic_read_u32(&var), UINT_MAX);
545 EXPECT_EQ_U32(pg_atomic_fetch_sub_u32(&var, INT_MAX), UINT_MAX);
546 EXPECT_EQ_U32(pg_atomic_read_u32(&var), (uint32) INT_MAX + 1);
547 EXPECT_EQ_U32(pg_atomic_sub_fetch_u32(&var, INT_MAX), 1);
549 expected = PG_INT16_MAX;
550 EXPECT_TRUE(!pg_atomic_compare_exchange_u32(&var, &expected, 1));
551 expected = PG_INT16_MAX + 1;
552 EXPECT_TRUE(!pg_atomic_compare_exchange_u32(&var, &expected, 1));
553 expected = PG_INT16_MIN;
554 EXPECT_TRUE(!pg_atomic_compare_exchange_u32(&var, &expected, 1));
555 expected = PG_INT16_MIN - 1;
556 EXPECT_TRUE(!pg_atomic_compare_exchange_u32(&var, &expected, 1));
557
558 /* fail exchange because of old expected */
559 expected = 10;
560 EXPECT_TRUE(!pg_atomic_compare_exchange_u32(&var, &expected, 1));
561
562 /* CAS is allowed to fail due to interrupts, try a couple of times */
563 for (i = 0; i < 1000; i++)
564 {
565 expected = 0;
566 if (!pg_atomic_compare_exchange_u32(&var, &expected, 1))
567 break;
568 }
569 if (i == 1000)
570 elog(ERROR, "atomic_compare_exchange_u32() never succeeded");
572 pg_atomic_write_u32(&var, 0);
573
574 /* try setting flagbits */
575 EXPECT_TRUE(!(pg_atomic_fetch_or_u32(&var, 1) & 1));
578 /* try clearing flagbits */
579 EXPECT_EQ_U32(pg_atomic_fetch_and_u32(&var, ~2) & 3, 3);
581 /* no bits set anymore */
583}
static uint32 pg_atomic_fetch_and_u32(volatile pg_atomic_uint32 *ptr, uint32 and_)
Definition: atomics.h:394
static bool pg_atomic_compare_exchange_u32(volatile pg_atomic_uint32 *ptr, uint32 *expected, uint32 newval)
Definition: atomics.h:347
static uint32 pg_atomic_fetch_or_u32(volatile pg_atomic_uint32 *ptr, uint32 or_)
Definition: atomics.h:408
static uint32 pg_atomic_sub_fetch_u32(volatile pg_atomic_uint32 *ptr, int32 sub_)
Definition: atomics.h:437
static uint32 pg_atomic_fetch_sub_u32(volatile pg_atomic_uint32 *ptr, int32 sub_)
Definition: atomics.h:379
static void pg_atomic_init_u32(volatile pg_atomic_uint32 *ptr, uint32 val)
Definition: atomics.h:219
static uint32 pg_atomic_fetch_add_u32(volatile pg_atomic_uint32 *ptr, int32 add_)
Definition: atomics.h:364
static uint32 pg_atomic_add_fetch_u32(volatile pg_atomic_uint32 *ptr, int32 add_)
Definition: atomics.h:422
static void pg_atomic_write_u32(volatile pg_atomic_uint32 *ptr, uint32 val)
Definition: atomics.h:274
static uint32 pg_atomic_read_u32(volatile pg_atomic_uint32 *ptr)
Definition: atomics.h:237
static uint32 pg_atomic_exchange_u32(volatile pg_atomic_uint32 *ptr, uint32 newval)
Definition: atomics.h:328
#define PG_INT16_MIN
Definition: c.h:593
uint32_t uint32
Definition: c.h:541
#define PG_INT16_MAX
Definition: c.h:594
#define EXPECT_EQ_U32(result_expr, expected_expr)
Definition: regress.c:59

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

587{
589 uint64 expected;
590 int i;
591
592 pg_atomic_init_u64(&var, 0);
594 pg_atomic_write_u64(&var, 3);
597 3);
603
604 /* fail exchange because of old expected */
605 expected = 10;
606 EXPECT_TRUE(!pg_atomic_compare_exchange_u64(&var, &expected, 1));
607
608 /* CAS is allowed to fail due to interrupts, try a couple of times */
609 for (i = 0; i < 100; i++)
610 {
611 expected = 0;
612 if (!pg_atomic_compare_exchange_u64(&var, &expected, 1))
613 break;
614 }
615 if (i == 100)
616 elog(ERROR, "atomic_compare_exchange_u64() never succeeded");
618
619 pg_atomic_write_u64(&var, 0);
620
621 /* try setting flagbits */
622 EXPECT_TRUE(!(pg_atomic_fetch_or_u64(&var, 1) & 1));
625 /* try clearing flagbits */
626 EXPECT_EQ_U64((pg_atomic_fetch_and_u64(&var, ~2) & 3), 3);
628 /* no bits set anymore */
630}
static void pg_atomic_write_u64(volatile pg_atomic_uint64 *ptr, uint64 val)
Definition: atomics.h:483
static bool pg_atomic_compare_exchange_u64(volatile pg_atomic_uint64 *ptr, uint64 *expected, uint64 newval)
Definition: atomics.h:520
static uint64 pg_atomic_fetch_add_u64(volatile pg_atomic_uint64 *ptr, int64 add_)
Definition: atomics.h:530
static uint64 pg_atomic_sub_fetch_u64(volatile pg_atomic_uint64 *ptr, int64 sub_)
Definition: atomics.h:576
static uint64 pg_atomic_fetch_and_u64(volatile pg_atomic_uint64 *ptr, uint64 and_)
Definition: atomics.h:549
static uint64 pg_atomic_fetch_or_u64(volatile pg_atomic_uint64 *ptr, uint64 or_)
Definition: atomics.h:558
static uint64 pg_atomic_add_fetch_u64(volatile pg_atomic_uint64 *ptr, int64 add_)
Definition: atomics.h:567
static void pg_atomic_init_u64(volatile pg_atomic_uint64 *ptr, uint64 val)
Definition: atomics.h:451
static uint64 pg_atomic_read_u64(volatile pg_atomic_uint64 *ptr)
Definition: atomics.h:465
static uint64 pg_atomic_fetch_sub_u64(volatile pg_atomic_uint64 *ptr, int64 sub_)
Definition: atomics.h:539
static uint64 pg_atomic_exchange_u64(volatile pg_atomic_uint64 *ptr, uint64 newval)
Definition: atomics.h:511
uint64_t uint64
Definition: c.h:542
#define EXPECT_EQ_U64(result_expr, expected_expr)
Definition: regress.c:69

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

327{
328 char *path = text_to_cstring(PG_GETARG_TEXT_PP(0));
329
330 canonicalize_path(path);
332}
#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:181

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

1001{
1002 bytea *string = PG_GETARG_BYTEA_PP(0);
1003 char *src_encoding_name = NameStr(*PG_GETARG_NAME(1));
1004 int src_encoding = pg_char_to_encoding(src_encoding_name);
1005 char *dest_encoding_name = NameStr(*PG_GETARG_NAME(2));
1006 int dest_encoding = pg_char_to_encoding(dest_encoding_name);
1007 bool noError = PG_GETARG_BOOL(3);
1008 TupleDesc tupdesc;
1009 char *src;
1010 char *dst;
1011 bytea *retval;
1012 Size srclen;
1013 Size dstsize;
1014 Oid proc;
1015 int convertedbytes;
1016 int dstlen;
1017 Datum values[2];
1018 bool nulls[2] = {0};
1019 HeapTuple tuple;
1020
1021 if (src_encoding < 0)
1022 ereport(ERROR,
1023 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1024 errmsg("invalid source encoding name \"%s\"",
1025 src_encoding_name)));
1026 if (dest_encoding < 0)
1027 ereport(ERROR,
1028 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1029 errmsg("invalid destination encoding name \"%s\"",
1030 dest_encoding_name)));
1031
1032 /* Build a tuple descriptor for our result type */
1033 if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
1034 elog(ERROR, "return type must be a row type");
1035 tupdesc = BlessTupleDesc(tupdesc);
1036
1037 srclen = VARSIZE_ANY_EXHDR(string);
1038 src = VARDATA_ANY(string);
1039
1040 if (src_encoding == dest_encoding)
1041 {
1042 /* just check that the source string is valid */
1043 int oklen;
1044
1045 oklen = pg_encoding_verifymbstr(src_encoding, src, srclen);
1046
1047 if (oklen == srclen)
1048 {
1049 convertedbytes = oklen;
1050 retval = string;
1051 }
1052 else if (!noError)
1053 {
1054 report_invalid_encoding(src_encoding, src + oklen, srclen - oklen);
1055 }
1056 else
1057 {
1058 /*
1059 * build bytea data type structure.
1060 */
1061 Assert(oklen < srclen);
1062 convertedbytes = oklen;
1063 retval = (bytea *) palloc(oklen + VARHDRSZ);
1064 SET_VARSIZE(retval, oklen + VARHDRSZ);
1065 memcpy(VARDATA(retval), src, oklen);
1066 }
1067 }
1068 else
1069 {
1070 proc = FindDefaultConversionProc(src_encoding, dest_encoding);
1071 if (!OidIsValid(proc))
1072 ereport(ERROR,
1073 (errcode(ERRCODE_UNDEFINED_FUNCTION),
1074 errmsg("default conversion function for encoding \"%s\" to \"%s\" does not exist",
1075 pg_encoding_to_char(src_encoding),
1076 pg_encoding_to_char(dest_encoding))));
1077
1078 if (srclen >= (MaxAllocSize / (Size) MAX_CONVERSION_GROWTH))
1079 ereport(ERROR,
1080 (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
1081 errmsg("out of memory"),
1082 errdetail("String of %d bytes is too long for encoding conversion.",
1083 (int) srclen)));
1084
1085 dstsize = (Size) srclen * MAX_CONVERSION_GROWTH + 1;
1087
1088 /* perform conversion */
1089 convertedbytes = pg_do_encoding_conversion_buf(proc,
1090 src_encoding,
1091 dest_encoding,
1092 (unsigned char *) src, srclen,
1093 (unsigned char *) dst, dstsize,
1094 noError);
1095 dstlen = strlen(dst);
1096
1097 /*
1098 * build bytea data type structure.
1099 */
1100 retval = (bytea *) palloc(dstlen + VARHDRSZ);
1101 SET_VARSIZE(retval, dstlen + VARHDRSZ);
1102 memcpy(VARDATA(retval), dst, dstlen);
1103
1104 pfree(dst);
1105 }
1106
1107 values[0] = Int32GetDatum(convertedbytes);
1108 values[1] = PointerGetDatum(retval);
1109 tuple = heap_form_tuple(tupdesc, values, nulls);
1110
1112}
#define NameStr(name)
Definition: c.h:754
#define VARHDRSZ
Definition: c.h:700
#define OidIsValid(objectId)
Definition: c.h:777
size_t Size
Definition: c.h:613
int errdetail(const char *fmt,...)
Definition: elog.c:1216
int errcode(int sqlerrcode)
Definition: elog.c:863
int errmsg(const char *fmt,...)
Definition: elog.c:1080
#define ereport(elevel,...)
Definition: elog.h:150
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:470
void report_invalid_encoding(int encoding, const char *mbstr, int len)
Definition: mbutils.c:1699
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:1229
MemoryContext CurrentMemoryContext
Definition: mcxt.c:160
Oid FindDefaultConversionProc(int32 for_encoding, int32 to_encoding)
Definition: namespace.c:4150
#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:222
char string[11]
Definition: preproc-type.c:52
static Size VARSIZE_ANY_EXHDR(const void *PTR)
Definition: varatt.h:472
static char * VARDATA(const void *PTR)
Definition: varatt.h:305
static char * VARDATA_ANY(const void *PTR)
Definition: varatt.h:486
static void SET_VARSIZE(void *PTR, Size len)
Definition: varatt.h:432
int pg_encoding_verifymbstr(int encoding, const char *mbstr, int len)
Definition: wchar.c:2202

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

938{
939 /* Test pg_encoding_set_invalid() */
940 for (int i = 0; i < _PG_LAST_ENCODING_; i++)
941 {
942 char buf[2],
943 bigbuf[16];
944 int len,
945 mblen,
946 valid;
947
948 if (pg_encoding_max_length(i) == 1)
949 continue;
951 len = strnlen(buf, 2);
952 if (len != 2)
954 "official invalid string for encoding \"%s\" has length %d",
956 mblen = pg_encoding_mblen(i, buf);
957 if (mblen != 2)
959 "official invalid string for encoding \"%s\" has mblen %d",
960 pg_enc2name_tbl[i].name, mblen);
961 valid = pg_encoding_verifymbstr(i, buf, len);
962 if (valid != 0)
964 "official invalid string for encoding \"%s\" has valid prefix of length %d",
965 pg_enc2name_tbl[i].name, valid);
966 valid = pg_encoding_verifymbstr(i, buf, 1);
967 if (valid != 0)
969 "first byte of official invalid string for encoding \"%s\" has valid prefix of length %d",
970 pg_enc2name_tbl[i].name, valid);
971 memset(bigbuf, ' ', sizeof(bigbuf));
972 bigbuf[0] = buf[0];
973 bigbuf[1] = buf[1];
974 valid = pg_encoding_verifymbstr(i, bigbuf, sizeof(bigbuf));
975 if (valid != 0)
977 "trailing data changed official invalid string for encoding \"%s\" to have valid prefix of length %d",
978 pg_enc2name_tbl[i].name, valid);
979 }
980
982}
#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:2051
int pg_encoding_max_length(int encoding)
Definition: wchar.c:2213
int pg_encoding_mblen(int encoding, const char *mbstr)
Definition: wchar.c:2135

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

723{
724 elog(ERROR, "test_fdw_handler is not implemented");
726}

References elog, ERROR, and PG_RETURN_NULL.

◆ test_inline_in_from_support_func()

Datum test_inline_in_from_support_func ( PG_FUNCTION_ARGS  )

Definition at line 810 of file regress.c.

811{
812 Node *rawreq = (Node *) PG_GETARG_POINTER(0);
813
814 if (IsA(rawreq, SupportRequestInlineInFrom))
815 {
816 /*
817 * Assume that the target is foo_from_bar; that's safe as long as we
818 * don't attach this to any other function.
819 */
821 StringInfoData sql;
822 RangeTblFunction *rtfunc = req->rtfunc;
823 FuncExpr *expr = (FuncExpr *) rtfunc->funcexpr;
824 Node *node;
825 Const *c;
826 char *colname;
827 char *tablename;
829 List *raw_parsetree_list;
830 List *querytree_list;
832
833 if (list_length(expr->args) != 3)
834 {
835 ereport(WARNING, (errmsg("test_inline_in_from_support_func called with %d args but expected 3", list_length(expr->args))));
836 PG_RETURN_POINTER(NULL);
837 }
838
839 /* Get colname */
840 node = linitial(expr->args);
841 if (!IsA(node, Const))
842 {
843 ereport(WARNING, (errmsg("test_inline_in_from_support_func called with non-Const parameters")));
844 PG_RETURN_POINTER(NULL);
845 }
846
847 c = (Const *) node;
848 if (c->consttype != TEXTOID || c->constisnull)
849 {
850 ereport(WARNING, (errmsg("test_inline_in_from_support_func called with non-TEXT parameters")));
851 PG_RETURN_POINTER(NULL);
852 }
853 colname = TextDatumGetCString(c->constvalue);
854
855 /* Get tablename */
856 node = lsecond(expr->args);
857 if (!IsA(node, Const))
858 {
859 ereport(WARNING, (errmsg("test_inline_in_from_support_func called with non-Const parameters")));
860 PG_RETURN_POINTER(NULL);
861 }
862
863 c = (Const *) node;
864 if (c->consttype != TEXTOID || c->constisnull)
865 {
866 ereport(WARNING, (errmsg("test_inline_in_from_support_func called with non-TEXT parameters")));
867 PG_RETURN_POINTER(NULL);
868 }
869 tablename = TextDatumGetCString(c->constvalue);
870
871 /* Begin constructing replacement SELECT query. */
872 initStringInfo(&sql);
873 appendStringInfo(&sql, "SELECT %s::text FROM %s",
874 quote_identifier(colname),
875 quote_identifier(tablename));
876
877 /* Add filter expression if present. */
878 node = lthird(expr->args);
879 if (!(IsA(node, Const) && ((Const *) node)->constisnull))
880 {
881 /*
882 * We only filter if $3 is not constant-NULL. This is not a very
883 * exact implementation of the PL/pgSQL original, but it's close
884 * enough for demonstration purposes.
885 */
886 appendStringInfo(&sql, " WHERE %s::text = $3",
887 quote_identifier(colname));
888 }
889
890 /* Build a SQLFunctionParseInfo with the parameters of my function. */
891 pinfo = prepare_sql_fn_parse_info(req->proc,
892 (Node *) expr,
893 expr->inputcollid);
894
895 /* Parse the generated SQL. */
896 raw_parsetree_list = pg_parse_query(sql.data);
897 if (list_length(raw_parsetree_list) != 1)
898 {
899 ereport(WARNING, (errmsg("test_inline_in_from_support_func parsed to more than one node")));
900 PG_RETURN_POINTER(NULL);
901 }
902
903 /* Analyze the parse tree as if it were a SQL-language body. */
904 querytree_list = pg_analyze_and_rewrite_withcb(linitial(raw_parsetree_list),
905 sql.data,
907 pinfo, NULL);
908 if (list_length(querytree_list) != 1)
909 {
910 ereport(WARNING, (errmsg("test_inline_in_from_support_func rewrote to more than one node")));
911 PG_RETURN_POINTER(NULL);
912 }
913
914 querytree = linitial(querytree_list);
915 if (!IsA(querytree, Query))
916 {
917 ereport(WARNING, (errmsg("test_inline_in_from_support_func didn't parse to a Query")));
918 PG_RETURN_POINTER(NULL);
919 }
920
922 }
923
924 PG_RETURN_POINTER(NULL);
925}
Datum querytree(PG_FUNCTION_ARGS)
Definition: _int_bool.c:665
#define TextDatumGetCString(d)
Definition: builtins.h:98
void sql_fn_parser_setup(struct ParseState *pstate, SQLFunctionParseInfoPtr pinfo)
Definition: functions.c:340
SQLFunctionParseInfoPtr prepare_sql_fn_parse_info(HeapTuple procedureTuple, Node *call_expr, Oid inputCollation)
Definition: functions.c:251
if(TABLE==NULL||TABLE_index==NULL)
Definition: isn.c:81
#define IsA(nodeptr, _type_)
Definition: nodes.h:164
void(* ParserSetupHook)(ParseState *pstate, void *arg)
Definition: params.h:107
static int list_length(const List *l)
Definition: pg_list.h:152
#define lthird(l)
Definition: pg_list.h:188
#define linitial(l)
Definition: pg_list.h:178
#define lsecond(l)
Definition: pg_list.h:183
List * pg_analyze_and_rewrite_withcb(RawStmt *parsetree, const char *query_string, ParserSetupHook parserSetup, void *parserSetupArg, QueryEnvironment *queryEnv)
Definition: postgres.c:763
List * pg_parse_query(const char *query_string)
Definition: postgres.c:604
char * c
const char * quote_identifier(const char *ident)
Definition: ruleutils.c:13062
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:145
void initStringInfo(StringInfo str)
Definition: stringinfo.c:97
List * args
Definition: primnodes.h:800
Definition: pg_list.h:54
Definition: nodes.h:135
RangeTblFunction * rtfunc
Definition: supportnodes.h:123

References appendStringInfo(), FuncExpr::args, StringInfoData::data, ereport, errmsg(), RangeTblFunction::funcexpr, if(), initStringInfo(), IsA, linitial, list_length(), lsecond, lthird, pg_analyze_and_rewrite_withcb(), PG_GETARG_POINTER, pg_parse_query(), PG_RETURN_POINTER, prepare_sql_fn_parse_info(), SupportRequestInlineInFrom::proc, querytree(), quote_identifier(), SupportRequestInlineInFrom::rtfunc, sql_fn_parser_setup(), TextDatumGetCString, and WARNING.

◆ test_opclass_options_func()

Datum test_opclass_options_func ( PG_FUNCTION_ARGS  )

Definition at line 929 of file regress.c.

930{
932}

References PG_RETURN_NULL.

◆ test_relpath()

Datum test_relpath ( PG_FUNCTION_ARGS  )

Definition at line 1130 of file regress.c.

1131{
1132 RelPathStr rpath;
1133
1134 /*
1135 * Verify that PROCNUMBER_CHARS and MAX_BACKENDS stay in sync.
1136 * Unfortunately I don't know how to express that in a way suitable for a
1137 * static assert.
1138 */
1139 if ((int) ceil(log10(MAX_BACKENDS)) != PROCNUMBER_CHARS)
1140 elog(WARNING, "mismatch between MAX_BACKENDS and PROCNUMBER_CHARS");
1141
1142 /* verify that the max-length relpath is generated ok */
1144 INIT_FORKNUM);
1145
1146 if (strlen(rpath.str) != REL_PATH_STR_MAXLEN)
1147 elog(WARNING, "maximum length relpath is if length %zu instead of %zu",
1148 strlen(rpath.str), REL_PATH_STR_MAXLEN);
1149
1151}
#define OID_MAX
Definition: postgres_ext.h:40
#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 639 of file regress.c.

640{
641 /*
642 * Basic tests for spinlocks, as well as the underlying operations.
643 *
644 * We embed the spinlock in a struct with other members to test that the
645 * spinlock operations don't perform too wide writes.
646 */
647 {
648 struct test_lock_struct
649 {
650 char data_before[4];
651 slock_t lock;
652 char data_after[4];
653 } struct_w_lock;
654
655 memcpy(struct_w_lock.data_before, "abcd", 4);
656 memcpy(struct_w_lock.data_after, "ef12", 4);
657
658 /* test basic operations via the SpinLock* API */
659 SpinLockInit(&struct_w_lock.lock);
660 SpinLockAcquire(&struct_w_lock.lock);
661 SpinLockRelease(&struct_w_lock.lock);
662
663 /* test basic operations via underlying S_* API */
664 S_INIT_LOCK(&struct_w_lock.lock);
665 S_LOCK(&struct_w_lock.lock);
666 S_UNLOCK(&struct_w_lock.lock);
667
668 /* and that "contended" acquisition works */
669 s_lock(&struct_w_lock.lock, "testfile", 17, "testfunc");
670 S_UNLOCK(&struct_w_lock.lock);
671
672 /*
673 * Check, using TAS directly, that a single spin cycle doesn't block
674 * when acquiring an already acquired lock.
675 */
676#ifdef TAS
677 S_LOCK(&struct_w_lock.lock);
678
679 if (!TAS(&struct_w_lock.lock))
680 elog(ERROR, "acquired already held spinlock");
681
682#ifdef TAS_SPIN
683 if (!TAS_SPIN(&struct_w_lock.lock))
684 elog(ERROR, "acquired already held spinlock");
685#endif /* defined(TAS_SPIN) */
686
687 S_UNLOCK(&struct_w_lock.lock);
688#endif /* defined(TAS) */
689
690 /*
691 * Verify that after all of this the non-lock contents are still
692 * correct.
693 */
694 if (memcmp(struct_w_lock.data_before, "abcd", 4) != 0)
695 elog(ERROR, "padding before spinlock modified");
696 if (memcmp(struct_w_lock.data_after, "ef12", 4) != 0)
697 elog(ERROR, "padding after spinlock modified");
698 }
699}
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:688
#define S_UNLOCK(lock)
Definition: s_lock.h:673
#define TAS_SPIN(lock)
Definition: s_lock.h:692
#define S_INIT_LOCK(lock)
Definition: s_lock.h:677
#define S_LOCK(lock)
Definition: s_lock.h:646
#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 737 of file regress.c.

738{
739 Node *rawreq = (Node *) PG_GETARG_POINTER(0);
740 Node *ret = NULL;
741
742 if (IsA(rawreq, SupportRequestSelectivity))
743 {
744 /*
745 * Assume that the target is int4eq; that's safe as long as we don't
746 * attach this to any other boolean-returning function.
747 */
750
751 if (req->is_join)
752 s1 = join_selectivity(req->root, Int4EqualOperator,
753 req->args,
754 req->inputcollid,
755 req->jointype,
756 req->sjinfo);
757 else
758 s1 = restriction_selectivity(req->root, Int4EqualOperator,
759 req->args,
760 req->inputcollid,
761 req->varRelid);
762
763 req->selectivity = s1;
764 ret = (Node *) req;
765 }
766
767 if (IsA(rawreq, SupportRequestCost))
768 {
769 /* Provide some generic estimate */
770 SupportRequestCost *req = (SupportRequestCost *) rawreq;
771
772 req->startup = 0;
773 req->per_tuple = 2 * cpu_operator_cost;
774 ret = (Node *) req;
775 }
776
777 if (IsA(rawreq, SupportRequestRows))
778 {
779 /*
780 * Assume that the target is generate_series_int4; that's safe as long
781 * as we don't attach this to any other set-returning function.
782 */
783 SupportRequestRows *req = (SupportRequestRows *) rawreq;
784
785 if (req->node && IsA(req->node, FuncExpr)) /* be paranoid */
786 {
787 List *args = ((FuncExpr *) req->node)->args;
788 Node *arg1 = linitial(args);
789 Node *arg2 = lsecond(args);
790
791 if (IsA(arg1, Const) &&
792 !((Const *) arg1)->constisnull &&
793 IsA(arg2, Const) &&
794 !((Const *) arg2)->constisnull)
795 {
796 int32 val1 = DatumGetInt32(((Const *) arg1)->constvalue);
797 int32 val2 = DatumGetInt32(((Const *) arg2)->constvalue);
798
799 req->rows = val2 - val1 + 1;
800 ret = (Node *) req;
801 }
802 }
803 }
804
806}
double cpu_operator_cost
Definition: costsize.c:134
double Selectivity
Definition: nodes.h:260
Selectivity restriction_selectivity(PlannerInfo *root, Oid operatorid, List *args, Oid inputcollid, int varRelid)
Definition: plancat.c:2183
Selectivity join_selectivity(PlannerInfo *root, Oid operatorid, List *args, Oid inputcollid, JoinType jointype, SpecialJoinInfo *sjinfo)
Definition: plancat.c:2222
char * s1
SpecialJoinInfo * sjinfo
Definition: supportnodes.h:158

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

260{
261 TriggerData *trigdata = (TriggerData *) fcinfo->context;
262 HeapTuple tuple;
263
264 if (!CALLED_AS_TRIGGER(fcinfo))
265 elog(ERROR, "trigger_return_old: not fired by trigger manager");
266
267 tuple = trigdata->tg_trigtuple;
268
269 return PointerGetDatum(tuple);
270}
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.

◆ wait_pid()

Datum wait_pid ( PG_FUNCTION_ARGS  )

Definition at line 478 of file regress.c.

479{
480 int pid = PG_GETARG_INT32(0);
481
482 if (!superuser())
483 elog(ERROR, "must be superuser to check PID liveness");
484
485 while (kill(pid, 0) == 0)
486 {
488 pg_usleep(50000);
489 }
490
491 if (errno != ESRCH)
492 elog(ERROR, "could not check PID %d liveness: %m", pid);
493
495}
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:123
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 176 of file regress.c.

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

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

211{
212 WIDGET *widget = (WIDGET *) PG_GETARG_POINTER(0);
213 char *str = psprintf("(%g,%g,%g)",
214 widget->center.x, widget->center.y, widget->radius);
215
217}
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.