Revise APIs for pushJsonbValue() and associated routines.

Instead of passing "JsonbParseState **" to pushJsonbValue(),
pass a pointer to a JsonbInState, which will contain the
parseState stack pointer as well as other useful fields.
Also, instead of returning a JsonbValue pointer that is often
meaningless/ignored, return the top-level JsonbValue pointer
in the "result" field of the JsonbInState.

This involves a lot of (mostly mechanical) edits, but I think
the results are notationally cleaner and easier to understand.
Certainly the business with sometimes capturing the result of
pushJsonbValue() and sometimes not was bug-prone and incapable of
mechanical verification.  In the new arrangement, JsonbInState.result
remains null until we've completed a valid sequence of pushes, so
that an incorrect sequence will result in a null-pointer dereference,
not mistaken use of a partial result.

However, this isn't simply an exercise in prettier notation.
The real reason for doing it is to provide a mechanism whereby
pushJsonbValue() can be told to construct the JsonbValue tree
in a context that is not CurrentMemoryContext.  That happens
when a non-null "outcontext" is specified in the JsonbInState.
No callers exercise that option in this patch, but the next
patch in the series will make use of it.

I tried to improve the comments in this area too.

Author: Tom Lane <[email protected]>
Reviewed-by: jian he <[email protected]>
Reviewed-by: Chao Li <[email protected]>
Discussion: https://postgr.es/m/[email protected]

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/0986e95161cec929d8f39c01e9848f34526be421

Modified Files
--------------
contrib/hstore/hstore_io.c              |  26 ++-
contrib/jsonb_plperl/jsonb_plperl.c     |  55 +++--
contrib/jsonb_plpython/jsonb_plpython.c |  67 ++++---
src/backend/utils/adt/jsonb.c           | 165 +++++++--------
src/backend/utils/adt/jsonb_util.c      | 343 +++++++++++++++++++++-----------
src/backend/utils/adt/jsonfuncs.c       | 235 ++++++++++------------
src/backend/utils/adt/jsonpath_exec.c   |  16 +-
src/include/utils/jsonb.h               |  43 +++-
8 files changed, 528 insertions(+), 422 deletions(-)

Reply via email to