confusing typedefs in jsonfuncs.c
The new jsonfuncs.c has some confusing typedef scheme. For example, it
has a bunch of definitions like this:
typedef struct getState
{
...
} getState, *GetState;
So GetState is a pointer to getState. I have never seen that kind of
convention before.
This then leads to code like
GetState state;
state = palloc0(sizeof(getState));
which has useless mental overhead.
But the fact that GetState is really a pointer isn't hidden at all,
because state is then derefenced with -> or cast from or to void*. So
whatever abstraction might have been intended isn't there at all. And
all of this is an intra-file interface anyway.
And to make this even more confusing, other types such as ColumnIOData
and JsonLexContext are not pointers but structs directly.
I think a more typical PostgreSQL code convention is to use capitalized
camelcase for structs, and use explicit pointers for pointers. I have
attached a patch that cleans this up, in my opinion.
Attachments:
jsonfuncs.patchtext/x-patch; charset=UTF-8; name=jsonfuncs.patchDownload
diff --git a/src/backend/utils/adt/json.c b/src/backend/utils/adt/json.c
index a231736..ecfe063 100644
--- a/src/backend/utils/adt/json.c
+++ b/src/backend/utils/adt/json.c
@@ -51,11 +51,11 @@
static inline void json_lex(JsonLexContext *lex);
static inline void json_lex_string(JsonLexContext *lex);
static inline void json_lex_number(JsonLexContext *lex, char *s);
-static inline void parse_scalar(JsonLexContext *lex, JsonSemAction sem);
-static void parse_object_field(JsonLexContext *lex, JsonSemAction sem);
-static void parse_object(JsonLexContext *lex, JsonSemAction sem);
-static void parse_array_element(JsonLexContext *lex, JsonSemAction sem);
-static void parse_array(JsonLexContext *lex, JsonSemAction sem);
+static inline void parse_scalar(JsonLexContext *lex, JsonSemAction *sem);
+static void parse_object_field(JsonLexContext *lex, JsonSemAction *sem);
+static void parse_object(JsonLexContext *lex, JsonSemAction *sem);
+static void parse_array_element(JsonLexContext *lex, JsonSemAction *sem);
+static void parse_array(JsonLexContext *lex, JsonSemAction *sem);
static void report_parse_error(JsonParseContext ctx, JsonLexContext *lex);
static void report_invalid_token(JsonLexContext *lex);
static int report_json_context(JsonLexContext *lex);
@@ -70,12 +70,11 @@ static void array_to_json_internal(Datum array, StringInfo result,
bool use_line_feeds);
/* the null action object used for pure validation */
-static jsonSemAction nullSemAction =
+static JsonSemAction nullSemAction =
{
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL
};
-static JsonSemAction NullSemAction = &nullSemAction;
/* Recursive Descent parser support routines */
@@ -170,7 +169,7 @@ static void array_to_json_internal(Datum array, StringInfo result,
/* validate it */
lex = makeJsonLexContext(result, false);
- pg_parse_json(lex, NullSemAction);
+ pg_parse_json(lex, &nullSemAction);
/* Internal representation is the same as text, for now */
PG_RETURN_TEXT_P(result);
@@ -222,7 +221,7 @@ static void array_to_json_internal(Datum array, StringInfo result,
/* Validate it. */
lex = makeJsonLexContext(result, false);
- pg_parse_json(lex, NullSemAction);
+ pg_parse_json(lex, &nullSemAction);
PG_RETURN_TEXT_P(result);
}
@@ -260,7 +259,7 @@ static void array_to_json_internal(Datum array, StringInfo result,
* pointer to a state object to be passed to those routines.
*/
void
-pg_parse_json(JsonLexContext *lex, JsonSemAction sem)
+pg_parse_json(JsonLexContext *lex, JsonSemAction *sem)
{
JsonTokenType tok;
@@ -296,7 +295,7 @@ static void array_to_json_internal(Datum array, StringInfo result,
* - object field
*/
static inline void
-parse_scalar(JsonLexContext *lex, JsonSemAction sem)
+parse_scalar(JsonLexContext *lex, JsonSemAction *sem)
{
char *val = NULL;
json_scalar_action sfunc = sem->scalar;
@@ -332,7 +331,7 @@ static void array_to_json_internal(Datum array, StringInfo result,
}
static void
-parse_object_field(JsonLexContext *lex, JsonSemAction sem)
+parse_object_field(JsonLexContext *lex, JsonSemAction *sem)
{
/*
* an object field is "fieldname" : value where value can be a scalar,
@@ -380,7 +379,7 @@ static void array_to_json_internal(Datum array, StringInfo result,
}
static void
-parse_object(JsonLexContext *lex, JsonSemAction sem)
+parse_object(JsonLexContext *lex, JsonSemAction *sem)
{
/*
* an object is a possibly empty sequence of object fields, separated by
@@ -428,7 +427,7 @@ static void array_to_json_internal(Datum array, StringInfo result,
}
static void
-parse_array_element(JsonLexContext *lex, JsonSemAction sem)
+parse_array_element(JsonLexContext *lex, JsonSemAction *sem)
{
json_aelem_action astart = sem->array_element_start;
json_aelem_action aend = sem->array_element_end;
@@ -459,7 +458,7 @@ static void array_to_json_internal(Datum array, StringInfo result,
}
static void
-parse_array(JsonLexContext *lex, JsonSemAction sem)
+parse_array(JsonLexContext *lex, JsonSemAction *sem)
{
/*
* an array is a possibly empty sequence of array elements, separated by
diff --git a/src/backend/utils/adt/jsonfuncs.c b/src/backend/utils/adt/jsonfuncs.c
index dd625a4..78a1945 100644
--- a/src/backend/utils/adt/jsonfuncs.c
+++ b/src/backend/utils/adt/jsonfuncs.c
@@ -99,17 +99,17 @@ static inline text *get_worker(text *json, char *field, int elem_index,
} JsonSearch;
/* state for json_object_keys */
-typedef struct okeysState
+typedef struct OkeysState
{
JsonLexContext *lex;
char **result;
int result_size;
int result_count;
int sent_count;
-} okeysState, *OkeysState;
+} OkeysState;
/* state for json_get* functions */
-typedef struct getState
+typedef struct GetState
{
JsonLexContext *lex;
JsonSearch search_type;
@@ -127,17 +127,17 @@ static inline text *get_worker(text *json, char *field, int elem_index,
bool *pathok;
int *array_level_index;
int *path_level_index;
-} getState, *GetState;
+} GetState;
/* state for json_array_length */
-typedef struct alenState
+typedef struct AlenState
{
JsonLexContext *lex;
int count;
-} alenState, *AlenState;
+} AlenState;
/* state for json_each */
-typedef struct eachState
+typedef struct EachState
{
JsonLexContext *lex;
Tuplestorestate *tuple_store;
@@ -147,20 +147,20 @@ static inline text *get_worker(text *json, char *field, int elem_index,
bool normalize_results;
bool next_scalar;
char *normalized_scalar;
-} eachState, *EachState;
+} EachState;
/* state for json_array_elements */
-typedef struct elementsState
+typedef struct ElementsState
{
JsonLexContext *lex;
Tuplestorestate *tuple_store;
TupleDesc ret_tdesc;
MemoryContext tmp_cxt;
char *result_start;
-} elementsState, *ElementsState;
+} ElementsState;
/* state for get_json_object_as_hash */
-typedef struct jhashState
+typedef struct JhashState
{
JsonLexContext *lex;
HTAB *hash;
@@ -168,16 +168,16 @@ static inline text *get_worker(text *json, char *field, int elem_index,
char *save_json_start;
bool use_json_as_text;
char *function_name;
-} jhashState, *JHashState;
+} JHashState;
/* used to build the hashtable */
-typedef struct jsonHashEntry
+typedef struct JsonHashEntry
{
char fname[NAMEDATALEN];
char *val;
char *json;
bool isnull;
-} jsonHashEntry, *JsonHashEntry;
+} JsonHashEntry;
/* these two are stolen from hstore / record_out, used in populate_record* */
typedef struct ColumnIOData
@@ -197,7 +197,7 @@ static inline text *get_worker(text *json, char *field, int elem_index,
} RecordIOData;
/* state for populate_recordset */
-typedef struct populateRecordsetState
+typedef struct PopulateRecordsetState
{
JsonLexContext *lex;
HTAB *json_hash;
@@ -209,7 +209,7 @@ static inline text *get_worker(text *json, char *field, int elem_index,
HeapTupleHeader rec;
RecordIOData *my_extra;
MemoryContext fn_mcxt; /* used to stash IO funcs */
-} populateRecordsetState, *PopulateRecordsetState;
+} PopulateRecordsetState;
/*
* SQL function json_object-keys
@@ -229,22 +229,22 @@ static inline text *get_worker(text *json, char *field, int elem_index,
json_object_keys(PG_FUNCTION_ARGS)
{
FuncCallContext *funcctx;
- OkeysState state;
+ OkeysState *state;
int i;
if (SRF_IS_FIRSTCALL())
{
text *json = PG_GETARG_TEXT_P(0);
JsonLexContext *lex = makeJsonLexContext(json, true);
- JsonSemAction sem;
+ JsonSemAction *sem;
MemoryContext oldcontext;
funcctx = SRF_FIRSTCALL_INIT();
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
- state = palloc(sizeof(okeysState));
- sem = palloc0(sizeof(jsonSemAction));
+ state = palloc(sizeof(OkeysState));
+ sem = palloc0(sizeof(JsonSemAction));
state->lex = lex;
state->result_size = 256;
@@ -272,7 +272,7 @@ static inline text *get_worker(text *json, char *field, int elem_index,
}
funcctx = SRF_PERCALL_SETUP();
- state = (OkeysState) funcctx->user_fctx;
+ state = (OkeysState *) funcctx->user_fctx;
if (state->sent_count < state->result_count)
{
@@ -293,7 +293,7 @@ static inline text *get_worker(text *json, char *field, int elem_index,
static void
okeys_object_field_start(void *state, char *fname, bool isnull)
{
- OkeysState _state = (OkeysState) state;
+ OkeysState *_state = (OkeysState *) state;
/* only collecting keys for the top level object */
if (_state->lex->lex_level != 1)
@@ -314,7 +314,7 @@ static inline text *get_worker(text *json, char *field, int elem_index,
static void
okeys_array_start(void *state)
{
- OkeysState _state = (OkeysState) state;
+ OkeysState *_state = (OkeysState *) state;
/* top level must be a json object */
if (_state->lex->lex_level == 0)
@@ -326,7 +326,7 @@ static inline text *get_worker(text *json, char *field, int elem_index,
static void
okeys_scalar(void *state, char *token, JsonTokenType tokentype)
{
- OkeysState _state = (OkeysState) state;
+ OkeysState *_state = (OkeysState *) state;
/* top level must be a json object */
if (_state->lex->lex_level == 0)
@@ -491,16 +491,16 @@ static inline text *get_worker(text *json, char *field, int elem_index,
int npath,
bool normalize_results)
{
- GetState state;
+ GetState *state;
JsonLexContext *lex = makeJsonLexContext(json, true);
- JsonSemAction sem;
+ JsonSemAction *sem;
/* only allowed to use one of these */
Assert(elem_index < 0 || (tpath == NULL && ipath == NULL && field == NULL));
Assert(tpath == NULL || field == NULL);
- state = palloc0(sizeof(getState));
- sem = palloc0(sizeof(jsonSemAction));
+ state = palloc0(sizeof(GetState));
+ sem = palloc0(sizeof(JsonSemAction));
state->lex = lex;
/* is it "_as_text" variant? */
@@ -560,7 +560,7 @@ static inline text *get_worker(text *json, char *field, int elem_index,
static void
get_object_start(void *state)
{
- GetState _state = (GetState) state;
+ GetState *_state = (GetState *) state;
/* json structure check */
if (_state->lex->lex_level == 0 && _state->search_type == JSON_SEARCH_ARRAY)
@@ -572,7 +572,7 @@ static inline text *get_worker(text *json, char *field, int elem_index,
static void
get_object_field_start(void *state, char *fname, bool isnull)
{
- GetState _state = (GetState) state;
+ GetState *_state = (GetState *) state;
bool get_next = false;
int lex_level = _state->lex->lex_level;
@@ -624,7 +624,7 @@ static inline text *get_worker(text *json, char *field, int elem_index,
static void
get_object_field_end(void *state, char *fname, bool isnull)
{
- GetState _state = (GetState) state;
+ GetState *_state = (GetState *) state;
bool get_last = false;
int lex_level = _state->lex->lex_level;
@@ -674,7 +674,7 @@ static inline text *get_worker(text *json, char *field, int elem_index,
static void
get_array_start(void *state)
{
- GetState _state = (GetState) state;
+ GetState *_state = (GetState *) state;
int lex_level = _state->lex->lex_level;
/* json structure check */
@@ -695,7 +695,7 @@ static inline text *get_worker(text *json, char *field, int elem_index,
static void
get_array_element_start(void *state, bool isnull)
{
- GetState _state = (GetState) state;
+ GetState *_state = (GetState *) state;
bool get_next = false;
int lex_level = _state->lex->lex_level;
@@ -754,7 +754,7 @@ static inline text *get_worker(text *json, char *field, int elem_index,
static void
get_array_element_end(void *state, bool isnull)
{
- GetState _state = (GetState) state;
+ GetState *_state = (GetState *) state;
bool get_last = false;
int lex_level = _state->lex->lex_level;
@@ -792,7 +792,7 @@ static inline text *get_worker(text *json, char *field, int elem_index,
static void
get_scalar(void *state, char *token, JsonTokenType tokentype)
{
- GetState _state = (GetState) state;
+ GetState *_state = (GetState *) state;
if (_state->lex->lex_level == 0 && _state->search_type != JSON_SEARCH_PATH)
ereport(ERROR,
@@ -816,12 +816,12 @@ static inline text *get_worker(text *json, char *field, int elem_index,
{
text *json = PG_GETARG_TEXT_P(0);
- AlenState state;
+ AlenState *state;
JsonLexContext *lex = makeJsonLexContext(json, false);
- JsonSemAction sem;
+ JsonSemAction *sem;
- state = palloc0(sizeof(alenState));
- sem = palloc0(sizeof(jsonSemAction));
+ state = palloc0(sizeof(AlenState));
+ sem = palloc0(sizeof(JsonSemAction));
/* palloc0 does this for us */
#if 0
@@ -847,7 +847,7 @@ static inline text *get_worker(text *json, char *field, int elem_index,
static void
alen_object_start(void *state)
{
- AlenState _state = (AlenState) state;
+ AlenState *_state = (AlenState *) state;
/* json structure check */
if (_state->lex->lex_level == 0)
@@ -859,7 +859,7 @@ static inline text *get_worker(text *json, char *field, int elem_index,
static void
alen_scalar(void *state, char *token, JsonTokenType tokentype)
{
- AlenState _state = (AlenState) state;
+ AlenState *_state = (AlenState *) state;
/* json structure check */
if (_state->lex->lex_level == 0)
@@ -871,7 +871,7 @@ static inline text *get_worker(text *json, char *field, int elem_index,
static void
alen_array_element_start(void *state, bool isnull)
{
- AlenState _state = (AlenState) state;
+ AlenState *_state = (AlenState *) state;
/* just count up all the level 1 elements */
if (_state->lex->lex_level == 1)
@@ -905,14 +905,14 @@ static inline text *get_worker(text *json, char *field, int elem_index,
{
text *json = PG_GETARG_TEXT_P(0);
JsonLexContext *lex = makeJsonLexContext(json, true);
- JsonSemAction sem;
+ JsonSemAction *sem;
ReturnSetInfo *rsi;
MemoryContext old_cxt;
TupleDesc tupdesc;
- EachState state;
+ EachState *state;
- state = palloc0(sizeof(eachState));
- sem = palloc0(sizeof(jsonSemAction));
+ state = palloc0(sizeof(EachState));
+ sem = palloc0(sizeof(JsonSemAction));
rsi = (ReturnSetInfo *) fcinfo->resultinfo;
@@ -968,7 +968,7 @@ static inline text *get_worker(text *json, char *field, int elem_index,
static void
each_object_field_start(void *state, char *fname, bool isnull)
{
- EachState _state = (EachState) state;
+ EachState *_state = (EachState *) state;
/* save a pointer to where the value starts */
if (_state->lex->lex_level == 1)
@@ -988,7 +988,7 @@ static inline text *get_worker(text *json, char *field, int elem_index,
static void
each_object_field_end(void *state, char *fname, bool isnull)
{
- EachState _state = (EachState) state;
+ EachState *_state = (EachState *) state;
MemoryContext old_cxt;
int len;
text *val;
@@ -1035,7 +1035,7 @@ static inline text *get_worker(text *json, char *field, int elem_index,
static void
each_array_start(void *state)
{
- EachState _state = (EachState) state;
+ EachState *_state = (EachState *) state;
/* json structure check */
if (_state->lex->lex_level == 0)
@@ -1047,7 +1047,7 @@ static inline text *get_worker(text *json, char *field, int elem_index,
static void
each_scalar(void *state, char *token, JsonTokenType tokentype)
{
- EachState _state = (EachState) state;
+ EachState *_state = (EachState *) state;
/* json structure check */
if (_state->lex->lex_level == 0)
@@ -1074,14 +1074,14 @@ static inline text *get_worker(text *json, char *field, int elem_index,
/* elements doesn't need any escaped strings, so use false here */
JsonLexContext *lex = makeJsonLexContext(json, false);
- JsonSemAction sem;
+ JsonSemAction *sem;
ReturnSetInfo *rsi;
MemoryContext old_cxt;
TupleDesc tupdesc;
- ElementsState state;
+ ElementsState *state;
- state = palloc0(sizeof(elementsState));
- sem = palloc0(sizeof(jsonSemAction));
+ state = palloc0(sizeof(ElementsState));
+ sem = palloc0(sizeof(JsonSemAction));
rsi = (ReturnSetInfo *) fcinfo->resultinfo;
@@ -1134,7 +1134,7 @@ static inline text *get_worker(text *json, char *field, int elem_index,
static void
elements_array_element_start(void *state, bool isnull)
{
- ElementsState _state = (ElementsState) state;
+ ElementsState *_state = (ElementsState *) state;
/* save a pointer to where the value starts */
if (_state->lex->lex_level == 1)
@@ -1144,7 +1144,7 @@ static inline text *get_worker(text *json, char *field, int elem_index,
static void
elements_array_element_end(void *state, bool isnull)
{
- ElementsState _state = (ElementsState) state;
+ ElementsState *_state = (ElementsState *) state;
MemoryContext old_cxt;
int len;
text *val;
@@ -1176,7 +1176,7 @@ static inline text *get_worker(text *json, char *field, int elem_index,
static void
elements_object_start(void *state)
{
- ElementsState _state = (ElementsState) state;
+ ElementsState *_state = (ElementsState *) state;
/* json structure check */
if (_state->lex->lex_level == 0)
@@ -1188,7 +1188,7 @@ static inline text *get_worker(text *json, char *field, int elem_index,
static void
elements_scalar(void *state, char *token, JsonTokenType tokentype)
{
- ElementsState _state = (ElementsState) state;
+ ElementsState *_state = (ElementsState *) state;
/* json structure check */
if (_state->lex->lex_level == 0)
@@ -1232,7 +1232,7 @@ static inline text *get_worker(text *json, char *field, int elem_index,
Datum *values;
bool *nulls;
char fname[NAMEDATALEN];
- JsonHashEntry hashentry;
+ JsonHashEntry *hashentry;
use_json_as_text = PG_ARGISNULL(2) ? false : PG_GETARG_BOOL(2);
@@ -1423,21 +1423,21 @@ static inline text *get_worker(text *json, char *field, int elem_index,
{
HASHCTL ctl;
HTAB *tab;
- JHashState state;
+ JHashState *state;
JsonLexContext *lex = makeJsonLexContext(json, true);
- JsonSemAction sem;
+ JsonSemAction *sem;
memset(&ctl, 0, sizeof(ctl));
ctl.keysize = NAMEDATALEN;
- ctl.entrysize = sizeof(jsonHashEntry);
+ ctl.entrysize = sizeof(JsonHashEntry);
ctl.hcxt = CurrentMemoryContext;
tab = hash_create("json object hashtable",
100,
&ctl,
HASH_ELEM | HASH_CONTEXT);
- state = palloc0(sizeof(jhashState));
- sem = palloc0(sizeof(jsonSemAction));
+ state = palloc0(sizeof(JHashState));
+ sem = palloc0(sizeof(JsonSemAction));
state->function_name = funcname;
state->hash = tab;
@@ -1458,7 +1458,7 @@ static inline text *get_worker(text *json, char *field, int elem_index,
static void
hash_object_field_start(void *state, char *fname, bool isnull)
{
- JHashState _state = (JHashState) state;
+ JHashState *_state = (JHashState *) state;
if (_state->lex->lex_level > 1)
return;
@@ -1483,8 +1483,8 @@ static inline text *get_worker(text *json, char *field, int elem_index,
static void
hash_object_field_end(void *state, char *fname, bool isnull)
{
- JHashState _state = (JHashState) state;
- JsonHashEntry hashentry;
+ JHashState *_state = (JHashState *) state;
+ JsonHashEntry *hashentry;
bool found;
char name[NAMEDATALEN];
@@ -1525,7 +1525,7 @@ static inline text *get_worker(text *json, char *field, int elem_index,
static void
hash_array_start(void *state)
{
- JHashState _state = (JHashState) state;
+ JHashState *_state = (JHashState *) state;
if (_state->lex->lex_level == 0)
ereport(ERROR,
@@ -1536,7 +1536,7 @@ static inline text *get_worker(text *json, char *field, int elem_index,
static void
hash_scalar(void *state, char *token, JsonTokenType tokentype)
{
- JHashState _state = (JHashState) state;
+ JHashState *_state = (JHashState *) state;
if (_state->lex->lex_level == 0)
ereport(ERROR,
@@ -1573,8 +1573,8 @@ static inline text *get_worker(text *json, char *field, int elem_index,
RecordIOData *my_extra;
int ncolumns;
JsonLexContext *lex;
- JsonSemAction sem;
- PopulateRecordsetState state;
+ JsonSemAction *sem;
+ PopulateRecordsetState *state;
use_json_as_text = PG_ARGISNULL(2) ? false : PG_GETARG_BOOL(2);
@@ -1602,8 +1602,8 @@ static inline text *get_worker(text *json, char *field, int elem_index,
*/
(void) get_call_result_type(fcinfo, NULL, &tupdesc);
- state = palloc0(sizeof(populateRecordsetState));
- sem = palloc0(sizeof(jsonSemAction));
+ state = palloc0(sizeof(PopulateRecordsetState));
+ sem = palloc0(sizeof(JsonSemAction));
/* make these in a sufficiently long-lived memory context */
@@ -1690,7 +1690,7 @@ static inline text *get_worker(text *json, char *field, int elem_index,
static void
populate_recordset_object_start(void *state)
{
- PopulateRecordsetState _state = (PopulateRecordsetState) state;
+ PopulateRecordsetState *_state = (PopulateRecordsetState *) state;
int lex_level = _state->lex->lex_level;
HASHCTL ctl;
@@ -1706,7 +1706,7 @@ static inline text *get_worker(text *json, char *field, int elem_index,
/* set up a new hash for this entry */
memset(&ctl, 0, sizeof(ctl));
ctl.keysize = NAMEDATALEN;
- ctl.entrysize = sizeof(jsonHashEntry);
+ ctl.entrysize = sizeof(JsonHashEntry);
ctl.hcxt = CurrentMemoryContext;
_state->json_hash = hash_create("json object hashtable",
100,
@@ -1717,7 +1717,7 @@ static inline text *get_worker(text *json, char *field, int elem_index,
static void
populate_recordset_object_end(void *state)
{
- PopulateRecordsetState _state = (PopulateRecordsetState) state;
+ PopulateRecordsetState *_state = (PopulateRecordsetState *) state;
HTAB *json_hash = _state->json_hash;
Datum *values;
bool *nulls;
@@ -1726,7 +1726,7 @@ static inline text *get_worker(text *json, char *field, int elem_index,
RecordIOData *my_extra = _state->my_extra;
int ncolumns = my_extra->ncolumns;
TupleDesc tupdesc = _state->ret_tdesc;
- JsonHashEntry hashentry;
+ JsonHashEntry *hashentry;
HeapTupleHeader rec = _state->rec;
HeapTuple rettuple;
@@ -1830,7 +1830,7 @@ static inline text *get_worker(text *json, char *field, int elem_index,
static void
populate_recordset_array_element_start(void *state, bool isnull)
{
- PopulateRecordsetState _state = (PopulateRecordsetState) state;
+ PopulateRecordsetState *_state = (PopulateRecordsetState *) state;
if (_state->lex->lex_level == 1 &&
_state->lex->token_type != JSON_TOKEN_OBJECT_START)
@@ -1842,7 +1842,7 @@ static inline text *get_worker(text *json, char *field, int elem_index,
static void
populate_recordset_array_start(void *state)
{
- PopulateRecordsetState _state = (PopulateRecordsetState) state;
+ PopulateRecordsetState *_state = (PopulateRecordsetState *) state;
if (_state->lex->lex_level != 0 && !_state->use_json_as_text)
ereport(ERROR,
@@ -1853,7 +1853,7 @@ static inline text *get_worker(text *json, char *field, int elem_index,
static void
populate_recordset_scalar(void *state, char *token, JsonTokenType tokentype)
{
- PopulateRecordsetState _state = (PopulateRecordsetState) state;
+ PopulateRecordsetState *_state = (PopulateRecordsetState *) state;
if (_state->lex->lex_level == 0)
ereport(ERROR,
@@ -1867,7 +1867,7 @@ static inline text *get_worker(text *json, char *field, int elem_index,
static void
populate_recordset_object_field_start(void *state, char *fname, bool isnull)
{
- PopulateRecordsetState _state = (PopulateRecordsetState) state;
+ PopulateRecordsetState *_state = (PopulateRecordsetState *) state;
if (_state->lex->lex_level > 2)
return;
@@ -1890,8 +1890,8 @@ static inline text *get_worker(text *json, char *field, int elem_index,
static void
populate_recordset_object_field_end(void *state, char *fname, bool isnull)
{
- PopulateRecordsetState _state = (PopulateRecordsetState) state;
- JsonHashEntry hashentry;
+ PopulateRecordsetState *_state = (PopulateRecordsetState *) state;
+ JsonHashEntry *hashentry;
bool found;
char name[NAMEDATALEN];
diff --git a/src/include/utils/jsonapi.h b/src/include/utils/jsonapi.h
index f5ec904..e25a0d9 100644
--- a/src/include/utils/jsonapi.h
+++ b/src/include/utils/jsonapi.h
@@ -74,7 +74,7 @@ typedef void (*json_scalar_action) (void *state, char *token, JsonTokenType toke
* to doing a pure parse with no side-effects, and is therefore exactly
* what the json input routines do.
*/
-typedef struct jsonSemAction
+typedef struct JsonSemAction
{
void *semstate;
json_struct_action object_start;
@@ -86,8 +86,7 @@ typedef struct jsonSemAction
json_aelem_action array_element_start;
json_aelem_action array_element_end;
json_scalar_action scalar;
-} jsonSemAction,
- *JsonSemAction;
+} JsonSemAction;
/*
* parse_json will parse the string in the lex calling the
@@ -98,7 +97,7 @@ typedef struct jsonSemAction
* points to. If the action pointers are NULL the parser
* does nothing and just continues.
*/
-extern void pg_parse_json(JsonLexContext *lex, JsonSemAction sem);
+extern void pg_parse_json(JsonLexContext *lex, JsonSemAction *sem);
/*
* constructor for JsonLexContext, with or without strval element.
Peter Eisentraut <peter_e@gmx.net> writes:
The new jsonfuncs.c has some confusing typedef scheme. For example, it
has a bunch of definitions like this:
typedef struct getState
{
...
} getState, *GetState;
So GetState is a pointer to getState. I have never seen that kind of
convention before.
Yeah, this is randomly different from everywhere else in PG. The more
usual convention if you want typedefs for both the struct and the
pointer type is that the pointer type is FooBar and the struct type is
FooBarData. This way seems seriously typo-prone.
I think a more typical PostgreSQL code convention is to use capitalized
camelcase for structs, and use explicit pointers for pointers. I have
attached a patch that cleans this up, in my opinion.
That way is fine with me too.
If you commit this, please hit 9.3 as well, so that we don't have
back-patching issues.
regards, tom lane
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On 07/18/2013 09:20 PM, Peter Eisentraut wrote:
The new jsonfuncs.c has some confusing typedef scheme. For example, it
has a bunch of definitions like this:typedef struct getState
{
...
} getState, *GetState;So GetState is a pointer to getState. I have never seen that kind of
convention before.This then leads to code like
GetState state;
state = palloc0(sizeof(getState));
which has useless mental overhead.
But the fact that GetState is really a pointer isn't hidden at all,
because state is then derefenced with -> or cast from or to void*. So
whatever abstraction might have been intended isn't there at all. And
all of this is an intra-file interface anyway.And to make this even more confusing, other types such as ColumnIOData
and JsonLexContext are not pointers but structs directly.I think a more typical PostgreSQL code convention is to use capitalized
camelcase for structs, and use explicit pointers for pointers. I have
attached a patch that cleans this up, in my opinion.
I don't have a problem with this. Sometimes when you've stared at
something for long enough you fail to notice such things, so I welcome
more eyeballs on the code.
Note that this is an externally visible API, so anyone who has written
an extension against it will possibly find it broken. But that's all the
more reason to clean it now, before it makes it to a released version.
cheers
andrew
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On Thu, 2013-07-18 at 21:34 -0400, Tom Lane wrote:
Yeah, this is randomly different from everywhere else in PG. The more
usual convention if you want typedefs for both the struct and the
pointer type is that the pointer type is FooBar and the struct type is
FooBarData.
I think that is more useful if you have a really good abstraction around
FooBar, like for Relation, for example. That's not really the case
here. This is more like node types, perhaps.
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers