PostgreSQL Source Code git master
Loading...
Searching...
No Matches
regress.c File Reference
#include "postgres.h"
#include <math.h>
#include <signal.h>
#include "access/detoast.h"
#include "access/htup_details.h"
#include "catalog/catalog.h"
#include "catalog/namespace.h"
#include "catalog/pg_operator.h"
#include "catalog/pg_type.h"
#include "commands/sequence.h"
#include "commands/trigger.h"
#include "executor/executor.h"
#include "executor/functions.h"
#include "executor/spi.h"
#include "funcapi.h"
#include "mb/pg_wchar.h"
#include "miscadmin.h"
#include "nodes/supportnodes.h"
#include "optimizer/optimizer.h"
#include "optimizer/plancat.h"
#include "parser/parse_coerce.h"
#include "port/atomics.h"
#include "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)
 

Macro Definition Documentation

◆ DELIM

#define DELIM   ','

Definition at line 86 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)
uint32_t uint32
Definition c.h:624
#define ERROR
Definition elog.h:40

Definition at line 64 of file regress.c.

65 { \
66 uint32 actual_result = (result_expr); \
67 uint32 expected_result = (expected_expr); \
68 if (actual_result != expected_result) \
69 elog(ERROR, \
70 "%s yielded %u, expected %s in file \"%s\" line %u", \
71 #result_expr, actual_result, #expected_expr, __FILE__, __LINE__); \
72 } while (0)

◆ 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:635
uint64_t uint64
Definition c.h:625

Definition at line 74 of file regress.c.

75 { \
76 uint64 actual_result = (result_expr); \
77 uint64 expected_result = (expected_expr); \
78 if (actual_result != expected_result) \
79 elog(ERROR, \
80 "%s yielded " UINT64_FORMAT ", expected %s in file \"%s\" line %u", \
81 #result_expr, actual_result, #expected_expr, __FILE__, __LINE__); \
82 } while (0)

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

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

◆ LDELIM

#define LDELIM   '('

Definition at line 84 of file regress.c.

◆ NARGS

#define NARGS   3

Definition at line 178 of file regress.c.

◆ RDELIM

#define RDELIM   ')'

Definition at line 85 of file regress.c.

◆ TEXTDOMAIN

#define TEXTDOMAIN   PG_TEXTDOMAIN("postgresql-regress")

Definition at line 54 of file regress.c.

Function Documentation

◆ binary_coercible()

Datum binary_coercible ( PG_FUNCTION_ARGS  )

Definition at line 1270 of file regress.c.

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

441{
442#if !defined(WIN32)
443 extern char **environ;
444#endif
445 int nvals = 0;
447 Datum *env;
448
449 for (char **s = environ; *s; s++)
450 nvals++;
451
452 env = palloc(nvals * sizeof(Datum));
453
454 for (int i = 0; i < nvals; i++)
456
457 result = construct_array_builtin(env, nvals, TEXTOID);
458
460}
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:1387
uint64_t Datum
Definition postgres.h:70
char ** environ

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

◆ int44in()

Datum int44in ( PG_FUNCTION_ARGS  )

Definition at line 291 of file regress.c.

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

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

◆ int44out()

Datum int44out ( PG_FUNCTION_ARGS  )

Definition at line 315 of file regress.c.

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

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

◆ interpt_pp()

Datum interpt_pp ( PG_FUNCTION_ARGS  )

Definition at line 100 of file regress.c.

101{
102 PATH *p1 = PG_GETARG_PATH_P(0);
103 PATH *p2 = PG_GETARG_PATH_P(1);
104 int i,
105 j;
106 LSEG seg1,
107 seg2;
108 bool found; /* We've found the intersection */
109
110 found = false; /* Haven't found it yet */
111
112 for (i = 0; i < p1->npts - 1 && !found; i++)
113 {
114 regress_lseg_construct(&seg1, &p1->p[i], &p1->p[i + 1]);
115 for (j = 0; j < p2->npts - 1 && !found; j++)
116 {
117 regress_lseg_construct(&seg2, &p2->p[j], &p2->p[j + 1]);
119 LsegPGetDatum(&seg1),
120 LsegPGetDatum(&seg2))))
121 found = true;
122 }
123 }
124
125 if (!found)
127
128 /*
129 * Note: DirectFunctionCall2 will kick out an error if lseg_interpt()
130 * returns NULL, but that should be impossible since we know the two
131 * segments intersect.
132 */
134 LsegPGetDatum(&seg1),
135 LsegPGetDatum(&seg2)));
136}
#define DirectFunctionCall2(func, arg1, arg2)
Definition fmgr.h:686
#define PG_RETURN_NULL()
Definition fmgr.h:346
#define PG_RETURN_DATUM(x)
Definition fmgr.h:354
static Datum LsegPGetDatum(const LSEG *X)
Definition geo_decls.h:193
#define PG_GETARG_PATH_P(n)
Definition geo_decls.h:215
Datum lseg_intersect(PG_FUNCTION_ARGS)
Definition geo_ops.c:2217
Datum lseg_interpt(PG_FUNCTION_ARGS)
Definition geo_ops.c:2408
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:141
Point p[FLEXIBLE_ARRAY_MEMBER]
Definition geo_decls.h:120
int32 npts
Definition geo_decls.h:117

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

◆ is_catalog_text_unique_index_oid()

Datum is_catalog_text_unique_index_oid ( PG_FUNCTION_ARGS  )

Definition at line 742 of file regress.c.

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

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

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

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

◆ PG_FUNCTION_INFO_V1() [1/33]

PG_FUNCTION_INFO_V1 ( binary_coercible  )

◆ PG_FUNCTION_INFO_V1() [2/33]

PG_FUNCTION_INFO_V1 ( get_environ  )

◆ PG_FUNCTION_INFO_V1() [3/33]

PG_FUNCTION_INFO_V1 ( int44in  )

◆ PG_FUNCTION_INFO_V1() [4/33]

PG_FUNCTION_INFO_V1 ( int44out  )

◆ PG_FUNCTION_INFO_V1() [5/33]

PG_FUNCTION_INFO_V1 ( interpt_pp  )

◆ PG_FUNCTION_INFO_V1() [6/33]

PG_FUNCTION_INFO_V1 ( is_catalog_text_unique_index_oid  )

◆ PG_FUNCTION_INFO_V1() [7/33]

PG_FUNCTION_INFO_V1 ( make_tuple_indirect  )

◆ PG_FUNCTION_INFO_V1() [8/33]

PG_FUNCTION_INFO_V1 ( overpaid  )

◆ PG_FUNCTION_INFO_V1() [9/33]

PG_FUNCTION_INFO_V1 ( pt_in_widget  )

◆ PG_FUNCTION_INFO_V1() [10/33]

PG_FUNCTION_INFO_V1 ( regress_setenv  )

◆ PG_FUNCTION_INFO_V1() [11/33]

PG_FUNCTION_INFO_V1 ( reverse_name  )

◆ PG_FUNCTION_INFO_V1() [12/33]

PG_FUNCTION_INFO_V1 ( test_atomic_ops  )

◆ PG_FUNCTION_INFO_V1() [13/33]

PG_FUNCTION_INFO_V1 ( test_bytea_to_text  )

◆ PG_FUNCTION_INFO_V1() [14/33]

PG_FUNCTION_INFO_V1 ( test_canonicalize_path  )

◆ PG_FUNCTION_INFO_V1() [15/33]

PG_FUNCTION_INFO_V1 ( test_enc_conversion  )

◆ PG_FUNCTION_INFO_V1() [16/33]

PG_FUNCTION_INFO_V1 ( test_enc_setup  )

◆ PG_FUNCTION_INFO_V1() [17/33]

PG_FUNCTION_INFO_V1 ( test_fdw_connection  )

◆ PG_FUNCTION_INFO_V1() [18/33]

PG_FUNCTION_INFO_V1 ( test_fdw_handler  )

◆ PG_FUNCTION_INFO_V1() [19/33]

PG_FUNCTION_INFO_V1 ( test_inline_in_from_support_func  )

◆ PG_FUNCTION_INFO_V1() [20/33]

PG_FUNCTION_INFO_V1 ( test_instr_time  )

◆ PG_FUNCTION_INFO_V1() [21/33]

PG_FUNCTION_INFO_V1 ( test_mblen_func  )

◆ PG_FUNCTION_INFO_V1() [22/33]

PG_FUNCTION_INFO_V1 ( test_opclass_options_func  )

◆ PG_FUNCTION_INFO_V1() [23/33]

PG_FUNCTION_INFO_V1 ( test_relpath  )

◆ PG_FUNCTION_INFO_V1() [24/33]

PG_FUNCTION_INFO_V1 ( test_support_func  )

◆ PG_FUNCTION_INFO_V1() [25/33]

PG_FUNCTION_INFO_V1 ( test_text_to_bytea  )

◆ PG_FUNCTION_INFO_V1() [26/33]

PG_FUNCTION_INFO_V1 ( test_text_to_wchars  )

◆ PG_FUNCTION_INFO_V1() [27/33]

PG_FUNCTION_INFO_V1 ( test_translation  )

◆ PG_FUNCTION_INFO_V1() [28/33]

PG_FUNCTION_INFO_V1 ( test_valid_server_encoding  )

◆ PG_FUNCTION_INFO_V1() [29/33]

PG_FUNCTION_INFO_V1 ( test_wchars_to_text  )

◆ PG_FUNCTION_INFO_V1() [30/33]

PG_FUNCTION_INFO_V1 ( trigger_return_old  )

◆ PG_FUNCTION_INFO_V1() [31/33]

PG_FUNCTION_INFO_V1 ( wait_pid  )

◆ PG_FUNCTION_INFO_V1() [32/33]

PG_FUNCTION_INFO_V1 ( widget_in  )

◆ PG_FUNCTION_INFO_V1() [33/33]

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

228{
229 Point *point = PG_GETARG_POINT_P(0);
230 WIDGET *widget = (WIDGET *) PG_GETARG_POINTER(1);
231 float8 distance;
232
234 PointPGetDatum(point),
235 PointPGetDatum(&widget->center)));
236
237 PG_RETURN_BOOL(distance < widget->radius);
238}
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:2011
static float8 DatumGetFloat8(Datum X)
Definition postgres.h:485
Point center
Definition regress.c:171

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

142{
143 lseg->p[0].x = pt1->x;
144 lseg->p[0].y = pt1->y;
145 lseg->p[1].x = pt2->x;
146 lseg->p[1].y = pt2->y;
147}
Point p[2]
Definition geo_decls.h:107
float8 y
Definition geo_decls.h:98
float8 x
Definition geo_decls.h:97

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

Referenced by interpt_pp().

◆ regress_setenv()

Datum regress_setenv ( PG_FUNCTION_ARGS  )

Definition at line 465 of file regress.c.

466{
467 char *envvar = text_to_cstring(PG_GETARG_TEXT_PP(0));
468 char *envval = text_to_cstring(PG_GETARG_TEXT_PP(1));
469
470 if (!superuser())
471 elog(ERROR, "must be superuser to change environment variables");
472
473 if (setenv(envvar, envval, 1) != 0)
474 elog(ERROR, "could not set environment variable: %m");
475
477}
#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, PG_GETARG_TEXT_PP, PG_RETURN_VOID, setenv, superuser(), and text_to_cstring().

◆ reverse_name()

Datum reverse_name ( PG_FUNCTION_ARGS  )

Definition at line 243 of file regress.c.

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

504{
505 pg_atomic_flag flag;
506
516}
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:56
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 708 of file regress.c.

709{
711
713
715
716 /*
717 * Arguably this shouldn't be tested as part of this function, but it's
718 * closely enough related that that seems ok for now.
719 */
721
722 PG_RETURN_BOOL(true);
723}
static void test_spinlock(void)
Definition regress.c:644
static void test_atomic_uint32(void)
Definition regress.c:519
static void test_atomic_flag(void)
Definition regress.c:503
static void test_atomic_uint64(void)
Definition regress.c:591

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

520{
522 uint32 expected;
523 int i;
524
525 pg_atomic_init_u32(&var, 0);
527 pg_atomic_write_u32(&var, 3);
530 3);
536
537 /* test around numerical limits */
538 EXPECT_EQ_U32(pg_atomic_fetch_add_u32(&var, INT_MAX), 0);
539 EXPECT_EQ_U32(pg_atomic_fetch_add_u32(&var, INT_MAX), INT_MAX);
540 pg_atomic_fetch_add_u32(&var, 2); /* wrap to 0 */
545 2 * PG_INT16_MAX + 1);
548 pg_atomic_fetch_add_u32(&var, 1); /* top up to UINT_MAX */
549 EXPECT_EQ_U32(pg_atomic_read_u32(&var), UINT_MAX);
550 EXPECT_EQ_U32(pg_atomic_fetch_sub_u32(&var, INT_MAX), UINT_MAX);
551 EXPECT_EQ_U32(pg_atomic_read_u32(&var), (uint32) INT_MAX + 1);
552 EXPECT_EQ_U32(pg_atomic_sub_fetch_u32(&var, INT_MAX), 1);
554 expected = PG_INT16_MAX;
555 EXPECT_TRUE(!pg_atomic_compare_exchange_u32(&var, &expected, 1));
556 expected = PG_INT16_MAX + 1;
557 EXPECT_TRUE(!pg_atomic_compare_exchange_u32(&var, &expected, 1));
558 expected = PG_INT16_MIN;
559 EXPECT_TRUE(!pg_atomic_compare_exchange_u32(&var, &expected, 1));
560 expected = PG_INT16_MIN - 1;
561 EXPECT_TRUE(!pg_atomic_compare_exchange_u32(&var, &expected, 1));
562
563 /* fail exchange because of old expected */
564 expected = 10;
565 EXPECT_TRUE(!pg_atomic_compare_exchange_u32(&var, &expected, 1));
566
567 /* CAS is allowed to fail due to interrupts, try a couple of times */
568 for (i = 0; i < 1000; i++)
569 {
570 expected = 0;
571 if (!pg_atomic_compare_exchange_u32(&var, &expected, 1))
572 break;
573 }
574 if (i == 1000)
575 elog(ERROR, "atomic_compare_exchange_u32() never succeeded");
577 pg_atomic_write_u32(&var, 0);
578
579 /* try setting flagbits */
580 EXPECT_TRUE(!(pg_atomic_fetch_or_u32(&var, 1) & 1));
583 /* try clearing flagbits */
584 EXPECT_EQ_U32(pg_atomic_fetch_and_u32(&var, ~2) & 3, 3);
586 /* no bits set anymore */
588}
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:64

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

592{
594 uint64 expected;
595 int i;
596
597 pg_atomic_init_u64(&var, 0);
599 pg_atomic_write_u64(&var, 3);
602 3);
608
609 /* fail exchange because of old expected */
610 expected = 10;
611 EXPECT_TRUE(!pg_atomic_compare_exchange_u64(&var, &expected, 1));
612
613 /* CAS is allowed to fail due to interrupts, try a couple of times */
614 for (i = 0; i < 100; i++)
615 {
616 expected = 0;
617 if (!pg_atomic_compare_exchange_u64(&var, &expected, 1))
618 break;
619 }
620 if (i == 100)
621 elog(ERROR, "atomic_compare_exchange_u64() never succeeded");
623
624 pg_atomic_write_u64(&var, 0);
625
626 /* try setting flagbits */
627 EXPECT_TRUE(!(pg_atomic_fetch_or_u64(&var, 1) & 1));
630 /* try clearing flagbits */
631 EXPECT_EQ_U64((pg_atomic_fetch_and_u64(&var, ~2) & 3), 3);
633 /* no bits set anymore */
635}
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:74

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

Datum test_bytea_to_text ( PG_FUNCTION_ARGS  )

Definition at line 1131 of file regress.c.

1132{
1134}
#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 331 of file regress.c.

332{
333 char *path = text_to_cstring(PG_GETARG_TEXT_PP(0));
334
335 canonicalize_path(path);
337}
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 1014 of file regress.c.

1015{
1016 bytea *string = PG_GETARG_BYTEA_PP(0);
1017 char *src_encoding_name = NameStr(*PG_GETARG_NAME(1));
1018 int src_encoding = pg_char_to_encoding(src_encoding_name);
1019 char *dest_encoding_name = NameStr(*PG_GETARG_NAME(2));
1020 int dest_encoding = pg_char_to_encoding(dest_encoding_name);
1021 bool noError = PG_GETARG_BOOL(3);
1022 TupleDesc tupdesc;
1023 char *src;
1024 char *dst;
1025 bytea *retval;
1026 Size srclen;
1027 Size dstsize;
1028 Oid proc;
1029 int convertedbytes;
1030 int dstlen;
1031 Datum values[2];
1032 bool nulls[2] = {0};
1033 HeapTuple tuple;
1034
1035 if (src_encoding < 0)
1036 ereport(ERROR,
1037 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1038 errmsg("invalid source encoding name \"%s\"",
1039 src_encoding_name)));
1040 if (dest_encoding < 0)
1041 ereport(ERROR,
1042 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1043 errmsg("invalid destination encoding name \"%s\"",
1044 dest_encoding_name)));
1045
1046 /* Build a tuple descriptor for our result type */
1047 if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
1048 elog(ERROR, "return type must be a row type");
1049 tupdesc = BlessTupleDesc(tupdesc);
1050
1051 srclen = VARSIZE_ANY_EXHDR(string);
1052 src = VARDATA_ANY(string);
1053
1054 if (src_encoding == dest_encoding)
1055 {
1056 /* just check that the source string is valid */
1057 int oklen;
1058
1059 oklen = pg_encoding_verifymbstr(src_encoding, src, srclen);
1060
1061 if (oklen == srclen)
1062 {
1063 convertedbytes = oklen;
1064 retval = string;
1065 }
1066 else if (!noError)
1067 {
1068 report_invalid_encoding(src_encoding, src + oklen, srclen - oklen);
1069 }
1070 else
1071 {
1072 /*
1073 * build bytea data type structure.
1074 */
1075 Assert(oklen < srclen);
1076 convertedbytes = oklen;
1077 retval = (bytea *) palloc(oklen + VARHDRSZ);
1078 SET_VARSIZE(retval, oklen + VARHDRSZ);
1079 memcpy(VARDATA(retval), src, oklen);
1080 }
1081 }
1082 else
1083 {
1084 proc = FindDefaultConversionProc(src_encoding, dest_encoding);
1085 if (!OidIsValid(proc))
1086 ereport(ERROR,
1087 (errcode(ERRCODE_UNDEFINED_FUNCTION),
1088 errmsg("default conversion function for encoding \"%s\" to \"%s\" does not exist",
1089 pg_encoding_to_char(src_encoding),
1090 pg_encoding_to_char(dest_encoding))));
1091
1092 if (srclen >= (MaxAllocSize / (Size) MAX_CONVERSION_GROWTH))
1093 ereport(ERROR,
1094 (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
1095 errmsg("out of memory"),
1096 errdetail("String of %d bytes is too long for encoding conversion.",
1097 (int) srclen)));
1098
1099 dstsize = (Size) srclen * MAX_CONVERSION_GROWTH + 1;
1101
1102 /* perform conversion */
1103 convertedbytes = pg_do_encoding_conversion_buf(proc,
1104 src_encoding,
1105 dest_encoding,
1106 (unsigned char *) src, srclen,
1107 (unsigned char *) dst, dstsize,
1108 noError);
1109 dstlen = strlen(dst);
1110
1111 /*
1112 * build bytea data type structure.
1113 */
1114 retval = (bytea *) palloc(dstlen + VARHDRSZ);
1115 SET_VARSIZE(retval, dstlen + VARHDRSZ);
1116 memcpy(VARDATA(retval), dst, dstlen);
1117
1118 pfree(dst);
1119 }
1120
1121 values[0] = Int32GetDatum(convertedbytes);
1122 values[1] = PointerGetDatum(retval);
1123 tuple = heap_form_tuple(tupdesc, values, nulls);
1124
1126}
#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:874
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:1824
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition mcxt.c:1232
MemoryContext CurrentMemoryContext
Definition mcxt.c:160
Oid FindDefaultConversionProc(int32 for_encoding, int32 to_encoding)
Definition namespace.c: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:2001

References Assert, BlessTupleDesc(), CurrentMemoryContext, elog, ereport, errcode(), errdetail(), errmsg, ERROR, 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 949 of file regress.c.

950{
951 /* Test pg_encoding_set_invalid() */
952 for (int i = 0; i < _PG_LAST_ENCODING_; i++)
953 {
954 char buf[2],
955 bigbuf[16];
956 int len,
957 mblen,
958 valid;
959
960 if (!PG_VALID_ENCODING(i))
961 continue;
962 if (pg_encoding_max_length(i) == 1)
963 continue;
965 len = strnlen(buf, 2);
966 if (len != 2)
968 "official invalid string for encoding \"%s\" has length %d",
970 mblen = pg_encoding_mblen(i, buf);
971 if (mblen != 2)
973 "official invalid string for encoding \"%s\" has mblen %d",
974 pg_enc2name_tbl[i].name, mblen);
975 valid = pg_encoding_verifymbstr(i, buf, len);
976 if (valid != 0)
978 "official invalid string for encoding \"%s\" has valid prefix of length %d",
979 pg_enc2name_tbl[i].name, valid);
980 valid = pg_encoding_verifymbstr(i, buf, 1);
981 if (valid != 0)
983 "first byte of official invalid string for encoding \"%s\" has valid prefix of length %d",
984 pg_enc2name_tbl[i].name, valid);
985 memset(bigbuf, ' ', sizeof(bigbuf));
986 bigbuf[0] = buf[0];
987 bigbuf[1] = buf[1];
988 valid = pg_encoding_verifymbstr(i, bigbuf, sizeof(bigbuf));
989 if (valid != 0)
991 "trailing data changed official invalid string for encoding \"%s\" to have valid prefix of length %d",
992 pg_enc2name_tbl[i].name, valid);
993 }
994
996}
#define WARNING
Definition elog.h:37
const pg_enc2name pg_enc2name_tbl[]
Definition encnames.c:305
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:1851
int pg_encoding_max_length(int encoding)
Definition wchar.c:2012
int pg_encoding_mblen(int encoding, const char *mbstr)
Definition wchar.c:1934

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

◆ test_fdw_connection()

Datum test_fdw_connection ( PG_FUNCTION_ARGS  )

Definition at line 735 of file regress.c.

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

References cstring_to_text(), and PG_RETURN_TEXT_P.

◆ test_fdw_handler()

Datum test_fdw_handler ( PG_FUNCTION_ARGS  )

Definition at line 727 of file regress.c.

728{
729 elog(ERROR, "test_fdw_handler is not implemented");
731}

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

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

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

◆ test_instr_time()

Datum test_instr_time ( PG_FUNCTION_ARGS  )

Definition at line 1394 of file regress.c.

1395{
1396 instr_time t;
1397 int64 test_ns[] = {0, 1000, INT64CONST(1000000000000000)};
1398 int64 max_err;
1399
1400 /*
1401 * The ns-to-ticks-to-ns roundtrip may lose precision due to integer
1402 * truncation in the fixed-point conversion. The maximum error depends on
1403 * ticks_per_ns_scaled relative to the shift factor.
1404 */
1405 max_err = (ticks_per_ns_scaled >> TICKS_TO_NS_SHIFT) + 1;
1406
1407 for (int i = 0; i < lengthof(test_ns); i++)
1408 {
1409 int64 result;
1410
1412 INSTR_TIME_ADD_NANOSEC(t, test_ns[i]);
1414
1415 if (result < test_ns[i] - max_err || result > test_ns[i])
1416 elog(ERROR,
1417 "INSTR_TIME_GET_NANOSEC(t) yielded " INT64_FORMAT
1418 ", expected " INT64_FORMAT " (max_err " INT64_FORMAT
1419 ") in file \"%s\" line %u",
1420 result, test_ns[i], max_err, __FILE__, __LINE__);
1421 }
1422
1423 PG_RETURN_BOOL(true);
1424}
#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, 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 1147 of file regress.c.

1148{
1149 const char *func = text_to_cstring(PG_GETARG_BYTEA_PP(0));
1151 text *string = PG_GETARG_BYTEA_PP(2);
1152 int offset = PG_GETARG_INT32(3);
1153 const char *data = VARDATA_ANY(string);
1154 size_t size = VARSIZE_ANY_EXHDR(string);
1155 int result = 0;
1156
1157 if (strcmp(func, "pg_mblen_unbounded") == 0)
1158 result = pg_mblen_unbounded(data + offset);
1159 else if (strcmp(func, "pg_mblen_cstr") == 0)
1160 result = pg_mblen_cstr(data + offset);
1161 else if (strcmp(func, "pg_mblen_with_len") == 0)
1162 result = pg_mblen_with_len(data + offset, size - offset);
1163 else if (strcmp(func, "pg_mblen_range") == 0)
1164 result = pg_mblen_range(data + offset, data + size);
1165 else if (strcmp(func, "pg_encoding_mblen") == 0)
1167 else
1168 elog(ERROR, "unknown function");
1169
1171}
#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, 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 941 of file regress.c.

942{
944}

References PG_RETURN_NULL.

◆ test_relpath()

Datum test_relpath ( PG_FUNCTION_ARGS  )

Definition at line 1283 of file regress.c.

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

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

750{
751 Node *rawreq = (Node *) PG_GETARG_POINTER(0);
752 Node *ret = NULL;
753
754 if (IsA(rawreq, SupportRequestSelectivity))
755 {
756 /*
757 * Assume that the target is int4eq; that's safe as long as we don't
758 * attach this to any other boolean-returning function.
759 */
762
763 if (req->is_join)
764 s1 = join_selectivity(req->root, Int4EqualOperator,
765 req->args,
766 req->inputcollid,
767 req->jointype,
768 req->sjinfo);
769 else
770 s1 = restriction_selectivity(req->root, Int4EqualOperator,
771 req->args,
772 req->inputcollid,
773 req->varRelid);
774
775 req->selectivity = s1;
776 ret = (Node *) req;
777 }
778
779 if (IsA(rawreq, SupportRequestCost))
780 {
781 /* Provide some generic estimate */
782 SupportRequestCost *req = (SupportRequestCost *) rawreq;
783
784 req->startup = 0;
785 req->per_tuple = 2 * cpu_operator_cost;
786 ret = (Node *) req;
787 }
788
789 if (IsA(rawreq, SupportRequestRows))
790 {
791 /*
792 * Assume that the target is generate_series_int4; that's safe as long
793 * as we don't attach this to any other set-returning function.
794 */
795 SupportRequestRows *req = (SupportRequestRows *) rawreq;
796
797 if (req->node && IsA(req->node, FuncExpr)) /* be paranoid */
798 {
799 List *args = ((FuncExpr *) req->node)->args;
800 Node *arg1 = linitial(args);
801 Node *arg2 = lsecond(args);
802
803 if (IsA(arg1, Const) &&
804 !((Const *) arg1)->constisnull &&
805 IsA(arg2, Const) &&
806 !((Const *) arg2)->constisnull)
807 {
808 int32 val1 = DatumGetInt32(((Const *) arg1)->constvalue);
809 int32 val2 = DatumGetInt32(((Const *) arg2)->constvalue);
810
811 req->rows = val2 - val1 + 1;
812 ret = (Node *) req;
813 }
814 }
815 }
816
818}
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
SpecialJoinInfo * sjinfo

References 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.

◆ test_text_to_bytea()

Datum test_text_to_bytea ( PG_FUNCTION_ARGS  )

Definition at line 1139 of file regress.c.

1140{
1142}
#define PG_RETURN_BYTEA_P(x)
Definition fmgr.h:373

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

1176{
1177 const char *encoding_name = text_to_cstring(PG_GETARG_BYTEA_PP(0));
1178 text *string = PG_GETARG_TEXT_PP(1);
1179 const char *data = VARDATA_ANY(string);
1180 size_t size = VARSIZE_ANY_EXHDR(string);
1181 pg_wchar *wchars = palloc(sizeof(pg_wchar) * (size + 1));
1182 Datum *datums;
1183 int wlen;
1184 int encoding;
1185
1186 encoding = pg_char_to_encoding(encoding_name);
1187 if (encoding < 0)
1188 elog(ERROR, "unknown encoding name: %s", encoding_name);
1189
1190 if (size > 0)
1191 {
1192 datums = palloc(sizeof(Datum) * size);
1194 data,
1195 wchars,
1196 size);
1197 Assert(wlen >= 0);
1198 Assert(wlen <= size);
1199 Assert(wchars[wlen] == 0);
1200
1201 for (int i = 0; i < wlen; ++i)
1202 datums[i] = UInt32GetDatum(wchars[i]);
1203 }
1204 else
1205 {
1206 datums = NULL;
1207 wlen = 0;
1208 }
1209
1210 PG_RETURN_ARRAYTYPE_P(construct_array_builtin(datums, wlen, INT4OID));
1211}
#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, 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 1315 of file regress.c.

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

References elog, ereport, errmsg, 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 1262 of file regress.c.

1263{
1265}
#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 1215 of file regress.c.

1216{
1217 const char *encoding_name = text_to_cstring(PG_GETARG_BYTEA_PP(0));
1218 ArrayType *array = PG_GETARG_ARRAYTYPE_P(1);
1219 Datum *datums;
1220 bool *nulls;
1221 char *mb;
1222 text *result;
1223 int wlen;
1224 int bytes;
1225 int encoding;
1226
1227 encoding = pg_char_to_encoding(encoding_name);
1228 if (encoding < 0)
1229 elog(ERROR, "unknown encoding name: %s", encoding_name);
1230
1231 deconstruct_array_builtin(array, INT4OID, &datums, &nulls, &wlen);
1232
1233 if (wlen > 0)
1234 {
1235 pg_wchar *wchars = palloc(sizeof(pg_wchar) * wlen);
1236
1237 for (int i = 0; i < wlen; ++i)
1238 {
1239 if (nulls[i])
1240 elog(ERROR, "unexpected NULL in array");
1241 wchars[i] = DatumGetInt32(datums[i]);
1242 }
1243
1244 mb = palloc(pg_encoding_max_length(encoding) * wlen + 1);
1245 bytes = pg_encoding_wchar2mb_with_len(encoding, wchars, mb, wlen);
1246 }
1247 else
1248 {
1249 mb = "";
1250 bytes = 0;
1251 }
1252
1253 result = palloc(bytes + VARHDRSZ);
1254 SET_VARSIZE(result, bytes + VARHDRSZ);
1255 memcpy(VARDATA(result), mb, bytes);
1256
1258}
#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, 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 264 of file regress.c.

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

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

◆ widget_in()

Datum widget_in ( PG_FUNCTION_ARGS  )

Definition at line 181 of file regress.c.

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

References DELIM, ereport, errcode(), errmsg, ERROR, 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 215 of file regress.c.

216{
217 WIDGET *widget = (WIDGET *) PG_GETARG_POINTER(0);
218 char *str = psprintf("(%g,%g,%g)",
219 widget->center.x, widget->center.y, widget->radius);
220
222}
char * psprintf(const char *fmt,...)
Definition psprintf.c:43
double radius
Definition regress.c:172

References WIDGET::center, PG_GETARG_POINTER, PG_RETURN_CSTRING, psprintf(), WIDGET::radius, str, Point::x, and Point::y.