From 4530066e0be9064ec7f64e2b15927030beee7aea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=AErekc=C3=A4H=20nitraM=E2=80=AE?= Date: Thu, 31 Oct 2024 23:32:48 +0100 Subject: [PATCH] Provide better typed json_typeof Further down in the header the function `json_error_code()` is defined to return the `enum json_error_code`. That function has a much better documentation value, as it also defines what values the returned value can have. It also sets a naming precedent, of having a function of the same name as the enum, which makes a lot of sense to me. In the future, when you bump the major version of the library anyway, you could change the define of json_typeof to `#define json_typeof json_type` and maybe start a deprecation cycle of the old name. --- src/jansson.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/jansson.h b/src/jansson.h index 391c85e9..41d0bf53 100644 --- a/src/jansson.h +++ b/src/jansson.h @@ -78,6 +78,10 @@ typedef long json_int_t; #endif #define json_typeof(json) ((json)->type) +static JSON_INLINE enum json_type json_type(const json_t *json) { + return (enum json_type)json->type; +} + #define json_is_object(json) ((json) && json_typeof(json) == JSON_OBJECT) #define json_is_array(json) ((json) && json_typeof(json) == JSON_ARRAY) #define json_is_string(json) ((json) && json_typeof(json) == JSON_STRING)