Skip to content

Commit 9816197

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 8eeccc7 commit 9816197

File tree

170 files changed

+40342
-5554
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

+40342
-5554
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: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
static void for_each_oneof_option(json_object *one_of_field,
1515
std::function<void(json_object *)> func)
1616
{
17-
int one_of_length = json_object_array_length(one_of_field);
17+
int one_of_length = doca_third_party_json_object_array_length(one_of_field);
1818
for (int i = 0; i < one_of_length; i++) {
19-
json_object *option = json_object_array_get_idx(one_of_field, i);
19+
json_object *option = doca_third_party_json_object_array_get_idx(one_of_field, i);
2020
func(option);
2121
}
2222
}
@@ -63,7 +63,7 @@ bool schema_analyzer::is_applicable(json_object *property_obj)
6363
return false;
6464
}
6565

66-
if (json_object_get_type(property_obj) != json_type_object) {
66+
if (doca_third_party_json_object_get_type(property_obj) != json_type_object) {
6767
return false;
6868
}
6969

@@ -99,15 +99,15 @@ property_type schema_analyzer::determine_property_type()
9999
json_object *type_field =
100100
json_utils::get_field(m_property_obj, config_strings::schema::JSON_TYPE);
101101
std::string json_type_str;
102-
if (json_object_get_type(type_field) == json_type_string) {
103-
json_type_str = json_object_get_string(type_field);
102+
if (doca_third_party_json_object_get_type(type_field) == json_type_string) {
103+
json_type_str = doca_third_party_json_object_get_string(type_field);
104104
}
105105

106106
// Object properties with nested properties
107107
if (json_type_str == config_strings::schema_types::JSON_TYPE_OBJECT) {
108108
json_object *properties_field =
109109
json_utils::get_field(m_property_obj, config_strings::schema::JSON_PROPERTIES);
110-
if (json_object_get_type(properties_field) == json_type_object) {
110+
if (doca_third_party_json_object_get_type(properties_field) == json_type_object) {
111111
return property_type::OBJECT;
112112
}
113113
}
@@ -140,7 +140,7 @@ std::type_index schema_analyzer::determine_value_type()
140140
json_object *type_field =
141141
json_utils::get_field(m_property_obj, config_strings::schema::JSON_TYPE);
142142

143-
std::string type_str = json_object_get_string(type_field);
143+
std::string type_str = doca_third_party_json_object_get_string(type_field);
144144
if (type_str == config_strings::schema_types::JSON_TYPE_BOOLEAN) {
145145
return typeid(bool);
146146
} else if (type_str == config_strings::schema_types::JSON_TYPE_INTEGER) {
@@ -161,7 +161,7 @@ std::experimental::any schema_analyzer::determine_default_value(std::type_index
161161
// Check for oneOf first - default values are nested inside oneOf options
162162
json_object *one_of_field =
163163
json_utils::try_get_field(m_property_obj, config_strings::schema::JSON_ONE_OF);
164-
if (one_of_field && json_object_get_type(one_of_field) == json_type_array) {
164+
if (one_of_field && doca_third_party_json_object_get_type(one_of_field) == json_type_array) {
165165
return extract_oneof_value(one_of_field, type, config_strings::schema::JSON_DEFAULT);
166166
}
167167

@@ -197,17 +197,17 @@ static void extract_constraints_from_json(json_object *obj, constraint_config &c
197197
return;
198198
}
199199
json_object *min_field = json_utils::try_get_field(obj, config_strings::schema::JSON_MINIMUM);
200-
if (min_field && json_object_get_type(min_field) == json_type_int) {
200+
if (min_field && doca_third_party_json_object_get_type(min_field) == json_type_int) {
201201
config.has_minimum = true;
202-
config.minimum_value = json_object_get_int64(min_field);
202+
config.minimum_value = doca_third_party_json_object_get_int64(min_field);
203203
}
204204
json_object *max_field = json_utils::try_get_field(obj, config_strings::schema::JSON_MAXIMUM);
205-
if (max_field && json_object_get_type(max_field) == json_type_int) {
205+
if (max_field && doca_third_party_json_object_get_type(max_field) == json_type_int) {
206206
config.has_maximum = true;
207-
config.maximum_value = json_object_get_int64(max_field);
207+
config.maximum_value = doca_third_party_json_object_get_int64(max_field);
208208
}
209209
json_object *enum_field = json_utils::try_get_field(obj, config_strings::schema::JSON_ENUM);
210-
if (enum_field && json_object_get_type(enum_field) == json_type_array) {
210+
if (enum_field && doca_third_party_json_object_get_type(enum_field) == json_type_array) {
211211
config.has_enum = true;
212212
config.enum_int_values = json_utils::extract_enum_values<int64_t>(enum_field);
213213
}
@@ -227,7 +227,7 @@ constraint_config schema_analyzer::analyze_constraint_config()
227227
for_each_oneof_option(one_of_field, [&](json_object *option) {
228228
json_object *type_field =
229229
json_utils::get_field(option, config_strings::schema::JSON_TYPE);
230-
std::string type_str = json_object_get_string(type_field);
230+
std::string type_str = doca_third_party_json_object_get_string(type_field);
231231
if (type_str == config_strings::schema_types::JSON_TYPE_INTEGER) {
232232
extract_constraints_from_json(option, config);
233233
}
@@ -262,12 +262,12 @@ enum_mapping_config schema_analyzer::analyze_enum_mapping_config()
262262
for_each_oneof_option(one_of_field, [&](json_object *option) {
263263
json_object *type_field = json_utils::get_field(option, config_strings::schema::JSON_TYPE);
264264

265-
std::string type_str = json_object_get_string(type_field);
265+
std::string type_str = doca_third_party_json_object_get_string(type_field);
266266
if (type_str == config_strings::schema_types::JSON_TYPE_INTEGER) {
267267
int_option = option;
268268
json_object *default_field =
269269
json_utils::get_field(option, config_strings::schema::JSON_DEFAULT);
270-
config.default_from_int_option = json_object_get_int64(default_field);
270+
config.default_from_int_option = doca_third_party_json_object_get_int64(default_field);
271271
} else if (type_str == config_strings::schema_types::JSON_TYPE_STRING) {
272272
string_option = option;
273273
}
@@ -310,8 +310,8 @@ bool schema_analyzer::has_memory_size_flag()
310310
return false;
311311
}
312312

313-
return json_object_get_type(memory_size_flag) == json_type_boolean &&
314-
json_object_get_boolean(memory_size_flag);
313+
return doca_third_party_json_object_get_type(memory_size_flag) == json_type_boolean &&
314+
doca_third_party_json_object_get_boolean(memory_size_flag);
315315
}
316316

317317
bool schema_analyzer::has_constraint_fields()
@@ -331,13 +331,13 @@ bool schema_analyzer::has_constraint_fields()
331331
if (has_oneof_field()) {
332332
json_object *one_of_field =
333333
json_utils::get_field(m_property_obj, config_strings::schema::JSON_ONE_OF);
334-
int one_of_length = json_object_array_length(one_of_field);
334+
int one_of_length = doca_third_party_json_object_array_length(one_of_field);
335335
for (int i = 0; i < one_of_length; i++) {
336-
json_object *option = json_object_array_get_idx(one_of_field, i);
336+
json_object *option = doca_third_party_json_object_array_get_idx(one_of_field, i);
337337
json_object *type_field =
338338
json_utils::get_field(option, config_strings::schema::JSON_TYPE);
339339

340-
std::string type_str = json_object_get_string(type_field);
340+
std::string type_str = doca_third_party_json_object_get_string(type_field);
341341

342342
// For integer option, check if it has constraints
343343
if (type_str == config_strings::schema_types::JSON_TYPE_INTEGER) {
@@ -361,7 +361,7 @@ bool schema_analyzer::has_oneof_field()
361361
json_object *one_of_field =
362362
json_utils::try_get_field(m_property_obj, config_strings::schema::JSON_ONE_OF);
363363

364-
if (one_of_field && json_object_get_type(one_of_field) != json_type_array) {
364+
if (one_of_field && doca_third_party_json_object_get_type(one_of_field) != json_type_array) {
365365
throw_xlio_exception("OneOf field must be an array for: " + m_path);
366366
}
367367

@@ -372,9 +372,9 @@ std::experimental::any schema_analyzer::extract_oneof_value(json_object *one_of_
372372
std::type_index type,
373373
const std::string &key)
374374
{
375-
int one_of_length = json_object_array_length(one_of_field);
375+
int one_of_length = doca_third_party_json_object_array_length(one_of_field);
376376
for (int i = 0; i < one_of_length; i++) {
377-
json_object *option = json_object_array_get_idx(one_of_field, i);
377+
json_object *option = doca_third_party_json_object_array_get_idx(one_of_field, i);
378378
json_object *key_field = json_utils::try_get_field(option, key.c_str());
379379

380380
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,11 +43,11 @@ 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 current_key = prefix.empty() ? key : (prefix + config_strings::misc::DOT + key);
4949

50-
json_type type = json_object_get_type(value);
50+
json_type type = doca_third_party_json_object_get_type(value);
5151
if (type == json_type_object) {
5252
// Recursively process nested objects
5353
process_json_object(current_key, value);

0 commit comments

Comments
 (0)