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 "common/pg_lzcompress.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 "portability/instr_time.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 (test_fdw_connection)
 
Datum test_fdw_connection (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 (test_bytea_to_text)
 
Datum test_bytea_to_text (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (test_text_to_bytea)
 
Datum test_text_to_bytea (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (test_mblen_func)
 
Datum test_mblen_func (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (test_text_to_wchars)
 
Datum test_text_to_wchars (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (test_wchars_to_text)
 
Datum test_wchars_to_text (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (test_valid_server_encoding)
 
Datum test_valid_server_encoding (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)
 
 PG_FUNCTION_INFO_V1 (test_instr_time)
 
Datum test_instr_time (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (test_pglz_compress)
 
Datum test_pglz_compress (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (test_pglz_decompress)
 
Datum test_pglz_decompress (PG_FUNCTION_ARGS)
 

Macro Definition Documentation

◆ DELIM

#define DELIM   ','

Definition at line 87 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:624
#define ERROR
Definition elog.h:40
static int fb(int x)

Definition at line 65 of file regress.c.

66 { \
70 elog(ERROR, \
71 "%s yielded %u, expected %s in file \"%s\" line %u", \
73 } 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:635
uint64_t uint64
Definition c.h:625

Definition at line 75 of file regress.c.

76 { \
80 elog(ERROR, \
81 "%s yielded " UINT64_FORMAT ", expected %s in file \"%s\" line %u", \
83 } 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 57 of file regress.c.

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

◆ LDELIM

#define LDELIM   '('

Definition at line 85 of file regress.c.

◆ NARGS

#define NARGS   3

Definition at line 180 of file regress.c.

◆ RDELIM

#define RDELIM   ')'

Definition at line 86 of file regress.c.

◆ TEXTDOMAIN

#define TEXTDOMAIN   PG_TEXTDOMAIN("postgresql-regress")

Definition at line 55 of file regress.c.

Function Documentation

◆ binary_coercible()

Datum binary_coercible ( PG_FUNCTION_ARGS  )

Definition at line 1272 of file regress.c.

1273{
1274 Oid srctype = PG_GETARG_OID(0);
1275 Oid targettype = PG_GETARG_OID(1);
1276
1277 PG_RETURN_BOOL(IsBinaryCoercible(srctype, targettype));
1278}
#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 442 of file regress.c.

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

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

◆ int44in()

Datum int44in ( PG_FUNCTION_ARGS  )

Definition at line 293 of file regress.c.

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

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

◆ int44out()

Datum int44out ( PG_FUNCTION_ARGS  )

Definition at line 317 of file regress.c.

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

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

◆ interpt_pp()

Datum interpt_pp ( PG_FUNCTION_ARGS  )

Definition at line 101 of file regress.c.

102{
105 int i,
106 j;
107 LSEG seg1,
108 seg2;
109 bool found; /* We've found the intersection */
110
111 found = false; /* Haven't found it yet */
112
113 for (i = 0; i < p1->npts - 1 && !found; i++)
114 {
115 regress_lseg_construct(&seg1, &p1->p[i], &p1->p[i + 1]);
116 for (j = 0; j < p2->npts - 1 && !found; j++)
117 {
118 regress_lseg_construct(&seg2, &p2->p[j], &p2->p[j + 1]);
122 found = true;
123 }
124 }
125
126 if (!found)
128
129 /*
130 * Note: DirectFunctionCall2 will kick out an error if lseg_interpt()
131 * returns NULL, but that should be impossible since we know the two
132 * segments intersect.
133 */
137}
#define DirectFunctionCall2(func, arg1, arg2)
Definition fmgr.h:690
#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:2251
Datum lseg_interpt(PG_FUNCTION_ARGS)
Definition geo_ops.c:2443
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:142

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

745{
747}
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 343 of file regress.c.

344{
346 HeapTupleData tuple;
347 int ncolumns;
348 Datum *values;
349 bool *nulls;
350
351 Oid tupType;
353 TupleDesc tupdesc;
354
356
357 int i;
358
360
361 /* Extract type info from the tuple itself */
365 ncolumns = tupdesc->natts;
366
367 /* Build a temporary HeapTuple control structure */
370 tuple.t_tableOid = InvalidOid;
371 tuple.t_data = rec;
372
373 values = (Datum *) palloc(ncolumns * sizeof(Datum));
374 nulls = (bool *) palloc(ncolumns * sizeof(bool));
375
376 heap_deform_tuple(&tuple, tupdesc, values, nulls);
377
379
380 for (i = 0; i < ncolumns; i++)
381 {
382 varlena *attr;
385
386 /* only work on existing, not-null varlenas */
387 if (TupleDescAttr(tupdesc, i)->attisdropped ||
388 nulls[i] ||
389 TupleDescAttr(tupdesc, i)->attlen != -1 ||
391 continue;
392
393 attr = (varlena *) DatumGetPointer(values[i]);
394
395 /* don't recursively indirect */
397 continue;
398
399 /* copy datum, so it still lives later */
401 attr = detoast_external_attr(attr);
402 else
403 {
404 varlena *oldattr = attr;
405
406 attr = palloc0(VARSIZE_ANY(oldattr));
408 }
409
410 /* build indirection Datum */
412 redirect_pointer.pointer = attr;
415 sizeof(redirect_pointer));
416
418 }
419
420 newtup = heap_form_tuple(tupdesc, values, nulls);
421 pfree(values);
422 pfree(nulls);
423 ReleaseTupleDesc(tupdesc);
424
426
427 /*
428 * We intentionally don't use PG_RETURN_HEAPTUPLEHEADER here, because that
429 * would cause the indirect toast pointers to be flattened out of the
430 * tuple immediately, rendering subsequent testing irrelevant. So just
431 * return the HeapTupleHeader pointer as-is. This violates the general
432 * rule that composite Datums shouldn't contain toast pointers, but so
433 * long as the regression test scripts don't insert the result of this
434 * function into a container type (record, array, etc) it should be OK.
435 */
436 PG_RETURN_POINTER(newtup->t_data);
437}
static Datum values[MAXATTR]
Definition bootstrap.c:190
memcpy(sums, checksumBaseOffsets, sizeof(checksumBaseOffsets))
varlena * detoast_external_attr(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:1025
void heap_deform_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *values, bool *isnull)
Definition heaptuple.c:1254
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:172
void pfree(void *pointer)
Definition mcxt.c:1619
void * palloc0(Size size)
Definition mcxt.c:1420
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition palloc.h:138
char attstorage
int16 attlen
static Pointer DatumGetPointer(Datum X)
Definition postgres.h:332
#define PointerGetDatum(X)
Definition postgres.h:354
#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:776
#define ReleaseTupleDesc(tupdesc)
Definition tupdesc.h:240
static FormData_pg_attribute * TupleDescAttr(TupleDesc tupdesc, int i)
Definition tupdesc.h:178
TupleDesc lookup_rowtype_tupdesc(Oid type_id, int32 typmod)
Definition typcache.c:1947
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(), memcpy(), 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 153 of file regress.c.

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

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

◆ PG_FUNCTION_INFO_V1() [1/35]

PG_FUNCTION_INFO_V1 ( binary_coercible  )

◆ PG_FUNCTION_INFO_V1() [2/35]

PG_FUNCTION_INFO_V1 ( get_environ  )

◆ PG_FUNCTION_INFO_V1() [3/35]

PG_FUNCTION_INFO_V1 ( int44in  )

◆ PG_FUNCTION_INFO_V1() [4/35]

PG_FUNCTION_INFO_V1 ( int44out  )

◆ PG_FUNCTION_INFO_V1() [5/35]

PG_FUNCTION_INFO_V1 ( interpt_pp  )

◆ PG_FUNCTION_INFO_V1() [6/35]

PG_FUNCTION_INFO_V1 ( is_catalog_text_unique_index_oid  )

◆ PG_FUNCTION_INFO_V1() [7/35]

PG_FUNCTION_INFO_V1 ( make_tuple_indirect  )

◆ PG_FUNCTION_INFO_V1() [8/35]

PG_FUNCTION_INFO_V1 ( overpaid  )

◆ PG_FUNCTION_INFO_V1() [9/35]

PG_FUNCTION_INFO_V1 ( pt_in_widget  )

◆ PG_FUNCTION_INFO_V1() [10/35]

PG_FUNCTION_INFO_V1 ( regress_setenv  )

◆ PG_FUNCTION_INFO_V1() [11/35]

PG_FUNCTION_INFO_V1 ( reverse_name  )

◆ PG_FUNCTION_INFO_V1() [12/35]

PG_FUNCTION_INFO_V1 ( test_atomic_ops  )

◆ PG_FUNCTION_INFO_V1() [13/35]

PG_FUNCTION_INFO_V1 ( test_bytea_to_text  )

◆ PG_FUNCTION_INFO_V1() [14/35]

PG_FUNCTION_INFO_V1 ( test_canonicalize_path  )

◆ PG_FUNCTION_INFO_V1() [15/35]

PG_FUNCTION_INFO_V1 ( test_enc_conversion  )

◆ PG_FUNCTION_INFO_V1() [16/35]

PG_FUNCTION_INFO_V1 ( test_enc_setup  )

◆ PG_FUNCTION_INFO_V1() [17/35]

PG_FUNCTION_INFO_V1 ( test_fdw_connection  )

◆ PG_FUNCTION_INFO_V1() [18/35]

PG_FUNCTION_INFO_V1 ( test_fdw_handler  )

◆ PG_FUNCTION_INFO_V1() [19/35]

PG_FUNCTION_INFO_V1 ( test_inline_in_from_support_func  )

◆ PG_FUNCTION_INFO_V1() [20/35]

PG_FUNCTION_INFO_V1 ( test_instr_time  )

◆ PG_FUNCTION_INFO_V1() [21/35]

PG_FUNCTION_INFO_V1 ( test_mblen_func  )

◆ PG_FUNCTION_INFO_V1() [22/35]

PG_FUNCTION_INFO_V1 ( test_opclass_options_func  )

◆ PG_FUNCTION_INFO_V1() [23/35]

PG_FUNCTION_INFO_V1 ( test_pglz_compress  )

◆ PG_FUNCTION_INFO_V1() [24/35]

PG_FUNCTION_INFO_V1 ( test_pglz_decompress  )

◆ PG_FUNCTION_INFO_V1() [25/35]

PG_FUNCTION_INFO_V1 ( test_relpath  )

◆ PG_FUNCTION_INFO_V1() [26/35]

PG_FUNCTION_INFO_V1 ( test_support_func  )

◆ PG_FUNCTION_INFO_V1() [27/35]

PG_FUNCTION_INFO_V1 ( test_text_to_bytea  )

◆ PG_FUNCTION_INFO_V1() [28/35]

PG_FUNCTION_INFO_V1 ( test_text_to_wchars  )

◆ PG_FUNCTION_INFO_V1() [29/35]

PG_FUNCTION_INFO_V1 ( test_translation  )

◆ PG_FUNCTION_INFO_V1() [30/35]

PG_FUNCTION_INFO_V1 ( test_valid_server_encoding  )

◆ PG_FUNCTION_INFO_V1() [31/35]

PG_FUNCTION_INFO_V1 ( test_wchars_to_text  )

◆ PG_FUNCTION_INFO_V1() [32/35]

PG_FUNCTION_INFO_V1 ( trigger_return_old  )

◆ PG_FUNCTION_INFO_V1() [33/35]

PG_FUNCTION_INFO_V1 ( wait_pid  )

◆ PG_FUNCTION_INFO_V1() [34/35]

PG_FUNCTION_INFO_V1 ( widget_in  )

◆ PG_FUNCTION_INFO_V1() [35/35]

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

230{
233 float8 distance;
234
237 PointPGetDatum(&widget->center)));
238
240}
double float8
Definition c.h:714
#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:2044
static float8 DatumGetFloat8(Datum X)
Definition postgres.h:498

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

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

References fb().

Referenced by interpt_pp().

◆ regress_setenv()

Datum regress_setenv ( PG_FUNCTION_ARGS  )

Definition at line 467 of file regress.c.

468{
469 char *envvar = text_to_cstring(PG_GETARG_TEXT_PP(0));
471
472 if (!superuser())
473 elog(ERROR, "must be superuser to change environment variables");
474
475 if (setenv(envvar, envval, 1) != 0)
476 elog(ERROR, "could not set environment variable: %m");
477
479}
#define elog(elevel,...)
Definition elog.h:228
#define PG_RETURN_VOID()
Definition fmgr.h:350
#define PG_GETARG_TEXT_PP(n)
Definition fmgr.h:310
bool superuser(void)
Definition superuser.c:47
char * text_to_cstring(const text *t)
Definition varlena.c:217
#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 245 of file regress.c.

246{
247 char *string = PG_GETARG_CSTRING(0);
248 int i;
249 int len;
250 char *new_string;
251
253 for (i = 0; i < NAMEDATALEN && string[i]; ++i)
254 ;
255 if (i == NAMEDATALEN || !string[i])
256 --i;
257 len = i;
258 for (; i >= 0; --i)
259 new_string[len - i] = string[i];
261}
#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 505 of file regress.c.

506{
508
518}
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:57
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 710 of file regress.c.

711{
713
715
717
718 /*
719 * Arguably this shouldn't be tested as part of this function, but it's
720 * closely enough related that that seems ok for now.
721 */
723
724 PG_RETURN_BOOL(true);
725}
static void test_spinlock(void)
Definition regress.c:646
static void test_atomic_uint32(void)
Definition regress.c:521
static void test_atomic_flag(void)
Definition regress.c:505
static void test_atomic_uint64(void)
Definition regress.c:593

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

522{
525 int i;
526
527 pg_atomic_init_u32(&var, 0);
529 pg_atomic_write_u32(&var, 3);
532 3);
538
539 /* test around numerical limits */
542 pg_atomic_fetch_add_u32(&var, 2); /* wrap to 0 */
547 2 * PG_INT16_MAX + 1);
550 pg_atomic_fetch_add_u32(&var, 1); /* top up to UINT_MAX */
564
565 /* fail exchange because of old expected */
566 expected = 10;
568
569 /* CAS is allowed to fail due to interrupts, try a couple of times */
570 for (i = 0; i < 1000; i++)
571 {
572 expected = 0;
574 break;
575 }
576 if (i == 1000)
577 elog(ERROR, "atomic_compare_exchange_u32() never succeeded");
579 pg_atomic_write_u32(&var, 0);
580
581 /* try setting flagbits */
582 EXPECT_TRUE(!(pg_atomic_fetch_or_u32(&var, 1) & 1));
585 /* try clearing flagbits */
586 EXPECT_EQ_U32(pg_atomic_fetch_and_u32(&var, ~2) & 3, 3);
588 /* no bits set anymore */
590}
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:669
#define PG_INT16_MAX
Definition c.h:670
#define EXPECT_EQ_U32(result_expr, expected_expr)
Definition regress.c:65

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

594{
597 int i;
598
599 pg_atomic_init_u64(&var, 0);
601 pg_atomic_write_u64(&var, 3);
604 3);
610
611 /* fail exchange because of old expected */
612 expected = 10;
614
615 /* CAS is allowed to fail due to interrupts, try a couple of times */
616 for (i = 0; i < 100; i++)
617 {
618 expected = 0;
620 break;
621 }
622 if (i == 100)
623 elog(ERROR, "atomic_compare_exchange_u64() never succeeded");
625
626 pg_atomic_write_u64(&var, 0);
627
628 /* try setting flagbits */
629 EXPECT_TRUE(!(pg_atomic_fetch_or_u64(&var, 1) & 1));
632 /* try clearing flagbits */
633 EXPECT_EQ_U64((pg_atomic_fetch_and_u64(&var, ~2) & 3), 3);
635 /* no bits set anymore */
637}
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:75

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

Datum test_bytea_to_text ( PG_FUNCTION_ARGS  )

Definition at line 1133 of file regress.c.

1134{
1136}
#define PG_GETARG_BYTEA_PP(n)
Definition fmgr.h:309
#define PG_RETURN_TEXT_P(x)
Definition fmgr.h:374

References PG_GETARG_BYTEA_PP, and PG_RETURN_TEXT_P.

◆ test_canonicalize_path()

Datum test_canonicalize_path ( PG_FUNCTION_ARGS  )

Definition at line 333 of file regress.c.

334{
335 char *path = text_to_cstring(PG_GETARG_TEXT_PP(0));
336
337 canonicalize_path(path);
339}
void canonicalize_path(char *path)
Definition path.c:337
text * cstring_to_text(const char *s)
Definition varlena.c:184

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

◆ test_enc_conversion()

Datum test_enc_conversion ( PG_FUNCTION_ARGS  )

Definition at line 1016 of file regress.c.

1017{
1018 bytea *string = PG_GETARG_BYTEA_PP(0);
1023 bool noError = PG_GETARG_BOOL(3);
1024 TupleDesc tupdesc;
1025 char *src;
1026 char *dst;
1027 bytea *retval;
1028 Size srclen;
1029 Size dstsize;
1030 Oid proc;
1031 int convertedbytes;
1032 int dstlen;
1033 Datum values[2];
1034 bool nulls[2] = {0};
1035 HeapTuple tuple;
1036
1037 if (src_encoding < 0)
1038 ereport(ERROR,
1040 errmsg("invalid source encoding name \"%s\"",
1042 if (dest_encoding < 0)
1043 ereport(ERROR,
1045 errmsg("invalid destination encoding name \"%s\"",
1047
1048 /* Build a tuple descriptor for our result type */
1049 if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
1050 elog(ERROR, "return type must be a row type");
1051 tupdesc = BlessTupleDesc(tupdesc);
1052
1053 srclen = VARSIZE_ANY_EXHDR(string);
1054 src = VARDATA_ANY(string);
1055
1057 {
1058 /* just check that the source string is valid */
1059 int oklen;
1060
1062
1063 if (oklen == srclen)
1064 {
1066 retval = string;
1067 }
1068 else if (!noError)
1069 {
1071 }
1072 else
1073 {
1074 /*
1075 * build bytea data type structure.
1076 */
1077 Assert(oklen < srclen);
1079 retval = (bytea *) palloc(oklen + VARHDRSZ);
1080 SET_VARSIZE(retval, oklen + VARHDRSZ);
1081 memcpy(VARDATA(retval), src, oklen);
1082 }
1083 }
1084 else
1085 {
1087 if (!OidIsValid(proc))
1088 ereport(ERROR,
1090 errmsg("default conversion function for encoding \"%s\" to \"%s\" does not exist",
1093
1095 ereport(ERROR,
1097 errmsg("out of memory"),
1098 errdetail("String of %d bytes is too long for encoding conversion.",
1099 (int) srclen)));
1100
1103
1104 /* perform conversion */
1108 (unsigned char *) src, srclen,
1109 (unsigned char *) dst, dstsize,
1110 noError);
1111 dstlen = strlen(dst);
1112
1113 /*
1114 * build bytea data type structure.
1115 */
1116 retval = (bytea *) palloc(dstlen + VARHDRSZ);
1117 SET_VARSIZE(retval, dstlen + VARHDRSZ);
1118 memcpy(VARDATA(retval), dst, dstlen);
1119
1120 pfree(dst);
1121 }
1122
1124 values[1] = PointerGetDatum(retval);
1125 tuple = heap_form_tuple(tupdesc, values, nulls);
1126
1128}
#define NameStr(name)
Definition c.h:835
#define VARHDRSZ
Definition c.h:781
#define Assert(condition)
Definition c.h:943
#define OidIsValid(objectId)
Definition c.h:858
size_t Size
Definition c.h:689
int errcode(int sqlerrcode)
Definition elog.c:875
int errdetail(const char *fmt,...) pg_attribute_printf(1
#define ereport(elevel,...)
Definition elog.h:152
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
#define MaxAllocSize
Definition fe_memutils.h:22
#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:478
void report_invalid_encoding(int encoding, const char *mbstr, int len)
Definition mbutils.c:1825
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition mcxt.c:1235
MemoryContext CurrentMemoryContext
Definition mcxt.c:161
Oid FindDefaultConversionProc(int32 for_encoding, int32 to_encoding)
Definition namespace.c:4152
static char * errmsg
#define MAX_CONVERSION_GROWTH
Definition pg_wchar.h:155
#define pg_encoding_to_char
Definition pg_wchar.h:483
#define pg_char_to_encoding
Definition pg_wchar.h:482
static Datum Int32GetDatum(int32 X)
Definition postgres.h:212
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:2002

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, memcpy(), 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 951 of file regress.c.

952{
953 /* Test pg_encoding_set_invalid() */
954 for (int i = 0; i < _PG_LAST_ENCODING_; i++)
955 {
956 char buf[2],
957 bigbuf[16];
958 int len,
959 mblen,
960 valid;
961
962 if (!PG_VALID_ENCODING(i))
963 continue;
964 if (pg_encoding_max_length(i) == 1)
965 continue;
967 len = strnlen(buf, 2);
968 if (len != 2)
970 "official invalid string for encoding \"%s\" has length %d",
972 mblen = pg_encoding_mblen(i, buf);
973 if (mblen != 2)
975 "official invalid string for encoding \"%s\" has mblen %d",
976 pg_enc2name_tbl[i].name, mblen);
977 valid = pg_encoding_verifymbstr(i, buf, len);
978 if (valid != 0)
980 "official invalid string for encoding \"%s\" has valid prefix of length %d",
981 pg_enc2name_tbl[i].name, valid);
982 valid = pg_encoding_verifymbstr(i, buf, 1);
983 if (valid != 0)
985 "first byte of official invalid string for encoding \"%s\" has valid prefix of length %d",
986 pg_enc2name_tbl[i].name, valid);
987 memset(bigbuf, ' ', sizeof(bigbuf));
988 bigbuf[0] = buf[0];
989 bigbuf[1] = buf[1];
990 valid = pg_encoding_verifymbstr(i, bigbuf, sizeof(bigbuf));
991 if (valid != 0)
993 "trailing data changed official invalid string for encoding \"%s\" to have valid prefix of length %d",
994 pg_enc2name_tbl[i].name, valid);
995 }
996
998}
#define WARNING
Definition elog.h:37
const pg_enc2name pg_enc2name_tbl[]
Definition encnames.c:308
static char buf[DEFAULT_XLOG_SEG_SIZE]
@ _PG_LAST_ENCODING_
Definition pg_wchar.h:121
#define PG_VALID_ENCODING(_enc)
Definition pg_wchar.h:140
const char * name
void pg_encoding_set_invalid(int encoding, char *dst)
Definition wchar.c:1852
int pg_encoding_max_length(int encoding)
Definition wchar.c:2013
int pg_encoding_mblen(int encoding, const char *mbstr)
Definition wchar.c:1935

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, PG_VALID_ENCODING, and WARNING.

◆ test_fdw_connection()

Datum test_fdw_connection ( PG_FUNCTION_ARGS  )

Definition at line 737 of file regress.c.

738{
739 PG_RETURN_TEXT_P(cstring_to_text("dbname=regress_doesnotexist user=doesnotexist password=secret"));
740}

References cstring_to_text(), and PG_RETURN_TEXT_P.

◆ test_fdw_handler()

Datum test_fdw_handler ( PG_FUNCTION_ARGS  )

Definition at line 729 of file regress.c.

730{
731 elog(ERROR, "test_fdw_handler is not implemented");
733}

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

825{
827
829 {
830 /*
831 * Assume that the target is foo_from_bar; that's safe as long as we
832 * don't attach this to any other function.
833 */
835 StringInfoData sql;
836 RangeTblFunction *rtfunc = req->rtfunc;
837 FuncExpr *expr = (FuncExpr *) rtfunc->funcexpr;
838 Node *node;
839 Const *c;
840 char *colname;
841 char *tablename;
846
847 if (list_length(expr->args) != 3)
848 {
849 ereport(WARNING, (errmsg("test_inline_in_from_support_func called with %d args but expected 3", list_length(expr->args))));
851 }
852
853 /* Get colname */
854 node = linitial(expr->args);
855 if (!IsA(node, Const))
856 {
857 ereport(WARNING, (errmsg("test_inline_in_from_support_func called with non-Const parameters")));
859 }
860
861 c = (Const *) node;
862 if (c->consttype != TEXTOID || c->constisnull)
863 {
864 ereport(WARNING, (errmsg("test_inline_in_from_support_func called with non-TEXT parameters")));
866 }
867 colname = TextDatumGetCString(c->constvalue);
868
869 /* Get tablename */
870 node = lsecond(expr->args);
871 if (!IsA(node, Const))
872 {
873 ereport(WARNING, (errmsg("test_inline_in_from_support_func called with non-Const parameters")));
875 }
876
877 c = (Const *) node;
878 if (c->consttype != TEXTOID || c->constisnull)
879 {
880 ereport(WARNING, (errmsg("test_inline_in_from_support_func called with non-TEXT parameters")));
882 }
883 tablename = TextDatumGetCString(c->constvalue);
884
885 /* Begin constructing replacement SELECT query. */
886 initStringInfo(&sql);
887 appendStringInfo(&sql, "SELECT %s::text FROM %s",
888 quote_identifier(colname),
889 quote_identifier(tablename));
890
891 /* Add filter expression if present. */
892 node = lthird(expr->args);
893 if (!(IsA(node, Const) && ((Const *) node)->constisnull))
894 {
895 /*
896 * We only filter if $3 is not constant-NULL. This is not a very
897 * exact implementation of the PL/pgSQL original, but it's close
898 * enough for demonstration purposes.
899 */
900 appendStringInfo(&sql, " WHERE %s::text = $3",
901 quote_identifier(colname));
902 }
903
904 /* Build a SQLFunctionParseInfo with the parameters of my function. */
905 pinfo = prepare_sql_fn_parse_info(req->proc,
906 (Node *) expr,
907 expr->inputcollid);
908
909 /* Parse the generated SQL. */
912 {
913 ereport(WARNING, (errmsg("test_inline_in_from_support_func parsed to more than one node")));
915 }
916
917 /* Analyze the parse tree as if it were a SQL-language body. */
919 sql.data,
921 pinfo, NULL);
922 if (list_length(querytree_list) != 1)
923 {
924 ereport(WARNING, (errmsg("test_inline_in_from_support_func rewrote to more than one node")));
926 }
927
929 if (!IsA(querytree, Query))
930 {
931 ereport(WARNING, (errmsg("test_inline_in_from_support_func didn't parse to a Query")));
933 }
934
936 }
937
939}
Datum querytree(PG_FUNCTION_ARGS)
Definition _int_bool.c:711
#define TextDatumGetCString(d)
Definition builtins.h:99
void sql_fn_parser_setup(struct ParseState *pstate, SQLFunctionParseInfoPtr pinfo)
Definition functions.c:341
SQLFunctionParseInfoPtr prepare_sql_fn_parse_info(HeapTuple procedureTuple, Node *call_expr, Oid inputCollation)
Definition functions.c:252
#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:775
List * pg_parse_query(const char *query_string)
Definition postgres.c:616
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_instr_time()

Datum test_instr_time ( PG_FUNCTION_ARGS  )

Definition at line 1396 of file regress.c.

1397{
1398 instr_time t;
1399 int64 test_ns[] = {0, 1000, INT64CONST(1000000000000000)};
1400 int64 max_err;
1401
1402 /*
1403 * The ns-to-ticks-to-ns roundtrip may lose precision due to integer
1404 * truncation in the fixed-point conversion. The maximum error depends on
1405 * ticks_per_ns_scaled relative to the shift factor.
1406 */
1408
1409 for (int i = 0; i < lengthof(test_ns); i++)
1410 {
1411 int64 result;
1412
1416
1417 if (result < test_ns[i] - max_err || result > test_ns[i])
1418 elog(ERROR,
1419 "INSTR_TIME_GET_NANOSEC(t) yielded " INT64_FORMAT
1420 ", expected " INT64_FORMAT " (max_err " INT64_FORMAT
1421 ") in file \"%s\" line %u",
1423 }
1424
1425 PG_RETURN_BOOL(true);
1426}
#define INT64CONST(x)
Definition c.h:630
#define INT64_FORMAT
Definition c.h:634
int64_t int64
Definition c.h:621
#define lengthof(array)
Definition c.h:873
uint64 ticks_per_ns_scaled
Definition instr_time.c:61
#define TICKS_TO_NS_SHIFT
Definition instr_time.h:89
#define INSTR_TIME_GET_NANOSEC(t)
Definition instr_time.h:445
#define INSTR_TIME_ADD_NANOSEC(t, n)
Definition instr_time.h:433
#define INSTR_TIME_SET_ZERO(t)
Definition instr_time.h:421

References elog, ERROR, fb(), i, INSTR_TIME_ADD_NANOSEC, INSTR_TIME_GET_NANOSEC, INSTR_TIME_SET_ZERO, INT64_FORMAT, INT64CONST, lengthof, PG_RETURN_BOOL, result, ticks_per_ns_scaled, and TICKS_TO_NS_SHIFT.

◆ test_mblen_func()

Datum test_mblen_func ( PG_FUNCTION_ARGS  )

Definition at line 1149 of file regress.c.

1150{
1151 const char *func = text_to_cstring(PG_GETARG_BYTEA_PP(0));
1153 text *string = PG_GETARG_BYTEA_PP(2);
1154 int offset = PG_GETARG_INT32(3);
1155 const char *data = VARDATA_ANY(string);
1156 size_t size = VARSIZE_ANY_EXHDR(string);
1157 int result = 0;
1158
1159 if (strcmp(func, "pg_mblen_unbounded") == 0)
1160 result = pg_mblen_unbounded(data + offset);
1161 else if (strcmp(func, "pg_mblen_cstr") == 0)
1162 result = pg_mblen_cstr(data + offset);
1163 else if (strcmp(func, "pg_mblen_with_len") == 0)
1164 result = pg_mblen_with_len(data + offset, size - offset);
1165 else if (strcmp(func, "pg_mblen_range") == 0)
1166 result = pg_mblen_range(data + offset, data + size);
1167 else if (strcmp(func, "pg_encoding_mblen") == 0)
1169 else
1170 elog(ERROR, "unknown function");
1171
1173}
#define PG_RETURN_INT32(x)
Definition fmgr.h:355
#define PG_GETARG_INT32(n)
Definition fmgr.h:269
static char * encoding
Definition initdb.c:139
int pg_mblen_cstr(const char *mbstr)
Definition mbutils.c:1045
int pg_mblen_unbounded(const char *mbstr)
Definition mbutils.c:1137
int pg_mblen_range(const char *mbstr, const char *end)
Definition mbutils.c:1084
int pg_mblen_with_len(const char *mbstr, int limit)
Definition mbutils.c:1108
const void * data

References data, elog, encoding, ERROR, fb(), pg_char_to_encoding, pg_encoding_mblen(), PG_GETARG_BYTEA_PP, PG_GETARG_INT32, pg_mblen_cstr(), pg_mblen_range(), pg_mblen_unbounded(), pg_mblen_with_len(), PG_RETURN_INT32, result, text_to_cstring(), VARDATA_ANY(), and VARSIZE_ANY_EXHDR().

◆ test_opclass_options_func()

Datum test_opclass_options_func ( PG_FUNCTION_ARGS  )

Definition at line 943 of file regress.c.

944{
946}

References PG_RETURN_NULL.

◆ test_pglz_compress()

Datum test_pglz_compress ( PG_FUNCTION_ARGS  )

Definition at line 1438 of file regress.c.

1439{
1441 char *source = VARDATA_ANY(input);
1444 bytea *result;
1445 int32 clen;
1446
1450 if (clen < 0)
1452
1455}
#define PG_RETURN_BYTEA_P(x)
Definition fmgr.h:373
FILE * input
const PGLZ_Strategy *const PGLZ_strategy_always
int32 pglz_compress(const char *source, int32 slen, char *dest, const PGLZ_Strategy *strategy)
#define PGLZ_MAX_OUTPUT(_dlen)
static rewind_source * source
Definition pg_rewind.c:89

References fb(), input, palloc(), PG_GETARG_BYTEA_PP, PG_RETURN_BYTEA_P, PG_RETURN_NULL, pglz_compress(), PGLZ_MAX_OUTPUT, PGLZ_strategy_always, result, SET_VARSIZE(), source, VARDATA(), VARDATA_ANY(), VARHDRSZ, and VARSIZE_ANY_EXHDR().

◆ test_pglz_decompress()

Datum test_pglz_decompress ( PG_FUNCTION_ARGS  )

Definition at line 1469 of file regress.c.

1470{
1474 char *source = VARDATA_ANY(input);
1476 bytea *result;
1477 int32 dlen;
1478
1479 if (rawsize < 0)
1480 elog(ERROR, "rawsize must not be negative");
1481
1483
1486 if (dlen < 0)
1487 elog(ERROR, "pglz_decompress failed");
1488
1491}
int32 pglz_decompress(const char *source, int32 slen, char *dest, int32 rawsize, bool check_complete)

References elog, ERROR, fb(), input, palloc(), PG_GETARG_BOOL, PG_GETARG_BYTEA_PP, PG_GETARG_INT32, PG_RETURN_BYTEA_P, pglz_decompress(), result, SET_VARSIZE(), source, VARDATA(), VARDATA_ANY(), VARHDRSZ, and VARSIZE_ANY_EXHDR().

◆ test_relpath()

Datum test_relpath ( PG_FUNCTION_ARGS  )

Definition at line 1285 of file regress.c.

1286{
1287 RelPathStr rpath;
1288
1289 /*
1290 * Verify that PROCNUMBER_CHARS and MAX_BACKENDS stay in sync.
1291 * Unfortunately I don't know how to express that in a way suitable for a
1292 * static assert.
1293 */
1294 if ((int) ceil(log10(MAX_BACKENDS)) != PROCNUMBER_CHARS)
1295 elog(WARNING, "mismatch between MAX_BACKENDS and PROCNUMBER_CHARS");
1296
1297 /* verify that the max-length relpath is generated ok */
1299 INIT_FORKNUM);
1300
1301 if (strlen(rpath.str) != REL_PATH_STR_MAXLEN)
1302 elog(WARNING, "maximum length relpath is if length %zu instead of %zu",
1304
1306}
#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 646 of file regress.c.

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

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

752{
754 Node *ret = NULL;
755
757 {
758 /*
759 * Assume that the target is int4eq; that's safe as long as we don't
760 * attach this to any other boolean-returning function.
761 */
764
765 if (req->is_join)
767 req->args,
768 req->inputcollid,
769 req->jointype,
770 req->sjinfo);
771 else
773 req->args,
774 req->inputcollid,
775 req->varRelid);
776
777 req->selectivity = s1;
778 ret = (Node *) req;
779 }
780
782 {
783 /* Provide some generic estimate */
785
786 req->startup = 0;
787 req->per_tuple = 2 * cpu_operator_cost;
788 ret = (Node *) req;
789 }
790
792 {
793 /*
794 * Assume that the target is generate_series_int4; that's safe as long
795 * as we don't attach this to any other set-returning function.
796 */
798
799 if (req->node && IsA(req->node, FuncExpr)) /* be paranoid */
800 {
801 List *args = ((FuncExpr *) req->node)->args;
802 Node *arg1 = linitial(args);
803 Node *arg2 = lsecond(args);
804
805 if (IsA(arg1, Const) &&
806 !((Const *) arg1)->constisnull &&
807 IsA(arg2, Const) &&
808 !((Const *) arg2)->constisnull)
809 {
812
813 req->rows = val2 - val1 + 1;
814 ret = (Node *) req;
815 }
816 }
817 }
818
820}
double cpu_operator_cost
Definition costsize.c:135
double Selectivity
Definition nodes.h:260
Selectivity restriction_selectivity(PlannerInfo *root, Oid operatorid, List *args, Oid inputcollid, int varRelid)
Definition plancat.c:2225
Selectivity join_selectivity(PlannerInfo *root, Oid operatorid, List *args, Oid inputcollid, JoinType jointype, SpecialJoinInfo *sjinfo)
Definition plancat.c:2264
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_text_to_bytea()

Datum test_text_to_bytea ( PG_FUNCTION_ARGS  )

Definition at line 1141 of file regress.c.

1142{
1144}

References PG_GETARG_TEXT_PP, and PG_RETURN_BYTEA_P.

◆ test_text_to_wchars()

Datum test_text_to_wchars ( PG_FUNCTION_ARGS  )

Definition at line 1177 of file regress.c.

1178{
1180 text *string = PG_GETARG_TEXT_PP(1);
1181 const char *data = VARDATA_ANY(string);
1182 size_t size = VARSIZE_ANY_EXHDR(string);
1183 pg_wchar *wchars = palloc(sizeof(pg_wchar) * (size + 1));
1184 Datum *datums;
1185 int wlen;
1186 int encoding;
1187
1189 if (encoding < 0)
1190 elog(ERROR, "unknown encoding name: %s", encoding_name);
1191
1192 if (size > 0)
1193 {
1194 datums = palloc(sizeof(Datum) * size);
1196 data,
1197 wchars,
1198 size);
1199 Assert(wlen >= 0);
1200 Assert(wlen <= size);
1201 Assert(wchars[wlen] == 0);
1202
1203 for (int i = 0; i < wlen; ++i)
1204 datums[i] = UInt32GetDatum(wchars[i]);
1205 }
1206 else
1207 {
1208 datums = NULL;
1209 wlen = 0;
1210 }
1211
1213}
#define PG_RETURN_ARRAYTYPE_P(x)
Definition array.h:265
unsigned int pg_wchar
Definition mbprint.c:31
int pg_encoding_mb2wchar_with_len(int encoding, const char *from, pg_wchar *to, int len)
Definition mbutils.c:1004
static Datum UInt32GetDatum(uint32 X)
Definition postgres.h:232

References Assert, construct_array_builtin(), data, elog, encoding, ERROR, fb(), i, palloc(), pg_char_to_encoding, pg_encoding_mb2wchar_with_len(), PG_GETARG_BYTEA_PP, PG_GETARG_TEXT_PP, PG_RETURN_ARRAYTYPE_P, text_to_cstring(), UInt32GetDatum(), VARDATA_ANY(), and VARSIZE_ANY_EXHDR().

◆ test_translation()

Datum test_translation ( PG_FUNCTION_ARGS  )

Definition at line 1317 of file regress.c.

1318{
1319#ifdef ENABLE_NLS
1320 static bool inited = false;
1321
1322 /*
1323 * Ideally we'd do this bit in a _PG_init() hook. However, it seems best
1324 * that the Solaris hack only get applied in the nls.sql test, so it
1325 * doesn't risk affecting other tests that load this module.
1326 */
1327 if (!inited)
1328 {
1329 /*
1330 * Solaris' built-in gettext is not bright about associating locales
1331 * with message catalogs that are named after just the language.
1332 * Apparently the customary workaround is for users to set the
1333 * LANGUAGE environment variable to provide a mapping. Do so here to
1334 * ensure that the nls.sql regression test will work.
1335 */
1336#if defined(__sun__)
1337 setenv("LANGUAGE", "es_ES.UTF-8:es", 1);
1338#endif
1340 inited = true;
1341 }
1342
1343 /*
1344 * If nls.sql failed to select a non-C locale, no translation will happen.
1345 * Report that so that we can distinguish this outcome from brokenness.
1346 * (We do this here, not in nls.sql, so as to need only 3 expected files.)
1347 */
1348 if (strcmp(GetConfigOption("lc_messages", false, false), "C") == 0)
1349 elog(NOTICE, "lc_messages is 'C'");
1350#else
1351 elog(NOTICE, "NLS is not enabled");
1352#endif
1353
1355 errmsg("translated PRId64 = %" PRId64, (int64) 424242424242));
1357 errmsg("translated PRId32 = %" PRId32, (int32) -1234));
1359 errmsg("translated PRIdMAX = %" PRIdMAX, (intmax_t) -123456789012));
1361 errmsg("translated PRIdPTR = %" PRIdPTR, (intptr_t) -9999));
1362
1364 errmsg("translated PRIu64 = %" PRIu64, (uint64) 424242424242));
1366 errmsg("translated PRIu32 = %" PRIu32, (uint32) -1234));
1368 errmsg("translated PRIuMAX = %" PRIuMAX, (uintmax_t) 123456789012));
1370 errmsg("translated PRIuPTR = %" PRIuPTR, (uintptr_t) 9999));
1371
1373 errmsg("translated PRIx64 = %" PRIx64, (uint64) 424242424242));
1375 errmsg("translated PRIx32 = %" PRIx32, (uint32) -1234));
1377 errmsg("translated PRIxMAX = %" PRIxMAX, (uintmax_t) 123456789012));
1379 errmsg("translated PRIxPTR = %" PRIxPTR, (uintptr_t) 9999));
1380
1382 errmsg("translated PRIX64 = %" PRIX64, (uint64) 424242424242));
1384 errmsg("translated PRIX32 = %" PRIX32, (uint32) -1234));
1386 errmsg("translated PRIXMAX = %" PRIXMAX, (uintmax_t) 123456789012));
1388 errmsg("translated PRIXPTR = %" PRIXPTR, (uintptr_t) 9999));
1389
1391}
#define NOTICE
Definition elog.h:36
const char * GetConfigOption(const char *name, bool missing_ok, bool restrict_privileged)
Definition guc.c:4257
void pg_bindtextdomain(const char *domain)
Definition miscinit.c:1890
#define TEXTDOMAIN
Definition regress.c:55

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

◆ test_valid_server_encoding()

Datum test_valid_server_encoding ( PG_FUNCTION_ARGS  )

Definition at line 1264 of file regress.c.

1265{
1267}
#define pg_valid_server_encoding
Definition pg_wchar.h:484

References PG_GETARG_TEXT_PP, PG_RETURN_BOOL, pg_valid_server_encoding, and text_to_cstring().

◆ test_wchars_to_text()

Datum test_wchars_to_text ( PG_FUNCTION_ARGS  )

Definition at line 1217 of file regress.c.

1218{
1220 ArrayType *array = PG_GETARG_ARRAYTYPE_P(1);
1221 Datum *datums;
1222 bool *nulls;
1223 char *mb;
1224 text *result;
1225 int wlen;
1226 int bytes;
1227 int encoding;
1228
1230 if (encoding < 0)
1231 elog(ERROR, "unknown encoding name: %s", encoding_name);
1232
1233 deconstruct_array_builtin(array, INT4OID, &datums, &nulls, &wlen);
1234
1235 if (wlen > 0)
1236 {
1237 pg_wchar *wchars = palloc(sizeof(pg_wchar) * wlen);
1238
1239 for (int i = 0; i < wlen; ++i)
1240 {
1241 if (nulls[i])
1242 elog(ERROR, "unexpected NULL in array");
1243 wchars[i] = DatumGetInt32(datums[i]);
1244 }
1245
1248 }
1249 else
1250 {
1251 mb = "";
1252 bytes = 0;
1253 }
1254
1255 result = palloc(bytes + VARHDRSZ);
1256 SET_VARSIZE(result, bytes + VARHDRSZ);
1257 memcpy(VARDATA(result), mb, bytes);
1258
1260}
#define PG_GETARG_ARRAYTYPE_P(n)
Definition array.h:263
void deconstruct_array_builtin(const ArrayType *array, Oid elmtype, Datum **elemsp, bool **nullsp, int *nelemsp)
int pg_encoding_wchar2mb_with_len(int encoding, const pg_wchar *from, char *to, int len)
Definition mbutils.c:1026

References DatumGetInt32(), deconstruct_array_builtin(), elog, encoding, ERROR, fb(), i, memcpy(), palloc(), pg_char_to_encoding, pg_encoding_max_length(), pg_encoding_wchar2mb_with_len(), PG_GETARG_ARRAYTYPE_P, PG_GETARG_BYTEA_PP, PG_RETURN_TEXT_P, result, SET_VARSIZE(), text_to_cstring(), VARDATA(), and VARHDRSZ.

◆ trigger_return_old()

Datum trigger_return_old ( PG_FUNCTION_ARGS  )

Definition at line 266 of file regress.c.

267{
268 TriggerData *trigdata = (TriggerData *) fcinfo->context;
269 HeapTuple tuple;
270
271 if (!CALLED_AS_TRIGGER(fcinfo))
272 elog(ERROR, "trigger_return_old: not fired by trigger manager");
273
274 tuple = trigdata->tg_trigtuple;
275
276 return PointerGetDatum(tuple);
277}
#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 485 of file regress.c.

486{
487 int pid = PG_GETARG_INT32(0);
488
489 if (!superuser())
490 elog(ERROR, "must be superuser to check PID liveness");
491
492 while (kill(pid, 0) == 0)
493 {
495 pg_usleep(50000);
496 }
497
498 if (errno != ESRCH)
499 elog(ERROR, "could not check PID %d liveness: %m", pid);
500
502}
#define CHECK_FOR_INTERRUPTS()
Definition miscadmin.h:125
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 183 of file regress.c.

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

References DELIM, ereport, errcode(), errmsg, ERROR, fb(), i, LDELIM, NARGS, palloc_object, PG_GETARG_CSTRING, PG_RETURN_POINTER, RDELIM, result, and str.

◆ widget_out()

Datum widget_out ( PG_FUNCTION_ARGS  )

Definition at line 217 of file regress.c.

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

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