#define EXPECT_TRUE(expr) \ do { \ if (!(expr)) \
elog(ERROR, \ "%s was unexpectedly false in file \"%s\" line %u", \ #expr, __FILE__, __LINE__); \
} while (0)
#define EXPECT_EQ_U32(result_expr, expected_expr) \ do { \
uint32 actual_result = (result_expr); \
uint32 expected_result = (expected_expr); \ if (actual_result != expected_result) \
elog(ERROR, \ "%s yielded %u, expected %s in file \"%s\" line %u", \ #result_expr, actual_result, #expected_expr, __FILE__, __LINE__); \
} while (0)
#define EXPECT_EQ_U64(result_expr, expected_expr) \ 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)
/* return the point where two paths intersect, or NULL if no intersection. */
PG_FUNCTION_INFO_V1(interpt_pp);
Datum
interpt_pp(PG_FUNCTION_ARGS)
{
PATH *p1 = PG_GETARG_PATH_P(0);
PATH *p2 = PG_GETARG_PATH_P(1); int i,
j;
LSEG seg1,
seg2; bool found; /* We've found the intersection */
found = false; /* Haven't found it yet */
for (i = 0; i < p1->npts - 1 && !found; i++)
{
regress_lseg_construct(&seg1, &p1->p[i], &p1->p[i + 1]); for (j = 0; j < p2->npts - 1 && !found; j++)
{
regress_lseg_construct(&seg2, &p2->p[j], &p2->p[j + 1]); if (DatumGetBool(DirectFunctionCall2(lseg_intersect,
LsegPGetDatum(&seg1),
LsegPGetDatum(&seg2))))
found = true;
}
}
Datum
widget_in(PG_FUNCTION_ARGS)
{ char *str = PG_GETARG_CSTRING(0); char *p,
*coord[NARGS]; int i;
WIDGET *result;
for (i = 0, p = str; *p && i < NARGS && *p != RDELIM; p++)
{ if (*p == DELIM || (*p == LDELIM && i == 0))
coord[i++] = p + 1;
}
/* *Note:DON'Tconvertthiserrorto"soft"style(errsave/ereturn).We *wantthisdatatypetostaypermanentlyinthehard-errorworldsothat *itcanbeusedfortestingthatsuchcasesstillworkreasonably.
*/ if (i < NARGS)
ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for type %s: \"%s\"", "widget", str)));
Datum
reverse_name(PG_FUNCTION_ARGS)
{ char *string = PG_GETARG_CSTRING(0); int i; int len; char *new_string;
new_string = palloc0(NAMEDATALEN); for (i = 0; i < NAMEDATALEN && string[i]; ++i)
; if (i == NAMEDATALEN || !string[i])
--i;
len = i; for (; i >= 0; --i)
new_string[len - i] = string[i];
PG_RETURN_CSTRING(new_string);
}
/* don't recursively indirect */ if (VARATT_IS_EXTERNAL_INDIRECT(attr)) continue;
/* copy datum, so it still lives later */ if (VARATT_IS_EXTERNAL_ONDISK(attr))
attr = detoast_external_attr(attr); else
{ struct varlena *oldattr = attr;
/* fail exchange because of old expected */
expected = 10;
EXPECT_TRUE(!pg_atomic_compare_exchange_u32(&var, &expected, 1));
/* CAS is allowed to fail due to interrupts, try a couple of times */ for (i = 0; i < 1000; i++)
{
expected = 0; if (!pg_atomic_compare_exchange_u32(&var, &expected, 1)) break;
} if (i == 1000)
elog(ERROR, "atomic_compare_exchange_u32() never succeeded");
EXPECT_EQ_U32(pg_atomic_read_u32(&var), 1);
pg_atomic_write_u32(&var, 0);
/* fail exchange because of old expected */
expected = 10;
EXPECT_TRUE(!pg_atomic_compare_exchange_u64(&var, &expected, 1));
/* CAS is allowed to fail due to interrupts, try a couple of times */ for (i = 0; i < 100; i++)
{
expected = 0; if (!pg_atomic_compare_exchange_u64(&var, &expected, 1)) break;
} if (i == 100)
elog(ERROR, "atomic_compare_exchange_u64() never succeeded");
EXPECT_EQ_U64(pg_atomic_read_u64(&var), 1);
/* test basic operations via the SpinLock* API */
SpinLockInit(&struct_w_lock.lock);
SpinLockAcquire(&struct_w_lock.lock);
SpinLockRelease(&struct_w_lock.lock);
/* test basic operations via underlying S_* API */
S_INIT_LOCK(&struct_w_lock.lock);
S_LOCK(&struct_w_lock.lock);
S_UNLOCK(&struct_w_lock.lock);
/* and that "contended" acquisition works */
s_lock(&struct_w_lock.lock, "testfile", 17, "testfunc");
S_UNLOCK(&struct_w_lock.lock);
/* *Check,usingTASdirectly,thatasinglespincycledoesn'tblock *whenacquiringanalreadyacquiredlock.
*/ #ifdef TAS
S_LOCK(&struct_w_lock.lock);
if (!TAS(&struct_w_lock.lock))
elog(ERROR, "acquired already held spinlock");
#ifdef TAS_SPIN if (!TAS_SPIN(&struct_w_lock.lock))
elog(ERROR, "acquired already held spinlock"); #endif/* defined(TAS_SPIN) */
PG_FUNCTION_INFO_V1(test_fdw_handler);
Datum
test_fdw_handler(PG_FUNCTION_ARGS)
{
elog(ERROR, "test_fdw_handler is not implemented");
PG_RETURN_NULL();
}
PG_FUNCTION_INFO_V1(is_catalog_text_unique_index_oid);
Datum
is_catalog_text_unique_index_oid(PG_FUNCTION_ARGS)
{ return IsCatalogTextUniqueIndexOid(PG_GETARG_OID(0));
}
PG_FUNCTION_INFO_V1(test_opclass_options_func);
Datum
test_opclass_options_func(PG_FUNCTION_ARGS)
{
PG_RETURN_NULL();
}
/* one-time tests for encoding infrastructure */
PG_FUNCTION_INFO_V1(test_enc_setup);
Datum
test_enc_setup(PG_FUNCTION_ARGS)
{ /* Test pg_encoding_set_invalid() */ for (int i = 0; i < _PG_LAST_ENCODING_; i++)
{ char buf[2],
bigbuf[16]; int len,
mblen,
valid;
if (pg_encoding_max_length(i) == 1) continue;
pg_encoding_set_invalid(i, buf);
len = strnlen(buf, 2); if (len != 2)
elog(WARNING, "official invalid string for encoding \"%s\" has length %d",
pg_enc2name_tbl[i].name, len);
mblen = pg_encoding_mblen(i, buf); if (mblen != 2)
elog(WARNING, "official invalid string for encoding \"%s\" has mblen %d",
pg_enc2name_tbl[i].name, mblen);
valid = pg_encoding_verifymbstr(i, buf, len); if (valid != 0)
elog(WARNING, "official invalid string for encoding \"%s\" has valid prefix of length %d",
pg_enc2name_tbl[i].name, valid);
valid = pg_encoding_verifymbstr(i, buf, 1); if (valid != 0)
elog(WARNING, "first byte of official invalid string for encoding \"%s\" has valid prefix of length %d",
pg_enc2name_tbl[i].name, valid);
memset(bigbuf, ' ', sizeof(bigbuf));
bigbuf[0] = buf[0];
bigbuf[1] = buf[1];
valid = pg_encoding_verifymbstr(i, bigbuf, sizeof(bigbuf)); if (valid != 0)
elog(WARNING, "trailing data changed official invalid string for encoding \"%s\" to have valid prefix of length %d",
pg_enc2name_tbl[i].name, valid);
}
PG_RETURN_VOID();
}
/* *Callanencodingconversionorverificationfunction. * *Arguments: *stringbytea--stringtoconvert *src_encname--sourceencoding *dest_encname--destinationencoding *noErrorbool--ifset,don'tereport()oninvalidoruntranslatable *input * *Resultisatuplewithtwoattributes: *int4--numberofinputbytessuccessfullyconverted *bytea--convertedstring
*/
PG_FUNCTION_INFO_V1(test_enc_conversion);
Datum
test_enc_conversion(PG_FUNCTION_ARGS)
{
bytea *string = PG_GETARG_BYTEA_PP(0); char *src_encoding_name = NameStr(*PG_GETARG_NAME(1)); int src_encoding = pg_char_to_encoding(src_encoding_name); char *dest_encoding_name = NameStr(*PG_GETARG_NAME(2)); int dest_encoding = pg_char_to_encoding(dest_encoding_name); bool noError = PG_GETARG_BOOL(3);
TupleDesc tupdesc; char *src; char *dst;
bytea *retval;
Size srclen;
Size dstsize;
Oid proc; int convertedbytes; int dstlen;
Datum values[2]; bool nulls[2] = {0};
HeapTuple tuple;
if (src_encoding < 0)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("invalid source encoding name \"%s\"",
src_encoding_name))); if (dest_encoding < 0)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("invalid destination encoding name \"%s\"",
dest_encoding_name)));
/* Build a tuple descriptor for our result type */ if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
elog(ERROR, "return type must be a row type");
tupdesc = BlessTupleDesc(tupdesc);
if (srclen >= (MaxAllocSize / (Size) MAX_CONVERSION_GROWTH))
ereport(ERROR,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("out of memory"),
errdetail("String of %d bytes is too long for encoding conversion.",
(int) srclen)));
/* Convert bytea to text without validation for corruption tests from SQL. */
PG_FUNCTION_INFO_V1(test_bytea_to_text);
Datum
test_bytea_to_text(PG_FUNCTION_ARGS)
{
PG_RETURN_TEXT_P(PG_GETARG_BYTEA_PP(0));
}
/* And the reverse. */
PG_FUNCTION_INFO_V1(test_text_to_bytea);
Datum
test_text_to_bytea(PG_FUNCTION_ARGS)
{
PG_RETURN_BYTEA_P(PG_GETARG_TEXT_PP(0));
}
/* Corruption tests in C. */
PG_FUNCTION_INFO_V1(test_mblen_func);
Datum
test_mblen_func(PG_FUNCTION_ARGS)
{ constchar *func = text_to_cstring(PG_GETARG_BYTEA_PP(0)); constchar *encoding = text_to_cstring(PG_GETARG_BYTEA_PP(1));
text *string = PG_GETARG_BYTEA_PP(2); int offset = PG_GETARG_INT32(3); constchar *data = VARDATA_ANY(string);
size_t size = VARSIZE_ANY_EXHDR(string); int result = 0;
if (strcmp(func, "pg_mblen_unbounded") == 0)
result = pg_mblen_unbounded(data + offset); elseif (strcmp(func, "pg_mblen_cstr") == 0)
result = pg_mblen_cstr(data + offset); elseif (strcmp(func, "pg_mblen_with_len") == 0)
result = pg_mblen_with_len(data + offset, size - offset); elseif (strcmp(func, "pg_mblen_range") == 0)
result = pg_mblen_range(data + offset, data + size); elseif (strcmp(func, "pg_encoding_mblen") == 0)
result = pg_encoding_mblen(pg_char_to_encoding(encoding), data + offset); else
elog(ERROR, "unknown function");
PG_RETURN_INT32(result);
}
PG_FUNCTION_INFO_V1(test_text_to_wchars);
Datum
test_text_to_wchars(PG_FUNCTION_ARGS)
{ constchar *encoding_name = text_to_cstring(PG_GETARG_BYTEA_PP(0));
text *string = PG_GETARG_TEXT_PP(1); constchar *data = VARDATA_ANY(string);
size_t size = VARSIZE_ANY_EXHDR(string);
pg_wchar *wchars = palloc(sizeof(pg_wchar) * (size + 1));
Datum *datums; int wlen; int encoding;
PG_FUNCTION_INFO_V1(test_wchars_to_text);
Datum
test_wchars_to_text(PG_FUNCTION_ARGS)
{ constchar *encoding_name = text_to_cstring(PG_GETARG_BYTEA_PP(0));
ArrayType *array = PG_GETARG_ARRAYTYPE_P(1);
Datum *datums; bool *nulls; char *mb;
text *result; int wlen; int bytes; int encoding;
PG_FUNCTION_INFO_V1(test_valid_server_encoding);
Datum
test_valid_server_encoding(PG_FUNCTION_ARGS)
{
PG_RETURN_BOOL(pg_valid_server_encoding(text_to_cstring(PG_GETARG_TEXT_PP(0))) >= 0);
}
/* Provide SQL access to IsBinaryCoercible() */
PG_FUNCTION_INFO_V1(binary_coercible);
Datum
binary_coercible(PG_FUNCTION_ARGS)
{
Oid srctype = PG_GETARG_OID(0);
Oid targettype = PG_GETARG_OID(1);
/* *Sanitychecksforfunctionsinrelpath.h
*/
PG_FUNCTION_INFO_V1(test_relpath);
Datum
test_relpath(PG_FUNCTION_ARGS)
{
RelPathStr rpath;
/* *VerifythatPROCNUMBER_CHARSandMAX_BACKENDSstayinsync. *UnfortunatelyIdon'tknowhowtoexpressthatinawaysuitablefora *staticassert.
*/ if ((int) ceil(log10(MAX_BACKENDS)) != PROCNUMBER_CHARS)
elog(WARNING, "mismatch between MAX_BACKENDS and PROCNUMBER_CHARS");
/* verify that the max-length relpath is generated ok */
rpath = GetRelationPath(OID_MAX, OID_MAX, OID_MAX, MAX_BACKENDS - 1,
INIT_FORKNUM);
if (strlen(rpath.str) != REL_PATH_STR_MAXLEN)
elog(WARNING, "maximum length relpath is if length %zu instead of %zu",
strlen(rpath.str), REL_PATH_STR_MAXLEN);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.