PostgreSQL Source Code git master
Loading...
Searching...
No Matches
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 TEXTDOMAIN   PG_TEXTDOMAIN("postgresql-regress")
 
#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)
 
 PG_FUNCTION_INFO_V1 (test_translation)
 
Datum test_translation (PG_FUNCTION_ARGS)
 

Macro Definition Documentation

◆ DELIM

#define DELIM   ','

Definition at line 85 of file regress.c.

◆ EXPECT_EQ_U32

#define EXPECT_EQ_U32 (   result_expr,
  expected_expr 
)
Value:
do { \
"%s yielded %u, expected %s in file \"%s\" line %u", \
} while (0)
uint32_t uint32
Definition c.h:546
#define ERROR
Definition elog.h:39
static int fb(int x)

Definition at line 63 of file regress.c.

64 { \
68 elog(ERROR, \
69 "%s yielded %u, expected %s in file \"%s\" line %u", \
71 } while (0)

◆ EXPECT_EQ_U64

#define EXPECT_EQ_U64 (   result_expr,
  expected_expr 
)
Value:
do { \
"%s yielded " UINT64_FORMAT ", expected %s in file \"%s\" line %u", \
} while (0)
#define UINT64_FORMAT
Definition c.h:565
uint64_t uint64
Definition c.h:547

Definition at line 73 of file regress.c.

74 { \
78 elog(ERROR, \
79 "%s yielded " UINT64_FORMAT ", expected %s in file \"%s\" line %u", \
81 } while (0)

◆ EXPECT_TRUE

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

Definition at line 55 of file regress.c.

56 { \
57 if (!(expr)) \
58 elog(ERROR, \
59 "%s was unexpectedly false in file \"%s\" line %u", \
60 #expr, __FILE__, __LINE__); \
61 } while (0)

◆ LDELIM

#define LDELIM   '('

Definition at line 83 of file regress.c.

◆ NARGS

#define NARGS   3

Definition at line 177 of file regress.c.

◆ RDELIM

#define RDELIM   ')'

Definition at line 84 of file regress.c.

◆ TEXTDOMAIN

#define TEXTDOMAIN   PG_TEXTDOMAIN("postgresql-regress")

Definition at line 53 of file regress.c.

Function Documentation

◆ binary_coercible()

Datum binary_coercible ( PG_FUNCTION_ARGS  )

Definition at line 1121 of file regress.c.

1122{
1123 Oid srctype = PG_GETARG_OID(0);
1124 Oid targettype = PG_GETARG_OID(1);
1125
1126 PG_RETURN_BOOL(IsBinaryCoercible(srctype, targettype));
1127}
#define PG_GETARG_OID(n)
Definition fmgr.h:275
#define PG_RETURN_BOOL(x)
Definition fmgr.h:360
bool IsBinaryCoercible(Oid srctype, Oid targettype)
unsigned int Oid

References IsBinaryCoercible(), PG_GETARG_OID, and PG_RETURN_BOOL.

◆ get_environ()

Datum get_environ ( PG_FUNCTION_ARGS  )

Definition at line 439 of file regress.c.

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

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

◆ int44in()

Datum int44in ( PG_FUNCTION_ARGS  )

Definition at line 290 of file regress.c.

291{
293 int32 *result = (int32 *) palloc(4 * sizeof(int32));
294 int i;
295
297 "%d, %d, %d, %d",
298 &result[0],
299 &result[1],
300 &result[2],
301 &result[3]);
302 while (i < 4)
303 result[i++] = 0;
304
305 PG_RETURN_POINTER(result);
306}
int32_t int32
Definition c.h:542
#define PG_GETARG_CSTRING(n)
Definition fmgr.h:278

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

◆ int44out()

Datum int44out ( PG_FUNCTION_ARGS  )

Definition at line 314 of file regress.c.

315{
317 char *result = (char *) palloc(16 * 4);
318
319 snprintf(result, 16 * 4, "%d,%d,%d,%d",
320 an_array[0],
321 an_array[1],
322 an_array[2],
323 an_array[3]);
324
325 PG_RETURN_CSTRING(result);
326}
#define PG_GETARG_POINTER(n)
Definition fmgr.h:277
#define PG_RETURN_CSTRING(x)
Definition fmgr.h:364
#define snprintf
Definition port.h:260

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

◆ interpt_pp()

Datum interpt_pp ( PG_FUNCTION_ARGS  )

Definition at line 99 of file regress.c.

100{
103 int i,
104 j;
105 LSEG seg1,
106 seg2;
107 bool found; /* We've found the intersection */
108
109 found = false; /* Haven't found it yet */
110
111 for (i = 0; i < p1->npts - 1 && !found; i++)
112 {
113 regress_lseg_construct(&seg1, &p1->p[i], &p1->p[i + 1]);
114 for (j = 0; j < p2->npts - 1 && !found; j++)
115 {
116 regress_lseg_construct(&seg2, &p2->p[j], &p2->p[j + 1]);
120 found = true;
121 }
122 }
123
124 if (!found)
126
127 /*
128 * Note: DirectFunctionCall2 will kick out an error if lseg_interpt()
129 * returns NULL, but that should be impossible since we know the two
130 * segments intersect.
131 */
135}
#define DirectFunctionCall2(func, arg1, arg2)
Definition fmgr.h:686
#define PG_RETURN_NULL()
Definition fmgr.h:346
#define PG_RETURN_DATUM(x)
Definition fmgr.h:354
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:140

References DatumGetBool(), DirectFunctionCall2, fb(), i, j, lseg_interpt(), lseg_intersect(), LsegPGetDatum(), 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 734 of file regress.c.

735{
737}
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 340 of file regress.c.

341{
343 HeapTupleData tuple;
344 int ncolumns;
345 Datum *values;
346 bool *nulls;
347
348 Oid tupType;
350 TupleDesc tupdesc;
351
353
354 int i;
355
357
358 /* Extract type info from the tuple itself */
362 ncolumns = tupdesc->natts;
363
364 /* Build a temporary HeapTuple control structure */
367 tuple.t_tableOid = InvalidOid;
368 tuple.t_data = rec;
369
370 values = (Datum *) palloc(ncolumns * sizeof(Datum));
371 nulls = (bool *) palloc(ncolumns * sizeof(bool));
372
373 heap_deform_tuple(&tuple, tupdesc, values, nulls);
374
376
377 for (i = 0; i < ncolumns; i++)
378 {
379 struct varlena *attr;
380 struct varlena *new_attr;
382
383 /* only work on existing, not-null varlenas */
384 if (TupleDescAttr(tupdesc, i)->attisdropped ||
385 nulls[i] ||
386 TupleDescAttr(tupdesc, i)->attlen != -1 ||
388 continue;
389
390 attr = (struct varlena *) DatumGetPointer(values[i]);
391
392 /* don't recursively indirect */
394 continue;
395
396 /* copy datum, so it still lives later */
398 attr = detoast_external_attr(attr);
399 else
400 {
401 struct varlena *oldattr = attr;
402
403 attr = palloc0(VARSIZE_ANY(oldattr));
405 }
406
407 /* build indirection Datum */
409 redirect_pointer.pointer = attr;
412 sizeof(redirect_pointer));
413
415 }
416
417 newtup = heap_form_tuple(tupdesc, values, nulls);
418 pfree(values);
419 pfree(nulls);
420 ReleaseTupleDesc(tupdesc);
421
423
424 /*
425 * We intentionally don't use PG_RETURN_HEAPTUPLEHEADER here, because that
426 * would cause the indirect toast pointers to be flattened out of the
427 * tuple immediately, rendering subsequent testing irrelevant. So just
428 * return the HeapTupleHeader pointer as-is. This violates the general
429 * rule that composite Datums shouldn't contain toast pointers, but so
430 * long as the regression test scripts don't insert the result of this
431 * function into a container type (record, array, etc) it should be OK.
432 */
433 PG_RETURN_POINTER(newtup->t_data);
434}
static Datum values[MAXATTR]
Definition bootstrap.c:155
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:313
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)
static uint32 HeapTupleHeaderGetDatumLength(const HeapTupleHeaderData *tup)
static Oid HeapTupleHeaderGetTypeId(const HeapTupleHeaderData *tup)
static void ItemPointerSetInvalid(ItemPointerData *pointer)
Definition itemptr.h:184
MemoryContext TopTransactionContext
Definition mcxt.c:171
void pfree(void *pointer)
Definition mcxt.c:1616
void * palloc0(Size size)
Definition mcxt.c:1417
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition palloc.h:124
char attstorage
int16 attlen
static Datum PointerGetDatum(const void *X)
Definition postgres.h:352
static Pointer DatumGetPointer(Datum X)
Definition postgres.h:342
#define InvalidOid
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:706
#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(), fb(), 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, 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 151 of file regress.c.

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

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

◆ PG_FUNCTION_INFO_V1() [1/25]

PG_FUNCTION_INFO_V1 ( binary_coercible  )

◆ PG_FUNCTION_INFO_V1() [2/25]

PG_FUNCTION_INFO_V1 ( get_environ  )

◆ PG_FUNCTION_INFO_V1() [3/25]

PG_FUNCTION_INFO_V1 ( int44in  )

◆ PG_FUNCTION_INFO_V1() [4/25]

PG_FUNCTION_INFO_V1 ( int44out  )

◆ PG_FUNCTION_INFO_V1() [5/25]

PG_FUNCTION_INFO_V1 ( interpt_pp  )

◆ PG_FUNCTION_INFO_V1() [6/25]

PG_FUNCTION_INFO_V1 ( is_catalog_text_unique_index_oid  )

◆ PG_FUNCTION_INFO_V1() [7/25]

PG_FUNCTION_INFO_V1 ( make_tuple_indirect  )

◆ PG_FUNCTION_INFO_V1() [8/25]

PG_FUNCTION_INFO_V1 ( overpaid  )

◆ PG_FUNCTION_INFO_V1() [9/25]

PG_FUNCTION_INFO_V1 ( pt_in_widget  )

◆ PG_FUNCTION_INFO_V1() [10/25]

PG_FUNCTION_INFO_V1 ( regress_setenv  )

◆ PG_FUNCTION_INFO_V1() [11/25]

PG_FUNCTION_INFO_V1 ( reverse_name  )

◆ PG_FUNCTION_INFO_V1() [12/25]

PG_FUNCTION_INFO_V1 ( test_atomic_ops  )

◆ PG_FUNCTION_INFO_V1() [13/25]

PG_FUNCTION_INFO_V1 ( test_canonicalize_path  )

◆ PG_FUNCTION_INFO_V1() [14/25]

PG_FUNCTION_INFO_V1 ( test_enc_conversion  )

◆ PG_FUNCTION_INFO_V1() [15/25]

PG_FUNCTION_INFO_V1 ( test_enc_setup  )

◆ PG_FUNCTION_INFO_V1() [16/25]

PG_FUNCTION_INFO_V1 ( test_fdw_handler  )

◆ PG_FUNCTION_INFO_V1() [17/25]

PG_FUNCTION_INFO_V1 ( test_inline_in_from_support_func  )

◆ PG_FUNCTION_INFO_V1() [18/25]

PG_FUNCTION_INFO_V1 ( test_opclass_options_func  )

◆ PG_FUNCTION_INFO_V1() [19/25]

PG_FUNCTION_INFO_V1 ( test_relpath  )

◆ PG_FUNCTION_INFO_V1() [20/25]

PG_FUNCTION_INFO_V1 ( test_support_func  )

◆ PG_FUNCTION_INFO_V1() [21/25]

PG_FUNCTION_INFO_V1 ( test_translation  )

◆ PG_FUNCTION_INFO_V1() [22/25]

PG_FUNCTION_INFO_V1 ( trigger_return_old  )

◆ PG_FUNCTION_INFO_V1() [23/25]

PG_FUNCTION_INFO_V1 ( wait_pid  )

◆ PG_FUNCTION_INFO_V1() [24/25]

PG_FUNCTION_INFO_V1 ( widget_in  )

◆ PG_FUNCTION_INFO_V1() [25/25]

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

227{
230 float8 distance;
231
234 PointPGetDatum(&widget->center)));
235
237}
double float8
Definition c.h:644
#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:495

References DatumGetFloat8(), DirectFunctionCall2, fb(), 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 140 of file regress.c.

141{
142 lseg->p[0].x = pt1->x;
143 lseg->p[0].y = pt1->y;
144 lseg->p[1].x = pt2->x;
145 lseg->p[1].y = pt2->y;
146}

References fb().

Referenced by interpt_pp().

◆ regress_setenv()

Datum regress_setenv ( PG_FUNCTION_ARGS  )

Definition at line 464 of file regress.c.

465{
466 char *envvar = text_to_cstring(PG_GETARG_TEXT_PP(0));
468
469 if (!superuser())
470 elog(ERROR, "must be superuser to change environment variables");
471
472 if (setenv(envvar, envval, 1) != 0)
473 elog(ERROR, "could not set environment variable: %m");
474
476}
#define elog(elevel,...)
Definition elog.h:226
#define PG_RETURN_VOID()
Definition fmgr.h:350
#define PG_GETARG_TEXT_PP(n)
Definition fmgr.h:310
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:542

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

◆ reverse_name()

Datum reverse_name ( PG_FUNCTION_ARGS  )

Definition at line 242 of file regress.c.

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

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

◆ test_atomic_flag()

static void test_atomic_flag ( void  )
static

Definition at line 502 of file regress.c.

503{
505
515}
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:55
char * flag(int b)
Definition test-ctype.c:33

References EXPECT_TRUE, fb(), 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 707 of file regress.c.

708{
710
712
714
715 /*
716 * Arguably this shouldn't be tested as part of this function, but it's
717 * closely enough related that that seems ok for now.
718 */
720
721 PG_RETURN_BOOL(true);
722}
static void test_spinlock(void)
Definition regress.c:643
static void test_atomic_uint32(void)
Definition regress.c:518
static void test_atomic_flag(void)
Definition regress.c:502
static void test_atomic_uint64(void)
Definition regress.c:590

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

519{
522 int i;
523
524 pg_atomic_init_u32(&var, 0);
526 pg_atomic_write_u32(&var, 3);
529 3);
535
536 /* test around numerical limits */
539 pg_atomic_fetch_add_u32(&var, 2); /* wrap to 0 */
544 2 * PG_INT16_MAX + 1);
547 pg_atomic_fetch_add_u32(&var, 1); /* top up to UINT_MAX */
561
562 /* fail exchange because of old expected */
563 expected = 10;
565
566 /* CAS is allowed to fail due to interrupts, try a couple of times */
567 for (i = 0; i < 1000; i++)
568 {
569 expected = 0;
571 break;
572 }
573 if (i == 1000)
574 elog(ERROR, "atomic_compare_exchange_u32() never succeeded");
576 pg_atomic_write_u32(&var, 0);
577
578 /* try setting flagbits */
579 EXPECT_TRUE(!(pg_atomic_fetch_or_u32(&var, 1) & 1));
582 /* try clearing flagbits */
583 EXPECT_EQ_U32(pg_atomic_fetch_and_u32(&var, ~2) & 3, 3);
585 /* no bits set anymore */
587}
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:219
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: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:330
#define PG_INT16_MIN
Definition c.h:599
#define PG_INT16_MAX
Definition c.h:600
#define EXPECT_EQ_U32(result_expr, expected_expr)
Definition regress.c:63

References elog, ERROR, EXPECT_EQ_U32, EXPECT_TRUE, fb(), 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 590 of file regress.c.

591{
594 int i;
595
596 pg_atomic_init_u64(&var, 0);
598 pg_atomic_write_u64(&var, 3);
601 3);
607
608 /* fail exchange because of old expected */
609 expected = 10;
611
612 /* CAS is allowed to fail due to interrupts, try a couple of times */
613 for (i = 0; i < 100; i++)
614 {
615 expected = 0;
617 break;
618 }
619 if (i == 100)
620 elog(ERROR, "atomic_compare_exchange_u64() never succeeded");
622
623 pg_atomic_write_u64(&var, 0);
624
625 /* try setting flagbits */
626 EXPECT_TRUE(!(pg_atomic_fetch_or_u64(&var, 1) & 1));
629 /* try clearing flagbits */
630 EXPECT_EQ_U64((pg_atomic_fetch_and_u64(&var, ~2) & 3), 3);
632 /* no bits set anymore */
634}
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:522
static uint64 pg_atomic_fetch_add_u64(volatile pg_atomic_uint64 *ptr, int64 add_)
Definition atomics.h:532
static uint64 pg_atomic_sub_fetch_u64(volatile pg_atomic_uint64 *ptr, int64 sub_)
Definition atomics.h:578
static uint64 pg_atomic_fetch_and_u64(volatile pg_atomic_uint64 *ptr, uint64 and_)
Definition atomics.h:551
static uint64 pg_atomic_fetch_or_u64(volatile pg_atomic_uint64 *ptr, uint64 or_)
Definition atomics.h:560
static uint64 pg_atomic_add_fetch_u64(volatile pg_atomic_uint64 *ptr, int64 add_)
Definition atomics.h:569
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:541
static uint64 pg_atomic_exchange_u64(volatile pg_atomic_uint64 *ptr, uint64 newval)
Definition atomics.h:513
#define EXPECT_EQ_U64(result_expr, expected_expr)
Definition regress.c:73

References elog, ERROR, EXPECT_EQ_U64, EXPECT_TRUE, fb(), 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 330 of file regress.c.

331{
332 char *path = text_to_cstring(PG_GETARG_TEXT_PP(0));
333
334 canonicalize_path(path);
336}
#define PG_RETURN_TEXT_P(x)
Definition fmgr.h:374
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 1004 of file regress.c.

1005{
1006 bytea *string = PG_GETARG_BYTEA_PP(0);
1011 bool noError = PG_GETARG_BOOL(3);
1012 TupleDesc tupdesc;
1013 char *src;
1014 char *dst;
1015 bytea *retval;
1016 Size srclen;
1017 Size dstsize;
1018 Oid proc;
1019 int convertedbytes;
1020 int dstlen;
1021 Datum values[2];
1022 bool nulls[2] = {0};
1023 HeapTuple tuple;
1024
1025 if (src_encoding < 0)
1026 ereport(ERROR,
1028 errmsg("invalid source encoding name \"%s\"",
1030 if (dest_encoding < 0)
1031 ereport(ERROR,
1033 errmsg("invalid destination encoding name \"%s\"",
1035
1036 /* Build a tuple descriptor for our result type */
1037 if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
1038 elog(ERROR, "return type must be a row type");
1039 tupdesc = BlessTupleDesc(tupdesc);
1040
1041 srclen = VARSIZE_ANY_EXHDR(string);
1042 src = VARDATA_ANY(string);
1043
1045 {
1046 /* just check that the source string is valid */
1047 int oklen;
1048
1050
1051 if (oklen == srclen)
1052 {
1054 retval = string;
1055 }
1056 else if (!noError)
1057 {
1059 }
1060 else
1061 {
1062 /*
1063 * build bytea data type structure.
1064 */
1065 Assert(oklen < srclen);
1067 retval = (bytea *) palloc(oklen + VARHDRSZ);
1068 SET_VARSIZE(retval, oklen + VARHDRSZ);
1069 memcpy(VARDATA(retval), src, oklen);
1070 }
1071 }
1072 else
1073 {
1075 if (!OidIsValid(proc))
1076 ereport(ERROR,
1078 errmsg("default conversion function for encoding \"%s\" to \"%s\" does not exist",
1081
1083 ereport(ERROR,
1085 errmsg("out of memory"),
1086 errdetail("String of %d bytes is too long for encoding conversion.",
1087 (int) srclen)));
1088
1091
1092 /* perform conversion */
1096 (unsigned char *) src, srclen,
1097 (unsigned char *) dst, dstsize,
1098 noError);
1099 dstlen = strlen(dst);
1100
1101 /*
1102 * build bytea data type structure.
1103 */
1104 retval = (bytea *) palloc(dstlen + VARHDRSZ);
1105 SET_VARSIZE(retval, dstlen + VARHDRSZ);
1106 memcpy(VARDATA(retval), dst, dstlen);
1107
1108 pfree(dst);
1109 }
1110
1112 values[1] = PointerGetDatum(retval);
1113 tuple = heap_form_tuple(tupdesc, values, nulls);
1114
1116}
#define NameStr(name)
Definition c.h:765
#define VARHDRSZ
Definition c.h:711
#define Assert(condition)
Definition c.h:873
#define OidIsValid(objectId)
Definition c.h:788
size_t Size
Definition c.h:619
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)
#define MaxAllocSize
Definition fe_memutils.h:22
#define PG_GETARG_BYTEA_PP(n)
Definition fmgr.h:309
#define PG_GETARG_NAME(n)
Definition fmgr.h:279
#define PG_GETARG_BOOL(n)
Definition fmgr.h:274
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
Definition funcapi.c:276
@ TYPEFUNC_COMPOSITE
Definition funcapi.h:149
static Datum HeapTupleGetDatum(const HeapTupleData *tuple)
Definition funcapi.h:230
int pg_do_encoding_conversion_buf(Oid proc, int src_encoding, int dest_encoding, unsigned char *src, int srclen, unsigned char *dest, int destlen, bool noError)
Definition mbutils.c:470
void report_invalid_encoding(int encoding, const char *mbstr, int len)
Definition mbutils.c:1701
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition mcxt.c:1232
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]
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, fb(), 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 941 of file regress.c.

942{
943 /* Test pg_encoding_set_invalid() */
944 for (int i = 0; i < _PG_LAST_ENCODING_; i++)
945 {
946 char buf[2],
947 bigbuf[16];
948 int len,
949 mblen,
950 valid;
951
952 if (pg_encoding_max_length(i) == 1)
953 continue;
955 len = strnlen(buf, 2);
956 if (len != 2)
958 "official invalid string for encoding \"%s\" has length %d",
960 mblen = pg_encoding_mblen(i, buf);
961 if (mblen != 2)
963 "official invalid string for encoding \"%s\" has mblen %d",
964 pg_enc2name_tbl[i].name, mblen);
965 valid = pg_encoding_verifymbstr(i, buf, len);
966 if (valid != 0)
968 "official invalid string for encoding \"%s\" has valid prefix of length %d",
969 pg_enc2name_tbl[i].name, valid);
970 valid = pg_encoding_verifymbstr(i, buf, 1);
971 if (valid != 0)
973 "first byte of official invalid string for encoding \"%s\" has valid prefix of length %d",
974 pg_enc2name_tbl[i].name, valid);
975 memset(bigbuf, ' ', sizeof(bigbuf));
976 bigbuf[0] = buf[0];
977 bigbuf[1] = buf[1];
978 valid = pg_encoding_verifymbstr(i, bigbuf, sizeof(bigbuf));
979 if (valid != 0)
981 "trailing data changed official invalid string for encoding \"%s\" to have valid prefix of length %d",
982 pg_enc2name_tbl[i].name, valid);
983 }
984
986}
#define WARNING
Definition elog.h:36
const pg_enc2name pg_enc2name_tbl[]
Definition encnames.c:308
static char buf[DEFAULT_XLOG_SEG_SIZE]
@ _PG_LAST_ENCODING_
Definition pg_wchar.h:271
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, fb(), i, len, name, pg_enc2name_tbl, pg_encoding_max_length(), pg_encoding_mblen(), pg_encoding_set_invalid(), pg_encoding_verifymbstr(), PG_RETURN_VOID, and WARNING.

◆ test_fdw_handler()

Datum test_fdw_handler ( PG_FUNCTION_ARGS  )

Definition at line 726 of file regress.c.

727{
728 elog(ERROR, "test_fdw_handler is not implemented");
730}

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

815{
817
819 {
820 /*
821 * Assume that the target is foo_from_bar; that's safe as long as we
822 * don't attach this to any other function.
823 */
825 StringInfoData sql;
826 RangeTblFunction *rtfunc = req->rtfunc;
827 FuncExpr *expr = (FuncExpr *) rtfunc->funcexpr;
828 Node *node;
829 Const *c;
830 char *colname;
831 char *tablename;
836
837 if (list_length(expr->args) != 3)
838 {
839 ereport(WARNING, (errmsg("test_inline_in_from_support_func called with %d args but expected 3", list_length(expr->args))));
841 }
842
843 /* Get colname */
844 node = linitial(expr->args);
845 if (!IsA(node, Const))
846 {
847 ereport(WARNING, (errmsg("test_inline_in_from_support_func called with non-Const parameters")));
849 }
850
851 c = (Const *) node;
852 if (c->consttype != TEXTOID || c->constisnull)
853 {
854 ereport(WARNING, (errmsg("test_inline_in_from_support_func called with non-TEXT parameters")));
856 }
857 colname = TextDatumGetCString(c->constvalue);
858
859 /* Get tablename */
860 node = lsecond(expr->args);
861 if (!IsA(node, Const))
862 {
863 ereport(WARNING, (errmsg("test_inline_in_from_support_func called with non-Const parameters")));
865 }
866
867 c = (Const *) node;
868 if (c->consttype != TEXTOID || c->constisnull)
869 {
870 ereport(WARNING, (errmsg("test_inline_in_from_support_func called with non-TEXT parameters")));
872 }
873 tablename = TextDatumGetCString(c->constvalue);
874
875 /* Begin constructing replacement SELECT query. */
876 initStringInfo(&sql);
877 appendStringInfo(&sql, "SELECT %s::text FROM %s",
878 quote_identifier(colname),
879 quote_identifier(tablename));
880
881 /* Add filter expression if present. */
882 node = lthird(expr->args);
883 if (!(IsA(node, Const) && ((Const *) node)->constisnull))
884 {
885 /*
886 * We only filter if $3 is not constant-NULL. This is not a very
887 * exact implementation of the PL/pgSQL original, but it's close
888 * enough for demonstration purposes.
889 */
890 appendStringInfo(&sql, " WHERE %s::text = $3",
891 quote_identifier(colname));
892 }
893
894 /* Build a SQLFunctionParseInfo with the parameters of my function. */
895 pinfo = prepare_sql_fn_parse_info(req->proc,
896 (Node *) expr,
897 expr->inputcollid);
898
899 /* Parse the generated SQL. */
902 {
903 ereport(WARNING, (errmsg("test_inline_in_from_support_func parsed to more than one node")));
905 }
906
907 /* Analyze the parse tree as if it were a SQL-language body. */
909 sql.data,
911 pinfo, NULL);
912 if (list_length(querytree_list) != 1)
913 {
914 ereport(WARNING, (errmsg("test_inline_in_from_support_func rewrote to more than one node")));
916 }
917
919 if (!IsA(querytree, Query))
920 {
921 ereport(WARNING, (errmsg("test_inline_in_from_support_func didn't parse to a Query")));
923 }
924
926 }
927
929}
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
#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:762
List * pg_parse_query(const char *query_string)
Definition postgres.c:603
char * c
const char * quote_identifier(const char *ident)
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition stringinfo.c:145
void initStringInfo(StringInfo str)
Definition stringinfo.c:97
Definition pg_list.h:54
Definition nodes.h:135

References appendStringInfo(), FuncExpr::args, StringInfoData::data, ereport, errmsg(), fb(), RangeTblFunction::funcexpr, 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(), querytree(), quote_identifier(), sql_fn_parser_setup(), TextDatumGetCString, and WARNING.

◆ test_opclass_options_func()

Datum test_opclass_options_func ( PG_FUNCTION_ARGS  )

Definition at line 933 of file regress.c.

934{
936}

References PG_RETURN_NULL.

◆ test_relpath()

Datum test_relpath ( PG_FUNCTION_ARGS  )

Definition at line 1134 of file regress.c.

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

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

References elog, ERROR, fb(), 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 741 of file regress.c.

742{
744 Node *ret = NULL;
745
747 {
748 /*
749 * Assume that the target is int4eq; that's safe as long as we don't
750 * attach this to any other boolean-returning function.
751 */
754
755 if (req->is_join)
757 req->args,
758 req->inputcollid,
759 req->jointype,
760 req->sjinfo);
761 else
763 req->args,
764 req->inputcollid,
765 req->varRelid);
766
767 req->selectivity = s1;
768 ret = (Node *) req;
769 }
770
772 {
773 /* Provide some generic estimate */
775
776 req->startup = 0;
777 req->per_tuple = 2 * cpu_operator_cost;
778 ret = (Node *) req;
779 }
780
782 {
783 /*
784 * Assume that the target is generate_series_int4; that's safe as long
785 * as we don't attach this to any other set-returning function.
786 */
788
789 if (req->node && IsA(req->node, FuncExpr)) /* be paranoid */
790 {
791 List *args = ((FuncExpr *) req->node)->args;
792 Node *arg1 = linitial(args);
793 Node *arg2 = lsecond(args);
794
795 if (IsA(arg1, Const) &&
796 !((Const *) arg1)->constisnull &&
797 IsA(arg2, Const) &&
798 !((Const *) arg2)->constisnull)
799 {
802
803 req->rows = val2 - val1 + 1;
804 ret = (Node *) req;
805 }
806 }
807 }
808
810}
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:2227
Selectivity join_selectivity(PlannerInfo *root, Oid operatorid, List *args, Oid inputcollid, JoinType jointype, SpecialJoinInfo *sjinfo)
Definition plancat.c:2266
char * s1

References cpu_operator_cost, DatumGetInt32(), fb(), IsA, join_selectivity(), linitial, lsecond, PG_GETARG_POINTER, PG_RETURN_POINTER, restriction_selectivity(), s1, and SupportRequestCost::startup.

◆ test_translation()

Datum test_translation ( PG_FUNCTION_ARGS  )

Definition at line 1166 of file regress.c.

1167{
1168#ifdef ENABLE_NLS
1169 static bool inited = false;
1170
1171 /*
1172 * Ideally we'd do this bit in a _PG_init() hook. However, it seems best
1173 * that the Solaris hack only get applied in the nls.sql test, so it
1174 * doesn't risk affecting other tests that load this module.
1175 */
1176 if (!inited)
1177 {
1178 /*
1179 * Solaris' built-in gettext is not bright about associating locales
1180 * with message catalogs that are named after just the language.
1181 * Apparently the customary workaround is for users to set the
1182 * LANGUAGE environment variable to provide a mapping. Do so here to
1183 * ensure that the nls.sql regression test will work.
1184 */
1185#if defined(__sun__)
1186 setenv("LANGUAGE", "es_ES.UTF-8:es", 1);
1187#endif
1189 inited = true;
1190 }
1191
1192 /*
1193 * If nls.sql failed to select a non-C locale, no translation will happen.
1194 * Report that so that we can distinguish this outcome from brokenness.
1195 * (We do this here, not in nls.sql, so as to need only 3 expected files.)
1196 */
1197 if (strcmp(GetConfigOption("lc_messages", false, false), "C") == 0)
1198 elog(NOTICE, "lc_messages is 'C'");
1199#else
1200 elog(NOTICE, "NLS is not enabled");
1201#endif
1202
1204 errmsg("translated PRId64 = %" PRId64, (int64) 424242424242));
1206 errmsg("translated PRId32 = %" PRId32, (int32) -1234));
1208 errmsg("translated PRIdMAX = %" PRIdMAX, (intmax_t) -123456789012));
1210 errmsg("translated PRIdPTR = %" PRIdPTR, (intptr_t) -9999));
1211
1213 errmsg("translated PRIu64 = %" PRIu64, (uint64) 424242424242));
1215 errmsg("translated PRIu32 = %" PRIu32, (uint32) -1234));
1217 errmsg("translated PRIuMAX = %" PRIuMAX, (uintmax_t) 123456789012));
1219 errmsg("translated PRIuPTR = %" PRIuPTR, (uintptr_t) 9999));
1220
1222 errmsg("translated PRIx64 = %" PRIx64, (uint64) 424242424242));
1224 errmsg("translated PRIx32 = %" PRIx32, (uint32) -1234));
1226 errmsg("translated PRIxMAX = %" PRIxMAX, (uintmax_t) 123456789012));
1228 errmsg("translated PRIxPTR = %" PRIxPTR, (uintptr_t) 9999));
1229
1231 errmsg("translated PRIX64 = %" PRIX64, (uint64) 424242424242));
1233 errmsg("translated PRIX32 = %" PRIX32, (uint32) -1234));
1235 errmsg("translated PRIXMAX = %" PRIXMAX, (uintmax_t) 123456789012));
1237 errmsg("translated PRIXPTR = %" PRIXPTR, (uintptr_t) 9999));
1238
1240}
int64_t int64
Definition c.h:543
#define NOTICE
Definition elog.h:35
const char * GetConfigOption(const char *name, bool missing_ok, bool restrict_privileged)
Definition guc.c:4219
void pg_bindtextdomain(const char *domain)
Definition miscinit.c:1888
#define TEXTDOMAIN
Definition regress.c:53

References elog, ereport, errmsg(), fb(), GetConfigOption(), NOTICE, pg_bindtextdomain(), PG_RETURN_VOID, setenv, and TEXTDOMAIN.

◆ trigger_return_old()

Datum trigger_return_old ( PG_FUNCTION_ARGS  )

Definition at line 263 of file regress.c.

264{
265 TriggerData *trigdata = (TriggerData *) fcinfo->context;
266 HeapTuple tuple;
267
268 if (!CALLED_AS_TRIGGER(fcinfo))
269 elog(ERROR, "trigger_return_old: not fired by trigger manager");
270
271 tuple = trigdata->tg_trigtuple;
272
273 return PointerGetDatum(tuple);
274}
#define CALLED_AS_TRIGGER(fcinfo)
Definition trigger.h:26

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

◆ wait_pid()

Datum wait_pid ( PG_FUNCTION_ARGS  )

Definition at line 482 of file regress.c.

483{
484 int pid = PG_GETARG_INT32(0);
485
486 if (!superuser())
487 elog(ERROR, "must be superuser to check PID liveness");
488
489 while (kill(pid, 0) == 0)
490 {
492 pg_usleep(50000);
493 }
494
495 if (errno != ESRCH)
496 elog(ERROR, "could not check PID %d liveness: %m", pid);
497
499}
#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:490

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

◆ widget_in()

Datum widget_in ( PG_FUNCTION_ARGS  )

Definition at line 180 of file regress.c.

181{
182 char *str = PG_GETARG_CSTRING(0);
183 char *p,
184 *coord[NARGS];
185 int i;
186 WIDGET *result;
187
188 for (i = 0, p = str; *p && i < NARGS && *p != RDELIM; p++)
189 {
190 if (*p == DELIM || (*p == LDELIM && i == 0))
191 coord[i++] = p + 1;
192 }
193
194 /*
195 * Note: DON'T convert this error to "soft" style (errsave/ereturn). We
196 * want this data type to stay permanently in the hard-error world so that
197 * it can be used for testing that such cases still work reasonably.
198 */
199 if (i < NARGS)
202 errmsg("invalid input syntax for type %s: \"%s\"",
203 "widget", str)));
204
205 result = palloc_object(WIDGET);
206 result->center.x = atof(coord[0]);
207 result->center.y = atof(coord[1]);
208 result->radius = atof(coord[2]);
209
210 PG_RETURN_POINTER(result);
211}
#define palloc_object(type)
Definition fe_memutils.h:74
const char * str
#define DELIM
Definition regress.c:85
#define RDELIM
Definition regress.c:84
#define LDELIM
Definition regress.c:83
#define NARGS
Definition regress.c:177
float8 y
Definition geo_decls.h:98
float8 x
Definition geo_decls.h:97
Point center
Definition regress.c:170
double radius
Definition regress.c:171

References WIDGET::center, DELIM, ereport, errcode(), errmsg(), ERROR, fb(), i, LDELIM, NARGS, palloc_object, 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 214 of file regress.c.

215{
217 char *str = psprintf("(%g,%g,%g)",
218 widget->center.x, widget->center.y, widget->radius);
219
221}
char * psprintf(const char *fmt,...)
Definition psprintf.c:43

References fb(), PG_GETARG_POINTER, PG_RETURN_CSTRING, psprintf(), and str.