mirror of
https://github.com/postgres/postgres.git
synced 2025-07-08 11:42:09 +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:
@ -35,7 +35,7 @@ static const struct pg_encoding *pg_find_encoding(const char *name);
|
||||
Datum
|
||||
binary_encode(PG_FUNCTION_ARGS)
|
||||
{
|
||||
bytea *data = PG_GETARG_BYTEA_P(0);
|
||||
bytea *data = PG_GETARG_BYTEA_PP(0);
|
||||
Datum name = PG_GETARG_DATUM(1);
|
||||
text *result;
|
||||
char *namebuf;
|
||||
@ -44,7 +44,7 @@ binary_encode(PG_FUNCTION_ARGS)
|
||||
res;
|
||||
const struct pg_encoding *enc;
|
||||
|
||||
datalen = VARSIZE(data) - VARHDRSZ;
|
||||
datalen = VARSIZE_ANY_EXHDR(data);
|
||||
|
||||
namebuf = TextDatumGetCString(name);
|
||||
|
||||
@ -54,10 +54,10 @@ binary_encode(PG_FUNCTION_ARGS)
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("unrecognized encoding: \"%s\"", namebuf)));
|
||||
|
||||
resultlen = enc->encode_len(VARDATA(data), datalen);
|
||||
resultlen = enc->encode_len(VARDATA_ANY(data), datalen);
|
||||
result = palloc(VARHDRSZ + resultlen);
|
||||
|
||||
res = enc->encode(VARDATA(data), datalen, VARDATA(result));
|
||||
res = enc->encode(VARDATA_ANY(data), datalen, VARDATA(result));
|
||||
|
||||
/* Make this FATAL 'cause we've trodden on memory ... */
|
||||
if (res > resultlen)
|
||||
@ -71,7 +71,7 @@ binary_encode(PG_FUNCTION_ARGS)
|
||||
Datum
|
||||
binary_decode(PG_FUNCTION_ARGS)
|
||||
{
|
||||
text *data = PG_GETARG_TEXT_P(0);
|
||||
text *data = PG_GETARG_TEXT_PP(0);
|
||||
Datum name = PG_GETARG_DATUM(1);
|
||||
bytea *result;
|
||||
char *namebuf;
|
||||
@ -80,7 +80,7 @@ binary_decode(PG_FUNCTION_ARGS)
|
||||
res;
|
||||
const struct pg_encoding *enc;
|
||||
|
||||
datalen = VARSIZE(data) - VARHDRSZ;
|
||||
datalen = VARSIZE_ANY_EXHDR(data);
|
||||
|
||||
namebuf = TextDatumGetCString(name);
|
||||
|
||||
@ -90,10 +90,10 @@ binary_decode(PG_FUNCTION_ARGS)
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("unrecognized encoding: \"%s\"", namebuf)));
|
||||
|
||||
resultlen = enc->decode_len(VARDATA(data), datalen);
|
||||
resultlen = enc->decode_len(VARDATA_ANY(data), datalen);
|
||||
result = palloc(VARHDRSZ + resultlen);
|
||||
|
||||
res = enc->decode(VARDATA(data), datalen, VARDATA(result));
|
||||
res = enc->decode(VARDATA_ANY(data), datalen, VARDATA(result));
|
||||
|
||||
/* Make this FATAL 'cause we've trodden on memory ... */
|
||||
if (res > resultlen)
|
||||
|
Reference in New Issue
Block a user