Commit e45c5be9 authored by Tom Lane's avatar Tom Lane

Fix thinko in JsObjectSize() macro.

The macro gave the wrong answers for a JsObject with is_json == 0:
it would return 1 if jsonb_cont == NULL, or if that wasn't NULL,
it would return 1 for any non-zero size.

We could fix that, but the only use of this macro at present is in the
JsObjectIsEmpty() macro, so it seems simpler and clearer to get rid of
JsObjectSize() and put corrected logic into JsObjectIsEmpty().

Thinko in commit cf35346e, so no need for back-patch.

Nikita Glukhov

Discussion: https://postgr.es/m/fbd1d566-bba0-a3de-d6d0-d3b1d7c24ff2@postgrespro.ru
parent f3db7f16
......@@ -308,14 +308,14 @@ typedef struct JsObject
((jsv)->is_json ? (jsv)->val.json.type == JSON_TOKEN_STRING \
: ((jsv)->val.jsonb && (jsv)->val.jsonb->type == jbvString))
#define JsObjectSize(jso) \
#define JsObjectIsEmpty(jso) \
((jso)->is_json \
? hash_get_num_entries((jso)->val.json_hash) \
: !(jso)->val.jsonb_cont || JsonContainerSize((jso)->val.jsonb_cont))
? hash_get_num_entries((jso)->val.json_hash) == 0 \
: ((jso)->val.jsonb_cont == NULL || \
JsonContainerSize((jso)->val.jsonb_cont) == 0))
#define JsObjectIsEmpty(jso) (JsObjectSize(jso) == 0)
#define JsObjectFree(jso) do { \
#define JsObjectFree(jso) \
do { \
if ((jso)->is_json) \
hash_destroy((jso)->val.json_hash); \
} while (0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment