Skip to content

Commit 5a08c29

Browse files
committed
issue: 4634244 migrate json-c from 0.13 to 0.17
Migrate the json-c library from version 0.13.1 to 0.17.0 to gain access to newer features and bug fixes. The new version uses Meson build system which is incompatible with the existing Autotools-based libxlio project. To maintain compatibility, convert the Meson build system to Autotools: * Create configure.ac with comprehensive feature detection for threads, atomic operations, and system headers * Add Makefile.am with proper source file management and libtool support * Generate pkg-config files (json-c.pc, json-c-uninstalled.pc) for proper library linking * Add json_compat.h for backward compatibility with renamed functions The new json-c 0.17.0 uses doca_third_party_ prefix for all exported functions to avoid symbol conflicts. Update all callers: * src/core/config/descriptor_providers/json_descriptor_provider.cpp * src/core/config/descriptor_providers/schema_analyzer.cpp * src/core/config/json_object_handle.cpp * src/core/config/json_utils.cpp * src/core/config/loaders/json_loader.cpp * tests/unit_tests/config/schema_analyzer.cpp Configuration changes: * Update configure.ac to build json-c subdirectory * Modify config/m4/json.m4 to point to new library paths * Update third_party/Makefile.am with proper subdirectory handling All 94 unit tests pass. Main project builds successfully with full backward compatibility maintained. Signed-off-by: Tomer Cabouly <[email protected]>
1 parent 1691622 commit 5a08c29

File tree

170 files changed

+40341
-5553
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

170 files changed

+40341
-5553
lines changed

src/core/config/descriptor_providers/json_descriptor_provider.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ json_descriptor_provider::json_descriptor_provider(const char *json_string)
3737

3838
config_descriptor json_descriptor_provider::load_descriptors()
3939
{
40-
json_object_handle schema_handle(json_tokener_parse(m_json_string));
40+
json_object_handle schema_handle(doca_third_party_json_tokener_parse(m_json_string));
4141
if (!schema_handle.get()) {
4242
throw_xlio_exception("Failed to parse JSON schema.");
4343
}
@@ -49,7 +49,7 @@ config_descriptor json_descriptor_provider::load_descriptors()
4949
json_object *properties =
5050
json_utils::get_field(schema_handle.get(), config_strings::schema::JSON_PROPERTIES);
5151

52-
json_object_object_foreach(properties, key, val)
52+
doca_third_party_json_object_object_foreach(properties, key, val)
5353
{
5454
process_schema_property(val, key, result_desc);
5555
}
@@ -59,22 +59,22 @@ config_descriptor json_descriptor_provider::load_descriptors()
5959

6060
void json_descriptor_provider::validate_schema(json_object *schema)
6161
{
62-
if (json_object_get_type(schema) != json_type_object) {
62+
if (doca_third_party_json_object_get_type(schema) != json_type_object) {
6363
throw_xlio_exception("Schema root must be an object.");
6464
}
6565

6666
json_object *properties =
6767
json_utils::get_field(schema, config_strings::schema::JSON_PROPERTIES);
6868

69-
json_object_object_foreach(properties, key, val)
69+
doca_third_party_json_object_object_foreach(properties, key, val)
7070
{
71-
if (json_object_get_type(val) != json_type_object) {
71+
if (doca_third_party_json_object_get_type(val) != json_type_object) {
7272
throw_xlio_exception("Property '" + std::string(key) + "' must be an object.");
7373
}
7474
}
7575

7676
json_object *type_field = json_utils::get_field(schema, config_strings::schema::JSON_TYPE);
77-
if (std::string(json_object_get_string(type_field)) !=
77+
if (std::string(doca_third_party_json_object_get_string(type_field)) !=
7878
config_strings::schema_types::JSON_TYPE_OBJECT) {
7979
throw_xlio_exception("Schema root must have type 'object'.");
8080
}
@@ -84,15 +84,15 @@ void json_descriptor_provider::validate_terminal_property(json_object *property_
8484
const std::string &current_path)
8585
{
8686
// Basic validation for terminal properties
87-
if (!property_obj || json_object_get_type(property_obj) != json_type_object) {
87+
if (!property_obj || doca_third_party_json_object_get_type(property_obj) != json_type_object) {
8888
throw_xlio_exception("Invalid property object for: " + current_path);
8989
}
9090

9191
// Check for required description field
9292
json_object *description_field =
9393
json_utils::get_field(property_obj, config_strings::schema::JSON_DESCRIPTION);
9494

95-
if (json_object_get_type(description_field) != json_type_string) {
95+
if (doca_third_party_json_object_get_type(description_field) != json_type_string) {
9696
throw_xlio_exception("Invalid 'description' field type for terminal property: " +
9797
current_path);
9898
}
@@ -119,8 +119,9 @@ void json_descriptor_provider::process_schema_property(json_object *property_obj
119119
if (analysis.json_property_type == property_type::OBJECT) {
120120
json_object *properties =
121121
json_utils::try_get_field(property_obj, config_strings::schema::JSON_PROPERTIES);
122-
if (properties && json_object_get_type(properties) == json_type_object) {
123-
json_object_object_foreach(properties, key, val)
122+
if (properties &&
123+
doca_third_party_json_object_get_type(properties) == json_type_object) {
124+
doca_third_party_json_object_object_foreach(properties, key, val)
124125
{
125126
process_schema_property(val, key, desc, current_path);
126127
}

src/core/config/descriptor_providers/schema_analyzer.cpp

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
static void for_each_oneof_option(json_object *one_of_field,
1616
std::function<void(json_object *)> func)
1717
{
18-
int one_of_length = json_object_array_length(one_of_field);
18+
int one_of_length = doca_third_party_json_object_array_length(one_of_field);
1919
for (int i = 0; i < one_of_length; i++) {
20-
json_object *option = json_object_array_get_idx(one_of_field, i);
20+
json_object *option = doca_third_party_json_object_array_get_idx(one_of_field, i);
2121
func(option);
2222
}
2323
}
@@ -46,7 +46,7 @@ bool schema_analyzer::is_applicable(json_object *property_obj)
4646
return false;
4747
}
4848

49-
if (json_object_get_type(property_obj) != json_type_object) {
49+
if (doca_third_party_json_object_get_type(property_obj) != json_type_object) {
5050
return false;
5151
}
5252

@@ -82,15 +82,15 @@ property_type schema_analyzer::determine_property_type()
8282
json_object *type_field =
8383
json_utils::get_field(m_property_obj, config_strings::schema::JSON_TYPE);
8484
std::string json_type_str;
85-
if (json_object_get_type(type_field) == json_type_string) {
86-
json_type_str = json_object_get_string(type_field);
85+
if (doca_third_party_json_object_get_type(type_field) == json_type_string) {
86+
json_type_str = doca_third_party_json_object_get_string(type_field);
8787
}
8888

8989
// Object properties with nested properties
9090
if (json_type_str == config_strings::schema_types::JSON_TYPE_OBJECT) {
9191
json_object *properties_field =
9292
json_utils::get_field(m_property_obj, config_strings::schema::JSON_PROPERTIES);
93-
if (json_object_get_type(properties_field) == json_type_object) {
93+
if (doca_third_party_json_object_get_type(properties_field) == json_type_object) {
9494
return property_type::OBJECT;
9595
}
9696
}
@@ -123,7 +123,7 @@ std::type_index schema_analyzer::determine_value_type()
123123
json_object *type_field =
124124
json_utils::get_field(m_property_obj, config_strings::schema::JSON_TYPE);
125125

126-
std::string type_str = json_object_get_string(type_field);
126+
std::string type_str = doca_third_party_json_object_get_string(type_field);
127127
if (type_str == config_strings::schema_types::JSON_TYPE_BOOLEAN) {
128128
return typeid(bool);
129129
} else if (type_str == config_strings::schema_types::JSON_TYPE_INTEGER) {
@@ -150,7 +150,7 @@ std::experimental::optional<std::experimental::any> schema_analyzer::determine_d
150150
// Check for oneOf first - default values are nested inside oneOf options
151151
json_object *one_of_field =
152152
json_utils::try_get_field(m_property_obj, config_strings::schema::JSON_ONE_OF);
153-
if (one_of_field && json_object_get_type(one_of_field) == json_type_array) {
153+
if (one_of_field && doca_third_party_json_object_get_type(one_of_field) == json_type_array) {
154154
return extract_oneof_value(one_of_field, type, config_strings::schema::JSON_DEFAULT);
155155
}
156156

@@ -185,17 +185,17 @@ static void extract_constraints_from_json(json_object *obj, constraint_config &c
185185
return;
186186
}
187187
json_object *min_field = json_utils::try_get_field(obj, config_strings::schema::JSON_MINIMUM);
188-
if (min_field && json_object_get_type(min_field) == json_type_int) {
188+
if (min_field && doca_third_party_json_object_get_type(min_field) == json_type_int) {
189189
config.has_minimum = true;
190-
config.minimum_value = json_object_get_int64(min_field);
190+
config.minimum_value = doca_third_party_json_object_get_int64(min_field);
191191
}
192192
json_object *max_field = json_utils::try_get_field(obj, config_strings::schema::JSON_MAXIMUM);
193-
if (max_field && json_object_get_type(max_field) == json_type_int) {
193+
if (max_field && doca_third_party_json_object_get_type(max_field) == json_type_int) {
194194
config.has_maximum = true;
195-
config.maximum_value = json_object_get_int64(max_field);
195+
config.maximum_value = doca_third_party_json_object_get_int64(max_field);
196196
}
197197
json_object *enum_field = json_utils::try_get_field(obj, config_strings::schema::JSON_ENUM);
198-
if (enum_field && json_object_get_type(enum_field) == json_type_array) {
198+
if (enum_field && doca_third_party_json_object_get_type(enum_field) == json_type_array) {
199199
config.has_enum = true;
200200
config.enum_int_values = json_utils::extract_enum_values<int64_t>(enum_field);
201201
}
@@ -218,7 +218,7 @@ constraint_config schema_analyzer::analyze_constraint_config()
218218
for_each_oneof_option(one_of_field, [&](json_object *option) {
219219
json_object *type_field =
220220
json_utils::get_field(option, config_strings::schema::JSON_TYPE);
221-
std::string type_str = json_object_get_string(type_field);
221+
std::string type_str = doca_third_party_json_object_get_string(type_field);
222222
if (type_str == config_strings::schema_types::JSON_TYPE_INTEGER) {
223223
extract_constraints_from_json(option, config);
224224
}
@@ -249,7 +249,7 @@ enum_mapping_config_t schema_analyzer::analyze_enum_mapping_config()
249249
for_each_oneof_option(one_of_field, [&](json_object *option) {
250250
json_object *type_field = json_utils::get_field(option, config_strings::schema::JSON_TYPE);
251251

252-
std::string type_str = json_object_get_string(type_field);
252+
std::string type_str = doca_third_party_json_object_get_string(type_field);
253253
if (type_str == config_strings::schema_types::JSON_TYPE_INTEGER) {
254254
int_option = option;
255255
} else if (type_str == config_strings::schema_types::JSON_TYPE_STRING) {
@@ -295,8 +295,8 @@ bool schema_analyzer::has_memory_size_flag()
295295
return false;
296296
}
297297

298-
return json_object_get_type(memory_size_flag) == json_type_boolean &&
299-
json_object_get_boolean(memory_size_flag);
298+
return doca_third_party_json_object_get_type(memory_size_flag) == json_type_boolean &&
299+
doca_third_party_json_object_get_boolean(memory_size_flag);
300300
}
301301

302302
bool schema_analyzer::has_power_of_2_or_zero_flag()
@@ -328,13 +328,13 @@ bool schema_analyzer::has_constraint_fields()
328328
if (has_oneof_field()) {
329329
json_object *one_of_field =
330330
json_utils::get_field(m_property_obj, config_strings::schema::JSON_ONE_OF);
331-
int one_of_length = json_object_array_length(one_of_field);
331+
int one_of_length = doca_third_party_json_object_array_length(one_of_field);
332332
for (int i = 0; i < one_of_length; i++) {
333-
json_object *option = json_object_array_get_idx(one_of_field, i);
333+
json_object *option = doca_third_party_json_object_array_get_idx(one_of_field, i);
334334
json_object *type_field =
335335
json_utils::get_field(option, config_strings::schema::JSON_TYPE);
336336

337-
std::string type_str = json_object_get_string(type_field);
337+
std::string type_str = doca_third_party_json_object_get_string(type_field);
338338

339339
// For integer option, check if it has constraints
340340
if (type_str == config_strings::schema_types::JSON_TYPE_INTEGER) {
@@ -358,7 +358,7 @@ bool schema_analyzer::has_oneof_field()
358358
json_object *one_of_field =
359359
json_utils::try_get_field(m_property_obj, config_strings::schema::JSON_ONE_OF);
360360

361-
if (one_of_field && json_object_get_type(one_of_field) != json_type_array) {
361+
if (one_of_field && doca_third_party_json_object_get_type(one_of_field) != json_type_array) {
362362
throw_xlio_exception("OneOf field must be an array for: " + m_path);
363363
}
364364

@@ -369,9 +369,9 @@ std::experimental::any schema_analyzer::extract_oneof_value(json_object *one_of_
369369
std::type_index type,
370370
const std::string &key)
371371
{
372-
int one_of_length = json_object_array_length(one_of_field);
372+
int one_of_length = doca_third_party_json_object_array_length(one_of_field);
373373
for (int i = 0; i < one_of_length; i++) {
374-
json_object *option = json_object_array_get_idx(one_of_field, i);
374+
json_object *option = doca_third_party_json_object_array_get_idx(one_of_field, i);
375375
json_object *key_field = json_utils::try_get_field(option, key.c_str());
376376

377377
if (key_field && std::type_index(json_utils::to_any_value(key_field).type()) == type) {

src/core/config/json_object_handle.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ json_object_handle::json_object_handle(json_object *obj)
1414
json_object_handle::~json_object_handle()
1515
{
1616
if (m_obj) {
17-
json_object_put(m_obj);
17+
doca_third_party_json_object_put(m_obj);
1818
}
1919
}
2020

src/core/config/json_utils.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ json_object *try_get_field(json_object *obj, const char *field_name)
3434
}
3535

3636
json_object *field = nullptr;
37-
if (json_object_object_get_ex(obj, field_name, &field)) {
37+
if (doca_third_party_json_object_object_get_ex(obj, field_name, &field)) {
3838
return field;
3939
}
4040

@@ -55,7 +55,7 @@ std::experimental::any to_any_value(json_object *obj)
5555
{json_type_object, convert_object},
5656
{json_type_array, convert_array}};
5757

58-
const json_type type = json_object_get_type(obj);
58+
const json_type type = doca_third_party_json_object_get_type(obj);
5959
const auto converter = type_converters.find(type);
6060

6161
if (converter == type_converters.end()) {
@@ -94,7 +94,7 @@ void validate_type(json_object *obj, json_type expected_type, const std::string
9494
throw_xlio_exception("JSON object is null in context: " + context);
9595
}
9696

97-
json_type actual_type = json_object_get_type(obj);
97+
json_type actual_type = doca_third_party_json_object_get_type(obj);
9898
if (actual_type != expected_type) {
9999
throw_xlio_exception("Type mismatch in " + context + ": expected " +
100100
get_type_name(expected_type) + ", got " + get_type_name(actual_type));
@@ -104,24 +104,24 @@ void validate_type(json_object *obj, json_type expected_type, const std::string
104104
// Converter function implementations
105105
static std::experimental::any convert_boolean(json_object *obj)
106106
{
107-
return bool(json_object_get_boolean(obj));
107+
return bool(doca_third_party_json_object_get_boolean(obj));
108108
}
109109

110110
static std::experimental::any convert_integer(json_object *obj)
111111
{
112-
return json_object_get_int64(obj);
112+
return doca_third_party_json_object_get_int64(obj);
113113
}
114114

115115
static std::experimental::any convert_string(json_object *obj)
116116
{
117-
const char *s = json_object_get_string(obj);
117+
const char *s = doca_third_party_json_object_get_string(obj);
118118
return std::string(s ? s : config_strings::misc::EMPTY_STRING);
119119
}
120120

121121
static std::experimental::any convert_object(json_object *obj)
122122
{
123123
std::map<std::string, std::experimental::any> obj_map;
124-
json_object_object_foreach(obj, key, val)
124+
doca_third_party_json_object_object_foreach(obj, key, val)
125125
{
126126
obj_map[key] = to_any_value(val);
127127
}
@@ -131,11 +131,11 @@ static std::experimental::any convert_object(json_object *obj)
131131
static std::experimental::any convert_array(json_object *obj)
132132
{
133133
std::vector<std::experimental::any> array_values;
134-
const int array_length = json_object_array_length(obj);
134+
const int array_length = doca_third_party_json_object_array_length(obj);
135135
array_values.reserve(array_length); // Optimize memory allocation
136136

137137
for (int i = 0; i < array_length; i++) {
138-
json_object *item = json_object_array_get_idx(obj, i);
138+
json_object *item = doca_third_party_json_object_array_get_idx(obj, i);
139139
array_values.push_back(to_any_value(item));
140140
}
141141
return array_values;
@@ -149,13 +149,13 @@ template <> std::vector<int64_t> extract_enum_values<int64_t>(json_object *enum_
149149
return values;
150150
}
151151

152-
const int enum_length = json_object_array_length(enum_field);
152+
const int enum_length = doca_third_party_json_object_array_length(enum_field);
153153
values.reserve(enum_length); // Optimize memory allocation
154154

155155
for (int i = 0; i < enum_length; i++) {
156-
json_object *enum_value = json_object_array_get_idx(enum_field, i);
157-
if (enum_value && json_object_get_type(enum_value) == json_type_int) {
158-
values.push_back(json_object_get_int64(enum_value));
156+
json_object *enum_value = doca_third_party_json_object_array_get_idx(enum_field, i);
157+
if (enum_value && doca_third_party_json_object_get_type(enum_value) == json_type_int) {
158+
values.push_back(doca_third_party_json_object_get_int64(enum_value));
159159
}
160160
}
161161
return values;
@@ -168,13 +168,13 @@ template <> std::vector<std::string> extract_enum_values<std::string>(json_objec
168168
return values;
169169
}
170170

171-
const int enum_length = json_object_array_length(enum_field);
171+
const int enum_length = doca_third_party_json_object_array_length(enum_field);
172172
values.reserve(enum_length); // Optimize memory allocation
173173

174174
for (int i = 0; i < enum_length; i++) {
175-
json_object *enum_value = json_object_array_get_idx(enum_field, i);
176-
if (enum_value && json_object_get_type(enum_value) == json_type_string) {
177-
const char *str_val = json_object_get_string(enum_value);
175+
json_object *enum_value = doca_third_party_json_object_array_get_idx(enum_field, i);
176+
if (enum_value && doca_third_party_json_object_get_type(enum_value) == json_type_string) {
177+
const char *str_val = doca_third_party_json_object_get_string(enum_value);
178178
if (str_val) {
179179
values.emplace_back(str_val);
180180
}

src/core/config/loaders/json_loader.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ std::map<std::string, std::experimental::any> json_loader::load_all() &
2626
return m_data;
2727
}
2828

29-
json_object *raw_obj = json_object_from_file(m_source.c_str());
29+
json_object *raw_obj = doca_third_party_json_object_from_file(m_source.c_str());
3030
if (!raw_obj) {
3131
throw_xlio_exception("Failed to parse JSON file: " + m_source);
3232
}
3333

3434
json_object_handle root_obj(raw_obj);
3535

36-
if (json_object_get_type(root_obj.get()) != json_type_object) {
36+
if (doca_third_party_json_object_get_type(root_obj.get()) != json_type_object) {
3737
throw_xlio_exception("Top-level JSON is not an object: " + m_source);
3838
}
3939

@@ -43,7 +43,7 @@ std::map<std::string, std::experimental::any> json_loader::load_all() &
4343

4444
void json_loader::process_json_object(const std::string &prefix, json_object *obj)
4545
{
46-
json_object_object_foreach(obj, key, value)
46+
doca_third_party_json_object_object_foreach(obj, key, value)
4747
{
4848
std::string key_str(key);
4949
if (key_str.find('.') != std::string::npos) {
@@ -53,7 +53,7 @@ void json_loader::process_json_object(const std::string &prefix, json_object *ob
5353
std::string current_key =
5454
prefix.empty() ? std::move(key_str) : (prefix + config_strings::misc::DOT + key_str);
5555

56-
json_type type = json_object_get_type(value);
56+
json_type type = doca_third_party_json_object_get_type(value);
5757
if (type == json_type_object) {
5858
// Recursively process nested objects
5959
process_json_object(current_key, value);

0 commit comments

Comments
 (0)