From 6e87701f86c7f7b7529a6959adf23b6b461ee8e0 Mon Sep 17 00:00:00 2001
From: Peter Geoghegan <pg@bowt.ie>
Date: Sat, 17 Sep 2022 18:19:39 -0700
Subject: [PATCH v4 2/4] Harmonize parameter names in jsonb code.

Make sure that function declarations use names that exactly match the
corresponding names from function definitions.  Having parameter names
that are reliably consistent in this way will make it easier to reason
about groups of related C functions from the same translation unit as a
module.  It will also make certain refactoring tasks easier.

Like other recent commits that cleaned up function parameter names, this
commit was written with help from clang-tidy.  Later commits will do the
same for other parts of the codebase.

Author: Peter Geoghegan <pg@bowt.ie>
Reviewed-By: David Rowley <dgrowleyml@gmail.com>
Discussion: https://postgr.es/m/CAH2-WznJt9CMM9KJTMjJh_zbL5hD9oX44qdJ4aqZtjFi-zA3Tg@mail.gmail.com
---
 src/include/utils/jsonb.h             |  6 +--
 src/backend/utils/adt/jsonb.c         | 12 ++---
 src/backend/utils/adt/jsonb_util.c    | 74 +++++++++++++--------------
 src/backend/utils/adt/jsonpath_exec.c |  2 +-
 4 files changed, 47 insertions(+), 47 deletions(-)

diff --git a/src/include/utils/jsonb.h b/src/include/utils/jsonb.h
index 4cbe6edf2..b03c17d73 100644
--- a/src/include/utils/jsonb.h
+++ b/src/include/utils/jsonb.h
@@ -379,13 +379,13 @@ typedef struct JsonbIterator
 extern uint32 getJsonbOffset(const JsonbContainer *jc, int index);
 extern uint32 getJsonbLength(const JsonbContainer *jc, int index);
 extern int	compareJsonbContainers(JsonbContainer *a, JsonbContainer *b);
-extern JsonbValue *findJsonbValueFromContainer(JsonbContainer *sheader,
+extern JsonbValue *findJsonbValueFromContainer(JsonbContainer *container,
 											   uint32 flags,
 											   JsonbValue *key);
 extern JsonbValue *getKeyJsonValueFromContainer(JsonbContainer *container,
 												const char *keyVal, int keyLen,
 												JsonbValue *res);
-extern JsonbValue *getIthJsonbValueFromContainer(JsonbContainer *sheader,
+extern JsonbValue *getIthJsonbValueFromContainer(JsonbContainer *container,
 												 uint32 i);
 extern JsonbValue *pushJsonbValue(JsonbParseState **pstate,
 								  JsonbIteratorToken seq, JsonbValue *jbval);
@@ -406,7 +406,7 @@ extern char *JsonbToCString(StringInfo out, JsonbContainer *in,
 extern char *JsonbToCStringIndent(StringInfo out, JsonbContainer *in,
 								  int estimated_len);
 extern bool JsonbExtractScalar(JsonbContainer *jbc, JsonbValue *res);
-extern const char *JsonbTypeName(JsonbValue *jb);
+extern const char *JsonbTypeName(JsonbValue *val);
 
 extern Datum jsonb_set_element(Jsonb *jb, Datum *path, int path_len,
 							   JsonbValue *newval);
diff --git a/src/backend/utils/adt/jsonb.c b/src/backend/utils/adt/jsonb.c
index 88b0000f9..9e14922ec 100644
--- a/src/backend/utils/adt/jsonb.c
+++ b/src/backend/utils/adt/jsonb.c
@@ -188,12 +188,12 @@ JsonbContainerTypeName(JsonbContainer *jbc)
  * Get the type name of a jsonb value.
  */
 const char *
-JsonbTypeName(JsonbValue *jbv)
+JsonbTypeName(JsonbValue *val)
 {
-	switch (jbv->type)
+	switch (val->type)
 	{
 		case jbvBinary:
-			return JsonbContainerTypeName(jbv->val.binary.data);
+			return JsonbContainerTypeName(val->val.binary.data);
 		case jbvObject:
 			return "object";
 		case jbvArray:
@@ -207,7 +207,7 @@ JsonbTypeName(JsonbValue *jbv)
 		case jbvNull:
 			return "null";
 		case jbvDatetime:
-			switch (jbv->val.datetime.typid)
+			switch (val->val.datetime.typid)
 			{
 				case DATEOID:
 					return "date";
@@ -221,11 +221,11 @@ JsonbTypeName(JsonbValue *jbv)
 					return "timestamp with time zone";
 				default:
 					elog(ERROR, "unrecognized jsonb value datetime type: %d",
-						 jbv->val.datetime.typid);
+						 val->val.datetime.typid);
 			}
 			return "unknown";
 		default:
-			elog(ERROR, "unrecognized jsonb value type: %d", jbv->type);
+			elog(ERROR, "unrecognized jsonb value type: %d", val->type);
 			return "unknown";
 	}
 }
diff --git a/src/backend/utils/adt/jsonb_util.c b/src/backend/utils/adt/jsonb_util.c
index 60442758b..7d6a1ed23 100644
--- a/src/backend/utils/adt/jsonb_util.c
+++ b/src/backend/utils/adt/jsonb_util.c
@@ -57,13 +57,13 @@ static short padBufferToInt(StringInfo buffer);
 static JsonbIterator *iteratorFromContainer(JsonbContainer *container, JsonbIterator *parent);
 static JsonbIterator *freeAndGetParent(JsonbIterator *it);
 static JsonbParseState *pushState(JsonbParseState **pstate);
-static void appendKey(JsonbParseState *pstate, JsonbValue *scalarVal);
+static void appendKey(JsonbParseState *pstate, JsonbValue *string);
 static void appendValue(JsonbParseState *pstate, JsonbValue *scalarVal);
 static void appendElement(JsonbParseState *pstate, JsonbValue *scalarVal);
 static int	lengthCompareJsonbStringValue(const void *a, const void *b);
 static int	lengthCompareJsonbString(const char *val1, int len1,
 									 const char *val2, int len2);
-static int	lengthCompareJsonbPair(const void *a, const void *b, void *arg);
+static int	lengthCompareJsonbPair(const void *a, const void *b, void *binequal);
 static void uniqueifyJsonbObject(JsonbValue *object);
 static JsonbValue *pushJsonbValueScalar(JsonbParseState **pstate,
 										JsonbIteratorToken seq,
@@ -1394,22 +1394,22 @@ JsonbHashScalarValueExtended(const JsonbValue *scalarVal, uint64 *hash,
  * Are two scalar JsonbValues of the same type a and b equal?
  */
 static bool
-equalsJsonbScalarValue(JsonbValue *aScalar, JsonbValue *bScalar)
+equalsJsonbScalarValue(JsonbValue *a, JsonbValue *b)
 {
-	if (aScalar->type == bScalar->type)
+	if (a->type == b->type)
 	{
-		switch (aScalar->type)
+		switch (a->type)
 		{
 			case jbvNull:
 				return true;
 			case jbvString:
-				return lengthCompareJsonbStringValue(aScalar, bScalar) == 0;
+				return lengthCompareJsonbStringValue(a, b) == 0;
 			case jbvNumeric:
 				return DatumGetBool(DirectFunctionCall2(numeric_eq,
-														PointerGetDatum(aScalar->val.numeric),
-														PointerGetDatum(bScalar->val.numeric)));
+														PointerGetDatum(a->val.numeric),
+														PointerGetDatum(b->val.numeric)));
 			case jbvBool:
-				return aScalar->val.boolean == bScalar->val.boolean;
+				return a->val.boolean == b->val.boolean;
 
 			default:
 				elog(ERROR, "invalid jsonb scalar type");
@@ -1426,28 +1426,28 @@ equalsJsonbScalarValue(JsonbValue *aScalar, JsonbValue *bScalar)
  * operators, where a lexical sort order is generally expected.
  */
 static int
-compareJsonbScalarValue(JsonbValue *aScalar, JsonbValue *bScalar)
+compareJsonbScalarValue(JsonbValue *a, JsonbValue *b)
 {
-	if (aScalar->type == bScalar->type)
+	if (a->type == b->type)
 	{
-		switch (aScalar->type)
+		switch (a->type)
 		{
 			case jbvNull:
 				return 0;
 			case jbvString:
-				return varstr_cmp(aScalar->val.string.val,
-								  aScalar->val.string.len,
-								  bScalar->val.string.val,
-								  bScalar->val.string.len,
+				return varstr_cmp(a->val.string.val,
+								  a->val.string.len,
+								  b->val.string.val,
+								  b->val.string.len,
 								  DEFAULT_COLLATION_OID);
 			case jbvNumeric:
 				return DatumGetInt32(DirectFunctionCall2(numeric_cmp,
-														 PointerGetDatum(aScalar->val.numeric),
-														 PointerGetDatum(bScalar->val.numeric)));
+														 PointerGetDatum(a->val.numeric),
+														 PointerGetDatum(b->val.numeric)));
 			case jbvBool:
-				if (aScalar->val.boolean == bScalar->val.boolean)
+				if (a->val.boolean == b->val.boolean)
 					return 0;
-				else if (aScalar->val.boolean > bScalar->val.boolean)
+				else if (a->val.boolean > b->val.boolean)
 					return 1;
 				else
 					return -1;
@@ -1608,13 +1608,13 @@ convertJsonbValue(StringInfo buffer, JEntry *header, JsonbValue *val, int level)
 }
 
 static void
-convertJsonbArray(StringInfo buffer, JEntry *pheader, JsonbValue *val, int level)
+convertJsonbArray(StringInfo buffer, JEntry *header, JsonbValue *val, int level)
 {
 	int			base_offset;
 	int			jentry_offset;
 	int			i;
 	int			totallen;
-	uint32		header;
+	uint32		containerhead;
 	int			nElems = val->val.array.nElems;
 
 	/* Remember where in the buffer this array starts. */
@@ -1627,15 +1627,15 @@ convertJsonbArray(StringInfo buffer, JEntry *pheader, JsonbValue *val, int level
 	 * Construct the header Jentry and store it in the beginning of the
 	 * variable-length payload.
 	 */
-	header = nElems | JB_FARRAY;
+	containerhead = nElems | JB_FARRAY;
 	if (val->val.array.rawScalar)
 	{
 		Assert(nElems == 1);
 		Assert(level == 0);
-		header |= JB_FSCALAR;
+		containerhead |= JB_FSCALAR;
 	}
 
-	appendToBuffer(buffer, (char *) &header, sizeof(uint32));
+	appendToBuffer(buffer, (char *) &containerhead, sizeof(uint32));
 
 	/* Reserve space for the JEntries of the elements. */
 	jentry_offset = reserveFromBuffer(buffer, sizeof(JEntry) * nElems);
@@ -1688,17 +1688,17 @@ convertJsonbArray(StringInfo buffer, JEntry *pheader, JsonbValue *val, int level
 						JENTRY_OFFLENMASK)));
 
 	/* Initialize the header of this node in the container's JEntry array */
-	*pheader = JENTRY_ISCONTAINER | totallen;
+	*header = JENTRY_ISCONTAINER | totallen;
 }
 
 static void
-convertJsonbObject(StringInfo buffer, JEntry *pheader, JsonbValue *val, int level)
+convertJsonbObject(StringInfo buffer, JEntry *header, JsonbValue *val, int level)
 {
 	int			base_offset;
 	int			jentry_offset;
 	int			i;
 	int			totallen;
-	uint32		header;
+	uint32		containerheader;
 	int			nPairs = val->val.object.nPairs;
 
 	/* Remember where in the buffer this object starts. */
@@ -1711,8 +1711,8 @@ convertJsonbObject(StringInfo buffer, JEntry *pheader, JsonbValue *val, int leve
 	 * Construct the header Jentry and store it in the beginning of the
 	 * variable-length payload.
 	 */
-	header = nPairs | JB_FOBJECT;
-	appendToBuffer(buffer, (char *) &header, sizeof(uint32));
+	containerheader = nPairs | JB_FOBJECT;
+	appendToBuffer(buffer, (char *) &containerheader, sizeof(uint32));
 
 	/* Reserve space for the JEntries of the keys and values. */
 	jentry_offset = reserveFromBuffer(buffer, sizeof(JEntry) * nPairs * 2);
@@ -1804,11 +1804,11 @@ convertJsonbObject(StringInfo buffer, JEntry *pheader, JsonbValue *val, int leve
 						JENTRY_OFFLENMASK)));
 
 	/* Initialize the header of this node in the container's JEntry array */
-	*pheader = JENTRY_ISCONTAINER | totallen;
+	*header = JENTRY_ISCONTAINER | totallen;
 }
 
 static void
-convertJsonbScalar(StringInfo buffer, JEntry *jentry, JsonbValue *scalarVal)
+convertJsonbScalar(StringInfo buffer, JEntry *header, JsonbValue *scalarVal)
 {
 	int			numlen;
 	short		padlen;
@@ -1816,13 +1816,13 @@ convertJsonbScalar(StringInfo buffer, JEntry *jentry, JsonbValue *scalarVal)
 	switch (scalarVal->type)
 	{
 		case jbvNull:
-			*jentry = JENTRY_ISNULL;
+			*header = JENTRY_ISNULL;
 			break;
 
 		case jbvString:
 			appendToBuffer(buffer, scalarVal->val.string.val, scalarVal->val.string.len);
 
-			*jentry = scalarVal->val.string.len;
+			*header = scalarVal->val.string.len;
 			break;
 
 		case jbvNumeric:
@@ -1831,11 +1831,11 @@ convertJsonbScalar(StringInfo buffer, JEntry *jentry, JsonbValue *scalarVal)
 
 			appendToBuffer(buffer, (char *) scalarVal->val.numeric, numlen);
 
-			*jentry = JENTRY_ISNUMERIC | (padlen + numlen);
+			*header = JENTRY_ISNUMERIC | (padlen + numlen);
 			break;
 
 		case jbvBool:
-			*jentry = (scalarVal->val.boolean) ?
+			*header = (scalarVal->val.boolean) ?
 				JENTRY_ISBOOL_TRUE : JENTRY_ISBOOL_FALSE;
 			break;
 
@@ -1851,7 +1851,7 @@ convertJsonbScalar(StringInfo buffer, JEntry *jentry, JsonbValue *scalarVal)
 				len = strlen(buf);
 				appendToBuffer(buffer, buf, len);
 
-				*jentry = len;
+				*header = len;
 			}
 			break;
 
diff --git a/src/backend/utils/adt/jsonpath_exec.c b/src/backend/utils/adt/jsonpath_exec.c
index 9f4192e07..8d83b2edb 100644
--- a/src/backend/utils/adt/jsonpath_exec.c
+++ b/src/backend/utils/adt/jsonpath_exec.c
@@ -252,7 +252,7 @@ static int	JsonbType(JsonbValue *jb);
 static JsonbValue *getScalar(JsonbValue *scalar, enum jbvType type);
 static JsonbValue *wrapItemsInArray(const JsonValueList *items);
 static int	compareDatetime(Datum val1, Oid typid1, Datum val2, Oid typid2,
-							bool useTz, bool *have_error);
+							bool useTz, bool *cast_error);
 
 /****************** User interface to JsonPath executor ********************/
 
-- 
2.34.1

