1
0
mirror of https://github.com/postgres/postgres.git synced 2025-08-06 18:42:54 +03:00

Make DatumGetFoo/PG_GETARG_FOO/PG_RETURN_FOO macro names more consistent.

By project convention, these names should include "P" when dealing with a
pointer type; that is, if the result of a GETARG macro is of type FOO *,
it should be called PG_GETARG_FOO_P not just PG_GETARG_FOO.  Some newer
types such as JSONB and ranges had not followed the convention, and a
number of contrib modules hadn't gotten that memo either.  Rename the
offending macros to improve consistency.

In passing, fix a few places that thought PG_DETOAST_DATUM() returns
a Datum; it does not, it returns "struct varlena *".  Applying
DatumGetPointer to that happens not to cause any bad effects today,
but it's formally wrong.  Also, adjust an ltree macro that was designed
without any thought for what pgindent would do with it.

This is all cosmetic and shouldn't have any impact on generated code.

Mark Dilger, some further tweaks by me

Discussion: https://postgr.es/m/EA5676F4-766F-4F38-8348-ECC7DB427C6A@gmail.com
This commit is contained in:
Tom Lane
2017-09-18 15:21:23 -04:00
parent 3e1683d37e
commit 4bd1994650
38 changed files with 471 additions and 461 deletions

View File

@@ -151,7 +151,7 @@ extern HStore *hstoreUpgrade(Datum orig);
#define DatumGetHStoreP(d) hstoreUpgrade(d)
#define PG_GETARG_HS(x) DatumGetHStoreP(PG_GETARG_DATUM(x))
#define PG_GETARG_HSTORE_P(x) DatumGetHStoreP(PG_GETARG_DATUM(x))
/*

View File

@@ -43,7 +43,7 @@ makeitem(char *str, int len, char flag)
Datum
gin_extract_hstore(PG_FUNCTION_ARGS)
{
HStore *hs = PG_GETARG_HS(0);
HStore *hs = PG_GETARG_HSTORE_P(0);
int32 *nentries = (int32 *) PG_GETARG_POINTER(1);
Datum *entries = NULL;
HEntry *hsent = ARRPTR(hs);
@@ -155,7 +155,7 @@ gin_consistent_hstore(PG_FUNCTION_ARGS)
bool *check = (bool *) PG_GETARG_POINTER(0);
StrategyNumber strategy = PG_GETARG_UINT16(1);
/* HStore *query = PG_GETARG_HS(2); */
/* HStore *query = PG_GETARG_HSTORE_P(2); */
int32 nkeys = PG_GETARG_INT32(3);
/* Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4); */

View File

@@ -518,7 +518,7 @@ ghstore_consistent(PG_FUNCTION_ARGS)
if (strategy == HStoreContainsStrategyNumber ||
strategy == HStoreOldContainsStrategyNumber)
{
HStore *query = PG_GETARG_HS(1);
HStore *query = PG_GETARG_HSTORE_P(1);
HEntry *qe = ARRPTR(query);
char *qv = STRPTR(query);
int count = HS_COUNT(query);

View File

@@ -962,7 +962,7 @@ hstore_populate_record(PG_FUNCTION_ARGS)
tupTypmod = HeapTupleHeaderGetTypMod(rec);
}
hs = PG_GETARG_HS(1);
hs = PG_GETARG_HSTORE_P(1);
entries = ARRPTR(hs);
ptr = STRPTR(hs);
@@ -1127,7 +1127,7 @@ PG_FUNCTION_INFO_V1(hstore_out);
Datum
hstore_out(PG_FUNCTION_ARGS)
{
HStore *in = PG_GETARG_HS(0);
HStore *in = PG_GETARG_HSTORE_P(0);
int buflen,
i;
int count = HS_COUNT(in);
@@ -1198,7 +1198,7 @@ PG_FUNCTION_INFO_V1(hstore_send);
Datum
hstore_send(PG_FUNCTION_ARGS)
{
HStore *in = PG_GETARG_HS(0);
HStore *in = PG_GETARG_HSTORE_P(0);
int i;
int count = HS_COUNT(in);
char *base = STRPTR(in);
@@ -1244,7 +1244,7 @@ PG_FUNCTION_INFO_V1(hstore_to_json_loose);
Datum
hstore_to_json_loose(PG_FUNCTION_ARGS)
{
HStore *in = PG_GETARG_HS(0);
HStore *in = PG_GETARG_HSTORE_P(0);
int i;
int count = HS_COUNT(in);
char *base = STRPTR(in);
@@ -1299,7 +1299,7 @@ PG_FUNCTION_INFO_V1(hstore_to_json);
Datum
hstore_to_json(PG_FUNCTION_ARGS)
{
HStore *in = PG_GETARG_HS(0);
HStore *in = PG_GETARG_HSTORE_P(0);
int i;
int count = HS_COUNT(in);
char *base = STRPTR(in);
@@ -1344,7 +1344,7 @@ PG_FUNCTION_INFO_V1(hstore_to_jsonb);
Datum
hstore_to_jsonb(PG_FUNCTION_ARGS)
{
HStore *in = PG_GETARG_HS(0);
HStore *in = PG_GETARG_HSTORE_P(0);
int i;
int count = HS_COUNT(in);
char *base = STRPTR(in);
@@ -1387,7 +1387,7 @@ PG_FUNCTION_INFO_V1(hstore_to_jsonb_loose);
Datum
hstore_to_jsonb_loose(PG_FUNCTION_ARGS)
{
HStore *in = PG_GETARG_HS(0);
HStore *in = PG_GETARG_HSTORE_P(0);
int i;
int count = HS_COUNT(in);
char *base = STRPTR(in);

View File

@@ -130,7 +130,7 @@ PG_FUNCTION_INFO_V1(hstore_fetchval);
Datum
hstore_fetchval(PG_FUNCTION_ARGS)
{
HStore *hs = PG_GETARG_HS(0);
HStore *hs = PG_GETARG_HSTORE_P(0);
text *key = PG_GETARG_TEXT_PP(1);
HEntry *entries = ARRPTR(hs);
text *out;
@@ -151,7 +151,7 @@ PG_FUNCTION_INFO_V1(hstore_exists);
Datum
hstore_exists(PG_FUNCTION_ARGS)
{
HStore *hs = PG_GETARG_HS(0);
HStore *hs = PG_GETARG_HSTORE_P(0);
text *key = PG_GETARG_TEXT_PP(1);
int idx = hstoreFindKey(hs, NULL,
VARDATA_ANY(key), VARSIZE_ANY_EXHDR(key));
@@ -164,7 +164,7 @@ PG_FUNCTION_INFO_V1(hstore_exists_any);
Datum
hstore_exists_any(PG_FUNCTION_ARGS)
{
HStore *hs = PG_GETARG_HS(0);
HStore *hs = PG_GETARG_HSTORE_P(0);
ArrayType *keys = PG_GETARG_ARRAYTYPE_P(1);
int nkeys;
Pairs *key_pairs = hstoreArrayToPairs(keys, &nkeys);
@@ -198,7 +198,7 @@ PG_FUNCTION_INFO_V1(hstore_exists_all);
Datum
hstore_exists_all(PG_FUNCTION_ARGS)
{
HStore *hs = PG_GETARG_HS(0);
HStore *hs = PG_GETARG_HSTORE_P(0);
ArrayType *keys = PG_GETARG_ARRAYTYPE_P(1);
int nkeys;
Pairs *key_pairs = hstoreArrayToPairs(keys, &nkeys);
@@ -232,7 +232,7 @@ PG_FUNCTION_INFO_V1(hstore_defined);
Datum
hstore_defined(PG_FUNCTION_ARGS)
{
HStore *hs = PG_GETARG_HS(0);
HStore *hs = PG_GETARG_HSTORE_P(0);
text *key = PG_GETARG_TEXT_PP(1);
HEntry *entries = ARRPTR(hs);
int idx = hstoreFindKey(hs, NULL,
@@ -247,7 +247,7 @@ PG_FUNCTION_INFO_V1(hstore_delete);
Datum
hstore_delete(PG_FUNCTION_ARGS)
{
HStore *hs = PG_GETARG_HS(0);
HStore *hs = PG_GETARG_HSTORE_P(0);
text *key = PG_GETARG_TEXT_PP(1);
char *keyptr = VARDATA_ANY(key);
int keylen = VARSIZE_ANY_EXHDR(key);
@@ -294,7 +294,7 @@ PG_FUNCTION_INFO_V1(hstore_delete_array);
Datum
hstore_delete_array(PG_FUNCTION_ARGS)
{
HStore *hs = PG_GETARG_HS(0);
HStore *hs = PG_GETARG_HSTORE_P(0);
HStore *out = palloc(VARSIZE(hs));
int hs_count = HS_COUNT(hs);
char *ps,
@@ -373,8 +373,8 @@ PG_FUNCTION_INFO_V1(hstore_delete_hstore);
Datum
hstore_delete_hstore(PG_FUNCTION_ARGS)
{
HStore *hs = PG_GETARG_HS(0);
HStore *hs2 = PG_GETARG_HS(1);
HStore *hs = PG_GETARG_HSTORE_P(0);
HStore *hs2 = PG_GETARG_HSTORE_P(1);
HStore *out = palloc(VARSIZE(hs));
int hs_count = HS_COUNT(hs);
int hs2_count = HS_COUNT(hs2);
@@ -473,8 +473,8 @@ PG_FUNCTION_INFO_V1(hstore_concat);
Datum
hstore_concat(PG_FUNCTION_ARGS)
{
HStore *s1 = PG_GETARG_HS(0);
HStore *s2 = PG_GETARG_HS(1);
HStore *s1 = PG_GETARG_HSTORE_P(0);
HStore *s2 = PG_GETARG_HSTORE_P(1);
HStore *out = palloc(VARSIZE(s1) + VARSIZE(s2));
char *ps1,
*ps2,
@@ -571,7 +571,7 @@ PG_FUNCTION_INFO_V1(hstore_slice_to_array);
Datum
hstore_slice_to_array(PG_FUNCTION_ARGS)
{
HStore *hs = PG_GETARG_HS(0);
HStore *hs = PG_GETARG_HSTORE_P(0);
HEntry *entries = ARRPTR(hs);
char *ptr = STRPTR(hs);
ArrayType *key_array = PG_GETARG_ARRAYTYPE_P(1);
@@ -634,7 +634,7 @@ PG_FUNCTION_INFO_V1(hstore_slice_to_hstore);
Datum
hstore_slice_to_hstore(PG_FUNCTION_ARGS)
{
HStore *hs = PG_GETARG_HS(0);
HStore *hs = PG_GETARG_HSTORE_P(0);
HEntry *entries = ARRPTR(hs);
char *ptr = STRPTR(hs);
ArrayType *key_array = PG_GETARG_ARRAYTYPE_P(1);
@@ -696,7 +696,7 @@ PG_FUNCTION_INFO_V1(hstore_akeys);
Datum
hstore_akeys(PG_FUNCTION_ARGS)
{
HStore *hs = PG_GETARG_HS(0);
HStore *hs = PG_GETARG_HSTORE_P(0);
Datum *d;
ArrayType *a;
HEntry *entries = ARRPTR(hs);
@@ -731,7 +731,7 @@ PG_FUNCTION_INFO_V1(hstore_avals);
Datum
hstore_avals(PG_FUNCTION_ARGS)
{
HStore *hs = PG_GETARG_HS(0);
HStore *hs = PG_GETARG_HSTORE_P(0);
Datum *d;
bool *nulls;
ArrayType *a;
@@ -827,7 +827,7 @@ PG_FUNCTION_INFO_V1(hstore_to_array);
Datum
hstore_to_array(PG_FUNCTION_ARGS)
{
HStore *hs = PG_GETARG_HS(0);
HStore *hs = PG_GETARG_HSTORE_P(0);
ArrayType *out = hstore_to_array_internal(hs, 1);
PG_RETURN_POINTER(out);
@@ -837,7 +837,7 @@ PG_FUNCTION_INFO_V1(hstore_to_matrix);
Datum
hstore_to_matrix(PG_FUNCTION_ARGS)
{
HStore *hs = PG_GETARG_HS(0);
HStore *hs = PG_GETARG_HSTORE_P(0);
ArrayType *out = hstore_to_array_internal(hs, 2);
PG_RETURN_POINTER(out);
@@ -891,7 +891,7 @@ hstore_skeys(PG_FUNCTION_ARGS)
if (SRF_IS_FIRSTCALL())
{
hs = PG_GETARG_HS(0);
hs = PG_GETARG_HSTORE_P(0);
funcctx = SRF_FIRSTCALL_INIT();
setup_firstcall(funcctx, hs, NULL);
}
@@ -925,7 +925,7 @@ hstore_svals(PG_FUNCTION_ARGS)
if (SRF_IS_FIRSTCALL())
{
hs = PG_GETARG_HS(0);
hs = PG_GETARG_HSTORE_P(0);
funcctx = SRF_FIRSTCALL_INIT();
setup_firstcall(funcctx, hs, NULL);
}
@@ -967,8 +967,8 @@ PG_FUNCTION_INFO_V1(hstore_contains);
Datum
hstore_contains(PG_FUNCTION_ARGS)
{
HStore *val = PG_GETARG_HS(0);
HStore *tmpl = PG_GETARG_HS(1);
HStore *val = PG_GETARG_HSTORE_P(0);
HStore *tmpl = PG_GETARG_HSTORE_P(1);
bool res = true;
HEntry *te = ARRPTR(tmpl);
char *tstr = STRPTR(tmpl);
@@ -1032,7 +1032,7 @@ hstore_each(PG_FUNCTION_ARGS)
if (SRF_IS_FIRSTCALL())
{
hs = PG_GETARG_HS(0);
hs = PG_GETARG_HSTORE_P(0);
funcctx = SRF_FIRSTCALL_INIT();
setup_firstcall(funcctx, hs, fcinfo);
}
@@ -1087,8 +1087,8 @@ PG_FUNCTION_INFO_V1(hstore_cmp);
Datum
hstore_cmp(PG_FUNCTION_ARGS)
{
HStore *hs1 = PG_GETARG_HS(0);
HStore *hs2 = PG_GETARG_HS(1);
HStore *hs1 = PG_GETARG_HSTORE_P(0);
HStore *hs2 = PG_GETARG_HSTORE_P(1);
int hcount1 = HS_COUNT(hs1);
int hcount2 = HS_COUNT(hs2);
int res = 0;
@@ -1235,7 +1235,7 @@ PG_FUNCTION_INFO_V1(hstore_hash);
Datum
hstore_hash(PG_FUNCTION_ARGS)
{
HStore *hs = PG_GETARG_HS(0);
HStore *hs = PG_GETARG_HSTORE_P(0);
Datum hval = hash_any((unsigned char *) VARDATA(hs),
VARSIZE(hs) - VARHDRSZ);