PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
regress.c File Reference
#include "postgres.h"
#include <math.h>
#include <signal.h>
#include "access/detoast.h"
#include "access/htup_details.h"
#include "catalog/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/spi.h"
#include "funcapi.h"
#include "mb/pg_wchar.h"
#include "miscadmin.h"
#include "nodes/supportnodes.h"
#include "optimizer/optimizer.h"
#include "optimizer/plancat.h"
#include "parser/parse_coerce.h"
#include "port/atomics.h"
#include "postmaster/postmaster.h"
#include "storage/spin.h"
#include "utils/array.h"
#include "utils/builtins.h"
#include "utils/geo_decls.h"
#include "utils/memutils.h"
#include "utils/rel.h"
#include "utils/typcache.h"
Include dependency graph for regress.c:

Go to the source code of this file.

Data Structures

struct  WIDGET
 

Macros

#define EXPECT_TRUE(expr)
 
#define EXPECT_EQ_U32(result_expr, expected_expr)
 
#define EXPECT_EQ_U64(result_expr, expected_expr)
 
#define LDELIM   '('
 
#define RDELIM   ')'
 
#define DELIM   ','
 
#define NARGS   3
 

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_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 79 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 57 of file regress.c.

◆ EXPECT_EQ_U64

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

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

◆ LDELIM

#define LDELIM   '('

Definition at line 77 of file regress.c.

◆ NARGS

#define NARGS   3

Definition at line 171 of file regress.c.

◆ RDELIM

#define RDELIM   ')'

Definition at line 78 of file regress.c.

Function Documentation

◆ binary_coercible()

Datum binary_coercible ( PG_FUNCTION_ARGS  )

Definition at line 996 of file regress.c.

997{
998 Oid srctype = PG_GETARG_OID(0);
999 Oid targettype = PG_GETARG_OID(1);
1000
1001 PG_RETURN_BOOL(IsBinaryCoercible(srctype, targettype));
1002}
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
bool IsBinaryCoercible(Oid srctype, Oid targettype)
unsigned int Oid
Definition: postgres_ext.h:30

References IsBinaryCoercible(), PG_GETARG_OID, and PG_RETURN_BOOL.

◆ get_environ()

Datum get_environ ( PG_FUNCTION_ARGS  )

Definition at line 433 of file regress.c.

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

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

◆ int44in()

Datum int44in ( PG_FUNCTION_ARGS  )

Definition at line 284 of file regress.c.

285{
286 char *input_string = PG_GETARG_CSTRING(0);
287 int32 *result = (int32 *) palloc(4 * sizeof(int32));
288 int i;
289
290 i = sscanf(input_string,
291 "%d, %d, %d, %d",
292 &result[0],
293 &result[1],
294 &result[2],
295 &result[3]);
296 while (i < 4)
297 result[i++] = 0;
298
299 PG_RETURN_POINTER(result);
300}
int32_t int32
Definition: c.h:498
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:277

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

◆ int44out()

Datum int44out ( PG_FUNCTION_ARGS  )

Definition at line 308 of file regress.c.

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

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

◆ interpt_pp()

Datum interpt_pp ( PG_FUNCTION_ARGS  )

Definition at line 93 of file regress.c.

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

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

◆ is_catalog_text_unique_index_oid()

Datum is_catalog_text_unique_index_oid ( PG_FUNCTION_ARGS  )

Definition at line 728 of file regress.c.

729{
731}
bool IsCatalogTextUniqueIndexOid(Oid relid)
Definition: catalog.c:156

References IsCatalogTextUniqueIndexOid(), and PG_GETARG_OID.

◆ make_tuple_indirect()

Datum make_tuple_indirect ( PG_FUNCTION_ARGS  )

Definition at line 334 of file regress.c.

335{
337 HeapTupleData tuple;
338 int ncolumns;
339 Datum *values;
340 bool *nulls;
341
342 Oid tupType;
343 int32 tupTypmod;
344 TupleDesc tupdesc;
345
346 HeapTuple newtup;
347
348 int i;
349
350 MemoryContext old_context;
351
352 /* Extract type info from the tuple itself */
353 tupType = HeapTupleHeaderGetTypeId(rec);
354 tupTypmod = HeapTupleHeaderGetTypMod(rec);
355 tupdesc = lookup_rowtype_tupdesc(tupType, tupTypmod);
356 ncolumns = tupdesc->natts;
357
358 /* Build a temporary HeapTuple control structure */
361 tuple.t_tableOid = InvalidOid;
362 tuple.t_data = rec;
363
364 values = (Datum *) palloc(ncolumns * sizeof(Datum));
365 nulls = (bool *) palloc(ncolumns * sizeof(bool));
366
367 heap_deform_tuple(&tuple, tupdesc, values, nulls);
368
370
371 for (i = 0; i < ncolumns; i++)
372 {
373 struct varlena *attr;
374 struct varlena *new_attr;
375 struct varatt_indirect redirect_pointer;
376
377 /* only work on existing, not-null varlenas */
378 if (TupleDescAttr(tupdesc, i)->attisdropped ||
379 nulls[i] ||
380 TupleDescAttr(tupdesc, i)->attlen != -1 ||
381 TupleDescAttr(tupdesc, i)->attstorage == TYPSTORAGE_PLAIN)
382 continue;
383
384 attr = (struct varlena *) DatumGetPointer(values[i]);
385
386 /* don't recursively indirect */
388 continue;
389
390 /* copy datum, so it still lives later */
392 attr = detoast_external_attr(attr);
393 else
394 {
395 struct varlena *oldattr = attr;
396
397 attr = palloc0(VARSIZE_ANY(oldattr));
398 memcpy(attr, oldattr, VARSIZE_ANY(oldattr));
399 }
400
401 /* build indirection Datum */
402 new_attr = (struct varlena *) palloc0(INDIRECT_POINTER_SIZE);
403 redirect_pointer.pointer = attr;
405 memcpy(VARDATA_EXTERNAL(new_attr), &redirect_pointer,
406 sizeof(redirect_pointer));
407
408 values[i] = PointerGetDatum(new_attr);
409 }
410
411 newtup = heap_form_tuple(tupdesc, values, nulls);
412 pfree(values);
413 pfree(nulls);
414 ReleaseTupleDesc(tupdesc);
415
416 MemoryContextSwitchTo(old_context);
417
418 /*
419 * We intentionally don't use PG_RETURN_HEAPTUPLEHEADER here, because that
420 * would cause the indirect toast pointers to be flattened out of the
421 * tuple immediately, rendering subsequent testing irrelevant. So just
422 * return the HeapTupleHeader pointer as-is. This violates the general
423 * rule that composite Datums shouldn't contain toast pointers, but so
424 * long as the regression test scripts don't insert the result of this
425 * function into a container type (record, array, etc) it should be OK.
426 */
427 PG_RETURN_POINTER(newtup->t_data);
428}
static Datum values[MAXATTR]
Definition: bootstrap.c:151
struct varlena * detoast_external_attr(struct varlena *attr)
Definition: detoast.c:45
#define INDIRECT_POINTER_SIZE
Definition: detoast.h:34
#define PG_GETARG_HEAPTUPLEHEADER(n)
Definition: fmgr.h:312
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
Definition: heaptuple.c:1117
void heap_deform_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *values, bool *isnull)
Definition: heaptuple.c:1346
static int32 HeapTupleHeaderGetTypMod(const HeapTupleHeaderData *tup)
Definition: htup_details.h:516
static uint32 HeapTupleHeaderGetDatumLength(const HeapTupleHeaderData *tup)
Definition: htup_details.h:492
static Oid HeapTupleHeaderGetTypeId(const HeapTupleHeaderData *tup)
Definition: htup_details.h:504
static void ItemPointerSetInvalid(ItemPointerData *pointer)
Definition: itemptr.h:184
MemoryContext TopTransactionContext
Definition: mcxt.c:170
void pfree(void *pointer)
Definition: mcxt.c:2150
void * palloc0(Size size)
Definition: mcxt.c:1973
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:124
char attstorage
Definition: pg_attribute.h:108
int16 attlen
Definition: pg_attribute.h:59
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:327
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:317
#define InvalidOid
Definition: postgres_ext.h:35
ItemPointerData t_self
Definition: htup.h:65
uint32 t_len
Definition: htup.h:64
HeapTupleHeader t_data
Definition: htup.h:68
Oid t_tableOid
Definition: htup.h:66
Definition: c.h:658
#define ReleaseTupleDesc(tupdesc)
Definition: tupdesc.h: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:1922
#define VARATT_IS_EXTERNAL_ONDISK(PTR)
Definition: varatt.h:290
#define VARATT_IS_EXTERNAL_INDIRECT(PTR)
Definition: varatt.h:292
#define VARSIZE_ANY(PTR)
Definition: varatt.h:311
#define SET_VARTAG_EXTERNAL(PTR, tag)
Definition: varatt.h:309
#define VARDATA_EXTERNAL(PTR)
Definition: varatt.h:286
@ VARTAG_INDIRECT
Definition: varatt.h:86

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

◆ overpaid()

Datum overpaid ( PG_FUNCTION_ARGS  )

Definition at line 145 of file regress.c.

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

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

◆ PG_FUNCTION_INFO_V1() [1/23]

PG_FUNCTION_INFO_V1 ( binary_coercible  )

◆ PG_FUNCTION_INFO_V1() [2/23]

PG_FUNCTION_INFO_V1 ( get_environ  )

◆ PG_FUNCTION_INFO_V1() [3/23]

PG_FUNCTION_INFO_V1 ( int44in  )

◆ PG_FUNCTION_INFO_V1() [4/23]

PG_FUNCTION_INFO_V1 ( int44out  )

◆ PG_FUNCTION_INFO_V1() [5/23]

PG_FUNCTION_INFO_V1 ( interpt_pp  )

◆ PG_FUNCTION_INFO_V1() [6/23]

PG_FUNCTION_INFO_V1 ( is_catalog_text_unique_index_oid  )

◆ PG_FUNCTION_INFO_V1() [7/23]

PG_FUNCTION_INFO_V1 ( make_tuple_indirect  )

◆ PG_FUNCTION_INFO_V1() [8/23]

PG_FUNCTION_INFO_V1 ( overpaid  )

◆ PG_FUNCTION_INFO_V1() [9/23]

PG_FUNCTION_INFO_V1 ( pt_in_widget  )

◆ PG_FUNCTION_INFO_V1() [10/23]

PG_FUNCTION_INFO_V1 ( regress_setenv  )

◆ PG_FUNCTION_INFO_V1() [11/23]

PG_FUNCTION_INFO_V1 ( reverse_name  )

◆ PG_FUNCTION_INFO_V1() [12/23]

PG_FUNCTION_INFO_V1 ( test_atomic_ops  )

◆ PG_FUNCTION_INFO_V1() [13/23]

PG_FUNCTION_INFO_V1 ( test_canonicalize_path  )

◆ PG_FUNCTION_INFO_V1() [14/23]

PG_FUNCTION_INFO_V1 ( test_enc_conversion  )

◆ PG_FUNCTION_INFO_V1() [15/23]

PG_FUNCTION_INFO_V1 ( test_enc_setup  )

◆ PG_FUNCTION_INFO_V1() [16/23]

PG_FUNCTION_INFO_V1 ( test_fdw_handler  )

◆ PG_FUNCTION_INFO_V1() [17/23]

PG_FUNCTION_INFO_V1 ( test_opclass_options_func  )

◆ PG_FUNCTION_INFO_V1() [18/23]

PG_FUNCTION_INFO_V1 ( test_relpath  )

◆ PG_FUNCTION_INFO_V1() [19/23]

PG_FUNCTION_INFO_V1 ( test_support_func  )

◆ PG_FUNCTION_INFO_V1() [20/23]

PG_FUNCTION_INFO_V1 ( trigger_return_old  )

◆ PG_FUNCTION_INFO_V1() [21/23]

PG_FUNCTION_INFO_V1 ( wait_pid  )

◆ PG_FUNCTION_INFO_V1() [22/23]

PG_FUNCTION_INFO_V1 ( widget_in  )

◆ PG_FUNCTION_INFO_V1() [23/23]

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

221{
222 Point *point = PG_GETARG_POINT_P(0);
223 WIDGET *widget = (WIDGET *) PG_GETARG_POINTER(1);
224 float8 distance;
225
227 PointPGetDatum(point),
228 PointPGetDatum(&widget->center)));
229
230 PG_RETURN_BOOL(distance < widget->radius);
231}
double float8
Definition: c.h:601
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:185
static Datum PointPGetDatum(const Point *X)
Definition: geo_decls.h:181
Datum point_distance(PG_FUNCTION_ARGS)
Definition: geo_ops.c:1993
static float8 DatumGetFloat8(Datum X)
Definition: postgres.h:499
Point center
Definition: regress.c:164

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

135{
136 lseg->p[0].x = pt1->x;
137 lseg->p[0].y = pt1->y;
138 lseg->p[1].x = pt2->x;
139 lseg->p[1].y = pt2->y;
140}
Point p[2]
Definition: geo_decls.h:108
float8 y
Definition: geo_decls.h:99
float8 x
Definition: geo_decls.h:98

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

Referenced by interpt_pp().

◆ regress_setenv()

Datum regress_setenv ( PG_FUNCTION_ARGS  )

Definition at line 458 of file regress.c.

459{
460 char *envvar = text_to_cstring(PG_GETARG_TEXT_PP(0));
461 char *envval = text_to_cstring(PG_GETARG_TEXT_PP(1));
462
463 if (!superuser())
464 elog(ERROR, "must be superuser to change environment variables");
465
466 if (setenv(envvar, envval, 1) != 0)
467 elog(ERROR, "could not set environment variable: %m");
468
470}
#define elog(elevel,...)
Definition: elog.h:225
#define PG_RETURN_VOID()
Definition: fmgr.h:349
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:309
bool superuser(void)
Definition: superuser.c:46
char * text_to_cstring(const text *t)
Definition: varlena.c:225
#define setenv(x, y, z)
Definition: win32_port.h:545

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

◆ reverse_name()

Datum reverse_name ( PG_FUNCTION_ARGS  )

Definition at line 236 of file regress.c.

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

497{
498 pg_atomic_flag flag;
499
509}
static void pg_atomic_clear_flag(volatile pg_atomic_flag *ptr)
Definition: atomics.h:207
static bool pg_atomic_test_set_flag(volatile pg_atomic_flag *ptr)
Definition: atomics.h:183
static bool pg_atomic_unlocked_test_flag(volatile pg_atomic_flag *ptr)
Definition: atomics.h:196
static void pg_atomic_init_flag(volatile pg_atomic_flag *ptr)
Definition: atomics.h:170
#define EXPECT_TRUE(expr)
Definition: regress.c:49
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 701 of file regress.c.

702{
704
706
708
709 /*
710 * Arguably this shouldn't be tested as part of this function, but it's
711 * closely enough related that that seems ok for now.
712 */
714
715 PG_RETURN_BOOL(true);
716}
static void test_spinlock(void)
Definition: regress.c:637
static void test_atomic_uint32(void)
Definition: regress.c:512
static void test_atomic_flag(void)
Definition: regress.c:496
static void test_atomic_uint64(void)
Definition: regress.c:584

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

513{
515 uint32 expected;
516 int i;
517
518 pg_atomic_init_u32(&var, 0);
520 pg_atomic_write_u32(&var, 3);
523 3);
529
530 /* test around numerical limits */
531 EXPECT_EQ_U32(pg_atomic_fetch_add_u32(&var, INT_MAX), 0);
532 EXPECT_EQ_U32(pg_atomic_fetch_add_u32(&var, INT_MAX), INT_MAX);
533 pg_atomic_fetch_add_u32(&var, 2); /* wrap to 0 */
538 2 * PG_INT16_MAX + 1);
541 pg_atomic_fetch_add_u32(&var, 1); /* top up to UINT_MAX */
542 EXPECT_EQ_U32(pg_atomic_read_u32(&var), UINT_MAX);
543 EXPECT_EQ_U32(pg_atomic_fetch_sub_u32(&var, INT_MAX), UINT_MAX);
544 EXPECT_EQ_U32(pg_atomic_read_u32(&var), (uint32) INT_MAX + 1);
545 EXPECT_EQ_U32(pg_atomic_sub_fetch_u32(&var, INT_MAX), 1);
547 expected = PG_INT16_MAX;
548 EXPECT_TRUE(!pg_atomic_compare_exchange_u32(&var, &expected, 1));
549 expected = PG_INT16_MAX + 1;
550 EXPECT_TRUE(!pg_atomic_compare_exchange_u32(&var, &expected, 1));
551 expected = PG_INT16_MIN;
552 EXPECT_TRUE(!pg_atomic_compare_exchange_u32(&var, &expected, 1));
553 expected = PG_INT16_MIN - 1;
554 EXPECT_TRUE(!pg_atomic_compare_exchange_u32(&var, &expected, 1));
555
556 /* fail exchange because of old expected */
557 expected = 10;
558 EXPECT_TRUE(!pg_atomic_compare_exchange_u32(&var, &expected, 1));
559
560 /* CAS is allowed to fail due to interrupts, try a couple of times */
561 for (i = 0; i < 1000; i++)
562 {
563 expected = 0;
564 if (!pg_atomic_compare_exchange_u32(&var, &expected, 1))
565 break;
566 }
567 if (i == 1000)
568 elog(ERROR, "atomic_compare_exchange_u32() never succeeded");
570 pg_atomic_write_u32(&var, 0);
571
572 /* try setting flagbits */
573 EXPECT_TRUE(!(pg_atomic_fetch_or_u32(&var, 1) & 1));
576 /* try clearing flagbits */
577 EXPECT_EQ_U32(pg_atomic_fetch_and_u32(&var, ~2) & 3, 3);
579 /* no bits set anymore */
581}
static uint32 pg_atomic_fetch_and_u32(volatile pg_atomic_uint32 *ptr, uint32 and_)
Definition: atomics.h:396
static bool pg_atomic_compare_exchange_u32(volatile pg_atomic_uint32 *ptr, uint32 *expected, uint32 newval)
Definition: atomics.h:349
static uint32 pg_atomic_fetch_or_u32(volatile pg_atomic_uint32 *ptr, uint32 or_)
Definition: atomics.h:410
static uint32 pg_atomic_sub_fetch_u32(volatile pg_atomic_uint32 *ptr, int32 sub_)
Definition: atomics.h:439
static uint32 pg_atomic_fetch_sub_u32(volatile pg_atomic_uint32 *ptr, int32 sub_)
Definition: atomics.h:381
static void pg_atomic_init_u32(volatile pg_atomic_uint32 *ptr, uint32 val)
Definition: atomics.h:221
static uint32 pg_atomic_fetch_add_u32(volatile pg_atomic_uint32 *ptr, int32 add_)
Definition: atomics.h:366
static uint32 pg_atomic_add_fetch_u32(volatile pg_atomic_uint32 *ptr, int32 add_)
Definition: atomics.h:424
static void pg_atomic_write_u32(volatile pg_atomic_uint32 *ptr, uint32 val)
Definition: atomics.h:276
static uint32 pg_atomic_read_u32(volatile pg_atomic_uint32 *ptr)
Definition: atomics.h:239
static uint32 pg_atomic_exchange_u32(volatile pg_atomic_uint32 *ptr, uint32 newval)
Definition: atomics.h:330
#define PG_INT16_MIN
Definition: c.h:556
uint32_t uint32
Definition: c.h:502
#define PG_INT16_MAX
Definition: c.h:557
#define EXPECT_EQ_U32(result_expr, expected_expr)
Definition: regress.c:57

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

585{
587 uint64 expected;
588 int i;
589
590 pg_atomic_init_u64(&var, 0);
592 pg_atomic_write_u64(&var, 3);
595 3);
601
602 /* fail exchange because of old expected */
603 expected = 10;
604 EXPECT_TRUE(!pg_atomic_compare_exchange_u64(&var, &expected, 1));
605
606 /* CAS is allowed to fail due to interrupts, try a couple of times */
607 for (i = 0; i < 100; i++)
608 {
609 expected = 0;
610 if (!pg_atomic_compare_exchange_u64(&var, &expected, 1))
611 break;
612 }
613 if (i == 100)
614 elog(ERROR, "atomic_compare_exchange_u64() never succeeded");
616
617 pg_atomic_write_u64(&var, 0);
618
619 /* try setting flagbits */
620 EXPECT_TRUE(!(pg_atomic_fetch_or_u64(&var, 1) & 1));
623 /* try clearing flagbits */
624 EXPECT_EQ_U64((pg_atomic_fetch_and_u64(&var, ~2) & 3), 3);
626 /* no bits set anymore */
628}
static void pg_atomic_write_u64(volatile pg_atomic_uint64 *ptr, uint64 val)
Definition: atomics.h:485
static bool pg_atomic_compare_exchange_u64(volatile pg_atomic_uint64 *ptr, uint64 *expected, uint64 newval)
Definition: atomics.h:512
static uint64 pg_atomic_fetch_add_u64(volatile pg_atomic_uint64 *ptr, int64 add_)
Definition: atomics.h:522
static uint64 pg_atomic_sub_fetch_u64(volatile pg_atomic_uint64 *ptr, int64 sub_)
Definition: atomics.h:568
static uint64 pg_atomic_fetch_and_u64(volatile pg_atomic_uint64 *ptr, uint64 and_)
Definition: atomics.h:541
static uint64 pg_atomic_fetch_or_u64(volatile pg_atomic_uint64 *ptr, uint64 or_)
Definition: atomics.h:550
static uint64 pg_atomic_add_fetch_u64(volatile pg_atomic_uint64 *ptr, int64 add_)
Definition: atomics.h:559
static void pg_atomic_init_u64(volatile pg_atomic_uint64 *ptr, uint64 val)
Definition: atomics.h:453
static uint64 pg_atomic_read_u64(volatile pg_atomic_uint64 *ptr)
Definition: atomics.h:467
static uint64 pg_atomic_fetch_sub_u64(volatile pg_atomic_uint64 *ptr, int64 sub_)
Definition: atomics.h:531
static uint64 pg_atomic_exchange_u64(volatile pg_atomic_uint64 *ptr, uint64 newval)
Definition: atomics.h:503
uint64_t uint64
Definition: c.h:503
#define EXPECT_EQ_U64(result_expr, expected_expr)
Definition: regress.c:67

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

325{
326 char *path = text_to_cstring(PG_GETARG_TEXT_PP(0));
327
328 canonicalize_path(path);
330}
#define PG_RETURN_TEXT_P(x)
Definition: fmgr.h:372
void canonicalize_path(char *path)
Definition: path.c:337
text * cstring_to_text(const char *s)
Definition: varlena.c:192

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

◆ test_enc_conversion()

Datum test_enc_conversion ( PG_FUNCTION_ARGS  )

Definition at line 879 of file regress.c.

880{
881 bytea *string = PG_GETARG_BYTEA_PP(0);
882 char *src_encoding_name = NameStr(*PG_GETARG_NAME(1));
883 int src_encoding = pg_char_to_encoding(src_encoding_name);
884 char *dest_encoding_name = NameStr(*PG_GETARG_NAME(2));
885 int dest_encoding = pg_char_to_encoding(dest_encoding_name);
886 bool noError = PG_GETARG_BOOL(3);
887 TupleDesc tupdesc;
888 char *src;
889 char *dst;
890 bytea *retval;
891 Size srclen;
892 Size dstsize;
893 Oid proc;
894 int convertedbytes;
895 int dstlen;
896 Datum values[2];
897 bool nulls[2] = {0};
898 HeapTuple tuple;
899
900 if (src_encoding < 0)
902 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
903 errmsg("invalid source encoding name \"%s\"",
904 src_encoding_name)));
905 if (dest_encoding < 0)
907 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
908 errmsg("invalid destination encoding name \"%s\"",
909 dest_encoding_name)));
910
911 /* Build a tuple descriptor for our result type */
912 if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
913 elog(ERROR, "return type must be a row type");
914 tupdesc = BlessTupleDesc(tupdesc);
915
916 srclen = VARSIZE_ANY_EXHDR(string);
917 src = VARDATA_ANY(string);
918
919 if (src_encoding == dest_encoding)
920 {
921 /* just check that the source string is valid */
922 int oklen;
923
924 oklen = pg_encoding_verifymbstr(src_encoding, src, srclen);
925
926 if (oklen == srclen)
927 {
928 convertedbytes = oklen;
929 retval = string;
930 }
931 else if (!noError)
932 {
933 report_invalid_encoding(src_encoding, src + oklen, srclen - oklen);
934 }
935 else
936 {
937 /*
938 * build bytea data type structure.
939 */
940 Assert(oklen < srclen);
941 convertedbytes = oklen;
942 retval = (bytea *) palloc(oklen + VARHDRSZ);
943 SET_VARSIZE(retval, oklen + VARHDRSZ);
944 memcpy(VARDATA(retval), src, oklen);
945 }
946 }
947 else
948 {
949 proc = FindDefaultConversionProc(src_encoding, dest_encoding);
950 if (!OidIsValid(proc))
952 (errcode(ERRCODE_UNDEFINED_FUNCTION),
953 errmsg("default conversion function for encoding \"%s\" to \"%s\" does not exist",
954 pg_encoding_to_char(src_encoding),
955 pg_encoding_to_char(dest_encoding))));
956
957 if (srclen >= (MaxAllocSize / (Size) MAX_CONVERSION_GROWTH))
959 (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
960 errmsg("out of memory"),
961 errdetail("String of %d bytes is too long for encoding conversion.",
962 (int) srclen)));
963
964 dstsize = (Size) srclen * MAX_CONVERSION_GROWTH + 1;
966
967 /* perform conversion */
968 convertedbytes = pg_do_encoding_conversion_buf(proc,
969 src_encoding,
970 dest_encoding,
971 (unsigned char *) src, srclen,
972 (unsigned char *) dst, dstsize,
973 noError);
974 dstlen = strlen(dst);
975
976 /*
977 * build bytea data type structure.
978 */
979 retval = (bytea *) palloc(dstlen + VARHDRSZ);
980 SET_VARSIZE(retval, dstlen + VARHDRSZ);
981 memcpy(VARDATA(retval), dst, dstlen);
982
983 pfree(dst);
984 }
985
986 values[0] = Int32GetDatum(convertedbytes);
987 values[1] = PointerGetDatum(retval);
988 tuple = heap_form_tuple(tupdesc, values, nulls);
989
991}
#define NameStr(name)
Definition: c.h:717
#define VARHDRSZ
Definition: c.h:663
#define OidIsValid(objectId)
Definition: c.h:746
size_t Size
Definition: c.h:576
int errdetail(const char *fmt,...)
Definition: elog.c:1204
int errcode(int sqlerrcode)
Definition: elog.c:854
int errmsg(const char *fmt,...)
Definition: elog.c:1071
#define ereport(elevel,...)
Definition: elog.h:149
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:2260
#define MaxAllocSize
Definition: fe_memutils.h:22
#define PG_GETARG_BYTEA_PP(n)
Definition: fmgr.h:308
#define PG_GETARG_NAME(n)
Definition: fmgr.h:278
#define PG_GETARG_BOOL(n)
Definition: fmgr.h:274
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
Definition: funcapi.c:276
@ TYPEFUNC_COMPOSITE
Definition: funcapi.h:149
static Datum HeapTupleGetDatum(const HeapTupleData *tuple)
Definition: funcapi.h:230
Assert(PointerIsAligned(start, uint64))
int pg_do_encoding_conversion_buf(Oid proc, int src_encoding, int dest_encoding, unsigned char *src, int srclen, unsigned char *dest, int destlen, bool noError)
Definition: mbutils.c:469
void report_invalid_encoding(int encoding, const char *mbstr, int len)
Definition: mbutils.c:1698
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:1260
MemoryContext CurrentMemoryContext
Definition: mcxt.c:159
Oid FindDefaultConversionProc(int32 for_encoding, int32 to_encoding)
Definition: namespace.c:4080
#define MAX_CONVERSION_GROWTH
Definition: pg_wchar.h:302
#define pg_encoding_to_char
Definition: pg_wchar.h:630
#define pg_char_to_encoding
Definition: pg_wchar.h:629
static Datum Int32GetDatum(int32 X)
Definition: postgres.h:217
char string[11]
Definition: preproc-type.c:52
#define VARDATA(PTR)
Definition: varatt.h:278
#define VARDATA_ANY(PTR)
Definition: varatt.h:324
#define SET_VARSIZE(PTR, len)
Definition: varatt.h:305
#define VARSIZE_ANY_EXHDR(PTR)
Definition: varatt.h:317
int pg_encoding_verifymbstr(int encoding, const char *mbstr, int len)
Definition: wchar.c:2163

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

◆ test_enc_setup()

Datum test_enc_setup ( PG_FUNCTION_ARGS  )

Definition at line 816 of file regress.c.

817{
818 /* Test pg_encoding_set_invalid() */
819 for (int i = 0; i < _PG_LAST_ENCODING_; i++)
820 {
821 char buf[2],
822 bigbuf[16];
823 int len,
824 mblen,
825 valid;
826
827 if (pg_encoding_max_length(i) == 1)
828 continue;
830 len = strnlen(buf, 2);
831 if (len != 2)
833 "official invalid string for encoding \"%s\" has length %d",
835 mblen = pg_encoding_mblen(i, buf);
836 if (mblen != 2)
838 "official invalid string for encoding \"%s\" has mblen %d",
839 pg_enc2name_tbl[i].name, mblen);
840 valid = pg_encoding_verifymbstr(i, buf, len);
841 if (valid != 0)
843 "official invalid string for encoding \"%s\" has valid prefix of length %d",
844 pg_enc2name_tbl[i].name, valid);
845 valid = pg_encoding_verifymbstr(i, buf, 1);
846 if (valid != 0)
848 "first byte of official invalid string for encoding \"%s\" has valid prefix of length %d",
849 pg_enc2name_tbl[i].name, valid);
850 memset(bigbuf, ' ', sizeof(bigbuf));
851 bigbuf[0] = buf[0];
852 bigbuf[1] = buf[1];
853 valid = pg_encoding_verifymbstr(i, bigbuf, sizeof(bigbuf));
854 if (valid != 0)
856 "trailing data changed official invalid string for encoding \"%s\" to have valid prefix of length %d",
857 pg_enc2name_tbl[i].name, valid);
858 }
859
861}
#define WARNING
Definition: elog.h:36
const pg_enc2name pg_enc2name_tbl[]
Definition: encnames.c:308
static char * buf
Definition: pg_test_fsync.c:72
@ _PG_LAST_ENCODING_
Definition: pg_wchar.h:271
size_t strnlen(const char *str, size_t maxlen)
Definition: strnlen.c:26
const char * name
void pg_encoding_set_invalid(int encoding, char *dst)
Definition: wchar.c:2049
int pg_encoding_max_length(int encoding)
Definition: wchar.c:2174
int pg_encoding_mblen(int encoding, const char *mbstr)
Definition: wchar.c:2116

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

◆ test_fdw_handler()

Datum test_fdw_handler ( PG_FUNCTION_ARGS  )

Definition at line 720 of file regress.c.

721{
722 elog(ERROR, "test_fdw_handler is not implemented");
724}

References elog, ERROR, and PG_RETURN_NULL.

◆ test_opclass_options_func()

Datum test_opclass_options_func ( PG_FUNCTION_ARGS  )

Definition at line 808 of file regress.c.

809{
811}

References PG_RETURN_NULL.

◆ test_relpath()

Datum test_relpath ( PG_FUNCTION_ARGS  )

Definition at line 1009 of file regress.c.

1010{
1011 RelPathStr rpath;
1012
1013 /*
1014 * Verify that PROCNUMBER_CHARS and MAX_BACKENDS stay in sync.
1015 * Unfortunately I don't know how to express that in a way suitable for a
1016 * static assert.
1017 */
1018 if ((int) ceil(log10(MAX_BACKENDS)) != PROCNUMBER_CHARS)
1019 elog(WARNING, "mismatch between MAX_BACKENDS and PROCNUMBER_CHARS");
1020
1021 /* verify that the max-length relpath is generated ok */
1023 INIT_FORKNUM);
1024
1025 if (strlen(rpath.str) != REL_PATH_STR_MAXLEN)
1026 elog(WARNING, "maximum length relpath is if length %zu instead of %zu",
1027 strlen(rpath.str), REL_PATH_STR_MAXLEN);
1028
1030}
#define OID_MAX
Definition: postgres_ext.h:38
#define MAX_BACKENDS
Definition: procnumber.h:39
RelPathStr GetRelationPath(Oid dbOid, Oid spcOid, RelFileNumber relNumber, int procNumber, ForkNumber forkNumber)
Definition: relpath.c:143
#define REL_PATH_STR_MAXLEN
Definition: relpath.h:96
@ INIT_FORKNUM
Definition: relpath.h:61
#define PROCNUMBER_CHARS
Definition: relpath.h:84
char str[REL_PATH_STR_MAXLEN+1]
Definition: relpath.h:123

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

◆ test_spinlock()

static void test_spinlock ( void  )
static

Definition at line 637 of file regress.c.

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

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

Referenced by test_atomic_ops().

◆ test_support_func()

Datum test_support_func ( PG_FUNCTION_ARGS  )

Definition at line 735 of file regress.c.

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

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

◆ trigger_return_old()

Datum trigger_return_old ( PG_FUNCTION_ARGS  )

Definition at line 257 of file regress.c.

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

477{
478 int pid = PG_GETARG_INT32(0);
479
480 if (!superuser())
481 elog(ERROR, "must be superuser to check PID liveness");
482
483 while (kill(pid, 0) == 0)
484 {
486 pg_usleep(50000);
487 }
488
489 if (errno != ESRCH)
490 elog(ERROR, "could not check PID %d liveness: %m", pid);
491
493}
#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 174 of file regress.c.

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

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

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