Skip to content

Commit

Permalink
docs: better document JSONB_MAX_DEPTH
Browse files Browse the repository at this point in the history
* refactor: add JSONB_API prefixing for src functions
  • Loading branch information
lcsmuller committed Apr 15, 2022
1 parent 06b6abd commit 9fc928e
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions json-build.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,16 @@ extern "C" {
#define JSONB_API extern
#endif

/* if necessary should be increased to avoid segfault */
#ifndef JSONB_MAX_DEPTH
#define JSONB_MAX_DEPTH 512
#endif
/**
* Maximum JSON nesting depth, if default value is unwanted then it should be
* defined before json-build.h is included:
*
* #define JSONB_MAX_DEPTH 256
* #include "json-build.h"
* */
#define JSONB_MAX_DEPTH 128
#endif /* JSONB_MAX_DEPTH */

/** @brief json-builder return codes */
typedef enum jsonbcode {
Expand Down Expand Up @@ -246,15 +252,15 @@ _jsonb_eval_state(enum jsonbstate state)
(buf)[(b)->pos + (_pos)] = '\0'; \
} while (0)

void
JSONB_API void
jsonb_init(jsonb *b)
{
static jsonb empty_builder;
*b = empty_builder;
b->top = b->stack;
}

jsonbcode
JSONB_API jsonbcode
jsonb_object(jsonb *b, char buf[], size_t bufsize)
{
enum jsonbstate new_state;
Expand Down Expand Up @@ -287,7 +293,7 @@ jsonb_object(jsonb *b, char buf[], size_t bufsize)
return JSONB_OK;
}

jsonbcode
JSONB_API jsonbcode
jsonb_object_pop(jsonb *b, char buf[], size_t bufsize)
{
enum jsonbcode code;
Expand Down Expand Up @@ -372,7 +378,7 @@ _jsonb_escape(
goto second_iter;
}

jsonbcode
JSONB_API jsonbcode
jsonb_key(jsonb *b, char buf[], size_t bufsize, const char key[], size_t len)
{
size_t pos = 0;
Expand All @@ -398,7 +404,7 @@ jsonb_key(jsonb *b, char buf[], size_t bufsize, const char key[], size_t len)
return JSONB_OK;
}

jsonbcode
JSONB_API jsonbcode
jsonb_array(jsonb *b, char buf[], size_t bufsize)
{
enum jsonbstate new_state;
Expand Down Expand Up @@ -431,7 +437,7 @@ jsonb_array(jsonb *b, char buf[], size_t bufsize)
return JSONB_OK;
}

jsonbcode
JSONB_API jsonbcode
jsonb_array_pop(jsonb *b, char buf[], size_t bufsize)
{
enum jsonbcode code;
Expand All @@ -454,7 +460,7 @@ jsonb_array_pop(jsonb *b, char buf[], size_t bufsize)
return code;
}

jsonbcode
JSONB_API jsonbcode
jsonb_token(
jsonb *b, char buf[], size_t bufsize, const char token[], size_t len)
{
Expand Down Expand Up @@ -490,20 +496,20 @@ jsonb_token(
return code;
}

jsonbcode
JSONB_API jsonbcode
jsonb_bool(jsonb *b, char buf[], size_t bufsize, int boolean)
{
if (boolean) return jsonb_token(b, buf, bufsize, "true", 4);
return jsonb_token(b, buf, bufsize, "false", 5);
}

jsonbcode
JSONB_API jsonbcode
jsonb_null(jsonb *b, char buf[], size_t bufsize)
{
return jsonb_token(b, buf, bufsize, "null", 4);
}

jsonbcode
JSONB_API jsonbcode
jsonb_string(
jsonb *b, char buf[], size_t bufsize, const char str[], size_t len)
{
Expand Down Expand Up @@ -542,7 +548,7 @@ jsonb_string(
return code;
}

jsonbcode
JSONB_API jsonbcode
jsonb_number(jsonb *b, char buf[], size_t bufsize, double number)
{
char token[32];
Expand Down

0 comments on commit 9fc928e

Please sign in to comment.