1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-08 11:42:09 +03:00

Introduce convenience macros to hide JsonbContainer header accesses better.

This improves readability a bit and may make future improvements easier.

In passing, make sure that the JB_ROOT_IS_XXX macros deliver boolean (0/1)
results; the previous coding was a bug hazard, though no actual bugs are
known.

Nikita Glukhov, extended a bit by me

Discussion: https://postgr.es/m/9e21a39c-c1d7-b9b5-44a0-c5345a5029f6@postgrespro.ru
This commit is contained in:
Tom Lane
2017-01-25 13:28:38 -05:00
parent 049ac809a7
commit f7c6246240
3 changed files with 20 additions and 14 deletions

View File

@ -1266,10 +1266,10 @@ get_jsonb_path_all(FunctionCallInfo fcinfo, bool as_text)
uint32 nelements;
/* Container must be array, but make sure */
if ((container->header & JB_FARRAY) == 0)
if (!JsonContainerIsArray(container))
elog(ERROR, "not a jsonb array");
nelements = container->header & JB_CMASK;
nelements = JsonContainerSize(container);
if (-lindex > nelements)
PG_RETURN_NULL();