Skip to content

Commit 9fc928e

Browse files
committed
docs: better document JSONB_MAX_DEPTH
* refactor: add JSONB_API prefixing for src functions
1 parent 06b6abd commit 9fc928e

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

json-build.h

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,16 @@ extern "C" {
1919
#define JSONB_API extern
2020
#endif
2121

22-
/* if necessary should be increased to avoid segfault */
2322
#ifndef JSONB_MAX_DEPTH
24-
#define JSONB_MAX_DEPTH 512
25-
#endif
23+
/**
24+
* Maximum JSON nesting depth, if default value is unwanted then it should be
25+
* defined before json-build.h is included:
26+
*
27+
* #define JSONB_MAX_DEPTH 256
28+
* #include "json-build.h"
29+
* */
30+
#define JSONB_MAX_DEPTH 128
31+
#endif /* JSONB_MAX_DEPTH */
2632

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

249-
void
255+
JSONB_API void
250256
jsonb_init(jsonb *b)
251257
{
252258
static jsonb empty_builder;
253259
*b = empty_builder;
254260
b->top = b->stack;
255261
}
256262

257-
jsonbcode
263+
JSONB_API jsonbcode
258264
jsonb_object(jsonb *b, char buf[], size_t bufsize)
259265
{
260266
enum jsonbstate new_state;
@@ -287,7 +293,7 @@ jsonb_object(jsonb *b, char buf[], size_t bufsize)
287293
return JSONB_OK;
288294
}
289295

290-
jsonbcode
296+
JSONB_API jsonbcode
291297
jsonb_object_pop(jsonb *b, char buf[], size_t bufsize)
292298
{
293299
enum jsonbcode code;
@@ -372,7 +378,7 @@ _jsonb_escape(
372378
goto second_iter;
373379
}
374380

375-
jsonbcode
381+
JSONB_API jsonbcode
376382
jsonb_key(jsonb *b, char buf[], size_t bufsize, const char key[], size_t len)
377383
{
378384
size_t pos = 0;
@@ -398,7 +404,7 @@ jsonb_key(jsonb *b, char buf[], size_t bufsize, const char key[], size_t len)
398404
return JSONB_OK;
399405
}
400406

401-
jsonbcode
407+
JSONB_API jsonbcode
402408
jsonb_array(jsonb *b, char buf[], size_t bufsize)
403409
{
404410
enum jsonbstate new_state;
@@ -431,7 +437,7 @@ jsonb_array(jsonb *b, char buf[], size_t bufsize)
431437
return JSONB_OK;
432438
}
433439

434-
jsonbcode
440+
JSONB_API jsonbcode
435441
jsonb_array_pop(jsonb *b, char buf[], size_t bufsize)
436442
{
437443
enum jsonbcode code;
@@ -454,7 +460,7 @@ jsonb_array_pop(jsonb *b, char buf[], size_t bufsize)
454460
return code;
455461
}
456462

457-
jsonbcode
463+
JSONB_API jsonbcode
458464
jsonb_token(
459465
jsonb *b, char buf[], size_t bufsize, const char token[], size_t len)
460466
{
@@ -490,20 +496,20 @@ jsonb_token(
490496
return code;
491497
}
492498

493-
jsonbcode
499+
JSONB_API jsonbcode
494500
jsonb_bool(jsonb *b, char buf[], size_t bufsize, int boolean)
495501
{
496502
if (boolean) return jsonb_token(b, buf, bufsize, "true", 4);
497503
return jsonb_token(b, buf, bufsize, "false", 5);
498504
}
499505

500-
jsonbcode
506+
JSONB_API jsonbcode
501507
jsonb_null(jsonb *b, char buf[], size_t bufsize)
502508
{
503509
return jsonb_token(b, buf, bufsize, "null", 4);
504510
}
505511

506-
jsonbcode
512+
JSONB_API jsonbcode
507513
jsonb_string(
508514
jsonb *b, char buf[], size_t bufsize, const char str[], size_t len)
509515
{
@@ -542,7 +548,7 @@ jsonb_string(
542548
return code;
543549
}
544550

545-
jsonbcode
551+
JSONB_API jsonbcode
546552
jsonb_number(jsonb *b, char buf[], size_t bufsize, double number)
547553
{
548554
char token[32];

0 commit comments

Comments
 (0)