@@ -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 */
2834typedef 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
250256jsonb_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
258264jsonb_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
291297jsonb_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
376382jsonb_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
402408jsonb_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
435441jsonb_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
458464jsonb_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
494500jsonb_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
501507jsonb_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
507513jsonb_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
546552jsonb_number (jsonb * b , char buf [], size_t bufsize , double number )
547553{
548554 char token [32 ];
0 commit comments