mirror of
https://github.com/postgres/postgres.git
synced 2025-07-27 12:41:57 +03:00
Use wrappers of PG_DETOAST_DATUM_PACKED() more.
This makes almost all core code follow the policy introduced in the previous commit. Specific decisions: - Text search support functions with char* and length arguments, such as prsstart and lexize, may receive unaligned strings. I doubt maintainers of non-core text search code will notice. - Use plain VARDATA() on values detoasted or synthesized earlier in the same function. Use VARDATA_ANY() on varlenas sourced outside the function, even if they happen to always have four-byte headers. As an exception, retain the universal practice of using VARDATA() on return values of SendFunctionCall(). - Retain PG_GETARG_BYTEA_P() in pageinspect. (Page images are too large for a one-byte header, so this misses no optimization.) Sites that do not call get_page_from_raw() typically need the four-byte alignment. - For now, do not change btree_gist. Its use of four-byte headers in memory is partly entangled with storage of 4-byte headers inside GBT_VARKEY, on disk. - For now, do not change gtrgm_consistent() or gtrgm_distance(). They incorporate the varlena header into a cache, and there are multiple credible implementation strategies to consider.
This commit is contained in:
@ -95,9 +95,9 @@ PG_FUNCTION_INFO_V1(xml_is_well_formed);
|
||||
Datum
|
||||
xml_is_well_formed(PG_FUNCTION_ARGS)
|
||||
{
|
||||
text *t = PG_GETARG_TEXT_P(0); /* document buffer */
|
||||
text *t = PG_GETARG_TEXT_PP(0); /* document buffer */
|
||||
bool result = false;
|
||||
int32 docsize = VARSIZE(t) - VARHDRSZ;
|
||||
int32 docsize = VARSIZE_ANY_EXHDR(t);
|
||||
xmlDocPtr doctree;
|
||||
PgXmlErrorContext *xmlerrcxt;
|
||||
|
||||
@ -105,7 +105,7 @@ xml_is_well_formed(PG_FUNCTION_ARGS)
|
||||
|
||||
PG_TRY();
|
||||
{
|
||||
doctree = xmlParseMemory((char *) VARDATA(t), docsize);
|
||||
doctree = xmlParseMemory((char *) VARDATA_ANY(t), docsize);
|
||||
|
||||
result = (doctree != NULL);
|
||||
|
||||
@ -133,7 +133,7 @@ PG_FUNCTION_INFO_V1(xml_encode_special_chars);
|
||||
Datum
|
||||
xml_encode_special_chars(PG_FUNCTION_ARGS)
|
||||
{
|
||||
text *tin = PG_GETARG_TEXT_P(0);
|
||||
text *tin = PG_GETARG_TEXT_PP(0);
|
||||
text *tout;
|
||||
xmlChar *ts,
|
||||
*tt;
|
||||
@ -248,10 +248,10 @@ PG_FUNCTION_INFO_V1(xpath_nodeset);
|
||||
Datum
|
||||
xpath_nodeset(PG_FUNCTION_ARGS)
|
||||
{
|
||||
text *document = PG_GETARG_TEXT_P(0);
|
||||
text *xpathsupp = PG_GETARG_TEXT_P(1); /* XPath expression */
|
||||
xmlChar *toptag = pgxml_texttoxmlchar(PG_GETARG_TEXT_P(2));
|
||||
xmlChar *septag = pgxml_texttoxmlchar(PG_GETARG_TEXT_P(3));
|
||||
text *document = PG_GETARG_TEXT_PP(0);
|
||||
text *xpathsupp = PG_GETARG_TEXT_PP(1); /* XPath expression */
|
||||
xmlChar *toptag = pgxml_texttoxmlchar(PG_GETARG_TEXT_PP(2));
|
||||
xmlChar *septag = pgxml_texttoxmlchar(PG_GETARG_TEXT_PP(3));
|
||||
xmlChar *xpath;
|
||||
text *xpres;
|
||||
xmlXPathObjectPtr res;
|
||||
@ -281,9 +281,9 @@ PG_FUNCTION_INFO_V1(xpath_list);
|
||||
Datum
|
||||
xpath_list(PG_FUNCTION_ARGS)
|
||||
{
|
||||
text *document = PG_GETARG_TEXT_P(0);
|
||||
text *xpathsupp = PG_GETARG_TEXT_P(1); /* XPath expression */
|
||||
xmlChar *plainsep = pgxml_texttoxmlchar(PG_GETARG_TEXT_P(2));
|
||||
text *document = PG_GETARG_TEXT_PP(0);
|
||||
text *xpathsupp = PG_GETARG_TEXT_PP(1); /* XPath expression */
|
||||
xmlChar *plainsep = pgxml_texttoxmlchar(PG_GETARG_TEXT_PP(2));
|
||||
xmlChar *xpath;
|
||||
text *xpres;
|
||||
xmlXPathObjectPtr res;
|
||||
@ -310,15 +310,15 @@ PG_FUNCTION_INFO_V1(xpath_string);
|
||||
Datum
|
||||
xpath_string(PG_FUNCTION_ARGS)
|
||||
{
|
||||
text *document = PG_GETARG_TEXT_P(0);
|
||||
text *xpathsupp = PG_GETARG_TEXT_P(1); /* XPath expression */
|
||||
text *document = PG_GETARG_TEXT_PP(0);
|
||||
text *xpathsupp = PG_GETARG_TEXT_PP(1); /* XPath expression */
|
||||
xmlChar *xpath;
|
||||
int32 pathsize;
|
||||
text *xpres;
|
||||
xmlXPathObjectPtr res;
|
||||
xpath_workspace workspace;
|
||||
|
||||
pathsize = VARSIZE(xpathsupp) - VARHDRSZ;
|
||||
pathsize = VARSIZE_ANY_EXHDR(xpathsupp);
|
||||
|
||||
/*
|
||||
* We encapsulate the supplied path with "string()" = 8 chars + 1 for NUL
|
||||
@ -328,7 +328,7 @@ xpath_string(PG_FUNCTION_ARGS)
|
||||
|
||||
xpath = (xmlChar *) palloc(pathsize + 9);
|
||||
memcpy((char *) xpath, "string(", 7);
|
||||
memcpy((char *) (xpath + 7), VARDATA(xpathsupp), pathsize);
|
||||
memcpy((char *) (xpath + 7), VARDATA_ANY(xpathsupp), pathsize);
|
||||
xpath[pathsize + 7] = ')';
|
||||
xpath[pathsize + 8] = '\0';
|
||||
|
||||
@ -351,8 +351,8 @@ PG_FUNCTION_INFO_V1(xpath_number);
|
||||
Datum
|
||||
xpath_number(PG_FUNCTION_ARGS)
|
||||
{
|
||||
text *document = PG_GETARG_TEXT_P(0);
|
||||
text *xpathsupp = PG_GETARG_TEXT_P(1); /* XPath expression */
|
||||
text *document = PG_GETARG_TEXT_PP(0);
|
||||
text *xpathsupp = PG_GETARG_TEXT_PP(1); /* XPath expression */
|
||||
xmlChar *xpath;
|
||||
float4 fRes;
|
||||
xmlXPathObjectPtr res;
|
||||
@ -383,8 +383,8 @@ PG_FUNCTION_INFO_V1(xpath_bool);
|
||||
Datum
|
||||
xpath_bool(PG_FUNCTION_ARGS)
|
||||
{
|
||||
text *document = PG_GETARG_TEXT_P(0);
|
||||
text *xpathsupp = PG_GETARG_TEXT_P(1); /* XPath expression */
|
||||
text *document = PG_GETARG_TEXT_PP(0);
|
||||
text *xpathsupp = PG_GETARG_TEXT_PP(1); /* XPath expression */
|
||||
xmlChar *xpath;
|
||||
int bRes;
|
||||
xmlXPathObjectPtr res;
|
||||
@ -413,7 +413,7 @@ xpath_bool(PG_FUNCTION_ARGS)
|
||||
static xmlXPathObjectPtr
|
||||
pgxml_xpath(text *document, xmlChar *xpath, xpath_workspace *workspace)
|
||||
{
|
||||
int32 docsize = VARSIZE(document) - VARHDRSZ;
|
||||
int32 docsize = VARSIZE_ANY_EXHDR(document);
|
||||
PgXmlErrorContext *xmlerrcxt;
|
||||
xmlXPathCompExprPtr comppath;
|
||||
|
||||
@ -425,7 +425,7 @@ pgxml_xpath(text *document, xmlChar *xpath, xpath_workspace *workspace)
|
||||
|
||||
PG_TRY();
|
||||
{
|
||||
workspace->doctree = xmlParseMemory((char *) VARDATA(document),
|
||||
workspace->doctree = xmlParseMemory((char *) VARDATA_ANY(document),
|
||||
docsize);
|
||||
if (workspace->doctree != NULL)
|
||||
{
|
||||
|
@ -49,8 +49,8 @@ xslt_process(PG_FUNCTION_ARGS)
|
||||
{
|
||||
#ifdef USE_LIBXSLT
|
||||
|
||||
text *doct = PG_GETARG_TEXT_P(0);
|
||||
text *ssheet = PG_GETARG_TEXT_P(1);
|
||||
text *doct = PG_GETARG_TEXT_PP(0);
|
||||
text *ssheet = PG_GETARG_TEXT_PP(1);
|
||||
text *result;
|
||||
text *paramstr;
|
||||
const char **params;
|
||||
@ -66,7 +66,7 @@ xslt_process(PG_FUNCTION_ARGS)
|
||||
|
||||
if (fcinfo->nargs == 3)
|
||||
{
|
||||
paramstr = PG_GETARG_TEXT_P(2);
|
||||
paramstr = PG_GETARG_TEXT_PP(2);
|
||||
params = parse_params(paramstr);
|
||||
}
|
||||
else
|
||||
@ -85,16 +85,16 @@ xslt_process(PG_FUNCTION_ARGS)
|
||||
bool xslt_sec_prefs_error;
|
||||
|
||||
/* Parse document */
|
||||
doctree = xmlParseMemory((char *) VARDATA(doct),
|
||||
VARSIZE(doct) - VARHDRSZ);
|
||||
doctree = xmlParseMemory((char *) VARDATA_ANY(doct),
|
||||
VARSIZE_ANY_EXHDR(doct));
|
||||
|
||||
if (doctree == NULL)
|
||||
xml_ereport(xmlerrcxt, ERROR, ERRCODE_EXTERNAL_ROUTINE_EXCEPTION,
|
||||
"error parsing XML document");
|
||||
|
||||
/* Same for stylesheet */
|
||||
ssdoc = xmlParseMemory((char *) VARDATA(ssheet),
|
||||
VARSIZE(ssheet) - VARHDRSZ);
|
||||
ssdoc = xmlParseMemory((char *) VARDATA_ANY(ssheet),
|
||||
VARSIZE_ANY_EXHDR(ssheet));
|
||||
|
||||
if (ssdoc == NULL)
|
||||
xml_ereport(xmlerrcxt, ERROR, ERRCODE_EXTERNAL_ROUTINE_EXCEPTION,
|
||||
|
Reference in New Issue
Block a user