Skip to content

Commit 913da11

Browse files
committed
Update json-c to 0.17-master-6e481aa
1 parent 5715a30 commit 913da11

22 files changed

+948
-176
lines changed

vendor/json-c/ChangeLog

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,42 @@
1+
0.17-master:
2+
3+
The below changelog is incomplete. For this merge in mtasa-blue, we are using revision 6e481aa @ https://github.com/json-c/json-c
4+
5+
6+
0.17 (up to commit 077661f, 2023-08-08)
7+
========================================
8+
9+
Deprecated and removed features:
10+
--------------------------------
11+
* None
12+
13+
New features
14+
------------
15+
* json_patch: add first implementation only with patch application
16+
* Add --disable-static and --disable-dynamic options to the cmake-configure script.
17+
* Add -DBUILD_APPS=NO option to disable app build
18+
* Minimum cmake version is now 3.9
19+
20+
Significant changes and bug fixes
21+
---------------------------------
22+
* When serializing with JSON_C_TO_STRING_PRETTY set, keep the opening and
23+
closing curly or square braces on same line for empty objects or arrays.
24+
* Disable locale handling when targeting a uClibc system due to problems
25+
with its duplocale() function.
26+
* When parsing with JSON_TOKENER_STRICT set, integer overflow/underflow
27+
now result in a json_tokener_error_parse_number. Without that flag
28+
values are capped at INT64_MIN/UINT64_MAX.
29+
* Fix memory leak with emtpy strings in json_object_set_string
30+
* json_object_from_fd_ex: fail if file is too large (>=INT_MAX bytes)
31+
* Add back json_number_chars, but only because it's part of the public API.
32+
* Entirely drop mode bits from open(O_RDONLY) to avoid warnings on certain
33+
platforms.
34+
* Specify dependent libraries, including -lbsd, in a more consistent way so
35+
linking against a static json-c works better
36+
* Fix a variety of build problems and add & improve tests
37+
* Update RFC reference to https://www.rfc-editor.org/rfc/rfc8259
38+
39+
***
140

241
0.16 (up to commit 66dcdf5, 2022-04-13)
342
========================================

vendor/json-c/arraylist.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,27 @@ int array_list_shrink(struct array_list *arr, size_t empty_slots)
125125
return 0;
126126
}
127127

128+
int array_list_insert_idx(struct array_list *arr, size_t idx, void *data)
129+
{
130+
size_t move_amount;
131+
132+
if (idx >= arr->length)
133+
return array_list_put_idx(arr, idx, data);
134+
135+
/* we're at full size, what size_t can support */
136+
if (arr->length == SIZE_T_MAX)
137+
return -1;
138+
139+
if (array_list_expand_internal(arr, arr->length + 1))
140+
return -1;
141+
142+
move_amount = (arr->length - idx) * sizeof(void *);
143+
memmove(arr->array + idx + 1, arr->array + idx, move_amount);
144+
arr->array[idx] = data;
145+
arr->length++;
146+
return 0;
147+
}
148+
128149
//static inline int _array_list_put_idx(struct array_list *arr, size_t idx, void *data)
129150
int array_list_put_idx(struct array_list *arr, size_t idx, void *data)
130151
{

vendor/json-c/arraylist.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ extern void array_list_free(struct array_list *al);
6262

6363
extern void *array_list_get_idx(struct array_list *al, size_t i);
6464

65+
extern int array_list_insert_idx(struct array_list *al, size_t i, void *data);
66+
6567
extern int array_list_put_idx(struct array_list *al, size_t i, void *data);
6668

6769
extern int array_list_add(struct array_list *al, void *data);

vendor/json-c/json_c_version.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012,2017-2022 Eric Haszlakiewicz
2+
* Copyright (c) 2012,2017 Eric Haszlakiewicz
33
*
44
* This library is free software; you can redistribute it and/or modify
55
* it under the terms of the MIT license. See COPYING for details.
@@ -17,11 +17,11 @@ extern "C" {
1717
#endif
1818

1919
#define JSON_C_MAJOR_VERSION 0
20-
#define JSON_C_MINOR_VERSION 16
21-
#define JSON_C_MICRO_VERSION 0
20+
#define JSON_C_MINOR_VERSION 17
21+
#define JSON_C_MICRO_VERSION 99
2222
#define JSON_C_VERSION_NUM \
2323
((JSON_C_MAJOR_VERSION << 16) | (JSON_C_MINOR_VERSION << 8) | JSON_C_MICRO_VERSION)
24-
#define JSON_C_VERSION "0.16"
24+
#define JSON_C_VERSION "0.17.99"
2525

2626
#ifndef JSON_EXPORT
2727
#if defined(_MSC_VER) && defined(JSON_C_DLL)

vendor/json-c/json_config.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1+
12
/* Define to 1 if you have the <inttypes.h> header file. */
3+
#if defined(_MSC_VER) && _MSC_VER >= 1800
24
#define JSON_C_HAVE_INTTYPES_H 1
5+
#endif

vendor/json-c/json_inttypes.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,25 @@
1313
#include <inttypes.h>
1414

1515
#else
16+
#ifdef JSON_C_HAVE_STDINT_H
1617
#include <stdint.h>
18+
#else
19+
/* Really only valid for old MS compilers, VS2008 and earlier: */
20+
typedef __int32 int32_t;
21+
typedef unsigned __int32 uint32_t;
22+
typedef __int64 int64_t;
23+
typedef unsigned __int64 uint64_t;
24+
#endif
1725

1826
#define PRId64 "I64d"
1927
#define SCNd64 "I64d"
2028
#define PRIu64 "I64u"
2129

2230
#endif
2331

32+
#if defined(_MSC_VER)
33+
#include <BaseTsd.h>
34+
typedef SSIZE_T ssize_t;
35+
#endif
36+
2437
#endif

vendor/json-c/json_object.c

Lines changed: 62 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
#endif
5454
#endif
5555

56+
const char *json_number_chars = "0123456789.+-eE"; /* Unused, but part of public API, drop for 1.0 */
5657
const char *json_hex_chars = "0123456789abcdefABCDEF";
5758

5859
static void json_object_generic_delete(struct json_object *jso);
@@ -64,6 +65,12 @@ static void json_object_generic_delete(struct json_object *jso);
6465
#define inline
6566
#endif
6667

68+
/* define colors */
69+
#define ANSI_COLOR_RESET "\033[0m"
70+
#define ANSI_COLOR_FG_GREEN "\033[0;32m"
71+
#define ANSI_COLOR_FG_BLUE "\033[0;34m"
72+
#define ANSI_COLOR_FG_MAGENTA "\033[0;35m"
73+
6774
/*
6875
* Helper functions to more safely cast to a particular type of json_object
6976
*/
@@ -460,35 +467,45 @@ static int json_object_object_to_json_string(struct json_object *jso, struct pri
460467
struct json_object_iter iter;
461468

462469
printbuf_strappend(pb, "{" /*}*/);
463-
if (flags & JSON_C_TO_STRING_PRETTY)
464-
printbuf_strappend(pb, "\n");
465470
json_object_object_foreachC(jso, iter)
466471
{
467472
if (had_children)
468473
{
469474
printbuf_strappend(pb, ",");
470-
if (flags & JSON_C_TO_STRING_PRETTY)
471-
printbuf_strappend(pb, "\n");
472475
}
476+
if (flags & JSON_C_TO_STRING_PRETTY)
477+
printbuf_strappend(pb, "\n");
473478
had_children = 1;
474479
if (flags & JSON_C_TO_STRING_SPACED && !(flags & JSON_C_TO_STRING_PRETTY))
475480
printbuf_strappend(pb, " ");
476481
indent(pb, level + 1, flags);
482+
if (flags & JSON_C_TO_STRING_COLOR)
483+
printbuf_strappend(pb, ANSI_COLOR_FG_BLUE);
484+
477485
printbuf_strappend(pb, "\"");
478486
json_escape_str(pb, iter.key, strlen(iter.key), flags);
487+
printbuf_strappend(pb, "\"");
488+
489+
if (flags & JSON_C_TO_STRING_COLOR)
490+
printbuf_strappend(pb, ANSI_COLOR_RESET);
491+
479492
if (flags & JSON_C_TO_STRING_SPACED)
480-
printbuf_strappend(pb, "\": ");
493+
printbuf_strappend(pb, ": ");
481494
else
482-
printbuf_strappend(pb, "\":");
483-
if (iter.val == NULL)
495+
printbuf_strappend(pb, ":");
496+
497+
if (iter.val == NULL) {
498+
if (flags & JSON_C_TO_STRING_COLOR)
499+
printbuf_strappend(pb, ANSI_COLOR_FG_MAGENTA);
484500
printbuf_strappend(pb, "null");
485-
else if (iter.val->_to_json_string(iter.val, pb, level + 1, flags) < 0)
501+
if (flags & JSON_C_TO_STRING_COLOR)
502+
printbuf_strappend(pb, ANSI_COLOR_RESET);
503+
} else if (iter.val->_to_json_string(iter.val, pb, level + 1, flags) < 0)
486504
return -1;
487505
}
488-
if (flags & JSON_C_TO_STRING_PRETTY)
506+
if ((flags & JSON_C_TO_STRING_PRETTY) && had_children)
489507
{
490-
if (had_children)
491-
printbuf_strappend(pb, "\n");
508+
printbuf_strappend(pb, "\n");
492509
indent(pb, level, flags);
493510
}
494511
if (flags & JSON_C_TO_STRING_SPACED && !(flags & JSON_C_TO_STRING_PRETTY))
@@ -629,9 +646,18 @@ void json_object_object_del(struct json_object *jso, const char *key)
629646
static int json_object_boolean_to_json_string(struct json_object *jso, struct printbuf *pb,
630647
int level, int flags)
631648
{
649+
int ret;
650+
651+
if (flags & JSON_C_TO_STRING_COLOR)
652+
printbuf_strappend(pb, ANSI_COLOR_FG_MAGENTA);
653+
632654
if (JC_BOOL(jso)->c_boolean)
633-
return printbuf_strappend(pb, "true");
634-
return printbuf_strappend(pb, "false");
655+
ret = printbuf_strappend(pb, "true");
656+
else
657+
ret = printbuf_strappend(pb, "false");
658+
if (ret > -1 && flags & JSON_C_TO_STRING_COLOR)
659+
return printbuf_strappend(pb, ANSI_COLOR_RESET);
660+
return ret;
635661
}
636662

637663
struct json_object *json_object_new_boolean(json_bool b)
@@ -1011,7 +1037,7 @@ static int json_object_double_to_json_string_format(struct json_object *jso, str
10111037
}
10121038
else
10131039
{
1014-
const char *std_format = "%.16g";
1040+
const char *std_format = "%.17g";
10151041
int format_drops_decimals = 0;
10161042
int looks_numeric = 0;
10171043

@@ -1220,9 +1246,13 @@ static int json_object_string_to_json_string(struct json_object *jso, struct pri
12201246
int level, int flags)
12211247
{
12221248
ssize_t len = JC_STRING(jso)->len;
1249+
if (flags & JSON_C_TO_STRING_COLOR)
1250+
printbuf_strappend(pb, ANSI_COLOR_FG_GREEN);
12231251
printbuf_strappend(pb, "\"");
12241252
json_escape_str(pb, get_string_component(jso), len < 0 ? -(ssize_t)len : len, flags);
12251253
printbuf_strappend(pb, "\"");
1254+
if (flags & JSON_C_TO_STRING_COLOR)
1255+
printbuf_strappend(pb, ANSI_COLOR_RESET);
12261256
return 0;
12271257
}
12281258

@@ -1381,31 +1411,34 @@ static int json_object_array_to_json_string(struct json_object *jso, struct prin
13811411
size_t ii;
13821412

13831413
printbuf_strappend(pb, "[");
1384-
if (flags & JSON_C_TO_STRING_PRETTY)
1385-
printbuf_strappend(pb, "\n");
13861414
for (ii = 0; ii < json_object_array_length(jso); ii++)
13871415
{
13881416
struct json_object *val;
13891417
if (had_children)
13901418
{
13911419
printbuf_strappend(pb, ",");
1392-
if (flags & JSON_C_TO_STRING_PRETTY)
1393-
printbuf_strappend(pb, "\n");
13941420
}
1421+
if (flags & JSON_C_TO_STRING_PRETTY)
1422+
printbuf_strappend(pb, "\n");
13951423
had_children = 1;
13961424
if (flags & JSON_C_TO_STRING_SPACED && !(flags & JSON_C_TO_STRING_PRETTY))
13971425
printbuf_strappend(pb, " ");
13981426
indent(pb, level + 1, flags);
13991427
val = json_object_array_get_idx(jso, ii);
1400-
if (val == NULL)
1428+
if (val == NULL) {
1429+
1430+
if (flags & JSON_C_TO_STRING_COLOR)
1431+
printbuf_strappend(pb, ANSI_COLOR_FG_MAGENTA);
14011432
printbuf_strappend(pb, "null");
1402-
else if (val->_to_json_string(val, pb, level + 1, flags) < 0)
1433+
if (flags & JSON_C_TO_STRING_COLOR)
1434+
printbuf_strappend(pb, ANSI_COLOR_RESET);
1435+
1436+
} else if (val->_to_json_string(val, pb, level + 1, flags) < 0)
14031437
return -1;
14041438
}
1405-
if (flags & JSON_C_TO_STRING_PRETTY)
1439+
if ((flags & JSON_C_TO_STRING_PRETTY) && had_children)
14061440
{
1407-
if (had_children)
1408-
printbuf_strappend(pb, "\n");
1441+
printbuf_strappend(pb, "\n");
14091442
indent(pb, level, flags);
14101443
}
14111444

@@ -1487,6 +1520,12 @@ int json_object_array_add(struct json_object *jso, struct json_object *val)
14871520
return array_list_add(JC_ARRAY(jso)->c_array, val);
14881521
}
14891522

1523+
int json_object_array_insert_idx(struct json_object *jso, size_t idx, struct json_object *val)
1524+
{
1525+
assert(json_object_get_type(jso) == json_type_array);
1526+
return array_list_insert_idx(JC_ARRAY(jso)->c_array, idx, val);
1527+
}
1528+
14901529
int json_object_array_put_idx(struct json_object *jso, size_t idx, struct json_object *val)
14911530
{
14921531
assert(json_object_get_type(jso) == json_type_array);

0 commit comments

Comments
 (0)