From 88dd316f757a0ef7df3af1965acd0e87a788d541 Mon Sep 17 00:00:00 2001 From: Tomer Cabouly Date: Tue, 16 Sep 2025 11:34:30 +0000 Subject: [PATCH] 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 --- .../json_descriptor_provider.cpp | 21 +- .../descriptor_providers/schema_analyzer.cpp | 46 +- src/core/config/json_object_handle.cpp | 2 +- src/core/config/json_utils.cpp | 34 +- src/core/config/loaders/json_loader.cpp | 8 +- tests/unit_tests/config/schema_analyzer.cpp | 159 +- third_party/json-c/.clang-format | 55 + third_party/json-c/.editorconfig | 2 +- .../.github/ISSUE_TEMPLATE/bug_report.md | 23 + third_party/json-c/.gitignore | 111 - third_party/json-c/.travis.yml | 179 +- third_party/json-c/AUTHORS | 74 +- third_party/json-c/CMakeLists.txt | 669 +- third_party/json-c/ChangeLog | 262 +- third_party/json-c/INSTALL | 1 - third_party/json-c/Makefile.am | 88 +- third_party/json-c/README.html | 9 +- third_party/json-c/README.md | 340 +- third_party/json-c/RELEASE_CHECKLIST.txt | 213 +- third_party/json-c/STYLE.txt | 62 +- third_party/json-c/abi-check.sh | 42 + third_party/json-c/appveyor.yml | 164 +- third_party/json-c/arraylist.c | 244 +- third_party/json-c/arraylist.h | 86 +- .../json-c/autoconf-archive/m4/libtool.m4 | 8394 ++++++++++++ .../json-c/autoconf-archive/m4/ltoptions.m4 | 437 + .../json-c/autoconf-archive/m4/ltsugar.m4 | 124 + .../json-c/autoconf-archive/m4/ltversion.m4 | 23 + .../json-c/autoconf-archive/m4/lt~obsolete.m4 | 99 + third_party/json-c/autogen.sh | 13 - third_party/json-c/bench/README.bench.md | 80 + third_party/json-c/bench/jc-bench.sh | 284 + third_party/json-c/bits.h | 36 - third_party/json-c/cmake-configure | 100 + third_party/json-c/cmake/Config.cmake.in | 4 + third_party/json-c/cmake/json_config.h.in | 5 + third_party/json-c/compile | 348 + third_party/json-c/config.guess | 1754 +++ .../json-c/{config.h.win32 => config.h} | 416 +- third_party/json-c/config.sub | 1890 +++ third_party/json-c/config/meson.build | 136 + third_party/json-c/configure.ac | 165 +- third_party/json-c/debug.c | 85 +- third_party/json-c/debug.h | 75 +- third_party/json-c/depcomp | 791 ++ third_party/json-c/doc/CMakeLists.txt | 16 + .../json-c/{Doxyfile => doc/Doxyfile.in} | 98 +- third_party/json-c/doc/fixup_markdown.sh | 6 + third_party/json-c/fuzz/build.sh | 38 +- .../json-c/fuzz/tokener_parse_ex_fuzzer.cc | 40 +- third_party/json-c/install-sh | 541 + third_party/json-c/issues_closed_for_0.13.md | 507 +- third_party/json-c/issues_closed_for_0.14.md | 202 + third_party/json-c/issues_closed_for_0.15.md | 85 + third_party/json-c/issues_closed_for_0.16.md | 107 + third_party/json-c/issues_closed_for_0.17.md | 88 + third_party/json-c/json-c-uninstalled.pc | 10 + third_party/json-c/json-c-uninstalled.pc.in | 11 +- third_party/json-c/json-c.pc | 10 + third_party/json-c/json-c.pc.in | 8 +- third_party/json-c/json-c.sym | 196 + third_party/json-c/json-c/json.h | 58 + third_party/json-c/json.h | 34 +- third_party/json-c/json.h.cmakein | 39 + third_party/json-c/json_c_version.c | 21 +- third_party/json-c/json_c_version.h | 46 +- third_party/json-c/json_config.h | 160 +- third_party/json-c/json_config.h.in | 160 +- third_party/json-c/json_inttypes.h | 14 + third_party/json-c/json_object.c | 1692 ++- third_party/json-c/json_object.h | 569 +- third_party/json-c/json_object_iterator.c | 133 +- third_party/json-c/json_object_iterator.h | 65 +- third_party/json-c/json_object_private.h | 115 +- third_party/json-c/json_patch.c | 377 + third_party/json-c/json_patch.h | 94 + third_party/json-c/json_pointer.c | 285 +- third_party/json-c/json_pointer.h | 49 +- third_party/json-c/json_pointer_private.h | 58 + third_party/json-c/json_tokener.c | 2063 +-- third_party/json-c/json_tokener.h | 283 +- third_party/json-c/json_types.h | 78 + third_party/json-c/json_util.c | 264 +- third_party/json-c/json_util.h | 71 +- third_party/json-c/json_visit.c | 86 +- third_party/json-c/json_visit.h | 42 +- third_party/json-c/libjson.c | 8 +- third_party/json-c/linkhash.c | 662 +- third_party/json-c/linkhash.h | 215 +- third_party/json-c/ltmain.sh | 11251 ++++++++++++++++ third_party/json-c/math_compat.h | 15 +- third_party/json-c/meson.build | 93 + third_party/json-c/missing | 215 + third_party/json-c/printbuf.c | 188 +- third_party/json-c/printbuf.h | 84 +- third_party/json-c/random_seed.c | 336 +- third_party/json-c/random_seed.h | 16 +- third_party/json-c/snprintf_compat.h | 4 +- third_party/json-c/stamp-h2 | 1 + third_party/json-c/strdup_compat.h | 6 +- third_party/json-c/strerror_override.c | 42 +- third_party/json-c/strerror_override.h | 25 +- .../json-c/strerror_override_private.h | 12 - third_party/json-c/tests/CMakeLists.txt | 64 + third_party/json-c/tests/Makefile.am | 64 - .../json-c/tests/json_patch_spec_tests.json | 233 + .../json-c/tests/json_patch_tests.json | 540 + third_party/json-c/tests/parse_flags.c | 19 +- third_party/json-c/tests/test-defs.sh | 7 +- third_party/json-c/tests/test1.c | 400 +- third_party/json-c/tests/test1.expected | 17 +- third_party/json-c/tests/test1.test | 16 + .../tests/test1Formatted_plain.expected | 17 +- .../tests/test1Formatted_pretty.expected | 19 +- .../tests/test1Formatted_spaced.expected | 17 +- .../test1Formatted_spaced_pretty.expected | 103 + ...ormatted_spaced_pretty_pretty_tab.expected | 103 + third_party/json-c/tests/test2.c | 40 +- third_party/json-c/tests/test2.test | 16 + .../test2Formatted_spaced_pretty.expected | 23 + ...ormatted_spaced_pretty_pretty_tab.expected | 23 + third_party/json-c/tests/test4.c | 74 +- third_party/json-c/tests/test4.expected | 1 + .../json-c/tests/testReplaceExisting.c | 50 +- third_party/json-c/tests/test_basic.test | 2 + third_party/json-c/tests/test_cast.c | 104 +- third_party/json-c/tests/test_cast.expected | 64 +- third_party/json-c/tests/test_charcase.c | 48 +- third_party/json-c/tests/test_compare.c | 268 +- .../json-c/tests/test_compare.expected | 23 +- third_party/json-c/tests/test_deep_copy.c | 276 +- .../json-c/tests/test_deep_copy.expected | 8 +- .../json-c/tests/test_double_serializer.c | 123 +- .../tests/test_double_serializer.expected | 6 + third_party/json-c/tests/test_float.c | 60 +- third_party/json-c/tests/test_float.expected | 1 + third_party/json-c/tests/test_int_add.c | 106 +- .../json-c/tests/test_int_add.expected | 3 + third_party/json-c/tests/test_int_get.c | 84 + .../json-c/tests/test_int_get.expected | 5 + third_party/json-c/tests/test_int_get.test | 1 + third_party/json-c/tests/test_json_patch.c | 158 + .../json-c/tests/test_json_patch.expected | 158 + third_party/json-c/tests/test_json_patch.test | 17 + third_party/json-c/tests/test_json_pointer.c | 343 +- .../json-c/tests/test_json_pointer.expected | 3 + third_party/json-c/tests/test_locale.c | 47 +- third_party/json-c/tests/test_null.c | 48 +- .../json-c/tests/test_object_iterator.c | 63 + .../tests/test_object_iterator.expected | 14 + .../json-c/tests/test_object_iterator.test | 1 + third_party/json-c/tests/test_parse.c | 724 +- third_party/json-c/tests/test_parse.expected | 164 +- third_party/json-c/tests/test_parse_int64.c | 107 +- .../json-c/tests/test_parse_int64.expected | 28 + third_party/json-c/tests/test_printbuf.c | 133 +- .../json-c/tests/test_printbuf.expected | 1 + .../json-c/tests/test_set_serializer.c | 81 +- .../json-c/tests/test_set_serializer.expected | 2 + third_party/json-c/tests/test_set_value.c | 155 +- .../json-c/tests/test_set_value.expected | 3 + third_party/json-c/tests/test_strerror.c | 13 + .../json-c/tests/test_strerror.expected | 2 + third_party/json-c/tests/test_strerror.test | 1 + third_party/json-c/tests/test_util_file.c | 253 +- .../json-c/tests/test_util_file.expected | 9 +- third_party/json-c/tests/test_visit.c | 124 +- third_party/json-c/tests/test_visit.expected | 34 + third_party/json-c/tests/valid_nested.json | 1 + third_party/json-c/vasprintf_compat.h | 41 +- 170 files changed, 40341 insertions(+), 5560 deletions(-) create mode 100644 third_party/json-c/.clang-format create mode 100644 third_party/json-c/.github/ISSUE_TEMPLATE/bug_report.md delete mode 100644 third_party/json-c/.gitignore mode change 100755 => 100644 third_party/json-c/STYLE.txt create mode 100644 third_party/json-c/abi-check.sh create mode 100644 third_party/json-c/autoconf-archive/m4/libtool.m4 create mode 100644 third_party/json-c/autoconf-archive/m4/ltoptions.m4 create mode 100644 third_party/json-c/autoconf-archive/m4/ltsugar.m4 create mode 100644 third_party/json-c/autoconf-archive/m4/ltversion.m4 create mode 100644 third_party/json-c/autoconf-archive/m4/lt~obsolete.m4 delete mode 100755 third_party/json-c/autogen.sh create mode 100644 third_party/json-c/bench/README.bench.md create mode 100755 third_party/json-c/bench/jc-bench.sh delete mode 100644 third_party/json-c/bits.h create mode 100755 third_party/json-c/cmake-configure create mode 100644 third_party/json-c/cmake/Config.cmake.in create mode 100644 third_party/json-c/cmake/json_config.h.in create mode 100755 third_party/json-c/compile create mode 100755 third_party/json-c/config.guess rename third_party/json-c/{config.h.win32 => config.h} (63%) create mode 100755 third_party/json-c/config.sub create mode 100644 third_party/json-c/config/meson.build create mode 100755 third_party/json-c/depcomp create mode 100644 third_party/json-c/doc/CMakeLists.txt rename third_party/json-c/{Doxyfile => doc/Doxyfile.in} (97%) create mode 100755 third_party/json-c/doc/fixup_markdown.sh create mode 100755 third_party/json-c/install-sh create mode 100644 third_party/json-c/issues_closed_for_0.14.md create mode 100644 third_party/json-c/issues_closed_for_0.15.md create mode 100644 third_party/json-c/issues_closed_for_0.16.md create mode 100644 third_party/json-c/issues_closed_for_0.17.md create mode 100644 third_party/json-c/json-c-uninstalled.pc create mode 100644 third_party/json-c/json-c.pc create mode 100644 third_party/json-c/json-c.sym create mode 100644 third_party/json-c/json-c/json.h create mode 100644 third_party/json-c/json.h.cmakein create mode 100644 third_party/json-c/json_patch.c create mode 100644 third_party/json-c/json_patch.h create mode 100644 third_party/json-c/json_pointer_private.h create mode 100644 third_party/json-c/json_types.h create mode 100755 third_party/json-c/ltmain.sh create mode 100644 third_party/json-c/meson.build create mode 100755 third_party/json-c/missing create mode 100644 third_party/json-c/stamp-h2 delete mode 100644 third_party/json-c/strerror_override_private.h create mode 100644 third_party/json-c/tests/CMakeLists.txt delete mode 100644 third_party/json-c/tests/Makefile.am create mode 100644 third_party/json-c/tests/json_patch_spec_tests.json create mode 100644 third_party/json-c/tests/json_patch_tests.json create mode 100644 third_party/json-c/tests/test1Formatted_spaced_pretty.expected create mode 100644 third_party/json-c/tests/test1Formatted_spaced_pretty_pretty_tab.expected create mode 100644 third_party/json-c/tests/test2Formatted_spaced_pretty.expected create mode 100644 third_party/json-c/tests/test2Formatted_spaced_pretty_pretty_tab.expected create mode 100644 third_party/json-c/tests/test_int_get.c create mode 100644 third_party/json-c/tests/test_int_get.expected create mode 120000 third_party/json-c/tests/test_int_get.test create mode 100644 third_party/json-c/tests/test_json_patch.c create mode 100644 third_party/json-c/tests/test_json_patch.expected create mode 100755 third_party/json-c/tests/test_json_patch.test create mode 100644 third_party/json-c/tests/test_object_iterator.c create mode 100644 third_party/json-c/tests/test_object_iterator.expected create mode 120000 third_party/json-c/tests/test_object_iterator.test create mode 100644 third_party/json-c/tests/test_strerror.c create mode 100644 third_party/json-c/tests/test_strerror.expected create mode 120000 third_party/json-c/tests/test_strerror.test create mode 100644 third_party/json-c/tests/valid_nested.json diff --git a/src/core/config/descriptor_providers/json_descriptor_provider.cpp b/src/core/config/descriptor_providers/json_descriptor_provider.cpp index 02e978999..51d170353 100644 --- a/src/core/config/descriptor_providers/json_descriptor_provider.cpp +++ b/src/core/config/descriptor_providers/json_descriptor_provider.cpp @@ -37,7 +37,7 @@ json_descriptor_provider::json_descriptor_provider(const char *json_string) config_descriptor json_descriptor_provider::load_descriptors() { - json_object_handle schema_handle(json_tokener_parse(m_json_string)); + json_object_handle schema_handle(doca_third_party_json_tokener_parse(m_json_string)); if (!schema_handle.get()) { throw_xlio_exception("Failed to parse JSON schema."); } @@ -49,7 +49,7 @@ config_descriptor json_descriptor_provider::load_descriptors() json_object *properties = json_utils::get_field(schema_handle.get(), config_strings::schema::JSON_PROPERTIES); - json_object_object_foreach(properties, key, val) + doca_third_party_json_object_object_foreach(properties, key, val) { process_schema_property(val, key, result_desc); } @@ -59,22 +59,22 @@ config_descriptor json_descriptor_provider::load_descriptors() void json_descriptor_provider::validate_schema(json_object *schema) { - if (json_object_get_type(schema) != json_type_object) { + if (doca_third_party_json_object_get_type(schema) != json_type_object) { throw_xlio_exception("Schema root must be an object."); } json_object *properties = json_utils::get_field(schema, config_strings::schema::JSON_PROPERTIES); - json_object_object_foreach(properties, key, val) + doca_third_party_json_object_object_foreach(properties, key, val) { - if (json_object_get_type(val) != json_type_object) { + if (doca_third_party_json_object_get_type(val) != json_type_object) { throw_xlio_exception("Property '" + std::string(key) + "' must be an object."); } } json_object *type_field = json_utils::get_field(schema, config_strings::schema::JSON_TYPE); - if (std::string(json_object_get_string(type_field)) != + if (std::string(doca_third_party_json_object_get_string(type_field)) != config_strings::schema_types::JSON_TYPE_OBJECT) { throw_xlio_exception("Schema root must have type 'object'."); } @@ -84,7 +84,7 @@ void json_descriptor_provider::validate_terminal_property(json_object *property_ const std::string ¤t_path) { // Basic validation for terminal properties - if (!property_obj || json_object_get_type(property_obj) != json_type_object) { + if (!property_obj || doca_third_party_json_object_get_type(property_obj) != json_type_object) { throw_xlio_exception("Invalid property object for: " + current_path); } @@ -92,7 +92,7 @@ void json_descriptor_provider::validate_terminal_property(json_object *property_ json_object *description_field = json_utils::get_field(property_obj, config_strings::schema::JSON_DESCRIPTION); - if (json_object_get_type(description_field) != json_type_string) { + if (doca_third_party_json_object_get_type(description_field) != json_type_string) { throw_xlio_exception("Invalid 'description' field type for terminal property: " + current_path); } @@ -119,8 +119,9 @@ void json_descriptor_provider::process_schema_property(json_object *property_obj if (analysis.json_property_type == property_type::OBJECT) { json_object *properties = json_utils::try_get_field(property_obj, config_strings::schema::JSON_PROPERTIES); - if (properties && json_object_get_type(properties) == json_type_object) { - json_object_object_foreach(properties, key, val) + if (properties && + doca_third_party_json_object_get_type(properties) == json_type_object) { + doca_third_party_json_object_object_foreach(properties, key, val) { process_schema_property(val, key, desc, current_path); } diff --git a/src/core/config/descriptor_providers/schema_analyzer.cpp b/src/core/config/descriptor_providers/schema_analyzer.cpp index a926e0f17..d048349de 100644 --- a/src/core/config/descriptor_providers/schema_analyzer.cpp +++ b/src/core/config/descriptor_providers/schema_analyzer.cpp @@ -16,9 +16,9 @@ static void for_each_oneof_option(json_object *one_of_field, std::function func) { - int one_of_length = json_object_array_length(one_of_field); + int one_of_length = doca_third_party_json_object_array_length(one_of_field); for (int i = 0; i < one_of_length; i++) { - json_object *option = json_object_array_get_idx(one_of_field, i); + json_object *option = doca_third_party_json_object_array_get_idx(one_of_field, i); func(option); } } @@ -47,7 +47,7 @@ bool schema_analyzer::is_applicable(json_object *property_obj) return false; } - if (json_object_get_type(property_obj) != json_type_object) { + if (doca_third_party_json_object_get_type(property_obj) != json_type_object) { return false; } @@ -83,15 +83,15 @@ property_type schema_analyzer::determine_property_type() json_object *type_field = json_utils::get_field(m_property_obj, config_strings::schema::JSON_TYPE); std::string json_type_str; - if (json_object_get_type(type_field) == json_type_string) { - json_type_str = json_object_get_string(type_field); + if (doca_third_party_json_object_get_type(type_field) == json_type_string) { + json_type_str = doca_third_party_json_object_get_string(type_field); } // Object properties with nested properties if (json_type_str == config_strings::schema_types::JSON_TYPE_OBJECT) { json_object *properties_field = json_utils::get_field(m_property_obj, config_strings::schema::JSON_PROPERTIES); - if (json_object_get_type(properties_field) == json_type_object) { + if (doca_third_party_json_object_get_type(properties_field) == json_type_object) { return property_type::OBJECT; } } @@ -124,7 +124,7 @@ std::type_index schema_analyzer::determine_value_type() json_object *type_field = json_utils::get_field(m_property_obj, config_strings::schema::JSON_TYPE); - std::string type_str = json_object_get_string(type_field); + std::string type_str = doca_third_party_json_object_get_string(type_field); if (type_str == config_strings::schema_types::JSON_TYPE_BOOLEAN) { return typeid(bool); } else if (type_str == config_strings::schema_types::JSON_TYPE_INTEGER) { @@ -151,7 +151,7 @@ std::experimental::optional schema_analyzer::determine_d // Check for oneOf first - default values are nested inside oneOf options json_object *one_of_field = json_utils::try_get_field(m_property_obj, config_strings::schema::JSON_ONE_OF); - if (one_of_field && json_object_get_type(one_of_field) == json_type_array) { + if (one_of_field && doca_third_party_json_object_get_type(one_of_field) == json_type_array) { return extract_oneof_value(one_of_field, type, config_strings::schema::JSON_DEFAULT); } @@ -205,17 +205,17 @@ static void extract_constraints_from_json(json_object *obj, constraint_config &c return; } json_object *min_field = json_utils::try_get_field(obj, config_strings::schema::JSON_MINIMUM); - if (min_field && json_object_get_type(min_field) == json_type_int) { + if (min_field && doca_third_party_json_object_get_type(min_field) == json_type_int) { config.has_minimum = true; - config.minimum_value = json_object_get_int64(min_field); + config.minimum_value = doca_third_party_json_object_get_int64(min_field); } json_object *max_field = json_utils::try_get_field(obj, config_strings::schema::JSON_MAXIMUM); - if (max_field && json_object_get_type(max_field) == json_type_int) { + if (max_field && doca_third_party_json_object_get_type(max_field) == json_type_int) { config.has_maximum = true; - config.maximum_value = json_object_get_int64(max_field); + config.maximum_value = doca_third_party_json_object_get_int64(max_field); } json_object *enum_field = json_utils::try_get_field(obj, config_strings::schema::JSON_ENUM); - if (enum_field && json_object_get_type(enum_field) == json_type_array) { + if (enum_field && doca_third_party_json_object_get_type(enum_field) == json_type_array) { config.has_enum = true; config.enum_int_values = json_utils::extract_enum_values(enum_field); } @@ -238,7 +238,7 @@ constraint_config schema_analyzer::analyze_constraint_config() for_each_oneof_option(one_of_field, [&](json_object *option) { json_object *type_field = json_utils::get_field(option, config_strings::schema::JSON_TYPE); - std::string type_str = json_object_get_string(type_field); + std::string type_str = doca_third_party_json_object_get_string(type_field); if (type_str == config_strings::schema_types::JSON_TYPE_INTEGER) { extract_constraints_from_json(option, config); } @@ -269,7 +269,7 @@ enum_mapping_config_t schema_analyzer::analyze_enum_mapping_config() for_each_oneof_option(one_of_field, [&](json_object *option) { json_object *type_field = json_utils::get_field(option, config_strings::schema::JSON_TYPE); - std::string type_str = json_object_get_string(type_field); + std::string type_str = doca_third_party_json_object_get_string(type_field); if (type_str == config_strings::schema_types::JSON_TYPE_INTEGER) { int_option = option; } else if (type_str == config_strings::schema_types::JSON_TYPE_STRING) { @@ -315,8 +315,8 @@ bool schema_analyzer::has_memory_size_flag() return false; } - return json_object_get_type(memory_size_flag) == json_type_boolean && - json_object_get_boolean(memory_size_flag); + return doca_third_party_json_object_get_type(memory_size_flag) == json_type_boolean && + doca_third_party_json_object_get_boolean(memory_size_flag); } bool schema_analyzer::has_power_of_2_or_zero_flag() @@ -348,13 +348,13 @@ bool schema_analyzer::has_constraint_fields() if (has_oneof_field()) { json_object *one_of_field = json_utils::get_field(m_property_obj, config_strings::schema::JSON_ONE_OF); - int one_of_length = json_object_array_length(one_of_field); + int one_of_length = doca_third_party_json_object_array_length(one_of_field); for (int i = 0; i < one_of_length; i++) { - json_object *option = json_object_array_get_idx(one_of_field, i); + json_object *option = doca_third_party_json_object_array_get_idx(one_of_field, i); json_object *type_field = json_utils::get_field(option, config_strings::schema::JSON_TYPE); - std::string type_str = json_object_get_string(type_field); + std::string type_str = doca_third_party_json_object_get_string(type_field); // For integer option, check if it has constraints if (type_str == config_strings::schema_types::JSON_TYPE_INTEGER) { @@ -378,7 +378,7 @@ bool schema_analyzer::has_oneof_field() json_object *one_of_field = json_utils::try_get_field(m_property_obj, config_strings::schema::JSON_ONE_OF); - if (one_of_field && json_object_get_type(one_of_field) != json_type_array) { + if (one_of_field && doca_third_party_json_object_get_type(one_of_field) != json_type_array) { throw_xlio_exception("OneOf field must be an array for: " + m_path); } @@ -389,9 +389,9 @@ std::experimental::any schema_analyzer::extract_oneof_value(json_object *one_of_ std::type_index type, const std::string &key) { - int one_of_length = json_object_array_length(one_of_field); + int one_of_length = doca_third_party_json_object_array_length(one_of_field); for (int i = 0; i < one_of_length; i++) { - json_object *option = json_object_array_get_idx(one_of_field, i); + json_object *option = doca_third_party_json_object_array_get_idx(one_of_field, i); json_object *key_field = json_utils::try_get_field(option, key.c_str()); if (key_field && std::type_index(json_utils::to_any_value(key_field).type()) == type) { diff --git a/src/core/config/json_object_handle.cpp b/src/core/config/json_object_handle.cpp index f4fb7c974..640b8e7f8 100644 --- a/src/core/config/json_object_handle.cpp +++ b/src/core/config/json_object_handle.cpp @@ -14,7 +14,7 @@ json_object_handle::json_object_handle(json_object *obj) json_object_handle::~json_object_handle() { if (m_obj) { - json_object_put(m_obj); + doca_third_party_json_object_put(m_obj); } } diff --git a/src/core/config/json_utils.cpp b/src/core/config/json_utils.cpp index 8d7e4a874..c76d9daab 100644 --- a/src/core/config/json_utils.cpp +++ b/src/core/config/json_utils.cpp @@ -34,7 +34,7 @@ json_object *try_get_field(json_object *obj, const char *field_name) } json_object *field = nullptr; - if (json_object_object_get_ex(obj, field_name, &field)) { + if (doca_third_party_json_object_object_get_ex(obj, field_name, &field)) { return field; } @@ -55,7 +55,7 @@ std::experimental::any to_any_value(json_object *obj) {json_type_object, convert_object}, {json_type_array, convert_array}}; - const json_type type = json_object_get_type(obj); + const json_type type = doca_third_party_json_object_get_type(obj); const auto converter = type_converters.find(type); if (converter == type_converters.end()) { @@ -94,7 +94,7 @@ void validate_type(json_object *obj, json_type expected_type, const std::string throw_xlio_exception("JSON object is null in context: " + context); } - json_type actual_type = json_object_get_type(obj); + json_type actual_type = doca_third_party_json_object_get_type(obj); if (actual_type != expected_type) { throw_xlio_exception("Type mismatch in " + context + ": expected " + 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 // Converter function implementations static std::experimental::any convert_boolean(json_object *obj) { - return bool(json_object_get_boolean(obj)); + return bool(doca_third_party_json_object_get_boolean(obj)); } static std::experimental::any convert_integer(json_object *obj) { - return json_object_get_int64(obj); + return doca_third_party_json_object_get_int64(obj); } static std::experimental::any convert_string(json_object *obj) { - const char *s = json_object_get_string(obj); + const char *s = doca_third_party_json_object_get_string(obj); return std::string(s ? s : config_strings::misc::EMPTY_STRING); } static std::experimental::any convert_object(json_object *obj) { std::map obj_map; - json_object_object_foreach(obj, key, val) + doca_third_party_json_object_object_foreach(obj, key, val) { obj_map[key] = to_any_value(val); } @@ -131,11 +131,11 @@ static std::experimental::any convert_object(json_object *obj) static std::experimental::any convert_array(json_object *obj) { std::vector array_values; - const int array_length = json_object_array_length(obj); + const int array_length = doca_third_party_json_object_array_length(obj); array_values.reserve(array_length); // Optimize memory allocation for (int i = 0; i < array_length; i++) { - json_object *item = json_object_array_get_idx(obj, i); + json_object *item = doca_third_party_json_object_array_get_idx(obj, i); array_values.push_back(to_any_value(item)); } return array_values; @@ -149,13 +149,13 @@ template <> std::vector extract_enum_values(json_object *enum_ return values; } - const int enum_length = json_object_array_length(enum_field); + const int enum_length = doca_third_party_json_object_array_length(enum_field); values.reserve(enum_length); // Optimize memory allocation for (int i = 0; i < enum_length; i++) { - json_object *enum_value = json_object_array_get_idx(enum_field, i); - if (enum_value && json_object_get_type(enum_value) == json_type_int) { - values.push_back(json_object_get_int64(enum_value)); + json_object *enum_value = doca_third_party_json_object_array_get_idx(enum_field, i); + if (enum_value && doca_third_party_json_object_get_type(enum_value) == json_type_int) { + values.push_back(doca_third_party_json_object_get_int64(enum_value)); } } return values; @@ -168,13 +168,13 @@ template <> std::vector extract_enum_values(json_objec return values; } - const int enum_length = json_object_array_length(enum_field); + const int enum_length = doca_third_party_json_object_array_length(enum_field); values.reserve(enum_length); // Optimize memory allocation for (int i = 0; i < enum_length; i++) { - json_object *enum_value = json_object_array_get_idx(enum_field, i); - if (enum_value && json_object_get_type(enum_value) == json_type_string) { - const char *str_val = json_object_get_string(enum_value); + json_object *enum_value = doca_third_party_json_object_array_get_idx(enum_field, i); + if (enum_value && doca_third_party_json_object_get_type(enum_value) == json_type_string) { + const char *str_val = doca_third_party_json_object_get_string(enum_value); if (str_val) { values.emplace_back(str_val); } diff --git a/src/core/config/loaders/json_loader.cpp b/src/core/config/loaders/json_loader.cpp index 93e62cc55..f937363a8 100644 --- a/src/core/config/loaders/json_loader.cpp +++ b/src/core/config/loaders/json_loader.cpp @@ -26,14 +26,14 @@ std::map json_loader::load_all() & return m_data; } - json_object *raw_obj = json_object_from_file(m_source.c_str()); + json_object *raw_obj = doca_third_party_json_object_from_file(m_source.c_str()); if (!raw_obj) { throw_xlio_exception("Failed to parse JSON file: " + m_source); } json_object_handle root_obj(raw_obj); - if (json_object_get_type(root_obj.get()) != json_type_object) { + if (doca_third_party_json_object_get_type(root_obj.get()) != json_type_object) { throw_xlio_exception("Top-level JSON is not an object: " + m_source); } @@ -43,7 +43,7 @@ std::map json_loader::load_all() & void json_loader::process_json_object(const std::string &prefix, json_object *obj) { - json_object_object_foreach(obj, key, value) + doca_third_party_json_object_object_foreach(obj, key, value) { std::string key_str(key); if (key_str.find('.') != std::string::npos) { @@ -53,7 +53,7 @@ void json_loader::process_json_object(const std::string &prefix, json_object *ob std::string current_key = prefix.empty() ? std::move(key_str) : (prefix + config_strings::misc::DOT + key_str); - json_type type = json_object_get_type(value); + json_type type = doca_third_party_json_object_get_type(value); if (type == json_type_object) { // Recursively process nested objects process_json_object(current_key, value); diff --git a/tests/unit_tests/config/schema_analyzer.cpp b/tests/unit_tests/config/schema_analyzer.cpp index 05075e559..4817b77b9 100644 --- a/tests/unit_tests/config/schema_analyzer.cpp +++ b/tests/unit_tests/config/schema_analyzer.cpp @@ -16,82 +16,75 @@ class schema_analyzer_test : public ::testing::Test { void SetUp() override { // Create test JSON objects for different property types - simple_property = json_object_new_object(); - json_object_object_add(simple_property, "type", json_object_new_string("integer")); - json_object_object_add(simple_property, "title", json_object_new_string("Test Property")); - json_object_object_add(simple_property, "description", - json_object_new_string("A test property")); - json_object_object_add(simple_property, "default", json_object_new_int(42)); - - extended_property = json_object_new_object(); - json_object_object_add(extended_property, "type", json_object_new_string("string")); - json_object_object_add(extended_property, "title", json_object_new_string("Memory Size")); - json_object_object_add(extended_property, "description", - json_object_new_string("A memory size property")); - json_object_object_add(extended_property, "x-memory-size", json_object_new_boolean(true)); - json_object *extended_one_of_array = json_object_new_array(); - json_object *extended_string_option = json_object_new_object(); - json_object_object_add(extended_string_option, "type", json_object_new_string("string")); - json_object_object_add(extended_string_option, "pattern", - json_object_new_string("^[0-9]+[KMGkmg]?[B]?$")); - json_object_object_add(extended_string_option, "default", json_object_new_string("32MB")); - json_object *extended_integer_option = json_object_new_object(); - json_object_object_add(extended_integer_option, "type", json_object_new_string("integer")); - json_object_object_add(extended_integer_option, "default", - json_object_new_int(32 * 1024 * 1024)); - json_object_array_add(extended_one_of_array, extended_string_option); - json_object_array_add(extended_one_of_array, extended_integer_option); - json_object_object_add(extended_property, "oneOf", extended_one_of_array); - - one_of_property = json_object_new_object(); - json_object *one_of_array = json_object_new_array(); - json_object *int_option = json_object_new_object(); - json_object_object_add(int_option, "type", json_object_new_string("integer")); - json_object_object_add(int_option, "default", json_object_new_int(1)); - json_object_array_add(one_of_array, int_option); - json_object *string_option = json_object_new_object(); - json_object_object_add(string_option, "type", json_object_new_string("string")); - json_object_object_add(string_option, "default", json_object_new_string("default_val")); - json_object_array_add(one_of_array, string_option); - json_object_object_add(one_of_property, "oneOf", one_of_array); - json_object_object_add(one_of_property, "title", json_object_new_string("OneOf Property")); - json_object_object_add(one_of_property, "description", - json_object_new_string("A oneOf property")); - - object_property = json_object_new_object(); - json_object_object_add(object_property, "type", json_object_new_string("object")); - json_object *properties = json_object_new_object(); + simple_property = doca_third_party_json_object_new_object(); + doca_third_party_json_object_object_add(simple_property, "type", doca_third_party_json_object_new_string("integer")); + doca_third_party_json_object_object_add(simple_property, "title", doca_third_party_json_object_new_string("Test Property")); + doca_third_party_json_object_object_add(simple_property, "description", + doca_third_party_json_object_new_string("A test property")); + doca_third_party_json_object_object_add(simple_property, "default", doca_third_party_json_object_new_int(42)); + + extended_property = doca_third_party_json_object_new_object(); + doca_third_party_json_object_object_add(extended_property, "type", doca_third_party_json_object_new_string("string")); + doca_third_party_json_object_object_add(extended_property, "title", doca_third_party_json_object_new_string("Memory Size")); + doca_third_party_json_object_object_add(extended_property, "description", + doca_third_party_json_object_new_string("A memory size property")); + doca_third_party_json_object_object_add(extended_property, "x-memory-size", doca_third_party_json_object_new_boolean(true)); + json_object *extended_one_of_array = doca_third_party_json_object_new_array(); + json_object *extended_string_option = doca_third_party_json_object_new_object(); + doca_third_party_json_object_object_add(extended_string_option, "type", doca_third_party_json_object_new_string("string")); + doca_third_party_json_object_object_add(extended_string_option, "pattern", + doca_third_party_json_object_new_string("^[0-9]+[KMGkmg]?[B]?$")); + doca_third_party_json_object_object_add(extended_string_option, "default", doca_third_party_json_object_new_string("32MB")); + json_object *extended_integer_option = doca_third_party_json_object_new_object(); + doca_third_party_json_object_object_add(extended_integer_option, "type", doca_third_party_json_object_new_string("integer")); + doca_third_party_json_object_object_add(extended_integer_option, "default", + doca_third_party_json_object_new_int(32 * 1024 * 1024)); + doca_third_party_json_object_array_add(extended_one_of_array, extended_string_option); + doca_third_party_json_object_array_add(extended_one_of_array, extended_integer_option); + doca_third_party_json_object_object_add(extended_property, "oneOf", extended_one_of_array); + + one_of_property = doca_third_party_json_object_new_object(); + json_object *one_of_array = doca_third_party_json_object_new_array(); + json_object *int_option = doca_third_party_json_object_new_object(); + doca_third_party_json_object_object_add(int_option, "type", doca_third_party_json_object_new_string("integer")); + doca_third_party_json_object_object_add(int_option, "default", doca_third_party_json_object_new_int(1)); + doca_third_party_json_object_array_add(one_of_array, int_option); + json_object *string_option = doca_third_party_json_object_new_object(); + doca_third_party_json_object_object_add(string_option, "type", doca_third_party_json_object_new_string("string")); + doca_third_party_json_object_object_add(string_option, "default", doca_third_party_json_object_new_string("default_val")); + doca_third_party_json_object_array_add(one_of_array, string_option); + doca_third_party_json_object_object_add(one_of_property, "oneOf", one_of_array); + doca_third_party_json_object_object_add(one_of_property, "title", doca_third_party_json_object_new_string("OneOf Property")); + doca_third_party_json_object_object_add(one_of_property, "description", + doca_third_party_json_object_new_string("A oneOf property")); + + object_property = doca_third_party_json_object_new_object(); + doca_third_party_json_object_object_add(object_property, "type", doca_third_party_json_object_new_string("object")); + json_object *properties = doca_third_party_json_object_new_object(); // Create a separate nested property to avoid reference counting issues - json_object *nested_property = json_object_new_object(); - json_object_object_add(nested_property, "type", json_object_new_string("string")); - json_object_object_add(properties, "nested", nested_property); - json_object_object_add(object_property, "properties", properties); - - array_property = json_object_new_object(); - json_object_object_add(array_property, "type", json_object_new_string("array")); - json_object_object_add(array_property, "title", json_object_new_string("Array Property")); - json_object_object_add(array_property, "description", - json_object_new_string("An array property")); - json_object *items = json_object_new_object(); - json_object_object_add(items, "type", json_object_new_string("string")); - json_object_object_add(array_property, "items", items); - json_object_object_add(array_property, "default", json_object_new_array()); - - simple_property_no_title = json_object_new_object(); - json_object_object_add(simple_property_no_title, "type", json_object_new_string("integer")); - json_object_object_add(simple_property_no_title, "description", - json_object_new_string("A test property")); - json_object_object_add(simple_property_no_title, "default", json_object_new_int(42)); + json_object *nested_property = doca_third_party_json_object_new_object(); + doca_third_party_json_object_object_add(nested_property, "type", doca_third_party_json_object_new_string("string")); + doca_third_party_json_object_object_add(properties, "nested", nested_property); + doca_third_party_json_object_object_add(object_property, "properties", properties); + + array_property = doca_third_party_json_object_new_object(); + doca_third_party_json_object_object_add(array_property, "type", doca_third_party_json_object_new_string("array")); + doca_third_party_json_object_object_add(array_property, "title", doca_third_party_json_object_new_string("Array Property")); + doca_third_party_json_object_object_add(array_property, "description", + doca_third_party_json_object_new_string("An array property")); + json_object *items = doca_third_party_json_object_new_object(); + doca_third_party_json_object_object_add(items, "type", doca_third_party_json_object_new_string("string")); + doca_third_party_json_object_object_add(array_property, "items", items); + doca_third_party_json_object_object_add(array_property, "default", doca_third_party_json_object_new_array()); } void TearDown() override { - json_object_put(simple_property); - json_object_put(extended_property); - json_object_put(one_of_property); - json_object_put(object_property); - json_object_put(array_property); - json_object_put(simple_property_no_title); + doca_third_party_json_object_put(simple_property); + doca_third_party_json_object_put(extended_property); + doca_third_party_json_object_put(one_of_property); + doca_third_party_json_object_put(object_property); + doca_third_party_json_object_put(array_property); } json_object *simple_property; @@ -180,24 +173,24 @@ TEST_F(schema_analyzer_test, analyze_null_property_throws) TEST_F(schema_analyzer_test, analyze_non_object_throws) { - json_object *non_object = json_object_new_string("not an object"); + json_object *non_object = doca_third_party_json_object_new_string("not an object"); ASSERT_THROW(schema_analyzer::analyze(non_object, "test.invalid"), xlio_exception); - json_object_put(non_object); + doca_third_party_json_object_put(non_object); } TEST_F(schema_analyzer_test, analyze_property_with_constraints) { - json_object *constrained_property = json_object_new_object(); - json_object_object_add(constrained_property, "type", json_object_new_string("integer")); - json_object_object_add(constrained_property, "minimum", json_object_new_int(0)); - json_object_object_add(constrained_property, "maximum", json_object_new_int(100)); - json_object_object_add(constrained_property, "default", json_object_new_int(50)); - json_object_object_add(constrained_property, "title", - json_object_new_string("Constrained Property")); - json_object_object_add(constrained_property, "description", - json_object_new_string("A constrained property")); + json_object *constrained_property = doca_third_party_json_object_new_object(); + doca_third_party_json_object_object_add(constrained_property, "type", doca_third_party_json_object_new_string("integer")); + doca_third_party_json_object_object_add(constrained_property, "minimum", doca_third_party_json_object_new_int(0)); + doca_third_party_json_object_object_add(constrained_property, "maximum", doca_third_party_json_object_new_int(100)); + doca_third_party_json_object_object_add(constrained_property, "default", doca_third_party_json_object_new_int(50)); + doca_third_party_json_object_object_add(constrained_property, "title", + doca_third_party_json_object_new_string("Constrained Property")); + doca_third_party_json_object_object_add(constrained_property, "description", + doca_third_party_json_object_new_string("A constrained property")); auto analysis = schema_analyzer::analyze(constrained_property, "test.constrained"); @@ -209,5 +202,5 @@ TEST_F(schema_analyzer_test, analyze_property_with_constraints) ASSERT_EQ(analysis.constraint_cfg.minimum_value, 0); ASSERT_EQ(analysis.constraint_cfg.maximum_value, 100); ASSERT_EQ(std::experimental::any_cast(*analysis.default_value), 50); - json_object_put(constrained_property); + doca_third_party_json_object_put(constrained_property); } diff --git a/third_party/json-c/.clang-format b/third_party/json-c/.clang-format new file mode 100644 index 000000000..365efb275 --- /dev/null +++ b/third_party/json-c/.clang-format @@ -0,0 +1,55 @@ +BasedOnStyle: LLVM +# If true, clang-format will attempt to re-flow comments +ReflowComments: false +# The column limit. +ColumnLimit: 100 +# Indent width for line continuations. +ContinuationIndentWidth: 4 +# The number of columns to use for indentation. +IndentWidth: 8 +# The number of columns used for tab stops. +TabWidth: 8 +UseTab: ForIndentation + +# Options for aligning backslashes in escaped newlines. +AlignEscapedNewlines: Left +# Short Block Style +AllowShortBlocksOnASingleLine: true +# If true, short case labels will be contracted to a single line. +AllowShortCaseLabelsOnASingleLine: true +# Dependent on the value, int f() { return 0; } can be put on a single line. +AllowShortFunctionsOnASingleLine: Empty +# The brace breaking style to use. +BreakBeforeBraces: Custom +# Control of individual brace wrapping cases. +BraceWrapping: + # Wrap brackets inside of a case + AfterCaseLabel: true + # Wrap class definition. + AfterClass: true + # Wrap control statements + AfterControlStatement: true + # Wrap enum definitions. + AfterEnum: true + # Wrap function definitions. + AfterFunction: true + # Wrap namespace definitions. + AfterNamespace: true + # Wrap struct definitions. + AfterStruct: true + # Wrap union definitions. + AfterUnion: true + # Wrap extern blocks. + AfterExternBlock: false + # Wrap before catch. + BeforeCatch: true + # Wrap before else. + BeforeElse: true + # Indent the wrapped braces themselves. + IndentBraces: false + # If false, empty function body can be put on a single line. + SplitEmptyFunction: false + # If false, empty record (e.g. class, struct or union) body can be put on a single line. + SplitEmptyRecord: false + # If false, empty namespace body can be put on a single line. + SplitEmptyNamespace: false diff --git a/third_party/json-c/.editorconfig b/third_party/json-c/.editorconfig index 7a625d1ea..e7fd7e42a 100644 --- a/third_party/json-c/.editorconfig +++ b/third_party/json-c/.editorconfig @@ -1,5 +1,5 @@ # EditorConfig -# http://EditorConfig.org +# https://EditorConfig.org # top-most EditorConfig file root = true diff --git a/third_party/json-c/.github/ISSUE_TEMPLATE/bug_report.md b/third_party/json-c/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 000000000..54bed91d1 --- /dev/null +++ b/third_party/json-c/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,23 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: '' +assignees: '' + +--- + +Note: for general questions and comments, please use the forums at: +https://groups.google.com/g/json-c + +**Describe the bug** +A clear and concise description of what the bug is, and any information about where you're running into the bug that you feel might be relevant. + +**Steps To Reproduce** +List the steps to reproduce the behavior. +If possible, please attach a sample json file and/or a minimal code example. + +**Version and Platform** +- json-c version: [e.g. json-c-0.14, or a specific commit hash] +- OS: [e.g. Ubuntu 20.04, Debian Buster, NetBSD 9, etc...] +- Custom cmake/build flags, if any diff --git a/third_party/json-c/.gitignore b/third_party/json-c/.gitignore deleted file mode 100644 index 6347caa44..000000000 --- a/third_party/json-c/.gitignore +++ /dev/null @@ -1,111 +0,0 @@ -# Temp files -*~ -*.swp -*.bak -*.backup -\#* -.\#* -*\# -*.sav -*.save -*.autosav -*.autosave - -# Tests -/test-driver -/tests/Makefile -/tests/Makefile.in -/tests/test1 -/tests/test1Formatted -/tests/test2 -/tests/test2Formatted -/tests/test4 -/tests/testReplaceExisting -/tests/testSubDir -/tests/test_cast -/tests/test_charcase -/tests/test_compare -/tests/test_deep_copy -/tests/test_double_serializer -/tests/test_float -/tests/test_int_add -/tests/test_json_pointer -/tests/test_locale -/tests/test_null -/tests/test_parse -/tests/test_parse_int64 -/tests/test_printbuf -/tests/test_set_serializer -/tests/test_set_value -/tests/test_util_file -/tests/test_visit -/tests/*.vg.out -/tests/*.log -/tests/*.trs - -# Generated folders -/Debug -/Release -/*/Debug -/*/Release - -# Generated binaries -*.lo -*.o -/libjson-c.la -/libjson.la - -# Archives -*.zip -*.tar.* -*.tgz -*.gz -*.bz2 -*.xz -*.lz -*.lzma -*.7z -*.dll -*.deb -*.rpm -*.apk -*.exe -*.msi -*.dmg -*.ipa - -.deps/ -.libs/ -/aclocal.m4 -/autoconf-archive -/autom4te.cache -/config.guess -/config.h.in -/json_config.h -/compile -/config.h -/config.log -/config.status -/config.sub -/configure -/depcomp -/doc -/install-sh -/json.pc -/json-c.pc -/json-c-uninstalled.pc -/libtool -/ltmain.sh -/Makefile -/Makefile.in -/missing -/stamp-h1 -/stamp-h2 - -# cmake auto-generated files -/CMakeCache.txt -/CMakeFiles -/cmake_install.cmake -/include -/libjson-c.a -/libjson-c.so diff --git a/third_party/json-c/.travis.yml b/third_party/json-c/.travis.yml index 1471983e9..769bf4f18 100644 --- a/third_party/json-c/.travis.yml +++ b/third_party/json-c/.travis.yml @@ -1,32 +1,147 @@ -language: cpp - -compiler: - - gcc - - clang - -addons: - apt: - packages: - - cppcheck - -os: - - linux - - osx - -before_install: - - echo $LANG - - echo $LC_ALL - - set -e - -install: - - sh autogen.sh - -before_script: - - ./configure - -script: - - make - -after_success: - - make check - - if type cppcheck &> /dev/null ; then cppcheck --error-exitcode=1 --quiet *.h *.c tests/ ; fi +language: cpp +matrix: + include: + +# ubuntu xenial 16.04 +# gcc 5 is the default on xenial + - os: linux + dist: xenial + compiler: gcc + addons: + apt: + packages: + - valgrind + - cppcheck + - doxygen + - cmake + env: CHECK="true" + +# ubuntu bionic 18.04 +# gcc 7 is the default on bionic + - os: linux + dist: bionic + compiler: gcc + addons: + apt: + packages: + - valgrind + - cppcheck + - doxygen + - cmake + env: CHECK="true" + +# ubuntu focal fossa 20.04 +# gcc 9 is the default on bionic + - os: linux + dist: focal + compiler: gcc + addons: + apt: + packages: + - valgrind + - cppcheck + - doxygen + - cmake + env: CHECK="true" + +# clang +# xenial + - os: linux + dist: xenial + compiler: clang + addons: + apt: + sources: + - llvm-toolchain-xenial-6.0 + packages: + - clang-6.0 + - cmake + env: MATRIX_EVAL="CC=clang-6.0 && CXX=clang++-6.0" + + # clang-7 is the default on focal, xenial and bionic + - os: linux + dist: focal + compiler: clang + addons: + apt: + packages: + - valgrind + - cppcheck + - doxygen + - cmake + env: CHECK="true" + +# osx + - os: osx + osx_image: xcode13.4 + env: XCODE="true" CHECK="true" + +# run coveralls + - os: linux + dist: xenial + compiler: gcc + addons: + apt: + packages: + - lcov + env: CHECK="true" + before_install: + - sudo gem install coveralls-lcov + - echo $CC + - echo $LANG + - echo $LC_ALL + - set -e + - if [ "$TRAVIS_OS_NAME" = "linux" ]; then + eval "${MATRIX_EVAL}"; + if [ -n "$MATRIX_EVAL" ] && [ "$TRAVIS_COMPILER" != "clang" ]; then + sudo apt-get install -y $CC; + fi; + fi + before_script: + - export CFLAGS="-fprofile-arcs -ftest-coverage" + - mkdir build && cd build && cmake .. + script: + - make + - make test + after_success: + - cd .. + - lcov -d build/ -b . -c -o build/all_coverage.info + - lcov -r build/all_coverage.info '/usr/*' '*CMakeFiles*' '*fuzz*' '*test*' -o build/coverage.info + - coveralls-lcov --verbose build/coverage.info + +# allow_failures: +# - os: osx + +before_install: + - echo $CC + - echo $LANG + - echo $LC_ALL + - set -e + - if [ "$TRAVIS_OS_NAME" = "linux" ]; then + eval "${MATRIX_EVAL}"; + if [ -n "$MATRIX_EVAL" ] && [ "$TRAVIS_COMPILER" != "clang" ]; then + sudo apt-get install -y $CC; + fi; + fi + +before_script: + # XXX osx on travis doesn't work w/ set -e, so turn it off :( + - set +e + - mkdir -p build || echo "Failed to mkdir build" + - cd build || echo "Failed to cd build" + - cmake .. || echo "Failed to run cmake" + +script: + - make + # when using bionic, Travis seems to ignore the "addons" section, so installing the packages with apt-get... + - if [ -n "$CHECK" ]; then + if [ "$TRAVIS_OS_NAME" = "osx" ]; then + brew install doxygen; + else + if [ "$TRAVIS_DIST" = "bionic" ]; then + sudo apt-get install -y valgrind cppcheck doxygen; + fi; + fi; + make distcheck; + if type cppcheck &> /dev/null ; then cppcheck --error-exitcode=1 --quiet *.h *.c tests/ ; fi; + fi diff --git a/third_party/json-c/AUTHORS b/third_party/json-c/AUTHORS index b389989c4..f0fcf9769 100644 --- a/third_party/json-c/AUTHORS +++ b/third_party/json-c/AUTHORS @@ -1,5 +1,71 @@ -Michael Clark -Jehiah Czebotar -Eric Haszlakiewicz +Alan Coopersmith +Alexander Dahl +Alexandru Ardelean +An7ar35 +andy5995 +Aram Poghosyan +Björn Esser +BonsaY +changyong guo +chenguoping +Chris Lamb +Christopher Head +Chris Wolfe C. Watford (christopher.watford@gmail.com) - +Daniel Danzberger +Darjan Krijan +David McCann +DeX77 +Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> +dota17 +Eric Haszlakiewicz +Eric Hawicz +Even Rouault +Federico Francescon +Gianluigi Tiesi +grdowns +Hex052 +hofnarr +ihsinme <61293369+ihsinme@users.noreply.github.com> +Ivan Romanov +Jaap Keuter +Jakov Smolic +janczer +JC (Jonathan Chen) +Jehan +Jehiah Czebotar +Jonathan Wiens +Jose Bollo +José Bollo +Juuso Alasuutari +Keith Holman +Khem Raj +Kizuna-Meraki +Leon Gross +Liang, Gao +Luca Mannella +Marc <34656315+MarcT512@users.noreply.github.com> +Matthias Gatto +max +Micah Snyder +Michael Clark +myd7349 +Pascal Cuoq +Pawday +Philosoph228 +Pierce Lopez +Po-Chuan Hsieh +Ramiro Polla +Rikard Falkeborn +Robert Bielik +Robert +Rosen Penev +Rubasri Kalidas +Sergey Sharshunov +Simon McVittie +ssrlive <30760636+ssrlive@users.noreply.github.com> +Tobias Nießen +Tobias Stoeckmann +Tudor Brindus +Unmanned Player <36690541+unmanned-player@users.noreply.github.com> +Yurii Rashkovskii diff --git a/third_party/json-c/CMakeLists.txt b/third_party/json-c/CMakeLists.txt index 5e828abce..ad60535c4 100644 --- a/third_party/json-c/CMakeLists.txt +++ b/third_party/json-c/CMakeLists.txt @@ -1,136 +1,601 @@ -#Licensed under the MIT license. See LICENSE file in the project root for full license information. +# +# Original work: +# +# json-c (copyright was originally missing from this file) +# +# Modified Work: +# +# Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. +# +# This software product is a proprietary product of NVIDIA CORPORATION & +# AFFILIATES (the "Company") and all right, title, and interest in and to the +# software product, including all associated intellectual property rights, are +# and shall remain exclusively with the Company. +# +# This software product is governed by the End User License Agreement +# provided with the software product. +# -cmake_minimum_required(VERSION 2.8.7) +# CMake 3.9 was released in 2017/07 +# As of 2023, many versions of Linux, NetBSD and FreeBSD provide, +# and many OpenWRT packages require, much newer CMake packages. +# We're stopping before 3.10 because that version starts requiring +# c++11, which isn't available on e.g HPUX. +cmake_minimum_required(VERSION 3.9) + +# The project() command manages VERSION variables. cmake_policy(SET CMP0048 NEW) -project(json-c VERSION 0.13.1) +# JSON-C library is C only project. +# PROJECT_VERSION{,_MAJOR,_MINOR,_PATCH} set by project(): +project(json-c LANGUAGES C VERSION 0.17) + +# Targets may not link directly to themselves. +cmake_policy(SET CMP0038 NEW) + +# MACOSX_RPATH is enabled by default. +# We set it explicitly to avoid the warning +cmake_policy(SET CMP0042 NEW) + +# Only interpret if() arguments as variables or keywords when unquoted. +cmake_policy(SET CMP0054 NEW) + +# set default build type if not specified by user +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE debug) +endif() + +set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O2") + +# Include file check macros honor CMAKE_REQUIRED_LIBRARIES +# i.e. the check_include_file() calls will include -lm when checking. +# New in version 3.12. +if(POLICY CMP0075) + cmake_policy(SET CMP0075 NEW) +endif() + +include(CTest) + +# Set some packaging variables. +set(CPACK_PACKAGE_NAME "${PROJECT_NAME}") +set(CPACK_PACKAGE_VERSION_MAJOR "${PROJECT_VERSION_MAJOR}") +set(CPACK_PACKAGE_VERSION_MINOR "${PROJECT_VERSION_MINOR}") +set(CPACK_PACKAGE_VERSION_PATCH "${PROJECT_VERSION_PATCH}") +set(JSON_C_BUGREPORT "json-c@googlegroups.com") +set(CPACK_SOURCE_IGNORE_FILES + ${PROJECT_SOURCE_DIR}/build + ${PROJECT_SOURCE_DIR}/cmake-build-debug + ${PROJECT_SOURCE_DIR}/pack + ${PROJECT_SOURCE_DIR}/.idea + ${PROJECT_SOURCE_DIR}/.DS_Store + ${PROJECT_SOURCE_DIR}/.git + ${PROJECT_SOURCE_DIR}/.vscode) include(CheckSymbolExists) +include(CheckIncludeFile) +include(CheckIncludeFiles) +include(CheckCSourceCompiles) +include(CheckTypeSize) +include(CPack) +include(GNUInstallDirs) +include(CMakePackageConfigHelpers) + +option(BUILD_SHARED_LIBS "Default to building shared libraries" ON) +option(BUILD_STATIC_LIBS "Default to building static libraries" ON) + +if (BUILD_SHARED_LIBS) + add_definitions(-D JSON_C_DLL) +endif() + +# Generate a release merge and test it to verify the correctness of republishing the package. +ADD_CUSTOM_TARGET(distcheck +COMMAND make package_source + COMMAND tar -xvf "${PROJECT_NAME}-${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}-Source.tar.gz" + COMMAND mkdir "${PROJECT_NAME}-${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}-Source/build" + COMMAND cmake "${PROJECT_NAME}-${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}-Source/" -B"./${PROJECT_NAME}-${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}-Source/build/" + COMMAND make -C "${PROJECT_NAME}-${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}-Source/build" + COMMAND make test -C "${PROJECT_NAME}-${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}-Source/build" + COMMAND rm -rf "${PROJECT_NAME}-${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}-Source" +) + +# Enable or disable features. By default, all features are turned off. +option(DISABLE_BSYMBOLIC "Avoid linking with -Bsymbolic-function." OFF) +option(DISABLE_THREAD_LOCAL_STORAGE "Disable using Thread-Local Storage (HAVE___THREAD)." OFF) +option(DISABLE_WERROR "Avoid treating compiler warnings as fatal errors." OFF) +option(ENABLE_RDRAND "Enable RDRAND Hardware RNG Hash Seed." OFF) +option(ENABLE_THREADING "Enable partial threading support." OFF) +option(OVERRIDE_GET_RANDOM_SEED "Override json_c_get_random_seed() with custom code." OFF) +option(DISABLE_EXTRA_LIBS "Avoid linking against extra libraries, such as libbsd." OFF) +option(DISABLE_JSON_POINTER "Disable JSON pointer (RFC6901) and JSON patch support." OFF) +option(DISABLE_JSON_PATCH "Disable JSON patch (RFC6902) support." OFF) +option(NEWLOCALE_NEEDS_FREELOCALE "Work around newlocale bugs in old FreeBSD by calling freelocale" OFF) + + +if (UNIX OR MINGW OR CYGWIN) + list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE) +endif() + +if (UNIX) + list(APPEND CMAKE_REQUIRED_LIBRARIES m) +endif() + +if (MSVC) + list(APPEND CMAKE_REQUIRED_DEFINITIONS /D_CRT_SECURE_NO_DEPRECATE) + list(APPEND CMAKE_REQUIRED_FLAGS /wd4996) +endif() + +if (NOT DISABLE_STATIC_FPIC) + # Use '-fPIC'/'-fPIE' option. + # This will allow other libraries to statically link in libjson-c.a + # which in turn prevents crashes in downstream apps that may use + # a different JSON library with identical symbol names. + set(CMAKE_POSITION_INDEPENDENT_CODE ON) +endif() + +check_include_file("fcntl.h" HAVE_FCNTL_H) +check_include_file("inttypes.h" HAVE_INTTYPES_H) +check_include_file(stdarg.h HAVE_STDARG_H) +check_include_file(strings.h HAVE_STRINGS_H) +check_include_file(string.h HAVE_STRING_H) +check_include_file(syslog.h HAVE_SYSLOG_H) + + +check_include_files("stdlib.h;stdarg.h;string.h;float.h" STDC_HEADERS) + +check_include_file(unistd.h HAVE_UNISTD_H) +check_include_file(sys/types.h HAVE_SYS_TYPES_H) +check_include_file(sys/resource.h HAVE_SYS_RESOURCE_H) # for getrusage + +check_include_file("dlfcn.h" HAVE_DLFCN_H) +check_include_file("endian.h" HAVE_ENDIAN_H) +check_include_file("limits.h" HAVE_LIMITS_H) +check_include_file("locale.h" HAVE_LOCALE_H) +check_include_file("memory.h" HAVE_MEMORY_H) + +check_include_file(stdint.h HAVE_STDINT_H) +check_include_file(stdlib.h HAVE_STDLIB_H) +check_include_file(sys/cdefs.h HAVE_SYS_CDEFS_H) +check_include_file(sys/param.h HAVE_SYS_PARAM_H) +check_include_file(sys/random.h HAVE_SYS_RANDOM_H) +check_include_file(sys/stat.h HAVE_SYS_STAT_H) +check_include_file(xlocale.h HAVE_XLOCALE_H) + +# Set json-c specific vars to stamp into json_config.h +# in a way that hopefully won't conflict with other +# projects that use json-c. +if (HAVE_INTTYPES_H) + set(JSON_C_HAVE_INTTYPES_H 1) +endif() +if (HAVE_STDINT_H) + set(JSON_C_HAVE_STDINT_H 1) +endif() + +check_symbol_exists(_isnan "float.h" HAVE_DECL__ISNAN) +check_symbol_exists(_finite "float.h" HAVE_DECL__FINITE) + +if ((MSVC AND NOT (MSVC_VERSION LESS 1800)) OR MINGW OR CYGWIN OR UNIX) + check_symbol_exists(INFINITY "math.h" HAVE_DECL_INFINITY) + check_symbol_exists(isinf "math.h" HAVE_DECL_ISINF) + check_symbol_exists(isnan "math.h" HAVE_DECL_ISNAN) + check_symbol_exists(nan "math.h" HAVE_DECL_NAN) +endif() + +check_symbol_exists(_doprnt "stdio.h" HAVE_DOPRNT) +if (UNIX OR MINGW OR CYGWIN) + check_symbol_exists(snprintf "stdio.h" HAVE_SNPRINTF) +endif() +check_symbol_exists(vasprintf "stdio.h" HAVE_VASPRINTF) +check_symbol_exists(vsnprintf "stdio.h" HAVE_VSNPRINTF) +check_symbol_exists(vprintf "stdio.h" HAVE_VPRINTF) + +check_symbol_exists(arc4random "stdlib.h" HAVE_ARC4RANDOM) +if (NOT HAVE_ARC4RANDOM AND DISABLE_EXTRA_LIBS STREQUAL "OFF") + check_include_file(bsd/stdlib.h HAVE_BSD_STDLIB_H) + if (HAVE_BSD_STDLIB_H) + list(APPEND CMAKE_REQUIRED_LIBRARIES "bsd") + unset(HAVE_ARC4RANDOM CACHE) + check_symbol_exists(arc4random "bsd/stdlib.h" HAVE_ARC4RANDOM) + if (NOT HAVE_ARC4RANDOM) + list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES "bsd") + endif() + endif() +endif() + +if (HAVE_FCNTL_H) + check_symbol_exists(open "fcntl.h" HAVE_OPEN) +endif() +if (HAVE_STDLIB_H) + check_symbol_exists(realloc "stdlib.h" HAVE_REALLOC) +endif() +if (HAVE_LOCALE_H) + check_symbol_exists(setlocale "locale.h" HAVE_SETLOCALE) + check_symbol_exists(uselocale "locale.h" HAVE_USELOCALE) +endif() + +# uClibc *intentionally* crashes in duplocale(), at least as of: +# https://github.com/ffainelli/uClibc/blob/266bdc1/libc/misc/locale/locale.c#L1322 +# So, if it looks like we're compiling for a system like that just disable +# locale handling entirely. +exec_program(${CMAKE_C_COMPILER} ARGS -dumpmachine OUTPUT_VARIABLE CMAKE_GNU_C_MACHINE) +if (CMAKE_GNU_C_MACHINE MATCHES "uclibc") + message(STATUS "Detected uClibc compiler, disabling locale handling") + set(HAVE_SETLOCALE 0) + set(HAVE_USELOCALE 0) +endif() + +if (HAVE_STRINGS_H) + check_symbol_exists(strcasecmp "strings.h" HAVE_STRCASECMP) + check_symbol_exists(strncasecmp "strings.h" HAVE_STRNCASECMP) +endif() +if (HAVE_STRING_H) + check_symbol_exists(strdup "string.h" HAVE_STRDUP) + check_symbol_exists(strerror "string.h" HAVE_STRERROR) +endif() +if (HAVE_SYSLOG_H) + check_symbol_exists(vsyslog "syslog.h" HAVE_VSYSLOG) +endif() +if (HAVE_SYS_RANDOM_H) + check_symbol_exists(getrandom "sys/random.h" HAVE_GETRANDOM) +endif() +if (HAVE_SYS_RESOURCE_H) + check_symbol_exists(getrusage "sys/resource.h" HAVE_GETRUSAGE) +endif() -check_symbol_exists(strtoll "stdlib.h" HAVE_STRTOLL) +check_symbol_exists(strtoll "stdlib.h" HAVE_STRTOLL) +check_symbol_exists(strtoull "stdlib.h" HAVE_STRTOULL) -set(cmake_strtoll "strtoll") +set(json_c_strtoll "strtoll") if (NOT HAVE_STRTOLL) - # Use _strtoi64 if strtoll is not available. - check_symbol_exists(_strtoi64 stdlib.h have_strtoi64) - if (have_strtoi64) - set(HAVE_STRTOLL 1) - set(cmake_strtoll "_strtoi64") - # could do the same for strtoull, if needed - endif () -endif () +# Use _strtoi64 if strtoll is not available. +check_symbol_exists(_strtoi64 "stdlib.h" __have_strtoi64) +if (__have_strtoi64) + #set(HAVE_STRTOLL 1) + set(json_c_strtoll "_strtoi64") +endif() +endif() + +set(json_c_strtoull "strtoull") +if (NOT HAVE_STRTOULL) +# Use _strtoui64 if strtoull is not available. +check_symbol_exists(_strtoui64 "stdlib.h" __have_strtoui64) +if (__have_strtoui64) + #set(HAVE_STRTOULL 1) + set(json_c_strtoull "_strtoui64") +endif() +endif() +check_type_size(int SIZEOF_INT) +check_type_size(int64_t SIZEOF_INT64_T) +check_type_size(long SIZEOF_LONG) +check_type_size("long long" SIZEOF_LONG_LONG) +check_type_size("size_t" SIZEOF_SIZE_T) +if (MSVC) +list(APPEND CMAKE_EXTRA_INCLUDE_FILES BaseTsd.h) +check_type_size("SSIZE_T" SIZEOF_SSIZE_T) +else() +check_type_size("ssize_t" SIZEOF_SSIZE_T) +endif() + +check_c_source_compiles( +" +extern void json_object_get(); +__asm__(\".section .gnu.json_object_get\\n\\t.ascii \\\"Please link against libjson-c instead of libjson\\\"\\n\\t.text\"); +int main(int c, char *v) { return 0;} +" +HAS_GNU_WARNING_LONG) + +check_c_source_compiles( + "int main() { int i, x = 0; i = __sync_add_and_fetch(&x,1); return x; }" + HAVE_ATOMIC_BUILTINS) + +if (NOT DISABLE_THREAD_LOCAL_STORAGE) + check_c_source_compiles( + "__thread int x = 0; int main() { return 0; }" + HAVE___THREAD) -if(MSVC) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4100 /wd4996 /wd4244 /wd4706 /wd4702 /wd4127 /wd4701") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4100 /wd4996 /wd4244 /wd4706 /wd4702 /wd4127 /wd4701") - set(cmake_create_config 1) -elseif(MINGW) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -D_GNU_SOURCE=1") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -D_GNU_SOURCE=1") - if (MSYS OR CMAKE_GENERATOR STREQUAL "Unix Makefiles") - execute_process(COMMAND echo ${CMAKE_CURRENT_SOURCE_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) - execute_process(COMMAND sh autogen.sh WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) - execute_process(COMMAND sh ./configure WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) - file(COPY ./config.h DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/include/) - file(COPY ./json_config.h DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/include/) - else() - set(cmake_create_config 1) + if (HAVE___THREAD) + set(SPEC___THREAD __thread) + elseif (MSVC) + set(SPEC___THREAD __declspec(thread)) endif() -elseif(UNIX) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -D_GNU_SOURCE") - execute_process(COMMAND echo ${CMAKE_CURRENT_SOURCE_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) - execute_process(COMMAND sh autogen.sh WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) - execute_process(COMMAND ./configure WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) - file(COPY ./config.h DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/include/) - file(COPY ./json_config.h DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/include/) -endif() - -if (cmake_create_config) - file(REMOVE ./config.h) # make sure any stale one is gone - configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.win32 ${CMAKE_CURRENT_BINARY_DIR}/include/config.h) - file(COPY ./json_config.h.win32 DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/include/) - file(RENAME ${CMAKE_CURRENT_BINARY_DIR}/include/json_config.h.win32 ${CMAKE_CURRENT_BINARY_DIR}/include/json_config.h) -endif () +endif() -include_directories(${CMAKE_CURRENT_BINARY_DIR}/include) +# Hardware random number is not available on Windows? Says, config.h.win32. Best to preserve compatibility. +if (WIN32) + set(ENABLE_RDRAND 0) +endif() + +# Once we've done basic symbol/header searches let's add them in. +configure_file(${PROJECT_SOURCE_DIR}/cmake/config.h.in ${PROJECT_BINARY_DIR}/config.h) +message(STATUS "Wrote ${PROJECT_BINARY_DIR}/config.h") +configure_file(${PROJECT_SOURCE_DIR}/cmake/json_config.h.in ${PROJECT_BINARY_DIR}/json_config.h) +message(STATUS "Wrote ${PROJECT_BINARY_DIR}/json_config.h") + +if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffunction-sections -fdata-sections") + if ("${DISABLE_WERROR}" STREQUAL "OFF") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror") + endif() + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wcast-qual") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-error=deprecated-declarations") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wextra") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wwrite-strings") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-parameter") + if (NOT WIN32) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wstrict-prototypes") + endif() + + add_definitions(-D_GNU_SOURCE) + + if ("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang") + # Remove this for 1.0 when we can bump the ABI and actually fix these warnings. + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-shorten-64-to-32") + endif() +elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /DEBUG") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4100") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4996") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4244") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4706") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4702") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4127") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4701") +endif() + +if (NOT ("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC")) + check_c_source_compiles( + " + /* uClibc toolchains without threading barf when _REENTRANT is defined */ + #define _REENTRANT 1 + #include + int main (void) + { + return 0; + } + " + REENTRANT_WORKS + ) + if (REENTRANT_WORKS) + add_compile_options("-D_REENTRANT") + endif() + + # OSX Mach-O doesn't support linking with '-Bsymbolic-functions'. + # Others may not support it, too. + list(APPEND CMAKE_REQUIRED_LIBRARIES "-Wl,-Bsymbolic-functions") + check_c_source_compiles( + " + int main (void) + { + return 0; + } + " + BSYMBOLIC_WORKS + ) + list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES "-Wl,-Bsymbolic-functions") + if (DISABLE_BSYMBOLIC STREQUAL "OFF" AND BSYMBOLIC_WORKS) + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-Bsymbolic-functions") + # XXX need cmake>=3.13 for this: + #add_link_options("-Wl,-Bsymbolic-functions") + endif() + + file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/check-version-script.sym" "TEST { global: *; };") + list(APPEND CMAKE_REQUIRED_LIBRARIES "-Wl,--version-script,${CMAKE_CURRENT_BINARY_DIR}/check-version-script.sym") + check_c_source_compiles( + " + int main (void) + { + return 0; + } + " + VERSION_SCRIPT_WORKS + ) + list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES "-Wl,--version-script,${CMAKE_CURRENT_BINARY_DIR}/check-version-script.sym") + if (VERSION_SCRIPT_WORKS) + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--version-script,${CMAKE_CURRENT_SOURCE_DIR}/json-c.sym") + endif() +endif() + +if ($ENV{VALGRIND}) + # Build so that valgrind doesn't complain about linkhash.c + add_definitions(-DVALGRIND=1) +endif() set(JSON_C_PUBLIC_HEADERS - ./json.h - ${CMAKE_CURRENT_BINARY_DIR}/include/config.h - ${CMAKE_CURRENT_BINARY_DIR}/include/json_config.h - ./arraylist.h - ./debug.h - ./json_c_version.h - ./json_inttypes.h - ./json_object.h - ./json_pointer.h - ./json_tokener.h - ./json_util.h - ./linkhash.h - ./printbuf.h + # Note: config.h is _not_ included here + ${PROJECT_BINARY_DIR}/json_config.h + + ${PROJECT_BINARY_DIR}/json.h + ${PROJECT_SOURCE_DIR}/arraylist.h + ${PROJECT_SOURCE_DIR}/debug.h + ${PROJECT_SOURCE_DIR}/json_c_version.h + ${PROJECT_SOURCE_DIR}/json_inttypes.h + ${PROJECT_SOURCE_DIR}/json_object.h + ${PROJECT_SOURCE_DIR}/json_object_iterator.h + ${PROJECT_SOURCE_DIR}/json_tokener.h + ${PROJECT_SOURCE_DIR}/json_types.h + ${PROJECT_SOURCE_DIR}/json_util.h + ${PROJECT_SOURCE_DIR}/json_visit.h + ${PROJECT_SOURCE_DIR}/linkhash.h + ${PROJECT_SOURCE_DIR}/printbuf.h ) + set(JSON_C_HEADERS ${JSON_C_PUBLIC_HEADERS} - ./json_object_private.h - ./random_seed.h - ./strerror_override.h - ./strerror_override_private.h - ./math_compat.h - ./snprintf_compat.h - ./strdup_compat.h - ./vasprintf_compat.h + ${PROJECT_SOURCE_DIR}/json_object_private.h + ${PROJECT_SOURCE_DIR}/json_pointer_private.h + ${PROJECT_SOURCE_DIR}/random_seed.h + ${PROJECT_SOURCE_DIR}/strerror_override.h + ${PROJECT_SOURCE_DIR}/math_compat.h + ${PROJECT_SOURCE_DIR}/snprintf_compat.h + ${PROJECT_SOURCE_DIR}/strdup_compat.h + ${PROJECT_SOURCE_DIR}/vasprintf_compat.h ) set(JSON_C_SOURCES - ./arraylist.c - ./debug.c - ./json_c_version.c - ./json_object.c - ./json_object_iterator.c - ./json_pointer.c - ./json_tokener.c - ./json_util.c - ./json_visit.c - ./linkhash.c - ./printbuf.c - ./random_seed.c - ./strerror_override.c + ${PROJECT_SOURCE_DIR}/arraylist.c + ${PROJECT_SOURCE_DIR}/debug.c + ${PROJECT_SOURCE_DIR}/json_c_version.c + ${PROJECT_SOURCE_DIR}/json_object.c + ${PROJECT_SOURCE_DIR}/json_object_iterator.c + ${PROJECT_SOURCE_DIR}/json_tokener.c + ${PROJECT_SOURCE_DIR}/json_util.c + ${PROJECT_SOURCE_DIR}/json_visit.c + ${PROJECT_SOURCE_DIR}/linkhash.c + ${PROJECT_SOURCE_DIR}/printbuf.c + ${PROJECT_SOURCE_DIR}/random_seed.c + ${PROJECT_SOURCE_DIR}/strerror_override.c ) -add_library(json-c - SHARED +if (NOT DISABLE_JSON_POINTER) + set(JSON_C_PUBLIC_HEADERS ${JSON_C_PUBLIC_HEADERS} ${PROJECT_SOURCE_DIR}/json_pointer.h) + set(JSON_C_SOURCES ${JSON_C_SOURCES} ${PROJECT_SOURCE_DIR}/json_pointer.c) + set(JSON_H_JSON_POINTER "#include \"json_pointer.h\"") + + if (NOT DISABLE_JSON_PATCH) + set(JSON_C_PUBLIC_HEADERS ${JSON_C_PUBLIC_HEADERS} ${PROJECT_SOURCE_DIR}/json_patch.h) + set(JSON_C_SOURCES ${JSON_C_SOURCES} ${PROJECT_SOURCE_DIR}/json_patch.c) + set(JSON_H_JSON_PATCH "#include \"json_patch.h\"") + endif() +else() + set(JSON_H_JSON_POINTER "") + set(JSON_H_JSON_PATCH "") +endif() + +configure_file(json.h.cmakein ${PROJECT_BINARY_DIR}/json.h @ONLY) + +include_directories(${PROJECT_SOURCE_DIR}) +include_directories(${PROJECT_BINARY_DIR}) + +add_subdirectory(doc) + +# "uninstall" custom target for make generators in unix like operating systems +# and if that target is not present +if (CMAKE_GENERATOR STREQUAL "Unix Makefiles") + if(NOT TARGET uninstall) + add_custom_target(uninstall + COMMAND cat ${PROJECT_BINARY_DIR}/install_manifest.txt | xargs rm + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + ) + endif() +endif() + +# XXX for a normal full distribution we'll need to figure out +# XXX how to build both shared and static libraries. +# Probably leverage that to build a local VALGRIND=1 library for testing too. +add_library(${PROJECT_NAME} ${JSON_C_SOURCES} ${JSON_C_HEADERS} ) +set_target_properties(${PROJECT_NAME} PROPERTIES + VERSION 5.3.0 + SOVERSION 5) +list(APPEND CMAKE_TARGETS ${PROJECT_NAME}) +# If json-c is used as subroject it set to target correct interface -I flags and allow +# to build external target without extra include_directories(...) +target_include_directories(${PROJECT_NAME} + PUBLIC + $ + $ +) -add_library(json-c-static - STATIC - ${JSON_C_SOURCES} - ${JSON_C_HEADERS} +target_link_libraries(${PROJECT_NAME} PUBLIC ${CMAKE_REQUIRED_LIBRARIES}) + +# Allow to build static and shared libraries at the same time +if (BUILD_STATIC_LIBS AND BUILD_SHARED_LIBS) + set(STATIC_LIB ${PROJECT_NAME}-static) + add_library(${STATIC_LIB} STATIC + ${JSON_C_SOURCES} + ${JSON_C_HEADERS} + ) + target_include_directories(${PROJECT_NAME}-static + PUBLIC + $ + $ + ) + + target_link_libraries(${PROJECT_NAME}-static PUBLIC ${CMAKE_REQUIRED_LIBRARIES}) + + # rename the static library + if (NOT MSVC) + set_target_properties(${STATIC_LIB} PROPERTIES + OUTPUT_NAME ${PROJECT_NAME} + ) + endif() + list(APPEND CMAKE_TARGETS ${STATIC_LIB}) +endif () + +# Always create new install dirs with 0755 permissions, regardless of umask +set(CMAKE_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS + OWNER_READ + OWNER_WRITE + OWNER_EXECUTE + GROUP_READ + GROUP_EXECUTE + WORLD_READ + WORLD_EXECUTE + ) + +install(TARGETS ${CMAKE_TARGETS} + EXPORT ${PROJECT_NAME}-targets + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ${CMAKE_INSTALL_INCLUDEDIR}/json-c ) -set_property(TARGET json-c PROPERTY C_STANDARD 99) -set_property(TARGET json-c-static PROPERTY C_STANDARD 99) -set_target_properties(json-c-static PROPERTIES OUTPUT_NAME json-c) +install(EXPORT ${PROJECT_NAME}-targets + FILE ${PROJECT_NAME}-targets.cmake + NAMESPACE ${PROJECT_NAME}:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} +) -install(TARGETS json-c json-c-static - RUNTIME DESTINATION bin - LIBRARY DESTINATION lib - ARCHIVE DESTINATION lib +configure_package_config_file( + "cmake/Config.cmake.in" + ${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config.cmake + INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" ) -install(FILES ${JSON_C_PUBLIC_HEADERS} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/json-c ) +install( + FILES ${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} +) -if (UNIX) - set(prefix ${CMAKE_INSTALL_PREFIX}) - set(exec_prefix ${CMAKE_INSTALL_PREFIX}/bin) - set(libdir ${CMAKE_INSTALL_PREFIX}/lib) - set(includedir ${CMAKE_INSTALL_PREFIX}/include) - set(VERSION ${PROJECT_VERSION}) - configure_file(json-c.pc.in json-c.pc @ONLY) - set(INSTALL_PKGCONFIG_DIR "${CMAKE_INSTALL_PREFIX}/lib/pkgconfig" CACHE PATH "Installation directory for pkgconfig (.pc) files") - install(FILES ${CMAKE_BINARY_DIR}/json-c.pc DESTINATION "${INSTALL_PKGCONFIG_DIR}") +if (UNIX OR MINGW OR CYGWIN) + SET(prefix ${CMAKE_INSTALL_PREFIX}) + # exec_prefix is prefix by default and CMake does not have the + # concept. + SET(exec_prefix ${CMAKE_INSTALL_PREFIX}) + SET(libdir ${CMAKE_INSTALL_FULL_LIBDIR}) + SET(includedir ${CMAKE_INSTALL_FULL_INCLUDEDIR}) + SET(VERSION ${PROJECT_VERSION}) + + # Linking against the static json-c requires + # dependent packages to include additional libs: + SET(LIBS_LIST ${CMAKE_REQUIRED_LIBRARIES}) + + # Note: We would need cmake >= 3.12 in order to use list(TRANSFORM ...) + function(list_transform_prepend var prefix) + set(temp "") + foreach(f ${${var}}) + list(APPEND temp "${prefix}${f}") + endforeach() + set(${var} "${temp}" PARENT_SCOPE) + endfunction() + list_transform_prepend(LIBS_LIST "-l") + + string(REPLACE ";" " " LIBS "${LIBS_LIST}") + + configure_file(json-c.pc.in json-c.pc @ONLY) + set(INSTALL_PKGCONFIG_DIR "${CMAKE_INSTALL_LIBDIR}/pkgconfig" CACHE PATH "Installation directory for pkgconfig (.pc) files") + install(FILES ${PROJECT_BINARY_DIR}/json-c.pc DESTINATION "${INSTALL_PKGCONFIG_DIR}") endif () + +install(FILES ${JSON_C_PUBLIC_HEADERS} DESTINATION ${CMAKE_INSTALL_FULL_INCLUDEDIR}/json-c) + +if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING AND + (NOT MSVC OR NOT (MSVC_VERSION LESS 1800)) # Tests need at least VS2013 + ) +add_subdirectory(tests) +endif() diff --git a/third_party/json-c/ChangeLog b/third_party/json-c/ChangeLog index 868122568..d1e3f4ed3 100644 --- a/third_party/json-c/ChangeLog +++ b/third_party/json-c/ChangeLog @@ -1,8 +1,243 @@ +0.17 (up to commit 077661f, 2023-08-08) +======================================== + +Deprecated and removed features: +-------------------------------- +* None + +New features +------------ +* json_patch: add first implementation only with patch application +* Add --disable-static and --disable-dynamic options to the cmake-configure script. +* Add -DBUILD_APPS=NO option to disable app build +* Minimum cmake version is now 3.9 + +Significant changes and bug fixes +--------------------------------- +* When serializing with JSON_C_TO_STRING_PRETTY set, keep the opening and + closing curly or square braces on same line for empty objects or arrays. +* Disable locale handling when targeting a uClibc system due to problems + with its duplocale() function. +* When parsing with JSON_TOKENER_STRICT set, integer overflow/underflow + now result in a json_tokener_error_parse_number. Without that flag + values are capped at INT64_MIN/UINT64_MAX. +* Fix memory leak with emtpy strings in json_object_set_string +* json_object_from_fd_ex: fail if file is too large (>=INT_MAX bytes) +* Add back json_number_chars, but only because it's part of the public API. +* Entirely drop mode bits from open(O_RDONLY) to avoid warnings on certain + platforms. +* Specify dependent libraries, including -lbsd, in a more consistent way so + linking against a static json-c works better +* Fix a variety of build problems and add & improve tests +* Update RFC reference to https://www.rfc-editor.org/rfc/rfc8259 + +*** + +0.16 (up to commit 66dcdf5, 2022-04-13) +======================================== + +Deprecated and removed features: +-------------------------------- +* JSON_C_OBJECT_KEY_IS_CONSTANT is deprecated in favor of + JSON_C_OBJECT_ADD_CONSTANT_KEY +* Direct access to lh_table and lh_entry structure members is deprecated. + Use access functions instead, lh_table_head(), lh_entry_next(), etc... +* Drop REFCOUNT_DEBUG code. + +New features +------------ +* The 0.16 release introduces no new features + +Build changes +------------- +* Add a DISABLE_EXTRA_LIBS option to skip using libbsd +* Add a DISABLE_JSON_POINTER option to skip compiling in json_pointer support. + +Significant changes and bug fixes +--------------------------------- +* Cap string length at INT_MAX to avoid various issues with very long strings. +* json_object_deep_copy: fix deep copy of strings containing '\0' +* Fix read past end of buffer in the "json_parse" command +* Avoid out of memory accesses in the locally provided vasprintf() function + (for those platforms that use it) +* Handle allocation failure in json_tokener_new_ex +* Fix use-after-free in json_tokener_new_ex() in the event of printbuf_new() returning NULL +* printbuf_memset(): set gaps to zero - areas within the print buffer which + have not been initialized by using printbuf_memset +* printbuf: return -1 on invalid arguments (len < 0 or total buffer > INT_MAX) +* sprintbuf(): propagate printbuf_memappend errors back to the caller + +Optimizations +-------------- +* Speed up parsing by replacing ctype functions with simplified, faster + non-locale-sensitive ones in json_tokener and json_object_to_json_string. +* Neither vertical tab nor formfeed are considered whitespace per the JSON spec +* json_object: speed up creation of objects, calloc() -> malloc() + set fields +* Avoid needless extra strlen() call in json_c_shallow_copy_default() and + json_object_equal() when the object is known to be a json_type_string. + +Other changes +------------- +* Validate size arguments in arraylist functions. +* Use getrandom() if available; with GRND_NONBLOCK to allow use of json-c + very early during boot, such as part of cryptsetup. +* Use arc4random() if it's available. +* random_seed: on error, continue to next method instead of exiting the process +* Close file when unable to read from /dev/urandom in get_dev_random_seed() + +*** + +0.15 (up to commit 870965e, 2020/07/26) +======================================== + +Deprecated and removed features: +-------------------------------- +* Deprecate `array_list_new()` in favor of `array_list_new2()` +* Remove the THIS_FUNCTION_IS_DEPRECATED define. +* Remove config.h.win32 + +New features +------------ +* Add a `JSON_TOKENER_ALLOW_TRAILING_CHARS` flag to allow multiple objects + to be parsed even when `JSON_TOKENER_STRICT` is set. +* Add `json_object_new_array_ext(int)` and `array_list_new_2(int)` to allow + arrays to be allocated with the exact size needed, when known. +* Add `json_object_array_shrink()` (and `array_list_shrink()`) and use it in + json_tokener to minimize the amount of memory used. +* Add a json_parse binary, for use in testing changes (not installed, but + available in the apps directory). + +Build changes +------------- +* #639/#621 - Add symbol versions to all exported symbols +* #508/#634 - Always enable -fPIC to allow use of the json-c static library in + other libraries +* Build both static and shared libraries at the same time. +* #626 - Restore compatibility with cmake 2.8 +* #471 - Always create directories with mode 0755, regardless of umask. +* #606/#604 - Improve support for OSes like AIX and IBM i, as well as for + MINGW32 and old versions of MSVC +* #451/#617 - Add a DISABLE_THREAD_LOCAL_STORAGE cmake option to disable + the use of thread-local storage. + +Significant changes and bug fixes +--------------------------------- +* Split the internal json_object structure into several sub-types, one for + each json_type (json_object_object, json_object_string, etc...). + This improves memory usage and speed, with the benchmark under + bench/ report 5.8% faster test time and 6%(max RSS)-12%(peak heap) + less memory usage. + Memory used just for json_object structures decreased 27%, so use cases + with fewer arrays and/or strings would benefit more. +* Minimize memory usage in array handling in json_tokener by shrinking + arrays to the exact number of elements parsed. On bench/ benchmark: + 9% faster test time, 39%(max RSS)-50%(peak heap) less memory usage. + Add json_object_array_shrink() and array_list_shrink() functions. +* #616 - Parsing of surrogate pairs in unicode escapes now properly handles + incremental parsing. +* Fix incremental parsing of numbers, especially those with exponents, e.g. + so parsing "[0", "e+", "-]" now properly returns an error. + Strict mode now rejects missing exponents ("0e"). +* Successfully return number objects at the top level even when they are + followed by a "-", "." or "e". This makes parsing things like "123-45" + behave consistently with things like "123xyz". + +Other changes +------------- +* #589 - Detect broken RDRAND during initialization; also, fix segfault + in the CPUID check. +* #592 - Fix integer overflows to prevert out of bounds write on large input. +* Protect against division by zero in linkhash, when created with zero size. +* #602 - Fix json_parse_uint64() internal error checking, leaving the retval + untouched in more failure cases. +* #614 - Prevent truncation when custom double formatters insert extra \0's + + +*** + +0.14 (up to commit 9ed00a6, 2020/04/14) +========================================= + +Deprecated and removed features: +-------------------------------- +* bits.h has been removed +* lh_abort() has been removed +* lh_table_lookup() has been removed, use lh_table_lookup_ex() instead. +* Remove TRUE and FALSE defines, use 1 and 0 instead. + +Build changes: +-------------- +## Deprecated and removed features: +* bits.h has been removed +* lh_abort() has been removed +* lh_table_lookup() has been removed, use lh_table_lookup_ex() instead. +* Remove TRUE and FALSE defines, use 1 and 0 instead. +* autoconf support, including autogen.sh, has been removed. See details about cmake, below. +* With the addition of json_tokener_get_parse_end(), access to internal fields of json_tokener, as well as use of many other symbols and types in json_tokener.h, is deprecated now. +* The use of Android.configure.mk to build for Android no longer works, and it is unknown how (or if) the new cmake-based build machinery can be used. + * Reports of success, or pull requests to correct issues are welcome. + +## Notable improvements and new features + +### Builds and documentation +* Build machinery has been switched to CMake. See README.md for details about how to build. + * TL;DR: `mkdir build ; cd build ; cmake -DCMAKE_INSTALL_PREFIX=/some/path ../json-c ; make all test install` + * To ease the transition, there is a `cmake-configure` wrapper that emulates the old autoconf-based configure script. + * This has enabled improvements to the build on Windows system; also all public functions have been fixed to be properly exported. For best results, use Visual Studio 2015 or newer. +* The json-c style guide has been updated to specify the use of clang-format, and all code has been reformatted. + * Since many lines of code have trivial changes now, when using git blame, be sure to specify -w +* Numerous improvements have been made to the documentation including function effects on refcounts, when passing a NULL is safe, and so on. + +### json_tokener changes +* Added a json_tokener_get_parse_end() function to replace direct access of tok->char_offset. + * The char_offset field, and the rest of the json_tokener structure remain exposed for now, but expect a future release to hide it like is done with json_object_private.h +* json_tokener_parse_ex() now accepts a new JSON_TOKENER_VALIDATE_UTF8 flag to validate that input is UTF8. + * If validation fails, json_tokener_get_error(tok) will return json_tokener_error_parse_utf8_string (see enum json_tokener_error). + +### Other changes and additions +* Add support for unsigned 64-bit integers, uint64_t, to gain one extra bit of magnitude for positive ints. + * json_tokener will now parse values up to UINT64_MAX (18446744073709551615) + * Existing methods returning int32_t or int64_t will cap out-of-range values at INT32_MAX or INT64_MAX, preserving existing behavior. + * The implementation includes the possibility of easily extending this to larger sizes in the future. +* A total of 7 new functions were added: + * json_object_get_uint64 ( struct json_object const* jso ) + * json_object_new_uint64 ( uint64_t i ) + * json_object_set_uint64 ( struct json_object* jso, uint64_t new_value ) + * json_parse_uint64 ( char const* buf, uint64_t* retval ) + * See description of uint64 support, above. + * json_tokener_get_parse_end ( struct json_tokener* tok ) + * See details under "json_tokener changes", above. + * json_object_from_fd_ex ( int fd, int in_depth ) + * Allows the max nesting depth to be specified. + * json_object_new_null ( ) + * Simply returns NULL. Its use is not recommended. +* The size of struct json_object has decreased from 96 bytes to 88 bytes. + +### Testing +* Many updates were made to test cases, increasing code coverage. +* There is now a quick way (JSONC_TEST_TRACE=1) to turn on shell tracing in tests. +* To run tests, use `make test`; the old "check" target no longer exists. + +## Significant bug fixes +For the full list of issues and pull requests since the previous release, please see issues_closed_for_0.14.md + +* [Issue #389](https://github.com/json-c/json-c/issues/389): Add an assert to explicitly crash when _ref_count is corrupted, instead of a later "double free" error. +* [Issue #407](https://github.com/json-c/json-c/issues/407): fix incorrect casts in calls to ctype functions (isdigit and isspace) so we don't crash when asserts are enabled on certain platforms and characters > 128 are parsed. +* [Issue #418](https://github.com/json-c/json-c/issues/418): Fix docs for json_util_from_fd and json_util_from_file to say that they return NULL on failures. +* [Issue #422](https://github.com/json-c/json-c/issues/422): json_object.c:set errno in json_object_get_double() when called on a json_type_string object with bad content. +* [Issue #453](https://github.com/json-c/json-c/issues/453): Fixed misalignment in JSON serialization when JSON_C_TO_STRING_SPACED and JSON_C_TO_STRING_PRETTY are used together. +* [Issue #463](https://github.com/json-c/json-c/issues/463): fix newlocale() call to use LC_NUMERIC_MASK instead of LC_NUMERIC, and remove incorrect comment. +* [Issue #486](https://github.com/json-c/json-c/issues/486): append a missing ".0" to negative double values to ensure they are serialized as floating point numbers. +* [Issue #488](https://github.com/json-c/json-c/issues/488): use JSON_EXPORT on functions so they are properly exported on Windows. +* [Issue #539](https://github.com/json-c/json-c/issues/539): use an internal-only serializer function in json_object_new_double_s() to avoid potential conflicts with user code that uses the json_object_userdata_to_json_string serializer. + +*** + 0.13.1 (up to commit 0f814e5, 2018/03/04) ========================================= -* Bump the major version of the .so library generated up to 4.0 to avoid +* Bump the major version of the .so library generated up to 4.0 to avoid conflicts because some downstream packagers of json-c had already done their own bump to ".so.3" for a much older 0.12 release. * Add const size_t json_c_object_sizeof() @@ -12,6 +247,7 @@ * Issue #396: fix build for certain uClibc based systems. * Add a top level fuzz directory for fuzzers run by OSS-Fuzz + 0.13 (up to commit 5dae561, 2017/11/29) ================================= @@ -26,7 +262,7 @@ See issues_closed_for_0.13.md for a complete list. Deprecated and removed features: -------------------------------- * All internal use of bits.h has been eliminated. The file will be removed. - Do not use: hexdigit(), error_ptr(), error_descrition() and it_error() + Do not use: hexdigit(), error_ptr(), error_descrition() and it_error() * lh_abort() is deprecated. It will be removed. Behavior changes: @@ -38,7 +274,7 @@ Behavior changes: * Use size_t for array length and size. Platforms where sizeof(size_t) != sizeof(int) may not be backwards compatible See commits 45c56b, 92e9a5 and others. -* Check for failue when allocating memory, returning NULL and errno=ENOMEM. +* Check for failure when allocating memory, returning NULL and errno=ENOMEM. See commit 2149a04. * Change json_object_object_add() return type from void to int, and will return -1 on failures, instead of exiting. (Note: this is not an ABI change) @@ -169,11 +405,11 @@ List of new functions added: * Make the json_tokener_errors array local. It has been deprecated for a while, and json_tokener_error_desc() should be used instead. - * change the floating point output format to %.17g so values with + * change the floating point output format to %.17g so values with more than 6 digits show up in the output. * Remove the old libjson.so name compatibility support. The library is - only created as libjson-c.so now and headers are only installed + only created as libjson-c.so now and headers are only installed into the ${prefix}/json-c directory. * When supported by the linker, add the -Bsymbolic-functions flag. @@ -229,7 +465,7 @@ List of new functions added: * Add an alternative iterator implementation, see json_object_iterator.h * Make json_object_iter public to enable external use of the json_object_object_foreachC macro. - * Add a printbuf_memset() function to provide an effecient way to set and + * Add a printbuf_memset() function to provide an efficient way to set and append things like whitespace indentation. * Adjust json_object_is_type and json_object_get_type so they return json_type_null for NULL objects and handle NULL passed to @@ -239,7 +475,7 @@ List of new functions added: * Allow json_tokener_parse_ex() to be re-used to parse multiple object. Also, fix some parsing issues with capitalized hexadecimal numbers and number in E notation. - * Add json_tokener_get_error() and json_tokener_error_desc() to better + * Add json_tokener_get_error() and json_tokener_error_desc() to better encapsulate the process of retrieving errors while parsing. * Various improvements to the documentation of many functions. * Add new json_object_array_sort() function. @@ -286,7 +522,7 @@ List of new functions added: Brent Miller, bdmiller at yahoo dash inc dot com * Disable REFCOUNT_DEBUG by default in json_object.c * Don't use this as a variable, so we can compile with a C++ compiler - * Add casts from void* to type of assignment when using malloc + * Add casts from void* to type of assignment when using malloc * Add #ifdef __cplusplus guards to all of the headers * Add typedefs for json_object, json_tokener, array_list, printbuf, lh_table Michael Clark, @@ -315,14 +551,14 @@ List of new functions added: 0.7 === * Add escaping of backslash to json output - * Add escaping of foward slash on tokenizing and output + * Add escaping of forward slash on tokenizing and output * Changes to internal tokenizer from using recursion to using a depth state structure to allow incremental parsing 0.6 === * Fix bug in escaping of control characters - Johan Bjrklund, johbjo09 at kth dot se + Johan Björklund, johbjo09 at kth dot se * Remove include "config.h" from headers (should only be included from .c files) Michael Clark @@ -370,13 +606,13 @@ List of new functions added: Added a Win32/Win64 compliant implementation of strndup * json_util.c - C. Watford (christopher.watford@gmail.com) Added cast and mask to suffice size_t v. unsigned int conversion - correctness + correctness * json_tokener.c - sign reversal issue on error info for nested object parse - spotted by Johan Bjrklund (johbjo09 at kth.se) + spotted by Johan Björklund (johbjo09 at kth.se) * json_object.c - escape " in json_escape_str * Change to automake and libtool to build shared and static library Michael Clark - + 0.1 === * initial release diff --git a/third_party/json-c/INSTALL b/third_party/json-c/INSTALL index 5fb10a02c..d8575d3fb 100644 --- a/third_party/json-c/INSTALL +++ b/third_party/json-c/INSTALL @@ -1,3 +1,2 @@ See README.md for installation instructions. - diff --git a/third_party/json-c/Makefile.am b/third_party/json-c/Makefile.am index d1be24acf..a65c89c4a 100644 --- a/third_party/json-c/Makefile.am +++ b/third_party/json-c/Makefile.am @@ -4,55 +4,33 @@ SUBDIRS = . noinst_LTLIBRARIES = libjson-c.la -# Don't install pkgconfig data -#pkgconfigdir = $(libdir)/pkgconfig -#pkgconfig_DATA = json-c.pc - -# Comment out header installation -#libjson_cincludedir = $(includedir)/json-c -#libjson_cinclude_HEADERS = \ -# arraylist.h \ -# bits.h \ -# debug.h \ -# json.h \ -# json_c_version.h \ -# json_config.h \ -# json_inttypes.h \ -# json_object.h \ -# json_object_iterator.h \ -# json_pointer.h \ -# json_tokener.h \ -# json_util.h \ -# json_visit.h \ -# linkhash.h \ -# printbuf.h - -noinst_HEADERS=\ - json_object_private.h \ - math_compat.h \ - strdup_compat.h \ - snprintf_compat.h \ - vasprintf_compat.h \ - random_seed.h \ - strerror_override.h \ +# Headers (public) - from Meson config +noinst_HEADERS = \ arraylist.h \ - bits.h \ debug.h \ json.h \ json_c_version.h \ - json_config.h \ json_inttypes.h \ json_object.h \ json_object_iterator.h \ json_pointer.h \ json_tokener.h \ + json_types.h \ json_util.h \ json_visit.h \ linkhash.h \ - printbuf.h - -libjson_c_la_LDFLAGS = -no-undefined -no-install + printbuf.h \ + json_patch.h \ + json_object_private.h \ + json_pointer_private.h \ + math_compat.h \ + strdup_compat.h \ + snprintf_compat.h \ + vasprintf_compat.h \ + random_seed.h \ + strerror_override.h +# Sources (from Meson config) libjson_c_la_SOURCES = \ arraylist.c \ debug.c \ @@ -66,12 +44,12 @@ libjson_c_la_SOURCES = \ linkhash.c \ printbuf.c \ random_seed.c \ - strerror_override.c \ - strerror_override_private.h + strerror_override.c +libjson_c_la_LDFLAGS = -no-undefined -DISTCLEANFILES= -DISTCLEANFILES+= \ +# Clean files +DISTCLEANFILES = \ config.h \ json-c-uninstalled.pc \ json-c.pc \ @@ -80,33 +58,3 @@ DISTCLEANFILES+= \ distclean-local: -rm -rf $(testsubdir) -JSON_CLEANFILES= -JSON_CLEANFILES+= \ - Makefile.in \ - aclocal.m4 \ - autom4te.cache/ \ - compile \ - config.guess \ - config.h.in \ - config.sub \ - configure \ - depcomp \ - install-sh \ - ltmain.sh \ - missing \ - test-driver \ - tests/Makefile.in -JSON_CLEANFILES+= \ - libtool \ - stamp-h1 \ - stamp-h2 - -# There's no built-in way to remove these after all the other -# maintainer-clean steps happen, so do it explicitly here. -really-clean: - $(MAKE) maintainer-clean - rm -rf ${JSON_CLEANFILES} - -uninstall-local: - rm -rf "$(DESTDIR)@includedir@/json-c" - rm -f "$(DESTDIR)@includedir@/json" diff --git a/third_party/json-c/README.html b/third_party/json-c/README.html index d36156952..483e4075b 100644 --- a/third_party/json-c/README.html +++ b/third_party/json-c/README.html @@ -8,8 +8,8 @@

JSON-C - A JSON implementation in C

Overview

-

JSON-C implements a reference counting object model that allows you to easily - construct JSON objects in C, output them as JSON formatted strings and parse +

JSON-C implements a reference counting object model that allows you to easily + construct JSON objects in C, output them as JSON formatted strings and parse JSON formatted strings back into the C representation of JSON objects. It aims to conform to RFC 7159.

@@ -26,13 +26,12 @@

Building

Documentation

-

Doxygen generated documentation exists here - and Win32 specific notes can be found here.

+

Doxygen generated documentation exists here.

GIT Reposository

git clone https://github.com/json-c/json-c.git

-

Mailing List

+

Mailing List

Send email to json-c <at> googlegroups <dot> com

License

diff --git a/third_party/json-c/README.md b/third_party/json-c/README.md index 1441e933e..04ac67f4b 100644 --- a/third_party/json-c/README.md +++ b/third_party/json-c/README.md @@ -1,140 +1,266 @@ -`json-c` {#mainpage} +\mainpage + +`json-c` ======== 1. [Overview and Build Status](#overview) -2. [Building on Unix](#buildunix) -3. [Install Prerequisites](#installprereq) -4. [Building with partial threading support](#buildthreaded) -5. [Linking to libjson-c](#linking) -6. [Using json-c](#using) +2. [Getting Help](#gettinghelp) +3. [Building on Unix](#buildunix) + * [Prerequisites](#installprereq) + * [Build commands](#buildcmds) +4. [CMake options](#CMake) +5. [Testing](#testing) +6. [Building with `vcpkg`](#buildvcpkg) +7. [Building for Android](#android) +7. [Linking to libjson-c](#linking) +8. [Using json-c](#using) JSON-C - A JSON implementation in C ----------------------------------- -Build Status -* [AppVeyor Build](https://ci.appveyor.com/project/hawicz/json-c) ![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/json-c/json-c?branch=master&svg=true) -* [Travis Build](https://travis-ci.org/json-c/json-c) ![Travis Build Status](https://travis-ci.org/json-c/json-c.svg?branch=master) - -JSON-C implements a reference counting object model that allows you to easily -construct JSON objects in C, output them as JSON formatted strings and parse +JSON-C implements a reference counting object model that allows you to easily +construct JSON objects in C, output them as JSON formatted strings and parse JSON formatted strings back into the C representation of JSON objects. -It aims to conform to [RFC 7159](https://tools.ietf.org/html/rfc7159). - +It aims to conform to [RFC 8259](https://www.rfc-editor.org/rfc/rfc8259). -Building on Unix with `git`, `gcc` and `autotools` --------------------------------------------------- +Skip down to [Using json-c](#using) +or check out the [API docs](https://json-c.github.io/json-c/), +if you already have json-c installed and ready to use. Home page for json-c: https://github.com/json-c/json-c/wiki -### Prerequisites: +Getting Help +------------ -See also the "Installing prerequisites" section below. +If you have questions about using json-c, please start a thread on +our forums at: https://groups.google.com/forum/#!forum/json-c - - `gcc`, `clang`, or another C compiler - - `libtool>=2.2.6b` +If you believe you've discovered a bug, report it at +(https://github.com/json-c/json-c/issues). Please be sure to include +the version of json-c you're using, the OS you're running on, and any +other relevant details. Fully reproducible test cases and/or patches +to fix problems are greatly appreciated. -If you're not using a release tarball, you'll also need: +Fixes for bugs, or small new features can be directly submitted as a +[pull request](https://github.com/json-c/json-c/pulls). For major new +features or large changes of any kind, please first start a discussion +on the [forums](https://groups.google.com/forum/#!forum/json-c). - - `autoconf>=2.64` (`autoreconf`) - - `automake>=1.13` -Make sure you have a complete `libtool` install, including `libtoolize`. +Building on Unix with `git`, `gcc` and `cmake` +-------------------------------------------------- -To generate docs (e.g. as part of make distcheck) you'll also need: - - `doxygen>=1.8.13` +If you already have json-c installed, see [Linking to `libjson-c`](#linking) +for how to build and link your program against it. -### Build instructions: +Build Status +* [AppVeyor Build](https://ci.appveyor.com/project/hawicz/json-c) ![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/json-c/json-c?branch=master&svg=true) +* [Travis Build](https://app.travis-ci.com/github/json-c/json-c) ![Travis Build Status](https://api.travis-ci.com/json-c/json-c.svg?branch=master) -`json-c` GitHub repo: https://github.com/json-c/json-c +Test Status +* [Coveralls](https://coveralls.io/github/json-c/json-c?branch=master) [![Coverage Status](https://coveralls.io/repos/github/json-c/json-c/badge.svg?branch=master)](https://coveralls.io/github/json-c/json-c?branch=master) -```sh -$ git clone https://github.com/json-c/json-c.git -$ cd json-c -$ sh autogen.sh -``` +### Prerequisites: + + - `gcc`, `clang`, or another C compiler -followed by + - `cmake>=2.8`, `>=3.16` recommended, `cmake=>3.1` for tests + +To generate docs you'll also need: + - `doxygen>=1.8.13` +If you are on a relatively modern system, you'll likely be able to install +the prerequisites using your OS's packaging system. + +### Install using apt (e.g. Ubuntu 16.04.2 LTS) ```sh -$ ./configure # --enable-threading -$ make -$ make install +sudo apt install git +sudo apt install cmake +sudo apt install doxygen # optional +sudo apt install valgrind # optional ``` -To build and run the test programs: +### Build instructions: + +`json-c` GitHub repo: https://github.com/json-c/json-c ```sh -$ make check -$ make USE_VALGRIND=0 check # optionally skip using valgrind +$ git clone https://github.com/json-c/json-c.git +$ mkdir json-c-build +$ cd json-c-build +$ cmake ../json-c # See CMake section below for custom arguments ``` -Install prerequisites ------------------------ +Note: it's also possible to put your build directory inside the json-c +source directory, or even not use a separate build directory at all, but +certain things might not work quite right (notably, `make distcheck`) -If you are on a relatively modern system, you'll likely be able to install -the prerequisites using your OS's packaging system. +Then: -### Install using apt (e.g. Ubuntu 16.04.2 LTS) ```sh -sudo apt install git -sudo apt install autoconf automake libtool -sudo apt install valgrind # optional +$ make +$ make test +$ make USE_VALGRIND=0 test # optionally skip using valgrind +$ sudo make install # it could be necessary to execute make install ``` -Then start from the "git clone" command, above. -### Manually install and build autoconf, automake and libtool +### Generating documentation with Doxygen: -For older OS's that don't have up-to-date version of the packages will -require a bit more work. For example, CentOS release 5.11, etc... +The library documentation can be generated directly from the source code using Doxygen tool: ```sh -curl -O http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz -curl -O http://ftp.gnu.org/gnu/automake/automake-1.15.tar.gz -curl -O http://ftp.gnu.org/gnu/libtool/libtool-2.2.6b.tar.gz +# in build directory +make doc +google-chrome doc/html/index.html +``` -tar xzf autoconf-2.69.tar.gz -tar xzf automake-1.15.tar.gz -tar xzf libtool-2.2.6b.tar.gz -export PATH=${HOME}/ac_install/bin:$PATH +CMake Options +-------------------- -(cd autoconf-2.69 && \ - ./configure --prefix ${HOME}/ac_install && \ - make && \ - make install) +The json-c library is built with [CMake](https://cmake.org/cmake-tutorial/), +which can take a few options. -(cd automake-1.15 && \ - ./configure --prefix ${HOME}/ac_install && \ - make && \ - make install) +Variable | Type | Description +-----------------------------|--------|-------------- +CMAKE_INSTALL_PREFIX | String | The install location. +CMAKE_BUILD_TYPE | String | Defaults to "debug". +BUILD_SHARED_LIBS | Bool | The default build generates a dynamic (dll/so) library. Set this to OFF to create a static library only. +BUILD_STATIC_LIBS | Bool | The default build generates a static (lib/a) library. Set this to OFF to create a shared library only. +DISABLE_STATIC_FPIC | Bool | The default builds position independent code. Set this to OFF to create a shared library only. +DISABLE_BSYMBOLIC | Bool | Disable use of -Bsymbolic-functions. +DISABLE_THREAD_LOCAL_STORAGE | Bool | Disable use of Thread-Local Storage (HAVE___THREAD). +DISABLE_WERROR | Bool | Disable use of -Werror. +DISABLE_EXTRA_LIBS | Bool | Disable use of extra libraries, libbsd +DISABLE_JSON_POINTER | Bool | Omit json_pointer support from the build. +ENABLE_RDRAND | Bool | Enable RDRAND Hardware RNG Hash Seed. +ENABLE_THREADING | Bool | Enable partial threading support. +OVERRIDE_GET_RANDOM_SEED | String | A block of code to use instead of the default implementation of json_c_get_random_seed(), e.g. on embedded platforms where not even the fallback to time() works. Must be a single line. -(cd libtool-2.2.6b && \ - ./configure --prefix ${HOME}/ac_install && \ - make && \ - make install) -``` +Pass these options as `-D` on CMake's command-line. +```sh +# build a static library only +cmake -DBUILD_SHARED_LIBS=OFF .. +``` -Building with partial threading support ----------------------------------------- +### Building with partial threading support Although json-c does not support fully multi-threaded access to -object trees, it has some code to help make use in threaded programs +object trees, it has some code to help make its use in threaded programs a bit safer. Currently, this is limited to using atomic operations for json_object_get() and json_object_put(). Since this may have a performance impact, of at least 3x slower according to https://stackoverflow.com/a/11609063, it is disabled by -default. You may turn it on by adjusting your configure command with: - --enable-threading +default. You may turn it on by adjusting your cmake command with: + -DENABLE_THREADING=ON Separately, the default hash function used for object field keys, -lh_char_hash, uses a compare-and-swap operation to ensure the randomly +lh_char_hash, uses a compare-and-swap operation to ensure the random seed is only generated once. Because this is a one-time operation, it is always compiled in when the compare-and-swap operation is available. +### cmake-configure wrapper script + +For those familiar with the old autoconf/autogen.sh/configure method, +there is a `cmake-configure` wrapper script to ease the transition to cmake. + +```sh +mkdir build +cd build +../cmake-configure --prefix=/some/install/path +make +``` + +cmake-configure can take a few options. + +| options | Description| +| ---- | ---- | +| prefix=PREFIX | install architecture-independent files in PREFIX | +| enable-threading | Enable code to support partly multi-threaded use | +| enable-rdrand | Enable RDRAND Hardware RNG Hash Seed generation on supported x86/x64 platforms. | +| enable-shared | build shared libraries [default=yes] | +| enable-static | build static libraries [default=yes] | +| disable-Bsymbolic | Avoid linking with -Bsymbolic-function | +| disable-werror | Avoid treating compiler warnings as fatal errors | + + +Testing: +---------- + +By default, if valgrind is available running tests uses it. +That can slow the tests down considerably, so to disable it use: +```sh +export USE_VALGRIND=0 +``` + +To run tests a separate build directory is recommended: +```sh +mkdir build-test +cd build-test +# VALGRIND=1 causes -DVALGRIND=1 to be passed when compiling code +# which uses slightly slower, but valgrind-safe code. +VALGRIND=1 cmake .. +make + +make test +# By default, if valgrind is available running tests uses it. +make USE_VALGRIND=0 test # optionally skip using valgrind +``` + +If a test fails, check `Testing/Temporary/LastTest.log`, +`tests/testSubDir/${testname}/${testname}.vg.out`, and other similar files. +If there is insufficient output try: +```sh +VERBOSE=1 CTEST_OUTPUT_ON_FAILURE=1 make test +``` +or +```sh +JSONC_TEST_TRACE=1 make test +``` +and check the log files again. + + +Building on Unix and Windows with `vcpkg` +-------------------------------------------------- + +You can download and install JSON-C using the [vcpkg](https://github.com/Microsoft/vcpkg/) dependency manager: + + git clone https://github.com/Microsoft/vcpkg.git + cd vcpkg + ./bootstrap-vcpkg.sh + ./vcpkg integrate install + vcpkg install json-c + +The JSON-C port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please [create an issue or pull request](https://github.com/Microsoft/vcpkg) on the vcpkg repository. + +Building for Android +---------------------- + +Building on Android is now particularly well supported, but there +have been some reports of success using +https://developer.android.com/ndk/guides/cmake + +``` +mkdir json-c-build +cd json-c-build/ +export NDK_HOME=~/Library/Android/sdk/ndk/22.1.7171670/ +cmake \ + --toolchain=$NDK_HOME/build/cmake/android.toolchain.cmake \ + -DANDROID_STL=none \ + -DANDROID_ABI=arm64-v8a \ + -DANDROID_PLATFORM=android-29 \ + -DANDROID_LD=lld \ + -DCMAKE_BUILD_TYPE=MinSizeRel \ + -DCMAKE_INSTALL_PREFIX= \ + -DENABLE_THREADING=true \ + .. +make install +``` + Linking to `libjson-c` ---------------------- @@ -146,28 +272,74 @@ CFLAGS += $(shell pkg-config --cflags json-c) LDFLAGS += $(shell pkg-config --libs json-c) ``` -Without `pkgconfig`, you would do something like this: +Without `pkgconfig`, you might do something like this: ```make JSON_C_DIR=/path/to/json_c/install CFLAGS += -I$(JSON_C_DIR)/include/json-c +# Or to use lines like: #include +#CFLAGS += -I$(JSON_C_DIR)/include LDFLAGS+= -L$(JSON_C_DIR)/lib -ljson-c ``` +If your project uses cmake: + +* Add to your CMakeLists.txt file: + +```cmake +find_package(json-c CONFIG) +target_link_libraries(${PROJECT_NAME} PRIVATE json-c::json-c) +``` + +* Then you might run in your project: + +```sh +cd build +cmake -DCMAKE_PREFIX_PATH=/path/to/json_c/install/lib64/cmake .. +``` Using json-c ------------ -To use json-c you can either include json.h, or preferrably, one of the +To use json-c you can either include json.h, or preferably, one of the following more specific header files: * json_object.h - Core types and methods. * json_tokener.h - Methods for parsing and serializing json-c object trees. * json_pointer.h - JSON Pointer (RFC 6901) implementation for retrieving objects from a json-c object tree. -* json_object_iterator.h - Methods for iterating over single json_object instances. +* json_object_iterator.h - Methods for iterating over single json_object instances. (See also `json_object_object_foreach()` in json_object.h) * json_visit.h - Methods for walking a tree of json-c objects. -* json_util.h - Miscelleanous utility functions. - -For a full list of headers see [files.html](files.html) +* json_util.h - Miscellaneous utility functions. + +For a full list of headers see [files.html](https://json-c.github.io/json-c/json-c-current-release/doc/html/files.html) + +The primary type in json-c is json_object. It describes a reference counted +tree of json objects which are created by either parsing text with a +json_tokener (i.e. `json_tokener_parse_ex()`), or by creating +(with `json_object_new_object()`, `json_object_new_int()`, etc...) and adding +(with `json_object_object_add()`, `json_object_array_add()`, etc...) them +individually. +Typically, every object in the tree will have one reference, from its parent. +When you are done with the tree of objects, you call json_object_put() on just +the root object to free it, which recurses down through any child objects +calling json_object_put() on each one of those in turn. + +You can get a reference to a single child +(`json_object_object_get()` or `json_object_array_get_idx()`) +and use that object as long as its parent is valid. +If you need a child object to live longer than its parent, you can +increment the child's refcount (`json_object_get()`) to allow it to survive +the parent being freed or it being removed from its parent +(`json_object_object_del()` or `json_object_array_del_idx()`) + +When parsing text, the json_tokener object is independent from the json_object +that it returns. It can be allocated (`json_tokener_new()`) +used one or multiple times (`json_tokener_parse_ex()`, and +freed (`json_tokener_free()`) while the json_object objects live on. + +A json_object tree can be serialized back into a string with +`json_object_to_json_string_ext()`. The string that is returned +is only valid until the next "to_json_string" call on that same object. +Also, it is freed when the json_object is freed. diff --git a/third_party/json-c/RELEASE_CHECKLIST.txt b/third_party/json-c/RELEASE_CHECKLIST.txt index 28cb97304..8720c3e5a 100644 --- a/third_party/json-c/RELEASE_CHECKLIST.txt +++ b/third_party/json-c/RELEASE_CHECKLIST.txt @@ -1,81 +1,130 @@ -Release checklist: - -release=0.13 -git clone https://github.com/json-c/json-c json-c-${release} -cd json-c-${release} - -Check that the compile works on Linux -Check that the compile works on NetBSD -Check that the compile works on Windows -Run "make distcheck" and fix any problems - (e.g. adding new files to SOURCES variables in Makefile.am) -Check ChangeLog to see if anything should be added. +# Release checklist: + +## Pre-release tasks + +* Figure out whether a release is worthwhile to do. +* Analyze the previous release branch to see if anything should have been + applied to master. +* Collect changes and assemble tentative release notes. + * Identify previous release branch point + * Check commit logs between previous branch point and now for + notable changes worth mentioning + * Create a new issues_closed_for_X.Y.md file + * Include notable entries from here in the release notes. + * Analyze APIs between previous release branch and master to produce list of + changes (added/removed/updated funcs, etc...), and detect backwards compat + issues. + * https://github.com/lvc/abi-compliance-checker + * See also `abi-check.sh` + * If the new release is not backwards compatible, then this is a MAJOR release. + * Mention removed features in ChangeLog + * Consider re-adding backwards compatible support, through symbol + aliases and appropriate entries in json-c.sym + * Be sure any new symbols are listed in json-c.sym as part of + the _new_ release version. + * Update the AUTHORS file + + PREV=$(git tag | tail -1) + ( git log -r ${PREV}..HEAD | grep Author: | sed -e's/Author: //' ; cat AUTHORS ) | sort -u > A1 + mv A1 AUTHORS + + * Exclude mentioning changes that have already been included in a point + release of the previous release branch. + +* Update ChangeLog with relevant notes before branching. + +* Check that the compile works on Linux - automatic through Travis +* Check that the compile works on NetBSD +* Check that the compile works on Windows - automatic through AppVeyor + +## Release creation + +Start creating the new release: + + PREV=$(git tag | tail -1) + PREV=${PREV#json-c-} + PREV=${PREV%-*} + release=0.$((${PREV#*.} + 1)) + cd ~ + git clone https://github.com/json-c/json-c json-c-${release} + + rm -rf distcheck + mkdir distcheck + cd distcheck + # Note, the build directory *must* be entirely separate from + # the source tree for distcheck to work properly. + cmake -DCMAKE_BUILD_TYPE=Release ../json-c-${release} + make distcheck + cd .. + Make any fixes/changes *before* branching. - git branch json-c-${release} - git checkout json-c-${release} + cd json-c-${release} + git checkout -b json-c-${release} ------------ -Update the version in json_c_version.h -Update the version in Doxyfile -Update the version in configure.ac -Update the version in CMakeLists.txt - Use ${release}. - -Update the libjson_la_LDFLAGS line in Makefile.am to the new version. - Generally, unless we're doing a major release, change: - -version-info x:y:z - to - -version-info x:y+1:z +Using ${release}: + Update the version in json_c_version.h + Update the version in CMakeLists.txt (VERSION in the project(...) line) ------------- +Update the set_target_properties() line in CmakeLists.txt to set the shared +library version. Generally, unless we're doing a major release, change: + VERSION x.y.z +to + VERSION x.y+1.z -Generate the configure script and other files: - sh autogen.sh - git add -f Makefile.in aclocal.m4 config.guess config.h.in \ - config.sub configure depcomp install-sh \ - ltmain.sh missing tests/Makefile.in \ - INSTALL + git commit -a -m "Bump version to ${release}" - # check for anything else to be added: - git status --ignored - git commit +If we're doing a major release (SONAME bump), also bump the version + of ALL symbols in json-c.sym. + See explanation at https://github.com/json-c/json-c/issues/621 + More info at: https://software.intel.com/sites/default/files/m/a/1/e/dsohowto.pdf ------------ Generate the doxygen documentation: - doxygen - git add -f doc - git commit doc + + (cd ../distcheck && make doc) + cp -r -p ../distcheck/doc/{html,Doxyfile} doc/. + rm doc/Doxyfile # Remove generated file w/ hardcoded paths + git add -f doc + git commit doc -m "Generate docs for the ${release} release" ------------ -cd .. -echo .git > excludes -echo autom4te.cache >> excludes -tar -czf json-c-${release}.tar.gz -X excludes json-c-${release} +Create the release tarballs: + + cd .. + echo .git > excludes + tar -czf json-c-${release}.tar.gz -X excludes json-c-${release} -echo doc >> excludes -tar -czf json-c-${release}-nodoc.tar.gz -X excludes json-c-${release} + echo 'doc/*.cmake' >> excludes + echo 'doc/CMakeFiles' >> excludes + echo 'doc/Makefile' >> excludes + echo 'doc/Doxyfile' >> excludes + echo 'doc/html' >> excludes + tar -czf json-c-${release}-nodoc.tar.gz -X excludes json-c-${release} ------------ Tag the branch: -cd json-c-${release} -git tag -a json-c-${release}-$(date +%Y%m%d) -m "Release json-c-${release}" -git push origin json-c-${release} -git push --tags + cd json-c-${release} + git tag -a json-c-${release}-$(date +%Y%m%d) -m "Release json-c-${release}" + + git push origin json-c-${release} + git push --tags ------------ Go to Amazon S3 service at: https://console.aws.amazon.com/s3/ -Upload the two tarballs in the json-c_releases folder. - When uploading, use "Reduced Redundancy", and make the uploaded files publicly accessible. +Upload the two tarballs in the json-c_releases/releases folder. +* Expand "Permissions", pick "Grant public-read access" +* Expand "Properties", ensure "Standard" storage class is picked. Logout of Amazon S3, and verify that the files are visible. https://s3.amazonaws.com/json-c_releases/releases/index.html @@ -84,53 +133,59 @@ Logout of Amazon S3, and verify that the files are visible. Post-release checklist: -git checkout master -Add new section to ChangeLog -Update the version in json_c_version.h -Update the version in Doxyfile -Update the version in configure.ac -Update the version in CMakeLists.txt - Use ${release}.99 to indicate a version "newer" than anything on the branch. + git checkout master -Leave the libjson_la_LDFLAGS line in Makefile.am alone. - For more details see: - http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html +Add new section to ChangeLog for ${release}+1 + +Use ${release}.99 to indicate a version "newer" than anything on the branch: + Update the version in json_c_version.h + Update the version in CMakeLists.txt + +Update RELEASE_CHECKLIST.txt, set release=${release}+1 + +Add a new empty section to the json-c.sym file, for ${release}+1 + +Update the set_target_properties() line in CmakeLists.txt to match the release branch. + + git commit -a -m "Update the master branch to version ${release}.99" + git push ------------ Update the gh-pages branch with new docs: -cd json-c-${release} -git checkout json-c-${release} -cd .. + cd json-c-${release} + git checkout json-c-${release} + cd .. -git clone -b gh-pages https://github.com/json-c/json-c json-c-pages -cd json-c-pages -mkdir json-c-${release} -cp -R ../json-c-${release}/doc json-c-${release}/. -cp ../json-c-${release}/README-WIN32.html json-c-${release}/. -git add json-c-${release} -git commit + git clone -b gh-pages https://github.com/json-c/json-c json-c-pages + cd json-c-pages + mkdir json-c-${release} + cp -R ../json-c-${release}/doc json-c-${release}/. + git add json-c-${release} + rm json-c-current-release + ln -s json-c-${release} json-c-current-release + git commit -a -m "Add the ${release} docs." -vi index.html - Add/change links to current release. + vi index.html + # Add/change links to current release. -git commit index.html + git commit -a -m "Update the doc links to point at ${release}" -git push + git push ------------ Update checksums on wiki page. -cd .. -openssl sha -sha256 json-c*gz -openssl md5 json-c*gz + cd .. + openssl sha -sha256 json-c*gz + openssl md5 json-c*gz Copy and paste this output into the wiki page at: - https://github.com/json-c/json-c/wiki +* https://github.com/json-c/json-c/wiki +* https://github.com/json-c/json-c/wiki/Old-Releases ------------ Send an email to the mailing list. - diff --git a/third_party/json-c/STYLE.txt b/third_party/json-c/STYLE.txt old mode 100755 new mode 100644 index e5acd1482..4e5d75ac5 --- a/third_party/json-c/STYLE.txt +++ b/third_party/json-c/STYLE.txt @@ -1,31 +1,31 @@ -In general: -For minor changes to a function, copy the existing formatting. -When changing the style, commit that separately from other changes. -For new code and major changes to a function, switch to the official json-c style. - -Official json-c style: -Aim for readability, not strict conformance to fixed style rules. -These rules are not comprehensive. Look to existing code for guidelines. -Indentation is tab based, with continuations of long lines starting with tabs then spaces for alignment. -Try to line up components of continuation lines with corresponding part of the line above (i.e. "indent -lp" effect), but avoid excessive identation tha causes extra line wraps. - e.g. (T=tab, S=space): -TTTTsome_long_func_call(arg1, arg2, -TTTTSSSSSSSSSSSSSSSSSSSarg3, arg4); -TTTTsome_reallly_really_long_func_name(arg1, -TTTTTarg2, arg3, arg4); -There should be a space between "if"/"while" and the following parenthesis. -"case" lines are indented at the same level as the "switch" statement. -Commas are followed by a single space. -Include spaces around most non-unary, non-postfix operators, "=", "==', "&", "||", etc... -Function calls have no space between the name and the parenthesis. -Curly braces go on their own line. -Curly braces may be omitted. - -Naming: -Words within function and variable names are separated with underscores. Avoid camel case. -Prefer longer, more descriptive names, but not excessively so. No single letter variable names. - -Other: -Variables should be defined for the smallest scope needed. -Functions should be defined static when possible. -When possible, avoid exposing internals in the public API. +In general: +For minor changes to a function, copy the existing formatting. +When changing the style, commit that separately from other changes. +For new code and major changes to a function, switch to the official json-c style. + +Official json-c style: + +Aim for readability, not strict conformance to fixed style rules. +Formatting is tab based; previous attempts at proper alignment with +spaces for continuation lines have been abandoned in favor of the +convenience of using clang-format. +Refer to the .clang-format file for details, and run the tool before commit: + + clang-format -i somefile.c foo.h + +For sections of code that would be significantly negatively impacted, surround +them with magic comments to disable formatting: + + /* clang-format off */ + ...code... + /* clang-format on */ + + +Naming: +Words within function and variable names are separated with underscores. Avoid camel case. +Prefer longer, more descriptive names, but not excessively so. No single letter variable names. + +Other: +Variables should be defined for the smallest scope needed. +Functions should be defined static when possible. +When possible, avoid exposing internals in the public API. diff --git a/third_party/json-c/abi-check.sh b/third_party/json-c/abi-check.sh new file mode 100644 index 000000000..6dab54a89 --- /dev/null +++ b/third_party/json-c/abi-check.sh @@ -0,0 +1,42 @@ +#!/bin/sh + +prev=0.16 +release=0.17 + +# ... clone json-c, abi-compliance-checker, abi-dumper + +mkdir build +cd build +CFLAGS=-Og cmake -DCMAKE_INSTALL_PREFIX=~/json-c-installs/json-c-${release} .. +make && make test && make install + +# Assume the old version has already been built + +cd ~/abi-compliance-checker +mkxml() +{ + ver="$1" +cat < json-c-${ver}.xml + + + ${ver} + + + +../json-c-installs/json-c-${ver}/include/json-c + + + +../json-c-installs/json-c-${ver}/lib64/libjson-c.so + + +EOF +} +mkxml ${release} +mkxml ${prev} + +perl abi-compliance-checker.pl -lib json-c -dump json-c-${prev}.xml -dump-path ./ABI-${prev}.dump +perl abi-compliance-checker.pl -lib json-c -dump json-c-${release}.xml -dump-path ./ABI-${release}.dump +perl abi-compliance-checker.pl -l json-c -old ABI-${prev}.dump -new ABI-${release}.dump + +echo "look in compat_reports/json-c/..." diff --git a/third_party/json-c/appveyor.yml b/third_party/json-c/appveyor.yml index 72b133195..e0349f6b2 100644 --- a/third_party/json-c/appveyor.yml +++ b/third_party/json-c/appveyor.yml @@ -1,39 +1,125 @@ -version: '{branch}.{build}' -os: Windows Server 2012 R2 - -configuration: -- Debug -- Release -platform: x64 -environment: - matrix: - - PlatformToolset: v140 - - PlatformToolset: v120 - - PlatformToolset: Windows7.1SDK - -build_script: -- cmake . -- > - msbuild "json-c.vcxproj" /m /verbosity:normal - /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" - /p:PlatformToolset=%PlatformToolset% /p:OutDir=lib\ - -after_build: -- md include\json-c -- copy json.h include\json-c\* -- copy debug.h include\json-c\* -- copy linkhash.h include\json-c\* -- copy arraylist.h include\json-c\* -- copy json_util.h include\json-c\* -- copy json_object.h include\json-c\* -- copy json_tokener.h include\json-c\* -- copy json_object_iterator.h include\json-c\* -- copy json_c_version.h include\json-c\* -- copy json_inttypes.h include\json-c\* -- copy include\json_config.h include\json-c\* -- copy json_object_private.h include\json-c\* -- 7z a json-c.lib.zip lib\json-c.dll include\json-c\*.h - -artifacts: -- path: json-c.lib.zip - name: json-c.lib.zip +version: '{branch}.{build}' + +image: +# b_toolset: v143 + - Visual Studio 2022 + + # VS2015 also used for earlier VS builds + # aka os: Windows Server 2012 R2 + - Visual Studio 2015 + + # aka os: Windows Server 2016 +# b_toolset: v141 + - Visual Studio 2017 + + # aka os: Windows Server 2019 +# b_toolset: v142 + - Visual Studio 2019 + +platform: x64 + +environment: + matrix: + - b_toolset: Windows7.1SDK + + - b_toolset: v120 + + - b_toolset: v140 + + - b_toolset: v141 + + - b_toolset: v142 + + - b_toolset: v143 + +configuration: + - Debug + - Release + +build_script: +- cmake -T %b_toolset% -DCMAKE_BUILD_TYPE=%CONFIGURATION% -DCMAKE_INSTALL_PREFIX=t_install . +- cmake --build . --target install + +matrix: + exclude: + # Skip release builds for all except the newest image + - image: Visual Studio 2015 + configuration: Release + + # In the "old" image, new toolsets aren't available: + - image: Visual Studio 2015 + b_toolset: v141 + + - image: Visual Studio 2015 + b_toolset: v142 + + - image: Visual Studio 2015 + b_toolset: v143 + + # ---- + + - image: Visual Studio 2017 + configuration: Release + + # In the "new" images, exclude all toolsets except the relevant + # one for that image: + + - image: Visual Studio 2017 + b_toolset: Windows7.1SDK + + - image: Visual Studio 2017 + b_toolset: v120 + + - image: Visual Studio 2017 + b_toolset: v140 + + - image: Visual Studio 2017 + b_toolset: v142 + + - image: Visual Studio 2017 + b_toolset: v143 + + # ---- + + - image: Visual Studio 2019 + configuration: Release + + - image: Visual Studio 2019 + b_toolset: Windows7.1SDK + + - image: Visual Studio 2019 + b_toolset: v120 + + - image: Visual Studio 2019 + b_toolset: v140 + + - image: Visual Studio 2019 + b_toolset: v141 + + - image: Visual Studio 2019 + b_toolset: v143 + + # ---- + + - image: Visual Studio 2022 + b_toolset: Windows7.1SDK + + - image: Visual Studio 2022 + b_toolset: v120 + + - image: Visual Studio 2022 + b_toolset: v140 + + - image: Visual Studio 2022 + b_toolset: v141 + + - image: Visual Studio 2022 + b_toolset: v142 + +after_build: +- cd t_install +- 7z a ../json-c.win32.%b_toolset%.%CONFIGURATION%.zip * + +artifacts: +- path: json-c.win32.%b_toolset%.%CONFIGURATION%.zip + name: json-c.win32.%b_toolset%.%CONFIGURATION%.zip diff --git a/third_party/json-c/arraylist.c b/third_party/json-c/arraylist.c index ddeb8d4eb..7138e9f85 100644 --- a/third_party/json-c/arraylist.c +++ b/third_party/json-c/arraylist.c @@ -1,4 +1,6 @@ /* + * Original work: + * * $Id: arraylist.c,v 1.4 2006/01/26 02:16:28 mclark Exp $ * * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd. @@ -7,6 +9,18 @@ * This library is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See COPYING for details. * + * Modified Work: + * + * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. + * + * This software product is a proprietary product of NVIDIA CORPORATION & + * AFFILIATES (the "Company") and all right, title, and interest in and to the + * software product, including all associated intellectual property rights, are + * and shall remain exclusively with the Company. + * + * This software product is governed by the End User License Agreement + * provided with the software product. + * */ #include "config.h" @@ -14,12 +28,12 @@ #include #ifdef STDC_HEADERS -# include -# include +#include +#include #endif /* STDC_HEADERS */ #if defined(HAVE_STRINGS_H) && !defined(_STRING_H) && !defined(__USE_BSD) -# include +#include #endif /* HAVE_STRINGS_H */ #ifndef SIZE_T_MAX @@ -36,111 +50,191 @@ #include "arraylist.h" -struct array_list* -array_list_new(array_list_free_fn *free_fn) +struct array_list *doca_third_party_array_list_new(array_list_free_fn *free_fn) { - struct array_list *arr; - - arr = (struct array_list*)calloc(1, sizeof(struct array_list)); - if(!arr) return NULL; - arr->size = ARRAY_LIST_DEFAULT_SIZE; - arr->length = 0; - arr->free_fn = free_fn; - if(!(arr->array = (void**)calloc(sizeof(void*), arr->size))) { - free(arr); - return NULL; - } - return arr; + return doca_third_party_array_list_new2(free_fn, ARRAY_LIST_DEFAULT_SIZE); } -extern void -array_list_free(struct array_list *arr) +struct array_list *doca_third_party_array_list_new2(array_list_free_fn *free_fn, int initial_size) { - size_t i; - for(i = 0; i < arr->length; i++) - if(arr->array[i]) arr->free_fn(arr->array[i]); - free(arr->array); - free(arr); + struct array_list *arr; + + if (initial_size < 0 || (size_t)initial_size >= SIZE_T_MAX / sizeof(void *)) + return NULL; + arr = (struct array_list *)malloc(sizeof(struct array_list)); + if (!arr) + return NULL; + arr->size = initial_size; + arr->length = 0; + arr->free_fn = free_fn; + if (!(arr->array = (void **)malloc(arr->size * sizeof(void *)))) + { + free(arr); + return NULL; + } + return arr; } -void* -array_list_get_idx(struct array_list *arr, size_t i) +extern void doca_third_party_array_list_free(struct array_list *arr) { - if(i >= arr->length) return NULL; - return arr->array[i]; + size_t i; + for (i = 0; i < arr->length; i++) + if (arr->array[i]) + arr->free_fn(arr->array[i]); + free(arr->array); + free(arr); +} + +void *doca_third_party_array_list_get_idx(struct array_list *arr, size_t i) +{ + if (i >= arr->length) + return NULL; + return arr->array[i]; } static int array_list_expand_internal(struct array_list *arr, size_t max) { - void *t; - size_t new_size; - - if(max < arr->size) return 0; - /* Avoid undefined behaviour on size_t overflow */ - if( arr->size >= SIZE_T_MAX / 2 ) - new_size = max; - else - { - new_size = arr->size << 1; - if (new_size < max) - new_size = max; - } - if (new_size > (~((size_t)0)) / sizeof(void*)) return -1; - if (!(t = realloc(arr->array, new_size*sizeof(void*)))) return -1; - arr->array = (void**)t; - (void)memset(arr->array + arr->size, 0, (new_size-arr->size)*sizeof(void*)); - arr->size = new_size; - return 0; + void *t; + size_t new_size; + + if (max < arr->size) + return 0; + /* Avoid undefined behaviour on size_t overflow */ + if (arr->size >= SIZE_T_MAX / 2) + new_size = max; + else + { + new_size = arr->size << 1; + if (new_size < max) + new_size = max; + } + if (new_size > (~((size_t)0)) / sizeof(void *)) + return -1; + if (!(t = realloc(arr->array, new_size * sizeof(void *)))) + return -1; + arr->array = (void **)t; + arr->size = new_size; + return 0; +} + +int doca_third_party_array_list_shrink(struct array_list *arr, size_t empty_slots) +{ + void *t; + size_t new_size; + + if (empty_slots >= SIZE_T_MAX / sizeof(void *) - arr->length) + return -1; + new_size = arr->length + empty_slots; + if (new_size == arr->size) + return 0; + if (new_size > arr->size) + return array_list_expand_internal(arr, new_size); + if (new_size == 0) + new_size = 1; + + if (!(t = realloc(arr->array, new_size * sizeof(void *)))) + return -1; + arr->array = (void **)t; + arr->size = new_size; + return 0; } -int -array_list_put_idx(struct array_list *arr, size_t idx, void *data) +int doca_third_party_array_list_insert_idx(struct array_list *arr, size_t idx, void *data) { - if (idx > SIZE_T_MAX - 1 ) return -1; - if(array_list_expand_internal(arr, idx+1)) return -1; - if(idx < arr->length && arr->array[idx]) - arr->free_fn(arr->array[idx]); - arr->array[idx] = data; - if(arr->length <= idx) arr->length = idx + 1; - return 0; + size_t move_amount; + + if (idx >= arr->length) + return doca_third_party_array_list_put_idx(arr, idx, data); + + /* we're at full size, what size_t can support */ + if (arr->length == SIZE_T_MAX) + return -1; + + if (array_list_expand_internal(arr, arr->length + 1)) + return -1; + + move_amount = (arr->length - idx) * sizeof(void *); + memmove(arr->array + idx + 1, arr->array + idx, move_amount); + arr->array[idx] = data; + arr->length++; + return 0; } -int -array_list_add(struct array_list *arr, void *data) +//static inline int _array_list_put_idx(struct array_list *arr, size_t idx, void *data) +int doca_third_party_array_list_put_idx(struct array_list *arr, size_t idx, void *data) { - return array_list_put_idx(arr, arr->length, data); + if (idx > SIZE_T_MAX - 1) + return -1; + if (array_list_expand_internal(arr, idx + 1)) + return -1; + if (idx < arr->length && arr->array[idx]) + arr->free_fn(arr->array[idx]); + arr->array[idx] = data; + if (idx > arr->length) + { + /* Zero out the arraylist slots in between the old length + and the newly added entry so we know those entries are + empty. + e.g. when setting array[7] in an array that used to be + only 5 elements longs, array[5] and array[6] need to be + set to 0. + */ + memset(arr->array + arr->length, 0, (idx - arr->length) * sizeof(void *)); + } + if (arr->length <= idx) + arr->length = idx + 1; + return 0; +} + +int doca_third_party_array_list_add(struct array_list *arr, void *data) +{ + /* Repeat some of array_list_put_idx() so we can skip several + checks that we know are unnecessary when appending at the end + */ + size_t idx = arr->length; + if (idx > SIZE_T_MAX - 1) + return -1; + if (array_list_expand_internal(arr, idx + 1)) + return -1; + arr->array[idx] = data; + arr->length++; + return 0; } -void -array_list_sort(struct array_list *arr, int(*sort_fn)(const void *, const void *)) +void doca_third_party_array_list_sort(struct array_list *arr, int (*compar)(const void *, const void *)) { - qsort(arr->array, arr->length, sizeof(arr->array[0]), sort_fn); + qsort(arr->array, arr->length, sizeof(arr->array[0]), compar); } -void* array_list_bsearch(const void **key, struct array_list *arr, - int (*sort_fn)(const void *, const void *)) +void *doca_third_party_array_list_bsearch(const void **key, struct array_list *arr, + int (*compar)(const void *, const void *)) { - return bsearch(key, arr->array, arr->length, sizeof(arr->array[0]), - sort_fn); + return bsearch(key, arr->array, arr->length, sizeof(arr->array[0]), compar); } -size_t -array_list_length(struct array_list *arr) +size_t doca_third_party_array_list_length(struct array_list *arr) { - return arr->length; + return arr->length; } -int -array_list_del_idx( struct array_list *arr, size_t idx, size_t count ) +int doca_third_party_array_list_del_idx(struct array_list *arr, size_t idx, size_t count) { size_t i, stop; + /* Avoid overflow in calculation with large indices. */ + if (idx > SIZE_T_MAX - count) + return -1; stop = idx + count; - if ( idx >= arr->length || stop > arr->length ) return -1; - for ( i = idx; i < stop; ++i ) { - if ( arr->array[i] ) arr->free_fn( arr->array[i] ); + if (idx >= arr->length || stop > arr->length) + return -1; + for (i = idx; i < stop; ++i) + { + // Because put_idx can skip entries, we need to check if + // there's actually anything in each slot we're erasing. + if (arr->array[i]) + arr->free_fn(arr->array[i]); } - memmove( arr->array + idx, arr->array + stop, (arr->length - stop) * sizeof(void*) ); + memmove(arr->array + idx, arr->array + stop, (arr->length - stop) * sizeof(void *)); arr->length -= count; return 0; } diff --git a/third_party/json-c/arraylist.h b/third_party/json-c/arraylist.h index 38603e8aa..11977f164 100644 --- a/third_party/json-c/arraylist.h +++ b/third_party/json-c/arraylist.h @@ -1,4 +1,6 @@ /* + * Original work: + * * $Id: arraylist.h,v 1.4 2006/01/26 02:16:28 mclark Exp $ * * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd. @@ -7,6 +9,18 @@ * This library is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See COPYING for details. * + * Modified Work: + * + * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. + * + * This software product is a proprietary product of NVIDIA CORPORATION & + * AFFILIATES (the "Company") and all right, title, and interest in and to the + * software product, including all associated intellectual property rights, are + * and shall remain exclusively with the Company. + * + * This software product is governed by the End User License Agreement + * provided with the software product. + * */ /** @@ -15,53 +29,73 @@ * Although this is exposed by the json_object_get_array() method, * it is not recommended for direct use. */ -#ifndef _arraylist_h_ -#define _arraylist_h_ +#ifndef _json_c_arraylist_h_ +#define _json_c_arraylist_h_ #ifdef __cplusplus extern "C" { #endif +#include + #define ARRAY_LIST_DEFAULT_SIZE 32 -typedef void (array_list_free_fn) (void *data); +typedef void(array_list_free_fn)(void *data); struct array_list { - void **array; - size_t length; - size_t size; - array_list_free_fn *free_fn; + void **array; + size_t length; + size_t size; + array_list_free_fn *free_fn; }; typedef struct array_list array_list; -extern struct array_list* -array_list_new(array_list_free_fn *free_fn); +/** + * Allocate an array_list of the default size (32). + * @deprecated Use array_list_new2() instead. + */ +extern struct array_list *doca_third_party_array_list_new(array_list_free_fn *free_fn); -extern void -array_list_free(struct array_list *al); +/** + * Allocate an array_list of the desired size. + * + * If possible, the size should be chosen to closely match + * the actual number of elements expected to be used. + * If the exact size is unknown, there are tradeoffs to be made: + * - too small - the array_list code will need to call realloc() more + * often (which might incur an additional memory copy). + * - too large - will waste memory, but that can be mitigated + * by calling array_list_shrink() once the final size is known. + * + * @see array_list_shrink + */ +extern struct array_list *doca_third_party_array_list_new2(array_list_free_fn *free_fn, int initial_size); + +extern void doca_third_party_array_list_free(struct array_list *al); -extern void* -array_list_get_idx(struct array_list *al, size_t i); +extern void *doca_third_party_array_list_get_idx(struct array_list *al, size_t i); -extern int -array_list_put_idx(struct array_list *al, size_t i, void *data); +extern int doca_third_party_array_list_insert_idx(struct array_list *al, size_t i, void *data); -extern int -array_list_add(struct array_list *al, void *data); +extern int doca_third_party_array_list_put_idx(struct array_list *al, size_t i, void *data); -extern size_t -array_list_length(struct array_list *al); +extern int doca_third_party_array_list_add(struct array_list *al, void *data); -extern void -array_list_sort(struct array_list *arr, int(*compar)(const void *, const void *)); +extern size_t doca_third_party_array_list_length(struct array_list *al); -extern void* array_list_bsearch(const void **key, - struct array_list *arr, - int (*sort_fn)(const void *, const void *)); +extern void doca_third_party_array_list_sort(struct array_list *arr, int (*compar)(const void *, const void *)); -extern int -array_list_del_idx(struct array_list *arr, size_t idx, size_t count); +extern void *doca_third_party_array_list_bsearch(const void **key, struct array_list *arr, + int (*compar)(const void *, const void *)); + +extern int doca_third_party_array_list_del_idx(struct array_list *arr, size_t idx, size_t count); + +/** + * Shrink the array list to just enough to fit the number of elements in it, + * plus empty_slots. + */ +extern int doca_third_party_array_list_shrink(struct array_list *arr, size_t empty_slots); #ifdef __cplusplus } diff --git a/third_party/json-c/autoconf-archive/m4/libtool.m4 b/third_party/json-c/autoconf-archive/m4/libtool.m4 new file mode 100644 index 000000000..c4c02946d --- /dev/null +++ b/third_party/json-c/autoconf-archive/m4/libtool.m4 @@ -0,0 +1,8394 @@ +# libtool.m4 - Configure libtool for the host system. -*-Autoconf-*- +# +# Copyright (C) 1996-2001, 2003-2015 Free Software Foundation, Inc. +# Written by Gordon Matzigkeit, 1996 +# +# This file is free software; the Free Software Foundation gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. + +m4_define([_LT_COPYING], [dnl +# Copyright (C) 2014 Free Software Foundation, Inc. +# This is free software; see the source for copying conditions. There is NO +# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +# GNU Libtool is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of of the License, or +# (at your option) any later version. +# +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program or library that is built +# using GNU Libtool, you may include this file under the same +# distribution terms that you use for the rest of that program. +# +# GNU Libtool is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +]) + +# serial 58 LT_INIT + + +# LT_PREREQ(VERSION) +# ------------------ +# Complain and exit if this libtool version is less that VERSION. +m4_defun([LT_PREREQ], +[m4_if(m4_version_compare(m4_defn([LT_PACKAGE_VERSION]), [$1]), -1, + [m4_default([$3], + [m4_fatal([Libtool version $1 or higher is required], + 63)])], + [$2])]) + + +# _LT_CHECK_BUILDDIR +# ------------------ +# Complain if the absolute build directory name contains unusual characters +m4_defun([_LT_CHECK_BUILDDIR], +[case `pwd` in + *\ * | *\ *) + AC_MSG_WARN([Libtool does not cope well with whitespace in `pwd`]) ;; +esac +]) + + +# LT_INIT([OPTIONS]) +# ------------------ +AC_DEFUN([LT_INIT], +[AC_PREREQ([2.62])dnl We use AC_PATH_PROGS_FEATURE_CHECK +AC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT])dnl +AC_BEFORE([$0], [LT_LANG])dnl +AC_BEFORE([$0], [LT_OUTPUT])dnl +AC_BEFORE([$0], [LTDL_INIT])dnl +m4_require([_LT_CHECK_BUILDDIR])dnl + +dnl Autoconf doesn't catch unexpanded LT_ macros by default: +m4_pattern_forbid([^_?LT_[A-Z_]+$])dnl +m4_pattern_allow([^(_LT_EOF|LT_DLGLOBAL|LT_DLLAZY_OR_NOW|LT_MULTI_MODULE)$])dnl +dnl aclocal doesn't pull ltoptions.m4, ltsugar.m4, or ltversion.m4 +dnl unless we require an AC_DEFUNed macro: +AC_REQUIRE([LTOPTIONS_VERSION])dnl +AC_REQUIRE([LTSUGAR_VERSION])dnl +AC_REQUIRE([LTVERSION_VERSION])dnl +AC_REQUIRE([LTOBSOLETE_VERSION])dnl +m4_require([_LT_PROG_LTMAIN])dnl + +_LT_SHELL_INIT([SHELL=${CONFIG_SHELL-/bin/sh}]) + +dnl Parse OPTIONS +_LT_SET_OPTIONS([$0], [$1]) + +# This can be used to rebuild libtool when needed +LIBTOOL_DEPS=$ltmain + +# Always use our own libtool. +LIBTOOL='$(SHELL) $(top_builddir)/libtool' +AC_SUBST(LIBTOOL)dnl + +_LT_SETUP + +# Only expand once: +m4_define([LT_INIT]) +])# LT_INIT + +# Old names: +AU_ALIAS([AC_PROG_LIBTOOL], [LT_INIT]) +AU_ALIAS([AM_PROG_LIBTOOL], [LT_INIT]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_PROG_LIBTOOL], []) +dnl AC_DEFUN([AM_PROG_LIBTOOL], []) + + +# _LT_PREPARE_CC_BASENAME +# ----------------------- +m4_defun([_LT_PREPARE_CC_BASENAME], [ +# Calculate cc_basename. Skip known compiler wrappers and cross-prefix. +func_cc_basename () +{ + for cc_temp in @S|@*""; do + case $cc_temp in + compile | *[[\\/]]compile | ccache | *[[\\/]]ccache ) ;; + distcc | *[[\\/]]distcc | purify | *[[\\/]]purify ) ;; + \-*) ;; + *) break;; + esac + done + func_cc_basename_result=`$ECHO "$cc_temp" | $SED "s%.*/%%; s%^$host_alias-%%"` +} +])# _LT_PREPARE_CC_BASENAME + + +# _LT_CC_BASENAME(CC) +# ------------------- +# It would be clearer to call AC_REQUIREs from _LT_PREPARE_CC_BASENAME, +# but that macro is also expanded into generated libtool script, which +# arranges for $SED and $ECHO to be set by different means. +m4_defun([_LT_CC_BASENAME], +[m4_require([_LT_PREPARE_CC_BASENAME])dnl +AC_REQUIRE([_LT_DECL_SED])dnl +AC_REQUIRE([_LT_PROG_ECHO_BACKSLASH])dnl +func_cc_basename $1 +cc_basename=$func_cc_basename_result +]) + + +# _LT_FILEUTILS_DEFAULTS +# ---------------------- +# It is okay to use these file commands and assume they have been set +# sensibly after 'm4_require([_LT_FILEUTILS_DEFAULTS])'. +m4_defun([_LT_FILEUTILS_DEFAULTS], +[: ${CP="cp -f"} +: ${MV="mv -f"} +: ${RM="rm -f"} +])# _LT_FILEUTILS_DEFAULTS + + +# _LT_SETUP +# --------- +m4_defun([_LT_SETUP], +[AC_REQUIRE([AC_CANONICAL_HOST])dnl +AC_REQUIRE([AC_CANONICAL_BUILD])dnl +AC_REQUIRE([_LT_PREPARE_SED_QUOTE_VARS])dnl +AC_REQUIRE([_LT_PROG_ECHO_BACKSLASH])dnl + +_LT_DECL([], [PATH_SEPARATOR], [1], [The PATH separator for the build system])dnl +dnl +_LT_DECL([], [host_alias], [0], [The host system])dnl +_LT_DECL([], [host], [0])dnl +_LT_DECL([], [host_os], [0])dnl +dnl +_LT_DECL([], [build_alias], [0], [The build system])dnl +_LT_DECL([], [build], [0])dnl +_LT_DECL([], [build_os], [0])dnl +dnl +AC_REQUIRE([AC_PROG_CC])dnl +AC_REQUIRE([LT_PATH_LD])dnl +AC_REQUIRE([LT_PATH_NM])dnl +dnl +AC_REQUIRE([AC_PROG_LN_S])dnl +test -z "$LN_S" && LN_S="ln -s" +_LT_DECL([], [LN_S], [1], [Whether we need soft or hard links])dnl +dnl +AC_REQUIRE([LT_CMD_MAX_LEN])dnl +_LT_DECL([objext], [ac_objext], [0], [Object file suffix (normally "o")])dnl +_LT_DECL([], [exeext], [0], [Executable file suffix (normally "")])dnl +dnl +m4_require([_LT_FILEUTILS_DEFAULTS])dnl +m4_require([_LT_CHECK_SHELL_FEATURES])dnl +m4_require([_LT_PATH_CONVERSION_FUNCTIONS])dnl +m4_require([_LT_CMD_RELOAD])dnl +m4_require([_LT_CHECK_MAGIC_METHOD])dnl +m4_require([_LT_CHECK_SHAREDLIB_FROM_LINKLIB])dnl +m4_require([_LT_CMD_OLD_ARCHIVE])dnl +m4_require([_LT_CMD_GLOBAL_SYMBOLS])dnl +m4_require([_LT_WITH_SYSROOT])dnl +m4_require([_LT_CMD_TRUNCATE])dnl + +_LT_CONFIG_LIBTOOL_INIT([ +# See if we are running on zsh, and set the options that allow our +# commands through without removal of \ escapes INIT. +if test -n "\${ZSH_VERSION+set}"; then + setopt NO_GLOB_SUBST +fi +]) +if test -n "${ZSH_VERSION+set}"; then + setopt NO_GLOB_SUBST +fi + +_LT_CHECK_OBJDIR + +m4_require([_LT_TAG_COMPILER])dnl + +case $host_os in +aix3*) + # AIX sometimes has problems with the GCC collect2 program. For some + # reason, if we set the COLLECT_NAMES environment variable, the problems + # vanish in a puff of smoke. + if test set != "${COLLECT_NAMES+set}"; then + COLLECT_NAMES= + export COLLECT_NAMES + fi + ;; +esac + +# Global variables: +ofile=libtool +can_build_shared=yes + +# All known linkers require a '.a' archive for static linking (except MSVC, +# which needs '.lib'). +libext=a + +with_gnu_ld=$lt_cv_prog_gnu_ld + +old_CC=$CC +old_CFLAGS=$CFLAGS + +# Set sane defaults for various variables +test -z "$CC" && CC=cc +test -z "$LTCC" && LTCC=$CC +test -z "$LTCFLAGS" && LTCFLAGS=$CFLAGS +test -z "$LD" && LD=ld +test -z "$ac_objext" && ac_objext=o + +_LT_CC_BASENAME([$compiler]) + +# Only perform the check for file, if the check method requires it +test -z "$MAGIC_CMD" && MAGIC_CMD=file +case $deplibs_check_method in +file_magic*) + if test "$file_magic_cmd" = '$MAGIC_CMD'; then + _LT_PATH_MAGIC + fi + ;; +esac + +# Use C for the default configuration in the libtool script +LT_SUPPORTED_TAG([CC]) +_LT_LANG_C_CONFIG +_LT_LANG_DEFAULT_CONFIG +_LT_CONFIG_COMMANDS +])# _LT_SETUP + + +# _LT_PREPARE_SED_QUOTE_VARS +# -------------------------- +# Define a few sed substitution that help us do robust quoting. +m4_defun([_LT_PREPARE_SED_QUOTE_VARS], +[# Backslashify metacharacters that are still active within +# double-quoted strings. +sed_quote_subst='s/\([["`$\\]]\)/\\\1/g' + +# Same as above, but do not quote variable references. +double_quote_subst='s/\([["`\\]]\)/\\\1/g' + +# Sed substitution to delay expansion of an escaped shell variable in a +# double_quote_subst'ed string. +delay_variable_subst='s/\\\\\\\\\\\$/\\\\\\$/g' + +# Sed substitution to delay expansion of an escaped single quote. +delay_single_quote_subst='s/'\''/'\'\\\\\\\'\''/g' + +# Sed substitution to avoid accidental globbing in evaled expressions +no_glob_subst='s/\*/\\\*/g' +]) + +# _LT_PROG_LTMAIN +# --------------- +# Note that this code is called both from 'configure', and 'config.status' +# now that we use AC_CONFIG_COMMANDS to generate libtool. Notably, +# 'config.status' has no value for ac_aux_dir unless we are using Automake, +# so we pass a copy along to make sure it has a sensible value anyway. +m4_defun([_LT_PROG_LTMAIN], +[m4_ifdef([AC_REQUIRE_AUX_FILE], [AC_REQUIRE_AUX_FILE([ltmain.sh])])dnl +_LT_CONFIG_LIBTOOL_INIT([ac_aux_dir='$ac_aux_dir']) +ltmain=$ac_aux_dir/ltmain.sh +])# _LT_PROG_LTMAIN + + +## ------------------------------------- ## +## Accumulate code for creating libtool. ## +## ------------------------------------- ## + +# So that we can recreate a full libtool script including additional +# tags, we accumulate the chunks of code to send to AC_CONFIG_COMMANDS +# in macros and then make a single call at the end using the 'libtool' +# label. + + +# _LT_CONFIG_LIBTOOL_INIT([INIT-COMMANDS]) +# ---------------------------------------- +# Register INIT-COMMANDS to be passed to AC_CONFIG_COMMANDS later. +m4_define([_LT_CONFIG_LIBTOOL_INIT], +[m4_ifval([$1], + [m4_append([_LT_OUTPUT_LIBTOOL_INIT], + [$1 +])])]) + +# Initialize. +m4_define([_LT_OUTPUT_LIBTOOL_INIT]) + + +# _LT_CONFIG_LIBTOOL([COMMANDS]) +# ------------------------------ +# Register COMMANDS to be passed to AC_CONFIG_COMMANDS later. +m4_define([_LT_CONFIG_LIBTOOL], +[m4_ifval([$1], + [m4_append([_LT_OUTPUT_LIBTOOL_COMMANDS], + [$1 +])])]) + +# Initialize. +m4_define([_LT_OUTPUT_LIBTOOL_COMMANDS]) + + +# _LT_CONFIG_SAVE_COMMANDS([COMMANDS], [INIT_COMMANDS]) +# ----------------------------------------------------- +m4_defun([_LT_CONFIG_SAVE_COMMANDS], +[_LT_CONFIG_LIBTOOL([$1]) +_LT_CONFIG_LIBTOOL_INIT([$2]) +]) + + +# _LT_FORMAT_COMMENT([COMMENT]) +# ----------------------------- +# Add leading comment marks to the start of each line, and a trailing +# full-stop to the whole comment if one is not present already. +m4_define([_LT_FORMAT_COMMENT], +[m4_ifval([$1], [ +m4_bpatsubst([m4_bpatsubst([$1], [^ *], [# ])], + [['`$\]], [\\\&])]m4_bmatch([$1], [[!?.]$], [], [.]) +)]) + + + +## ------------------------ ## +## FIXME: Eliminate VARNAME ## +## ------------------------ ## + + +# _LT_DECL([CONFIGNAME], VARNAME, VALUE, [DESCRIPTION], [IS-TAGGED?]) +# ------------------------------------------------------------------- +# CONFIGNAME is the name given to the value in the libtool script. +# VARNAME is the (base) name used in the configure script. +# VALUE may be 0, 1 or 2 for a computed quote escaped value based on +# VARNAME. Any other value will be used directly. +m4_define([_LT_DECL], +[lt_if_append_uniq([lt_decl_varnames], [$2], [, ], + [lt_dict_add_subkey([lt_decl_dict], [$2], [libtool_name], + [m4_ifval([$1], [$1], [$2])]) + lt_dict_add_subkey([lt_decl_dict], [$2], [value], [$3]) + m4_ifval([$4], + [lt_dict_add_subkey([lt_decl_dict], [$2], [description], [$4])]) + lt_dict_add_subkey([lt_decl_dict], [$2], + [tagged?], [m4_ifval([$5], [yes], [no])])]) +]) + + +# _LT_TAGDECL([CONFIGNAME], VARNAME, VALUE, [DESCRIPTION]) +# -------------------------------------------------------- +m4_define([_LT_TAGDECL], [_LT_DECL([$1], [$2], [$3], [$4], [yes])]) + + +# lt_decl_tag_varnames([SEPARATOR], [VARNAME1...]) +# ------------------------------------------------ +m4_define([lt_decl_tag_varnames], +[_lt_decl_filter([tagged?], [yes], $@)]) + + +# _lt_decl_filter(SUBKEY, VALUE, [SEPARATOR], [VARNAME1..]) +# --------------------------------------------------------- +m4_define([_lt_decl_filter], +[m4_case([$#], + [0], [m4_fatal([$0: too few arguments: $#])], + [1], [m4_fatal([$0: too few arguments: $#: $1])], + [2], [lt_dict_filter([lt_decl_dict], [$1], [$2], [], lt_decl_varnames)], + [3], [lt_dict_filter([lt_decl_dict], [$1], [$2], [$3], lt_decl_varnames)], + [lt_dict_filter([lt_decl_dict], $@)])[]dnl +]) + + +# lt_decl_quote_varnames([SEPARATOR], [VARNAME1...]) +# -------------------------------------------------- +m4_define([lt_decl_quote_varnames], +[_lt_decl_filter([value], [1], $@)]) + + +# lt_decl_dquote_varnames([SEPARATOR], [VARNAME1...]) +# --------------------------------------------------- +m4_define([lt_decl_dquote_varnames], +[_lt_decl_filter([value], [2], $@)]) + + +# lt_decl_varnames_tagged([SEPARATOR], [VARNAME1...]) +# --------------------------------------------------- +m4_define([lt_decl_varnames_tagged], +[m4_assert([$# <= 2])dnl +_$0(m4_quote(m4_default([$1], [[, ]])), + m4_ifval([$2], [[$2]], [m4_dquote(lt_decl_tag_varnames)]), + m4_split(m4_normalize(m4_quote(_LT_TAGS)), [ ]))]) +m4_define([_lt_decl_varnames_tagged], +[m4_ifval([$3], [lt_combine([$1], [$2], [_], $3)])]) + + +# lt_decl_all_varnames([SEPARATOR], [VARNAME1...]) +# ------------------------------------------------ +m4_define([lt_decl_all_varnames], +[_$0(m4_quote(m4_default([$1], [[, ]])), + m4_if([$2], [], + m4_quote(lt_decl_varnames), + m4_quote(m4_shift($@))))[]dnl +]) +m4_define([_lt_decl_all_varnames], +[lt_join($@, lt_decl_varnames_tagged([$1], + lt_decl_tag_varnames([[, ]], m4_shift($@))))dnl +]) + + +# _LT_CONFIG_STATUS_DECLARE([VARNAME]) +# ------------------------------------ +# Quote a variable value, and forward it to 'config.status' so that its +# declaration there will have the same value as in 'configure'. VARNAME +# must have a single quote delimited value for this to work. +m4_define([_LT_CONFIG_STATUS_DECLARE], +[$1='`$ECHO "$][$1" | $SED "$delay_single_quote_subst"`']) + + +# _LT_CONFIG_STATUS_DECLARATIONS +# ------------------------------ +# We delimit libtool config variables with single quotes, so when +# we write them to config.status, we have to be sure to quote all +# embedded single quotes properly. In configure, this macro expands +# each variable declared with _LT_DECL (and _LT_TAGDECL) into: +# +# ='`$ECHO "$" | $SED "$delay_single_quote_subst"`' +m4_defun([_LT_CONFIG_STATUS_DECLARATIONS], +[m4_foreach([_lt_var], m4_quote(lt_decl_all_varnames), + [m4_n([_LT_CONFIG_STATUS_DECLARE(_lt_var)])])]) + + +# _LT_LIBTOOL_TAGS +# ---------------- +# Output comment and list of tags supported by the script +m4_defun([_LT_LIBTOOL_TAGS], +[_LT_FORMAT_COMMENT([The names of the tagged configurations supported by this script])dnl +available_tags='_LT_TAGS'dnl +]) + + +# _LT_LIBTOOL_DECLARE(VARNAME, [TAG]) +# ----------------------------------- +# Extract the dictionary values for VARNAME (optionally with TAG) and +# expand to a commented shell variable setting: +# +# # Some comment about what VAR is for. +# visible_name=$lt_internal_name +m4_define([_LT_LIBTOOL_DECLARE], +[_LT_FORMAT_COMMENT(m4_quote(lt_dict_fetch([lt_decl_dict], [$1], + [description])))[]dnl +m4_pushdef([_libtool_name], + m4_quote(lt_dict_fetch([lt_decl_dict], [$1], [libtool_name])))[]dnl +m4_case(m4_quote(lt_dict_fetch([lt_decl_dict], [$1], [value])), + [0], [_libtool_name=[$]$1], + [1], [_libtool_name=$lt_[]$1], + [2], [_libtool_name=$lt_[]$1], + [_libtool_name=lt_dict_fetch([lt_decl_dict], [$1], [value])])[]dnl +m4_ifval([$2], [_$2])[]m4_popdef([_libtool_name])[]dnl +]) + + +# _LT_LIBTOOL_CONFIG_VARS +# ----------------------- +# Produce commented declarations of non-tagged libtool config variables +# suitable for insertion in the LIBTOOL CONFIG section of the 'libtool' +# script. Tagged libtool config variables (even for the LIBTOOL CONFIG +# section) are produced by _LT_LIBTOOL_TAG_VARS. +m4_defun([_LT_LIBTOOL_CONFIG_VARS], +[m4_foreach([_lt_var], + m4_quote(_lt_decl_filter([tagged?], [no], [], lt_decl_varnames)), + [m4_n([_LT_LIBTOOL_DECLARE(_lt_var)])])]) + + +# _LT_LIBTOOL_TAG_VARS(TAG) +# ------------------------- +m4_define([_LT_LIBTOOL_TAG_VARS], +[m4_foreach([_lt_var], m4_quote(lt_decl_tag_varnames), + [m4_n([_LT_LIBTOOL_DECLARE(_lt_var, [$1])])])]) + + +# _LT_TAGVAR(VARNAME, [TAGNAME]) +# ------------------------------ +m4_define([_LT_TAGVAR], [m4_ifval([$2], [$1_$2], [$1])]) + + +# _LT_CONFIG_COMMANDS +# ------------------- +# Send accumulated output to $CONFIG_STATUS. Thanks to the lists of +# variables for single and double quote escaping we saved from calls +# to _LT_DECL, we can put quote escaped variables declarations +# into 'config.status', and then the shell code to quote escape them in +# for loops in 'config.status'. Finally, any additional code accumulated +# from calls to _LT_CONFIG_LIBTOOL_INIT is expanded. +m4_defun([_LT_CONFIG_COMMANDS], +[AC_PROVIDE_IFELSE([LT_OUTPUT], + dnl If the libtool generation code has been placed in $CONFIG_LT, + dnl instead of duplicating it all over again into config.status, + dnl then we will have config.status run $CONFIG_LT later, so it + dnl needs to know what name is stored there: + [AC_CONFIG_COMMANDS([libtool], + [$SHELL $CONFIG_LT || AS_EXIT(1)], [CONFIG_LT='$CONFIG_LT'])], + dnl If the libtool generation code is destined for config.status, + dnl expand the accumulated commands and init code now: + [AC_CONFIG_COMMANDS([libtool], + [_LT_OUTPUT_LIBTOOL_COMMANDS], [_LT_OUTPUT_LIBTOOL_COMMANDS_INIT])]) +])#_LT_CONFIG_COMMANDS + + +# Initialize. +m4_define([_LT_OUTPUT_LIBTOOL_COMMANDS_INIT], +[ + +# The HP-UX ksh and POSIX shell print the target directory to stdout +# if CDPATH is set. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + +sed_quote_subst='$sed_quote_subst' +double_quote_subst='$double_quote_subst' +delay_variable_subst='$delay_variable_subst' +_LT_CONFIG_STATUS_DECLARATIONS +LTCC='$LTCC' +LTCFLAGS='$LTCFLAGS' +compiler='$compiler_DEFAULT' + +# A function that is used when there is no print builtin or printf. +func_fallback_echo () +{ + eval 'cat <<_LTECHO_EOF +\$[]1 +_LTECHO_EOF' +} + +# Quote evaled strings. +for var in lt_decl_all_varnames([[ \ +]], lt_decl_quote_varnames); do + case \`eval \\\\\$ECHO \\\\""\\\\\$\$var"\\\\"\` in + *[[\\\\\\\`\\"\\\$]]*) + eval "lt_\$var=\\\\\\"\\\`\\\$ECHO \\"\\\$\$var\\" | \\\$SED \\"\\\$sed_quote_subst\\"\\\`\\\\\\"" ## exclude from sc_prohibit_nested_quotes + ;; + *) + eval "lt_\$var=\\\\\\"\\\$\$var\\\\\\"" + ;; + esac +done + +# Double-quote double-evaled strings. +for var in lt_decl_all_varnames([[ \ +]], lt_decl_dquote_varnames); do + case \`eval \\\\\$ECHO \\\\""\\\\\$\$var"\\\\"\` in + *[[\\\\\\\`\\"\\\$]]*) + eval "lt_\$var=\\\\\\"\\\`\\\$ECHO \\"\\\$\$var\\" | \\\$SED -e \\"\\\$double_quote_subst\\" -e \\"\\\$sed_quote_subst\\" -e \\"\\\$delay_variable_subst\\"\\\`\\\\\\"" ## exclude from sc_prohibit_nested_quotes + ;; + *) + eval "lt_\$var=\\\\\\"\\\$\$var\\\\\\"" + ;; + esac +done + +_LT_OUTPUT_LIBTOOL_INIT +]) + +# _LT_GENERATED_FILE_INIT(FILE, [COMMENT]) +# ------------------------------------ +# Generate a child script FILE with all initialization necessary to +# reuse the environment learned by the parent script, and make the +# file executable. If COMMENT is supplied, it is inserted after the +# '#!' sequence but before initialization text begins. After this +# macro, additional text can be appended to FILE to form the body of +# the child script. The macro ends with non-zero status if the +# file could not be fully written (such as if the disk is full). +m4_ifdef([AS_INIT_GENERATED], +[m4_defun([_LT_GENERATED_FILE_INIT],[AS_INIT_GENERATED($@)])], +[m4_defun([_LT_GENERATED_FILE_INIT], +[m4_require([AS_PREPARE])]dnl +[m4_pushdef([AS_MESSAGE_LOG_FD])]dnl +[lt_write_fail=0 +cat >$1 <<_ASEOF || lt_write_fail=1 +#! $SHELL +# Generated by $as_me. +$2 +SHELL=\${CONFIG_SHELL-$SHELL} +export SHELL +_ASEOF +cat >>$1 <<\_ASEOF || lt_write_fail=1 +AS_SHELL_SANITIZE +_AS_PREPARE +exec AS_MESSAGE_FD>&1 +_ASEOF +test 0 = "$lt_write_fail" && chmod +x $1[]dnl +m4_popdef([AS_MESSAGE_LOG_FD])])])# _LT_GENERATED_FILE_INIT + +# LT_OUTPUT +# --------- +# This macro allows early generation of the libtool script (before +# AC_OUTPUT is called), incase it is used in configure for compilation +# tests. +AC_DEFUN([LT_OUTPUT], +[: ${CONFIG_LT=./config.lt} +AC_MSG_NOTICE([creating $CONFIG_LT]) +_LT_GENERATED_FILE_INIT(["$CONFIG_LT"], +[# Run this file to recreate a libtool stub with the current configuration.]) + +cat >>"$CONFIG_LT" <<\_LTEOF +lt_cl_silent=false +exec AS_MESSAGE_LOG_FD>>config.log +{ + echo + AS_BOX([Running $as_me.]) +} >&AS_MESSAGE_LOG_FD + +lt_cl_help="\ +'$as_me' creates a local libtool stub from the current configuration, +for use in further configure time tests before the real libtool is +generated. + +Usage: $[0] [[OPTIONS]] + + -h, --help print this help, then exit + -V, --version print version number, then exit + -q, --quiet do not print progress messages + -d, --debug don't remove temporary files + +Report bugs to ." + +lt_cl_version="\ +m4_ifset([AC_PACKAGE_NAME], [AC_PACKAGE_NAME ])config.lt[]dnl +m4_ifset([AC_PACKAGE_VERSION], [ AC_PACKAGE_VERSION]) +configured by $[0], generated by m4_PACKAGE_STRING. + +Copyright (C) 2011 Free Software Foundation, Inc. +This config.lt script is free software; the Free Software Foundation +gives unlimited permision to copy, distribute and modify it." + +while test 0 != $[#] +do + case $[1] in + --version | --v* | -V ) + echo "$lt_cl_version"; exit 0 ;; + --help | --h* | -h ) + echo "$lt_cl_help"; exit 0 ;; + --debug | --d* | -d ) + debug=: ;; + --quiet | --q* | --silent | --s* | -q ) + lt_cl_silent=: ;; + + -*) AC_MSG_ERROR([unrecognized option: $[1] +Try '$[0] --help' for more information.]) ;; + + *) AC_MSG_ERROR([unrecognized argument: $[1] +Try '$[0] --help' for more information.]) ;; + esac + shift +done + +if $lt_cl_silent; then + exec AS_MESSAGE_FD>/dev/null +fi +_LTEOF + +cat >>"$CONFIG_LT" <<_LTEOF +_LT_OUTPUT_LIBTOOL_COMMANDS_INIT +_LTEOF + +cat >>"$CONFIG_LT" <<\_LTEOF +AC_MSG_NOTICE([creating $ofile]) +_LT_OUTPUT_LIBTOOL_COMMANDS +AS_EXIT(0) +_LTEOF +chmod +x "$CONFIG_LT" + +# configure is writing to config.log, but config.lt does its own redirection, +# appending to config.log, which fails on DOS, as config.log is still kept +# open by configure. Here we exec the FD to /dev/null, effectively closing +# config.log, so it can be properly (re)opened and appended to by config.lt. +lt_cl_success=: +test yes = "$silent" && + lt_config_lt_args="$lt_config_lt_args --quiet" +exec AS_MESSAGE_LOG_FD>/dev/null +$SHELL "$CONFIG_LT" $lt_config_lt_args || lt_cl_success=false +exec AS_MESSAGE_LOG_FD>>config.log +$lt_cl_success || AS_EXIT(1) +])# LT_OUTPUT + + +# _LT_CONFIG(TAG) +# --------------- +# If TAG is the built-in tag, create an initial libtool script with a +# default configuration from the untagged config vars. Otherwise add code +# to config.status for appending the configuration named by TAG from the +# matching tagged config vars. +m4_defun([_LT_CONFIG], +[m4_require([_LT_FILEUTILS_DEFAULTS])dnl +_LT_CONFIG_SAVE_COMMANDS([ + m4_define([_LT_TAG], m4_if([$1], [], [C], [$1]))dnl + m4_if(_LT_TAG, [C], [ + # See if we are running on zsh, and set the options that allow our + # commands through without removal of \ escapes. + if test -n "${ZSH_VERSION+set}"; then + setopt NO_GLOB_SUBST + fi + + cfgfile=${ofile}T + trap "$RM \"$cfgfile\"; exit 1" 1 2 15 + $RM "$cfgfile" + + cat <<_LT_EOF >> "$cfgfile" +#! $SHELL +# Generated automatically by $as_me ($PACKAGE) $VERSION +# NOTE: Changes made to this file will be lost: look at ltmain.sh. + +# Provide generalized library-building support services. +# Written by Gordon Matzigkeit, 1996 + +_LT_COPYING +_LT_LIBTOOL_TAGS + +# Configured defaults for sys_lib_dlsearch_path munging. +: \${LT_SYS_LIBRARY_PATH="$configure_time_lt_sys_library_path"} + +# ### BEGIN LIBTOOL CONFIG +_LT_LIBTOOL_CONFIG_VARS +_LT_LIBTOOL_TAG_VARS +# ### END LIBTOOL CONFIG + +_LT_EOF + + cat <<'_LT_EOF' >> "$cfgfile" + +# ### BEGIN FUNCTIONS SHARED WITH CONFIGURE + +_LT_PREPARE_MUNGE_PATH_LIST +_LT_PREPARE_CC_BASENAME + +# ### END FUNCTIONS SHARED WITH CONFIGURE + +_LT_EOF + + case $host_os in + aix3*) + cat <<\_LT_EOF >> "$cfgfile" +# AIX sometimes has problems with the GCC collect2 program. For some +# reason, if we set the COLLECT_NAMES environment variable, the problems +# vanish in a puff of smoke. +if test set != "${COLLECT_NAMES+set}"; then + COLLECT_NAMES= + export COLLECT_NAMES +fi +_LT_EOF + ;; + esac + + _LT_PROG_LTMAIN + + # We use sed instead of cat because bash on DJGPP gets confused if + # if finds mixed CR/LF and LF-only lines. Since sed operates in + # text mode, it properly converts lines to CR/LF. This bash problem + # is reportedly fixed, but why not run on old versions too? + sed '$q' "$ltmain" >> "$cfgfile" \ + || (rm -f "$cfgfile"; exit 1) + + mv -f "$cfgfile" "$ofile" || + (rm -f "$ofile" && cp "$cfgfile" "$ofile" && rm -f "$cfgfile") + chmod +x "$ofile" +], +[cat <<_LT_EOF >> "$ofile" + +dnl Unfortunately we have to use $1 here, since _LT_TAG is not expanded +dnl in a comment (ie after a #). +# ### BEGIN LIBTOOL TAG CONFIG: $1 +_LT_LIBTOOL_TAG_VARS(_LT_TAG) +# ### END LIBTOOL TAG CONFIG: $1 +_LT_EOF +])dnl /m4_if +], +[m4_if([$1], [], [ + PACKAGE='$PACKAGE' + VERSION='$VERSION' + RM='$RM' + ofile='$ofile'], []) +])dnl /_LT_CONFIG_SAVE_COMMANDS +])# _LT_CONFIG + + +# LT_SUPPORTED_TAG(TAG) +# --------------------- +# Trace this macro to discover what tags are supported by the libtool +# --tag option, using: +# autoconf --trace 'LT_SUPPORTED_TAG:$1' +AC_DEFUN([LT_SUPPORTED_TAG], []) + + +# C support is built-in for now +m4_define([_LT_LANG_C_enabled], []) +m4_define([_LT_TAGS], []) + + +# LT_LANG(LANG) +# ------------- +# Enable libtool support for the given language if not already enabled. +AC_DEFUN([LT_LANG], +[AC_BEFORE([$0], [LT_OUTPUT])dnl +m4_case([$1], + [C], [_LT_LANG(C)], + [C++], [_LT_LANG(CXX)], + [Go], [_LT_LANG(GO)], + [Java], [_LT_LANG(GCJ)], + [Fortran 77], [_LT_LANG(F77)], + [Fortran], [_LT_LANG(FC)], + [Windows Resource], [_LT_LANG(RC)], + [m4_ifdef([_LT_LANG_]$1[_CONFIG], + [_LT_LANG($1)], + [m4_fatal([$0: unsupported language: "$1"])])])dnl +])# LT_LANG + + +# _LT_LANG(LANGNAME) +# ------------------ +m4_defun([_LT_LANG], +[m4_ifdef([_LT_LANG_]$1[_enabled], [], + [LT_SUPPORTED_TAG([$1])dnl + m4_append([_LT_TAGS], [$1 ])dnl + m4_define([_LT_LANG_]$1[_enabled], [])dnl + _LT_LANG_$1_CONFIG($1)])dnl +])# _LT_LANG + + +m4_ifndef([AC_PROG_GO], [ +############################################################ +# NOTE: This macro has been submitted for inclusion into # +# GNU Autoconf as AC_PROG_GO. When it is available in # +# a released version of Autoconf we should remove this # +# macro and use it instead. # +############################################################ +m4_defun([AC_PROG_GO], +[AC_LANG_PUSH(Go)dnl +AC_ARG_VAR([GOC], [Go compiler command])dnl +AC_ARG_VAR([GOFLAGS], [Go compiler flags])dnl +_AC_ARG_VAR_LDFLAGS()dnl +AC_CHECK_TOOL(GOC, gccgo) +if test -z "$GOC"; then + if test -n "$ac_tool_prefix"; then + AC_CHECK_PROG(GOC, [${ac_tool_prefix}gccgo], [${ac_tool_prefix}gccgo]) + fi +fi +if test -z "$GOC"; then + AC_CHECK_PROG(GOC, gccgo, gccgo, false) +fi +])#m4_defun +])#m4_ifndef + + +# _LT_LANG_DEFAULT_CONFIG +# ----------------------- +m4_defun([_LT_LANG_DEFAULT_CONFIG], +[AC_PROVIDE_IFELSE([AC_PROG_CXX], + [LT_LANG(CXX)], + [m4_define([AC_PROG_CXX], defn([AC_PROG_CXX])[LT_LANG(CXX)])]) + +AC_PROVIDE_IFELSE([AC_PROG_F77], + [LT_LANG(F77)], + [m4_define([AC_PROG_F77], defn([AC_PROG_F77])[LT_LANG(F77)])]) + +AC_PROVIDE_IFELSE([AC_PROG_FC], + [LT_LANG(FC)], + [m4_define([AC_PROG_FC], defn([AC_PROG_FC])[LT_LANG(FC)])]) + +dnl The call to [A][M_PROG_GCJ] is quoted like that to stop aclocal +dnl pulling things in needlessly. +AC_PROVIDE_IFELSE([AC_PROG_GCJ], + [LT_LANG(GCJ)], + [AC_PROVIDE_IFELSE([A][M_PROG_GCJ], + [LT_LANG(GCJ)], + [AC_PROVIDE_IFELSE([LT_PROG_GCJ], + [LT_LANG(GCJ)], + [m4_ifdef([AC_PROG_GCJ], + [m4_define([AC_PROG_GCJ], defn([AC_PROG_GCJ])[LT_LANG(GCJ)])]) + m4_ifdef([A][M_PROG_GCJ], + [m4_define([A][M_PROG_GCJ], defn([A][M_PROG_GCJ])[LT_LANG(GCJ)])]) + m4_ifdef([LT_PROG_GCJ], + [m4_define([LT_PROG_GCJ], defn([LT_PROG_GCJ])[LT_LANG(GCJ)])])])])]) + +AC_PROVIDE_IFELSE([AC_PROG_GO], + [LT_LANG(GO)], + [m4_define([AC_PROG_GO], defn([AC_PROG_GO])[LT_LANG(GO)])]) + +AC_PROVIDE_IFELSE([LT_PROG_RC], + [LT_LANG(RC)], + [m4_define([LT_PROG_RC], defn([LT_PROG_RC])[LT_LANG(RC)])]) +])# _LT_LANG_DEFAULT_CONFIG + +# Obsolete macros: +AU_DEFUN([AC_LIBTOOL_CXX], [LT_LANG(C++)]) +AU_DEFUN([AC_LIBTOOL_F77], [LT_LANG(Fortran 77)]) +AU_DEFUN([AC_LIBTOOL_FC], [LT_LANG(Fortran)]) +AU_DEFUN([AC_LIBTOOL_GCJ], [LT_LANG(Java)]) +AU_DEFUN([AC_LIBTOOL_RC], [LT_LANG(Windows Resource)]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_LIBTOOL_CXX], []) +dnl AC_DEFUN([AC_LIBTOOL_F77], []) +dnl AC_DEFUN([AC_LIBTOOL_FC], []) +dnl AC_DEFUN([AC_LIBTOOL_GCJ], []) +dnl AC_DEFUN([AC_LIBTOOL_RC], []) + + +# _LT_TAG_COMPILER +# ---------------- +m4_defun([_LT_TAG_COMPILER], +[AC_REQUIRE([AC_PROG_CC])dnl + +_LT_DECL([LTCC], [CC], [1], [A C compiler])dnl +_LT_DECL([LTCFLAGS], [CFLAGS], [1], [LTCC compiler flags])dnl +_LT_TAGDECL([CC], [compiler], [1], [A language specific compiler])dnl +_LT_TAGDECL([with_gcc], [GCC], [0], [Is the compiler the GNU compiler?])dnl + +# If no C compiler was specified, use CC. +LTCC=${LTCC-"$CC"} + +# If no C compiler flags were specified, use CFLAGS. +LTCFLAGS=${LTCFLAGS-"$CFLAGS"} + +# Allow CC to be a program name with arguments. +compiler=$CC +])# _LT_TAG_COMPILER + + +# _LT_COMPILER_BOILERPLATE +# ------------------------ +# Check for compiler boilerplate output or warnings with +# the simple compiler test code. +m4_defun([_LT_COMPILER_BOILERPLATE], +[m4_require([_LT_DECL_SED])dnl +ac_outfile=conftest.$ac_objext +echo "$lt_simple_compile_test_code" >conftest.$ac_ext +eval "$ac_compile" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err +_lt_compiler_boilerplate=`cat conftest.err` +$RM conftest* +])# _LT_COMPILER_BOILERPLATE + + +# _LT_LINKER_BOILERPLATE +# ---------------------- +# Check for linker boilerplate output or warnings with +# the simple link test code. +m4_defun([_LT_LINKER_BOILERPLATE], +[m4_require([_LT_DECL_SED])dnl +ac_outfile=conftest.$ac_objext +echo "$lt_simple_link_test_code" >conftest.$ac_ext +eval "$ac_link" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err +_lt_linker_boilerplate=`cat conftest.err` +$RM -r conftest* +])# _LT_LINKER_BOILERPLATE + +# _LT_REQUIRED_DARWIN_CHECKS +# ------------------------- +m4_defun_once([_LT_REQUIRED_DARWIN_CHECKS],[ + case $host_os in + rhapsody* | darwin*) + AC_CHECK_TOOL([DSYMUTIL], [dsymutil], [:]) + AC_CHECK_TOOL([NMEDIT], [nmedit], [:]) + AC_CHECK_TOOL([LIPO], [lipo], [:]) + AC_CHECK_TOOL([OTOOL], [otool], [:]) + AC_CHECK_TOOL([OTOOL64], [otool64], [:]) + _LT_DECL([], [DSYMUTIL], [1], + [Tool to manipulate archived DWARF debug symbol files on Mac OS X]) + _LT_DECL([], [NMEDIT], [1], + [Tool to change global to local symbols on Mac OS X]) + _LT_DECL([], [LIPO], [1], + [Tool to manipulate fat objects and archives on Mac OS X]) + _LT_DECL([], [OTOOL], [1], + [ldd/readelf like tool for Mach-O binaries on Mac OS X]) + _LT_DECL([], [OTOOL64], [1], + [ldd/readelf like tool for 64 bit Mach-O binaries on Mac OS X 10.4]) + + AC_CACHE_CHECK([for -single_module linker flag],[lt_cv_apple_cc_single_mod], + [lt_cv_apple_cc_single_mod=no + if test -z "$LT_MULTI_MODULE"; then + # By default we will add the -single_module flag. You can override + # by either setting the environment variable LT_MULTI_MODULE + # non-empty at configure time, or by adding -multi_module to the + # link flags. + rm -rf libconftest.dylib* + echo "int foo(void){return 1;}" > conftest.c + echo "$LTCC $LTCFLAGS $LDFLAGS -o libconftest.dylib \ +-dynamiclib -Wl,-single_module conftest.c" >&AS_MESSAGE_LOG_FD + $LTCC $LTCFLAGS $LDFLAGS -o libconftest.dylib \ + -dynamiclib -Wl,-single_module conftest.c 2>conftest.err + _lt_result=$? + # If there is a non-empty error log, and "single_module" + # appears in it, assume the flag caused a linker warning + if test -s conftest.err && $GREP single_module conftest.err; then + cat conftest.err >&AS_MESSAGE_LOG_FD + # Otherwise, if the output was created with a 0 exit code from + # the compiler, it worked. + elif test -f libconftest.dylib && test 0 = "$_lt_result"; then + lt_cv_apple_cc_single_mod=yes + else + cat conftest.err >&AS_MESSAGE_LOG_FD + fi + rm -rf libconftest.dylib* + rm -f conftest.* + fi]) + + AC_CACHE_CHECK([for -exported_symbols_list linker flag], + [lt_cv_ld_exported_symbols_list], + [lt_cv_ld_exported_symbols_list=no + save_LDFLAGS=$LDFLAGS + echo "_main" > conftest.sym + LDFLAGS="$LDFLAGS -Wl,-exported_symbols_list,conftest.sym" + AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])], + [lt_cv_ld_exported_symbols_list=yes], + [lt_cv_ld_exported_symbols_list=no]) + LDFLAGS=$save_LDFLAGS + ]) + + AC_CACHE_CHECK([for -force_load linker flag],[lt_cv_ld_force_load], + [lt_cv_ld_force_load=no + cat > conftest.c << _LT_EOF +int forced_loaded() { return 2;} +_LT_EOF + echo "$LTCC $LTCFLAGS -c -o conftest.o conftest.c" >&AS_MESSAGE_LOG_FD + $LTCC $LTCFLAGS -c -o conftest.o conftest.c 2>&AS_MESSAGE_LOG_FD + echo "$AR cr libconftest.a conftest.o" >&AS_MESSAGE_LOG_FD + $AR cr libconftest.a conftest.o 2>&AS_MESSAGE_LOG_FD + echo "$RANLIB libconftest.a" >&AS_MESSAGE_LOG_FD + $RANLIB libconftest.a 2>&AS_MESSAGE_LOG_FD + cat > conftest.c << _LT_EOF +int main() { return 0;} +_LT_EOF + echo "$LTCC $LTCFLAGS $LDFLAGS -o conftest conftest.c -Wl,-force_load,./libconftest.a" >&AS_MESSAGE_LOG_FD + $LTCC $LTCFLAGS $LDFLAGS -o conftest conftest.c -Wl,-force_load,./libconftest.a 2>conftest.err + _lt_result=$? + if test -s conftest.err && $GREP force_load conftest.err; then + cat conftest.err >&AS_MESSAGE_LOG_FD + elif test -f conftest && test 0 = "$_lt_result" && $GREP forced_load conftest >/dev/null 2>&1; then + lt_cv_ld_force_load=yes + else + cat conftest.err >&AS_MESSAGE_LOG_FD + fi + rm -f conftest.err libconftest.a conftest conftest.c + rm -rf conftest.dSYM + ]) + case $host_os in + rhapsody* | darwin1.[[012]]) + _lt_dar_allow_undefined='$wl-undefined ${wl}suppress' ;; + darwin1.*) + _lt_dar_allow_undefined='$wl-flat_namespace $wl-undefined ${wl}suppress' ;; + darwin*) # darwin 5.x on + # if running on 10.5 or later, the deployment target defaults + # to the OS version, if on x86, and 10.4, the deployment + # target defaults to 10.4. Don't you love it? + case ${MACOSX_DEPLOYMENT_TARGET-10.0},$host in + 10.0,*86*-darwin8*|10.0,*-darwin[[912]]*) + _lt_dar_allow_undefined='$wl-undefined ${wl}dynamic_lookup' ;; + 10.[[012]][[,.]]*) + _lt_dar_allow_undefined='$wl-flat_namespace $wl-undefined ${wl}suppress' ;; + 10.*|11.*) + _lt_dar_allow_undefined='$wl-undefined ${wl}dynamic_lookup' ;; + esac + ;; + esac + if test yes = "$lt_cv_apple_cc_single_mod"; then + _lt_dar_single_mod='$single_module' + fi + if test yes = "$lt_cv_ld_exported_symbols_list"; then + _lt_dar_export_syms=' $wl-exported_symbols_list,$output_objdir/$libname-symbols.expsym' + else + _lt_dar_export_syms='~$NMEDIT -s $output_objdir/$libname-symbols.expsym $lib' + fi + if test : != "$DSYMUTIL" && test no = "$lt_cv_ld_force_load"; then + _lt_dsymutil='~$DSYMUTIL $lib || :' + else + _lt_dsymutil= + fi + ;; + esac +]) + + +# _LT_DARWIN_LINKER_FEATURES([TAG]) +# --------------------------------- +# Checks for linker and compiler features on darwin +m4_defun([_LT_DARWIN_LINKER_FEATURES], +[ + m4_require([_LT_REQUIRED_DARWIN_CHECKS]) + _LT_TAGVAR(archive_cmds_need_lc, $1)=no + _LT_TAGVAR(hardcode_direct, $1)=no + _LT_TAGVAR(hardcode_automatic, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=unsupported + if test yes = "$lt_cv_ld_force_load"; then + _LT_TAGVAR(whole_archive_flag_spec, $1)='`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience $wl-force_load,$conv\"; done; func_echo_all \"$new_convenience\"`' + m4_case([$1], [F77], [_LT_TAGVAR(compiler_needs_object, $1)=yes], + [FC], [_LT_TAGVAR(compiler_needs_object, $1)=yes]) + else + _LT_TAGVAR(whole_archive_flag_spec, $1)='' + fi + _LT_TAGVAR(link_all_deplibs, $1)=yes + _LT_TAGVAR(allow_undefined_flag, $1)=$_lt_dar_allow_undefined + case $cc_basename in + ifort*|nagfor*) _lt_dar_can_shared=yes ;; + *) _lt_dar_can_shared=$GCC ;; + esac + if test yes = "$_lt_dar_can_shared"; then + output_verbose_link_cmd=func_echo_all + _LT_TAGVAR(archive_cmds, $1)="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod$_lt_dsymutil" + _LT_TAGVAR(module_cmds, $1)="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags$_lt_dsymutil" + _LT_TAGVAR(archive_expsym_cmds, $1)="sed 's|^|_|' < \$export_symbols > \$output_objdir/\$libname-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod$_lt_dar_export_syms$_lt_dsymutil" + _LT_TAGVAR(module_expsym_cmds, $1)="sed -e 's|^|_|' < \$export_symbols > \$output_objdir/\$libname-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags$_lt_dar_export_syms$_lt_dsymutil" + m4_if([$1], [CXX], +[ if test yes != "$lt_cv_apple_cc_single_mod"; then + _LT_TAGVAR(archive_cmds, $1)="\$CC -r -keep_private_externs -nostdlib -o \$lib-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$lib-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring$_lt_dsymutil" + _LT_TAGVAR(archive_expsym_cmds, $1)="sed 's|^|_|' < \$export_symbols > \$output_objdir/\$libname-symbols.expsym~\$CC -r -keep_private_externs -nostdlib -o \$lib-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$lib-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring$_lt_dar_export_syms$_lt_dsymutil" + fi +],[]) + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi +]) + +# _LT_SYS_MODULE_PATH_AIX([TAGNAME]) +# ---------------------------------- +# Links a minimal program and checks the executable +# for the system default hardcoded library path. In most cases, +# this is /usr/lib:/lib, but when the MPI compilers are used +# the location of the communication and MPI libs are included too. +# If we don't find anything, use the default library path according +# to the aix ld manual. +# Store the results from the different compilers for each TAGNAME. +# Allow to override them for all tags through lt_cv_aix_libpath. +m4_defun([_LT_SYS_MODULE_PATH_AIX], +[m4_require([_LT_DECL_SED])dnl +if test set = "${lt_cv_aix_libpath+set}"; then + aix_libpath=$lt_cv_aix_libpath +else + AC_CACHE_VAL([_LT_TAGVAR([lt_cv_aix_libpath_], [$1])], + [AC_LINK_IFELSE([AC_LANG_PROGRAM],[ + lt_aix_libpath_sed='[ + /Import File Strings/,/^$/ { + /^0/ { + s/^0 *\([^ ]*\) *$/\1/ + p + } + }]' + _LT_TAGVAR([lt_cv_aix_libpath_], [$1])=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` + # Check for a 64-bit object if we didn't find anything. + if test -z "$_LT_TAGVAR([lt_cv_aix_libpath_], [$1])"; then + _LT_TAGVAR([lt_cv_aix_libpath_], [$1])=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` + fi],[]) + if test -z "$_LT_TAGVAR([lt_cv_aix_libpath_], [$1])"; then + _LT_TAGVAR([lt_cv_aix_libpath_], [$1])=/usr/lib:/lib + fi + ]) + aix_libpath=$_LT_TAGVAR([lt_cv_aix_libpath_], [$1]) +fi +])# _LT_SYS_MODULE_PATH_AIX + + +# _LT_SHELL_INIT(ARG) +# ------------------- +m4_define([_LT_SHELL_INIT], +[m4_divert_text([M4SH-INIT], [$1 +])])# _LT_SHELL_INIT + + + +# _LT_PROG_ECHO_BACKSLASH +# ----------------------- +# Find how we can fake an echo command that does not interpret backslash. +# In particular, with Autoconf 2.60 or later we add some code to the start +# of the generated configure script that will find a shell with a builtin +# printf (that we can use as an echo command). +m4_defun([_LT_PROG_ECHO_BACKSLASH], +[ECHO='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' +ECHO=$ECHO$ECHO$ECHO$ECHO$ECHO +ECHO=$ECHO$ECHO$ECHO$ECHO$ECHO$ECHO + +AC_MSG_CHECKING([how to print strings]) +# Test print first, because it will be a builtin if present. +if test "X`( print -r -- -n ) 2>/dev/null`" = X-n && \ + test "X`print -r -- $ECHO 2>/dev/null`" = "X$ECHO"; then + ECHO='print -r --' +elif test "X`printf %s $ECHO 2>/dev/null`" = "X$ECHO"; then + ECHO='printf %s\n' +else + # Use this function as a fallback that always works. + func_fallback_echo () + { + eval 'cat <<_LTECHO_EOF +$[]1 +_LTECHO_EOF' + } + ECHO='func_fallback_echo' +fi + +# func_echo_all arg... +# Invoke $ECHO with all args, space-separated. +func_echo_all () +{ + $ECHO "$*" +} + +case $ECHO in + printf*) AC_MSG_RESULT([printf]) ;; + print*) AC_MSG_RESULT([print -r]) ;; + *) AC_MSG_RESULT([cat]) ;; +esac + +m4_ifdef([_AS_DETECT_SUGGESTED], +[_AS_DETECT_SUGGESTED([ + test -n "${ZSH_VERSION+set}${BASH_VERSION+set}" || ( + ECHO='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' + ECHO=$ECHO$ECHO$ECHO$ECHO$ECHO + ECHO=$ECHO$ECHO$ECHO$ECHO$ECHO$ECHO + PATH=/empty FPATH=/empty; export PATH FPATH + test "X`printf %s $ECHO`" = "X$ECHO" \ + || test "X`print -r -- $ECHO`" = "X$ECHO" )])]) + +_LT_DECL([], [SHELL], [1], [Shell to use when invoking shell scripts]) +_LT_DECL([], [ECHO], [1], [An echo program that protects backslashes]) +])# _LT_PROG_ECHO_BACKSLASH + + +# _LT_WITH_SYSROOT +# ---------------- +AC_DEFUN([_LT_WITH_SYSROOT], +[AC_MSG_CHECKING([for sysroot]) +AC_ARG_WITH([sysroot], +[AS_HELP_STRING([--with-sysroot@<:@=DIR@:>@], + [Search for dependent libraries within DIR (or the compiler's sysroot + if not specified).])], +[], [with_sysroot=no]) + +dnl lt_sysroot will always be passed unquoted. We quote it here +dnl in case the user passed a directory name. +lt_sysroot= +case $with_sysroot in #( + yes) + if test yes = "$GCC"; then + lt_sysroot=`$CC --print-sysroot 2>/dev/null` + fi + ;; #( + /*) + lt_sysroot=`echo "$with_sysroot" | sed -e "$sed_quote_subst"` + ;; #( + no|'') + ;; #( + *) + AC_MSG_RESULT([$with_sysroot]) + AC_MSG_ERROR([The sysroot must be an absolute path.]) + ;; +esac + + AC_MSG_RESULT([${lt_sysroot:-no}]) +_LT_DECL([], [lt_sysroot], [0], [The root where to search for ]dnl +[dependent libraries, and where our libraries should be installed.])]) + +# _LT_ENABLE_LOCK +# --------------- +m4_defun([_LT_ENABLE_LOCK], +[AC_ARG_ENABLE([libtool-lock], + [AS_HELP_STRING([--disable-libtool-lock], + [avoid locking (might break parallel builds)])]) +test no = "$enable_libtool_lock" || enable_libtool_lock=yes + +# Some flags need to be propagated to the compiler or linker for good +# libtool support. +case $host in +ia64-*-hpux*) + # Find out what ABI is being produced by ac_compile, and set mode + # options accordingly. + echo 'int i;' > conftest.$ac_ext + if AC_TRY_EVAL(ac_compile); then + case `/usr/bin/file conftest.$ac_objext` in + *ELF-32*) + HPUX_IA64_MODE=32 + ;; + *ELF-64*) + HPUX_IA64_MODE=64 + ;; + esac + fi + rm -rf conftest* + ;; +*-*-irix6*) + # Find out what ABI is being produced by ac_compile, and set linker + # options accordingly. + echo '[#]line '$LINENO' "configure"' > conftest.$ac_ext + if AC_TRY_EVAL(ac_compile); then + if test yes = "$lt_cv_prog_gnu_ld"; then + case `/usr/bin/file conftest.$ac_objext` in + *32-bit*) + LD="${LD-ld} -melf32bsmip" + ;; + *N32*) + LD="${LD-ld} -melf32bmipn32" + ;; + *64-bit*) + LD="${LD-ld} -melf64bmip" + ;; + esac + else + case `/usr/bin/file conftest.$ac_objext` in + *32-bit*) + LD="${LD-ld} -32" + ;; + *N32*) + LD="${LD-ld} -n32" + ;; + *64-bit*) + LD="${LD-ld} -64" + ;; + esac + fi + fi + rm -rf conftest* + ;; + +mips64*-*linux*) + # Find out what ABI is being produced by ac_compile, and set linker + # options accordingly. + echo '[#]line '$LINENO' "configure"' > conftest.$ac_ext + if AC_TRY_EVAL(ac_compile); then + emul=elf + case `/usr/bin/file conftest.$ac_objext` in + *32-bit*) + emul="${emul}32" + ;; + *64-bit*) + emul="${emul}64" + ;; + esac + case `/usr/bin/file conftest.$ac_objext` in + *MSB*) + emul="${emul}btsmip" + ;; + *LSB*) + emul="${emul}ltsmip" + ;; + esac + case `/usr/bin/file conftest.$ac_objext` in + *N32*) + emul="${emul}n32" + ;; + esac + LD="${LD-ld} -m $emul" + fi + rm -rf conftest* + ;; + +x86_64-*kfreebsd*-gnu|x86_64-*linux*|powerpc*-*linux*| \ +s390*-*linux*|s390*-*tpf*|sparc*-*linux*) + # Find out what ABI is being produced by ac_compile, and set linker + # options accordingly. Note that the listed cases only cover the + # situations where additional linker options are needed (such as when + # doing 32-bit compilation for a host where ld defaults to 64-bit, or + # vice versa); the common cases where no linker options are needed do + # not appear in the list. + echo 'int i;' > conftest.$ac_ext + if AC_TRY_EVAL(ac_compile); then + case `/usr/bin/file conftest.o` in + *32-bit*) + case $host in + x86_64-*kfreebsd*-gnu) + LD="${LD-ld} -m elf_i386_fbsd" + ;; + x86_64-*linux*) + case `/usr/bin/file conftest.o` in + *x86-64*) + LD="${LD-ld} -m elf32_x86_64" + ;; + *) + LD="${LD-ld} -m elf_i386" + ;; + esac + ;; + powerpc64le-*linux*) + LD="${LD-ld} -m elf32lppclinux" + ;; + powerpc64-*linux*) + LD="${LD-ld} -m elf32ppclinux" + ;; + s390x-*linux*) + LD="${LD-ld} -m elf_s390" + ;; + sparc64-*linux*) + LD="${LD-ld} -m elf32_sparc" + ;; + esac + ;; + *64-bit*) + case $host in + x86_64-*kfreebsd*-gnu) + LD="${LD-ld} -m elf_x86_64_fbsd" + ;; + x86_64-*linux*) + LD="${LD-ld} -m elf_x86_64" + ;; + powerpcle-*linux*) + LD="${LD-ld} -m elf64lppc" + ;; + powerpc-*linux*) + LD="${LD-ld} -m elf64ppc" + ;; + s390*-*linux*|s390*-*tpf*) + LD="${LD-ld} -m elf64_s390" + ;; + sparc*-*linux*) + LD="${LD-ld} -m elf64_sparc" + ;; + esac + ;; + esac + fi + rm -rf conftest* + ;; + +*-*-sco3.2v5*) + # On SCO OpenServer 5, we need -belf to get full-featured binaries. + SAVE_CFLAGS=$CFLAGS + CFLAGS="$CFLAGS -belf" + AC_CACHE_CHECK([whether the C compiler needs -belf], lt_cv_cc_needs_belf, + [AC_LANG_PUSH(C) + AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],[[]])],[lt_cv_cc_needs_belf=yes],[lt_cv_cc_needs_belf=no]) + AC_LANG_POP]) + if test yes != "$lt_cv_cc_needs_belf"; then + # this is probably gcc 2.8.0, egcs 1.0 or newer; no need for -belf + CFLAGS=$SAVE_CFLAGS + fi + ;; +*-*solaris*) + # Find out what ABI is being produced by ac_compile, and set linker + # options accordingly. + echo 'int i;' > conftest.$ac_ext + if AC_TRY_EVAL(ac_compile); then + case `/usr/bin/file conftest.o` in + *64-bit*) + case $lt_cv_prog_gnu_ld in + yes*) + case $host in + i?86-*-solaris*|x86_64-*-solaris*) + LD="${LD-ld} -m elf_x86_64" + ;; + sparc*-*-solaris*) + LD="${LD-ld} -m elf64_sparc" + ;; + esac + # GNU ld 2.21 introduced _sol2 emulations. Use them if available. + if ${LD-ld} -V | grep _sol2 >/dev/null 2>&1; then + LD=${LD-ld}_sol2 + fi + ;; + *) + if ${LD-ld} -64 -r -o conftest2.o conftest.o >/dev/null 2>&1; then + LD="${LD-ld} -64" + fi + ;; + esac + ;; + esac + fi + rm -rf conftest* + ;; +esac + +need_locks=$enable_libtool_lock +])# _LT_ENABLE_LOCK + + +# _LT_PROG_AR +# ----------- +m4_defun([_LT_PROG_AR], +[AC_CHECK_TOOLS(AR, [ar], false) +: ${AR=ar} +: ${AR_FLAGS=cr} +_LT_DECL([], [AR], [1], [The archiver]) +_LT_DECL([], [AR_FLAGS], [1], [Flags to create an archive]) + +AC_CACHE_CHECK([for archiver @FILE support], [lt_cv_ar_at_file], + [lt_cv_ar_at_file=no + AC_COMPILE_IFELSE([AC_LANG_PROGRAM], + [echo conftest.$ac_objext > conftest.lst + lt_ar_try='$AR $AR_FLAGS libconftest.a @conftest.lst >&AS_MESSAGE_LOG_FD' + AC_TRY_EVAL([lt_ar_try]) + if test 0 -eq "$ac_status"; then + # Ensure the archiver fails upon bogus file names. + rm -f conftest.$ac_objext libconftest.a + AC_TRY_EVAL([lt_ar_try]) + if test 0 -ne "$ac_status"; then + lt_cv_ar_at_file=@ + fi + fi + rm -f conftest.* libconftest.a + ]) + ]) + +if test no = "$lt_cv_ar_at_file"; then + archiver_list_spec= +else + archiver_list_spec=$lt_cv_ar_at_file +fi +_LT_DECL([], [archiver_list_spec], [1], + [How to feed a file listing to the archiver]) +])# _LT_PROG_AR + + +# _LT_CMD_OLD_ARCHIVE +# ------------------- +m4_defun([_LT_CMD_OLD_ARCHIVE], +[_LT_PROG_AR + +AC_CHECK_TOOL(STRIP, strip, :) +test -z "$STRIP" && STRIP=: +_LT_DECL([], [STRIP], [1], [A symbol stripping program]) + +AC_CHECK_TOOL(RANLIB, ranlib, :) +test -z "$RANLIB" && RANLIB=: +_LT_DECL([], [RANLIB], [1], + [Commands used to install an old-style archive]) + +# Determine commands to create old-style static archives. +old_archive_cmds='$AR $AR_FLAGS $oldlib$oldobjs' +old_postinstall_cmds='chmod 644 $oldlib' +old_postuninstall_cmds= + +if test -n "$RANLIB"; then + case $host_os in + bitrig* | openbsd*) + old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB -t \$tool_oldlib" + ;; + *) + old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB \$tool_oldlib" + ;; + esac + old_archive_cmds="$old_archive_cmds~\$RANLIB \$tool_oldlib" +fi + +case $host_os in + darwin*) + lock_old_archive_extraction=yes ;; + *) + lock_old_archive_extraction=no ;; +esac +_LT_DECL([], [old_postinstall_cmds], [2]) +_LT_DECL([], [old_postuninstall_cmds], [2]) +_LT_TAGDECL([], [old_archive_cmds], [2], + [Commands used to build an old-style archive]) +_LT_DECL([], [lock_old_archive_extraction], [0], + [Whether to use a lock for old archive extraction]) +])# _LT_CMD_OLD_ARCHIVE + + +# _LT_COMPILER_OPTION(MESSAGE, VARIABLE-NAME, FLAGS, +# [OUTPUT-FILE], [ACTION-SUCCESS], [ACTION-FAILURE]) +# ---------------------------------------------------------------- +# Check whether the given compiler option works +AC_DEFUN([_LT_COMPILER_OPTION], +[m4_require([_LT_FILEUTILS_DEFAULTS])dnl +m4_require([_LT_DECL_SED])dnl +AC_CACHE_CHECK([$1], [$2], + [$2=no + m4_if([$4], , [ac_outfile=conftest.$ac_objext], [ac_outfile=$4]) + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + lt_compiler_flag="$3" ## exclude from sc_useless_quotes_in_assignment + # Insert the option either (1) after the last *FLAGS variable, or + # (2) before a word containing "conftest.", or (3) at the end. + # Note that $ac_compile itself does not contain backslashes and begins + # with a dollar sign (not a hyphen), so the echo should work correctly. + # The option is referenced via a variable to avoid confusing sed. + lt_compile=`echo "$ac_compile" | $SED \ + -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ + -e 's: [[^ ]]*conftest\.: $lt_compiler_flag&:; t' \ + -e 's:$: $lt_compiler_flag:'` + (eval echo "\"\$as_me:$LINENO: $lt_compile\"" >&AS_MESSAGE_LOG_FD) + (eval "$lt_compile" 2>conftest.err) + ac_status=$? + cat conftest.err >&AS_MESSAGE_LOG_FD + echo "$as_me:$LINENO: \$? = $ac_status" >&AS_MESSAGE_LOG_FD + if (exit $ac_status) && test -s "$ac_outfile"; then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings other than the usual output. + $ECHO "$_lt_compiler_boilerplate" | $SED '/^$/d' >conftest.exp + $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 + if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then + $2=yes + fi + fi + $RM conftest* +]) + +if test yes = "[$]$2"; then + m4_if([$5], , :, [$5]) +else + m4_if([$6], , :, [$6]) +fi +])# _LT_COMPILER_OPTION + +# Old name: +AU_ALIAS([AC_LIBTOOL_COMPILER_OPTION], [_LT_COMPILER_OPTION]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_LIBTOOL_COMPILER_OPTION], []) + + +# _LT_LINKER_OPTION(MESSAGE, VARIABLE-NAME, FLAGS, +# [ACTION-SUCCESS], [ACTION-FAILURE]) +# ---------------------------------------------------- +# Check whether the given linker option works +AC_DEFUN([_LT_LINKER_OPTION], +[m4_require([_LT_FILEUTILS_DEFAULTS])dnl +m4_require([_LT_DECL_SED])dnl +AC_CACHE_CHECK([$1], [$2], + [$2=no + save_LDFLAGS=$LDFLAGS + LDFLAGS="$LDFLAGS $3" + echo "$lt_simple_link_test_code" > conftest.$ac_ext + if (eval $ac_link 2>conftest.err) && test -s conftest$ac_exeext; then + # The linker can only warn and ignore the option if not recognized + # So say no if there are warnings + if test -s conftest.err; then + # Append any errors to the config.log. + cat conftest.err 1>&AS_MESSAGE_LOG_FD + $ECHO "$_lt_linker_boilerplate" | $SED '/^$/d' > conftest.exp + $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 + if diff conftest.exp conftest.er2 >/dev/null; then + $2=yes + fi + else + $2=yes + fi + fi + $RM -r conftest* + LDFLAGS=$save_LDFLAGS +]) + +if test yes = "[$]$2"; then + m4_if([$4], , :, [$4]) +else + m4_if([$5], , :, [$5]) +fi +])# _LT_LINKER_OPTION + +# Old name: +AU_ALIAS([AC_LIBTOOL_LINKER_OPTION], [_LT_LINKER_OPTION]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_LIBTOOL_LINKER_OPTION], []) + + +# LT_CMD_MAX_LEN +#--------------- +AC_DEFUN([LT_CMD_MAX_LEN], +[AC_REQUIRE([AC_CANONICAL_HOST])dnl +# find the maximum length of command line arguments +AC_MSG_CHECKING([the maximum length of command line arguments]) +AC_CACHE_VAL([lt_cv_sys_max_cmd_len], [dnl + i=0 + teststring=ABCD + + case $build_os in + msdosdjgpp*) + # On DJGPP, this test can blow up pretty badly due to problems in libc + # (any single argument exceeding 2000 bytes causes a buffer overrun + # during glob expansion). Even if it were fixed, the result of this + # check would be larger than it should be. + lt_cv_sys_max_cmd_len=12288; # 12K is about right + ;; + + gnu*) + # Under GNU Hurd, this test is not required because there is + # no limit to the length of command line arguments. + # Libtool will interpret -1 as no limit whatsoever + lt_cv_sys_max_cmd_len=-1; + ;; + + cygwin* | mingw* | cegcc*) + # On Win9x/ME, this test blows up -- it succeeds, but takes + # about 5 minutes as the teststring grows exponentially. + # Worse, since 9x/ME are not pre-emptively multitasking, + # you end up with a "frozen" computer, even though with patience + # the test eventually succeeds (with a max line length of 256k). + # Instead, let's just punt: use the minimum linelength reported by + # all of the supported platforms: 8192 (on NT/2K/XP). + lt_cv_sys_max_cmd_len=8192; + ;; + + mint*) + # On MiNT this can take a long time and run out of memory. + lt_cv_sys_max_cmd_len=8192; + ;; + + amigaos*) + # On AmigaOS with pdksh, this test takes hours, literally. + # So we just punt and use a minimum line length of 8192. + lt_cv_sys_max_cmd_len=8192; + ;; + + bitrig* | darwin* | dragonfly* | freebsd* | netbsd* | openbsd*) + # This has been around since 386BSD, at least. Likely further. + if test -x /sbin/sysctl; then + lt_cv_sys_max_cmd_len=`/sbin/sysctl -n kern.argmax` + elif test -x /usr/sbin/sysctl; then + lt_cv_sys_max_cmd_len=`/usr/sbin/sysctl -n kern.argmax` + else + lt_cv_sys_max_cmd_len=65536 # usable default for all BSDs + fi + # And add a safety zone + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4` + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3` + ;; + + interix*) + # We know the value 262144 and hardcode it with a safety zone (like BSD) + lt_cv_sys_max_cmd_len=196608 + ;; + + os2*) + # The test takes a long time on OS/2. + lt_cv_sys_max_cmd_len=8192 + ;; + + osf*) + # Dr. Hans Ekkehard Plesser reports seeing a kernel panic running configure + # due to this test when exec_disable_arg_limit is 1 on Tru64. It is not + # nice to cause kernel panics so lets avoid the loop below. + # First set a reasonable default. + lt_cv_sys_max_cmd_len=16384 + # + if test -x /sbin/sysconfig; then + case `/sbin/sysconfig -q proc exec_disable_arg_limit` in + *1*) lt_cv_sys_max_cmd_len=-1 ;; + esac + fi + ;; + sco3.2v5*) + lt_cv_sys_max_cmd_len=102400 + ;; + sysv5* | sco5v6* | sysv4.2uw2*) + kargmax=`grep ARG_MAX /etc/conf/cf.d/stune 2>/dev/null` + if test -n "$kargmax"; then + lt_cv_sys_max_cmd_len=`echo $kargmax | sed 's/.*[[ ]]//'` + else + lt_cv_sys_max_cmd_len=32768 + fi + ;; + *) + lt_cv_sys_max_cmd_len=`(getconf ARG_MAX) 2> /dev/null` + if test -n "$lt_cv_sys_max_cmd_len" && \ + test undefined != "$lt_cv_sys_max_cmd_len"; then + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4` + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3` + else + # Make teststring a little bigger before we do anything with it. + # a 1K string should be a reasonable start. + for i in 1 2 3 4 5 6 7 8; do + teststring=$teststring$teststring + done + SHELL=${SHELL-${CONFIG_SHELL-/bin/sh}} + # If test is not a shell built-in, we'll probably end up computing a + # maximum length that is only half of the actual maximum length, but + # we can't tell. + while { test X`env echo "$teststring$teststring" 2>/dev/null` \ + = "X$teststring$teststring"; } >/dev/null 2>&1 && + test 17 != "$i" # 1/2 MB should be enough + do + i=`expr $i + 1` + teststring=$teststring$teststring + done + # Only check the string length outside the loop. + lt_cv_sys_max_cmd_len=`expr "X$teststring" : ".*" 2>&1` + teststring= + # Add a significant safety factor because C++ compilers can tack on + # massive amounts of additional arguments before passing them to the + # linker. It appears as though 1/2 is a usable value. + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 2` + fi + ;; + esac +]) +if test -n "$lt_cv_sys_max_cmd_len"; then + AC_MSG_RESULT($lt_cv_sys_max_cmd_len) +else + AC_MSG_RESULT(none) +fi +max_cmd_len=$lt_cv_sys_max_cmd_len +_LT_DECL([], [max_cmd_len], [0], + [What is the maximum length of a command?]) +])# LT_CMD_MAX_LEN + +# Old name: +AU_ALIAS([AC_LIBTOOL_SYS_MAX_CMD_LEN], [LT_CMD_MAX_LEN]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_LIBTOOL_SYS_MAX_CMD_LEN], []) + + +# _LT_HEADER_DLFCN +# ---------------- +m4_defun([_LT_HEADER_DLFCN], +[AC_CHECK_HEADERS([dlfcn.h], [], [], [AC_INCLUDES_DEFAULT])dnl +])# _LT_HEADER_DLFCN + + +# _LT_TRY_DLOPEN_SELF (ACTION-IF-TRUE, ACTION-IF-TRUE-W-USCORE, +# ACTION-IF-FALSE, ACTION-IF-CROSS-COMPILING) +# ---------------------------------------------------------------- +m4_defun([_LT_TRY_DLOPEN_SELF], +[m4_require([_LT_HEADER_DLFCN])dnl +if test yes = "$cross_compiling"; then : + [$4] +else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +[#line $LINENO "configure" +#include "confdefs.h" + +#if HAVE_DLFCN_H +#include +#endif + +#include + +#ifdef RTLD_GLOBAL +# define LT_DLGLOBAL RTLD_GLOBAL +#else +# ifdef DL_GLOBAL +# define LT_DLGLOBAL DL_GLOBAL +# else +# define LT_DLGLOBAL 0 +# endif +#endif + +/* We may have to define LT_DLLAZY_OR_NOW in the command line if we + find out it does not work in some platform. */ +#ifndef LT_DLLAZY_OR_NOW +# ifdef RTLD_LAZY +# define LT_DLLAZY_OR_NOW RTLD_LAZY +# else +# ifdef DL_LAZY +# define LT_DLLAZY_OR_NOW DL_LAZY +# else +# ifdef RTLD_NOW +# define LT_DLLAZY_OR_NOW RTLD_NOW +# else +# ifdef DL_NOW +# define LT_DLLAZY_OR_NOW DL_NOW +# else +# define LT_DLLAZY_OR_NOW 0 +# endif +# endif +# endif +# endif +#endif + +/* When -fvisibility=hidden is used, assume the code has been annotated + correspondingly for the symbols needed. */ +#if defined __GNUC__ && (((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)) || (__GNUC__ > 3)) +int fnord () __attribute__((visibility("default"))); +#endif + +int fnord () { return 42; } +int main () +{ + void *self = dlopen (0, LT_DLGLOBAL|LT_DLLAZY_OR_NOW); + int status = $lt_dlunknown; + + if (self) + { + if (dlsym (self,"fnord")) status = $lt_dlno_uscore; + else + { + if (dlsym( self,"_fnord")) status = $lt_dlneed_uscore; + else puts (dlerror ()); + } + /* dlclose (self); */ + } + else + puts (dlerror ()); + + return status; +}] +_LT_EOF + if AC_TRY_EVAL(ac_link) && test -s "conftest$ac_exeext" 2>/dev/null; then + (./conftest; exit; ) >&AS_MESSAGE_LOG_FD 2>/dev/null + lt_status=$? + case x$lt_status in + x$lt_dlno_uscore) $1 ;; + x$lt_dlneed_uscore) $2 ;; + x$lt_dlunknown|x*) $3 ;; + esac + else : + # compilation failed + $3 + fi +fi +rm -fr conftest* +])# _LT_TRY_DLOPEN_SELF + + +# LT_SYS_DLOPEN_SELF +# ------------------ +AC_DEFUN([LT_SYS_DLOPEN_SELF], +[m4_require([_LT_HEADER_DLFCN])dnl +if test yes != "$enable_dlopen"; then + enable_dlopen=unknown + enable_dlopen_self=unknown + enable_dlopen_self_static=unknown +else + lt_cv_dlopen=no + lt_cv_dlopen_libs= + + case $host_os in + beos*) + lt_cv_dlopen=load_add_on + lt_cv_dlopen_libs= + lt_cv_dlopen_self=yes + ;; + + mingw* | pw32* | cegcc*) + lt_cv_dlopen=LoadLibrary + lt_cv_dlopen_libs= + ;; + + cygwin*) + lt_cv_dlopen=dlopen + lt_cv_dlopen_libs= + ;; + + darwin*) + # if libdl is installed we need to link against it + AC_CHECK_LIB([dl], [dlopen], + [lt_cv_dlopen=dlopen lt_cv_dlopen_libs=-ldl],[ + lt_cv_dlopen=dyld + lt_cv_dlopen_libs= + lt_cv_dlopen_self=yes + ]) + ;; + + tpf*) + # Don't try to run any link tests for TPF. We know it's impossible + # because TPF is a cross-compiler, and we know how we open DSOs. + lt_cv_dlopen=dlopen + lt_cv_dlopen_libs= + lt_cv_dlopen_self=no + ;; + + *) + AC_CHECK_FUNC([shl_load], + [lt_cv_dlopen=shl_load], + [AC_CHECK_LIB([dld], [shl_load], + [lt_cv_dlopen=shl_load lt_cv_dlopen_libs=-ldld], + [AC_CHECK_FUNC([dlopen], + [lt_cv_dlopen=dlopen], + [AC_CHECK_LIB([dl], [dlopen], + [lt_cv_dlopen=dlopen lt_cv_dlopen_libs=-ldl], + [AC_CHECK_LIB([svld], [dlopen], + [lt_cv_dlopen=dlopen lt_cv_dlopen_libs=-lsvld], + [AC_CHECK_LIB([dld], [dld_link], + [lt_cv_dlopen=dld_link lt_cv_dlopen_libs=-ldld]) + ]) + ]) + ]) + ]) + ]) + ;; + esac + + if test no = "$lt_cv_dlopen"; then + enable_dlopen=no + else + enable_dlopen=yes + fi + + case $lt_cv_dlopen in + dlopen) + save_CPPFLAGS=$CPPFLAGS + test yes = "$ac_cv_header_dlfcn_h" && CPPFLAGS="$CPPFLAGS -DHAVE_DLFCN_H" + + save_LDFLAGS=$LDFLAGS + wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $export_dynamic_flag_spec\" + + save_LIBS=$LIBS + LIBS="$lt_cv_dlopen_libs $LIBS" + + AC_CACHE_CHECK([whether a program can dlopen itself], + lt_cv_dlopen_self, [dnl + _LT_TRY_DLOPEN_SELF( + lt_cv_dlopen_self=yes, lt_cv_dlopen_self=yes, + lt_cv_dlopen_self=no, lt_cv_dlopen_self=cross) + ]) + + if test yes = "$lt_cv_dlopen_self"; then + wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $lt_prog_compiler_static\" + AC_CACHE_CHECK([whether a statically linked program can dlopen itself], + lt_cv_dlopen_self_static, [dnl + _LT_TRY_DLOPEN_SELF( + lt_cv_dlopen_self_static=yes, lt_cv_dlopen_self_static=yes, + lt_cv_dlopen_self_static=no, lt_cv_dlopen_self_static=cross) + ]) + fi + + CPPFLAGS=$save_CPPFLAGS + LDFLAGS=$save_LDFLAGS + LIBS=$save_LIBS + ;; + esac + + case $lt_cv_dlopen_self in + yes|no) enable_dlopen_self=$lt_cv_dlopen_self ;; + *) enable_dlopen_self=unknown ;; + esac + + case $lt_cv_dlopen_self_static in + yes|no) enable_dlopen_self_static=$lt_cv_dlopen_self_static ;; + *) enable_dlopen_self_static=unknown ;; + esac +fi +_LT_DECL([dlopen_support], [enable_dlopen], [0], + [Whether dlopen is supported]) +_LT_DECL([dlopen_self], [enable_dlopen_self], [0], + [Whether dlopen of programs is supported]) +_LT_DECL([dlopen_self_static], [enable_dlopen_self_static], [0], + [Whether dlopen of statically linked programs is supported]) +])# LT_SYS_DLOPEN_SELF + +# Old name: +AU_ALIAS([AC_LIBTOOL_DLOPEN_SELF], [LT_SYS_DLOPEN_SELF]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_LIBTOOL_DLOPEN_SELF], []) + + +# _LT_COMPILER_C_O([TAGNAME]) +# --------------------------- +# Check to see if options -c and -o are simultaneously supported by compiler. +# This macro does not hard code the compiler like AC_PROG_CC_C_O. +m4_defun([_LT_COMPILER_C_O], +[m4_require([_LT_DECL_SED])dnl +m4_require([_LT_FILEUTILS_DEFAULTS])dnl +m4_require([_LT_TAG_COMPILER])dnl +AC_CACHE_CHECK([if $compiler supports -c -o file.$ac_objext], + [_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)], + [_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)=no + $RM -r conftest 2>/dev/null + mkdir conftest + cd conftest + mkdir out + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + + lt_compiler_flag="-o out/conftest2.$ac_objext" + # Insert the option either (1) after the last *FLAGS variable, or + # (2) before a word containing "conftest.", or (3) at the end. + # Note that $ac_compile itself does not contain backslashes and begins + # with a dollar sign (not a hyphen), so the echo should work correctly. + lt_compile=`echo "$ac_compile" | $SED \ + -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ + -e 's: [[^ ]]*conftest\.: $lt_compiler_flag&:; t' \ + -e 's:$: $lt_compiler_flag:'` + (eval echo "\"\$as_me:$LINENO: $lt_compile\"" >&AS_MESSAGE_LOG_FD) + (eval "$lt_compile" 2>out/conftest.err) + ac_status=$? + cat out/conftest.err >&AS_MESSAGE_LOG_FD + echo "$as_me:$LINENO: \$? = $ac_status" >&AS_MESSAGE_LOG_FD + if (exit $ac_status) && test -s out/conftest2.$ac_objext + then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings + $ECHO "$_lt_compiler_boilerplate" | $SED '/^$/d' > out/conftest.exp + $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2 + if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then + _LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)=yes + fi + fi + chmod u+w . 2>&AS_MESSAGE_LOG_FD + $RM conftest* + # SGI C++ compiler will create directory out/ii_files/ for + # template instantiation + test -d out/ii_files && $RM out/ii_files/* && rmdir out/ii_files + $RM out/* && rmdir out + cd .. + $RM -r conftest + $RM conftest* +]) +_LT_TAGDECL([compiler_c_o], [lt_cv_prog_compiler_c_o], [1], + [Does compiler simultaneously support -c and -o options?]) +])# _LT_COMPILER_C_O + + +# _LT_COMPILER_FILE_LOCKS([TAGNAME]) +# ---------------------------------- +# Check to see if we can do hard links to lock some files if needed +m4_defun([_LT_COMPILER_FILE_LOCKS], +[m4_require([_LT_ENABLE_LOCK])dnl +m4_require([_LT_FILEUTILS_DEFAULTS])dnl +_LT_COMPILER_C_O([$1]) + +hard_links=nottested +if test no = "$_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)" && test no != "$need_locks"; then + # do not overwrite the value of need_locks provided by the user + AC_MSG_CHECKING([if we can lock with hard links]) + hard_links=yes + $RM conftest* + ln conftest.a conftest.b 2>/dev/null && hard_links=no + touch conftest.a + ln conftest.a conftest.b 2>&5 || hard_links=no + ln conftest.a conftest.b 2>/dev/null && hard_links=no + AC_MSG_RESULT([$hard_links]) + if test no = "$hard_links"; then + AC_MSG_WARN(['$CC' does not support '-c -o', so 'make -j' may be unsafe]) + need_locks=warn + fi +else + need_locks=no +fi +_LT_DECL([], [need_locks], [1], [Must we lock files when doing compilation?]) +])# _LT_COMPILER_FILE_LOCKS + + +# _LT_CHECK_OBJDIR +# ---------------- +m4_defun([_LT_CHECK_OBJDIR], +[AC_CACHE_CHECK([for objdir], [lt_cv_objdir], +[rm -f .libs 2>/dev/null +mkdir .libs 2>/dev/null +if test -d .libs; then + lt_cv_objdir=.libs +else + # MS-DOS does not allow filenames that begin with a dot. + lt_cv_objdir=_libs +fi +rmdir .libs 2>/dev/null]) +objdir=$lt_cv_objdir +_LT_DECL([], [objdir], [0], + [The name of the directory that contains temporary libtool files])dnl +m4_pattern_allow([LT_OBJDIR])dnl +AC_DEFINE_UNQUOTED([LT_OBJDIR], "$lt_cv_objdir/", + [Define to the sub-directory where libtool stores uninstalled libraries.]) +])# _LT_CHECK_OBJDIR + + +# _LT_LINKER_HARDCODE_LIBPATH([TAGNAME]) +# -------------------------------------- +# Check hardcoding attributes. +m4_defun([_LT_LINKER_HARDCODE_LIBPATH], +[AC_MSG_CHECKING([how to hardcode library paths into programs]) +_LT_TAGVAR(hardcode_action, $1)= +if test -n "$_LT_TAGVAR(hardcode_libdir_flag_spec, $1)" || + test -n "$_LT_TAGVAR(runpath_var, $1)" || + test yes = "$_LT_TAGVAR(hardcode_automatic, $1)"; then + + # We can hardcode non-existent directories. + if test no != "$_LT_TAGVAR(hardcode_direct, $1)" && + # If the only mechanism to avoid hardcoding is shlibpath_var, we + # have to relink, otherwise we might link with an installed library + # when we should be linking with a yet-to-be-installed one + ## test no != "$_LT_TAGVAR(hardcode_shlibpath_var, $1)" && + test no != "$_LT_TAGVAR(hardcode_minus_L, $1)"; then + # Linking always hardcodes the temporary library directory. + _LT_TAGVAR(hardcode_action, $1)=relink + else + # We can link without hardcoding, and we can hardcode nonexisting dirs. + _LT_TAGVAR(hardcode_action, $1)=immediate + fi +else + # We cannot hardcode anything, or else we can only hardcode existing + # directories. + _LT_TAGVAR(hardcode_action, $1)=unsupported +fi +AC_MSG_RESULT([$_LT_TAGVAR(hardcode_action, $1)]) + +if test relink = "$_LT_TAGVAR(hardcode_action, $1)" || + test yes = "$_LT_TAGVAR(inherit_rpath, $1)"; then + # Fast installation is not supported + enable_fast_install=no +elif test yes = "$shlibpath_overrides_runpath" || + test no = "$enable_shared"; then + # Fast installation is not necessary + enable_fast_install=needless +fi +_LT_TAGDECL([], [hardcode_action], [0], + [How to hardcode a shared library path into an executable]) +])# _LT_LINKER_HARDCODE_LIBPATH + + +# _LT_CMD_STRIPLIB +# ---------------- +m4_defun([_LT_CMD_STRIPLIB], +[m4_require([_LT_DECL_EGREP]) +striplib= +old_striplib= +AC_MSG_CHECKING([whether stripping libraries is possible]) +if test -n "$STRIP" && $STRIP -V 2>&1 | $GREP "GNU strip" >/dev/null; then + test -z "$old_striplib" && old_striplib="$STRIP --strip-debug" + test -z "$striplib" && striplib="$STRIP --strip-unneeded" + AC_MSG_RESULT([yes]) +else +# FIXME - insert some real tests, host_os isn't really good enough + case $host_os in + darwin*) + if test -n "$STRIP"; then + striplib="$STRIP -x" + old_striplib="$STRIP -S" + AC_MSG_RESULT([yes]) + else + AC_MSG_RESULT([no]) + fi + ;; + *) + AC_MSG_RESULT([no]) + ;; + esac +fi +_LT_DECL([], [old_striplib], [1], [Commands to strip libraries]) +_LT_DECL([], [striplib], [1]) +])# _LT_CMD_STRIPLIB + + +# _LT_PREPARE_MUNGE_PATH_LIST +# --------------------------- +# Make sure func_munge_path_list() is defined correctly. +m4_defun([_LT_PREPARE_MUNGE_PATH_LIST], +[[# func_munge_path_list VARIABLE PATH +# ----------------------------------- +# VARIABLE is name of variable containing _space_ separated list of +# directories to be munged by the contents of PATH, which is string +# having a format: +# "DIR[:DIR]:" +# string "DIR[ DIR]" will be prepended to VARIABLE +# ":DIR[:DIR]" +# string "DIR[ DIR]" will be appended to VARIABLE +# "DIRP[:DIRP]::[DIRA:]DIRA" +# string "DIRP[ DIRP]" will be prepended to VARIABLE and string +# "DIRA[ DIRA]" will be appended to VARIABLE +# "DIR[:DIR]" +# VARIABLE will be replaced by "DIR[ DIR]" +func_munge_path_list () +{ + case x@S|@2 in + x) + ;; + *:) + eval @S|@1=\"`$ECHO @S|@2 | $SED 's/:/ /g'` \@S|@@S|@1\" + ;; + x:*) + eval @S|@1=\"\@S|@@S|@1 `$ECHO @S|@2 | $SED 's/:/ /g'`\" + ;; + *::*) + eval @S|@1=\"\@S|@@S|@1\ `$ECHO @S|@2 | $SED -e 's/.*:://' -e 's/:/ /g'`\" + eval @S|@1=\"`$ECHO @S|@2 | $SED -e 's/::.*//' -e 's/:/ /g'`\ \@S|@@S|@1\" + ;; + *) + eval @S|@1=\"`$ECHO @S|@2 | $SED 's/:/ /g'`\" + ;; + esac +} +]])# _LT_PREPARE_PATH_LIST + + +# _LT_SYS_DYNAMIC_LINKER([TAG]) +# ----------------------------- +# PORTME Fill in your ld.so characteristics +m4_defun([_LT_SYS_DYNAMIC_LINKER], +[AC_REQUIRE([AC_CANONICAL_HOST])dnl +m4_require([_LT_DECL_EGREP])dnl +m4_require([_LT_FILEUTILS_DEFAULTS])dnl +m4_require([_LT_DECL_OBJDUMP])dnl +m4_require([_LT_DECL_SED])dnl +m4_require([_LT_CHECK_SHELL_FEATURES])dnl +m4_require([_LT_PREPARE_MUNGE_PATH_LIST])dnl +AC_MSG_CHECKING([dynamic linker characteristics]) +m4_if([$1], + [], [ +if test yes = "$GCC"; then + case $host_os in + darwin*) lt_awk_arg='/^libraries:/,/LR/' ;; + *) lt_awk_arg='/^libraries:/' ;; + esac + case $host_os in + mingw* | cegcc*) lt_sed_strip_eq='s|=\([[A-Za-z]]:\)|\1|g' ;; + *) lt_sed_strip_eq='s|=/|/|g' ;; + esac + lt_search_path_spec=`$CC -print-search-dirs | awk $lt_awk_arg | $SED -e "s/^libraries://" -e $lt_sed_strip_eq` + case $lt_search_path_spec in + *\;*) + # if the path contains ";" then we assume it to be the separator + # otherwise default to the standard path separator (i.e. ":") - it is + # assumed that no part of a normal pathname contains ";" but that should + # okay in the real world where ";" in dirpaths is itself problematic. + lt_search_path_spec=`$ECHO "$lt_search_path_spec" | $SED 's/;/ /g'` + ;; + *) + lt_search_path_spec=`$ECHO "$lt_search_path_spec" | $SED "s/$PATH_SEPARATOR/ /g"` + ;; + esac + # Ok, now we have the path, separated by spaces, we can step through it + # and add multilib dir if necessary... + lt_tmp_lt_search_path_spec= + lt_multi_os_dir=/`$CC $CPPFLAGS $CFLAGS $LDFLAGS -print-multi-os-directory 2>/dev/null` + # ...but if some path component already ends with the multilib dir we assume + # that all is fine and trust -print-search-dirs as is (GCC 4.2? or newer). + case "$lt_multi_os_dir; $lt_search_path_spec " in + "/; "* | "/.; "* | "/./; "* | *"$lt_multi_os_dir "* | *"$lt_multi_os_dir/ "*) + lt_multi_os_dir= + ;; + esac + for lt_sys_path in $lt_search_path_spec; do + if test -d "$lt_sys_path$lt_multi_os_dir"; then + lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path$lt_multi_os_dir" + elif test -n "$lt_multi_os_dir"; then + test -d "$lt_sys_path" && \ + lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path" + fi + done + lt_search_path_spec=`$ECHO "$lt_tmp_lt_search_path_spec" | awk ' +BEGIN {RS = " "; FS = "/|\n";} { + lt_foo = ""; + lt_count = 0; + for (lt_i = NF; lt_i > 0; lt_i--) { + if ($lt_i != "" && $lt_i != ".") { + if ($lt_i == "..") { + lt_count++; + } else { + if (lt_count == 0) { + lt_foo = "/" $lt_i lt_foo; + } else { + lt_count--; + } + } + } + } + if (lt_foo != "") { lt_freq[[lt_foo]]++; } + if (lt_freq[[lt_foo]] == 1) { print lt_foo; } +}'` + # AWK program above erroneously prepends '/' to C:/dos/paths + # for these hosts. + case $host_os in + mingw* | cegcc*) lt_search_path_spec=`$ECHO "$lt_search_path_spec" |\ + $SED 's|/\([[A-Za-z]]:\)|\1|g'` ;; + esac + sys_lib_search_path_spec=`$ECHO "$lt_search_path_spec" | $lt_NL2SP` +else + sys_lib_search_path_spec="/lib /usr/lib /usr/local/lib" +fi]) +library_names_spec= +libname_spec='lib$name' +soname_spec= +shrext_cmds=.so +postinstall_cmds= +postuninstall_cmds= +finish_cmds= +finish_eval= +shlibpath_var= +shlibpath_overrides_runpath=unknown +version_type=none +dynamic_linker="$host_os ld.so" +sys_lib_dlsearch_path_spec="/lib /usr/lib" +need_lib_prefix=unknown +hardcode_into_libs=no + +# when you set need_version to no, make sure it does not cause -set_version +# flags to be left without arguments +need_version=unknown + +AC_ARG_VAR([LT_SYS_LIBRARY_PATH], +[User-defined run-time library search path.]) + +case $host_os in +aix3*) + version_type=linux # correct to gnu/linux during the next big refactor + library_names_spec='$libname$release$shared_ext$versuffix $libname.a' + shlibpath_var=LIBPATH + + # AIX 3 has no versioning support, so we append a major version to the name. + soname_spec='$libname$release$shared_ext$major' + ;; + +aix[[4-9]]*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + hardcode_into_libs=yes + if test ia64 = "$host_cpu"; then + # AIX 5 supports IA64 + library_names_spec='$libname$release$shared_ext$major $libname$release$shared_ext$versuffix $libname$shared_ext' + shlibpath_var=LD_LIBRARY_PATH + else + # With GCC up to 2.95.x, collect2 would create an import file + # for dependence libraries. The import file would start with + # the line '#! .'. This would cause the generated library to + # depend on '.', always an invalid library. This was fixed in + # development snapshots of GCC prior to 3.0. + case $host_os in + aix4 | aix4.[[01]] | aix4.[[01]].*) + if { echo '#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 97)' + echo ' yes ' + echo '#endif'; } | $CC -E - | $GREP yes > /dev/null; then + : + else + can_build_shared=no + fi + ;; + esac + # Using Import Files as archive members, it is possible to support + # filename-based versioning of shared library archives on AIX. While + # this would work for both with and without runtime linking, it will + # prevent static linking of such archives. So we do filename-based + # shared library versioning with .so extension only, which is used + # when both runtime linking and shared linking is enabled. + # Unfortunately, runtime linking may impact performance, so we do + # not want this to be the default eventually. Also, we use the + # versioned .so libs for executables only if there is the -brtl + # linker flag in LDFLAGS as well, or --with-aix-soname=svr4 only. + # To allow for filename-based versioning support, we need to create + # libNAME.so.V as an archive file, containing: + # *) an Import File, referring to the versioned filename of the + # archive as well as the shared archive member, telling the + # bitwidth (32 or 64) of that shared object, and providing the + # list of exported symbols of that shared object, eventually + # decorated with the 'weak' keyword + # *) the shared object with the F_LOADONLY flag set, to really avoid + # it being seen by the linker. + # At run time we better use the real file rather than another symlink, + # but for link time we create the symlink libNAME.so -> libNAME.so.V + + case $with_aix_soname,$aix_use_runtimelinking in + # AIX (on Power*) has no versioning support, so currently we cannot hardcode correct + # soname into executable. Probably we can add versioning support to + # collect2, so additional links can be useful in future. + aix,yes) # traditional libtool + dynamic_linker='AIX unversionable lib.so' + # If using run time linking (on AIX 4.2 or later) use lib.so + # instead of lib.a to let people know that these are not + # typical AIX shared libraries. + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + ;; + aix,no) # traditional AIX only + dynamic_linker='AIX lib.a[(]lib.so.V[)]' + # We preserve .a as extension for shared libraries through AIX4.2 + # and later when we are not doing run time linking. + library_names_spec='$libname$release.a $libname.a' + soname_spec='$libname$release$shared_ext$major' + ;; + svr4,*) # full svr4 only + dynamic_linker="AIX lib.so.V[(]$shared_archive_member_spec.o[)]" + library_names_spec='$libname$release$shared_ext$major $libname$shared_ext' + # We do not specify a path in Import Files, so LIBPATH fires. + shlibpath_overrides_runpath=yes + ;; + *,yes) # both, prefer svr4 + dynamic_linker="AIX lib.so.V[(]$shared_archive_member_spec.o[)], lib.a[(]lib.so.V[)]" + library_names_spec='$libname$release$shared_ext$major $libname$shared_ext' + # unpreferred sharedlib libNAME.a needs extra handling + postinstall_cmds='test -n "$linkname" || linkname="$realname"~func_stripname "" ".so" "$linkname"~$install_shared_prog "$dir/$func_stripname_result.$libext" "$destdir/$func_stripname_result.$libext"~test -z "$tstripme" || test -z "$striplib" || $striplib "$destdir/$func_stripname_result.$libext"' + postuninstall_cmds='for n in $library_names $old_library; do :; done~func_stripname "" ".so" "$n"~test "$func_stripname_result" = "$n" || func_append rmfiles " $odir/$func_stripname_result.$libext"' + # We do not specify a path in Import Files, so LIBPATH fires. + shlibpath_overrides_runpath=yes + ;; + *,no) # both, prefer aix + dynamic_linker="AIX lib.a[(]lib.so.V[)], lib.so.V[(]$shared_archive_member_spec.o[)]" + library_names_spec='$libname$release.a $libname.a' + soname_spec='$libname$release$shared_ext$major' + # unpreferred sharedlib libNAME.so.V and symlink libNAME.so need extra handling + postinstall_cmds='test -z "$dlname" || $install_shared_prog $dir/$dlname $destdir/$dlname~test -z "$tstripme" || test -z "$striplib" || $striplib $destdir/$dlname~test -n "$linkname" || linkname=$realname~func_stripname "" ".a" "$linkname"~(cd "$destdir" && $LN_S -f $dlname $func_stripname_result.so)' + postuninstall_cmds='test -z "$dlname" || func_append rmfiles " $odir/$dlname"~for n in $old_library $library_names; do :; done~func_stripname "" ".a" "$n"~func_append rmfiles " $odir/$func_stripname_result.so"' + ;; + esac + shlibpath_var=LIBPATH + fi + ;; + +amigaos*) + case $host_cpu in + powerpc) + # Since July 2007 AmigaOS4 officially supports .so libraries. + # When compiling the executable, add -use-dynld -Lsobjs: to the compileline. + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + ;; + m68k) + library_names_spec='$libname.ixlibrary $libname.a' + # Create ${libname}_ixlibrary.a entries in /sys/libs. + finish_eval='for lib in `ls $libdir/*.ixlibrary 2>/dev/null`; do libname=`func_echo_all "$lib" | $SED '\''s%^.*/\([[^/]]*\)\.ixlibrary$%\1%'\''`; $RM /sys/libs/${libname}_ixlibrary.a; $show "cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a"; cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a || exit 1; done' + ;; + esac + ;; + +beos*) + library_names_spec='$libname$shared_ext' + dynamic_linker="$host_os ld.so" + shlibpath_var=LIBRARY_PATH + ;; + +bsdi[[45]]*) + version_type=linux # correct to gnu/linux during the next big refactor + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + finish_cmds='PATH="\$PATH:/sbin" ldconfig $libdir' + shlibpath_var=LD_LIBRARY_PATH + sys_lib_search_path_spec="/shlib /usr/lib /usr/X11/lib /usr/contrib/lib /lib /usr/local/lib" + sys_lib_dlsearch_path_spec="/shlib /usr/lib /usr/local/lib" + # the default ld.so.conf also contains /usr/contrib/lib and + # /usr/X11R6/lib (/usr/X11 is a link to /usr/X11R6), but let us allow + # libtool to hard-code these into programs + ;; + +cygwin* | mingw* | pw32* | cegcc*) + version_type=windows + shrext_cmds=.dll + need_version=no + need_lib_prefix=no + + case $GCC,$cc_basename in + yes,*) + # gcc + library_names_spec='$libname.dll.a' + # DLL is installed to $(libdir)/../bin by postinstall_cmds + postinstall_cmds='base_file=`basename \$file`~ + dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\$base_file'\''i; echo \$dlname'\''`~ + dldir=$destdir/`dirname \$dlpath`~ + test -d \$dldir || mkdir -p \$dldir~ + $install_prog $dir/$dlname \$dldir/$dlname~ + chmod a+x \$dldir/$dlname~ + if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then + eval '\''$striplib \$dldir/$dlname'\'' || exit \$?; + fi' + postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~ + dlpath=$dir/\$dldll~ + $RM \$dlpath' + shlibpath_overrides_runpath=yes + + case $host_os in + cygwin*) + # Cygwin DLLs use 'cyg' prefix rather than 'lib' + soname_spec='`echo $libname | sed -e 's/^lib/cyg/'``echo $release | $SED -e 's/[[.]]/-/g'`$versuffix$shared_ext' +m4_if([$1], [],[ + sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/lib/w32api"]) + ;; + mingw* | cegcc*) + # MinGW DLLs use traditional 'lib' prefix + soname_spec='$libname`echo $release | $SED -e 's/[[.]]/-/g'`$versuffix$shared_ext' + ;; + pw32*) + # pw32 DLLs use 'pw' prefix rather than 'lib' + library_names_spec='`echo $libname | sed -e 's/^lib/pw/'``echo $release | $SED -e 's/[[.]]/-/g'`$versuffix$shared_ext' + ;; + esac + dynamic_linker='Win32 ld.exe' + ;; + + *,cl*) + # Native MSVC + libname_spec='$name' + soname_spec='$libname`echo $release | $SED -e 's/[[.]]/-/g'`$versuffix$shared_ext' + library_names_spec='$libname.dll.lib' + + case $build_os in + mingw*) + sys_lib_search_path_spec= + lt_save_ifs=$IFS + IFS=';' + for lt_path in $LIB + do + IFS=$lt_save_ifs + # Let DOS variable expansion print the short 8.3 style file name. + lt_path=`cd "$lt_path" 2>/dev/null && cmd //C "for %i in (".") do @echo %~si"` + sys_lib_search_path_spec="$sys_lib_search_path_spec $lt_path" + done + IFS=$lt_save_ifs + # Convert to MSYS style. + sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | sed -e 's|\\\\|/|g' -e 's| \\([[a-zA-Z]]\\):| /\\1|g' -e 's|^ ||'` + ;; + cygwin*) + # Convert to unix form, then to dos form, then back to unix form + # but this time dos style (no spaces!) so that the unix form looks + # like /cygdrive/c/PROGRA~1:/cygdr... + sys_lib_search_path_spec=`cygpath --path --unix "$LIB"` + sys_lib_search_path_spec=`cygpath --path --dos "$sys_lib_search_path_spec" 2>/dev/null` + sys_lib_search_path_spec=`cygpath --path --unix "$sys_lib_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"` + ;; + *) + sys_lib_search_path_spec=$LIB + if $ECHO "$sys_lib_search_path_spec" | [$GREP ';[c-zC-Z]:/' >/dev/null]; then + # It is most probably a Windows format PATH. + sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e 's/;/ /g'` + else + sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"` + fi + # FIXME: find the short name or the path components, as spaces are + # common. (e.g. "Program Files" -> "PROGRA~1") + ;; + esac + + # DLL is installed to $(libdir)/../bin by postinstall_cmds + postinstall_cmds='base_file=`basename \$file`~ + dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\$base_file'\''i; echo \$dlname'\''`~ + dldir=$destdir/`dirname \$dlpath`~ + test -d \$dldir || mkdir -p \$dldir~ + $install_prog $dir/$dlname \$dldir/$dlname' + postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~ + dlpath=$dir/\$dldll~ + $RM \$dlpath' + shlibpath_overrides_runpath=yes + dynamic_linker='Win32 link.exe' + ;; + + *) + # Assume MSVC wrapper + library_names_spec='$libname`echo $release | $SED -e 's/[[.]]/-/g'`$versuffix$shared_ext $libname.lib' + dynamic_linker='Win32 ld.exe' + ;; + esac + # FIXME: first we should search . and the directory the executable is in + shlibpath_var=PATH + ;; + +darwin* | rhapsody*) + dynamic_linker="$host_os dyld" + version_type=darwin + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$major$shared_ext $libname$shared_ext' + soname_spec='$libname$release$major$shared_ext' + shlibpath_overrides_runpath=yes + shlibpath_var=DYLD_LIBRARY_PATH + shrext_cmds='`test .$module = .yes && echo .so || echo .dylib`' +m4_if([$1], [],[ + sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/local/lib"]) + sys_lib_dlsearch_path_spec='/usr/local/lib /lib /usr/lib' + ;; + +dgux*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + ;; + +freebsd* | dragonfly*) + # DragonFly does not have aout. When/if they implement a new + # versioning mechanism, adjust this. + if test -x /usr/bin/objformat; then + objformat=`/usr/bin/objformat` + else + case $host_os in + freebsd[[23]].*) objformat=aout ;; + *) objformat=elf ;; + esac + fi + version_type=freebsd-$objformat + case $version_type in + freebsd-elf*) + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + need_version=no + need_lib_prefix=no + ;; + freebsd-*) + library_names_spec='$libname$release$shared_ext$versuffix $libname$shared_ext$versuffix' + need_version=yes + ;; + esac + shlibpath_var=LD_LIBRARY_PATH + case $host_os in + freebsd2.*) + shlibpath_overrides_runpath=yes + ;; + freebsd3.[[01]]* | freebsdelf3.[[01]]*) + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + freebsd3.[[2-9]]* | freebsdelf3.[[2-9]]* | \ + freebsd4.[[0-5]] | freebsdelf4.[[0-5]] | freebsd4.1.1 | freebsdelf4.1.1) + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + ;; + *) # from 4.6 on, and DragonFly + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + esac + ;; + +haiku*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + dynamic_linker="$host_os runtime_loader" + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LIBRARY_PATH + shlibpath_overrides_runpath=no + sys_lib_dlsearch_path_spec='/boot/home/config/lib /boot/common/lib /boot/system/lib' + hardcode_into_libs=yes + ;; + +hpux9* | hpux10* | hpux11*) + # Give a soname corresponding to the major version so that dld.sl refuses to + # link against other versions. + version_type=sunos + need_lib_prefix=no + need_version=no + case $host_cpu in + ia64*) + shrext_cmds='.so' + hardcode_into_libs=yes + dynamic_linker="$host_os dld.so" + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes # Unless +noenvvar is specified. + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + if test 32 = "$HPUX_IA64_MODE"; then + sys_lib_search_path_spec="/usr/lib/hpux32 /usr/local/lib/hpux32 /usr/local/lib" + sys_lib_dlsearch_path_spec=/usr/lib/hpux32 + else + sys_lib_search_path_spec="/usr/lib/hpux64 /usr/local/lib/hpux64" + sys_lib_dlsearch_path_spec=/usr/lib/hpux64 + fi + ;; + hppa*64*) + shrext_cmds='.sl' + hardcode_into_libs=yes + dynamic_linker="$host_os dld.sl" + shlibpath_var=LD_LIBRARY_PATH # How should we handle SHLIB_PATH + shlibpath_overrides_runpath=yes # Unless +noenvvar is specified. + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + sys_lib_search_path_spec="/usr/lib/pa20_64 /usr/ccs/lib/pa20_64" + sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec + ;; + *) + shrext_cmds='.sl' + dynamic_linker="$host_os dld.sl" + shlibpath_var=SHLIB_PATH + shlibpath_overrides_runpath=no # +s is required to enable SHLIB_PATH + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + ;; + esac + # HP-UX runs *really* slowly unless shared libraries are mode 555, ... + postinstall_cmds='chmod 555 $lib' + # or fails outright, so override atomically: + install_override_mode=555 + ;; + +interix[[3-9]]*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + dynamic_linker='Interix 3.x ld.so.1 (PE, like ELF)' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + ;; + +irix5* | irix6* | nonstopux*) + case $host_os in + nonstopux*) version_type=nonstopux ;; + *) + if test yes = "$lt_cv_prog_gnu_ld"; then + version_type=linux # correct to gnu/linux during the next big refactor + else + version_type=irix + fi ;; + esac + need_lib_prefix=no + need_version=no + soname_spec='$libname$release$shared_ext$major' + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$release$shared_ext $libname$shared_ext' + case $host_os in + irix5* | nonstopux*) + libsuff= shlibsuff= + ;; + *) + case $LD in # libtool.m4 will add one of these switches to LD + *-32|*"-32 "|*-melf32bsmip|*"-melf32bsmip ") + libsuff= shlibsuff= libmagic=32-bit;; + *-n32|*"-n32 "|*-melf32bmipn32|*"-melf32bmipn32 ") + libsuff=32 shlibsuff=N32 libmagic=N32;; + *-64|*"-64 "|*-melf64bmip|*"-melf64bmip ") + libsuff=64 shlibsuff=64 libmagic=64-bit;; + *) libsuff= shlibsuff= libmagic=never-match;; + esac + ;; + esac + shlibpath_var=LD_LIBRARY${shlibsuff}_PATH + shlibpath_overrides_runpath=no + sys_lib_search_path_spec="/usr/lib$libsuff /lib$libsuff /usr/local/lib$libsuff" + sys_lib_dlsearch_path_spec="/usr/lib$libsuff /lib$libsuff" + hardcode_into_libs=yes + ;; + +# No shared lib support for Linux oldld, aout, or coff. +linux*oldld* | linux*aout* | linux*coff*) + dynamic_linker=no + ;; + +linux*android*) + version_type=none # Android doesn't support versioned libraries. + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext' + soname_spec='$libname$release$shared_ext' + finish_cmds= + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + + # This implies no fast_install, which is unacceptable. + # Some rework will be needed to allow for fast_install + # before this can be enabled. + hardcode_into_libs=yes + + dynamic_linker='Android linker' + # Don't embed -rpath directories since the linker doesn't support them. + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + ;; + +# This must be glibc/ELF. +linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -n $libdir' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + + # Some binutils ld are patched to set DT_RUNPATH + AC_CACHE_VAL([lt_cv_shlibpath_overrides_runpath], + [lt_cv_shlibpath_overrides_runpath=no + save_LDFLAGS=$LDFLAGS + save_libdir=$libdir + eval "libdir=/foo; wl=\"$_LT_TAGVAR(lt_prog_compiler_wl, $1)\"; \ + LDFLAGS=\"\$LDFLAGS $_LT_TAGVAR(hardcode_libdir_flag_spec, $1)\"" + AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])], + [AS_IF([ ($OBJDUMP -p conftest$ac_exeext) 2>/dev/null | grep "RUNPATH.*$libdir" >/dev/null], + [lt_cv_shlibpath_overrides_runpath=yes])]) + LDFLAGS=$save_LDFLAGS + libdir=$save_libdir + ]) + shlibpath_overrides_runpath=$lt_cv_shlibpath_overrides_runpath + + # This implies no fast_install, which is unacceptable. + # Some rework will be needed to allow for fast_install + # before this can be enabled. + hardcode_into_libs=yes + + # Ideally, we could use ldconfig to report *all* directores which are + # searched for libraries, however this is still not possible. Aside from not + # being certain /sbin/ldconfig is available, command + # 'ldconfig -N -X -v | grep ^/' on 64bit Fedora does not report /usr/lib64, + # even though it is searched at run-time. Try to do the best guess by + # appending ld.so.conf contents (and includes) to the search path. + if test -f /etc/ld.so.conf; then + lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s 2>/dev/null", \[$]2)); skip = 1; } { if (!skip) print \[$]0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/#.*//;/^[ ]*hwcap[ ]/d;s/[:, ]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;s/"//g;/^$/d' | tr '\n' ' '` + sys_lib_dlsearch_path_spec="/lib /usr/lib $lt_ld_extra" + fi + + # We used to test for /lib/ld.so.1 and disable shared libraries on + # powerpc, because MkLinux only supported shared libraries with the + # GNU dynamic linker. Since this was broken with cross compilers, + # most powerpc-linux boxes support dynamic linking these days and + # people can always --disable-shared, the test was removed, and we + # assume the GNU/Linux dynamic linker is in use. + dynamic_linker='GNU/Linux ld.so' + ;; + +netbsdelf*-gnu) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + dynamic_linker='NetBSD ld.elf_so' + ;; + +netbsd*) + version_type=sunos + need_lib_prefix=no + need_version=no + if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then + library_names_spec='$libname$release$shared_ext$versuffix $libname$shared_ext$versuffix' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir' + dynamic_linker='NetBSD (a.out) ld.so' + else + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + dynamic_linker='NetBSD ld.elf_so' + fi + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + +newsos6) + version_type=linux # correct to gnu/linux during the next big refactor + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + ;; + +*nto* | *qnx*) + version_type=qnx + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + dynamic_linker='ldqnx.so' + ;; + +openbsd* | bitrig*) + version_type=sunos + sys_lib_dlsearch_path_spec=/usr/lib + need_lib_prefix=no + if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`"; then + need_version=no + else + need_version=yes + fi + library_names_spec='$libname$release$shared_ext$versuffix $libname$shared_ext$versuffix' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + ;; + +os2*) + libname_spec='$name' + version_type=windows + shrext_cmds=.dll + need_version=no + need_lib_prefix=no + # OS/2 can only load a DLL with a base name of 8 characters or less. + soname_spec='`test -n "$os2dllname" && libname="$os2dllname"; + v=$($ECHO $release$versuffix | tr -d .-); + n=$($ECHO $libname | cut -b -$((8 - ${#v})) | tr . _); + $ECHO $n$v`$shared_ext' + library_names_spec='${libname}_dll.$libext' + dynamic_linker='OS/2 ld.exe' + shlibpath_var=BEGINLIBPATH + sys_lib_search_path_spec="/lib /usr/lib /usr/local/lib" + sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec + postinstall_cmds='base_file=`basename \$file`~ + dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\$base_file'\''i; $ECHO \$dlname'\''`~ + dldir=$destdir/`dirname \$dlpath`~ + test -d \$dldir || mkdir -p \$dldir~ + $install_prog $dir/$dlname \$dldir/$dlname~ + chmod a+x \$dldir/$dlname~ + if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then + eval '\''$striplib \$dldir/$dlname'\'' || exit \$?; + fi' + postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; $ECHO \$dlname'\''`~ + dlpath=$dir/\$dldll~ + $RM \$dlpath' + ;; + +osf3* | osf4* | osf5*) + version_type=osf + need_lib_prefix=no + need_version=no + soname_spec='$libname$release$shared_ext$major' + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + shlibpath_var=LD_LIBRARY_PATH + sys_lib_search_path_spec="/usr/shlib /usr/ccs/lib /usr/lib/cmplrs/cc /usr/lib /usr/local/lib /var/shlib" + sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec + ;; + +rdos*) + dynamic_linker=no + ;; + +solaris*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + # ldd complains unless libraries are executable + postinstall_cmds='chmod +x $lib' + ;; + +sunos4*) + version_type=sunos + library_names_spec='$libname$release$shared_ext$versuffix $libname$shared_ext$versuffix' + finish_cmds='PATH="\$PATH:/usr/etc" ldconfig $libdir' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + if test yes = "$with_gnu_ld"; then + need_lib_prefix=no + fi + need_version=yes + ;; + +sysv4 | sysv4.3*) + version_type=linux # correct to gnu/linux during the next big refactor + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + case $host_vendor in + sni) + shlibpath_overrides_runpath=no + need_lib_prefix=no + runpath_var=LD_RUN_PATH + ;; + siemens) + need_lib_prefix=no + ;; + motorola) + need_lib_prefix=no + need_version=no + shlibpath_overrides_runpath=no + sys_lib_search_path_spec='/lib /usr/lib /usr/ccs/lib' + ;; + esac + ;; + +sysv4*MP*) + if test -d /usr/nec; then + version_type=linux # correct to gnu/linux during the next big refactor + library_names_spec='$libname$shared_ext.$versuffix $libname$shared_ext.$major $libname$shared_ext' + soname_spec='$libname$shared_ext.$major' + shlibpath_var=LD_LIBRARY_PATH + fi + ;; + +sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*) + version_type=sco + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + if test yes = "$with_gnu_ld"; then + sys_lib_search_path_spec='/usr/local/lib /usr/gnu/lib /usr/ccs/lib /usr/lib /lib' + else + sys_lib_search_path_spec='/usr/ccs/lib /usr/lib' + case $host_os in + sco3.2v5*) + sys_lib_search_path_spec="$sys_lib_search_path_spec /lib" + ;; + esac + fi + sys_lib_dlsearch_path_spec='/usr/lib' + ;; + +tpf*) + # TPF is a cross-target only. Preferred cross-host = GNU/Linux. + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + ;; + +uts4*) + version_type=linux # correct to gnu/linux during the next big refactor + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + ;; + +*) + dynamic_linker=no + ;; +esac +AC_MSG_RESULT([$dynamic_linker]) +test no = "$dynamic_linker" && can_build_shared=no + +variables_saved_for_relink="PATH $shlibpath_var $runpath_var" +if test yes = "$GCC"; then + variables_saved_for_relink="$variables_saved_for_relink GCC_EXEC_PREFIX COMPILER_PATH LIBRARY_PATH" +fi + +if test set = "${lt_cv_sys_lib_search_path_spec+set}"; then + sys_lib_search_path_spec=$lt_cv_sys_lib_search_path_spec +fi + +if test set = "${lt_cv_sys_lib_dlsearch_path_spec+set}"; then + sys_lib_dlsearch_path_spec=$lt_cv_sys_lib_dlsearch_path_spec +fi + +# remember unaugmented sys_lib_dlsearch_path content for libtool script decls... +configure_time_dlsearch_path=$sys_lib_dlsearch_path_spec + +# ... but it needs LT_SYS_LIBRARY_PATH munging for other configure-time code +func_munge_path_list sys_lib_dlsearch_path_spec "$LT_SYS_LIBRARY_PATH" + +# to be used as default LT_SYS_LIBRARY_PATH value in generated libtool +configure_time_lt_sys_library_path=$LT_SYS_LIBRARY_PATH + +_LT_DECL([], [variables_saved_for_relink], [1], + [Variables whose values should be saved in libtool wrapper scripts and + restored at link time]) +_LT_DECL([], [need_lib_prefix], [0], + [Do we need the "lib" prefix for modules?]) +_LT_DECL([], [need_version], [0], [Do we need a version for libraries?]) +_LT_DECL([], [version_type], [0], [Library versioning type]) +_LT_DECL([], [runpath_var], [0], [Shared library runtime path variable]) +_LT_DECL([], [shlibpath_var], [0],[Shared library path variable]) +_LT_DECL([], [shlibpath_overrides_runpath], [0], + [Is shlibpath searched before the hard-coded library search path?]) +_LT_DECL([], [libname_spec], [1], [Format of library name prefix]) +_LT_DECL([], [library_names_spec], [1], + [[List of archive names. First name is the real one, the rest are links. + The last name is the one that the linker finds with -lNAME]]) +_LT_DECL([], [soname_spec], [1], + [[The coded name of the library, if different from the real name]]) +_LT_DECL([], [install_override_mode], [1], + [Permission mode override for installation of shared libraries]) +_LT_DECL([], [postinstall_cmds], [2], + [Command to use after installation of a shared archive]) +_LT_DECL([], [postuninstall_cmds], [2], + [Command to use after uninstallation of a shared archive]) +_LT_DECL([], [finish_cmds], [2], + [Commands used to finish a libtool library installation in a directory]) +_LT_DECL([], [finish_eval], [1], + [[As "finish_cmds", except a single script fragment to be evaled but + not shown]]) +_LT_DECL([], [hardcode_into_libs], [0], + [Whether we should hardcode library paths into libraries]) +_LT_DECL([], [sys_lib_search_path_spec], [2], + [Compile-time system search path for libraries]) +_LT_DECL([sys_lib_dlsearch_path_spec], [configure_time_dlsearch_path], [2], + [Detected run-time system search path for libraries]) +_LT_DECL([], [configure_time_lt_sys_library_path], [2], + [Explicit LT_SYS_LIBRARY_PATH set during ./configure time]) +])# _LT_SYS_DYNAMIC_LINKER + + +# _LT_PATH_TOOL_PREFIX(TOOL) +# -------------------------- +# find a file program that can recognize shared library +AC_DEFUN([_LT_PATH_TOOL_PREFIX], +[m4_require([_LT_DECL_EGREP])dnl +AC_MSG_CHECKING([for $1]) +AC_CACHE_VAL(lt_cv_path_MAGIC_CMD, +[case $MAGIC_CMD in +[[\\/*] | ?:[\\/]*]) + lt_cv_path_MAGIC_CMD=$MAGIC_CMD # Let the user override the test with a path. + ;; +*) + lt_save_MAGIC_CMD=$MAGIC_CMD + lt_save_ifs=$IFS; IFS=$PATH_SEPARATOR +dnl $ac_dummy forces splitting on constant user-supplied paths. +dnl POSIX.2 word splitting is done only on the output of word expansions, +dnl not every word. This closes a longstanding sh security hole. + ac_dummy="m4_if([$2], , $PATH, [$2])" + for ac_dir in $ac_dummy; do + IFS=$lt_save_ifs + test -z "$ac_dir" && ac_dir=. + if test -f "$ac_dir/$1"; then + lt_cv_path_MAGIC_CMD=$ac_dir/"$1" + if test -n "$file_magic_test_file"; then + case $deplibs_check_method in + "file_magic "*) + file_magic_regex=`expr "$deplibs_check_method" : "file_magic \(.*\)"` + MAGIC_CMD=$lt_cv_path_MAGIC_CMD + if eval $file_magic_cmd \$file_magic_test_file 2> /dev/null | + $EGREP "$file_magic_regex" > /dev/null; then + : + else + cat <<_LT_EOF 1>&2 + +*** Warning: the command libtool uses to detect shared libraries, +*** $file_magic_cmd, produces output that libtool cannot recognize. +*** The result is that libtool may fail to recognize shared libraries +*** as such. This will affect the creation of libtool libraries that +*** depend on shared libraries, but programs linked with such libtool +*** libraries will work regardless of this problem. Nevertheless, you +*** may want to report the problem to your system manager and/or to +*** bug-libtool@gnu.org + +_LT_EOF + fi ;; + esac + fi + break + fi + done + IFS=$lt_save_ifs + MAGIC_CMD=$lt_save_MAGIC_CMD + ;; +esac]) +MAGIC_CMD=$lt_cv_path_MAGIC_CMD +if test -n "$MAGIC_CMD"; then + AC_MSG_RESULT($MAGIC_CMD) +else + AC_MSG_RESULT(no) +fi +_LT_DECL([], [MAGIC_CMD], [0], + [Used to examine libraries when file_magic_cmd begins with "file"])dnl +])# _LT_PATH_TOOL_PREFIX + +# Old name: +AU_ALIAS([AC_PATH_TOOL_PREFIX], [_LT_PATH_TOOL_PREFIX]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_PATH_TOOL_PREFIX], []) + + +# _LT_PATH_MAGIC +# -------------- +# find a file program that can recognize a shared library +m4_defun([_LT_PATH_MAGIC], +[_LT_PATH_TOOL_PREFIX(${ac_tool_prefix}file, /usr/bin$PATH_SEPARATOR$PATH) +if test -z "$lt_cv_path_MAGIC_CMD"; then + if test -n "$ac_tool_prefix"; then + _LT_PATH_TOOL_PREFIX(file, /usr/bin$PATH_SEPARATOR$PATH) + else + MAGIC_CMD=: + fi +fi +])# _LT_PATH_MAGIC + + +# LT_PATH_LD +# ---------- +# find the pathname to the GNU or non-GNU linker +AC_DEFUN([LT_PATH_LD], +[AC_REQUIRE([AC_PROG_CC])dnl +AC_REQUIRE([AC_CANONICAL_HOST])dnl +AC_REQUIRE([AC_CANONICAL_BUILD])dnl +m4_require([_LT_DECL_SED])dnl +m4_require([_LT_DECL_EGREP])dnl +m4_require([_LT_PROG_ECHO_BACKSLASH])dnl + +AC_ARG_WITH([gnu-ld], + [AS_HELP_STRING([--with-gnu-ld], + [assume the C compiler uses GNU ld @<:@default=no@:>@])], + [test no = "$withval" || with_gnu_ld=yes], + [with_gnu_ld=no])dnl + +ac_prog=ld +if test yes = "$GCC"; then + # Check if gcc -print-prog-name=ld gives a path. + AC_MSG_CHECKING([for ld used by $CC]) + case $host in + *-*-mingw*) + # gcc leaves a trailing carriage return, which upsets mingw + ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;; + *) + ac_prog=`($CC -print-prog-name=ld) 2>&5` ;; + esac + case $ac_prog in + # Accept absolute paths. + [[\\/]]* | ?:[[\\/]]*) + re_direlt='/[[^/]][[^/]]*/\.\./' + # Canonicalize the pathname of ld + ac_prog=`$ECHO "$ac_prog"| $SED 's%\\\\%/%g'` + while $ECHO "$ac_prog" | $GREP "$re_direlt" > /dev/null 2>&1; do + ac_prog=`$ECHO $ac_prog| $SED "s%$re_direlt%/%"` + done + test -z "$LD" && LD=$ac_prog + ;; + "") + # If it fails, then pretend we aren't using GCC. + ac_prog=ld + ;; + *) + # If it is relative, then search for the first ld in PATH. + with_gnu_ld=unknown + ;; + esac +elif test yes = "$with_gnu_ld"; then + AC_MSG_CHECKING([for GNU ld]) +else + AC_MSG_CHECKING([for non-GNU ld]) +fi +AC_CACHE_VAL(lt_cv_path_LD, +[if test -z "$LD"; then + lt_save_ifs=$IFS; IFS=$PATH_SEPARATOR + for ac_dir in $PATH; do + IFS=$lt_save_ifs + test -z "$ac_dir" && ac_dir=. + if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then + lt_cv_path_LD=$ac_dir/$ac_prog + # Check to see if the program is GNU ld. I'd rather use --version, + # but apparently some variants of GNU ld only accept -v. + # Break only if it was the GNU/non-GNU ld that we prefer. + case `"$lt_cv_path_LD" -v 2>&1 &1 conftest.i +cat conftest.i conftest.i >conftest2.i +: ${lt_DD:=$DD} +AC_PATH_PROGS_FEATURE_CHECK([lt_DD], [dd], +[if "$ac_path_lt_DD" bs=32 count=1 conftest.out 2>/dev/null; then + cmp -s conftest.i conftest.out \ + && ac_cv_path_lt_DD="$ac_path_lt_DD" ac_path_lt_DD_found=: +fi]) +rm -f conftest.i conftest2.i conftest.out]) +])# _LT_PATH_DD + + +# _LT_CMD_TRUNCATE +# ---------------- +# find command to truncate a binary pipe +m4_defun([_LT_CMD_TRUNCATE], +[m4_require([_LT_PATH_DD]) +AC_CACHE_CHECK([how to truncate binary pipes], [lt_cv_truncate_bin], +[printf 0123456789abcdef0123456789abcdef >conftest.i +cat conftest.i conftest.i >conftest2.i +lt_cv_truncate_bin= +if "$ac_cv_path_lt_DD" bs=32 count=1 conftest.out 2>/dev/null; then + cmp -s conftest.i conftest.out \ + && lt_cv_truncate_bin="$ac_cv_path_lt_DD bs=4096 count=1" +fi +rm -f conftest.i conftest2.i conftest.out +test -z "$lt_cv_truncate_bin" && lt_cv_truncate_bin="$SED -e 4q"]) +_LT_DECL([lt_truncate_bin], [lt_cv_truncate_bin], [1], + [Command to truncate a binary pipe]) +])# _LT_CMD_TRUNCATE + + +# _LT_CHECK_MAGIC_METHOD +# ---------------------- +# how to check for library dependencies +# -- PORTME fill in with the dynamic library characteristics +m4_defun([_LT_CHECK_MAGIC_METHOD], +[m4_require([_LT_DECL_EGREP]) +m4_require([_LT_DECL_OBJDUMP]) +AC_CACHE_CHECK([how to recognize dependent libraries], +lt_cv_deplibs_check_method, +[lt_cv_file_magic_cmd='$MAGIC_CMD' +lt_cv_file_magic_test_file= +lt_cv_deplibs_check_method='unknown' +# Need to set the preceding variable on all platforms that support +# interlibrary dependencies. +# 'none' -- dependencies not supported. +# 'unknown' -- same as none, but documents that we really don't know. +# 'pass_all' -- all dependencies passed with no checks. +# 'test_compile' -- check by making test program. +# 'file_magic [[regex]]' -- check by looking for files in library path +# that responds to the $file_magic_cmd with a given extended regex. +# If you have 'file' or equivalent on your system and you're not sure +# whether 'pass_all' will *always* work, you probably want this one. + +case $host_os in +aix[[4-9]]*) + lt_cv_deplibs_check_method=pass_all + ;; + +beos*) + lt_cv_deplibs_check_method=pass_all + ;; + +bsdi[[45]]*) + lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[ML]]SB (shared object|dynamic lib)' + lt_cv_file_magic_cmd='/usr/bin/file -L' + lt_cv_file_magic_test_file=/shlib/libc.so + ;; + +cygwin*) + # func_win32_libid is a shell function defined in ltmain.sh + lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL' + lt_cv_file_magic_cmd='func_win32_libid' + ;; + +mingw* | pw32*) + # Base MSYS/MinGW do not provide the 'file' command needed by + # func_win32_libid shell function, so use a weaker test based on 'objdump', + # unless we find 'file', for example because we are cross-compiling. + if ( file / ) >/dev/null 2>&1; then + lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL' + lt_cv_file_magic_cmd='func_win32_libid' + else + # Keep this pattern in sync with the one in func_win32_libid. + lt_cv_deplibs_check_method='file_magic file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64)' + lt_cv_file_magic_cmd='$OBJDUMP -f' + fi + ;; + +cegcc*) + # use the weaker test based on 'objdump'. See mingw*. + lt_cv_deplibs_check_method='file_magic file format pe-arm-.*little(.*architecture: arm)?' + lt_cv_file_magic_cmd='$OBJDUMP -f' + ;; + +darwin* | rhapsody*) + lt_cv_deplibs_check_method=pass_all + ;; + +freebsd* | dragonfly*) + if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then + case $host_cpu in + i*86 ) + # Not sure whether the presence of OpenBSD here was a mistake. + # Let's accept both of them until this is cleared up. + lt_cv_deplibs_check_method='file_magic (FreeBSD|OpenBSD|DragonFly)/i[[3-9]]86 (compact )?demand paged shared library' + lt_cv_file_magic_cmd=/usr/bin/file + lt_cv_file_magic_test_file=`echo /usr/lib/libc.so.*` + ;; + esac + else + lt_cv_deplibs_check_method=pass_all + fi + ;; + +haiku*) + lt_cv_deplibs_check_method=pass_all + ;; + +hpux10.20* | hpux11*) + lt_cv_file_magic_cmd=/usr/bin/file + case $host_cpu in + ia64*) + lt_cv_deplibs_check_method='file_magic (s[[0-9]][[0-9]][[0-9]]|ELF-[[0-9]][[0-9]]) shared object file - IA64' + lt_cv_file_magic_test_file=/usr/lib/hpux32/libc.so + ;; + hppa*64*) + [lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|ELF[ -][0-9][0-9])(-bit)?( [LM]SB)? shared object( file)?[, -]* PA-RISC [0-9]\.[0-9]'] + lt_cv_file_magic_test_file=/usr/lib/pa20_64/libc.sl + ;; + *) + lt_cv_deplibs_check_method='file_magic (s[[0-9]][[0-9]][[0-9]]|PA-RISC[[0-9]]\.[[0-9]]) shared library' + lt_cv_file_magic_test_file=/usr/lib/libc.sl + ;; + esac + ;; + +interix[[3-9]]*) + # PIC code is broken on Interix 3.x, that's why |\.a not |_pic\.a here + lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so|\.a)$' + ;; + +irix5* | irix6* | nonstopux*) + case $LD in + *-32|*"-32 ") libmagic=32-bit;; + *-n32|*"-n32 ") libmagic=N32;; + *-64|*"-64 ") libmagic=64-bit;; + *) libmagic=never-match;; + esac + lt_cv_deplibs_check_method=pass_all + ;; + +# This must be glibc/ELF. +linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*) + lt_cv_deplibs_check_method=pass_all + ;; + +netbsd* | netbsdelf*-gnu) + if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then + lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|_pic\.a)$' + else + lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so|_pic\.a)$' + fi + ;; + +newos6*) + lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[ML]]SB (executable|dynamic lib)' + lt_cv_file_magic_cmd=/usr/bin/file + lt_cv_file_magic_test_file=/usr/lib/libnls.so + ;; + +*nto* | *qnx*) + lt_cv_deplibs_check_method=pass_all + ;; + +openbsd* | bitrig*) + if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`"; then + lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|\.so|_pic\.a)$' + else + lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|_pic\.a)$' + fi + ;; + +osf3* | osf4* | osf5*) + lt_cv_deplibs_check_method=pass_all + ;; + +rdos*) + lt_cv_deplibs_check_method=pass_all + ;; + +solaris*) + lt_cv_deplibs_check_method=pass_all + ;; + +sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*) + lt_cv_deplibs_check_method=pass_all + ;; + +sysv4 | sysv4.3*) + case $host_vendor in + motorola) + lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[ML]]SB (shared object|dynamic lib) M[[0-9]][[0-9]]* Version [[0-9]]' + lt_cv_file_magic_test_file=`echo /usr/lib/libc.so*` + ;; + ncr) + lt_cv_deplibs_check_method=pass_all + ;; + sequent) + lt_cv_file_magic_cmd='/bin/file' + lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[LM]]SB (shared object|dynamic lib )' + ;; + sni) + lt_cv_file_magic_cmd='/bin/file' + lt_cv_deplibs_check_method="file_magic ELF [[0-9]][[0-9]]*-bit [[LM]]SB dynamic lib" + lt_cv_file_magic_test_file=/lib/libc.so + ;; + siemens) + lt_cv_deplibs_check_method=pass_all + ;; + pc) + lt_cv_deplibs_check_method=pass_all + ;; + esac + ;; + +tpf*) + lt_cv_deplibs_check_method=pass_all + ;; +os2*) + lt_cv_deplibs_check_method=pass_all + ;; +esac +]) + +file_magic_glob= +want_nocaseglob=no +if test "$build" = "$host"; then + case $host_os in + mingw* | pw32*) + if ( shopt | grep nocaseglob ) >/dev/null 2>&1; then + want_nocaseglob=yes + else + file_magic_glob=`echo aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ | $SED -e "s/\(..\)/s\/[[\1]]\/[[\1]]\/g;/g"` + fi + ;; + esac +fi + +file_magic_cmd=$lt_cv_file_magic_cmd +deplibs_check_method=$lt_cv_deplibs_check_method +test -z "$deplibs_check_method" && deplibs_check_method=unknown + +_LT_DECL([], [deplibs_check_method], [1], + [Method to check whether dependent libraries are shared objects]) +_LT_DECL([], [file_magic_cmd], [1], + [Command to use when deplibs_check_method = "file_magic"]) +_LT_DECL([], [file_magic_glob], [1], + [How to find potential files when deplibs_check_method = "file_magic"]) +_LT_DECL([], [want_nocaseglob], [1], + [Find potential files using nocaseglob when deplibs_check_method = "file_magic"]) +])# _LT_CHECK_MAGIC_METHOD + + +# LT_PATH_NM +# ---------- +# find the pathname to a BSD- or MS-compatible name lister +AC_DEFUN([LT_PATH_NM], +[AC_REQUIRE([AC_PROG_CC])dnl +AC_CACHE_CHECK([for BSD- or MS-compatible name lister (nm)], lt_cv_path_NM, +[if test -n "$NM"; then + # Let the user override the test. + lt_cv_path_NM=$NM +else + lt_nm_to_check=${ac_tool_prefix}nm + if test -n "$ac_tool_prefix" && test "$build" = "$host"; then + lt_nm_to_check="$lt_nm_to_check nm" + fi + for lt_tmp_nm in $lt_nm_to_check; do + lt_save_ifs=$IFS; IFS=$PATH_SEPARATOR + for ac_dir in $PATH /usr/ccs/bin/elf /usr/ccs/bin /usr/ucb /bin; do + IFS=$lt_save_ifs + test -z "$ac_dir" && ac_dir=. + tmp_nm=$ac_dir/$lt_tmp_nm + if test -f "$tmp_nm" || test -f "$tmp_nm$ac_exeext"; then + # Check to see if the nm accepts a BSD-compat flag. + # Adding the 'sed 1q' prevents false positives on HP-UX, which says: + # nm: unknown option "B" ignored + # Tru64's nm complains that /dev/null is an invalid object file + # MSYS converts /dev/null to NUL, MinGW nm treats NUL as empty + case $build_os in + mingw*) lt_bad_file=conftest.nm/nofile ;; + *) lt_bad_file=/dev/null ;; + esac + case `"$tmp_nm" -B $lt_bad_file 2>&1 | sed '1q'` in + *$lt_bad_file* | *'Invalid file or object type'*) + lt_cv_path_NM="$tmp_nm -B" + break 2 + ;; + *) + case `"$tmp_nm" -p /dev/null 2>&1 | sed '1q'` in + */dev/null*) + lt_cv_path_NM="$tmp_nm -p" + break 2 + ;; + *) + lt_cv_path_NM=${lt_cv_path_NM="$tmp_nm"} # keep the first match, but + continue # so that we can try to find one that supports BSD flags + ;; + esac + ;; + esac + fi + done + IFS=$lt_save_ifs + done + : ${lt_cv_path_NM=no} +fi]) +if test no != "$lt_cv_path_NM"; then + NM=$lt_cv_path_NM +else + # Didn't find any BSD compatible name lister, look for dumpbin. + if test -n "$DUMPBIN"; then : + # Let the user override the test. + else + AC_CHECK_TOOLS(DUMPBIN, [dumpbin "link -dump"], :) + case `$DUMPBIN -symbols -headers /dev/null 2>&1 | sed '1q'` in + *COFF*) + DUMPBIN="$DUMPBIN -symbols -headers" + ;; + *) + DUMPBIN=: + ;; + esac + fi + AC_SUBST([DUMPBIN]) + if test : != "$DUMPBIN"; then + NM=$DUMPBIN + fi +fi +test -z "$NM" && NM=nm +AC_SUBST([NM]) +_LT_DECL([], [NM], [1], [A BSD- or MS-compatible name lister])dnl + +AC_CACHE_CHECK([the name lister ($NM) interface], [lt_cv_nm_interface], + [lt_cv_nm_interface="BSD nm" + echo "int some_variable = 0;" > conftest.$ac_ext + (eval echo "\"\$as_me:$LINENO: $ac_compile\"" >&AS_MESSAGE_LOG_FD) + (eval "$ac_compile" 2>conftest.err) + cat conftest.err >&AS_MESSAGE_LOG_FD + (eval echo "\"\$as_me:$LINENO: $NM \\\"conftest.$ac_objext\\\"\"" >&AS_MESSAGE_LOG_FD) + (eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out) + cat conftest.err >&AS_MESSAGE_LOG_FD + (eval echo "\"\$as_me:$LINENO: output\"" >&AS_MESSAGE_LOG_FD) + cat conftest.out >&AS_MESSAGE_LOG_FD + if $GREP 'External.*some_variable' conftest.out > /dev/null; then + lt_cv_nm_interface="MS dumpbin" + fi + rm -f conftest*]) +])# LT_PATH_NM + +# Old names: +AU_ALIAS([AM_PROG_NM], [LT_PATH_NM]) +AU_ALIAS([AC_PROG_NM], [LT_PATH_NM]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AM_PROG_NM], []) +dnl AC_DEFUN([AC_PROG_NM], []) + +# _LT_CHECK_SHAREDLIB_FROM_LINKLIB +# -------------------------------- +# how to determine the name of the shared library +# associated with a specific link library. +# -- PORTME fill in with the dynamic library characteristics +m4_defun([_LT_CHECK_SHAREDLIB_FROM_LINKLIB], +[m4_require([_LT_DECL_EGREP]) +m4_require([_LT_DECL_OBJDUMP]) +m4_require([_LT_DECL_DLLTOOL]) +AC_CACHE_CHECK([how to associate runtime and link libraries], +lt_cv_sharedlib_from_linklib_cmd, +[lt_cv_sharedlib_from_linklib_cmd='unknown' + +case $host_os in +cygwin* | mingw* | pw32* | cegcc*) + # two different shell functions defined in ltmain.sh; + # decide which one to use based on capabilities of $DLLTOOL + case `$DLLTOOL --help 2>&1` in + *--identify-strict*) + lt_cv_sharedlib_from_linklib_cmd=func_cygming_dll_for_implib + ;; + *) + lt_cv_sharedlib_from_linklib_cmd=func_cygming_dll_for_implib_fallback + ;; + esac + ;; +*) + # fallback: assume linklib IS sharedlib + lt_cv_sharedlib_from_linklib_cmd=$ECHO + ;; +esac +]) +sharedlib_from_linklib_cmd=$lt_cv_sharedlib_from_linklib_cmd +test -z "$sharedlib_from_linklib_cmd" && sharedlib_from_linklib_cmd=$ECHO + +_LT_DECL([], [sharedlib_from_linklib_cmd], [1], + [Command to associate shared and link libraries]) +])# _LT_CHECK_SHAREDLIB_FROM_LINKLIB + + +# _LT_PATH_MANIFEST_TOOL +# ---------------------- +# locate the manifest tool +m4_defun([_LT_PATH_MANIFEST_TOOL], +[AC_CHECK_TOOL(MANIFEST_TOOL, mt, :) +test -z "$MANIFEST_TOOL" && MANIFEST_TOOL=mt +AC_CACHE_CHECK([if $MANIFEST_TOOL is a manifest tool], [lt_cv_path_mainfest_tool], + [lt_cv_path_mainfest_tool=no + echo "$as_me:$LINENO: $MANIFEST_TOOL '-?'" >&AS_MESSAGE_LOG_FD + $MANIFEST_TOOL '-?' 2>conftest.err > conftest.out + cat conftest.err >&AS_MESSAGE_LOG_FD + if $GREP 'Manifest Tool' conftest.out > /dev/null; then + lt_cv_path_mainfest_tool=yes + fi + rm -f conftest*]) +if test yes != "$lt_cv_path_mainfest_tool"; then + MANIFEST_TOOL=: +fi +_LT_DECL([], [MANIFEST_TOOL], [1], [Manifest tool])dnl +])# _LT_PATH_MANIFEST_TOOL + + +# _LT_DLL_DEF_P([FILE]) +# --------------------- +# True iff FILE is a Windows DLL '.def' file. +# Keep in sync with func_dll_def_p in the libtool script +AC_DEFUN([_LT_DLL_DEF_P], +[dnl + test DEF = "`$SED -n dnl + -e '\''s/^[[ ]]*//'\'' dnl Strip leading whitespace + -e '\''/^\(;.*\)*$/d'\'' dnl Delete empty lines and comments + -e '\''s/^\(EXPORTS\|LIBRARY\)\([[ ]].*\)*$/DEF/p'\'' dnl + -e q dnl Only consider the first "real" line + $1`" dnl +])# _LT_DLL_DEF_P + + +# LT_LIB_M +# -------- +# check for math library +AC_DEFUN([LT_LIB_M], +[AC_REQUIRE([AC_CANONICAL_HOST])dnl +LIBM= +case $host in +*-*-beos* | *-*-cegcc* | *-*-cygwin* | *-*-haiku* | *-*-pw32* | *-*-darwin*) + # These system don't have libm, or don't need it + ;; +*-ncr-sysv4.3*) + AC_CHECK_LIB(mw, _mwvalidcheckl, LIBM=-lmw) + AC_CHECK_LIB(m, cos, LIBM="$LIBM -lm") + ;; +*) + AC_CHECK_LIB(m, cos, LIBM=-lm) + ;; +esac +AC_SUBST([LIBM]) +])# LT_LIB_M + +# Old name: +AU_ALIAS([AC_CHECK_LIBM], [LT_LIB_M]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_CHECK_LIBM], []) + + +# _LT_COMPILER_NO_RTTI([TAGNAME]) +# ------------------------------- +m4_defun([_LT_COMPILER_NO_RTTI], +[m4_require([_LT_TAG_COMPILER])dnl + +_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)= + +if test yes = "$GCC"; then + case $cc_basename in + nvcc*) + _LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=' -Xcompiler -fno-builtin' ;; + *) + _LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=' -fno-builtin' ;; + esac + + _LT_COMPILER_OPTION([if $compiler supports -fno-rtti -fno-exceptions], + lt_cv_prog_compiler_rtti_exceptions, + [-fno-rtti -fno-exceptions], [], + [_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)="$_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1) -fno-rtti -fno-exceptions"]) +fi +_LT_TAGDECL([no_builtin_flag], [lt_prog_compiler_no_builtin_flag], [1], + [Compiler flag to turn off builtin functions]) +])# _LT_COMPILER_NO_RTTI + + +# _LT_CMD_GLOBAL_SYMBOLS +# ---------------------- +m4_defun([_LT_CMD_GLOBAL_SYMBOLS], +[AC_REQUIRE([AC_CANONICAL_HOST])dnl +AC_REQUIRE([AC_PROG_CC])dnl +AC_REQUIRE([AC_PROG_AWK])dnl +AC_REQUIRE([LT_PATH_NM])dnl +AC_REQUIRE([LT_PATH_LD])dnl +m4_require([_LT_DECL_SED])dnl +m4_require([_LT_DECL_EGREP])dnl +m4_require([_LT_TAG_COMPILER])dnl + +# Check for command to grab the raw symbol name followed by C symbol from nm. +AC_MSG_CHECKING([command to parse $NM output from $compiler object]) +AC_CACHE_VAL([lt_cv_sys_global_symbol_pipe], +[ +# These are sane defaults that work on at least a few old systems. +# [They come from Ultrix. What could be older than Ultrix?!! ;)] + +# Character class describing NM global symbol codes. +symcode='[[BCDEGRST]]' + +# Regexp to match symbols that can be accessed directly from C. +sympat='\([[_A-Za-z]][[_A-Za-z0-9]]*\)' + +# Define system-specific variables. +case $host_os in +aix*) + symcode='[[BCDT]]' + ;; +cygwin* | mingw* | pw32* | cegcc*) + symcode='[[ABCDGISTW]]' + ;; +hpux*) + if test ia64 = "$host_cpu"; then + symcode='[[ABCDEGRST]]' + fi + ;; +irix* | nonstopux*) + symcode='[[BCDEGRST]]' + ;; +osf*) + symcode='[[BCDEGQRST]]' + ;; +solaris*) + symcode='[[BDRT]]' + ;; +sco3.2v5*) + symcode='[[DT]]' + ;; +sysv4.2uw2*) + symcode='[[DT]]' + ;; +sysv5* | sco5v6* | unixware* | OpenUNIX*) + symcode='[[ABDT]]' + ;; +sysv4) + symcode='[[DFNSTU]]' + ;; +esac + +# If we're using GNU nm, then use its standard symbol codes. +case `$NM -V 2>&1` in +*GNU* | *'with BFD'*) + symcode='[[ABCDGIRSTW]]' ;; +esac + +if test "$lt_cv_nm_interface" = "MS dumpbin"; then + # Gets list of data symbols to import. + lt_cv_sys_global_symbol_to_import="sed -n -e 's/^I .* \(.*\)$/\1/p'" + # Adjust the below global symbol transforms to fixup imported variables. + lt_cdecl_hook=" -e 's/^I .* \(.*\)$/extern __declspec(dllimport) char \1;/p'" + lt_c_name_hook=" -e 's/^I .* \(.*\)$/ {\"\1\", (void *) 0},/p'" + lt_c_name_lib_hook="\ + -e 's/^I .* \(lib.*\)$/ {\"\1\", (void *) 0},/p'\ + -e 's/^I .* \(.*\)$/ {\"lib\1\", (void *) 0},/p'" +else + # Disable hooks by default. + lt_cv_sys_global_symbol_to_import= + lt_cdecl_hook= + lt_c_name_hook= + lt_c_name_lib_hook= +fi + +# Transform an extracted symbol line into a proper C declaration. +# Some systems (esp. on ia64) link data and code symbols differently, +# so use this general approach. +lt_cv_sys_global_symbol_to_cdecl="sed -n"\ +$lt_cdecl_hook\ +" -e 's/^T .* \(.*\)$/extern int \1();/p'"\ +" -e 's/^$symcode$symcode* .* \(.*\)$/extern char \1;/p'" + +# Transform an extracted symbol line into symbol name and symbol address +lt_cv_sys_global_symbol_to_c_name_address="sed -n"\ +$lt_c_name_hook\ +" -e 's/^: \(.*\) .*$/ {\"\1\", (void *) 0},/p'"\ +" -e 's/^$symcode$symcode* .* \(.*\)$/ {\"\1\", (void *) \&\1},/p'" + +# Transform an extracted symbol line into symbol name with lib prefix and +# symbol address. +lt_cv_sys_global_symbol_to_c_name_address_lib_prefix="sed -n"\ +$lt_c_name_lib_hook\ +" -e 's/^: \(.*\) .*$/ {\"\1\", (void *) 0},/p'"\ +" -e 's/^$symcode$symcode* .* \(lib.*\)$/ {\"\1\", (void *) \&\1},/p'"\ +" -e 's/^$symcode$symcode* .* \(.*\)$/ {\"lib\1\", (void *) \&\1},/p'" + +# Handle CRLF in mingw tool chain +opt_cr= +case $build_os in +mingw*) + opt_cr=`$ECHO 'x\{0,1\}' | tr x '\015'` # option cr in regexp + ;; +esac + +# Try without a prefix underscore, then with it. +for ac_symprfx in "" "_"; do + + # Transform symcode, sympat, and symprfx into a raw symbol and a C symbol. + symxfrm="\\1 $ac_symprfx\\2 \\2" + + # Write the raw and C identifiers. + if test "$lt_cv_nm_interface" = "MS dumpbin"; then + # Fake it for dumpbin and say T for any non-static function, + # D for any global variable and I for any imported variable. + # Also find C++ and __fastcall symbols from MSVC++, + # which start with @ or ?. + lt_cv_sys_global_symbol_pipe="$AWK ['"\ +" {last_section=section; section=\$ 3};"\ +" /^COFF SYMBOL TABLE/{for(i in hide) delete hide[i]};"\ +" /Section length .*#relocs.*(pick any)/{hide[last_section]=1};"\ +" /^ *Symbol name *: /{split(\$ 0,sn,\":\"); si=substr(sn[2],2)};"\ +" /^ *Type *: code/{print \"T\",si,substr(si,length(prfx))};"\ +" /^ *Type *: data/{print \"I\",si,substr(si,length(prfx))};"\ +" \$ 0!~/External *\|/{next};"\ +" / 0+ UNDEF /{next}; / UNDEF \([^|]\)*()/{next};"\ +" {if(hide[section]) next};"\ +" {f=\"D\"}; \$ 0~/\(\).*\|/{f=\"T\"};"\ +" {split(\$ 0,a,/\||\r/); split(a[2],s)};"\ +" s[1]~/^[@?]/{print f,s[1],s[1]; next};"\ +" s[1]~prfx {split(s[1],t,\"@\"); print f,t[1],substr(t[1],length(prfx))}"\ +" ' prfx=^$ac_symprfx]" + else + lt_cv_sys_global_symbol_pipe="sed -n -e 's/^.*[[ ]]\($symcode$symcode*\)[[ ]][[ ]]*$ac_symprfx$sympat$opt_cr$/$symxfrm/p'" + fi + lt_cv_sys_global_symbol_pipe="$lt_cv_sys_global_symbol_pipe | sed '/ __gnu_lto/d'" + + # Check to see that the pipe works correctly. + pipe_works=no + + rm -f conftest* + cat > conftest.$ac_ext <<_LT_EOF +#ifdef __cplusplus +extern "C" { +#endif +char nm_test_var; +void nm_test_func(void); +void nm_test_func(void){} +#ifdef __cplusplus +} +#endif +int main(){nm_test_var='a';nm_test_func();return(0);} +_LT_EOF + + if AC_TRY_EVAL(ac_compile); then + # Now try to grab the symbols. + nlist=conftest.nm + $ECHO "$as_me:$LINENO: $NM conftest.$ac_objext | $lt_cv_sys_global_symbol_pipe > $nlist" >&AS_MESSAGE_LOG_FD + if eval "$NM" conftest.$ac_objext \| "$lt_cv_sys_global_symbol_pipe" \> $nlist 2>&AS_MESSAGE_LOG_FD && test -s "$nlist"; then + # Try sorting and uniquifying the output. + if sort "$nlist" | uniq > "$nlist"T; then + mv -f "$nlist"T "$nlist" + else + rm -f "$nlist"T + fi + + # Make sure that we snagged all the symbols we need. + if $GREP ' nm_test_var$' "$nlist" >/dev/null; then + if $GREP ' nm_test_func$' "$nlist" >/dev/null; then + cat <<_LT_EOF > conftest.$ac_ext +/* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests. */ +#if defined _WIN32 || defined __CYGWIN__ || defined _WIN32_WCE +/* DATA imports from DLLs on WIN32 can't be const, because runtime + relocations are performed -- see ld's documentation on pseudo-relocs. */ +# define LT@&t@_DLSYM_CONST +#elif defined __osf__ +/* This system does not cope well with relocations in const data. */ +# define LT@&t@_DLSYM_CONST +#else +# define LT@&t@_DLSYM_CONST const +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +_LT_EOF + # Now generate the symbol file. + eval "$lt_cv_sys_global_symbol_to_cdecl"' < "$nlist" | $GREP -v main >> conftest.$ac_ext' + + cat <<_LT_EOF >> conftest.$ac_ext + +/* The mapping between symbol names and symbols. */ +LT@&t@_DLSYM_CONST struct { + const char *name; + void *address; +} +lt__PROGRAM__LTX_preloaded_symbols[[]] = +{ + { "@PROGRAM@", (void *) 0 }, +_LT_EOF + $SED "s/^$symcode$symcode* .* \(.*\)$/ {\"\1\", (void *) \&\1},/" < "$nlist" | $GREP -v main >> conftest.$ac_ext + cat <<\_LT_EOF >> conftest.$ac_ext + {0, (void *) 0} +}; + +/* This works around a problem in FreeBSD linker */ +#ifdef FREEBSD_WORKAROUND +static const void *lt_preloaded_setup() { + return lt__PROGRAM__LTX_preloaded_symbols; +} +#endif + +#ifdef __cplusplus +} +#endif +_LT_EOF + # Now try linking the two files. + mv conftest.$ac_objext conftstm.$ac_objext + lt_globsym_save_LIBS=$LIBS + lt_globsym_save_CFLAGS=$CFLAGS + LIBS=conftstm.$ac_objext + CFLAGS="$CFLAGS$_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)" + if AC_TRY_EVAL(ac_link) && test -s conftest$ac_exeext; then + pipe_works=yes + fi + LIBS=$lt_globsym_save_LIBS + CFLAGS=$lt_globsym_save_CFLAGS + else + echo "cannot find nm_test_func in $nlist" >&AS_MESSAGE_LOG_FD + fi + else + echo "cannot find nm_test_var in $nlist" >&AS_MESSAGE_LOG_FD + fi + else + echo "cannot run $lt_cv_sys_global_symbol_pipe" >&AS_MESSAGE_LOG_FD + fi + else + echo "$progname: failed program was:" >&AS_MESSAGE_LOG_FD + cat conftest.$ac_ext >&5 + fi + rm -rf conftest* conftst* + + # Do not use the global_symbol_pipe unless it works. + if test yes = "$pipe_works"; then + break + else + lt_cv_sys_global_symbol_pipe= + fi +done +]) +if test -z "$lt_cv_sys_global_symbol_pipe"; then + lt_cv_sys_global_symbol_to_cdecl= +fi +if test -z "$lt_cv_sys_global_symbol_pipe$lt_cv_sys_global_symbol_to_cdecl"; then + AC_MSG_RESULT(failed) +else + AC_MSG_RESULT(ok) +fi + +# Response file support. +if test "$lt_cv_nm_interface" = "MS dumpbin"; then + nm_file_list_spec='@' +elif $NM --help 2>/dev/null | grep '[[@]]FILE' >/dev/null; then + nm_file_list_spec='@' +fi + +_LT_DECL([global_symbol_pipe], [lt_cv_sys_global_symbol_pipe], [1], + [Take the output of nm and produce a listing of raw symbols and C names]) +_LT_DECL([global_symbol_to_cdecl], [lt_cv_sys_global_symbol_to_cdecl], [1], + [Transform the output of nm in a proper C declaration]) +_LT_DECL([global_symbol_to_import], [lt_cv_sys_global_symbol_to_import], [1], + [Transform the output of nm into a list of symbols to manually relocate]) +_LT_DECL([global_symbol_to_c_name_address], + [lt_cv_sys_global_symbol_to_c_name_address], [1], + [Transform the output of nm in a C name address pair]) +_LT_DECL([global_symbol_to_c_name_address_lib_prefix], + [lt_cv_sys_global_symbol_to_c_name_address_lib_prefix], [1], + [Transform the output of nm in a C name address pair when lib prefix is needed]) +_LT_DECL([nm_interface], [lt_cv_nm_interface], [1], + [The name lister interface]) +_LT_DECL([], [nm_file_list_spec], [1], + [Specify filename containing input files for $NM]) +]) # _LT_CMD_GLOBAL_SYMBOLS + + +# _LT_COMPILER_PIC([TAGNAME]) +# --------------------------- +m4_defun([_LT_COMPILER_PIC], +[m4_require([_LT_TAG_COMPILER])dnl +_LT_TAGVAR(lt_prog_compiler_wl, $1)= +_LT_TAGVAR(lt_prog_compiler_pic, $1)= +_LT_TAGVAR(lt_prog_compiler_static, $1)= + +m4_if([$1], [CXX], [ + # C++ specific cases for pic, static, wl, etc. + if test yes = "$GXX"; then + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' + + case $host_os in + aix*) + # All AIX code is PIC. + if test ia64 = "$host_cpu"; then + # AIX 5 now supports IA64 processor + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + fi + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + + amigaos*) + case $host_cpu in + powerpc) + # see comment about AmigaOS4 .so support + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + m68k) + # FIXME: we need at least 68020 code to build shared libraries, but + # adding the '-m68020' flag to GCC prevents building anything better, + # like '-m68040'. + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-m68020 -resident32 -malways-restore-a4' + ;; + esac + ;; + + beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*) + # PIC is the default for these OSes. + ;; + mingw* | cygwin* | os2* | pw32* | cegcc*) + # This hack is so that the source file can tell whether it is being + # built for inclusion in a dll (and should export symbols for example). + # Although the cygwin gcc ignores -fPIC, still need this for old-style + # (--disable-auto-import) libraries + m4_if([$1], [GCJ], [], + [_LT_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT']) + case $host_os in + os2*) + _LT_TAGVAR(lt_prog_compiler_static, $1)='$wl-static' + ;; + esac + ;; + darwin* | rhapsody*) + # PIC is the default on this platform + # Common symbols not allowed in MH_DYLIB files + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fno-common' + ;; + *djgpp*) + # DJGPP does not support shared libraries at all + _LT_TAGVAR(lt_prog_compiler_pic, $1)= + ;; + haiku*) + # PIC is the default for Haiku. + # The "-static" flag exists, but is broken. + _LT_TAGVAR(lt_prog_compiler_static, $1)= + ;; + interix[[3-9]]*) + # Interix 3.x gcc -fpic/-fPIC options generate broken code. + # Instead, we relocate shared libraries at runtime. + ;; + sysv4*MP*) + if test -d /usr/nec; then + _LT_TAGVAR(lt_prog_compiler_pic, $1)=-Kconform_pic + fi + ;; + hpux*) + # PIC is the default for 64-bit PA HP-UX, but not for 32-bit + # PA HP-UX. On IA64 HP-UX, PIC is the default but the pic flag + # sets the default TLS model and affects inlining. + case $host_cpu in + hppa*64*) + ;; + *) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + esac + ;; + *qnx* | *nto*) + # QNX uses GNU C++, but need to define -shared option too, otherwise + # it will coredump. + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared' + ;; + *) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + esac + else + case $host_os in + aix[[4-9]]*) + # All AIX code is PIC. + if test ia64 = "$host_cpu"; then + # AIX 5 now supports IA64 processor + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + else + _LT_TAGVAR(lt_prog_compiler_static, $1)='-bnso -bI:/lib/syscalls.exp' + fi + ;; + chorus*) + case $cc_basename in + cxch68*) + # Green Hills C++ Compiler + # _LT_TAGVAR(lt_prog_compiler_static, $1)="--no_auto_instantiation -u __main -u __premain -u _abort -r $COOL_DIR/lib/libOrb.a $MVME_DIR/lib/CC/libC.a $MVME_DIR/lib/classix/libcx.s.a" + ;; + esac + ;; + mingw* | cygwin* | os2* | pw32* | cegcc*) + # This hack is so that the source file can tell whether it is being + # built for inclusion in a dll (and should export symbols for example). + m4_if([$1], [GCJ], [], + [_LT_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT']) + ;; + dgux*) + case $cc_basename in + ec++*) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + ;; + ghcx*) + # Green Hills C++ Compiler + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic' + ;; + *) + ;; + esac + ;; + freebsd* | dragonfly*) + # FreeBSD uses GNU C++ + ;; + hpux9* | hpux10* | hpux11*) + case $cc_basename in + CC*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_static, $1)='$wl-a ${wl}archive' + if test ia64 != "$host_cpu"; then + _LT_TAGVAR(lt_prog_compiler_pic, $1)='+Z' + fi + ;; + aCC*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_static, $1)='$wl-a ${wl}archive' + case $host_cpu in + hppa*64*|ia64*) + # +Z the default + ;; + *) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='+Z' + ;; + esac + ;; + *) + ;; + esac + ;; + interix*) + # This is c89, which is MS Visual C++ (no shared libs) + # Anyone wants to do a port? + ;; + irix5* | irix6* | nonstopux*) + case $cc_basename in + CC*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + # CC pic flag -KPIC is the default. + ;; + *) + ;; + esac + ;; + linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*) + case $cc_basename in + KCC*) + # KAI C++ Compiler + _LT_TAGVAR(lt_prog_compiler_wl, $1)='--backend -Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + ecpc* ) + # old Intel C++ for x86_64, which still supported -KPIC. + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' + ;; + icpc* ) + # Intel C++, used to be incompatible with GCC. + # ICC 10 doesn't accept -KPIC any more. + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' + ;; + pgCC* | pgcpp*) + # Portland Group C++ compiler + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fpic' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + cxx*) + # Compaq C++ + # Make sure the PIC flag is empty. It appears that all Alpha + # Linux and Compaq Tru64 Unix objects are PIC. + _LT_TAGVAR(lt_prog_compiler_pic, $1)= + _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + ;; + xlc* | xlC* | bgxl[[cC]]* | mpixl[[cC]]*) + # IBM XL 8.0, 9.0 on PPC and BlueGene + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-qpic' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-qstaticlink' + ;; + *) + case `$CC -V 2>&1 | sed 5q` in + *Sun\ C*) + # Sun C++ 5.9 + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ' + ;; + esac + ;; + esac + ;; + lynxos*) + ;; + m88k*) + ;; + mvs*) + case $cc_basename in + cxx*) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-W c,exportall' + ;; + *) + ;; + esac + ;; + netbsd* | netbsdelf*-gnu) + ;; + *qnx* | *nto*) + # QNX uses GNU C++, but need to define -shared option too, otherwise + # it will coredump. + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared' + ;; + osf3* | osf4* | osf5*) + case $cc_basename in + KCC*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='--backend -Wl,' + ;; + RCC*) + # Rational C++ 2.4.1 + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic' + ;; + cxx*) + # Digital/Compaq C++ + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + # Make sure the PIC flag is empty. It appears that all Alpha + # Linux and Compaq Tru64 Unix objects are PIC. + _LT_TAGVAR(lt_prog_compiler_pic, $1)= + _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + ;; + *) + ;; + esac + ;; + psos*) + ;; + solaris*) + case $cc_basename in + CC* | sunCC*) + # Sun C++ 4.2, 5.x and Centerline C++ + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ' + ;; + gcx*) + # Green Hills C++ Compiler + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-PIC' + ;; + *) + ;; + esac + ;; + sunos4*) + case $cc_basename in + CC*) + # Sun C++ 4.x + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + lcc*) + # Lucid + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic' + ;; + *) + ;; + esac + ;; + sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*) + case $cc_basename in + CC*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + esac + ;; + tandem*) + case $cc_basename in + NCC*) + # NonStop-UX NCC 3.20 + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + ;; + *) + ;; + esac + ;; + vxworks*) + ;; + *) + _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no + ;; + esac + fi +], +[ + if test yes = "$GCC"; then + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' + + case $host_os in + aix*) + # All AIX code is PIC. + if test ia64 = "$host_cpu"; then + # AIX 5 now supports IA64 processor + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + fi + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + + amigaos*) + case $host_cpu in + powerpc) + # see comment about AmigaOS4 .so support + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + m68k) + # FIXME: we need at least 68020 code to build shared libraries, but + # adding the '-m68020' flag to GCC prevents building anything better, + # like '-m68040'. + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-m68020 -resident32 -malways-restore-a4' + ;; + esac + ;; + + beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*) + # PIC is the default for these OSes. + ;; + + mingw* | cygwin* | pw32* | os2* | cegcc*) + # This hack is so that the source file can tell whether it is being + # built for inclusion in a dll (and should export symbols for example). + # Although the cygwin gcc ignores -fPIC, still need this for old-style + # (--disable-auto-import) libraries + m4_if([$1], [GCJ], [], + [_LT_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT']) + case $host_os in + os2*) + _LT_TAGVAR(lt_prog_compiler_static, $1)='$wl-static' + ;; + esac + ;; + + darwin* | rhapsody*) + # PIC is the default on this platform + # Common symbols not allowed in MH_DYLIB files + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fno-common' + ;; + + haiku*) + # PIC is the default for Haiku. + # The "-static" flag exists, but is broken. + _LT_TAGVAR(lt_prog_compiler_static, $1)= + ;; + + hpux*) + # PIC is the default for 64-bit PA HP-UX, but not for 32-bit + # PA HP-UX. On IA64 HP-UX, PIC is the default but the pic flag + # sets the default TLS model and affects inlining. + case $host_cpu in + hppa*64*) + # +Z the default + ;; + *) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + esac + ;; + + interix[[3-9]]*) + # Interix 3.x gcc -fpic/-fPIC options generate broken code. + # Instead, we relocate shared libraries at runtime. + ;; + + msdosdjgpp*) + # Just because we use GCC doesn't mean we suddenly get shared libraries + # on systems that don't support them. + _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no + enable_shared=no + ;; + + *nto* | *qnx*) + # QNX uses GNU C++, but need to define -shared option too, otherwise + # it will coredump. + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared' + ;; + + sysv4*MP*) + if test -d /usr/nec; then + _LT_TAGVAR(lt_prog_compiler_pic, $1)=-Kconform_pic + fi + ;; + + *) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + esac + + case $cc_basename in + nvcc*) # Cuda Compiler Driver 2.2 + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Xlinker ' + if test -n "$_LT_TAGVAR(lt_prog_compiler_pic, $1)"; then + _LT_TAGVAR(lt_prog_compiler_pic, $1)="-Xcompiler $_LT_TAGVAR(lt_prog_compiler_pic, $1)" + fi + ;; + esac + else + # PORTME Check for flag to pass linker flags through the system compiler. + case $host_os in + aix*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + if test ia64 = "$host_cpu"; then + # AIX 5 now supports IA64 processor + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + else + _LT_TAGVAR(lt_prog_compiler_static, $1)='-bnso -bI:/lib/syscalls.exp' + fi + ;; + + darwin* | rhapsody*) + # PIC is the default on this platform + # Common symbols not allowed in MH_DYLIB files + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fno-common' + case $cc_basename in + nagfor*) + # NAG Fortran compiler + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,-Wl,,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-PIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + esac + ;; + + mingw* | cygwin* | pw32* | os2* | cegcc*) + # This hack is so that the source file can tell whether it is being + # built for inclusion in a dll (and should export symbols for example). + m4_if([$1], [GCJ], [], + [_LT_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT']) + case $host_os in + os2*) + _LT_TAGVAR(lt_prog_compiler_static, $1)='$wl-static' + ;; + esac + ;; + + hpux9* | hpux10* | hpux11*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + # PIC is the default for IA64 HP-UX and 64-bit HP-UX, but + # not for PA HP-UX. + case $host_cpu in + hppa*64*|ia64*) + # +Z the default + ;; + *) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='+Z' + ;; + esac + # Is there a better lt_prog_compiler_static that works with the bundled CC? + _LT_TAGVAR(lt_prog_compiler_static, $1)='$wl-a ${wl}archive' + ;; + + irix5* | irix6* | nonstopux*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + # PIC (with -KPIC) is the default. + _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + ;; + + linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*) + case $cc_basename in + # old Intel for x86_64, which still supported -KPIC. + ecc*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' + ;; + # flang / f18. f95 an alias for gfortran or flang on Debian + flang* | f18* | f95*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' + ;; + # icc used to be incompatible with GCC. + # ICC 10 doesn't accept -KPIC any more. + icc* | ifort*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' + ;; + # Lahey Fortran 8.1. + lf95*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='--shared' + _LT_TAGVAR(lt_prog_compiler_static, $1)='--static' + ;; + nagfor*) + # NAG Fortran compiler + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,-Wl,,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-PIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + tcc*) + # Fabrice Bellard et al's Tiny C Compiler + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' + ;; + pgcc* | pgf77* | pgf90* | pgf95* | pgfortran*) + # Portland Group compilers (*not* the Pentium gcc compiler, + # which looks to be a dead project) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fpic' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + ccc*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + # All Alpha code is PIC. + _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + ;; + xl* | bgxl* | bgf* | mpixl*) + # IBM XL C 8.0/Fortran 10.1, 11.1 on PPC and BlueGene + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-qpic' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-qstaticlink' + ;; + *) + case `$CC -V 2>&1 | sed 5q` in + *Sun\ Ceres\ Fortran* | *Sun*Fortran*\ [[1-7]].* | *Sun*Fortran*\ 8.[[0-3]]*) + # Sun Fortran 8.3 passes all unrecognized flags to the linker + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + _LT_TAGVAR(lt_prog_compiler_wl, $1)='' + ;; + *Sun\ F* | *Sun*Fortran*) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ' + ;; + *Sun\ C*) + # Sun C 5.9 + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + ;; + *Intel*\ [[CF]]*Compiler*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' + ;; + *Portland\ Group*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fpic' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + esac + ;; + esac + ;; + + newsos6) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + + *nto* | *qnx*) + # QNX uses GNU C++, but need to define -shared option too, otherwise + # it will coredump. + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared' + ;; + + osf3* | osf4* | osf5*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + # All OSF/1 code is PIC. + _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + ;; + + rdos*) + _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + ;; + + solaris*) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + case $cc_basename in + f77* | f90* | f95* | sunf77* | sunf90* | sunf95*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ';; + *) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,';; + esac + ;; + + sunos4*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-PIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + + sysv4 | sysv4.2uw2* | sysv4.3*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + + sysv4*MP*) + if test -d /usr/nec; then + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-Kconform_pic' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + fi + ;; + + sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + + unicos*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no + ;; + + uts4*) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + + *) + _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no + ;; + esac + fi +]) +case $host_os in + # For platforms that do not support PIC, -DPIC is meaningless: + *djgpp*) + _LT_TAGVAR(lt_prog_compiler_pic, $1)= + ;; + *) + _LT_TAGVAR(lt_prog_compiler_pic, $1)="$_LT_TAGVAR(lt_prog_compiler_pic, $1)@&t@m4_if([$1],[],[ -DPIC],[m4_if([$1],[CXX],[ -DPIC],[])])" + ;; +esac + +AC_CACHE_CHECK([for $compiler option to produce PIC], + [_LT_TAGVAR(lt_cv_prog_compiler_pic, $1)], + [_LT_TAGVAR(lt_cv_prog_compiler_pic, $1)=$_LT_TAGVAR(lt_prog_compiler_pic, $1)]) +_LT_TAGVAR(lt_prog_compiler_pic, $1)=$_LT_TAGVAR(lt_cv_prog_compiler_pic, $1) + +# +# Check to make sure the PIC flag actually works. +# +if test -n "$_LT_TAGVAR(lt_prog_compiler_pic, $1)"; then + _LT_COMPILER_OPTION([if $compiler PIC flag $_LT_TAGVAR(lt_prog_compiler_pic, $1) works], + [_LT_TAGVAR(lt_cv_prog_compiler_pic_works, $1)], + [$_LT_TAGVAR(lt_prog_compiler_pic, $1)@&t@m4_if([$1],[],[ -DPIC],[m4_if([$1],[CXX],[ -DPIC],[])])], [], + [case $_LT_TAGVAR(lt_prog_compiler_pic, $1) in + "" | " "*) ;; + *) _LT_TAGVAR(lt_prog_compiler_pic, $1)=" $_LT_TAGVAR(lt_prog_compiler_pic, $1)" ;; + esac], + [_LT_TAGVAR(lt_prog_compiler_pic, $1)= + _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no]) +fi +_LT_TAGDECL([pic_flag], [lt_prog_compiler_pic], [1], + [Additional compiler flags for building library objects]) + +_LT_TAGDECL([wl], [lt_prog_compiler_wl], [1], + [How to pass a linker flag through the compiler]) +# +# Check to make sure the static flag actually works. +# +wl=$_LT_TAGVAR(lt_prog_compiler_wl, $1) eval lt_tmp_static_flag=\"$_LT_TAGVAR(lt_prog_compiler_static, $1)\" +_LT_LINKER_OPTION([if $compiler static flag $lt_tmp_static_flag works], + _LT_TAGVAR(lt_cv_prog_compiler_static_works, $1), + $lt_tmp_static_flag, + [], + [_LT_TAGVAR(lt_prog_compiler_static, $1)=]) +_LT_TAGDECL([link_static_flag], [lt_prog_compiler_static], [1], + [Compiler flag to prevent dynamic linking]) +])# _LT_COMPILER_PIC + + +# _LT_LINKER_SHLIBS([TAGNAME]) +# ---------------------------- +# See if the linker supports building shared libraries. +m4_defun([_LT_LINKER_SHLIBS], +[AC_REQUIRE([LT_PATH_LD])dnl +AC_REQUIRE([LT_PATH_NM])dnl +m4_require([_LT_PATH_MANIFEST_TOOL])dnl +m4_require([_LT_FILEUTILS_DEFAULTS])dnl +m4_require([_LT_DECL_EGREP])dnl +m4_require([_LT_DECL_SED])dnl +m4_require([_LT_CMD_GLOBAL_SYMBOLS])dnl +m4_require([_LT_TAG_COMPILER])dnl +AC_MSG_CHECKING([whether the $compiler linker ($LD) supports shared libraries]) +m4_if([$1], [CXX], [ + _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' + _LT_TAGVAR(exclude_expsyms, $1)=['_GLOBAL_OFFSET_TABLE_|_GLOBAL__F[ID]_.*'] + case $host_os in + aix[[4-9]]*) + # If we're using GNU nm, then we don't want the "-C" option. + # -C means demangle to GNU nm, but means don't demangle to AIX nm. + # Without the "-l" option, or with the "-B" option, AIX nm treats + # weak defined symbols like other global defined symbols, whereas + # GNU nm marks them as "W". + # While the 'weak' keyword is ignored in the Export File, we need + # it in the Import File for the 'aix-soname' feature, so we have + # to replace the "-B" option with "-P" for AIX nm. + if $NM -V 2>&1 | $GREP 'GNU' > /dev/null; then + _LT_TAGVAR(export_symbols_cmds, $1)='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "W")) && ([substr](\$ 3,1,1) != ".")) { if (\$ 2 == "W") { print \$ 3 " weak" } else { print \$ 3 } } }'\'' | sort -u > $export_symbols' + else + _LT_TAGVAR(export_symbols_cmds, $1)='`func_echo_all $NM | $SED -e '\''s/B\([[^B]]*\)$/P\1/'\''` -PCpgl $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) && ([substr](\$ 1,1,1) != ".")) { if ((\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) { print \$ 1 " weak" } else { print \$ 1 } } }'\'' | sort -u > $export_symbols' + fi + ;; + pw32*) + _LT_TAGVAR(export_symbols_cmds, $1)=$ltdll_cmds + ;; + cygwin* | mingw* | cegcc*) + case $cc_basename in + cl*) + _LT_TAGVAR(exclude_expsyms, $1)='_NULL_IMPORT_DESCRIPTOR|_IMPORT_DESCRIPTOR_.*' + ;; + *) + _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[[BCDGRS]][[ ]]/s/.*[[ ]]\([[^ ]]*\)/\1 DATA/;s/^.*[[ ]]__nm__\([[^ ]]*\)[[ ]][[^ ]]*/\1 DATA/;/^I[[ ]]/d;/^[[AITW]][[ ]]/s/.* //'\'' | sort | uniq > $export_symbols' + _LT_TAGVAR(exclude_expsyms, $1)=['[_]+GLOBAL_OFFSET_TABLE_|[_]+GLOBAL__[FID]_.*|[_]+head_[A-Za-z0-9_]+_dll|[A-Za-z0-9_]+_dll_iname'] + ;; + esac + ;; + linux* | k*bsd*-gnu | gnu*) + _LT_TAGVAR(link_all_deplibs, $1)=no + ;; + *) + _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' + ;; + esac +], [ + runpath_var= + _LT_TAGVAR(allow_undefined_flag, $1)= + _LT_TAGVAR(always_export_symbols, $1)=no + _LT_TAGVAR(archive_cmds, $1)= + _LT_TAGVAR(archive_expsym_cmds, $1)= + _LT_TAGVAR(compiler_needs_object, $1)=no + _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no + _LT_TAGVAR(export_dynamic_flag_spec, $1)= + _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' + _LT_TAGVAR(hardcode_automatic, $1)=no + _LT_TAGVAR(hardcode_direct, $1)=no + _LT_TAGVAR(hardcode_direct_absolute, $1)=no + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)= + _LT_TAGVAR(hardcode_libdir_separator, $1)= + _LT_TAGVAR(hardcode_minus_L, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=unsupported + _LT_TAGVAR(inherit_rpath, $1)=no + _LT_TAGVAR(link_all_deplibs, $1)=unknown + _LT_TAGVAR(module_cmds, $1)= + _LT_TAGVAR(module_expsym_cmds, $1)= + _LT_TAGVAR(old_archive_from_new_cmds, $1)= + _LT_TAGVAR(old_archive_from_expsyms_cmds, $1)= + _LT_TAGVAR(thread_safe_flag_spec, $1)= + _LT_TAGVAR(whole_archive_flag_spec, $1)= + # include_expsyms should be a list of space-separated symbols to be *always* + # included in the symbol list + _LT_TAGVAR(include_expsyms, $1)= + # exclude_expsyms can be an extended regexp of symbols to exclude + # it will be wrapped by ' (' and ')$', so one must not match beginning or + # end of line. Example: 'a|bc|.*d.*' will exclude the symbols 'a' and 'bc', + # as well as any symbol that contains 'd'. + _LT_TAGVAR(exclude_expsyms, $1)=['_GLOBAL_OFFSET_TABLE_|_GLOBAL__F[ID]_.*'] + # Although _GLOBAL_OFFSET_TABLE_ is a valid symbol C name, most a.out + # platforms (ab)use it in PIC code, but their linkers get confused if + # the symbol is explicitly referenced. Since portable code cannot + # rely on this symbol name, it's probably fine to never include it in + # preloaded symbol tables. + # Exclude shared library initialization/finalization symbols. +dnl Note also adjust exclude_expsyms for C++ above. + extract_expsyms_cmds= + + case $host_os in + cygwin* | mingw* | pw32* | cegcc*) + # FIXME: the MSVC++ port hasn't been tested in a loooong time + # When not using gcc, we currently assume that we are using + # Microsoft Visual C++. + if test yes != "$GCC"; then + with_gnu_ld=no + fi + ;; + interix*) + # we just hope/assume this is gcc and not c89 (= MSVC++) + with_gnu_ld=yes + ;; + openbsd* | bitrig*) + with_gnu_ld=no + ;; + linux* | k*bsd*-gnu | gnu*) + _LT_TAGVAR(link_all_deplibs, $1)=no + ;; + esac + + _LT_TAGVAR(ld_shlibs, $1)=yes + + # On some targets, GNU ld is compatible enough with the native linker + # that we're better off using the native interface for both. + lt_use_gnu_ld_interface=no + if test yes = "$with_gnu_ld"; then + case $host_os in + aix*) + # The AIX port of GNU ld has always aspired to compatibility + # with the native linker. However, as the warning in the GNU ld + # block says, versions before 2.19.5* couldn't really create working + # shared libraries, regardless of the interface used. + case `$LD -v 2>&1` in + *\ \(GNU\ Binutils\)\ 2.19.5*) ;; + *\ \(GNU\ Binutils\)\ 2.[[2-9]]*) ;; + *\ \(GNU\ Binutils\)\ [[3-9]]*) ;; + *) + lt_use_gnu_ld_interface=yes + ;; + esac + ;; + *) + lt_use_gnu_ld_interface=yes + ;; + esac + fi + + if test yes = "$lt_use_gnu_ld_interface"; then + # If archive_cmds runs LD, not CC, wlarc should be empty + wlarc='$wl' + + # Set some defaults for GNU ld with shared library support. These + # are reset later if shared libraries are not supported. Putting them + # here allows them to be overridden if necessary. + runpath_var=LD_RUN_PATH + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath $wl$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl--export-dynamic' + # ancient GNU ld didn't support --whole-archive et. al. + if $LD --help 2>&1 | $GREP 'no-whole-archive' > /dev/null; then + _LT_TAGVAR(whole_archive_flag_spec, $1)=$wlarc'--whole-archive$convenience '$wlarc'--no-whole-archive' + else + _LT_TAGVAR(whole_archive_flag_spec, $1)= + fi + supports_anon_versioning=no + case `$LD -v | $SED -e 's/([^)]\+)\s\+//' 2>&1` in + *GNU\ gold*) supports_anon_versioning=yes ;; + *\ [[01]].* | *\ 2.[[0-9]].* | *\ 2.10.*) ;; # catch versions < 2.11 + *\ 2.11.93.0.2\ *) supports_anon_versioning=yes ;; # RH7.3 ... + *\ 2.11.92.0.12\ *) supports_anon_versioning=yes ;; # Mandrake 8.2 ... + *\ 2.11.*) ;; # other 2.11 versions + *) supports_anon_versioning=yes ;; + esac + + # See if GNU ld supports shared libraries. + case $host_os in + aix[[3-9]]*) + # On AIX/PPC, the GNU linker is very broken + if test ia64 != "$host_cpu"; then + _LT_TAGVAR(ld_shlibs, $1)=no + cat <<_LT_EOF 1>&2 + +*** Warning: the GNU linker, at least up to release 2.19, is reported +*** to be unable to reliably create shared libraries on AIX. +*** Therefore, libtool is disabling shared libraries support. If you +*** really care for shared libraries, you may want to install binutils +*** 2.20 or above, or modify your PATH so that a non-GNU linker is found. +*** You will then need to restart the configuration process. + +_LT_EOF + fi + ;; + + amigaos*) + case $host_cpu in + powerpc) + # see comment about AmigaOS4 .so support + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='' + ;; + m68k) + _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/a2ixlibrary.data~$ECHO "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$ECHO "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$ECHO "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$ECHO "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_minus_L, $1)=yes + ;; + esac + ;; + + beos*) + if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + # Joseph Beckenbach says some releases of gcc + # support --undefined. This deserves some investigation. FIXME + _LT_TAGVAR(archive_cmds, $1)='$CC -nostart $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + + cygwin* | mingw* | pw32* | cegcc*) + # _LT_TAGVAR(hardcode_libdir_flag_spec, $1) is actually meaningless, + # as there is no search path for DLLs. + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl--export-all-symbols' + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + _LT_TAGVAR(always_export_symbols, $1)=no + _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes + _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[[BCDGRS]][[ ]]/s/.*[[ ]]\([[^ ]]*\)/\1 DATA/;s/^.*[[ ]]__nm__\([[^ ]]*\)[[ ]][[^ ]]*/\1 DATA/;/^I[[ ]]/d;/^[[AITW]][[ ]]/s/.* //'\'' | sort | uniq > $export_symbols' + _LT_TAGVAR(exclude_expsyms, $1)=['[_]+GLOBAL_OFFSET_TABLE_|[_]+GLOBAL__[FID]_.*|[_]+head_[A-Za-z0-9_]+_dll|[A-Za-z0-9_]+_dll_iname'] + + if $LD --help 2>&1 | $GREP 'auto-import' > /dev/null; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -o $output_objdir/$soname $wl--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' + # If the export-symbols file already is a .def file, use it as + # is; otherwise, prepend EXPORTS... + _LT_TAGVAR(archive_expsym_cmds, $1)='if _LT_DLL_DEF_P([$export_symbols]); then + cp $export_symbols $output_objdir/$soname.def; + else + echo EXPORTS > $output_objdir/$soname.def; + cat $export_symbols >> $output_objdir/$soname.def; + fi~ + $CC -shared $output_objdir/$soname.def $libobjs $deplibs $compiler_flags -o $output_objdir/$soname $wl--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + + haiku*) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + _LT_TAGVAR(link_all_deplibs, $1)=yes + ;; + + os2*) + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_minus_L, $1)=yes + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + shrext_cmds=.dll + _LT_TAGVAR(archive_cmds, $1)='$ECHO "LIBRARY ${soname%$shared_ext} INITINSTANCE TERMINSTANCE" > $output_objdir/$libname.def~ + $ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~ + $ECHO "DATA MULTIPLE NONSHARED" >> $output_objdir/$libname.def~ + $ECHO EXPORTS >> $output_objdir/$libname.def~ + emxexp $libobjs | $SED /"_DLL_InitTerm"/d >> $output_objdir/$libname.def~ + $CC -Zdll -Zcrtdll -o $output_objdir/$soname $libobjs $deplibs $compiler_flags $output_objdir/$libname.def~ + emximp -o $lib $output_objdir/$libname.def' + _LT_TAGVAR(archive_expsym_cmds, $1)='$ECHO "LIBRARY ${soname%$shared_ext} INITINSTANCE TERMINSTANCE" > $output_objdir/$libname.def~ + $ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~ + $ECHO "DATA MULTIPLE NONSHARED" >> $output_objdir/$libname.def~ + $ECHO EXPORTS >> $output_objdir/$libname.def~ + prefix_cmds="$SED"~ + if test EXPORTS = "`$SED 1q $export_symbols`"; then + prefix_cmds="$prefix_cmds -e 1d"; + fi~ + prefix_cmds="$prefix_cmds -e \"s/^\(.*\)$/_\1/g\""~ + cat $export_symbols | $prefix_cmds >> $output_objdir/$libname.def~ + $CC -Zdll -Zcrtdll -o $output_objdir/$soname $libobjs $deplibs $compiler_flags $output_objdir/$libname.def~ + emximp -o $lib $output_objdir/$libname.def' + _LT_TAGVAR(old_archive_From_new_cmds, $1)='emximp -o $output_objdir/${libname}_dll.a $output_objdir/$libname.def' + _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes + ;; + + interix[[3-9]]*) + _LT_TAGVAR(hardcode_direct, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath,$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl-E' + # Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc. + # Instead, shared libraries are loaded at an image base (0x10000000 by + # default) and relocated if they conflict, which is a slow very memory + # consuming and fragmenting process. To avoid this, we pick a random, + # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link + # time. Moving up from 0x10000000 also allows more sbrk(2) space. + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-h,$soname $wl--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='sed "s|^|_|" $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-h,$soname $wl--retain-symbols-file,$output_objdir/$soname.expsym $wl--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + ;; + + gnu* | linux* | tpf* | k*bsd*-gnu | kopensolaris*-gnu) + tmp_diet=no + if test linux-dietlibc = "$host_os"; then + case $cc_basename in + diet\ *) tmp_diet=yes;; # linux-dietlibc with static linking (!diet-dyn) + esac + fi + if $LD --help 2>&1 | $EGREP ': supported targets:.* elf' > /dev/null \ + && test no = "$tmp_diet" + then + tmp_addflag=' $pic_flag' + tmp_sharedflag='-shared' + case $cc_basename,$host_cpu in + pgcc*) # Portland Group C compiler + _LT_TAGVAR(whole_archive_flag_spec, $1)='$wl--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` $wl--no-whole-archive' + tmp_addflag=' $pic_flag' + ;; + pgf77* | pgf90* | pgf95* | pgfortran*) + # Portland Group f77 and f90 compilers + _LT_TAGVAR(whole_archive_flag_spec, $1)='$wl--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` $wl--no-whole-archive' + tmp_addflag=' $pic_flag -Mnomain' ;; + ecc*,ia64* | icc*,ia64*) # Intel C compiler on ia64 + tmp_addflag=' -i_dynamic' ;; + efc*,ia64* | ifort*,ia64*) # Intel Fortran compiler on ia64 + tmp_addflag=' -i_dynamic -nofor_main' ;; + ifc* | ifort*) # Intel Fortran compiler + tmp_addflag=' -nofor_main' ;; + lf95*) # Lahey Fortran 8.1 + _LT_TAGVAR(whole_archive_flag_spec, $1)= + tmp_sharedflag='--shared' ;; + nagfor*) # NAGFOR 5.3 + tmp_sharedflag='-Wl,-shared' ;; + xl[[cC]]* | bgxl[[cC]]* | mpixl[[cC]]*) # IBM XL C 8.0 on PPC (deal with xlf below) + tmp_sharedflag='-qmkshrobj' + tmp_addflag= ;; + nvcc*) # Cuda Compiler Driver 2.2 + _LT_TAGVAR(whole_archive_flag_spec, $1)='$wl--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` $wl--no-whole-archive' + _LT_TAGVAR(compiler_needs_object, $1)=yes + ;; + esac + case `$CC -V 2>&1 | sed 5q` in + *Sun\ C*) # Sun C 5.9 + _LT_TAGVAR(whole_archive_flag_spec, $1)='$wl--whole-archive`new_convenience=; for conv in $convenience\"\"; do test -z \"$conv\" || new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` $wl--no-whole-archive' + _LT_TAGVAR(compiler_needs_object, $1)=yes + tmp_sharedflag='-G' ;; + *Sun\ F*) # Sun Fortran 8.3 + tmp_sharedflag='-G' ;; + esac + _LT_TAGVAR(archive_cmds, $1)='$CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + + if test yes = "$supports_anon_versioning"; then + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $output_objdir/$libname.ver~ + cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ + echo "local: *; };" >> $output_objdir/$libname.ver~ + $CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-version-script $wl$output_objdir/$libname.ver -o $lib' + fi + + case $cc_basename in + tcc*) + _LT_TAGVAR(export_dynamic_flag_spec, $1)='-rdynamic' + ;; + xlf* | bgf* | bgxlf* | mpixlf*) + # IBM XL Fortran 10.1 on PPC cannot create shared libs itself + _LT_TAGVAR(whole_archive_flag_spec, $1)='--whole-archive$convenience --no-whole-archive' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath $wl$libdir' + _LT_TAGVAR(archive_cmds, $1)='$LD -shared $libobjs $deplibs $linker_flags -soname $soname -o $lib' + if test yes = "$supports_anon_versioning"; then + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $output_objdir/$libname.ver~ + cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ + echo "local: *; };" >> $output_objdir/$libname.ver~ + $LD -shared $libobjs $deplibs $linker_flags -soname $soname -version-script $output_objdir/$libname.ver -o $lib' + fi + ;; + esac + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + + netbsd* | netbsdelf*-gnu) + if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then + _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib' + wlarc= + else + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' + fi + ;; + + solaris*) + if $LD -v 2>&1 | $GREP 'BFD 2\.8' > /dev/null; then + _LT_TAGVAR(ld_shlibs, $1)=no + cat <<_LT_EOF 1>&2 + +*** Warning: The releases 2.8.* of the GNU linker cannot reliably +*** create shared libraries on Solaris systems. Therefore, libtool +*** is disabling shared libraries support. We urge you to upgrade GNU +*** binutils to release 2.9.1 or newer. Another option is to modify +*** your PATH or compiler configuration so that the native linker is +*** used, and then restart. + +_LT_EOF + elif $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + + sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX*) + case `$LD -v 2>&1` in + *\ [[01]].* | *\ 2.[[0-9]].* | *\ 2.1[[0-5]].*) + _LT_TAGVAR(ld_shlibs, $1)=no + cat <<_LT_EOF 1>&2 + +*** Warning: Releases of the GNU linker prior to 2.16.91.0.3 cannot +*** reliably create shared libraries on SCO systems. Therefore, libtool +*** is disabling shared libraries support. We urge you to upgrade GNU +*** binutils to release 2.16.91.0.3 or newer. Another option is to modify +*** your PATH or compiler configuration so that the native linker is +*** used, and then restart. + +_LT_EOF + ;; + *) + # For security reasons, it is highly recommended that you always + # use absolute paths for naming shared libraries, and exclude the + # DT_RUNPATH tag from executables and libraries. But doing so + # requires that you compile everything twice, which is a pain. + if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath $wl$libdir' + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + esac + ;; + + sunos4*) + _LT_TAGVAR(archive_cmds, $1)='$LD -assert pure-text -Bshareable -o $lib $libobjs $deplibs $linker_flags' + wlarc= + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + *) + if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + esac + + if test no = "$_LT_TAGVAR(ld_shlibs, $1)"; then + runpath_var= + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)= + _LT_TAGVAR(export_dynamic_flag_spec, $1)= + _LT_TAGVAR(whole_archive_flag_spec, $1)= + fi + else + # PORTME fill in a description of your system's linker (not GNU ld) + case $host_os in + aix3*) + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + _LT_TAGVAR(always_export_symbols, $1)=yes + _LT_TAGVAR(archive_expsym_cmds, $1)='$LD -o $output_objdir/$soname $libobjs $deplibs $linker_flags -bE:$export_symbols -T512 -H512 -bM:SRE~$AR $AR_FLAGS $lib $output_objdir/$soname' + # Note: this linker hardcodes the directories in LIBPATH if there + # are no directories specified by -L. + _LT_TAGVAR(hardcode_minus_L, $1)=yes + if test yes = "$GCC" && test -z "$lt_prog_compiler_static"; then + # Neither direct hardcoding nor static linking is supported with a + # broken collect2. + _LT_TAGVAR(hardcode_direct, $1)=unsupported + fi + ;; + + aix[[4-9]]*) + if test ia64 = "$host_cpu"; then + # On IA64, the linker does run time linking by default, so we don't + # have to do anything special. + aix_use_runtimelinking=no + exp_sym_flag='-Bexport' + no_entry_flag= + else + # If we're using GNU nm, then we don't want the "-C" option. + # -C means demangle to GNU nm, but means don't demangle to AIX nm. + # Without the "-l" option, or with the "-B" option, AIX nm treats + # weak defined symbols like other global defined symbols, whereas + # GNU nm marks them as "W". + # While the 'weak' keyword is ignored in the Export File, we need + # it in the Import File for the 'aix-soname' feature, so we have + # to replace the "-B" option with "-P" for AIX nm. + if $NM -V 2>&1 | $GREP 'GNU' > /dev/null; then + _LT_TAGVAR(export_symbols_cmds, $1)='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "W")) && ([substr](\$ 3,1,1) != ".")) { if (\$ 2 == "W") { print \$ 3 " weak" } else { print \$ 3 } } }'\'' | sort -u > $export_symbols' + else + _LT_TAGVAR(export_symbols_cmds, $1)='`func_echo_all $NM | $SED -e '\''s/B\([[^B]]*\)$/P\1/'\''` -PCpgl $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) && ([substr](\$ 1,1,1) != ".")) { if ((\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) { print \$ 1 " weak" } else { print \$ 1 } } }'\'' | sort -u > $export_symbols' + fi + aix_use_runtimelinking=no + + # Test if we are trying to use run time linking or normal + # AIX style linking. If -brtl is somewhere in LDFLAGS, we + # have runtime linking enabled, and use it for executables. + # For shared libraries, we enable/disable runtime linking + # depending on the kind of the shared library created - + # when "with_aix_soname,aix_use_runtimelinking" is: + # "aix,no" lib.a(lib.so.V) shared, rtl:no, for executables + # "aix,yes" lib.so shared, rtl:yes, for executables + # lib.a static archive + # "both,no" lib.so.V(shr.o) shared, rtl:yes + # lib.a(lib.so.V) shared, rtl:no, for executables + # "both,yes" lib.so.V(shr.o) shared, rtl:yes, for executables + # lib.a(lib.so.V) shared, rtl:no + # "svr4,*" lib.so.V(shr.o) shared, rtl:yes, for executables + # lib.a static archive + case $host_os in aix4.[[23]]|aix4.[[23]].*|aix[[5-9]]*) + for ld_flag in $LDFLAGS; do + if (test x-brtl = "x$ld_flag" || test x-Wl,-brtl = "x$ld_flag"); then + aix_use_runtimelinking=yes + break + fi + done + if test svr4,no = "$with_aix_soname,$aix_use_runtimelinking"; then + # With aix-soname=svr4, we create the lib.so.V shared archives only, + # so we don't have lib.a shared libs to link our executables. + # We have to force runtime linking in this case. + aix_use_runtimelinking=yes + LDFLAGS="$LDFLAGS -Wl,-brtl" + fi + ;; + esac + + exp_sym_flag='-bexport' + no_entry_flag='-bnoentry' + fi + + # When large executables or shared objects are built, AIX ld can + # have problems creating the table of contents. If linking a library + # or program results in "error TOC overflow" add -mminimal-toc to + # CXXFLAGS/CFLAGS for g++/gcc. In the cases where that is not + # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS. + + _LT_TAGVAR(archive_cmds, $1)='' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_direct_absolute, $1)=yes + _LT_TAGVAR(hardcode_libdir_separator, $1)=':' + _LT_TAGVAR(link_all_deplibs, $1)=yes + _LT_TAGVAR(file_list_spec, $1)='$wl-f,' + case $with_aix_soname,$aix_use_runtimelinking in + aix,*) ;; # traditional, no import file + svr4,* | *,yes) # use import file + # The Import File defines what to hardcode. + _LT_TAGVAR(hardcode_direct, $1)=no + _LT_TAGVAR(hardcode_direct_absolute, $1)=no + ;; + esac + + if test yes = "$GCC"; then + case $host_os in aix4.[[012]]|aix4.[[012]].*) + # We only want to do this on AIX 4.2 and lower, the check + # below for broken collect2 doesn't work under 4.3+ + collect2name=`$CC -print-prog-name=collect2` + if test -f "$collect2name" && + strings "$collect2name" | $GREP resolve_lib_name >/dev/null + then + # We have reworked collect2 + : + else + # We have old collect2 + _LT_TAGVAR(hardcode_direct, $1)=unsupported + # It fails to find uninstalled libraries when the uninstalled + # path is not listed in the libpath. Setting hardcode_minus_L + # to unsupported forces relinking + _LT_TAGVAR(hardcode_minus_L, $1)=yes + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)= + fi + ;; + esac + shared_flag='-shared' + if test yes = "$aix_use_runtimelinking"; then + shared_flag="$shared_flag "'$wl-G' + fi + # Need to ensure runtime linking is disabled for the traditional + # shared library, or the linker may eventually find shared libraries + # /with/ Import File - we do not want to mix them. + shared_flag_aix='-shared' + shared_flag_svr4='-shared $wl-G' + else + # not using gcc + if test ia64 = "$host_cpu"; then + # VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release + # chokes on -Wl,-G. The following line is correct: + shared_flag='-G' + else + if test yes = "$aix_use_runtimelinking"; then + shared_flag='$wl-G' + else + shared_flag='$wl-bM:SRE' + fi + shared_flag_aix='$wl-bM:SRE' + shared_flag_svr4='$wl-G' + fi + fi + + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl-bexpall' + # It seems that -bexpall does not export symbols beginning with + # underscore (_), so it is better to generate a list of symbols to export. + _LT_TAGVAR(always_export_symbols, $1)=yes + if test aix,yes = "$with_aix_soname,$aix_use_runtimelinking"; then + # Warning - without using the other runtime loading flags (-brtl), + # -berok will link without error, but may produce a broken library. + _LT_TAGVAR(allow_undefined_flag, $1)='-berok' + # Determine the default libpath from the value encoded in an + # empty executable. + _LT_SYS_MODULE_PATH_AIX([$1]) + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-blibpath:$libdir:'"$aix_libpath" + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -o $output_objdir/$soname $libobjs $deplibs $wl'$no_entry_flag' $compiler_flags `if test -n "$allow_undefined_flag"; then func_echo_all "$wl$allow_undefined_flag"; else :; fi` $wl'$exp_sym_flag:\$export_symbols' '$shared_flag + else + if test ia64 = "$host_cpu"; then + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-R $libdir:/usr/lib:/lib' + _LT_TAGVAR(allow_undefined_flag, $1)="-z nodefs" + _LT_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\$wl$no_entry_flag"' $compiler_flags $wl$allow_undefined_flag '"\$wl$exp_sym_flag:\$export_symbols" + else + # Determine the default libpath from the value encoded in an + # empty executable. + _LT_SYS_MODULE_PATH_AIX([$1]) + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-blibpath:$libdir:'"$aix_libpath" + # Warning - without using the other run time loading flags, + # -berok will link without error, but may produce a broken library. + _LT_TAGVAR(no_undefined_flag, $1)=' $wl-bernotok' + _LT_TAGVAR(allow_undefined_flag, $1)=' $wl-berok' + if test yes = "$with_gnu_ld"; then + # We only use this code for GNU lds that support --whole-archive. + _LT_TAGVAR(whole_archive_flag_spec, $1)='$wl--whole-archive$convenience $wl--no-whole-archive' + else + # Exported symbols can be pulled into shared objects from archives + _LT_TAGVAR(whole_archive_flag_spec, $1)='$convenience' + fi + _LT_TAGVAR(archive_cmds_need_lc, $1)=yes + _LT_TAGVAR(archive_expsym_cmds, $1)='$RM -r $output_objdir/$realname.d~$MKDIR $output_objdir/$realname.d' + # -brtl affects multiple linker settings, -berok does not and is overridden later + compiler_flags_filtered='`func_echo_all "$compiler_flags " | $SED -e "s%-brtl\\([[, ]]\\)%-berok\\1%g"`' + if test svr4 != "$with_aix_soname"; then + # This is similar to how AIX traditionally builds its shared libraries. + _LT_TAGVAR(archive_expsym_cmds, $1)="$_LT_TAGVAR(archive_expsym_cmds, $1)"'~$CC '$shared_flag_aix' -o $output_objdir/$realname.d/$soname $libobjs $deplibs $wl-bnoentry '$compiler_flags_filtered'$wl-bE:$export_symbols$allow_undefined_flag~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$realname.d/$soname' + fi + if test aix != "$with_aix_soname"; then + _LT_TAGVAR(archive_expsym_cmds, $1)="$_LT_TAGVAR(archive_expsym_cmds, $1)"'~$CC '$shared_flag_svr4' -o $output_objdir/$realname.d/$shared_archive_member_spec.o $libobjs $deplibs $wl-bnoentry '$compiler_flags_filtered'$wl-bE:$export_symbols$allow_undefined_flag~$STRIP -e $output_objdir/$realname.d/$shared_archive_member_spec.o~( func_echo_all "#! $soname($shared_archive_member_spec.o)"; if test shr_64 = "$shared_archive_member_spec"; then func_echo_all "# 64"; else func_echo_all "# 32"; fi; cat $export_symbols ) > $output_objdir/$realname.d/$shared_archive_member_spec.imp~$AR $AR_FLAGS $output_objdir/$soname $output_objdir/$realname.d/$shared_archive_member_spec.o $output_objdir/$realname.d/$shared_archive_member_spec.imp' + else + # used by -dlpreopen to get the symbols + _LT_TAGVAR(archive_expsym_cmds, $1)="$_LT_TAGVAR(archive_expsym_cmds, $1)"'~$MV $output_objdir/$realname.d/$soname $output_objdir' + fi + _LT_TAGVAR(archive_expsym_cmds, $1)="$_LT_TAGVAR(archive_expsym_cmds, $1)"'~$RM -r $output_objdir/$realname.d' + fi + fi + ;; + + amigaos*) + case $host_cpu in + powerpc) + # see comment about AmigaOS4 .so support + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='' + ;; + m68k) + _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/a2ixlibrary.data~$ECHO "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$ECHO "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$ECHO "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$ECHO "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_minus_L, $1)=yes + ;; + esac + ;; + + bsdi[[45]]*) + _LT_TAGVAR(export_dynamic_flag_spec, $1)=-rdynamic + ;; + + cygwin* | mingw* | pw32* | cegcc*) + # When not using gcc, we currently assume that we are using + # Microsoft Visual C++. + # hardcode_libdir_flag_spec is actually meaningless, as there is + # no search path for DLLs. + case $cc_basename in + cl*) + # Native MSVC + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)=' ' + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + _LT_TAGVAR(always_export_symbols, $1)=yes + _LT_TAGVAR(file_list_spec, $1)='@' + # Tell ltmain to make .lib files, not .a files. + libext=lib + # Tell ltmain to make .dll files, not .so files. + shrext_cmds=.dll + # FIXME: Setting linknames here is a bad hack. + _LT_TAGVAR(archive_cmds, $1)='$CC -o $output_objdir/$soname $libobjs $compiler_flags $deplibs -Wl,-DLL,-IMPLIB:"$tool_output_objdir$libname.dll.lib"~linknames=' + _LT_TAGVAR(archive_expsym_cmds, $1)='if _LT_DLL_DEF_P([$export_symbols]); then + cp "$export_symbols" "$output_objdir/$soname.def"; + echo "$tool_output_objdir$soname.def" > "$output_objdir/$soname.exp"; + else + $SED -e '\''s/^/-link -EXPORT:/'\'' < $export_symbols > $output_objdir/$soname.exp; + fi~ + $CC -o $tool_output_objdir$soname $libobjs $compiler_flags $deplibs "@$tool_output_objdir$soname.exp" -Wl,-DLL,-IMPLIB:"$tool_output_objdir$libname.dll.lib"~ + linknames=' + # The linker will not automatically build a static lib if we build a DLL. + # _LT_TAGVAR(old_archive_from_new_cmds, $1)='true' + _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes + _LT_TAGVAR(exclude_expsyms, $1)='_NULL_IMPORT_DESCRIPTOR|_IMPORT_DESCRIPTOR_.*' + _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[[BCDGRS]][[ ]]/s/.*[[ ]]\([[^ ]]*\)/\1,DATA/'\'' | $SED -e '\''/^[[AITW]][[ ]]/s/.*[[ ]]//'\'' | sort | uniq > $export_symbols' + # Don't use ranlib + _LT_TAGVAR(old_postinstall_cmds, $1)='chmod 644 $oldlib' + _LT_TAGVAR(postlink_cmds, $1)='lt_outputfile="@OUTPUT@"~ + lt_tool_outputfile="@TOOL_OUTPUT@"~ + case $lt_outputfile in + *.exe|*.EXE) ;; + *) + lt_outputfile=$lt_outputfile.exe + lt_tool_outputfile=$lt_tool_outputfile.exe + ;; + esac~ + if test : != "$MANIFEST_TOOL" && test -f "$lt_outputfile.manifest"; then + $MANIFEST_TOOL -manifest "$lt_tool_outputfile.manifest" -outputresource:"$lt_tool_outputfile" || exit 1; + $RM "$lt_outputfile.manifest"; + fi' + ;; + *) + # Assume MSVC wrapper + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)=' ' + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + # Tell ltmain to make .lib files, not .a files. + libext=lib + # Tell ltmain to make .dll files, not .so files. + shrext_cmds=.dll + # FIXME: Setting linknames here is a bad hack. + _LT_TAGVAR(archive_cmds, $1)='$CC -o $lib $libobjs $compiler_flags `func_echo_all "$deplibs" | $SED '\''s/ -lc$//'\''` -link -dll~linknames=' + # The linker will automatically build a .lib file if we build a DLL. + _LT_TAGVAR(old_archive_from_new_cmds, $1)='true' + # FIXME: Should let the user specify the lib program. + _LT_TAGVAR(old_archive_cmds, $1)='lib -OUT:$oldlib$oldobjs$old_deplibs' + _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes + ;; + esac + ;; + + darwin* | rhapsody*) + _LT_DARWIN_LINKER_FEATURES($1) + ;; + + dgux*) + _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + # FreeBSD 2.2.[012] allows us to include c++rt0.o to get C++ constructor + # support. Future versions do this automatically, but an explicit c++rt0.o + # does not break anything, and helps significantly (at the cost of a little + # extra space). + freebsd2.2*) + _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags /usr/lib/c++rt0.o' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + # Unfortunately, older versions of FreeBSD 2 do not have this feature. + freebsd2.*) + _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_minus_L, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + # FreeBSD 3 and greater uses gcc -shared to do shared libraries. + freebsd* | dragonfly*) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + hpux9*) + if test yes = "$GCC"; then + _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$CC -shared $pic_flag $wl+b $wl$install_libdir -o $output_objdir/$soname $libobjs $deplibs $compiler_flags~test "x$output_objdir/$soname" = "x$lib" || mv $output_objdir/$soname $lib' + else + _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$LD -b +b $install_libdir -o $output_objdir/$soname $libobjs $deplibs $linker_flags~test "x$output_objdir/$soname" = "x$lib" || mv $output_objdir/$soname $lib' + fi + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl+b $wl$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + _LT_TAGVAR(hardcode_direct, $1)=yes + + # hardcode_minus_L: Not really in the search PATH, + # but as the default location of the library. + _LT_TAGVAR(hardcode_minus_L, $1)=yes + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl-E' + ;; + + hpux10*) + if test yes,no = "$GCC,$with_gnu_ld"; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $wl+h $wl$soname $wl+b $wl$install_libdir -o $lib $libobjs $deplibs $compiler_flags' + else + _LT_TAGVAR(archive_cmds, $1)='$LD -b +h $soname +b $install_libdir -o $lib $libobjs $deplibs $linker_flags' + fi + if test no = "$with_gnu_ld"; then + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl+b $wl$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_direct_absolute, $1)=yes + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl-E' + # hardcode_minus_L: Not really in the search PATH, + # but as the default location of the library. + _LT_TAGVAR(hardcode_minus_L, $1)=yes + fi + ;; + + hpux11*) + if test yes,no = "$GCC,$with_gnu_ld"; then + case $host_cpu in + hppa*64*) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $wl+h $wl$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + ia64*) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $wl+h $wl$soname $wl+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags' + ;; + *) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $wl+h $wl$soname $wl+b $wl$install_libdir -o $lib $libobjs $deplibs $compiler_flags' + ;; + esac + else + case $host_cpu in + hppa*64*) + _LT_TAGVAR(archive_cmds, $1)='$CC -b $wl+h $wl$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + ia64*) + _LT_TAGVAR(archive_cmds, $1)='$CC -b $wl+h $wl$soname $wl+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags' + ;; + *) + m4_if($1, [], [ + # Older versions of the 11.00 compiler do not understand -b yet + # (HP92453-01 A.11.01.20 doesn't, HP92453-01 B.11.X.35175-35176.GP does) + _LT_LINKER_OPTION([if $CC understands -b], + _LT_TAGVAR(lt_cv_prog_compiler__b, $1), [-b], + [_LT_TAGVAR(archive_cmds, $1)='$CC -b $wl+h $wl$soname $wl+b $wl$install_libdir -o $lib $libobjs $deplibs $compiler_flags'], + [_LT_TAGVAR(archive_cmds, $1)='$LD -b +h $soname +b $install_libdir -o $lib $libobjs $deplibs $linker_flags'])], + [_LT_TAGVAR(archive_cmds, $1)='$CC -b $wl+h $wl$soname $wl+b $wl$install_libdir -o $lib $libobjs $deplibs $compiler_flags']) + ;; + esac + fi + if test no = "$with_gnu_ld"; then + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl+b $wl$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + + case $host_cpu in + hppa*64*|ia64*) + _LT_TAGVAR(hardcode_direct, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + *) + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_direct_absolute, $1)=yes + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl-E' + + # hardcode_minus_L: Not really in the search PATH, + # but as the default location of the library. + _LT_TAGVAR(hardcode_minus_L, $1)=yes + ;; + esac + fi + ;; + + irix5* | irix6* | nonstopux*) + if test yes = "$GCC"; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations -o $lib' + # Try to use the -exported_symbol ld option, if it does not + # work, assume that -exports_file does not work either and + # implicitly export all symbols. + # This should be the same for all languages, so no per-tag cache variable. + AC_CACHE_CHECK([whether the $host_os linker accepts -exported_symbol], + [lt_cv_irix_exported_symbol], + [save_LDFLAGS=$LDFLAGS + LDFLAGS="$LDFLAGS -shared $wl-exported_symbol ${wl}foo $wl-update_registry $wl/dev/null" + AC_LINK_IFELSE( + [AC_LANG_SOURCE( + [AC_LANG_CASE([C], [[int foo (void) { return 0; }]], + [C++], [[int foo (void) { return 0; }]], + [Fortran 77], [[ + subroutine foo + end]], + [Fortran], [[ + subroutine foo + end]])])], + [lt_cv_irix_exported_symbol=yes], + [lt_cv_irix_exported_symbol=no]) + LDFLAGS=$save_LDFLAGS]) + if test yes = "$lt_cv_irix_exported_symbol"; then + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations $wl-exports_file $wl$export_symbols -o $lib' + fi + _LT_TAGVAR(link_all_deplibs, $1)=no + else + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -exports_file $export_symbols -o $lib' + fi + _LT_TAGVAR(archive_cmds_need_lc, $1)='no' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath $wl$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + _LT_TAGVAR(inherit_rpath, $1)=yes + _LT_TAGVAR(link_all_deplibs, $1)=yes + ;; + + linux*) + case $cc_basename in + tcc*) + # Fabrice Bellard et al's Tiny C Compiler + _LT_TAGVAR(ld_shlibs, $1)=yes + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' + ;; + esac + ;; + + netbsd* | netbsdelf*-gnu) + if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then + _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' # a.out + else + _LT_TAGVAR(archive_cmds, $1)='$LD -shared -o $lib $libobjs $deplibs $linker_flags' # ELF + fi + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + newsos6) + _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath $wl$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + *nto* | *qnx*) + ;; + + openbsd* | bitrig*) + if test -f /usr/libexec/ld.so; then + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_TAGVAR(hardcode_direct_absolute, $1)=yes + if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`"; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags $wl-retain-symbols-file,$export_symbols' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath,$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl-E' + else + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath,$libdir' + fi + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + + os2*) + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_minus_L, $1)=yes + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + shrext_cmds=.dll + _LT_TAGVAR(archive_cmds, $1)='$ECHO "LIBRARY ${soname%$shared_ext} INITINSTANCE TERMINSTANCE" > $output_objdir/$libname.def~ + $ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~ + $ECHO "DATA MULTIPLE NONSHARED" >> $output_objdir/$libname.def~ + $ECHO EXPORTS >> $output_objdir/$libname.def~ + emxexp $libobjs | $SED /"_DLL_InitTerm"/d >> $output_objdir/$libname.def~ + $CC -Zdll -Zcrtdll -o $output_objdir/$soname $libobjs $deplibs $compiler_flags $output_objdir/$libname.def~ + emximp -o $lib $output_objdir/$libname.def' + _LT_TAGVAR(archive_expsym_cmds, $1)='$ECHO "LIBRARY ${soname%$shared_ext} INITINSTANCE TERMINSTANCE" > $output_objdir/$libname.def~ + $ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~ + $ECHO "DATA MULTIPLE NONSHARED" >> $output_objdir/$libname.def~ + $ECHO EXPORTS >> $output_objdir/$libname.def~ + prefix_cmds="$SED"~ + if test EXPORTS = "`$SED 1q $export_symbols`"; then + prefix_cmds="$prefix_cmds -e 1d"; + fi~ + prefix_cmds="$prefix_cmds -e \"s/^\(.*\)$/_\1/g\""~ + cat $export_symbols | $prefix_cmds >> $output_objdir/$libname.def~ + $CC -Zdll -Zcrtdll -o $output_objdir/$soname $libobjs $deplibs $compiler_flags $output_objdir/$libname.def~ + emximp -o $lib $output_objdir/$libname.def' + _LT_TAGVAR(old_archive_From_new_cmds, $1)='emximp -o $output_objdir/${libname}_dll.a $output_objdir/$libname.def' + _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes + ;; + + osf3*) + if test yes = "$GCC"; then + _LT_TAGVAR(allow_undefined_flag, $1)=' $wl-expect_unresolved $wl\*' + _LT_TAGVAR(archive_cmds, $1)='$CC -shared$allow_undefined_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations -o $lib' + else + _LT_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*' + _LT_TAGVAR(archive_cmds, $1)='$CC -shared$allow_undefined_flag $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib' + fi + _LT_TAGVAR(archive_cmds_need_lc, $1)='no' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath $wl$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + ;; + + osf4* | osf5*) # as osf3* with the addition of -msym flag + if test yes = "$GCC"; then + _LT_TAGVAR(allow_undefined_flag, $1)=' $wl-expect_unresolved $wl\*' + _LT_TAGVAR(archive_cmds, $1)='$CC -shared$allow_undefined_flag $pic_flag $libobjs $deplibs $compiler_flags $wl-msym $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations -o $lib' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath $wl$libdir' + else + _LT_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*' + _LT_TAGVAR(archive_cmds, $1)='$CC -shared$allow_undefined_flag $libobjs $deplibs $compiler_flags -msym -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done; printf "%s\\n" "-hidden">> $lib.exp~ + $CC -shared$allow_undefined_flag $wl-input $wl$lib.exp $compiler_flags $libobjs $deplibs -soname $soname `test -n "$verstring" && $ECHO "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib~$RM $lib.exp' + + # Both c and cxx compiler support -rpath directly + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir' + fi + _LT_TAGVAR(archive_cmds_need_lc, $1)='no' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + ;; + + solaris*) + _LT_TAGVAR(no_undefined_flag, $1)=' -z defs' + if test yes = "$GCC"; then + wlarc='$wl' + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $wl-z ${wl}text $wl-h $wl$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $CC -shared $pic_flag $wl-z ${wl}text $wl-M $wl$lib.exp $wl-h $wl$soname -o $lib $libobjs $deplibs $compiler_flags~$RM $lib.exp' + else + case `$CC -V 2>&1` in + *"Compilers 5.0"*) + wlarc='' + _LT_TAGVAR(archive_cmds, $1)='$LD -G$allow_undefined_flag -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $LD -G$allow_undefined_flag -M $lib.exp -h $soname -o $lib $libobjs $deplibs $linker_flags~$RM $lib.exp' + ;; + *) + wlarc='$wl' + _LT_TAGVAR(archive_cmds, $1)='$CC -G$allow_undefined_flag -h $soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $CC -G$allow_undefined_flag -M $lib.exp -h $soname -o $lib $libobjs $deplibs $compiler_flags~$RM $lib.exp' + ;; + esac + fi + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + case $host_os in + solaris2.[[0-5]] | solaris2.[[0-5]].*) ;; + *) + # The compiler driver will combine and reorder linker options, + # but understands '-z linker_flag'. GCC discards it without '$wl', + # but is careful enough not to reorder. + # Supported since Solaris 2.6 (maybe 2.5.1?) + if test yes = "$GCC"; then + _LT_TAGVAR(whole_archive_flag_spec, $1)='$wl-z ${wl}allextract$convenience $wl-z ${wl}defaultextract' + else + _LT_TAGVAR(whole_archive_flag_spec, $1)='-z allextract$convenience -z defaultextract' + fi + ;; + esac + _LT_TAGVAR(link_all_deplibs, $1)=yes + ;; + + sunos4*) + if test sequent = "$host_vendor"; then + # Use $CC to link under sequent, because it throws in some extra .o + # files that make .init and .fini sections work. + _LT_TAGVAR(archive_cmds, $1)='$CC -G $wl-h $soname -o $lib $libobjs $deplibs $compiler_flags' + else + _LT_TAGVAR(archive_cmds, $1)='$LD -assert pure-text -Bstatic -o $lib $libobjs $deplibs $linker_flags' + fi + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_minus_L, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + sysv4) + case $host_vendor in + sni) + _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_direct, $1)=yes # is this really true??? + ;; + siemens) + ## LD is ld it makes a PLAMLIB + ## CC just makes a GrossModule. + _LT_TAGVAR(archive_cmds, $1)='$LD -G -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(reload_cmds, $1)='$CC -r -o $output$reload_objs' + _LT_TAGVAR(hardcode_direct, $1)=no + ;; + motorola) + _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_direct, $1)=no #Motorola manual says yes, but my tests say they lie + ;; + esac + runpath_var='LD_RUN_PATH' + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + sysv4.3*) + _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_TAGVAR(export_dynamic_flag_spec, $1)='-Bexport' + ;; + + sysv4*MP*) + if test -d /usr/nec; then + _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + runpath_var=LD_RUN_PATH + hardcode_runpath_var=yes + _LT_TAGVAR(ld_shlibs, $1)=yes + fi + ;; + + sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[[01]].[[10]]* | unixware7* | sco3.2v5.0.[[024]]*) + _LT_TAGVAR(no_undefined_flag, $1)='$wl-z,text' + _LT_TAGVAR(archive_cmds_need_lc, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + runpath_var='LD_RUN_PATH' + + if test yes = "$GCC"; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + else + _LT_TAGVAR(archive_cmds, $1)='$CC -G $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + fi + ;; + + sysv5* | sco3.2v5* | sco5v6*) + # Note: We CANNOT use -z defs as we might desire, because we do not + # link with -lc, and that would cause any symbols used from libc to + # always be unresolved, which means just about no library would + # ever link correctly. If we're not using GNU ld we use -z text + # though, which does catch some bad symbols but isn't as heavy-handed + # as -z defs. + _LT_TAGVAR(no_undefined_flag, $1)='$wl-z,text' + _LT_TAGVAR(allow_undefined_flag, $1)='$wl-z,nodefs' + _LT_TAGVAR(archive_cmds_need_lc, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-R,$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=':' + _LT_TAGVAR(link_all_deplibs, $1)=yes + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl-Bexport' + runpath_var='LD_RUN_PATH' + + if test yes = "$GCC"; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + else + _LT_TAGVAR(archive_cmds, $1)='$CC -G $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + fi + ;; + + uts4*) + _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + *) + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + esac + + if test sni = "$host_vendor"; then + case $host in + sysv4 | sysv4.2uw2* | sysv4.3* | sysv5*) + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl-Blargedynsym' + ;; + esac + fi + fi +]) +AC_MSG_RESULT([$_LT_TAGVAR(ld_shlibs, $1)]) +test no = "$_LT_TAGVAR(ld_shlibs, $1)" && can_build_shared=no + +_LT_TAGVAR(with_gnu_ld, $1)=$with_gnu_ld + +_LT_DECL([], [libext], [0], [Old archive suffix (normally "a")])dnl +_LT_DECL([], [shrext_cmds], [1], [Shared library suffix (normally ".so")])dnl +_LT_DECL([], [extract_expsyms_cmds], [2], + [The commands to extract the exported symbol list from a shared archive]) + +# +# Do we need to explicitly link libc? +# +case "x$_LT_TAGVAR(archive_cmds_need_lc, $1)" in +x|xyes) + # Assume -lc should be added + _LT_TAGVAR(archive_cmds_need_lc, $1)=yes + + if test yes,yes = "$GCC,$enable_shared"; then + case $_LT_TAGVAR(archive_cmds, $1) in + *'~'*) + # FIXME: we may have to deal with multi-command sequences. + ;; + '$CC '*) + # Test whether the compiler implicitly links with -lc since on some + # systems, -lgcc has to come before -lc. If gcc already passes -lc + # to ld, don't add -lc before -lgcc. + AC_CACHE_CHECK([whether -lc should be explicitly linked in], + [lt_cv_]_LT_TAGVAR(archive_cmds_need_lc, $1), + [$RM conftest* + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + + if AC_TRY_EVAL(ac_compile) 2>conftest.err; then + soname=conftest + lib=conftest + libobjs=conftest.$ac_objext + deplibs= + wl=$_LT_TAGVAR(lt_prog_compiler_wl, $1) + pic_flag=$_LT_TAGVAR(lt_prog_compiler_pic, $1) + compiler_flags=-v + linker_flags=-v + verstring= + output_objdir=. + libname=conftest + lt_save_allow_undefined_flag=$_LT_TAGVAR(allow_undefined_flag, $1) + _LT_TAGVAR(allow_undefined_flag, $1)= + if AC_TRY_EVAL(_LT_TAGVAR(archive_cmds, $1) 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1) + then + lt_cv_[]_LT_TAGVAR(archive_cmds_need_lc, $1)=no + else + lt_cv_[]_LT_TAGVAR(archive_cmds_need_lc, $1)=yes + fi + _LT_TAGVAR(allow_undefined_flag, $1)=$lt_save_allow_undefined_flag + else + cat conftest.err 1>&5 + fi + $RM conftest* + ]) + _LT_TAGVAR(archive_cmds_need_lc, $1)=$lt_cv_[]_LT_TAGVAR(archive_cmds_need_lc, $1) + ;; + esac + fi + ;; +esac + +_LT_TAGDECL([build_libtool_need_lc], [archive_cmds_need_lc], [0], + [Whether or not to add -lc for building shared libraries]) +_LT_TAGDECL([allow_libtool_libs_with_static_runtimes], + [enable_shared_with_static_runtimes], [0], + [Whether or not to disallow shared libs when runtime libs are static]) +_LT_TAGDECL([], [export_dynamic_flag_spec], [1], + [Compiler flag to allow reflexive dlopens]) +_LT_TAGDECL([], [whole_archive_flag_spec], [1], + [Compiler flag to generate shared objects directly from archives]) +_LT_TAGDECL([], [compiler_needs_object], [1], + [Whether the compiler copes with passing no objects directly]) +_LT_TAGDECL([], [old_archive_from_new_cmds], [2], + [Create an old-style archive from a shared archive]) +_LT_TAGDECL([], [old_archive_from_expsyms_cmds], [2], + [Create a temporary old-style archive to link instead of a shared archive]) +_LT_TAGDECL([], [archive_cmds], [2], [Commands used to build a shared archive]) +_LT_TAGDECL([], [archive_expsym_cmds], [2]) +_LT_TAGDECL([], [module_cmds], [2], + [Commands used to build a loadable module if different from building + a shared archive.]) +_LT_TAGDECL([], [module_expsym_cmds], [2]) +_LT_TAGDECL([], [with_gnu_ld], [1], + [Whether we are building with GNU ld or not]) +_LT_TAGDECL([], [allow_undefined_flag], [1], + [Flag that allows shared libraries with undefined symbols to be built]) +_LT_TAGDECL([], [no_undefined_flag], [1], + [Flag that enforces no undefined symbols]) +_LT_TAGDECL([], [hardcode_libdir_flag_spec], [1], + [Flag to hardcode $libdir into a binary during linking. + This must work even if $libdir does not exist]) +_LT_TAGDECL([], [hardcode_libdir_separator], [1], + [Whether we need a single "-rpath" flag with a separated argument]) +_LT_TAGDECL([], [hardcode_direct], [0], + [Set to "yes" if using DIR/libNAME$shared_ext during linking hardcodes + DIR into the resulting binary]) +_LT_TAGDECL([], [hardcode_direct_absolute], [0], + [Set to "yes" if using DIR/libNAME$shared_ext during linking hardcodes + DIR into the resulting binary and the resulting library dependency is + "absolute", i.e impossible to change by setting $shlibpath_var if the + library is relocated]) +_LT_TAGDECL([], [hardcode_minus_L], [0], + [Set to "yes" if using the -LDIR flag during linking hardcodes DIR + into the resulting binary]) +_LT_TAGDECL([], [hardcode_shlibpath_var], [0], + [Set to "yes" if using SHLIBPATH_VAR=DIR during linking hardcodes DIR + into the resulting binary]) +_LT_TAGDECL([], [hardcode_automatic], [0], + [Set to "yes" if building a shared library automatically hardcodes DIR + into the library and all subsequent libraries and executables linked + against it]) +_LT_TAGDECL([], [inherit_rpath], [0], + [Set to yes if linker adds runtime paths of dependent libraries + to runtime path list]) +_LT_TAGDECL([], [link_all_deplibs], [0], + [Whether libtool must link a program against all its dependency libraries]) +_LT_TAGDECL([], [always_export_symbols], [0], + [Set to "yes" if exported symbols are required]) +_LT_TAGDECL([], [export_symbols_cmds], [2], + [The commands to list exported symbols]) +_LT_TAGDECL([], [exclude_expsyms], [1], + [Symbols that should not be listed in the preloaded symbols]) +_LT_TAGDECL([], [include_expsyms], [1], + [Symbols that must always be exported]) +_LT_TAGDECL([], [prelink_cmds], [2], + [Commands necessary for linking programs (against libraries) with templates]) +_LT_TAGDECL([], [postlink_cmds], [2], + [Commands necessary for finishing linking programs]) +_LT_TAGDECL([], [file_list_spec], [1], + [Specify filename containing input files]) +dnl FIXME: Not yet implemented +dnl _LT_TAGDECL([], [thread_safe_flag_spec], [1], +dnl [Compiler flag to generate thread safe objects]) +])# _LT_LINKER_SHLIBS + + +# _LT_LANG_C_CONFIG([TAG]) +# ------------------------ +# Ensure that the configuration variables for a C compiler are suitably +# defined. These variables are subsequently used by _LT_CONFIG to write +# the compiler configuration to 'libtool'. +m4_defun([_LT_LANG_C_CONFIG], +[m4_require([_LT_DECL_EGREP])dnl +lt_save_CC=$CC +AC_LANG_PUSH(C) + +# Source file extension for C test sources. +ac_ext=c + +# Object file extension for compiled C test sources. +objext=o +_LT_TAGVAR(objext, $1)=$objext + +# Code to be used in simple compile tests +lt_simple_compile_test_code="int some_variable = 0;" + +# Code to be used in simple link tests +lt_simple_link_test_code='int main(){return(0);}' + +_LT_TAG_COMPILER +# Save the default compiler, since it gets overwritten when the other +# tags are being tested, and _LT_TAGVAR(compiler, []) is a NOP. +compiler_DEFAULT=$CC + +# save warnings/boilerplate of simple test code +_LT_COMPILER_BOILERPLATE +_LT_LINKER_BOILERPLATE + +## CAVEAT EMPTOR: +## There is no encapsulation within the following macros, do not change +## the running order or otherwise move them around unless you know exactly +## what you are doing... +if test -n "$compiler"; then + _LT_COMPILER_NO_RTTI($1) + _LT_COMPILER_PIC($1) + _LT_COMPILER_C_O($1) + _LT_COMPILER_FILE_LOCKS($1) + _LT_LINKER_SHLIBS($1) + _LT_SYS_DYNAMIC_LINKER($1) + _LT_LINKER_HARDCODE_LIBPATH($1) + LT_SYS_DLOPEN_SELF + _LT_CMD_STRIPLIB + + # Report what library types will actually be built + AC_MSG_CHECKING([if libtool supports shared libraries]) + AC_MSG_RESULT([$can_build_shared]) + + AC_MSG_CHECKING([whether to build shared libraries]) + test no = "$can_build_shared" && enable_shared=no + + # On AIX, shared libraries and static libraries use the same namespace, and + # are all built from PIC. + case $host_os in + aix3*) + test yes = "$enable_shared" && enable_static=no + if test -n "$RANLIB"; then + archive_cmds="$archive_cmds~\$RANLIB \$lib" + postinstall_cmds='$RANLIB $lib' + fi + ;; + + aix[[4-9]]*) + if test ia64 != "$host_cpu"; then + case $enable_shared,$with_aix_soname,$aix_use_runtimelinking in + yes,aix,yes) ;; # shared object as lib.so file only + yes,svr4,*) ;; # shared object as lib.so archive member only + yes,*) enable_static=no ;; # shared object in lib.a archive as well + esac + fi + ;; + esac + AC_MSG_RESULT([$enable_shared]) + + AC_MSG_CHECKING([whether to build static libraries]) + # Make sure either enable_shared or enable_static is yes. + test yes = "$enable_shared" || enable_static=yes + AC_MSG_RESULT([$enable_static]) + + _LT_CONFIG($1) +fi +AC_LANG_POP +CC=$lt_save_CC +])# _LT_LANG_C_CONFIG + + +# _LT_LANG_CXX_CONFIG([TAG]) +# -------------------------- +# Ensure that the configuration variables for a C++ compiler are suitably +# defined. These variables are subsequently used by _LT_CONFIG to write +# the compiler configuration to 'libtool'. +m4_defun([_LT_LANG_CXX_CONFIG], +[m4_require([_LT_FILEUTILS_DEFAULTS])dnl +m4_require([_LT_DECL_EGREP])dnl +m4_require([_LT_PATH_MANIFEST_TOOL])dnl +if test -n "$CXX" && ( test no != "$CXX" && + ( (test g++ = "$CXX" && `g++ -v >/dev/null 2>&1` ) || + (test g++ != "$CXX"))); then + AC_PROG_CXXCPP +else + _lt_caught_CXX_error=yes +fi + +AC_LANG_PUSH(C++) +_LT_TAGVAR(archive_cmds_need_lc, $1)=no +_LT_TAGVAR(allow_undefined_flag, $1)= +_LT_TAGVAR(always_export_symbols, $1)=no +_LT_TAGVAR(archive_expsym_cmds, $1)= +_LT_TAGVAR(compiler_needs_object, $1)=no +_LT_TAGVAR(export_dynamic_flag_spec, $1)= +_LT_TAGVAR(hardcode_direct, $1)=no +_LT_TAGVAR(hardcode_direct_absolute, $1)=no +_LT_TAGVAR(hardcode_libdir_flag_spec, $1)= +_LT_TAGVAR(hardcode_libdir_separator, $1)= +_LT_TAGVAR(hardcode_minus_L, $1)=no +_LT_TAGVAR(hardcode_shlibpath_var, $1)=unsupported +_LT_TAGVAR(hardcode_automatic, $1)=no +_LT_TAGVAR(inherit_rpath, $1)=no +_LT_TAGVAR(module_cmds, $1)= +_LT_TAGVAR(module_expsym_cmds, $1)= +_LT_TAGVAR(link_all_deplibs, $1)=unknown +_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds +_LT_TAGVAR(reload_flag, $1)=$reload_flag +_LT_TAGVAR(reload_cmds, $1)=$reload_cmds +_LT_TAGVAR(no_undefined_flag, $1)= +_LT_TAGVAR(whole_archive_flag_spec, $1)= +_LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no + +# Source file extension for C++ test sources. +ac_ext=cpp + +# Object file extension for compiled C++ test sources. +objext=o +_LT_TAGVAR(objext, $1)=$objext + +# No sense in running all these tests if we already determined that +# the CXX compiler isn't working. Some variables (like enable_shared) +# are currently assumed to apply to all compilers on this platform, +# and will be corrupted by setting them based on a non-working compiler. +if test yes != "$_lt_caught_CXX_error"; then + # Code to be used in simple compile tests + lt_simple_compile_test_code="int some_variable = 0;" + + # Code to be used in simple link tests + lt_simple_link_test_code='int main(int, char *[[]]) { return(0); }' + + # ltmain only uses $CC for tagged configurations so make sure $CC is set. + _LT_TAG_COMPILER + + # save warnings/boilerplate of simple test code + _LT_COMPILER_BOILERPLATE + _LT_LINKER_BOILERPLATE + + # Allow CC to be a program name with arguments. + lt_save_CC=$CC + lt_save_CFLAGS=$CFLAGS + lt_save_LD=$LD + lt_save_GCC=$GCC + GCC=$GXX + lt_save_with_gnu_ld=$with_gnu_ld + lt_save_path_LD=$lt_cv_path_LD + if test -n "${lt_cv_prog_gnu_ldcxx+set}"; then + lt_cv_prog_gnu_ld=$lt_cv_prog_gnu_ldcxx + else + $as_unset lt_cv_prog_gnu_ld + fi + if test -n "${lt_cv_path_LDCXX+set}"; then + lt_cv_path_LD=$lt_cv_path_LDCXX + else + $as_unset lt_cv_path_LD + fi + test -z "${LDCXX+set}" || LD=$LDCXX + CC=${CXX-"c++"} + CFLAGS=$CXXFLAGS + compiler=$CC + _LT_TAGVAR(compiler, $1)=$CC + _LT_CC_BASENAME([$compiler]) + + if test -n "$compiler"; then + # We don't want -fno-exception when compiling C++ code, so set the + # no_builtin_flag separately + if test yes = "$GXX"; then + _LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=' -fno-builtin' + else + _LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)= + fi + + if test yes = "$GXX"; then + # Set up default GNU C++ configuration + + LT_PATH_LD + + # Check if GNU C++ uses GNU ld as the underlying linker, since the + # archiving commands below assume that GNU ld is being used. + if test yes = "$with_gnu_ld"; then + _LT_TAGVAR(archive_cmds, $1)='$CC $pic_flag -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC $pic_flag -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' + + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath $wl$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl--export-dynamic' + + # If archive_cmds runs LD, not CC, wlarc should be empty + # XXX I think wlarc can be eliminated in ltcf-cxx, but I need to + # investigate it a little bit more. (MM) + wlarc='$wl' + + # ancient GNU ld didn't support --whole-archive et. al. + if eval "`$CC -print-prog-name=ld` --help 2>&1" | + $GREP 'no-whole-archive' > /dev/null; then + _LT_TAGVAR(whole_archive_flag_spec, $1)=$wlarc'--whole-archive$convenience '$wlarc'--no-whole-archive' + else + _LT_TAGVAR(whole_archive_flag_spec, $1)= + fi + else + with_gnu_ld=no + wlarc= + + # A generic and very simple default shared library creation + # command for GNU C++ for the case where it uses the native + # linker, instead of GNU ld. If possible, this setting should + # overridden to take advantage of the native linker features on + # the platform it is being used on. + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $lib' + fi + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP " \-L"' + + else + GXX=no + with_gnu_ld=no + wlarc= + fi + + # PORTME: fill in a description of your system's C++ link characteristics + AC_MSG_CHECKING([whether the $compiler linker ($LD) supports shared libraries]) + _LT_TAGVAR(ld_shlibs, $1)=yes + case $host_os in + aix3*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + aix[[4-9]]*) + if test ia64 = "$host_cpu"; then + # On IA64, the linker does run time linking by default, so we don't + # have to do anything special. + aix_use_runtimelinking=no + exp_sym_flag='-Bexport' + no_entry_flag= + else + aix_use_runtimelinking=no + + # Test if we are trying to use run time linking or normal + # AIX style linking. If -brtl is somewhere in LDFLAGS, we + # have runtime linking enabled, and use it for executables. + # For shared libraries, we enable/disable runtime linking + # depending on the kind of the shared library created - + # when "with_aix_soname,aix_use_runtimelinking" is: + # "aix,no" lib.a(lib.so.V) shared, rtl:no, for executables + # "aix,yes" lib.so shared, rtl:yes, for executables + # lib.a static archive + # "both,no" lib.so.V(shr.o) shared, rtl:yes + # lib.a(lib.so.V) shared, rtl:no, for executables + # "both,yes" lib.so.V(shr.o) shared, rtl:yes, for executables + # lib.a(lib.so.V) shared, rtl:no + # "svr4,*" lib.so.V(shr.o) shared, rtl:yes, for executables + # lib.a static archive + case $host_os in aix4.[[23]]|aix4.[[23]].*|aix[[5-9]]*) + for ld_flag in $LDFLAGS; do + case $ld_flag in + *-brtl*) + aix_use_runtimelinking=yes + break + ;; + esac + done + if test svr4,no = "$with_aix_soname,$aix_use_runtimelinking"; then + # With aix-soname=svr4, we create the lib.so.V shared archives only, + # so we don't have lib.a shared libs to link our executables. + # We have to force runtime linking in this case. + aix_use_runtimelinking=yes + LDFLAGS="$LDFLAGS -Wl,-brtl" + fi + ;; + esac + + exp_sym_flag='-bexport' + no_entry_flag='-bnoentry' + fi + + # When large executables or shared objects are built, AIX ld can + # have problems creating the table of contents. If linking a library + # or program results in "error TOC overflow" add -mminimal-toc to + # CXXFLAGS/CFLAGS for g++/gcc. In the cases where that is not + # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS. + + _LT_TAGVAR(archive_cmds, $1)='' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_direct_absolute, $1)=yes + _LT_TAGVAR(hardcode_libdir_separator, $1)=':' + _LT_TAGVAR(link_all_deplibs, $1)=yes + _LT_TAGVAR(file_list_spec, $1)='$wl-f,' + case $with_aix_soname,$aix_use_runtimelinking in + aix,*) ;; # no import file + svr4,* | *,yes) # use import file + # The Import File defines what to hardcode. + _LT_TAGVAR(hardcode_direct, $1)=no + _LT_TAGVAR(hardcode_direct_absolute, $1)=no + ;; + esac + + if test yes = "$GXX"; then + case $host_os in aix4.[[012]]|aix4.[[012]].*) + # We only want to do this on AIX 4.2 and lower, the check + # below for broken collect2 doesn't work under 4.3+ + collect2name=`$CC -print-prog-name=collect2` + if test -f "$collect2name" && + strings "$collect2name" | $GREP resolve_lib_name >/dev/null + then + # We have reworked collect2 + : + else + # We have old collect2 + _LT_TAGVAR(hardcode_direct, $1)=unsupported + # It fails to find uninstalled libraries when the uninstalled + # path is not listed in the libpath. Setting hardcode_minus_L + # to unsupported forces relinking + _LT_TAGVAR(hardcode_minus_L, $1)=yes + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)= + fi + esac + shared_flag='-shared' + if test yes = "$aix_use_runtimelinking"; then + shared_flag=$shared_flag' $wl-G' + fi + # Need to ensure runtime linking is disabled for the traditional + # shared library, or the linker may eventually find shared libraries + # /with/ Import File - we do not want to mix them. + shared_flag_aix='-shared' + shared_flag_svr4='-shared $wl-G' + else + # not using gcc + if test ia64 = "$host_cpu"; then + # VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release + # chokes on -Wl,-G. The following line is correct: + shared_flag='-G' + else + if test yes = "$aix_use_runtimelinking"; then + shared_flag='$wl-G' + else + shared_flag='$wl-bM:SRE' + fi + shared_flag_aix='$wl-bM:SRE' + shared_flag_svr4='$wl-G' + fi + fi + + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl-bexpall' + # It seems that -bexpall does not export symbols beginning with + # underscore (_), so it is better to generate a list of symbols to + # export. + _LT_TAGVAR(always_export_symbols, $1)=yes + if test aix,yes = "$with_aix_soname,$aix_use_runtimelinking"; then + # Warning - without using the other runtime loading flags (-brtl), + # -berok will link without error, but may produce a broken library. + # The "-G" linker flag allows undefined symbols. + _LT_TAGVAR(no_undefined_flag, $1)='-bernotok' + # Determine the default libpath from the value encoded in an empty + # executable. + _LT_SYS_MODULE_PATH_AIX([$1]) + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-blibpath:$libdir:'"$aix_libpath" + + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -o $output_objdir/$soname $libobjs $deplibs $wl'$no_entry_flag' $compiler_flags `if test -n "$allow_undefined_flag"; then func_echo_all "$wl$allow_undefined_flag"; else :; fi` $wl'$exp_sym_flag:\$export_symbols' '$shared_flag + else + if test ia64 = "$host_cpu"; then + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-R $libdir:/usr/lib:/lib' + _LT_TAGVAR(allow_undefined_flag, $1)="-z nodefs" + _LT_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\$wl$no_entry_flag"' $compiler_flags $wl$allow_undefined_flag '"\$wl$exp_sym_flag:\$export_symbols" + else + # Determine the default libpath from the value encoded in an + # empty executable. + _LT_SYS_MODULE_PATH_AIX([$1]) + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-blibpath:$libdir:'"$aix_libpath" + # Warning - without using the other run time loading flags, + # -berok will link without error, but may produce a broken library. + _LT_TAGVAR(no_undefined_flag, $1)=' $wl-bernotok' + _LT_TAGVAR(allow_undefined_flag, $1)=' $wl-berok' + if test yes = "$with_gnu_ld"; then + # We only use this code for GNU lds that support --whole-archive. + _LT_TAGVAR(whole_archive_flag_spec, $1)='$wl--whole-archive$convenience $wl--no-whole-archive' + else + # Exported symbols can be pulled into shared objects from archives + _LT_TAGVAR(whole_archive_flag_spec, $1)='$convenience' + fi + _LT_TAGVAR(archive_cmds_need_lc, $1)=yes + _LT_TAGVAR(archive_expsym_cmds, $1)='$RM -r $output_objdir/$realname.d~$MKDIR $output_objdir/$realname.d' + # -brtl affects multiple linker settings, -berok does not and is overridden later + compiler_flags_filtered='`func_echo_all "$compiler_flags " | $SED -e "s%-brtl\\([[, ]]\\)%-berok\\1%g"`' + if test svr4 != "$with_aix_soname"; then + # This is similar to how AIX traditionally builds its shared + # libraries. Need -bnortl late, we may have -brtl in LDFLAGS. + _LT_TAGVAR(archive_expsym_cmds, $1)="$_LT_TAGVAR(archive_expsym_cmds, $1)"'~$CC '$shared_flag_aix' -o $output_objdir/$realname.d/$soname $libobjs $deplibs $wl-bnoentry '$compiler_flags_filtered'$wl-bE:$export_symbols$allow_undefined_flag~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$realname.d/$soname' + fi + if test aix != "$with_aix_soname"; then + _LT_TAGVAR(archive_expsym_cmds, $1)="$_LT_TAGVAR(archive_expsym_cmds, $1)"'~$CC '$shared_flag_svr4' -o $output_objdir/$realname.d/$shared_archive_member_spec.o $libobjs $deplibs $wl-bnoentry '$compiler_flags_filtered'$wl-bE:$export_symbols$allow_undefined_flag~$STRIP -e $output_objdir/$realname.d/$shared_archive_member_spec.o~( func_echo_all "#! $soname($shared_archive_member_spec.o)"; if test shr_64 = "$shared_archive_member_spec"; then func_echo_all "# 64"; else func_echo_all "# 32"; fi; cat $export_symbols ) > $output_objdir/$realname.d/$shared_archive_member_spec.imp~$AR $AR_FLAGS $output_objdir/$soname $output_objdir/$realname.d/$shared_archive_member_spec.o $output_objdir/$realname.d/$shared_archive_member_spec.imp' + else + # used by -dlpreopen to get the symbols + _LT_TAGVAR(archive_expsym_cmds, $1)="$_LT_TAGVAR(archive_expsym_cmds, $1)"'~$MV $output_objdir/$realname.d/$soname $output_objdir' + fi + _LT_TAGVAR(archive_expsym_cmds, $1)="$_LT_TAGVAR(archive_expsym_cmds, $1)"'~$RM -r $output_objdir/$realname.d' + fi + fi + ;; + + beos*) + if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + # Joseph Beckenbach says some releases of gcc + # support --undefined. This deserves some investigation. FIXME + _LT_TAGVAR(archive_cmds, $1)='$CC -nostart $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + + chorus*) + case $cc_basename in + *) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + esac + ;; + + cygwin* | mingw* | pw32* | cegcc*) + case $GXX,$cc_basename in + ,cl* | no,cl*) + # Native MSVC + # hardcode_libdir_flag_spec is actually meaningless, as there is + # no search path for DLLs. + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)=' ' + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + _LT_TAGVAR(always_export_symbols, $1)=yes + _LT_TAGVAR(file_list_spec, $1)='@' + # Tell ltmain to make .lib files, not .a files. + libext=lib + # Tell ltmain to make .dll files, not .so files. + shrext_cmds=.dll + # FIXME: Setting linknames here is a bad hack. + _LT_TAGVAR(archive_cmds, $1)='$CC -o $output_objdir/$soname $libobjs $compiler_flags $deplibs -Wl,-DLL,-IMPLIB:"$tool_output_objdir$libname.dll.lib"~linknames=' + _LT_TAGVAR(archive_expsym_cmds, $1)='if _LT_DLL_DEF_P([$export_symbols]); then + cp "$export_symbols" "$output_objdir/$soname.def"; + echo "$tool_output_objdir$soname.def" > "$output_objdir/$soname.exp"; + else + $SED -e '\''s/^/-link -EXPORT:/'\'' < $export_symbols > $output_objdir/$soname.exp; + fi~ + $CC -o $tool_output_objdir$soname $libobjs $compiler_flags $deplibs "@$tool_output_objdir$soname.exp" -Wl,-DLL,-IMPLIB:"$tool_output_objdir$libname.dll.lib"~ + linknames=' + # The linker will not automatically build a static lib if we build a DLL. + # _LT_TAGVAR(old_archive_from_new_cmds, $1)='true' + _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes + # Don't use ranlib + _LT_TAGVAR(old_postinstall_cmds, $1)='chmod 644 $oldlib' + _LT_TAGVAR(postlink_cmds, $1)='lt_outputfile="@OUTPUT@"~ + lt_tool_outputfile="@TOOL_OUTPUT@"~ + case $lt_outputfile in + *.exe|*.EXE) ;; + *) + lt_outputfile=$lt_outputfile.exe + lt_tool_outputfile=$lt_tool_outputfile.exe + ;; + esac~ + func_to_tool_file "$lt_outputfile"~ + if test : != "$MANIFEST_TOOL" && test -f "$lt_outputfile.manifest"; then + $MANIFEST_TOOL -manifest "$lt_tool_outputfile.manifest" -outputresource:"$lt_tool_outputfile" || exit 1; + $RM "$lt_outputfile.manifest"; + fi' + ;; + *) + # g++ + # _LT_TAGVAR(hardcode_libdir_flag_spec, $1) is actually meaningless, + # as there is no search path for DLLs. + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl--export-all-symbols' + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + _LT_TAGVAR(always_export_symbols, $1)=no + _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes + + if $LD --help 2>&1 | $GREP 'auto-import' > /dev/null; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $output_objdir/$soname $wl--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' + # If the export-symbols file already is a .def file, use it as + # is; otherwise, prepend EXPORTS... + _LT_TAGVAR(archive_expsym_cmds, $1)='if _LT_DLL_DEF_P([$export_symbols]); then + cp $export_symbols $output_objdir/$soname.def; + else + echo EXPORTS > $output_objdir/$soname.def; + cat $export_symbols >> $output_objdir/$soname.def; + fi~ + $CC -shared -nostdlib $output_objdir/$soname.def $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $output_objdir/$soname $wl--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + esac + ;; + darwin* | rhapsody*) + _LT_DARWIN_LINKER_FEATURES($1) + ;; + + os2*) + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_minus_L, $1)=yes + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + shrext_cmds=.dll + _LT_TAGVAR(archive_cmds, $1)='$ECHO "LIBRARY ${soname%$shared_ext} INITINSTANCE TERMINSTANCE" > $output_objdir/$libname.def~ + $ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~ + $ECHO "DATA MULTIPLE NONSHARED" >> $output_objdir/$libname.def~ + $ECHO EXPORTS >> $output_objdir/$libname.def~ + emxexp $libobjs | $SED /"_DLL_InitTerm"/d >> $output_objdir/$libname.def~ + $CC -Zdll -Zcrtdll -o $output_objdir/$soname $libobjs $deplibs $compiler_flags $output_objdir/$libname.def~ + emximp -o $lib $output_objdir/$libname.def' + _LT_TAGVAR(archive_expsym_cmds, $1)='$ECHO "LIBRARY ${soname%$shared_ext} INITINSTANCE TERMINSTANCE" > $output_objdir/$libname.def~ + $ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~ + $ECHO "DATA MULTIPLE NONSHARED" >> $output_objdir/$libname.def~ + $ECHO EXPORTS >> $output_objdir/$libname.def~ + prefix_cmds="$SED"~ + if test EXPORTS = "`$SED 1q $export_symbols`"; then + prefix_cmds="$prefix_cmds -e 1d"; + fi~ + prefix_cmds="$prefix_cmds -e \"s/^\(.*\)$/_\1/g\""~ + cat $export_symbols | $prefix_cmds >> $output_objdir/$libname.def~ + $CC -Zdll -Zcrtdll -o $output_objdir/$soname $libobjs $deplibs $compiler_flags $output_objdir/$libname.def~ + emximp -o $lib $output_objdir/$libname.def' + _LT_TAGVAR(old_archive_From_new_cmds, $1)='emximp -o $output_objdir/${libname}_dll.a $output_objdir/$libname.def' + _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes + ;; + + dgux*) + case $cc_basename in + ec++*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + ghcx*) + # Green Hills C++ Compiler + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + *) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + esac + ;; + + freebsd2.*) + # C++ shared libraries reported to be fairly broken before + # switch to ELF + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + + freebsd-elf*) + _LT_TAGVAR(archive_cmds_need_lc, $1)=no + ;; + + freebsd* | dragonfly*) + # FreeBSD 3 and later use GNU C++ and GNU ld with standard ELF + # conventions + _LT_TAGVAR(ld_shlibs, $1)=yes + ;; + + haiku*) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + _LT_TAGVAR(link_all_deplibs, $1)=yes + ;; + + hpux9*) + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl+b $wl$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl-E' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_minus_L, $1)=yes # Not in the search PATH, + # but as the default + # location of the library. + + case $cc_basename in + CC*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + aCC*) + _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$CC -b $wl+b $wl$install_libdir -o $output_objdir/$soname $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~test "x$output_objdir/$soname" = "x$lib" || mv $output_objdir/$soname $lib' + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $EGREP " \-L"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' + ;; + *) + if test yes = "$GXX"; then + _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$CC -shared -nostdlib $pic_flag $wl+b $wl$install_libdir -o $output_objdir/$soname $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~test "x$output_objdir/$soname" = "x$lib" || mv $output_objdir/$soname $lib' + else + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + esac + ;; + + hpux10*|hpux11*) + if test no = "$with_gnu_ld"; then + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl+b $wl$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + + case $host_cpu in + hppa*64*|ia64*) + ;; + *) + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl-E' + ;; + esac + fi + case $host_cpu in + hppa*64*|ia64*) + _LT_TAGVAR(hardcode_direct, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + *) + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_direct_absolute, $1)=yes + _LT_TAGVAR(hardcode_minus_L, $1)=yes # Not in the search PATH, + # but as the default + # location of the library. + ;; + esac + + case $cc_basename in + CC*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + aCC*) + case $host_cpu in + hppa*64*) + _LT_TAGVAR(archive_cmds, $1)='$CC -b $wl+h $wl$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + ia64*) + _LT_TAGVAR(archive_cmds, $1)='$CC -b $wl+h $wl$soname $wl+nodefaultrpath -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + *) + _LT_TAGVAR(archive_cmds, $1)='$CC -b $wl+h $wl$soname $wl+b $wl$install_libdir -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + esac + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $GREP " \-L"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' + ;; + *) + if test yes = "$GXX"; then + if test no = "$with_gnu_ld"; then + case $host_cpu in + hppa*64*) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib -fPIC $wl+h $wl$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + ia64*) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $pic_flag $wl+h $wl$soname $wl+nodefaultrpath -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + *) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $pic_flag $wl+h $wl$soname $wl+b $wl$install_libdir -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + esac + fi + else + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + esac + ;; + + interix[[3-9]]*) + _LT_TAGVAR(hardcode_direct, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath,$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl-E' + # Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc. + # Instead, shared libraries are loaded at an image base (0x10000000 by + # default) and relocated if they conflict, which is a slow very memory + # consuming and fragmenting process. To avoid this, we pick a random, + # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link + # time. Moving up from 0x10000000 also allows more sbrk(2) space. + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-h,$soname $wl--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='sed "s|^|_|" $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-h,$soname $wl--retain-symbols-file,$output_objdir/$soname.expsym $wl--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + ;; + irix5* | irix6*) + case $cc_basename in + CC*) + # SGI C++ + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -all -multigot $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib' + + # Archives containing C++ object files must be created using + # "CC -ar", where "CC" is the IRIX C++ compiler. This is + # necessary to make sure instantiated templates are included + # in the archive. + _LT_TAGVAR(old_archive_cmds, $1)='$CC -ar -WR,-u -o $oldlib $oldobjs' + ;; + *) + if test yes = "$GXX"; then + if test no = "$with_gnu_ld"; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations -o $lib' + else + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` -o $lib' + fi + fi + _LT_TAGVAR(link_all_deplibs, $1)=yes + ;; + esac + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath $wl$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + _LT_TAGVAR(inherit_rpath, $1)=yes + ;; + + linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*) + case $cc_basename in + KCC*) + # Kuck and Associates, Inc. (KAI) C++ Compiler + + # KCC will only create a shared library if the output file + # ends with ".so" (or ".sl" for HP-UX), so rename the library + # to its proper name (with version) after linking. + _LT_TAGVAR(archive_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\$tempext\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\$tempext\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib $wl-retain-symbols-file,$export_symbols; mv \$templib $lib' + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`$CC $CFLAGS -v conftest.$objext -o libconftest$shared_ext 2>&1 | $GREP "ld"`; rm -f libconftest$shared_ext; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' + + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath,$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl--export-dynamic' + + # Archives containing C++ object files must be created using + # "CC -Bstatic", where "CC" is the KAI C++ compiler. + _LT_TAGVAR(old_archive_cmds, $1)='$CC -Bstatic -o $oldlib $oldobjs' + ;; + icpc* | ecpc* ) + # Intel C++ + with_gnu_ld=yes + # version 8.0 and above of icpc choke on multiply defined symbols + # if we add $predep_objects and $postdep_objects, however 7.1 and + # earlier do not add the objects themselves. + case `$CC -V 2>&1` in + *"Version 7."*) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' + ;; + *) # Version 8.0 or newer + tmp_idyn= + case $host_cpu in + ia64*) tmp_idyn=' -i_dynamic';; + esac + _LT_TAGVAR(archive_cmds, $1)='$CC -shared'"$tmp_idyn"' $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared'"$tmp_idyn"' $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' + ;; + esac + _LT_TAGVAR(archive_cmds_need_lc, $1)=no + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath,$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl--export-dynamic' + _LT_TAGVAR(whole_archive_flag_spec, $1)='$wl--whole-archive$convenience $wl--no-whole-archive' + ;; + pgCC* | pgcpp*) + # Portland Group C++ compiler + case `$CC -V` in + *pgCC\ [[1-5]].* | *pgcpp\ [[1-5]].*) + _LT_TAGVAR(prelink_cmds, $1)='tpldir=Template.dir~ + rm -rf $tpldir~ + $CC --prelink_objects --instantiation_dir $tpldir $objs $libobjs $compile_deplibs~ + compile_command="$compile_command `find $tpldir -name \*.o | sort | $NL2SP`"' + _LT_TAGVAR(old_archive_cmds, $1)='tpldir=Template.dir~ + rm -rf $tpldir~ + $CC --prelink_objects --instantiation_dir $tpldir $oldobjs$old_deplibs~ + $AR $AR_FLAGS $oldlib$oldobjs$old_deplibs `find $tpldir -name \*.o | sort | $NL2SP`~ + $RANLIB $oldlib' + _LT_TAGVAR(archive_cmds, $1)='tpldir=Template.dir~ + rm -rf $tpldir~ + $CC --prelink_objects --instantiation_dir $tpldir $predep_objects $libobjs $deplibs $convenience $postdep_objects~ + $CC -shared $pic_flag $predep_objects $libobjs $deplibs `find $tpldir -name \*.o | sort | $NL2SP` $postdep_objects $compiler_flags $wl-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='tpldir=Template.dir~ + rm -rf $tpldir~ + $CC --prelink_objects --instantiation_dir $tpldir $predep_objects $libobjs $deplibs $convenience $postdep_objects~ + $CC -shared $pic_flag $predep_objects $libobjs $deplibs `find $tpldir -name \*.o | sort | $NL2SP` $postdep_objects $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' + ;; + *) # Version 6 and above use weak symbols + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' + ;; + esac + + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl--rpath $wl$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl--export-dynamic' + _LT_TAGVAR(whole_archive_flag_spec, $1)='$wl--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` $wl--no-whole-archive' + ;; + cxx*) + # Compaq C++ + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname -o $lib $wl-retain-symbols-file $wl$export_symbols' + + runpath_var=LD_RUN_PATH + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "ld"`; templist=`func_echo_all "$templist" | $SED "s/\(^.*ld.*\)\( .*ld .*$\)/\1/"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "X$list" | $Xsed' + ;; + xl* | mpixl* | bgxl*) + # IBM XL 8.0 on PPC, with GNU ld + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath $wl$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl--export-dynamic' + _LT_TAGVAR(archive_cmds, $1)='$CC -qmkshrobj $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + if test yes = "$supports_anon_versioning"; then + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $output_objdir/$libname.ver~ + cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ + echo "local: *; };" >> $output_objdir/$libname.ver~ + $CC -qmkshrobj $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-version-script $wl$output_objdir/$libname.ver -o $lib' + fi + ;; + *) + case `$CC -V 2>&1 | sed 5q` in + *Sun\ C*) + # Sun C++ 5.9 + _LT_TAGVAR(no_undefined_flag, $1)=' -zdefs' + _LT_TAGVAR(archive_cmds, $1)='$CC -G$allow_undefined_flag -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G$allow_undefined_flag -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-retain-symbols-file $wl$export_symbols' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_TAGVAR(whole_archive_flag_spec, $1)='$wl--whole-archive`new_convenience=; for conv in $convenience\"\"; do test -z \"$conv\" || new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` $wl--no-whole-archive' + _LT_TAGVAR(compiler_needs_object, $1)=yes + + # Not sure whether something based on + # $CC $CFLAGS -v conftest.$objext -o libconftest$shared_ext 2>&1 + # would be better. + output_verbose_link_cmd='func_echo_all' + + # Archives containing C++ object files must be created using + # "CC -xar", where "CC" is the Sun C++ compiler. This is + # necessary to make sure instantiated templates are included + # in the archive. + _LT_TAGVAR(old_archive_cmds, $1)='$CC -xar -o $oldlib $oldobjs' + ;; + esac + ;; + esac + ;; + + lynxos*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + + m88k*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + + mvs*) + case $cc_basename in + cxx*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + *) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + esac + ;; + + netbsd*) + if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then + _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $predep_objects $libobjs $deplibs $postdep_objects $linker_flags' + wlarc= + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + fi + # Workaround some broken pre-1.5 toolchains + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP conftest.$objext | $SED -e "s:-lgcc -lc -lgcc::"' + ;; + + *nto* | *qnx*) + _LT_TAGVAR(ld_shlibs, $1)=yes + ;; + + openbsd* | bitrig*) + if test -f /usr/libexec/ld.so; then + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_TAGVAR(hardcode_direct_absolute, $1)=yes + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $lib' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath,$libdir' + if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`"; then + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-retain-symbols-file,$export_symbols -o $lib' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl-E' + _LT_TAGVAR(whole_archive_flag_spec, $1)=$wlarc'--whole-archive$convenience '$wlarc'--no-whole-archive' + fi + output_verbose_link_cmd=func_echo_all + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + + osf3* | osf4* | osf5*) + case $cc_basename in + KCC*) + # Kuck and Associates, Inc. (KAI) C++ Compiler + + # KCC will only create a shared library if the output file + # ends with ".so" (or ".sl" for HP-UX), so rename the library + # to its proper name (with version) after linking. + _LT_TAGVAR(archive_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo "$lib" | $SED -e "s/\$tempext\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib' + + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath,$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + + # Archives containing C++ object files must be created using + # the KAI C++ compiler. + case $host in + osf3*) _LT_TAGVAR(old_archive_cmds, $1)='$CC -Bstatic -o $oldlib $oldobjs' ;; + *) _LT_TAGVAR(old_archive_cmds, $1)='$CC -o $oldlib $oldobjs' ;; + esac + ;; + RCC*) + # Rational C++ 2.4.1 + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + cxx*) + case $host in + osf3*) + _LT_TAGVAR(allow_undefined_flag, $1)=' $wl-expect_unresolved $wl\*' + _LT_TAGVAR(archive_cmds, $1)='$CC -shared$allow_undefined_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $soname `test -n "$verstring" && func_echo_all "$wl-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath $wl$libdir' + ;; + *) + _LT_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*' + _LT_TAGVAR(archive_cmds, $1)='$CC -shared$allow_undefined_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -msym -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done~ + echo "-hidden">> $lib.exp~ + $CC -shared$allow_undefined_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -msym -soname $soname $wl-input $wl$lib.exp `test -n "$verstring" && $ECHO "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib~ + $RM $lib.exp' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir' + ;; + esac + + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "ld" | $GREP -v "ld:"`; templist=`func_echo_all "$templist" | $SED "s/\(^.*ld.*\)\( .*ld.*$\)/\1/"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' + ;; + *) + if test yes,no = "$GXX,$with_gnu_ld"; then + _LT_TAGVAR(allow_undefined_flag, $1)=' $wl-expect_unresolved $wl\*' + case $host in + osf3*) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $allow_undefined_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations -o $lib' + ;; + *) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -nostdlib $allow_undefined_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-msym $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations -o $lib' + ;; + esac + + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath $wl$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP " \-L"' + + else + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + esac + ;; + + psos*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + + sunos4*) + case $cc_basename in + CC*) + # Sun C++ 4.x + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + lcc*) + # Lucid + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + *) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + esac + ;; + + solaris*) + case $cc_basename in + CC* | sunCC*) + # Sun C++ 4.2, 5.x and Centerline C++ + _LT_TAGVAR(archive_cmds_need_lc,$1)=yes + _LT_TAGVAR(no_undefined_flag, $1)=' -zdefs' + _LT_TAGVAR(archive_cmds, $1)='$CC -G$allow_undefined_flag -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $CC -G$allow_undefined_flag $wl-M $wl$lib.exp -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$RM $lib.exp' + + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + case $host_os in + solaris2.[[0-5]] | solaris2.[[0-5]].*) ;; + *) + # The compiler driver will combine and reorder linker options, + # but understands '-z linker_flag'. + # Supported since Solaris 2.6 (maybe 2.5.1?) + _LT_TAGVAR(whole_archive_flag_spec, $1)='-z allextract$convenience -z defaultextract' + ;; + esac + _LT_TAGVAR(link_all_deplibs, $1)=yes + + output_verbose_link_cmd='func_echo_all' + + # Archives containing C++ object files must be created using + # "CC -xar", where "CC" is the Sun C++ compiler. This is + # necessary to make sure instantiated templates are included + # in the archive. + _LT_TAGVAR(old_archive_cmds, $1)='$CC -xar -o $oldlib $oldobjs' + ;; + gcx*) + # Green Hills C++ Compiler + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-h $wl$soname -o $lib' + + # The C++ compiler must be used to create the archive. + _LT_TAGVAR(old_archive_cmds, $1)='$CC $LDFLAGS -archive -o $oldlib $oldobjs' + ;; + *) + # GNU C++ compiler with Solaris linker + if test yes,no = "$GXX,$with_gnu_ld"; then + _LT_TAGVAR(no_undefined_flag, $1)=' $wl-z ${wl}defs' + if $CC --version | $GREP -v '^2\.7' > /dev/null; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-h $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $CC -shared $pic_flag -nostdlib $wl-M $wl$lib.exp $wl-h $wl$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$RM $lib.exp' + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP " \-L"' + else + # g++ 2.7 appears to require '-G' NOT '-shared' on this + # platform. + _LT_TAGVAR(archive_cmds, $1)='$CC -G -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-h $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $CC -G -nostdlib $wl-M $wl$lib.exp $wl-h $wl$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$RM $lib.exp' + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + output_verbose_link_cmd='$CC -G $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP " \-L"' + fi + + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-R $wl$libdir' + case $host_os in + solaris2.[[0-5]] | solaris2.[[0-5]].*) ;; + *) + _LT_TAGVAR(whole_archive_flag_spec, $1)='$wl-z ${wl}allextract$convenience $wl-z ${wl}defaultextract' + ;; + esac + fi + ;; + esac + ;; + + sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[[01]].[[10]]* | unixware7* | sco3.2v5.0.[[024]]*) + _LT_TAGVAR(no_undefined_flag, $1)='$wl-z,text' + _LT_TAGVAR(archive_cmds_need_lc, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + runpath_var='LD_RUN_PATH' + + case $cc_basename in + CC*) + _LT_TAGVAR(archive_cmds, $1)='$CC -G $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + *) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + esac + ;; + + sysv5* | sco3.2v5* | sco5v6*) + # Note: We CANNOT use -z defs as we might desire, because we do not + # link with -lc, and that would cause any symbols used from libc to + # always be unresolved, which means just about no library would + # ever link correctly. If we're not using GNU ld we use -z text + # though, which does catch some bad symbols but isn't as heavy-handed + # as -z defs. + _LT_TAGVAR(no_undefined_flag, $1)='$wl-z,text' + _LT_TAGVAR(allow_undefined_flag, $1)='$wl-z,nodefs' + _LT_TAGVAR(archive_cmds_need_lc, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-R,$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=':' + _LT_TAGVAR(link_all_deplibs, $1)=yes + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl-Bexport' + runpath_var='LD_RUN_PATH' + + case $cc_basename in + CC*) + _LT_TAGVAR(archive_cmds, $1)='$CC -G $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(old_archive_cmds, $1)='$CC -Tprelink_objects $oldobjs~ + '"$_LT_TAGVAR(old_archive_cmds, $1)" + _LT_TAGVAR(reload_cmds, $1)='$CC -Tprelink_objects $reload_objs~ + '"$_LT_TAGVAR(reload_cmds, $1)" + ;; + *) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + esac + ;; + + tandem*) + case $cc_basename in + NCC*) + # NonStop-UX NCC 3.20 + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + *) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + esac + ;; + + vxworks*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + + *) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + esac + + AC_MSG_RESULT([$_LT_TAGVAR(ld_shlibs, $1)]) + test no = "$_LT_TAGVAR(ld_shlibs, $1)" && can_build_shared=no + + _LT_TAGVAR(GCC, $1)=$GXX + _LT_TAGVAR(LD, $1)=$LD + + ## CAVEAT EMPTOR: + ## There is no encapsulation within the following macros, do not change + ## the running order or otherwise move them around unless you know exactly + ## what you are doing... + _LT_SYS_HIDDEN_LIBDEPS($1) + _LT_COMPILER_PIC($1) + _LT_COMPILER_C_O($1) + _LT_COMPILER_FILE_LOCKS($1) + _LT_LINKER_SHLIBS($1) + _LT_SYS_DYNAMIC_LINKER($1) + _LT_LINKER_HARDCODE_LIBPATH($1) + + _LT_CONFIG($1) + fi # test -n "$compiler" + + CC=$lt_save_CC + CFLAGS=$lt_save_CFLAGS + LDCXX=$LD + LD=$lt_save_LD + GCC=$lt_save_GCC + with_gnu_ld=$lt_save_with_gnu_ld + lt_cv_path_LDCXX=$lt_cv_path_LD + lt_cv_path_LD=$lt_save_path_LD + lt_cv_prog_gnu_ldcxx=$lt_cv_prog_gnu_ld + lt_cv_prog_gnu_ld=$lt_save_with_gnu_ld +fi # test yes != "$_lt_caught_CXX_error" + +AC_LANG_POP +])# _LT_LANG_CXX_CONFIG + + +# _LT_FUNC_STRIPNAME_CNF +# ---------------------- +# func_stripname_cnf prefix suffix name +# strip PREFIX and SUFFIX off of NAME. +# PREFIX and SUFFIX must not contain globbing or regex special +# characters, hashes, percent signs, but SUFFIX may contain a leading +# dot (in which case that matches only a dot). +# +# This function is identical to the (non-XSI) version of func_stripname, +# except this one can be used by m4 code that may be executed by configure, +# rather than the libtool script. +m4_defun([_LT_FUNC_STRIPNAME_CNF],[dnl +AC_REQUIRE([_LT_DECL_SED]) +AC_REQUIRE([_LT_PROG_ECHO_BACKSLASH]) +func_stripname_cnf () +{ + case @S|@2 in + .*) func_stripname_result=`$ECHO "@S|@3" | $SED "s%^@S|@1%%; s%\\\\@S|@2\$%%"`;; + *) func_stripname_result=`$ECHO "@S|@3" | $SED "s%^@S|@1%%; s%@S|@2\$%%"`;; + esac +} # func_stripname_cnf +])# _LT_FUNC_STRIPNAME_CNF + + +# _LT_SYS_HIDDEN_LIBDEPS([TAGNAME]) +# --------------------------------- +# Figure out "hidden" library dependencies from verbose +# compiler output when linking a shared library. +# Parse the compiler output and extract the necessary +# objects, libraries and library flags. +m4_defun([_LT_SYS_HIDDEN_LIBDEPS], +[m4_require([_LT_FILEUTILS_DEFAULTS])dnl +AC_REQUIRE([_LT_FUNC_STRIPNAME_CNF])dnl +# Dependencies to place before and after the object being linked: +_LT_TAGVAR(predep_objects, $1)= +_LT_TAGVAR(postdep_objects, $1)= +_LT_TAGVAR(predeps, $1)= +_LT_TAGVAR(postdeps, $1)= +_LT_TAGVAR(compiler_lib_search_path, $1)= + +dnl we can't use the lt_simple_compile_test_code here, +dnl because it contains code intended for an executable, +dnl not a library. It's possible we should let each +dnl tag define a new lt_????_link_test_code variable, +dnl but it's only used here... +m4_if([$1], [], [cat > conftest.$ac_ext <<_LT_EOF +int a; +void foo (void) { a = 0; } +_LT_EOF +], [$1], [CXX], [cat > conftest.$ac_ext <<_LT_EOF +class Foo +{ +public: + Foo (void) { a = 0; } +private: + int a; +}; +_LT_EOF +], [$1], [F77], [cat > conftest.$ac_ext <<_LT_EOF + subroutine foo + implicit none + integer*4 a + a=0 + return + end +_LT_EOF +], [$1], [FC], [cat > conftest.$ac_ext <<_LT_EOF + subroutine foo + implicit none + integer a + a=0 + return + end +_LT_EOF +], [$1], [GCJ], [cat > conftest.$ac_ext <<_LT_EOF +public class foo { + private int a; + public void bar (void) { + a = 0; + } +}; +_LT_EOF +], [$1], [GO], [cat > conftest.$ac_ext <<_LT_EOF +package foo +func foo() { +} +_LT_EOF +]) + +_lt_libdeps_save_CFLAGS=$CFLAGS +case "$CC $CFLAGS " in #( +*\ -flto*\ *) CFLAGS="$CFLAGS -fno-lto" ;; +*\ -fwhopr*\ *) CFLAGS="$CFLAGS -fno-whopr" ;; +*\ -fuse-linker-plugin*\ *) CFLAGS="$CFLAGS -fno-use-linker-plugin" ;; +esac + +dnl Parse the compiler output and extract the necessary +dnl objects, libraries and library flags. +if AC_TRY_EVAL(ac_compile); then + # Parse the compiler output and extract the necessary + # objects, libraries and library flags. + + # Sentinel used to keep track of whether or not we are before + # the conftest object file. + pre_test_object_deps_done=no + + for p in `eval "$output_verbose_link_cmd"`; do + case $prev$p in + + -L* | -R* | -l*) + # Some compilers place space between "-{L,R}" and the path. + # Remove the space. + if test x-L = "$p" || + test x-R = "$p"; then + prev=$p + continue + fi + + # Expand the sysroot to ease extracting the directories later. + if test -z "$prev"; then + case $p in + -L*) func_stripname_cnf '-L' '' "$p"; prev=-L; p=$func_stripname_result ;; + -R*) func_stripname_cnf '-R' '' "$p"; prev=-R; p=$func_stripname_result ;; + -l*) func_stripname_cnf '-l' '' "$p"; prev=-l; p=$func_stripname_result ;; + esac + fi + case $p in + =*) func_stripname_cnf '=' '' "$p"; p=$lt_sysroot$func_stripname_result ;; + esac + if test no = "$pre_test_object_deps_done"; then + case $prev in + -L | -R) + # Internal compiler library paths should come after those + # provided the user. The postdeps already come after the + # user supplied libs so there is no need to process them. + if test -z "$_LT_TAGVAR(compiler_lib_search_path, $1)"; then + _LT_TAGVAR(compiler_lib_search_path, $1)=$prev$p + else + _LT_TAGVAR(compiler_lib_search_path, $1)="${_LT_TAGVAR(compiler_lib_search_path, $1)} $prev$p" + fi + ;; + # The "-l" case would never come before the object being + # linked, so don't bother handling this case. + esac + else + if test -z "$_LT_TAGVAR(postdeps, $1)"; then + _LT_TAGVAR(postdeps, $1)=$prev$p + else + _LT_TAGVAR(postdeps, $1)="${_LT_TAGVAR(postdeps, $1)} $prev$p" + fi + fi + prev= + ;; + + *.lto.$objext) ;; # Ignore GCC LTO objects + *.$objext) + # This assumes that the test object file only shows up + # once in the compiler output. + if test "$p" = "conftest.$objext"; then + pre_test_object_deps_done=yes + continue + fi + + if test no = "$pre_test_object_deps_done"; then + if test -z "$_LT_TAGVAR(predep_objects, $1)"; then + _LT_TAGVAR(predep_objects, $1)=$p + else + _LT_TAGVAR(predep_objects, $1)="$_LT_TAGVAR(predep_objects, $1) $p" + fi + else + if test -z "$_LT_TAGVAR(postdep_objects, $1)"; then + _LT_TAGVAR(postdep_objects, $1)=$p + else + _LT_TAGVAR(postdep_objects, $1)="$_LT_TAGVAR(postdep_objects, $1) $p" + fi + fi + ;; + + *) ;; # Ignore the rest. + + esac + done + + # Clean up. + rm -f a.out a.exe +else + echo "libtool.m4: error: problem compiling $1 test program" +fi + +$RM -f confest.$objext +CFLAGS=$_lt_libdeps_save_CFLAGS + +# PORTME: override above test on systems where it is broken +m4_if([$1], [CXX], +[case $host_os in +interix[[3-9]]*) + # Interix 3.5 installs completely hosed .la files for C++, so rather than + # hack all around it, let's just trust "g++" to DTRT. + _LT_TAGVAR(predep_objects,$1)= + _LT_TAGVAR(postdep_objects,$1)= + _LT_TAGVAR(postdeps,$1)= + ;; +esac +]) + +case " $_LT_TAGVAR(postdeps, $1) " in +*" -lc "*) _LT_TAGVAR(archive_cmds_need_lc, $1)=no ;; +esac + _LT_TAGVAR(compiler_lib_search_dirs, $1)= +if test -n "${_LT_TAGVAR(compiler_lib_search_path, $1)}"; then + _LT_TAGVAR(compiler_lib_search_dirs, $1)=`echo " ${_LT_TAGVAR(compiler_lib_search_path, $1)}" | $SED -e 's! -L! !g' -e 's!^ !!'` +fi +_LT_TAGDECL([], [compiler_lib_search_dirs], [1], + [The directories searched by this compiler when creating a shared library]) +_LT_TAGDECL([], [predep_objects], [1], + [Dependencies to place before and after the objects being linked to + create a shared library]) +_LT_TAGDECL([], [postdep_objects], [1]) +_LT_TAGDECL([], [predeps], [1]) +_LT_TAGDECL([], [postdeps], [1]) +_LT_TAGDECL([], [compiler_lib_search_path], [1], + [The library search path used internally by the compiler when linking + a shared library]) +])# _LT_SYS_HIDDEN_LIBDEPS + + +# _LT_LANG_F77_CONFIG([TAG]) +# -------------------------- +# Ensure that the configuration variables for a Fortran 77 compiler are +# suitably defined. These variables are subsequently used by _LT_CONFIG +# to write the compiler configuration to 'libtool'. +m4_defun([_LT_LANG_F77_CONFIG], +[AC_LANG_PUSH(Fortran 77) +if test -z "$F77" || test no = "$F77"; then + _lt_disable_F77=yes +fi + +_LT_TAGVAR(archive_cmds_need_lc, $1)=no +_LT_TAGVAR(allow_undefined_flag, $1)= +_LT_TAGVAR(always_export_symbols, $1)=no +_LT_TAGVAR(archive_expsym_cmds, $1)= +_LT_TAGVAR(export_dynamic_flag_spec, $1)= +_LT_TAGVAR(hardcode_direct, $1)=no +_LT_TAGVAR(hardcode_direct_absolute, $1)=no +_LT_TAGVAR(hardcode_libdir_flag_spec, $1)= +_LT_TAGVAR(hardcode_libdir_separator, $1)= +_LT_TAGVAR(hardcode_minus_L, $1)=no +_LT_TAGVAR(hardcode_automatic, $1)=no +_LT_TAGVAR(inherit_rpath, $1)=no +_LT_TAGVAR(module_cmds, $1)= +_LT_TAGVAR(module_expsym_cmds, $1)= +_LT_TAGVAR(link_all_deplibs, $1)=unknown +_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds +_LT_TAGVAR(reload_flag, $1)=$reload_flag +_LT_TAGVAR(reload_cmds, $1)=$reload_cmds +_LT_TAGVAR(no_undefined_flag, $1)= +_LT_TAGVAR(whole_archive_flag_spec, $1)= +_LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no + +# Source file extension for f77 test sources. +ac_ext=f + +# Object file extension for compiled f77 test sources. +objext=o +_LT_TAGVAR(objext, $1)=$objext + +# No sense in running all these tests if we already determined that +# the F77 compiler isn't working. Some variables (like enable_shared) +# are currently assumed to apply to all compilers on this platform, +# and will be corrupted by setting them based on a non-working compiler. +if test yes != "$_lt_disable_F77"; then + # Code to be used in simple compile tests + lt_simple_compile_test_code="\ + subroutine t + return + end +" + + # Code to be used in simple link tests + lt_simple_link_test_code="\ + program t + end +" + + # ltmain only uses $CC for tagged configurations so make sure $CC is set. + _LT_TAG_COMPILER + + # save warnings/boilerplate of simple test code + _LT_COMPILER_BOILERPLATE + _LT_LINKER_BOILERPLATE + + # Allow CC to be a program name with arguments. + lt_save_CC=$CC + lt_save_GCC=$GCC + lt_save_CFLAGS=$CFLAGS + CC=${F77-"f77"} + CFLAGS=$FFLAGS + compiler=$CC + _LT_TAGVAR(compiler, $1)=$CC + _LT_CC_BASENAME([$compiler]) + GCC=$G77 + if test -n "$compiler"; then + AC_MSG_CHECKING([if libtool supports shared libraries]) + AC_MSG_RESULT([$can_build_shared]) + + AC_MSG_CHECKING([whether to build shared libraries]) + test no = "$can_build_shared" && enable_shared=no + + # On AIX, shared libraries and static libraries use the same namespace, and + # are all built from PIC. + case $host_os in + aix3*) + test yes = "$enable_shared" && enable_static=no + if test -n "$RANLIB"; then + archive_cmds="$archive_cmds~\$RANLIB \$lib" + postinstall_cmds='$RANLIB $lib' + fi + ;; + aix[[4-9]]*) + if test ia64 != "$host_cpu"; then + case $enable_shared,$with_aix_soname,$aix_use_runtimelinking in + yes,aix,yes) ;; # shared object as lib.so file only + yes,svr4,*) ;; # shared object as lib.so archive member only + yes,*) enable_static=no ;; # shared object in lib.a archive as well + esac + fi + ;; + esac + AC_MSG_RESULT([$enable_shared]) + + AC_MSG_CHECKING([whether to build static libraries]) + # Make sure either enable_shared or enable_static is yes. + test yes = "$enable_shared" || enable_static=yes + AC_MSG_RESULT([$enable_static]) + + _LT_TAGVAR(GCC, $1)=$G77 + _LT_TAGVAR(LD, $1)=$LD + + ## CAVEAT EMPTOR: + ## There is no encapsulation within the following macros, do not change + ## the running order or otherwise move them around unless you know exactly + ## what you are doing... + _LT_COMPILER_PIC($1) + _LT_COMPILER_C_O($1) + _LT_COMPILER_FILE_LOCKS($1) + _LT_LINKER_SHLIBS($1) + _LT_SYS_DYNAMIC_LINKER($1) + _LT_LINKER_HARDCODE_LIBPATH($1) + + _LT_CONFIG($1) + fi # test -n "$compiler" + + GCC=$lt_save_GCC + CC=$lt_save_CC + CFLAGS=$lt_save_CFLAGS +fi # test yes != "$_lt_disable_F77" + +AC_LANG_POP +])# _LT_LANG_F77_CONFIG + + +# _LT_LANG_FC_CONFIG([TAG]) +# ------------------------- +# Ensure that the configuration variables for a Fortran compiler are +# suitably defined. These variables are subsequently used by _LT_CONFIG +# to write the compiler configuration to 'libtool'. +m4_defun([_LT_LANG_FC_CONFIG], +[AC_LANG_PUSH(Fortran) + +if test -z "$FC" || test no = "$FC"; then + _lt_disable_FC=yes +fi + +_LT_TAGVAR(archive_cmds_need_lc, $1)=no +_LT_TAGVAR(allow_undefined_flag, $1)= +_LT_TAGVAR(always_export_symbols, $1)=no +_LT_TAGVAR(archive_expsym_cmds, $1)= +_LT_TAGVAR(export_dynamic_flag_spec, $1)= +_LT_TAGVAR(hardcode_direct, $1)=no +_LT_TAGVAR(hardcode_direct_absolute, $1)=no +_LT_TAGVAR(hardcode_libdir_flag_spec, $1)= +_LT_TAGVAR(hardcode_libdir_separator, $1)= +_LT_TAGVAR(hardcode_minus_L, $1)=no +_LT_TAGVAR(hardcode_automatic, $1)=no +_LT_TAGVAR(inherit_rpath, $1)=no +_LT_TAGVAR(module_cmds, $1)= +_LT_TAGVAR(module_expsym_cmds, $1)= +_LT_TAGVAR(link_all_deplibs, $1)=unknown +_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds +_LT_TAGVAR(reload_flag, $1)=$reload_flag +_LT_TAGVAR(reload_cmds, $1)=$reload_cmds +_LT_TAGVAR(no_undefined_flag, $1)= +_LT_TAGVAR(whole_archive_flag_spec, $1)= +_LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no + +# Source file extension for fc test sources. +ac_ext=${ac_fc_srcext-f} + +# Object file extension for compiled fc test sources. +objext=o +_LT_TAGVAR(objext, $1)=$objext + +# No sense in running all these tests if we already determined that +# the FC compiler isn't working. Some variables (like enable_shared) +# are currently assumed to apply to all compilers on this platform, +# and will be corrupted by setting them based on a non-working compiler. +if test yes != "$_lt_disable_FC"; then + # Code to be used in simple compile tests + lt_simple_compile_test_code="\ + subroutine t + return + end +" + + # Code to be used in simple link tests + lt_simple_link_test_code="\ + program t + end +" + + # ltmain only uses $CC for tagged configurations so make sure $CC is set. + _LT_TAG_COMPILER + + # save warnings/boilerplate of simple test code + _LT_COMPILER_BOILERPLATE + _LT_LINKER_BOILERPLATE + + # Allow CC to be a program name with arguments. + lt_save_CC=$CC + lt_save_GCC=$GCC + lt_save_CFLAGS=$CFLAGS + CC=${FC-"f95"} + CFLAGS=$FCFLAGS + compiler=$CC + GCC=$ac_cv_fc_compiler_gnu + + _LT_TAGVAR(compiler, $1)=$CC + _LT_CC_BASENAME([$compiler]) + + if test -n "$compiler"; then + AC_MSG_CHECKING([if libtool supports shared libraries]) + AC_MSG_RESULT([$can_build_shared]) + + AC_MSG_CHECKING([whether to build shared libraries]) + test no = "$can_build_shared" && enable_shared=no + + # On AIX, shared libraries and static libraries use the same namespace, and + # are all built from PIC. + case $host_os in + aix3*) + test yes = "$enable_shared" && enable_static=no + if test -n "$RANLIB"; then + archive_cmds="$archive_cmds~\$RANLIB \$lib" + postinstall_cmds='$RANLIB $lib' + fi + ;; + aix[[4-9]]*) + if test ia64 != "$host_cpu"; then + case $enable_shared,$with_aix_soname,$aix_use_runtimelinking in + yes,aix,yes) ;; # shared object as lib.so file only + yes,svr4,*) ;; # shared object as lib.so archive member only + yes,*) enable_static=no ;; # shared object in lib.a archive as well + esac + fi + ;; + esac + AC_MSG_RESULT([$enable_shared]) + + AC_MSG_CHECKING([whether to build static libraries]) + # Make sure either enable_shared or enable_static is yes. + test yes = "$enable_shared" || enable_static=yes + AC_MSG_RESULT([$enable_static]) + + _LT_TAGVAR(GCC, $1)=$ac_cv_fc_compiler_gnu + _LT_TAGVAR(LD, $1)=$LD + + ## CAVEAT EMPTOR: + ## There is no encapsulation within the following macros, do not change + ## the running order or otherwise move them around unless you know exactly + ## what you are doing... + _LT_SYS_HIDDEN_LIBDEPS($1) + _LT_COMPILER_PIC($1) + _LT_COMPILER_C_O($1) + _LT_COMPILER_FILE_LOCKS($1) + _LT_LINKER_SHLIBS($1) + _LT_SYS_DYNAMIC_LINKER($1) + _LT_LINKER_HARDCODE_LIBPATH($1) + + _LT_CONFIG($1) + fi # test -n "$compiler" + + GCC=$lt_save_GCC + CC=$lt_save_CC + CFLAGS=$lt_save_CFLAGS +fi # test yes != "$_lt_disable_FC" + +AC_LANG_POP +])# _LT_LANG_FC_CONFIG + + +# _LT_LANG_GCJ_CONFIG([TAG]) +# -------------------------- +# Ensure that the configuration variables for the GNU Java Compiler compiler +# are suitably defined. These variables are subsequently used by _LT_CONFIG +# to write the compiler configuration to 'libtool'. +m4_defun([_LT_LANG_GCJ_CONFIG], +[AC_REQUIRE([LT_PROG_GCJ])dnl +AC_LANG_SAVE + +# Source file extension for Java test sources. +ac_ext=java + +# Object file extension for compiled Java test sources. +objext=o +_LT_TAGVAR(objext, $1)=$objext + +# Code to be used in simple compile tests +lt_simple_compile_test_code="class foo {}" + +# Code to be used in simple link tests +lt_simple_link_test_code='public class conftest { public static void main(String[[]] argv) {}; }' + +# ltmain only uses $CC for tagged configurations so make sure $CC is set. +_LT_TAG_COMPILER + +# save warnings/boilerplate of simple test code +_LT_COMPILER_BOILERPLATE +_LT_LINKER_BOILERPLATE + +# Allow CC to be a program name with arguments. +lt_save_CC=$CC +lt_save_CFLAGS=$CFLAGS +lt_save_GCC=$GCC +GCC=yes +CC=${GCJ-"gcj"} +CFLAGS=$GCJFLAGS +compiler=$CC +_LT_TAGVAR(compiler, $1)=$CC +_LT_TAGVAR(LD, $1)=$LD +_LT_CC_BASENAME([$compiler]) + +# GCJ did not exist at the time GCC didn't implicitly link libc in. +_LT_TAGVAR(archive_cmds_need_lc, $1)=no + +_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds +_LT_TAGVAR(reload_flag, $1)=$reload_flag +_LT_TAGVAR(reload_cmds, $1)=$reload_cmds + +## CAVEAT EMPTOR: +## There is no encapsulation within the following macros, do not change +## the running order or otherwise move them around unless you know exactly +## what you are doing... +if test -n "$compiler"; then + _LT_COMPILER_NO_RTTI($1) + _LT_COMPILER_PIC($1) + _LT_COMPILER_C_O($1) + _LT_COMPILER_FILE_LOCKS($1) + _LT_LINKER_SHLIBS($1) + _LT_LINKER_HARDCODE_LIBPATH($1) + + _LT_CONFIG($1) +fi + +AC_LANG_RESTORE + +GCC=$lt_save_GCC +CC=$lt_save_CC +CFLAGS=$lt_save_CFLAGS +])# _LT_LANG_GCJ_CONFIG + + +# _LT_LANG_GO_CONFIG([TAG]) +# -------------------------- +# Ensure that the configuration variables for the GNU Go compiler +# are suitably defined. These variables are subsequently used by _LT_CONFIG +# to write the compiler configuration to 'libtool'. +m4_defun([_LT_LANG_GO_CONFIG], +[AC_REQUIRE([LT_PROG_GO])dnl +AC_LANG_SAVE + +# Source file extension for Go test sources. +ac_ext=go + +# Object file extension for compiled Go test sources. +objext=o +_LT_TAGVAR(objext, $1)=$objext + +# Code to be used in simple compile tests +lt_simple_compile_test_code="package main; func main() { }" + +# Code to be used in simple link tests +lt_simple_link_test_code='package main; func main() { }' + +# ltmain only uses $CC for tagged configurations so make sure $CC is set. +_LT_TAG_COMPILER + +# save warnings/boilerplate of simple test code +_LT_COMPILER_BOILERPLATE +_LT_LINKER_BOILERPLATE + +# Allow CC to be a program name with arguments. +lt_save_CC=$CC +lt_save_CFLAGS=$CFLAGS +lt_save_GCC=$GCC +GCC=yes +CC=${GOC-"gccgo"} +CFLAGS=$GOFLAGS +compiler=$CC +_LT_TAGVAR(compiler, $1)=$CC +_LT_TAGVAR(LD, $1)=$LD +_LT_CC_BASENAME([$compiler]) + +# Go did not exist at the time GCC didn't implicitly link libc in. +_LT_TAGVAR(archive_cmds_need_lc, $1)=no + +_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds +_LT_TAGVAR(reload_flag, $1)=$reload_flag +_LT_TAGVAR(reload_cmds, $1)=$reload_cmds + +## CAVEAT EMPTOR: +## There is no encapsulation within the following macros, do not change +## the running order or otherwise move them around unless you know exactly +## what you are doing... +if test -n "$compiler"; then + _LT_COMPILER_NO_RTTI($1) + _LT_COMPILER_PIC($1) + _LT_COMPILER_C_O($1) + _LT_COMPILER_FILE_LOCKS($1) + _LT_LINKER_SHLIBS($1) + _LT_LINKER_HARDCODE_LIBPATH($1) + + _LT_CONFIG($1) +fi + +AC_LANG_RESTORE + +GCC=$lt_save_GCC +CC=$lt_save_CC +CFLAGS=$lt_save_CFLAGS +])# _LT_LANG_GO_CONFIG + + +# _LT_LANG_RC_CONFIG([TAG]) +# ------------------------- +# Ensure that the configuration variables for the Windows resource compiler +# are suitably defined. These variables are subsequently used by _LT_CONFIG +# to write the compiler configuration to 'libtool'. +m4_defun([_LT_LANG_RC_CONFIG], +[AC_REQUIRE([LT_PROG_RC])dnl +AC_LANG_SAVE + +# Source file extension for RC test sources. +ac_ext=rc + +# Object file extension for compiled RC test sources. +objext=o +_LT_TAGVAR(objext, $1)=$objext + +# Code to be used in simple compile tests +lt_simple_compile_test_code='sample MENU { MENUITEM "&Soup", 100, CHECKED }' + +# Code to be used in simple link tests +lt_simple_link_test_code=$lt_simple_compile_test_code + +# ltmain only uses $CC for tagged configurations so make sure $CC is set. +_LT_TAG_COMPILER + +# save warnings/boilerplate of simple test code +_LT_COMPILER_BOILERPLATE +_LT_LINKER_BOILERPLATE + +# Allow CC to be a program name with arguments. +lt_save_CC=$CC +lt_save_CFLAGS=$CFLAGS +lt_save_GCC=$GCC +GCC= +CC=${RC-"windres"} +CFLAGS= +compiler=$CC +_LT_TAGVAR(compiler, $1)=$CC +_LT_CC_BASENAME([$compiler]) +_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)=yes + +if test -n "$compiler"; then + : + _LT_CONFIG($1) +fi + +GCC=$lt_save_GCC +AC_LANG_RESTORE +CC=$lt_save_CC +CFLAGS=$lt_save_CFLAGS +])# _LT_LANG_RC_CONFIG + + +# LT_PROG_GCJ +# ----------- +AC_DEFUN([LT_PROG_GCJ], +[m4_ifdef([AC_PROG_GCJ], [AC_PROG_GCJ], + [m4_ifdef([A][M_PROG_GCJ], [A][M_PROG_GCJ], + [AC_CHECK_TOOL(GCJ, gcj,) + test set = "${GCJFLAGS+set}" || GCJFLAGS="-g -O2" + AC_SUBST(GCJFLAGS)])])[]dnl +]) + +# Old name: +AU_ALIAS([LT_AC_PROG_GCJ], [LT_PROG_GCJ]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([LT_AC_PROG_GCJ], []) + + +# LT_PROG_GO +# ---------- +AC_DEFUN([LT_PROG_GO], +[AC_CHECK_TOOL(GOC, gccgo,) +]) + + +# LT_PROG_RC +# ---------- +AC_DEFUN([LT_PROG_RC], +[AC_CHECK_TOOL(RC, windres,) +]) + +# Old name: +AU_ALIAS([LT_AC_PROG_RC], [LT_PROG_RC]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([LT_AC_PROG_RC], []) + + +# _LT_DECL_EGREP +# -------------- +# If we don't have a new enough Autoconf to choose the best grep +# available, choose the one first in the user's PATH. +m4_defun([_LT_DECL_EGREP], +[AC_REQUIRE([AC_PROG_EGREP])dnl +AC_REQUIRE([AC_PROG_FGREP])dnl +test -z "$GREP" && GREP=grep +_LT_DECL([], [GREP], [1], [A grep program that handles long lines]) +_LT_DECL([], [EGREP], [1], [An ERE matcher]) +_LT_DECL([], [FGREP], [1], [A literal string matcher]) +dnl Non-bleeding-edge autoconf doesn't subst GREP, so do it here too +AC_SUBST([GREP]) +]) + + +# _LT_DECL_OBJDUMP +# -------------- +# If we don't have a new enough Autoconf to choose the best objdump +# available, choose the one first in the user's PATH. +m4_defun([_LT_DECL_OBJDUMP], +[AC_CHECK_TOOL(OBJDUMP, objdump, false) +test -z "$OBJDUMP" && OBJDUMP=objdump +_LT_DECL([], [OBJDUMP], [1], [An object symbol dumper]) +AC_SUBST([OBJDUMP]) +]) + +# _LT_DECL_DLLTOOL +# ---------------- +# Ensure DLLTOOL variable is set. +m4_defun([_LT_DECL_DLLTOOL], +[AC_CHECK_TOOL(DLLTOOL, dlltool, false) +test -z "$DLLTOOL" && DLLTOOL=dlltool +_LT_DECL([], [DLLTOOL], [1], [DLL creation program]) +AC_SUBST([DLLTOOL]) +]) + +# _LT_DECL_SED +# ------------ +# Check for a fully-functional sed program, that truncates +# as few characters as possible. Prefer GNU sed if found. +m4_defun([_LT_DECL_SED], +[AC_PROG_SED +test -z "$SED" && SED=sed +Xsed="$SED -e 1s/^X//" +_LT_DECL([], [SED], [1], [A sed program that does not truncate output]) +_LT_DECL([], [Xsed], ["\$SED -e 1s/^X//"], + [Sed that helps us avoid accidentally triggering echo(1) options like -n]) +])# _LT_DECL_SED + +m4_ifndef([AC_PROG_SED], [ +############################################################ +# NOTE: This macro has been submitted for inclusion into # +# GNU Autoconf as AC_PROG_SED. When it is available in # +# a released version of Autoconf we should remove this # +# macro and use it instead. # +############################################################ + +m4_defun([AC_PROG_SED], +[AC_MSG_CHECKING([for a sed that does not truncate output]) +AC_CACHE_VAL(lt_cv_path_SED, +[# Loop through the user's path and test for sed and gsed. +# Then use that list of sed's as ones to test for truncation. +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for lt_ac_prog in sed gsed; do + for ac_exec_ext in '' $ac_executable_extensions; do + if $as_executable_p "$as_dir/$lt_ac_prog$ac_exec_ext"; then + lt_ac_sed_list="$lt_ac_sed_list $as_dir/$lt_ac_prog$ac_exec_ext" + fi + done + done +done +IFS=$as_save_IFS +lt_ac_max=0 +lt_ac_count=0 +# Add /usr/xpg4/bin/sed as it is typically found on Solaris +# along with /bin/sed that truncates output. +for lt_ac_sed in $lt_ac_sed_list /usr/xpg4/bin/sed; do + test ! -f "$lt_ac_sed" && continue + cat /dev/null > conftest.in + lt_ac_count=0 + echo $ECHO_N "0123456789$ECHO_C" >conftest.in + # Check for GNU sed and select it if it is found. + if "$lt_ac_sed" --version 2>&1 < /dev/null | grep 'GNU' > /dev/null; then + lt_cv_path_SED=$lt_ac_sed + break + fi + while true; do + cat conftest.in conftest.in >conftest.tmp + mv conftest.tmp conftest.in + cp conftest.in conftest.nl + echo >>conftest.nl + $lt_ac_sed -e 's/a$//' < conftest.nl >conftest.out || break + cmp -s conftest.out conftest.nl || break + # 10000 chars as input seems more than enough + test 10 -lt "$lt_ac_count" && break + lt_ac_count=`expr $lt_ac_count + 1` + if test "$lt_ac_count" -gt "$lt_ac_max"; then + lt_ac_max=$lt_ac_count + lt_cv_path_SED=$lt_ac_sed + fi + done +done +]) +SED=$lt_cv_path_SED +AC_SUBST([SED]) +AC_MSG_RESULT([$SED]) +])#AC_PROG_SED +])#m4_ifndef + +# Old name: +AU_ALIAS([LT_AC_PROG_SED], [AC_PROG_SED]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([LT_AC_PROG_SED], []) + + +# _LT_CHECK_SHELL_FEATURES +# ------------------------ +# Find out whether the shell is Bourne or XSI compatible, +# or has some other useful features. +m4_defun([_LT_CHECK_SHELL_FEATURES], +[if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then + lt_unset=unset +else + lt_unset=false +fi +_LT_DECL([], [lt_unset], [0], [whether the shell understands "unset"])dnl + +# test EBCDIC or ASCII +case `echo X|tr X '\101'` in + A) # ASCII based system + # \n is not interpreted correctly by Solaris 8 /usr/ucb/tr + lt_SP2NL='tr \040 \012' + lt_NL2SP='tr \015\012 \040\040' + ;; + *) # EBCDIC based system + lt_SP2NL='tr \100 \n' + lt_NL2SP='tr \r\n \100\100' + ;; +esac +_LT_DECL([SP2NL], [lt_SP2NL], [1], [turn spaces into newlines])dnl +_LT_DECL([NL2SP], [lt_NL2SP], [1], [turn newlines into spaces])dnl +])# _LT_CHECK_SHELL_FEATURES + + +# _LT_PATH_CONVERSION_FUNCTIONS +# ----------------------------- +# Determine what file name conversion functions should be used by +# func_to_host_file (and, implicitly, by func_to_host_path). These are needed +# for certain cross-compile configurations and native mingw. +m4_defun([_LT_PATH_CONVERSION_FUNCTIONS], +[AC_REQUIRE([AC_CANONICAL_HOST])dnl +AC_REQUIRE([AC_CANONICAL_BUILD])dnl +AC_MSG_CHECKING([how to convert $build file names to $host format]) +AC_CACHE_VAL(lt_cv_to_host_file_cmd, +[case $host in + *-*-mingw* ) + case $build in + *-*-mingw* ) # actually msys + lt_cv_to_host_file_cmd=func_convert_file_msys_to_w32 + ;; + *-*-cygwin* ) + lt_cv_to_host_file_cmd=func_convert_file_cygwin_to_w32 + ;; + * ) # otherwise, assume *nix + lt_cv_to_host_file_cmd=func_convert_file_nix_to_w32 + ;; + esac + ;; + *-*-cygwin* ) + case $build in + *-*-mingw* ) # actually msys + lt_cv_to_host_file_cmd=func_convert_file_msys_to_cygwin + ;; + *-*-cygwin* ) + lt_cv_to_host_file_cmd=func_convert_file_noop + ;; + * ) # otherwise, assume *nix + lt_cv_to_host_file_cmd=func_convert_file_nix_to_cygwin + ;; + esac + ;; + * ) # unhandled hosts (and "normal" native builds) + lt_cv_to_host_file_cmd=func_convert_file_noop + ;; +esac +]) +to_host_file_cmd=$lt_cv_to_host_file_cmd +AC_MSG_RESULT([$lt_cv_to_host_file_cmd]) +_LT_DECL([to_host_file_cmd], [lt_cv_to_host_file_cmd], + [0], [convert $build file names to $host format])dnl + +AC_MSG_CHECKING([how to convert $build file names to toolchain format]) +AC_CACHE_VAL(lt_cv_to_tool_file_cmd, +[#assume ordinary cross tools, or native build. +lt_cv_to_tool_file_cmd=func_convert_file_noop +case $host in + *-*-mingw* ) + case $build in + *-*-mingw* ) # actually msys + lt_cv_to_tool_file_cmd=func_convert_file_msys_to_w32 + ;; + esac + ;; +esac +]) +to_tool_file_cmd=$lt_cv_to_tool_file_cmd +AC_MSG_RESULT([$lt_cv_to_tool_file_cmd]) +_LT_DECL([to_tool_file_cmd], [lt_cv_to_tool_file_cmd], + [0], [convert $build files to toolchain format])dnl +])# _LT_PATH_CONVERSION_FUNCTIONS diff --git a/third_party/json-c/autoconf-archive/m4/ltoptions.m4 b/third_party/json-c/autoconf-archive/m4/ltoptions.m4 new file mode 100644 index 000000000..94b082976 --- /dev/null +++ b/third_party/json-c/autoconf-archive/m4/ltoptions.m4 @@ -0,0 +1,437 @@ +# Helper functions for option handling. -*- Autoconf -*- +# +# Copyright (C) 2004-2005, 2007-2009, 2011-2015 Free Software +# Foundation, Inc. +# Written by Gary V. Vaughan, 2004 +# +# This file is free software; the Free Software Foundation gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. + +# serial 8 ltoptions.m4 + +# This is to help aclocal find these macros, as it can't see m4_define. +AC_DEFUN([LTOPTIONS_VERSION], [m4_if([1])]) + + +# _LT_MANGLE_OPTION(MACRO-NAME, OPTION-NAME) +# ------------------------------------------ +m4_define([_LT_MANGLE_OPTION], +[[_LT_OPTION_]m4_bpatsubst($1__$2, [[^a-zA-Z0-9_]], [_])]) + + +# _LT_SET_OPTION(MACRO-NAME, OPTION-NAME) +# --------------------------------------- +# Set option OPTION-NAME for macro MACRO-NAME, and if there is a +# matching handler defined, dispatch to it. Other OPTION-NAMEs are +# saved as a flag. +m4_define([_LT_SET_OPTION], +[m4_define(_LT_MANGLE_OPTION([$1], [$2]))dnl +m4_ifdef(_LT_MANGLE_DEFUN([$1], [$2]), + _LT_MANGLE_DEFUN([$1], [$2]), + [m4_warning([Unknown $1 option '$2'])])[]dnl +]) + + +# _LT_IF_OPTION(MACRO-NAME, OPTION-NAME, IF-SET, [IF-NOT-SET]) +# ------------------------------------------------------------ +# Execute IF-SET if OPTION is set, IF-NOT-SET otherwise. +m4_define([_LT_IF_OPTION], +[m4_ifdef(_LT_MANGLE_OPTION([$1], [$2]), [$3], [$4])]) + + +# _LT_UNLESS_OPTIONS(MACRO-NAME, OPTION-LIST, IF-NOT-SET) +# ------------------------------------------------------- +# Execute IF-NOT-SET unless all options in OPTION-LIST for MACRO-NAME +# are set. +m4_define([_LT_UNLESS_OPTIONS], +[m4_foreach([_LT_Option], m4_split(m4_normalize([$2])), + [m4_ifdef(_LT_MANGLE_OPTION([$1], _LT_Option), + [m4_define([$0_found])])])[]dnl +m4_ifdef([$0_found], [m4_undefine([$0_found])], [$3 +])[]dnl +]) + + +# _LT_SET_OPTIONS(MACRO-NAME, OPTION-LIST) +# ---------------------------------------- +# OPTION-LIST is a space-separated list of Libtool options associated +# with MACRO-NAME. If any OPTION has a matching handler declared with +# LT_OPTION_DEFINE, dispatch to that macro; otherwise complain about +# the unknown option and exit. +m4_defun([_LT_SET_OPTIONS], +[# Set options +m4_foreach([_LT_Option], m4_split(m4_normalize([$2])), + [_LT_SET_OPTION([$1], _LT_Option)]) + +m4_if([$1],[LT_INIT],[ + dnl + dnl Simply set some default values (i.e off) if boolean options were not + dnl specified: + _LT_UNLESS_OPTIONS([LT_INIT], [dlopen], [enable_dlopen=no + ]) + _LT_UNLESS_OPTIONS([LT_INIT], [win32-dll], [enable_win32_dll=no + ]) + dnl + dnl If no reference was made to various pairs of opposing options, then + dnl we run the default mode handler for the pair. For example, if neither + dnl 'shared' nor 'disable-shared' was passed, we enable building of shared + dnl archives by default: + _LT_UNLESS_OPTIONS([LT_INIT], [shared disable-shared], [_LT_ENABLE_SHARED]) + _LT_UNLESS_OPTIONS([LT_INIT], [static disable-static], [_LT_ENABLE_STATIC]) + _LT_UNLESS_OPTIONS([LT_INIT], [pic-only no-pic], [_LT_WITH_PIC]) + _LT_UNLESS_OPTIONS([LT_INIT], [fast-install disable-fast-install], + [_LT_ENABLE_FAST_INSTALL]) + _LT_UNLESS_OPTIONS([LT_INIT], [aix-soname=aix aix-soname=both aix-soname=svr4], + [_LT_WITH_AIX_SONAME([aix])]) + ]) +])# _LT_SET_OPTIONS + + +## --------------------------------- ## +## Macros to handle LT_INIT options. ## +## --------------------------------- ## + +# _LT_MANGLE_DEFUN(MACRO-NAME, OPTION-NAME) +# ----------------------------------------- +m4_define([_LT_MANGLE_DEFUN], +[[_LT_OPTION_DEFUN_]m4_bpatsubst(m4_toupper([$1__$2]), [[^A-Z0-9_]], [_])]) + + +# LT_OPTION_DEFINE(MACRO-NAME, OPTION-NAME, CODE) +# ----------------------------------------------- +m4_define([LT_OPTION_DEFINE], +[m4_define(_LT_MANGLE_DEFUN([$1], [$2]), [$3])[]dnl +])# LT_OPTION_DEFINE + + +# dlopen +# ------ +LT_OPTION_DEFINE([LT_INIT], [dlopen], [enable_dlopen=yes +]) + +AU_DEFUN([AC_LIBTOOL_DLOPEN], +[_LT_SET_OPTION([LT_INIT], [dlopen]) +AC_DIAGNOSE([obsolete], +[$0: Remove this warning and the call to _LT_SET_OPTION when you +put the 'dlopen' option into LT_INIT's first parameter.]) +]) + +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_LIBTOOL_DLOPEN], []) + + +# win32-dll +# --------- +# Declare package support for building win32 dll's. +LT_OPTION_DEFINE([LT_INIT], [win32-dll], +[enable_win32_dll=yes + +case $host in +*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-cegcc*) + AC_CHECK_TOOL(AS, as, false) + AC_CHECK_TOOL(DLLTOOL, dlltool, false) + AC_CHECK_TOOL(OBJDUMP, objdump, false) + ;; +esac + +test -z "$AS" && AS=as +_LT_DECL([], [AS], [1], [Assembler program])dnl + +test -z "$DLLTOOL" && DLLTOOL=dlltool +_LT_DECL([], [DLLTOOL], [1], [DLL creation program])dnl + +test -z "$OBJDUMP" && OBJDUMP=objdump +_LT_DECL([], [OBJDUMP], [1], [Object dumper program])dnl +])# win32-dll + +AU_DEFUN([AC_LIBTOOL_WIN32_DLL], +[AC_REQUIRE([AC_CANONICAL_HOST])dnl +_LT_SET_OPTION([LT_INIT], [win32-dll]) +AC_DIAGNOSE([obsolete], +[$0: Remove this warning and the call to _LT_SET_OPTION when you +put the 'win32-dll' option into LT_INIT's first parameter.]) +]) + +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_LIBTOOL_WIN32_DLL], []) + + +# _LT_ENABLE_SHARED([DEFAULT]) +# ---------------------------- +# implement the --enable-shared flag, and supports the 'shared' and +# 'disable-shared' LT_INIT options. +# DEFAULT is either 'yes' or 'no'. If omitted, it defaults to 'yes'. +m4_define([_LT_ENABLE_SHARED], +[m4_define([_LT_ENABLE_SHARED_DEFAULT], [m4_if($1, no, no, yes)])dnl +AC_ARG_ENABLE([shared], + [AS_HELP_STRING([--enable-shared@<:@=PKGS@:>@], + [build shared libraries @<:@default=]_LT_ENABLE_SHARED_DEFAULT[@:>@])], + [p=${PACKAGE-default} + case $enableval in + yes) enable_shared=yes ;; + no) enable_shared=no ;; + *) + enable_shared=no + # Look at the argument we got. We use all the common list separators. + lt_save_ifs=$IFS; IFS=$IFS$PATH_SEPARATOR, + for pkg in $enableval; do + IFS=$lt_save_ifs + if test "X$pkg" = "X$p"; then + enable_shared=yes + fi + done + IFS=$lt_save_ifs + ;; + esac], + [enable_shared=]_LT_ENABLE_SHARED_DEFAULT) + + _LT_DECL([build_libtool_libs], [enable_shared], [0], + [Whether or not to build shared libraries]) +])# _LT_ENABLE_SHARED + +LT_OPTION_DEFINE([LT_INIT], [shared], [_LT_ENABLE_SHARED([yes])]) +LT_OPTION_DEFINE([LT_INIT], [disable-shared], [_LT_ENABLE_SHARED([no])]) + +# Old names: +AC_DEFUN([AC_ENABLE_SHARED], +[_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[shared]) +]) + +AC_DEFUN([AC_DISABLE_SHARED], +[_LT_SET_OPTION([LT_INIT], [disable-shared]) +]) + +AU_DEFUN([AM_ENABLE_SHARED], [AC_ENABLE_SHARED($@)]) +AU_DEFUN([AM_DISABLE_SHARED], [AC_DISABLE_SHARED($@)]) + +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AM_ENABLE_SHARED], []) +dnl AC_DEFUN([AM_DISABLE_SHARED], []) + + + +# _LT_ENABLE_STATIC([DEFAULT]) +# ---------------------------- +# implement the --enable-static flag, and support the 'static' and +# 'disable-static' LT_INIT options. +# DEFAULT is either 'yes' or 'no'. If omitted, it defaults to 'yes'. +m4_define([_LT_ENABLE_STATIC], +[m4_define([_LT_ENABLE_STATIC_DEFAULT], [m4_if($1, no, no, yes)])dnl +AC_ARG_ENABLE([static], + [AS_HELP_STRING([--enable-static@<:@=PKGS@:>@], + [build static libraries @<:@default=]_LT_ENABLE_STATIC_DEFAULT[@:>@])], + [p=${PACKAGE-default} + case $enableval in + yes) enable_static=yes ;; + no) enable_static=no ;; + *) + enable_static=no + # Look at the argument we got. We use all the common list separators. + lt_save_ifs=$IFS; IFS=$IFS$PATH_SEPARATOR, + for pkg in $enableval; do + IFS=$lt_save_ifs + if test "X$pkg" = "X$p"; then + enable_static=yes + fi + done + IFS=$lt_save_ifs + ;; + esac], + [enable_static=]_LT_ENABLE_STATIC_DEFAULT) + + _LT_DECL([build_old_libs], [enable_static], [0], + [Whether or not to build static libraries]) +])# _LT_ENABLE_STATIC + +LT_OPTION_DEFINE([LT_INIT], [static], [_LT_ENABLE_STATIC([yes])]) +LT_OPTION_DEFINE([LT_INIT], [disable-static], [_LT_ENABLE_STATIC([no])]) + +# Old names: +AC_DEFUN([AC_ENABLE_STATIC], +[_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[static]) +]) + +AC_DEFUN([AC_DISABLE_STATIC], +[_LT_SET_OPTION([LT_INIT], [disable-static]) +]) + +AU_DEFUN([AM_ENABLE_STATIC], [AC_ENABLE_STATIC($@)]) +AU_DEFUN([AM_DISABLE_STATIC], [AC_DISABLE_STATIC($@)]) + +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AM_ENABLE_STATIC], []) +dnl AC_DEFUN([AM_DISABLE_STATIC], []) + + + +# _LT_ENABLE_FAST_INSTALL([DEFAULT]) +# ---------------------------------- +# implement the --enable-fast-install flag, and support the 'fast-install' +# and 'disable-fast-install' LT_INIT options. +# DEFAULT is either 'yes' or 'no'. If omitted, it defaults to 'yes'. +m4_define([_LT_ENABLE_FAST_INSTALL], +[m4_define([_LT_ENABLE_FAST_INSTALL_DEFAULT], [m4_if($1, no, no, yes)])dnl +AC_ARG_ENABLE([fast-install], + [AS_HELP_STRING([--enable-fast-install@<:@=PKGS@:>@], + [optimize for fast installation @<:@default=]_LT_ENABLE_FAST_INSTALL_DEFAULT[@:>@])], + [p=${PACKAGE-default} + case $enableval in + yes) enable_fast_install=yes ;; + no) enable_fast_install=no ;; + *) + enable_fast_install=no + # Look at the argument we got. We use all the common list separators. + lt_save_ifs=$IFS; IFS=$IFS$PATH_SEPARATOR, + for pkg in $enableval; do + IFS=$lt_save_ifs + if test "X$pkg" = "X$p"; then + enable_fast_install=yes + fi + done + IFS=$lt_save_ifs + ;; + esac], + [enable_fast_install=]_LT_ENABLE_FAST_INSTALL_DEFAULT) + +_LT_DECL([fast_install], [enable_fast_install], [0], + [Whether or not to optimize for fast installation])dnl +])# _LT_ENABLE_FAST_INSTALL + +LT_OPTION_DEFINE([LT_INIT], [fast-install], [_LT_ENABLE_FAST_INSTALL([yes])]) +LT_OPTION_DEFINE([LT_INIT], [disable-fast-install], [_LT_ENABLE_FAST_INSTALL([no])]) + +# Old names: +AU_DEFUN([AC_ENABLE_FAST_INSTALL], +[_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[fast-install]) +AC_DIAGNOSE([obsolete], +[$0: Remove this warning and the call to _LT_SET_OPTION when you put +the 'fast-install' option into LT_INIT's first parameter.]) +]) + +AU_DEFUN([AC_DISABLE_FAST_INSTALL], +[_LT_SET_OPTION([LT_INIT], [disable-fast-install]) +AC_DIAGNOSE([obsolete], +[$0: Remove this warning and the call to _LT_SET_OPTION when you put +the 'disable-fast-install' option into LT_INIT's first parameter.]) +]) + +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_ENABLE_FAST_INSTALL], []) +dnl AC_DEFUN([AM_DISABLE_FAST_INSTALL], []) + + +# _LT_WITH_AIX_SONAME([DEFAULT]) +# ---------------------------------- +# implement the --with-aix-soname flag, and support the `aix-soname=aix' +# and `aix-soname=both' and `aix-soname=svr4' LT_INIT options. DEFAULT +# is either `aix', `both' or `svr4'. If omitted, it defaults to `aix'. +m4_define([_LT_WITH_AIX_SONAME], +[m4_define([_LT_WITH_AIX_SONAME_DEFAULT], [m4_if($1, svr4, svr4, m4_if($1, both, both, aix))])dnl +shared_archive_member_spec= +case $host,$enable_shared in +power*-*-aix[[5-9]]*,yes) + AC_MSG_CHECKING([which variant of shared library versioning to provide]) + AC_ARG_WITH([aix-soname], + [AS_HELP_STRING([--with-aix-soname=aix|svr4|both], + [shared library versioning (aka "SONAME") variant to provide on AIX, @<:@default=]_LT_WITH_AIX_SONAME_DEFAULT[@:>@.])], + [case $withval in + aix|svr4|both) + ;; + *) + AC_MSG_ERROR([Unknown argument to --with-aix-soname]) + ;; + esac + lt_cv_with_aix_soname=$with_aix_soname], + [AC_CACHE_VAL([lt_cv_with_aix_soname], + [lt_cv_with_aix_soname=]_LT_WITH_AIX_SONAME_DEFAULT) + with_aix_soname=$lt_cv_with_aix_soname]) + AC_MSG_RESULT([$with_aix_soname]) + if test aix != "$with_aix_soname"; then + # For the AIX way of multilib, we name the shared archive member + # based on the bitwidth used, traditionally 'shr.o' or 'shr_64.o', + # and 'shr.imp' or 'shr_64.imp', respectively, for the Import File. + # Even when GNU compilers ignore OBJECT_MODE but need '-maix64' flag, + # the AIX toolchain works better with OBJECT_MODE set (default 32). + if test 64 = "${OBJECT_MODE-32}"; then + shared_archive_member_spec=shr_64 + else + shared_archive_member_spec=shr + fi + fi + ;; +*) + with_aix_soname=aix + ;; +esac + +_LT_DECL([], [shared_archive_member_spec], [0], + [Shared archive member basename, for filename based shared library versioning on AIX])dnl +])# _LT_WITH_AIX_SONAME + +LT_OPTION_DEFINE([LT_INIT], [aix-soname=aix], [_LT_WITH_AIX_SONAME([aix])]) +LT_OPTION_DEFINE([LT_INIT], [aix-soname=both], [_LT_WITH_AIX_SONAME([both])]) +LT_OPTION_DEFINE([LT_INIT], [aix-soname=svr4], [_LT_WITH_AIX_SONAME([svr4])]) + + +# _LT_WITH_PIC([MODE]) +# -------------------- +# implement the --with-pic flag, and support the 'pic-only' and 'no-pic' +# LT_INIT options. +# MODE is either 'yes' or 'no'. If omitted, it defaults to 'both'. +m4_define([_LT_WITH_PIC], +[AC_ARG_WITH([pic], + [AS_HELP_STRING([--with-pic@<:@=PKGS@:>@], + [try to use only PIC/non-PIC objects @<:@default=use both@:>@])], + [lt_p=${PACKAGE-default} + case $withval in + yes|no) pic_mode=$withval ;; + *) + pic_mode=default + # Look at the argument we got. We use all the common list separators. + lt_save_ifs=$IFS; IFS=$IFS$PATH_SEPARATOR, + for lt_pkg in $withval; do + IFS=$lt_save_ifs + if test "X$lt_pkg" = "X$lt_p"; then + pic_mode=yes + fi + done + IFS=$lt_save_ifs + ;; + esac], + [pic_mode=m4_default([$1], [default])]) + +_LT_DECL([], [pic_mode], [0], [What type of objects to build])dnl +])# _LT_WITH_PIC + +LT_OPTION_DEFINE([LT_INIT], [pic-only], [_LT_WITH_PIC([yes])]) +LT_OPTION_DEFINE([LT_INIT], [no-pic], [_LT_WITH_PIC([no])]) + +# Old name: +AU_DEFUN([AC_LIBTOOL_PICMODE], +[_LT_SET_OPTION([LT_INIT], [pic-only]) +AC_DIAGNOSE([obsolete], +[$0: Remove this warning and the call to _LT_SET_OPTION when you +put the 'pic-only' option into LT_INIT's first parameter.]) +]) + +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_LIBTOOL_PICMODE], []) + +## ----------------- ## +## LTDL_INIT Options ## +## ----------------- ## + +m4_define([_LTDL_MODE], []) +LT_OPTION_DEFINE([LTDL_INIT], [nonrecursive], + [m4_define([_LTDL_MODE], [nonrecursive])]) +LT_OPTION_DEFINE([LTDL_INIT], [recursive], + [m4_define([_LTDL_MODE], [recursive])]) +LT_OPTION_DEFINE([LTDL_INIT], [subproject], + [m4_define([_LTDL_MODE], [subproject])]) + +m4_define([_LTDL_TYPE], []) +LT_OPTION_DEFINE([LTDL_INIT], [installable], + [m4_define([_LTDL_TYPE], [installable])]) +LT_OPTION_DEFINE([LTDL_INIT], [convenience], + [m4_define([_LTDL_TYPE], [convenience])]) diff --git a/third_party/json-c/autoconf-archive/m4/ltsugar.m4 b/third_party/json-c/autoconf-archive/m4/ltsugar.m4 new file mode 100644 index 000000000..48bc9344a --- /dev/null +++ b/third_party/json-c/autoconf-archive/m4/ltsugar.m4 @@ -0,0 +1,124 @@ +# ltsugar.m4 -- libtool m4 base layer. -*-Autoconf-*- +# +# Copyright (C) 2004-2005, 2007-2008, 2011-2015 Free Software +# Foundation, Inc. +# Written by Gary V. Vaughan, 2004 +# +# This file is free software; the Free Software Foundation gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. + +# serial 6 ltsugar.m4 + +# This is to help aclocal find these macros, as it can't see m4_define. +AC_DEFUN([LTSUGAR_VERSION], [m4_if([0.1])]) + + +# lt_join(SEP, ARG1, [ARG2...]) +# ----------------------------- +# Produce ARG1SEPARG2...SEPARGn, omitting [] arguments and their +# associated separator. +# Needed until we can rely on m4_join from Autoconf 2.62, since all earlier +# versions in m4sugar had bugs. +m4_define([lt_join], +[m4_if([$#], [1], [], + [$#], [2], [[$2]], + [m4_if([$2], [], [], [[$2]_])$0([$1], m4_shift(m4_shift($@)))])]) +m4_define([_lt_join], +[m4_if([$#$2], [2], [], + [m4_if([$2], [], [], [[$1$2]])$0([$1], m4_shift(m4_shift($@)))])]) + + +# lt_car(LIST) +# lt_cdr(LIST) +# ------------ +# Manipulate m4 lists. +# These macros are necessary as long as will still need to support +# Autoconf-2.59, which quotes differently. +m4_define([lt_car], [[$1]]) +m4_define([lt_cdr], +[m4_if([$#], 0, [m4_fatal([$0: cannot be called without arguments])], + [$#], 1, [], + [m4_dquote(m4_shift($@))])]) +m4_define([lt_unquote], $1) + + +# lt_append(MACRO-NAME, STRING, [SEPARATOR]) +# ------------------------------------------ +# Redefine MACRO-NAME to hold its former content plus 'SEPARATOR''STRING'. +# Note that neither SEPARATOR nor STRING are expanded; they are appended +# to MACRO-NAME as is (leaving the expansion for when MACRO-NAME is invoked). +# No SEPARATOR is output if MACRO-NAME was previously undefined (different +# than defined and empty). +# +# This macro is needed until we can rely on Autoconf 2.62, since earlier +# versions of m4sugar mistakenly expanded SEPARATOR but not STRING. +m4_define([lt_append], +[m4_define([$1], + m4_ifdef([$1], [m4_defn([$1])[$3]])[$2])]) + + + +# lt_combine(SEP, PREFIX-LIST, INFIX, SUFFIX1, [SUFFIX2...]) +# ---------------------------------------------------------- +# Produce a SEP delimited list of all paired combinations of elements of +# PREFIX-LIST with SUFFIX1 through SUFFIXn. Each element of the list +# has the form PREFIXmINFIXSUFFIXn. +# Needed until we can rely on m4_combine added in Autoconf 2.62. +m4_define([lt_combine], +[m4_if(m4_eval([$# > 3]), [1], + [m4_pushdef([_Lt_sep], [m4_define([_Lt_sep], m4_defn([lt_car]))])]]dnl +[[m4_foreach([_Lt_prefix], [$2], + [m4_foreach([_Lt_suffix], + ]m4_dquote(m4_dquote(m4_shift(m4_shift(m4_shift($@)))))[, + [_Lt_sep([$1])[]m4_defn([_Lt_prefix])[$3]m4_defn([_Lt_suffix])])])])]) + + +# lt_if_append_uniq(MACRO-NAME, VARNAME, [SEPARATOR], [UNIQ], [NOT-UNIQ]) +# ----------------------------------------------------------------------- +# Iff MACRO-NAME does not yet contain VARNAME, then append it (delimited +# by SEPARATOR if supplied) and expand UNIQ, else NOT-UNIQ. +m4_define([lt_if_append_uniq], +[m4_ifdef([$1], + [m4_if(m4_index([$3]m4_defn([$1])[$3], [$3$2$3]), [-1], + [lt_append([$1], [$2], [$3])$4], + [$5])], + [lt_append([$1], [$2], [$3])$4])]) + + +# lt_dict_add(DICT, KEY, VALUE) +# ----------------------------- +m4_define([lt_dict_add], +[m4_define([$1($2)], [$3])]) + + +# lt_dict_add_subkey(DICT, KEY, SUBKEY, VALUE) +# -------------------------------------------- +m4_define([lt_dict_add_subkey], +[m4_define([$1($2:$3)], [$4])]) + + +# lt_dict_fetch(DICT, KEY, [SUBKEY]) +# ---------------------------------- +m4_define([lt_dict_fetch], +[m4_ifval([$3], + m4_ifdef([$1($2:$3)], [m4_defn([$1($2:$3)])]), + m4_ifdef([$1($2)], [m4_defn([$1($2)])]))]) + + +# lt_if_dict_fetch(DICT, KEY, [SUBKEY], VALUE, IF-TRUE, [IF-FALSE]) +# ----------------------------------------------------------------- +m4_define([lt_if_dict_fetch], +[m4_if(lt_dict_fetch([$1], [$2], [$3]), [$4], + [$5], + [$6])]) + + +# lt_dict_filter(DICT, [SUBKEY], VALUE, [SEPARATOR], KEY, [...]) +# -------------------------------------------------------------- +m4_define([lt_dict_filter], +[m4_if([$5], [], [], + [lt_join(m4_quote(m4_default([$4], [[, ]])), + lt_unquote(m4_split(m4_normalize(m4_foreach(_Lt_key, lt_car([m4_shiftn(4, $@)]), + [lt_if_dict_fetch([$1], _Lt_key, [$2], [$3], [_Lt_key ])])))))])[]dnl +]) diff --git a/third_party/json-c/autoconf-archive/m4/ltversion.m4 b/third_party/json-c/autoconf-archive/m4/ltversion.m4 new file mode 100644 index 000000000..fa04b52a3 --- /dev/null +++ b/third_party/json-c/autoconf-archive/m4/ltversion.m4 @@ -0,0 +1,23 @@ +# ltversion.m4 -- version numbers -*- Autoconf -*- +# +# Copyright (C) 2004, 2011-2015 Free Software Foundation, Inc. +# Written by Scott James Remnant, 2004 +# +# This file is free software; the Free Software Foundation gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. + +# @configure_input@ + +# serial 4179 ltversion.m4 +# This file is part of GNU Libtool + +m4_define([LT_PACKAGE_VERSION], [2.4.6]) +m4_define([LT_PACKAGE_REVISION], [2.4.6]) + +AC_DEFUN([LTVERSION_VERSION], +[macro_version='2.4.6' +macro_revision='2.4.6' +_LT_DECL(, macro_version, 0, [Which release of libtool.m4 was used?]) +_LT_DECL(, macro_revision, 0) +]) diff --git a/third_party/json-c/autoconf-archive/m4/lt~obsolete.m4 b/third_party/json-c/autoconf-archive/m4/lt~obsolete.m4 new file mode 100644 index 000000000..c6b26f88f --- /dev/null +++ b/third_party/json-c/autoconf-archive/m4/lt~obsolete.m4 @@ -0,0 +1,99 @@ +# lt~obsolete.m4 -- aclocal satisfying obsolete definitions. -*-Autoconf-*- +# +# Copyright (C) 2004-2005, 2007, 2009, 2011-2015 Free Software +# Foundation, Inc. +# Written by Scott James Remnant, 2004. +# +# This file is free software; the Free Software Foundation gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. + +# serial 5 lt~obsolete.m4 + +# These exist entirely to fool aclocal when bootstrapping libtool. +# +# In the past libtool.m4 has provided macros via AC_DEFUN (or AU_DEFUN), +# which have later been changed to m4_define as they aren't part of the +# exported API, or moved to Autoconf or Automake where they belong. +# +# The trouble is, aclocal is a bit thick. It'll see the old AC_DEFUN +# in /usr/share/aclocal/libtool.m4 and remember it, then when it sees us +# using a macro with the same name in our local m4/libtool.m4 it'll +# pull the old libtool.m4 in (it doesn't see our shiny new m4_define +# and doesn't know about Autoconf macros at all.) +# +# So we provide this file, which has a silly filename so it's always +# included after everything else. This provides aclocal with the +# AC_DEFUNs it wants, but when m4 processes it, it doesn't do anything +# because those macros already exist, or will be overwritten later. +# We use AC_DEFUN over AU_DEFUN for compatibility with aclocal-1.6. +# +# Anytime we withdraw an AC_DEFUN or AU_DEFUN, remember to add it here. +# Yes, that means every name once taken will need to remain here until +# we give up compatibility with versions before 1.7, at which point +# we need to keep only those names which we still refer to. + +# This is to help aclocal find these macros, as it can't see m4_define. +AC_DEFUN([LTOBSOLETE_VERSION], [m4_if([1])]) + +m4_ifndef([AC_LIBTOOL_LINKER_OPTION], [AC_DEFUN([AC_LIBTOOL_LINKER_OPTION])]) +m4_ifndef([AC_PROG_EGREP], [AC_DEFUN([AC_PROG_EGREP])]) +m4_ifndef([_LT_AC_PROG_ECHO_BACKSLASH], [AC_DEFUN([_LT_AC_PROG_ECHO_BACKSLASH])]) +m4_ifndef([_LT_AC_SHELL_INIT], [AC_DEFUN([_LT_AC_SHELL_INIT])]) +m4_ifndef([_LT_AC_SYS_LIBPATH_AIX], [AC_DEFUN([_LT_AC_SYS_LIBPATH_AIX])]) +m4_ifndef([_LT_PROG_LTMAIN], [AC_DEFUN([_LT_PROG_LTMAIN])]) +m4_ifndef([_LT_AC_TAGVAR], [AC_DEFUN([_LT_AC_TAGVAR])]) +m4_ifndef([AC_LTDL_ENABLE_INSTALL], [AC_DEFUN([AC_LTDL_ENABLE_INSTALL])]) +m4_ifndef([AC_LTDL_PREOPEN], [AC_DEFUN([AC_LTDL_PREOPEN])]) +m4_ifndef([_LT_AC_SYS_COMPILER], [AC_DEFUN([_LT_AC_SYS_COMPILER])]) +m4_ifndef([_LT_AC_LOCK], [AC_DEFUN([_LT_AC_LOCK])]) +m4_ifndef([AC_LIBTOOL_SYS_OLD_ARCHIVE], [AC_DEFUN([AC_LIBTOOL_SYS_OLD_ARCHIVE])]) +m4_ifndef([_LT_AC_TRY_DLOPEN_SELF], [AC_DEFUN([_LT_AC_TRY_DLOPEN_SELF])]) +m4_ifndef([AC_LIBTOOL_PROG_CC_C_O], [AC_DEFUN([AC_LIBTOOL_PROG_CC_C_O])]) +m4_ifndef([AC_LIBTOOL_SYS_HARD_LINK_LOCKS], [AC_DEFUN([AC_LIBTOOL_SYS_HARD_LINK_LOCKS])]) +m4_ifndef([AC_LIBTOOL_OBJDIR], [AC_DEFUN([AC_LIBTOOL_OBJDIR])]) +m4_ifndef([AC_LTDL_OBJDIR], [AC_DEFUN([AC_LTDL_OBJDIR])]) +m4_ifndef([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH], [AC_DEFUN([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH])]) +m4_ifndef([AC_LIBTOOL_SYS_LIB_STRIP], [AC_DEFUN([AC_LIBTOOL_SYS_LIB_STRIP])]) +m4_ifndef([AC_PATH_MAGIC], [AC_DEFUN([AC_PATH_MAGIC])]) +m4_ifndef([AC_PROG_LD_GNU], [AC_DEFUN([AC_PROG_LD_GNU])]) +m4_ifndef([AC_PROG_LD_RELOAD_FLAG], [AC_DEFUN([AC_PROG_LD_RELOAD_FLAG])]) +m4_ifndef([AC_DEPLIBS_CHECK_METHOD], [AC_DEFUN([AC_DEPLIBS_CHECK_METHOD])]) +m4_ifndef([AC_LIBTOOL_PROG_COMPILER_NO_RTTI], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_NO_RTTI])]) +m4_ifndef([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE], [AC_DEFUN([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE])]) +m4_ifndef([AC_LIBTOOL_PROG_COMPILER_PIC], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_PIC])]) +m4_ifndef([AC_LIBTOOL_PROG_LD_SHLIBS], [AC_DEFUN([AC_LIBTOOL_PROG_LD_SHLIBS])]) +m4_ifndef([AC_LIBTOOL_POSTDEP_PREDEP], [AC_DEFUN([AC_LIBTOOL_POSTDEP_PREDEP])]) +m4_ifndef([LT_AC_PROG_EGREP], [AC_DEFUN([LT_AC_PROG_EGREP])]) +m4_ifndef([LT_AC_PROG_SED], [AC_DEFUN([LT_AC_PROG_SED])]) +m4_ifndef([_LT_CC_BASENAME], [AC_DEFUN([_LT_CC_BASENAME])]) +m4_ifndef([_LT_COMPILER_BOILERPLATE], [AC_DEFUN([_LT_COMPILER_BOILERPLATE])]) +m4_ifndef([_LT_LINKER_BOILERPLATE], [AC_DEFUN([_LT_LINKER_BOILERPLATE])]) +m4_ifndef([_AC_PROG_LIBTOOL], [AC_DEFUN([_AC_PROG_LIBTOOL])]) +m4_ifndef([AC_LIBTOOL_SETUP], [AC_DEFUN([AC_LIBTOOL_SETUP])]) +m4_ifndef([_LT_AC_CHECK_DLFCN], [AC_DEFUN([_LT_AC_CHECK_DLFCN])]) +m4_ifndef([AC_LIBTOOL_SYS_DYNAMIC_LINKER], [AC_DEFUN([AC_LIBTOOL_SYS_DYNAMIC_LINKER])]) +m4_ifndef([_LT_AC_TAGCONFIG], [AC_DEFUN([_LT_AC_TAGCONFIG])]) +m4_ifndef([AC_DISABLE_FAST_INSTALL], [AC_DEFUN([AC_DISABLE_FAST_INSTALL])]) +m4_ifndef([_LT_AC_LANG_CXX], [AC_DEFUN([_LT_AC_LANG_CXX])]) +m4_ifndef([_LT_AC_LANG_F77], [AC_DEFUN([_LT_AC_LANG_F77])]) +m4_ifndef([_LT_AC_LANG_GCJ], [AC_DEFUN([_LT_AC_LANG_GCJ])]) +m4_ifndef([AC_LIBTOOL_LANG_C_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_C_CONFIG])]) +m4_ifndef([_LT_AC_LANG_C_CONFIG], [AC_DEFUN([_LT_AC_LANG_C_CONFIG])]) +m4_ifndef([AC_LIBTOOL_LANG_CXX_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_CXX_CONFIG])]) +m4_ifndef([_LT_AC_LANG_CXX_CONFIG], [AC_DEFUN([_LT_AC_LANG_CXX_CONFIG])]) +m4_ifndef([AC_LIBTOOL_LANG_F77_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_F77_CONFIG])]) +m4_ifndef([_LT_AC_LANG_F77_CONFIG], [AC_DEFUN([_LT_AC_LANG_F77_CONFIG])]) +m4_ifndef([AC_LIBTOOL_LANG_GCJ_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_GCJ_CONFIG])]) +m4_ifndef([_LT_AC_LANG_GCJ_CONFIG], [AC_DEFUN([_LT_AC_LANG_GCJ_CONFIG])]) +m4_ifndef([AC_LIBTOOL_LANG_RC_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_RC_CONFIG])]) +m4_ifndef([_LT_AC_LANG_RC_CONFIG], [AC_DEFUN([_LT_AC_LANG_RC_CONFIG])]) +m4_ifndef([AC_LIBTOOL_CONFIG], [AC_DEFUN([AC_LIBTOOL_CONFIG])]) +m4_ifndef([_LT_AC_FILE_LTDLL_C], [AC_DEFUN([_LT_AC_FILE_LTDLL_C])]) +m4_ifndef([_LT_REQUIRED_DARWIN_CHECKS], [AC_DEFUN([_LT_REQUIRED_DARWIN_CHECKS])]) +m4_ifndef([_LT_AC_PROG_CXXCPP], [AC_DEFUN([_LT_AC_PROG_CXXCPP])]) +m4_ifndef([_LT_PREPARE_SED_QUOTE_VARS], [AC_DEFUN([_LT_PREPARE_SED_QUOTE_VARS])]) +m4_ifndef([_LT_PROG_ECHO_BACKSLASH], [AC_DEFUN([_LT_PROG_ECHO_BACKSLASH])]) +m4_ifndef([_LT_PROG_F77], [AC_DEFUN([_LT_PROG_F77])]) +m4_ifndef([_LT_PROG_FC], [AC_DEFUN([_LT_PROG_FC])]) +m4_ifndef([_LT_PROG_CXX], [AC_DEFUN([_LT_PROG_CXX])]) diff --git a/third_party/json-c/autogen.sh b/third_party/json-c/autogen.sh deleted file mode 100755 index 69e765a60..000000000 --- a/third_party/json-c/autogen.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/sh -autoreconf -v --install || exit 1 - -# If there are any options, assume the user wants to run configure. -# To run configure w/o any options, use ./autogen.sh --configure -if [ $# -gt 0 ] ; then - case "$1" in - --conf*) - shift 1 - ;; - esac - exec ./configure "$@" -fi diff --git a/third_party/json-c/bench/README.bench.md b/third_party/json-c/bench/README.bench.md new file mode 100644 index 000000000..c37cb1a69 --- /dev/null +++ b/third_party/json-c/bench/README.bench.md @@ -0,0 +1,80 @@ + +Benchmark tests for json-c + +General strategy: +------------------- + +* Identify "after" commit hash + * Use provided directory + * Use provided commit hash + * Local changes in current working directory + * ${cur_branch} +* Identify "before" commit hash, in order of preference + * Use provided directory + * Use provided commit hash + * Use origin/${cur_branch}, if different from ${after_commit} + * Use previous release + +* If not using existing dir, clone to src-${after_commit} + * or, checkout appropriate commit in existing src-${after_commit} +* Create build & install dirs for ${after_commit} +* Build & install ${after_commit} +* Compile benchmark programs against install-${after_commit} + +* If not using existing dir, clone to src-${before_commit} + * or, checkout appropriate commit in existing src-${before_commit} +* Create build & install dirs for ${before_commit} +* Build & install ${before_commit} +* Compile benchmark programs against install-${before_commit} + +* Run benchmark in each location +* Compare results + +heaptrack memory profiler +--------------------------- + +https://milianw.de/blog/heaptrack-a-heap-memory-profiler-for-linux.html + + +``` +yum install libdwarf-devel elfutils boost-devel libunwind-devel + +git clone git://anongit.kde.org/heaptrack +cd heaptrack +mkdir build +cd build +cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo \ + -DCMAKE_INSTALL_PREFIX=$HOME/heaptrack-install .. +make install +``` + + +Issues +-------- + +* jc-bench.sh is incomplete. + +* valgrind massif misreports "extra-heap" bytes? + + "json_parse -n canada.json" shows 38640 KB maxrss. + + Using valgrind --tool=massif, a large amount of memory is listed as + wasted "extra-heap" bytes. (~5.6MB) + + ``` + valgrind --tool=massif --massif-out-file=massif.out ./json_parse -n ~/canada.json + ms_print massif.out + ``` + + + Using heaptrack, and analyzing the histogram, only shows ~2.6MB + ``` + heaptrack ./json_parse -n canada.json + heaptrack --analyze heaptrack*gz -H histogram.out + awk ' { s=$1; count=$2; ru=(int((s+ 15) / 16)) * 16; wasted = ((ru-s)*count); print s, count, ru-s, wasted; total=total+wasted} END { print "Total: ", total }' histogram.out + ``` + + With the (unreleased) arraylist trimming changes, maxrss reported by + getrusage() goes down, but massif claims *more* total usage, and a HUGE + extra-heap amount (50% of total). + diff --git a/third_party/json-c/bench/jc-bench.sh b/third_party/json-c/bench/jc-bench.sh new file mode 100755 index 000000000..06a0242af --- /dev/null +++ b/third_party/json-c/bench/jc-bench.sh @@ -0,0 +1,284 @@ +#!/bin/sh +# +# Benchmarking harness for json-c +# +# Use this to compare the behavior of two different versions of the library, +# such as json-c-0.14 release vs master, master vs local changes, etc... +# + +set -e + +trap 'echo "FAILED!"' EXIT + +RUNDIR=$(dirname "$0") +RUNDIR=$(cd "$RUNDIR" && pwd) + +TOP=$(cd "$RUNDIR/.." && pwd) + +usage() +{ + exitval=$1 + errmsg=$2 + if [ $exitval -ne 0 ] ; then + exec 1>&2 + fi + if [ ! -z "$errmsg" ] ; then + echo "ERROR: $errmsg" 1>&2 + fi + cat < $_commit] as 'after'" + else + # Local changes in current working directory + # ${cur_branch} + after_src_dir=$TOP + after_commit= + echo "Using local changes in $TOP as 'after'" + fi +fi + +# Identify "before" commit hash, in order of preference +if [ ! -z "$before_arg" -a -d "$before_arg" ] ; then + # Use provided directory + before_src_dir="$before_arg" + before_commit= + echo "Using provided directory [$before_arg] as 'before'" +else + _commit= + if [ ! -z "$before_arg" ] ; then + # Use provided commit hash + _commit=$(git rev-parse --verify "$before_arg") + fi + if [ ! -z "$_commit" ] ;then + before_src_dir= # i.e. current tree + before_commit="$_commit" + echo "Using provided commit [$before_arg => $_commit] as 'before'" + else + # Use origin/${cur_branch}, if different from ${after_commit} + _cur_branch=$(git rev-parse --abbrev-ref HEAD) + _commit= + if [ ! -z "${_cur_branch}" ] ; then + _commit=$(git rev-parse --verify "origin/${_cur_branch}") + echo "Using origin/${_cur_branch} [$_commit] as 'before'" + fi + if [ "$_commit" = "${after_commit}" ] ; then + _commit= + fi + fi + + if [ ! -z "$_commit" ] ; then + before_src_dir= # i.e. current tree + before_commit="$_commit" + else + # Use previous release + before_src_dir= # i.e. current tree + before_commit="$(git tag | sort | tail -1)" + echo "Using previous release [$before_commit] as 'before'" + fi +fi + +echo + +compile_benchmark() +{ + local bname=$1 + local src_dir="$2" + local src_commit="$3" + + local build_dir="${WORK}/$bname/build" + local inst_dir="${WORK}/$bname/install" + local bench_dir="${WORK}/$bname/bench" + + echo + echo "=========== $bname ===========" + echo + + mkdir -p "${build_dir}" + mkdir -p "${inst_dir}" + mkdir -p "${bench_dir}" + + if [ ! -z "$src_commit" ] ; then + # Resolve the short hash, tag or branch name to full hash + src_commit=$(git rev-parse $src_commit) + fi + + # No src dir specified, clone and checkout $src_commit + if [ -z "$src_dir" ] ; then + src_dir="${WORK}/$bname/src" + echo "=== Using sources in $src_dir" + mkdir -p "$src_dir" + at_commit=$(git --git-dir="$src_dir/.git" rev-parse HEAD 2> /dev/null || true) + echo "at_commit: $at_commit" + if [ -z "$at_commit" ] ; then + # Assume it's an empty dir + git clone -n "$TOP" "$src_dir" + fi + git -C "$src_dir" --git-dir="$src_dir/.git" checkout "$src_commit" + fi + # else, use the provided $src_dir + + if [ -e "${src_dir}/CMakeLists.txt" ] ; then + cd "${build_dir}" + cmake -DCMAKE_INSTALL_PREFIX="${inst_dir}" "${src_dir}" + else + # Old versions of json-c used automake/autoconf + cd "${src_dir}" + sh autogen.sh # always run it, configure doesn't always work + cd "${build_dir}" + "${src_dir}/configure" --prefix="${inst_dir}" + fi + make all install + + cd "${bench_dir}" + cmake -DCMAKE_PREFIX_PATH="${inst_dir}" "${TOP}/apps" + make all +} + +# XXX TODO: name "after" and "before" uniquely using the dir & commit + +if [ $do_all -ne 0 -o $do_build -ne 0 ] ; then + sleep 5 # Wait slightly, to allow the human to read the message + # about what exactly we're doing to benchmark. + compile_benchmark "after" "${after_src_dir}" "${after_commit}" + compile_benchmark "before" "${before_src_dir}" "${before_commit}" +fi + +run_benchmark() +{ + local bname=$1 + local inst_dir="${WORK}/$bname/install" + local bench_dir="${WORK}/$bname/bench" + + local INPUT=${DATA}/canada.json + + cd "${bench_dir}" + mkdir -p results + (time ./json_parse -n "${INPUT}") > results/basic_timing.out 2>&1 + valgrind --tool=massif --massif-out-file=massif.out ./json_parse -n "${INPUT}" + ms_print massif.out > results/ms_print.out + heaptrack -o heaptrack_out ./json_parse -n "${INPUT}" + heaptrack --analyze heaptrack_out.gz -H histogram.out > results/heaptrack.out + awk ' { s=$1; count=$2; ru=(int((s+ 15) / 16)) * 16; wasted = ((ru-s)*count); print s, count, ru-s, wasted; total=total+wasted} END { print "Total: ", total }' histogram.out > results/histogram2.out + + # XXX stamp some info about what was built & run into ./results/. + + echo "DONE with $bname" +} + +if [ $do_all -ne 0 -o $do_run -ne 0 ] ; then + run_benchmark "after" + run_benchmark "before" +fi + +if [ $do_compare -ne 0 ] ; then + # XXX this needs better analysis + cd "${WORK}" + diff -udr before/bench/results after/bench/results || true +else + echo "To compare results, run:" + echo "$0 --compare" +fi + +trap '' EXIT + +:<<=cut + +Benchmarks to run: + +* Parse JSON strings, of various sizes and characteristics + * Flags: STRICT vs. non-STRICT, validate UTF8 + +* Serialization time + * plain, spaces, pretty + +* json_c_visit tests +* JSON pointer tests + +Things to record and compare: + +* Running time +* Peak memory usage +* Useful bytes vs. overhead for memory allocations +* Total number of allocations +* Average allocation size +* Log of all allocation sizes + +=cut + diff --git a/third_party/json-c/bits.h b/third_party/json-c/bits.h deleted file mode 100644 index 14c1c132d..000000000 --- a/third_party/json-c/bits.h +++ /dev/null @@ -1,36 +0,0 @@ -/** - * @file - * @brief Do not use, only contains deprecated defines. - * @deprecated Use json_util.h instead. - * - * $Id: bits.h,v 1.10 2006/01/30 23:07:57 mclark Exp $ - * - * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd. - * Michael Clark - * - * This library is free software; you can redistribute it and/or modify - * it under the terms of the MIT license. See COPYING for details. - * - */ - -#ifndef _bits_h_ -#define _bits_h_ - -/** - * @deprecated - */ -#define hexdigit(x) (((x) <= '9') ? (x) - '0' : ((x) & 7) + 9) -/** - * @deprecated - */ -#define error_ptr(error) ((void*)error) -/** - * @deprecated - */ -#define error_description(error) (json_tokener_get_error(error)) -/** - * @deprecated - */ -#define is_error(ptr) (ptr == NULL) - -#endif diff --git a/third_party/json-c/cmake-configure b/third_party/json-c/cmake-configure new file mode 100755 index 000000000..7110bd0b6 --- /dev/null +++ b/third_party/json-c/cmake-configure @@ -0,0 +1,100 @@ +#!/bin/bash + +# Wrapper around cmake to emulate useful options +# from the previous autoconf-based configure script. + +RUNDIR=$(dirname "$0") +RUNDIR=$(cd "$RUNDIR" && pwd) +CURDIR=$(pwd) + +FLAGS=() + +usage() +{ + exitval="$1" + errmsg="$2" + + if [ $exitval -ne 0 ] ; then + exec 1>&2 + fi + if [ ! -z "$errmsg" ] ; then + echo "ERROR: $errmsg" 1>&2 + fi + cat <] [-- []] + --prefix=PREFIX install architecture-independent files in PREFIX + --enable-threading Enable code to support partly multi-threaded use + --enable-rdrand Enable RDRAND Hardware RNG Hash Seed generation on + supported x86/x64 platforms. + --enable-shared build shared libraries [default=yes] + --enable-static build static libraries [default=yes] + --disable-Bsymbolic Avoid linking with -Bsymbolic-function + --disable-werror Avoid treating compiler warnings as fatal errors + --disable-extra-libs Avoid linking against extra libraries, such as libbsd + +EOF + exit +} + +if [ "$CURDIR" = "$RUNDIR" ] ; then + usage 1 "Please mkdir some other build directory, and run this script from there." +fi + +if ! cmake --version ; then + usage 1 "Unable to find a working cmake, please be sure you have it installed and on your PATH" +fi + +while [ $# -gt 0 ] ; do + case "$1" in + -h|--help) + usage 0 + ;; + --prefix) + FLAGS+=(-DCMAKE_INSTALL_PREFIX="$2") + shift + ;; + --prefix=*) + FLAGS+=(-DCMAKE_INSTALL_PREFIX="${1##--prefix=}") + ;; + --enable-threading) + FLAGS+=(-DENABLE_THREADING=ON) + ;; + --enable-rdrand) + FLAGS+=(-DENABLE_RDRAND=ON) + ;; + --enable-shared) + FLAGS+=(-DBUILD_SHARED_LIBS=ON) + ;; + --disable-shared) + FLAGS+=(-DBUILD_SHARED_LIBS=OFF) + ;; + --enable-static) + FLAGS+=(-DBUILD_STATIC_LIBS=ON) + ;; + --disable-static) + FLAGS+=(-DBUILD_STATIC_LIBS=OFF) + ;; + --disable-Bsymbolic) + FLAGS+=(-DDISABLE_BSYMBOLIC=ON) + ;; + --disable-werror) + FLAGS+=(-DDISABLE_WERROR=ON) + ;; + --disable-extra-libs) + FLAGS+=(-DDISABLE_EXTRA_LIBS=ON) + ;; + --) + shift + break + ;; + -*) + usage 1 "Unknown arguments: $*" + ;; + *) + break + ;; + esac + shift +done + +exec cmake "${FLAGS[@]}" "$@" "${RUNDIR}" diff --git a/third_party/json-c/cmake/Config.cmake.in b/third_party/json-c/cmake/Config.cmake.in new file mode 100644 index 000000000..035dc0fa0 --- /dev/null +++ b/third_party/json-c/cmake/Config.cmake.in @@ -0,0 +1,4 @@ +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-targets.cmake") +check_required_components("@PROJECT_NAME@") diff --git a/third_party/json-c/cmake/json_config.h.in b/third_party/json-c/cmake/json_config.h.in new file mode 100644 index 000000000..790fd7e33 --- /dev/null +++ b/third_party/json-c/cmake/json_config.h.in @@ -0,0 +1,5 @@ +/* Define to 1 if you have the header file. */ +#cmakedefine JSON_C_HAVE_INTTYPES_H @JSON_C_HAVE_INTTYPES_H@ + +/* Define to 1 if you have the header file. */ +#cmakedefine JSON_C_HAVE_STDINT_H @JSON_C_HAVE_STDINT_H@ diff --git a/third_party/json-c/compile b/third_party/json-c/compile new file mode 100755 index 000000000..df363c8fb --- /dev/null +++ b/third_party/json-c/compile @@ -0,0 +1,348 @@ +#! /bin/sh +# Wrapper for compilers which do not understand '-c -o'. + +scriptversion=2018-03-07.03; # UTC + +# Copyright (C) 1999-2021 Free Software Foundation, Inc. +# Written by Tom Tromey . +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + +# This file is maintained in Automake, please report +# bugs to or send patches to +# . + +nl=' +' + +# We need space, tab and new line, in precisely that order. Quoting is +# there to prevent tools from complaining about whitespace usage. +IFS=" "" $nl" + +file_conv= + +# func_file_conv build_file lazy +# Convert a $build file to $host form and store it in $file +# Currently only supports Windows hosts. If the determined conversion +# type is listed in (the comma separated) LAZY, no conversion will +# take place. +func_file_conv () +{ + file=$1 + case $file in + / | /[!/]*) # absolute file, and not a UNC file + if test -z "$file_conv"; then + # lazily determine how to convert abs files + case `uname -s` in + MINGW*) + file_conv=mingw + ;; + CYGWIN* | MSYS*) + file_conv=cygwin + ;; + *) + file_conv=wine + ;; + esac + fi + case $file_conv/,$2, in + *,$file_conv,*) + ;; + mingw/*) + file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` + ;; + cygwin/* | msys/*) + file=`cygpath -m "$file" || echo "$file"` + ;; + wine/*) + file=`winepath -w "$file" || echo "$file"` + ;; + esac + ;; + esac +} + +# func_cl_dashL linkdir +# Make cl look for libraries in LINKDIR +func_cl_dashL () +{ + func_file_conv "$1" + if test -z "$lib_path"; then + lib_path=$file + else + lib_path="$lib_path;$file" + fi + linker_opts="$linker_opts -LIBPATH:$file" +} + +# func_cl_dashl library +# Do a library search-path lookup for cl +func_cl_dashl () +{ + lib=$1 + found=no + save_IFS=$IFS + IFS=';' + for dir in $lib_path $LIB + do + IFS=$save_IFS + if $shared && test -f "$dir/$lib.dll.lib"; then + found=yes + lib=$dir/$lib.dll.lib + break + fi + if test -f "$dir/$lib.lib"; then + found=yes + lib=$dir/$lib.lib + break + fi + if test -f "$dir/lib$lib.a"; then + found=yes + lib=$dir/lib$lib.a + break + fi + done + IFS=$save_IFS + + if test "$found" != yes; then + lib=$lib.lib + fi +} + +# func_cl_wrapper cl arg... +# Adjust compile command to suit cl +func_cl_wrapper () +{ + # Assume a capable shell + lib_path= + shared=: + linker_opts= + for arg + do + if test -n "$eat"; then + eat= + else + case $1 in + -o) + # configure might choose to run compile as 'compile cc -o foo foo.c'. + eat=1 + case $2 in + *.o | *.[oO][bB][jJ]) + func_file_conv "$2" + set x "$@" -Fo"$file" + shift + ;; + *) + func_file_conv "$2" + set x "$@" -Fe"$file" + shift + ;; + esac + ;; + -I) + eat=1 + func_file_conv "$2" mingw + set x "$@" -I"$file" + shift + ;; + -I*) + func_file_conv "${1#-I}" mingw + set x "$@" -I"$file" + shift + ;; + -l) + eat=1 + func_cl_dashl "$2" + set x "$@" "$lib" + shift + ;; + -l*) + func_cl_dashl "${1#-l}" + set x "$@" "$lib" + shift + ;; + -L) + eat=1 + func_cl_dashL "$2" + ;; + -L*) + func_cl_dashL "${1#-L}" + ;; + -static) + shared=false + ;; + -Wl,*) + arg=${1#-Wl,} + save_ifs="$IFS"; IFS=',' + for flag in $arg; do + IFS="$save_ifs" + linker_opts="$linker_opts $flag" + done + IFS="$save_ifs" + ;; + -Xlinker) + eat=1 + linker_opts="$linker_opts $2" + ;; + -*) + set x "$@" "$1" + shift + ;; + *.cc | *.CC | *.cxx | *.CXX | *.[cC]++) + func_file_conv "$1" + set x "$@" -Tp"$file" + shift + ;; + *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO]) + func_file_conv "$1" mingw + set x "$@" "$file" + shift + ;; + *) + set x "$@" "$1" + shift + ;; + esac + fi + shift + done + if test -n "$linker_opts"; then + linker_opts="-link$linker_opts" + fi + exec "$@" $linker_opts + exit 1 +} + +eat= + +case $1 in + '') + echo "$0: No command. Try '$0 --help' for more information." 1>&2 + exit 1; + ;; + -h | --h*) + cat <<\EOF +Usage: compile [--help] [--version] PROGRAM [ARGS] + +Wrapper for compilers which do not understand '-c -o'. +Remove '-o dest.o' from ARGS, run PROGRAM with the remaining +arguments, and rename the output as expected. + +If you are trying to build a whole package this is not the +right script to run: please start by reading the file 'INSTALL'. + +Report bugs to . +EOF + exit $? + ;; + -v | --v*) + echo "compile $scriptversion" + exit $? + ;; + cl | *[/\\]cl | cl.exe | *[/\\]cl.exe | \ + icl | *[/\\]icl | icl.exe | *[/\\]icl.exe ) + func_cl_wrapper "$@" # Doesn't return... + ;; +esac + +ofile= +cfile= + +for arg +do + if test -n "$eat"; then + eat= + else + case $1 in + -o) + # configure might choose to run compile as 'compile cc -o foo foo.c'. + # So we strip '-o arg' only if arg is an object. + eat=1 + case $2 in + *.o | *.obj) + ofile=$2 + ;; + *) + set x "$@" -o "$2" + shift + ;; + esac + ;; + *.c) + cfile=$1 + set x "$@" "$1" + shift + ;; + *) + set x "$@" "$1" + shift + ;; + esac + fi + shift +done + +if test -z "$ofile" || test -z "$cfile"; then + # If no '-o' option was seen then we might have been invoked from a + # pattern rule where we don't need one. That is ok -- this is a + # normal compilation that the losing compiler can handle. If no + # '.c' file was seen then we are probably linking. That is also + # ok. + exec "$@" +fi + +# Name of file we expect compiler to create. +cofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` + +# Create the lock directory. +# Note: use '[/\\:.-]' here to ensure that we don't use the same name +# that we are using for the .o file. Also, base the name on the expected +# object file name, since that is what matters with a parallel build. +lockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d +while true; do + if mkdir "$lockdir" >/dev/null 2>&1; then + break + fi + sleep 1 +done +# FIXME: race condition here if user kills between mkdir and trap. +trap "rmdir '$lockdir'; exit 1" 1 2 15 + +# Run the compile. +"$@" +ret=$? + +if test -f "$cofile"; then + test "$cofile" = "$ofile" || mv "$cofile" "$ofile" +elif test -f "${cofile}bj"; then + test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" +fi + +rmdir "$lockdir" +exit $ret + +# Local Variables: +# mode: shell-script +# sh-indentation: 2 +# eval: (add-hook 'before-save-hook 'time-stamp) +# time-stamp-start: "scriptversion=" +# time-stamp-format: "%:y-%02m-%02d.%02H" +# time-stamp-time-zone: "UTC0" +# time-stamp-end: "; # UTC" +# End: diff --git a/third_party/json-c/config.guess b/third_party/json-c/config.guess new file mode 100755 index 000000000..7f76b6228 --- /dev/null +++ b/third_party/json-c/config.guess @@ -0,0 +1,1754 @@ +#! /bin/sh +# Attempt to guess a canonical system name. +# Copyright 1992-2022 Free Software Foundation, Inc. + +# shellcheck disable=SC2006,SC2268 # see below for rationale + +timestamp='2022-01-09' + +# This file is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, see . +# +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that +# program. This Exception is an additional permission under section 7 +# of the GNU General Public License, version 3 ("GPLv3"). +# +# Originally written by Per Bothner; maintained since 2000 by Ben Elliston. +# +# You can get the latest version of this script from: +# https://git.savannah.gnu.org/cgit/config.git/plain/config.guess +# +# Please send patches to . + + +# The "shellcheck disable" line above the timestamp inhibits complaints +# about features and limitations of the classic Bourne shell that were +# superseded or lifted in POSIX. However, this script identifies a wide +# variety of pre-POSIX systems that do not have POSIX shells at all, and +# even some reasonably current systems (Solaris 10 as case-in-point) still +# have a pre-POSIX /bin/sh. + + +me=`echo "$0" | sed -e 's,.*/,,'` + +usage="\ +Usage: $0 [OPTION] + +Output the configuration name of the system \`$me' is run on. + +Options: + -h, --help print this help, then exit + -t, --time-stamp print date of last modification, then exit + -v, --version print version number, then exit + +Report bugs and patches to ." + +version="\ +GNU config.guess ($timestamp) + +Originally written by Per Bothner. +Copyright 1992-2022 Free Software Foundation, Inc. + +This is free software; see the source for copying conditions. There is NO +warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." + +help=" +Try \`$me --help' for more information." + +# Parse command line +while test $# -gt 0 ; do + case $1 in + --time-stamp | --time* | -t ) + echo "$timestamp" ; exit ;; + --version | -v ) + echo "$version" ; exit ;; + --help | --h* | -h ) + echo "$usage"; exit ;; + -- ) # Stop option processing + shift; break ;; + - ) # Use stdin as input. + break ;; + -* ) + echo "$me: invalid option $1$help" >&2 + exit 1 ;; + * ) + break ;; + esac +done + +if test $# != 0; then + echo "$me: too many arguments$help" >&2 + exit 1 +fi + +# Just in case it came from the environment. +GUESS= + +# CC_FOR_BUILD -- compiler used by this script. Note that the use of a +# compiler to aid in system detection is discouraged as it requires +# temporary files to be created and, as you can see below, it is a +# headache to deal with in a portable fashion. + +# Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still +# use `HOST_CC' if defined, but it is deprecated. + +# Portable tmp directory creation inspired by the Autoconf team. + +tmp= +# shellcheck disable=SC2172 +trap 'test -z "$tmp" || rm -fr "$tmp"' 0 1 2 13 15 + +set_cc_for_build() { + # prevent multiple calls if $tmp is already set + test "$tmp" && return 0 + : "${TMPDIR=/tmp}" + # shellcheck disable=SC2039,SC3028 + { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } || + { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir "$tmp" 2>/dev/null) ; } || + { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir "$tmp" 2>/dev/null) && echo "Warning: creating insecure temp directory" >&2 ; } || + { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } + dummy=$tmp/dummy + case ${CC_FOR_BUILD-},${HOST_CC-},${CC-} in + ,,) echo "int x;" > "$dummy.c" + for driver in cc gcc c89 c99 ; do + if ($driver -c -o "$dummy.o" "$dummy.c") >/dev/null 2>&1 ; then + CC_FOR_BUILD=$driver + break + fi + done + if test x"$CC_FOR_BUILD" = x ; then + CC_FOR_BUILD=no_compiler_found + fi + ;; + ,,*) CC_FOR_BUILD=$CC ;; + ,*,*) CC_FOR_BUILD=$HOST_CC ;; + esac +} + +# This is needed to find uname on a Pyramid OSx when run in the BSD universe. +# (ghazi@noc.rutgers.edu 1994-08-24) +if test -f /.attbin/uname ; then + PATH=$PATH:/.attbin ; export PATH +fi + +UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown +UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown +UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown +UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown + +case $UNAME_SYSTEM in +Linux|GNU|GNU/*) + LIBC=unknown + + set_cc_for_build + cat <<-EOF > "$dummy.c" + #include + #if defined(__UCLIBC__) + LIBC=uclibc + #elif defined(__dietlibc__) + LIBC=dietlibc + #elif defined(__GLIBC__) + LIBC=gnu + #else + #include + /* First heuristic to detect musl libc. */ + #ifdef __DEFINED_va_list + LIBC=musl + #endif + #endif + EOF + cc_set_libc=`$CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^LIBC' | sed 's, ,,g'` + eval "$cc_set_libc" + + # Second heuristic to detect musl libc. + if [ "$LIBC" = unknown ] && + command -v ldd >/dev/null && + ldd --version 2>&1 | grep -q ^musl; then + LIBC=musl + fi + + # If the system lacks a compiler, then just pick glibc. + # We could probably try harder. + if [ "$LIBC" = unknown ]; then + LIBC=gnu + fi + ;; +esac + +# Note: order is significant - the case branches are not exclusive. + +case $UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION in + *:NetBSD:*:*) + # NetBSD (nbsd) targets should (where applicable) match one or + # more of the tuples: *-*-netbsdelf*, *-*-netbsdaout*, + # *-*-netbsdecoff* and *-*-netbsd*. For targets that recently + # switched to ELF, *-*-netbsd* would select the old + # object file format. This provides both forward + # compatibility and a consistent mechanism for selecting the + # object file format. + # + # Note: NetBSD doesn't particularly care about the vendor + # portion of the name. We always set it to "unknown". + UNAME_MACHINE_ARCH=`(uname -p 2>/dev/null || \ + /sbin/sysctl -n hw.machine_arch 2>/dev/null || \ + /usr/sbin/sysctl -n hw.machine_arch 2>/dev/null || \ + echo unknown)` + case $UNAME_MACHINE_ARCH in + aarch64eb) machine=aarch64_be-unknown ;; + armeb) machine=armeb-unknown ;; + arm*) machine=arm-unknown ;; + sh3el) machine=shl-unknown ;; + sh3eb) machine=sh-unknown ;; + sh5el) machine=sh5le-unknown ;; + earmv*) + arch=`echo "$UNAME_MACHINE_ARCH" | sed -e 's,^e\(armv[0-9]\).*$,\1,'` + endian=`echo "$UNAME_MACHINE_ARCH" | sed -ne 's,^.*\(eb\)$,\1,p'` + machine=${arch}${endian}-unknown + ;; + *) machine=$UNAME_MACHINE_ARCH-unknown ;; + esac + # The Operating System including object format, if it has switched + # to ELF recently (or will in the future) and ABI. + case $UNAME_MACHINE_ARCH in + earm*) + os=netbsdelf + ;; + arm*|i386|m68k|ns32k|sh3*|sparc|vax) + set_cc_for_build + if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \ + | grep -q __ELF__ + then + # Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout). + # Return netbsd for either. FIX? + os=netbsd + else + os=netbsdelf + fi + ;; + *) + os=netbsd + ;; + esac + # Determine ABI tags. + case $UNAME_MACHINE_ARCH in + earm*) + expr='s/^earmv[0-9]/-eabi/;s/eb$//' + abi=`echo "$UNAME_MACHINE_ARCH" | sed -e "$expr"` + ;; + esac + # The OS release + # Debian GNU/NetBSD machines have a different userland, and + # thus, need a distinct triplet. However, they do not need + # kernel version information, so it can be replaced with a + # suitable tag, in the style of linux-gnu. + case $UNAME_VERSION in + Debian*) + release='-gnu' + ;; + *) + release=`echo "$UNAME_RELEASE" | sed -e 's/[-_].*//' | cut -d. -f1,2` + ;; + esac + # Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM: + # contains redundant information, the shorter form: + # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used. + GUESS=$machine-${os}${release}${abi-} + ;; + *:Bitrig:*:*) + UNAME_MACHINE_ARCH=`arch | sed 's/Bitrig.//'` + GUESS=$UNAME_MACHINE_ARCH-unknown-bitrig$UNAME_RELEASE + ;; + *:OpenBSD:*:*) + UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'` + GUESS=$UNAME_MACHINE_ARCH-unknown-openbsd$UNAME_RELEASE + ;; + *:SecBSD:*:*) + UNAME_MACHINE_ARCH=`arch | sed 's/SecBSD.//'` + GUESS=$UNAME_MACHINE_ARCH-unknown-secbsd$UNAME_RELEASE + ;; + *:LibertyBSD:*:*) + UNAME_MACHINE_ARCH=`arch | sed 's/^.*BSD\.//'` + GUESS=$UNAME_MACHINE_ARCH-unknown-libertybsd$UNAME_RELEASE + ;; + *:MidnightBSD:*:*) + GUESS=$UNAME_MACHINE-unknown-midnightbsd$UNAME_RELEASE + ;; + *:ekkoBSD:*:*) + GUESS=$UNAME_MACHINE-unknown-ekkobsd$UNAME_RELEASE + ;; + *:SolidBSD:*:*) + GUESS=$UNAME_MACHINE-unknown-solidbsd$UNAME_RELEASE + ;; + *:OS108:*:*) + GUESS=$UNAME_MACHINE-unknown-os108_$UNAME_RELEASE + ;; + macppc:MirBSD:*:*) + GUESS=powerpc-unknown-mirbsd$UNAME_RELEASE + ;; + *:MirBSD:*:*) + GUESS=$UNAME_MACHINE-unknown-mirbsd$UNAME_RELEASE + ;; + *:Sortix:*:*) + GUESS=$UNAME_MACHINE-unknown-sortix + ;; + *:Twizzler:*:*) + GUESS=$UNAME_MACHINE-unknown-twizzler + ;; + *:Redox:*:*) + GUESS=$UNAME_MACHINE-unknown-redox + ;; + mips:OSF1:*.*) + GUESS=mips-dec-osf1 + ;; + alpha:OSF1:*:*) + # Reset EXIT trap before exiting to avoid spurious non-zero exit code. + trap '' 0 + case $UNAME_RELEASE in + *4.0) + UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'` + ;; + *5.*) + UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'` + ;; + esac + # According to Compaq, /usr/sbin/psrinfo has been available on + # OSF/1 and Tru64 systems produced since 1995. I hope that + # covers most systems running today. This code pipes the CPU + # types through head -n 1, so we only detect the type of CPU 0. + ALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^ The alpha \(.*\) processor.*$/\1/p' | head -n 1` + case $ALPHA_CPU_TYPE in + "EV4 (21064)") + UNAME_MACHINE=alpha ;; + "EV4.5 (21064)") + UNAME_MACHINE=alpha ;; + "LCA4 (21066/21068)") + UNAME_MACHINE=alpha ;; + "EV5 (21164)") + UNAME_MACHINE=alphaev5 ;; + "EV5.6 (21164A)") + UNAME_MACHINE=alphaev56 ;; + "EV5.6 (21164PC)") + UNAME_MACHINE=alphapca56 ;; + "EV5.7 (21164PC)") + UNAME_MACHINE=alphapca57 ;; + "EV6 (21264)") + UNAME_MACHINE=alphaev6 ;; + "EV6.7 (21264A)") + UNAME_MACHINE=alphaev67 ;; + "EV6.8CB (21264C)") + UNAME_MACHINE=alphaev68 ;; + "EV6.8AL (21264B)") + UNAME_MACHINE=alphaev68 ;; + "EV6.8CX (21264D)") + UNAME_MACHINE=alphaev68 ;; + "EV6.9A (21264/EV69A)") + UNAME_MACHINE=alphaev69 ;; + "EV7 (21364)") + UNAME_MACHINE=alphaev7 ;; + "EV7.9 (21364A)") + UNAME_MACHINE=alphaev79 ;; + esac + # A Pn.n version is a patched version. + # A Vn.n version is a released version. + # A Tn.n version is a released field test version. + # A Xn.n version is an unreleased experimental baselevel. + # 1.2 uses "1.2" for uname -r. + OSF_REL=`echo "$UNAME_RELEASE" | sed -e 's/^[PVTX]//' | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz` + GUESS=$UNAME_MACHINE-dec-osf$OSF_REL + ;; + Amiga*:UNIX_System_V:4.0:*) + GUESS=m68k-unknown-sysv4 + ;; + *:[Aa]miga[Oo][Ss]:*:*) + GUESS=$UNAME_MACHINE-unknown-amigaos + ;; + *:[Mm]orph[Oo][Ss]:*:*) + GUESS=$UNAME_MACHINE-unknown-morphos + ;; + *:OS/390:*:*) + GUESS=i370-ibm-openedition + ;; + *:z/VM:*:*) + GUESS=s390-ibm-zvmoe + ;; + *:OS400:*:*) + GUESS=powerpc-ibm-os400 + ;; + arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*) + GUESS=arm-acorn-riscix$UNAME_RELEASE + ;; + arm*:riscos:*:*|arm*:RISCOS:*:*) + GUESS=arm-unknown-riscos + ;; + SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*) + GUESS=hppa1.1-hitachi-hiuxmpp + ;; + Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*) + # akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE. + case `(/bin/universe) 2>/dev/null` in + att) GUESS=pyramid-pyramid-sysv3 ;; + *) GUESS=pyramid-pyramid-bsd ;; + esac + ;; + NILE*:*:*:dcosx) + GUESS=pyramid-pyramid-svr4 + ;; + DRS?6000:unix:4.0:6*) + GUESS=sparc-icl-nx6 + ;; + DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*) + case `/usr/bin/uname -p` in + sparc) GUESS=sparc-icl-nx7 ;; + esac + ;; + s390x:SunOS:*:*) + SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'` + GUESS=$UNAME_MACHINE-ibm-solaris2$SUN_REL + ;; + sun4H:SunOS:5.*:*) + SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'` + GUESS=sparc-hal-solaris2$SUN_REL + ;; + sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*) + SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'` + GUESS=sparc-sun-solaris2$SUN_REL + ;; + i86pc:AuroraUX:5.*:* | i86xen:AuroraUX:5.*:*) + GUESS=i386-pc-auroraux$UNAME_RELEASE + ;; + i86pc:SunOS:5.*:* | i86xen:SunOS:5.*:*) + set_cc_for_build + SUN_ARCH=i386 + # If there is a compiler, see if it is configured for 64-bit objects. + # Note that the Sun cc does not turn __LP64__ into 1 like gcc does. + # This test works for both compilers. + if test "$CC_FOR_BUILD" != no_compiler_found; then + if (echo '#ifdef __amd64'; echo IS_64BIT_ARCH; echo '#endif') | \ + (CCOPTS="" $CC_FOR_BUILD -m64 -E - 2>/dev/null) | \ + grep IS_64BIT_ARCH >/dev/null + then + SUN_ARCH=x86_64 + fi + fi + SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'` + GUESS=$SUN_ARCH-pc-solaris2$SUN_REL + ;; + sun4*:SunOS:6*:*) + # According to config.sub, this is the proper way to canonicalize + # SunOS6. Hard to guess exactly what SunOS6 will be like, but + # it's likely to be more like Solaris than SunOS4. + SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'` + GUESS=sparc-sun-solaris3$SUN_REL + ;; + sun4*:SunOS:*:*) + case `/usr/bin/arch -k` in + Series*|S4*) + UNAME_RELEASE=`uname -v` + ;; + esac + # Japanese Language versions have a version number like `4.1.3-JL'. + SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/-/_/'` + GUESS=sparc-sun-sunos$SUN_REL + ;; + sun3*:SunOS:*:*) + GUESS=m68k-sun-sunos$UNAME_RELEASE + ;; + sun*:*:4.2BSD:*) + UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null` + test "x$UNAME_RELEASE" = x && UNAME_RELEASE=3 + case `/bin/arch` in + sun3) + GUESS=m68k-sun-sunos$UNAME_RELEASE + ;; + sun4) + GUESS=sparc-sun-sunos$UNAME_RELEASE + ;; + esac + ;; + aushp:SunOS:*:*) + GUESS=sparc-auspex-sunos$UNAME_RELEASE + ;; + # The situation for MiNT is a little confusing. The machine name + # can be virtually everything (everything which is not + # "atarist" or "atariste" at least should have a processor + # > m68000). The system name ranges from "MiNT" over "FreeMiNT" + # to the lowercase version "mint" (or "freemint"). Finally + # the system name "TOS" denotes a system which is actually not + # MiNT. But MiNT is downward compatible to TOS, so this should + # be no problem. + atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*) + GUESS=m68k-atari-mint$UNAME_RELEASE + ;; + atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*) + GUESS=m68k-atari-mint$UNAME_RELEASE + ;; + *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*) + GUESS=m68k-atari-mint$UNAME_RELEASE + ;; + milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*) + GUESS=m68k-milan-mint$UNAME_RELEASE + ;; + hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*) + GUESS=m68k-hades-mint$UNAME_RELEASE + ;; + *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*) + GUESS=m68k-unknown-mint$UNAME_RELEASE + ;; + m68k:machten:*:*) + GUESS=m68k-apple-machten$UNAME_RELEASE + ;; + powerpc:machten:*:*) + GUESS=powerpc-apple-machten$UNAME_RELEASE + ;; + RISC*:Mach:*:*) + GUESS=mips-dec-mach_bsd4.3 + ;; + RISC*:ULTRIX:*:*) + GUESS=mips-dec-ultrix$UNAME_RELEASE + ;; + VAX*:ULTRIX*:*:*) + GUESS=vax-dec-ultrix$UNAME_RELEASE + ;; + 2020:CLIX:*:* | 2430:CLIX:*:*) + GUESS=clipper-intergraph-clix$UNAME_RELEASE + ;; + mips:*:*:UMIPS | mips:*:*:RISCos) + set_cc_for_build + sed 's/^ //' << EOF > "$dummy.c" +#ifdef __cplusplus +#include /* for printf() prototype */ + int main (int argc, char *argv[]) { +#else + int main (argc, argv) int argc; char *argv[]; { +#endif + #if defined (host_mips) && defined (MIPSEB) + #if defined (SYSTYPE_SYSV) + printf ("mips-mips-riscos%ssysv\\n", argv[1]); exit (0); + #endif + #if defined (SYSTYPE_SVR4) + printf ("mips-mips-riscos%ssvr4\\n", argv[1]); exit (0); + #endif + #if defined (SYSTYPE_BSD43) || defined(SYSTYPE_BSD) + printf ("mips-mips-riscos%sbsd\\n", argv[1]); exit (0); + #endif + #endif + exit (-1); + } +EOF + $CC_FOR_BUILD -o "$dummy" "$dummy.c" && + dummyarg=`echo "$UNAME_RELEASE" | sed -n 's/\([0-9]*\).*/\1/p'` && + SYSTEM_NAME=`"$dummy" "$dummyarg"` && + { echo "$SYSTEM_NAME"; exit; } + GUESS=mips-mips-riscos$UNAME_RELEASE + ;; + Motorola:PowerMAX_OS:*:*) + GUESS=powerpc-motorola-powermax + ;; + Motorola:*:4.3:PL8-*) + GUESS=powerpc-harris-powermax + ;; + Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*) + GUESS=powerpc-harris-powermax + ;; + Night_Hawk:Power_UNIX:*:*) + GUESS=powerpc-harris-powerunix + ;; + m88k:CX/UX:7*:*) + GUESS=m88k-harris-cxux7 + ;; + m88k:*:4*:R4*) + GUESS=m88k-motorola-sysv4 + ;; + m88k:*:3*:R3*) + GUESS=m88k-motorola-sysv3 + ;; + AViiON:dgux:*:*) + # DG/UX returns AViiON for all architectures + UNAME_PROCESSOR=`/usr/bin/uname -p` + if test "$UNAME_PROCESSOR" = mc88100 || test "$UNAME_PROCESSOR" = mc88110 + then + if test "$TARGET_BINARY_INTERFACE"x = m88kdguxelfx || \ + test "$TARGET_BINARY_INTERFACE"x = x + then + GUESS=m88k-dg-dgux$UNAME_RELEASE + else + GUESS=m88k-dg-dguxbcs$UNAME_RELEASE + fi + else + GUESS=i586-dg-dgux$UNAME_RELEASE + fi + ;; + M88*:DolphinOS:*:*) # DolphinOS (SVR3) + GUESS=m88k-dolphin-sysv3 + ;; + M88*:*:R3*:*) + # Delta 88k system running SVR3 + GUESS=m88k-motorola-sysv3 + ;; + XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3) + GUESS=m88k-tektronix-sysv3 + ;; + Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD) + GUESS=m68k-tektronix-bsd + ;; + *:IRIX*:*:*) + IRIX_REL=`echo "$UNAME_RELEASE" | sed -e 's/-/_/g'` + GUESS=mips-sgi-irix$IRIX_REL + ;; + ????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX. + GUESS=romp-ibm-aix # uname -m gives an 8 hex-code CPU id + ;; # Note that: echo "'`uname -s`'" gives 'AIX ' + i*86:AIX:*:*) + GUESS=i386-ibm-aix + ;; + ia64:AIX:*:*) + if test -x /usr/bin/oslevel ; then + IBM_REV=`/usr/bin/oslevel` + else + IBM_REV=$UNAME_VERSION.$UNAME_RELEASE + fi + GUESS=$UNAME_MACHINE-ibm-aix$IBM_REV + ;; + *:AIX:2:3) + if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then + set_cc_for_build + sed 's/^ //' << EOF > "$dummy.c" + #include + + main() + { + if (!__power_pc()) + exit(1); + puts("powerpc-ibm-aix3.2.5"); + exit(0); + } +EOF + if $CC_FOR_BUILD -o "$dummy" "$dummy.c" && SYSTEM_NAME=`"$dummy"` + then + GUESS=$SYSTEM_NAME + else + GUESS=rs6000-ibm-aix3.2.5 + fi + elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then + GUESS=rs6000-ibm-aix3.2.4 + else + GUESS=rs6000-ibm-aix3.2 + fi + ;; + *:AIX:*:[4567]) + IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'` + if /usr/sbin/lsattr -El "$IBM_CPU_ID" | grep ' POWER' >/dev/null 2>&1; then + IBM_ARCH=rs6000 + else + IBM_ARCH=powerpc + fi + if test -x /usr/bin/lslpp ; then + IBM_REV=`/usr/bin/lslpp -Lqc bos.rte.libc | \ + awk -F: '{ print $3 }' | sed s/[0-9]*$/0/` + else + IBM_REV=$UNAME_VERSION.$UNAME_RELEASE + fi + GUESS=$IBM_ARCH-ibm-aix$IBM_REV + ;; + *:AIX:*:*) + GUESS=rs6000-ibm-aix + ;; + ibmrt:4.4BSD:*|romp-ibm:4.4BSD:*) + GUESS=romp-ibm-bsd4.4 + ;; + ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC BSD and + GUESS=romp-ibm-bsd$UNAME_RELEASE # 4.3 with uname added to + ;; # report: romp-ibm BSD 4.3 + *:BOSX:*:*) + GUESS=rs6000-bull-bosx + ;; + DPX/2?00:B.O.S.:*:*) + GUESS=m68k-bull-sysv3 + ;; + 9000/[34]??:4.3bsd:1.*:*) + GUESS=m68k-hp-bsd + ;; + hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*) + GUESS=m68k-hp-bsd4.4 + ;; + 9000/[34678]??:HP-UX:*:*) + HPUX_REV=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*.[0B]*//'` + case $UNAME_MACHINE in + 9000/31?) HP_ARCH=m68000 ;; + 9000/[34]??) HP_ARCH=m68k ;; + 9000/[678][0-9][0-9]) + if test -x /usr/bin/getconf; then + sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null` + sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null` + case $sc_cpu_version in + 523) HP_ARCH=hppa1.0 ;; # CPU_PA_RISC1_0 + 528) HP_ARCH=hppa1.1 ;; # CPU_PA_RISC1_1 + 532) # CPU_PA_RISC2_0 + case $sc_kernel_bits in + 32) HP_ARCH=hppa2.0n ;; + 64) HP_ARCH=hppa2.0w ;; + '') HP_ARCH=hppa2.0 ;; # HP-UX 10.20 + esac ;; + esac + fi + if test "$HP_ARCH" = ""; then + set_cc_for_build + sed 's/^ //' << EOF > "$dummy.c" + + #define _HPUX_SOURCE + #include + #include + + int main () + { + #if defined(_SC_KERNEL_BITS) + long bits = sysconf(_SC_KERNEL_BITS); + #endif + long cpu = sysconf (_SC_CPU_VERSION); + + switch (cpu) + { + case CPU_PA_RISC1_0: puts ("hppa1.0"); break; + case CPU_PA_RISC1_1: puts ("hppa1.1"); break; + case CPU_PA_RISC2_0: + #if defined(_SC_KERNEL_BITS) + switch (bits) + { + case 64: puts ("hppa2.0w"); break; + case 32: puts ("hppa2.0n"); break; + default: puts ("hppa2.0"); break; + } break; + #else /* !defined(_SC_KERNEL_BITS) */ + puts ("hppa2.0"); break; + #endif + default: puts ("hppa1.0"); break; + } + exit (0); + } +EOF + (CCOPTS="" $CC_FOR_BUILD -o "$dummy" "$dummy.c" 2>/dev/null) && HP_ARCH=`"$dummy"` + test -z "$HP_ARCH" && HP_ARCH=hppa + fi ;; + esac + if test "$HP_ARCH" = hppa2.0w + then + set_cc_for_build + + # hppa2.0w-hp-hpux* has a 64-bit kernel and a compiler generating + # 32-bit code. hppa64-hp-hpux* has the same kernel and a compiler + # generating 64-bit code. GNU and HP use different nomenclature: + # + # $ CC_FOR_BUILD=cc ./config.guess + # => hppa2.0w-hp-hpux11.23 + # $ CC_FOR_BUILD="cc +DA2.0w" ./config.guess + # => hppa64-hp-hpux11.23 + + if echo __LP64__ | (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | + grep -q __LP64__ + then + HP_ARCH=hppa2.0w + else + HP_ARCH=hppa64 + fi + fi + GUESS=$HP_ARCH-hp-hpux$HPUX_REV + ;; + ia64:HP-UX:*:*) + HPUX_REV=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*.[0B]*//'` + GUESS=ia64-hp-hpux$HPUX_REV + ;; + 3050*:HI-UX:*:*) + set_cc_for_build + sed 's/^ //' << EOF > "$dummy.c" + #include + int + main () + { + long cpu = sysconf (_SC_CPU_VERSION); + /* The order matters, because CPU_IS_HP_MC68K erroneously returns + true for CPU_PA_RISC1_0. CPU_IS_PA_RISC returns correct + results, however. */ + if (CPU_IS_PA_RISC (cpu)) + { + switch (cpu) + { + case CPU_PA_RISC1_0: puts ("hppa1.0-hitachi-hiuxwe2"); break; + case CPU_PA_RISC1_1: puts ("hppa1.1-hitachi-hiuxwe2"); break; + case CPU_PA_RISC2_0: puts ("hppa2.0-hitachi-hiuxwe2"); break; + default: puts ("hppa-hitachi-hiuxwe2"); break; + } + } + else if (CPU_IS_HP_MC68K (cpu)) + puts ("m68k-hitachi-hiuxwe2"); + else puts ("unknown-hitachi-hiuxwe2"); + exit (0); + } +EOF + $CC_FOR_BUILD -o "$dummy" "$dummy.c" && SYSTEM_NAME=`"$dummy"` && + { echo "$SYSTEM_NAME"; exit; } + GUESS=unknown-hitachi-hiuxwe2 + ;; + 9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:*) + GUESS=hppa1.1-hp-bsd + ;; + 9000/8??:4.3bsd:*:*) + GUESS=hppa1.0-hp-bsd + ;; + *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*) + GUESS=hppa1.0-hp-mpeix + ;; + hp7??:OSF1:*:* | hp8?[79]:OSF1:*:*) + GUESS=hppa1.1-hp-osf + ;; + hp8??:OSF1:*:*) + GUESS=hppa1.0-hp-osf + ;; + i*86:OSF1:*:*) + if test -x /usr/sbin/sysversion ; then + GUESS=$UNAME_MACHINE-unknown-osf1mk + else + GUESS=$UNAME_MACHINE-unknown-osf1 + fi + ;; + parisc*:Lites*:*:*) + GUESS=hppa1.1-hp-lites + ;; + C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*) + GUESS=c1-convex-bsd + ;; + C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*) + if getsysinfo -f scalar_acc + then echo c32-convex-bsd + else echo c2-convex-bsd + fi + exit ;; + C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*) + GUESS=c34-convex-bsd + ;; + C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*) + GUESS=c38-convex-bsd + ;; + C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*) + GUESS=c4-convex-bsd + ;; + CRAY*Y-MP:*:*:*) + CRAY_REL=`echo "$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'` + GUESS=ymp-cray-unicos$CRAY_REL + ;; + CRAY*[A-Z]90:*:*:*) + echo "$UNAME_MACHINE"-cray-unicos"$UNAME_RELEASE" \ + | sed -e 's/CRAY.*\([A-Z]90\)/\1/' \ + -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \ + -e 's/\.[^.]*$/.X/' + exit ;; + CRAY*TS:*:*:*) + CRAY_REL=`echo "$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'` + GUESS=t90-cray-unicos$CRAY_REL + ;; + CRAY*T3E:*:*:*) + CRAY_REL=`echo "$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'` + GUESS=alphaev5-cray-unicosmk$CRAY_REL + ;; + CRAY*SV1:*:*:*) + CRAY_REL=`echo "$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'` + GUESS=sv1-cray-unicos$CRAY_REL + ;; + *:UNICOS/mp:*:*) + CRAY_REL=`echo "$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'` + GUESS=craynv-cray-unicosmp$CRAY_REL + ;; + F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*) + FUJITSU_PROC=`uname -m | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz` + FUJITSU_SYS=`uname -p | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/\///'` + FUJITSU_REL=`echo "$UNAME_RELEASE" | sed -e 's/ /_/'` + GUESS=${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL} + ;; + 5000:UNIX_System_V:4.*:*) + FUJITSU_SYS=`uname -p | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/\///'` + FUJITSU_REL=`echo "$UNAME_RELEASE" | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/ /_/'` + GUESS=sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL} + ;; + i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*) + GUESS=$UNAME_MACHINE-pc-bsdi$UNAME_RELEASE + ;; + sparc*:BSD/OS:*:*) + GUESS=sparc-unknown-bsdi$UNAME_RELEASE + ;; + *:BSD/OS:*:*) + GUESS=$UNAME_MACHINE-unknown-bsdi$UNAME_RELEASE + ;; + arm:FreeBSD:*:*) + UNAME_PROCESSOR=`uname -p` + set_cc_for_build + if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \ + | grep -q __ARM_PCS_VFP + then + FREEBSD_REL=`echo "$UNAME_RELEASE" | sed -e 's/[-(].*//'` + GUESS=$UNAME_PROCESSOR-unknown-freebsd$FREEBSD_REL-gnueabi + else + FREEBSD_REL=`echo "$UNAME_RELEASE" | sed -e 's/[-(].*//'` + GUESS=$UNAME_PROCESSOR-unknown-freebsd$FREEBSD_REL-gnueabihf + fi + ;; + *:FreeBSD:*:*) + UNAME_PROCESSOR=`/usr/bin/uname -p` + case $UNAME_PROCESSOR in + amd64) + UNAME_PROCESSOR=x86_64 ;; + i386) + UNAME_PROCESSOR=i586 ;; + esac + FREEBSD_REL=`echo "$UNAME_RELEASE" | sed -e 's/[-(].*//'` + GUESS=$UNAME_PROCESSOR-unknown-freebsd$FREEBSD_REL + ;; + i*:CYGWIN*:*) + GUESS=$UNAME_MACHINE-pc-cygwin + ;; + *:MINGW64*:*) + GUESS=$UNAME_MACHINE-pc-mingw64 + ;; + *:MINGW*:*) + GUESS=$UNAME_MACHINE-pc-mingw32 + ;; + *:MSYS*:*) + GUESS=$UNAME_MACHINE-pc-msys + ;; + i*:PW*:*) + GUESS=$UNAME_MACHINE-pc-pw32 + ;; + *:SerenityOS:*:*) + GUESS=$UNAME_MACHINE-pc-serenity + ;; + *:Interix*:*) + case $UNAME_MACHINE in + x86) + GUESS=i586-pc-interix$UNAME_RELEASE + ;; + authenticamd | genuineintel | EM64T) + GUESS=x86_64-unknown-interix$UNAME_RELEASE + ;; + IA64) + GUESS=ia64-unknown-interix$UNAME_RELEASE + ;; + esac ;; + i*:UWIN*:*) + GUESS=$UNAME_MACHINE-pc-uwin + ;; + amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*) + GUESS=x86_64-pc-cygwin + ;; + prep*:SunOS:5.*:*) + SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'` + GUESS=powerpcle-unknown-solaris2$SUN_REL + ;; + *:GNU:*:*) + # the GNU system + GNU_ARCH=`echo "$UNAME_MACHINE" | sed -e 's,[-/].*$,,'` + GNU_REL=`echo "$UNAME_RELEASE" | sed -e 's,/.*$,,'` + GUESS=$GNU_ARCH-unknown-$LIBC$GNU_REL + ;; + *:GNU/*:*:*) + # other systems with GNU libc and userland + GNU_SYS=`echo "$UNAME_SYSTEM" | sed 's,^[^/]*/,,' | tr "[:upper:]" "[:lower:]"` + GNU_REL=`echo "$UNAME_RELEASE" | sed -e 's/[-(].*//'` + GUESS=$UNAME_MACHINE-unknown-$GNU_SYS$GNU_REL-$LIBC + ;; + *:Minix:*:*) + GUESS=$UNAME_MACHINE-unknown-minix + ;; + aarch64:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + aarch64_be:Linux:*:*) + UNAME_MACHINE=aarch64_be + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + alpha:Linux:*:*) + case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' /proc/cpuinfo 2>/dev/null` in + EV5) UNAME_MACHINE=alphaev5 ;; + EV56) UNAME_MACHINE=alphaev56 ;; + PCA56) UNAME_MACHINE=alphapca56 ;; + PCA57) UNAME_MACHINE=alphapca56 ;; + EV6) UNAME_MACHINE=alphaev6 ;; + EV67) UNAME_MACHINE=alphaev67 ;; + EV68*) UNAME_MACHINE=alphaev68 ;; + esac + objdump --private-headers /bin/sh | grep -q ld.so.1 + if test "$?" = 0 ; then LIBC=gnulibc1 ; fi + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + arc:Linux:*:* | arceb:Linux:*:* | arc32:Linux:*:* | arc64:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + arm*:Linux:*:*) + set_cc_for_build + if echo __ARM_EABI__ | $CC_FOR_BUILD -E - 2>/dev/null \ + | grep -q __ARM_EABI__ + then + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + else + if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \ + | grep -q __ARM_PCS_VFP + then + GUESS=$UNAME_MACHINE-unknown-linux-${LIBC}eabi + else + GUESS=$UNAME_MACHINE-unknown-linux-${LIBC}eabihf + fi + fi + ;; + avr32*:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + cris:Linux:*:*) + GUESS=$UNAME_MACHINE-axis-linux-$LIBC + ;; + crisv32:Linux:*:*) + GUESS=$UNAME_MACHINE-axis-linux-$LIBC + ;; + e2k:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + frv:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + hexagon:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + i*86:Linux:*:*) + GUESS=$UNAME_MACHINE-pc-linux-$LIBC + ;; + ia64:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + k1om:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + loongarch32:Linux:*:* | loongarch64:Linux:*:* | loongarchx32:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + m32r*:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + m68*:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + mips:Linux:*:* | mips64:Linux:*:*) + set_cc_for_build + IS_GLIBC=0 + test x"${LIBC}" = xgnu && IS_GLIBC=1 + sed 's/^ //' << EOF > "$dummy.c" + #undef CPU + #undef mips + #undef mipsel + #undef mips64 + #undef mips64el + #if ${IS_GLIBC} && defined(_ABI64) + LIBCABI=gnuabi64 + #else + #if ${IS_GLIBC} && defined(_ABIN32) + LIBCABI=gnuabin32 + #else + LIBCABI=${LIBC} + #endif + #endif + + #if ${IS_GLIBC} && defined(__mips64) && defined(__mips_isa_rev) && __mips_isa_rev>=6 + CPU=mipsisa64r6 + #else + #if ${IS_GLIBC} && !defined(__mips64) && defined(__mips_isa_rev) && __mips_isa_rev>=6 + CPU=mipsisa32r6 + #else + #if defined(__mips64) + CPU=mips64 + #else + CPU=mips + #endif + #endif + #endif + + #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) + MIPS_ENDIAN=el + #else + #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) + MIPS_ENDIAN= + #else + MIPS_ENDIAN= + #endif + #endif +EOF + cc_set_vars=`$CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^CPU\|^MIPS_ENDIAN\|^LIBCABI'` + eval "$cc_set_vars" + test "x$CPU" != x && { echo "$CPU${MIPS_ENDIAN}-unknown-linux-$LIBCABI"; exit; } + ;; + mips64el:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + openrisc*:Linux:*:*) + GUESS=or1k-unknown-linux-$LIBC + ;; + or32:Linux:*:* | or1k*:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + padre:Linux:*:*) + GUESS=sparc-unknown-linux-$LIBC + ;; + parisc64:Linux:*:* | hppa64:Linux:*:*) + GUESS=hppa64-unknown-linux-$LIBC + ;; + parisc:Linux:*:* | hppa:Linux:*:*) + # Look for CPU level + case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in + PA7*) GUESS=hppa1.1-unknown-linux-$LIBC ;; + PA8*) GUESS=hppa2.0-unknown-linux-$LIBC ;; + *) GUESS=hppa-unknown-linux-$LIBC ;; + esac + ;; + ppc64:Linux:*:*) + GUESS=powerpc64-unknown-linux-$LIBC + ;; + ppc:Linux:*:*) + GUESS=powerpc-unknown-linux-$LIBC + ;; + ppc64le:Linux:*:*) + GUESS=powerpc64le-unknown-linux-$LIBC + ;; + ppcle:Linux:*:*) + GUESS=powerpcle-unknown-linux-$LIBC + ;; + riscv32:Linux:*:* | riscv32be:Linux:*:* | riscv64:Linux:*:* | riscv64be:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + s390:Linux:*:* | s390x:Linux:*:*) + GUESS=$UNAME_MACHINE-ibm-linux-$LIBC + ;; + sh64*:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + sh*:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + sparc:Linux:*:* | sparc64:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + tile*:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + vax:Linux:*:*) + GUESS=$UNAME_MACHINE-dec-linux-$LIBC + ;; + x86_64:Linux:*:*) + set_cc_for_build + LIBCABI=$LIBC + if test "$CC_FOR_BUILD" != no_compiler_found; then + if (echo '#ifdef __ILP32__'; echo IS_X32; echo '#endif') | \ + (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \ + grep IS_X32 >/dev/null + then + LIBCABI=${LIBC}x32 + fi + fi + GUESS=$UNAME_MACHINE-pc-linux-$LIBCABI + ;; + xtensa*:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + i*86:DYNIX/ptx:4*:*) + # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there. + # earlier versions are messed up and put the nodename in both + # sysname and nodename. + GUESS=i386-sequent-sysv4 + ;; + i*86:UNIX_SV:4.2MP:2.*) + # Unixware is an offshoot of SVR4, but it has its own version + # number series starting with 2... + # I am not positive that other SVR4 systems won't match this, + # I just have to hope. -- rms. + # Use sysv4.2uw... so that sysv4* matches it. + GUESS=$UNAME_MACHINE-pc-sysv4.2uw$UNAME_VERSION + ;; + i*86:OS/2:*:*) + # If we were able to find `uname', then EMX Unix compatibility + # is probably installed. + GUESS=$UNAME_MACHINE-pc-os2-emx + ;; + i*86:XTS-300:*:STOP) + GUESS=$UNAME_MACHINE-unknown-stop + ;; + i*86:atheos:*:*) + GUESS=$UNAME_MACHINE-unknown-atheos + ;; + i*86:syllable:*:*) + GUESS=$UNAME_MACHINE-pc-syllable + ;; + i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.[02]*:*) + GUESS=i386-unknown-lynxos$UNAME_RELEASE + ;; + i*86:*DOS:*:*) + GUESS=$UNAME_MACHINE-pc-msdosdjgpp + ;; + i*86:*:4.*:*) + UNAME_REL=`echo "$UNAME_RELEASE" | sed 's/\/MP$//'` + if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then + GUESS=$UNAME_MACHINE-univel-sysv$UNAME_REL + else + GUESS=$UNAME_MACHINE-pc-sysv$UNAME_REL + fi + ;; + i*86:*:5:[678]*) + # UnixWare 7.x, OpenUNIX and OpenServer 6. + case `/bin/uname -X | grep "^Machine"` in + *486*) UNAME_MACHINE=i486 ;; + *Pentium) UNAME_MACHINE=i586 ;; + *Pent*|*Celeron) UNAME_MACHINE=i686 ;; + esac + GUESS=$UNAME_MACHINE-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION} + ;; + i*86:*:3.2:*) + if test -f /usr/options/cb.name; then + UNAME_REL=`sed -n 's/.*Version //p' /dev/null >/dev/null ; then + UNAME_REL=`(/bin/uname -X|grep Release|sed -e 's/.*= //')` + (/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486 + (/bin/uname -X|grep '^Machine.*Pentium' >/dev/null) \ + && UNAME_MACHINE=i586 + (/bin/uname -X|grep '^Machine.*Pent *II' >/dev/null) \ + && UNAME_MACHINE=i686 + (/bin/uname -X|grep '^Machine.*Pentium Pro' >/dev/null) \ + && UNAME_MACHINE=i686 + GUESS=$UNAME_MACHINE-pc-sco$UNAME_REL + else + GUESS=$UNAME_MACHINE-pc-sysv32 + fi + ;; + pc:*:*:*) + # Left here for compatibility: + # uname -m prints for DJGPP always 'pc', but it prints nothing about + # the processor, so we play safe by assuming i586. + # Note: whatever this is, it MUST be the same as what config.sub + # prints for the "djgpp" host, or else GDB configure will decide that + # this is a cross-build. + GUESS=i586-pc-msdosdjgpp + ;; + Intel:Mach:3*:*) + GUESS=i386-pc-mach3 + ;; + paragon:*:*:*) + GUESS=i860-intel-osf1 + ;; + i860:*:4.*:*) # i860-SVR4 + if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then + GUESS=i860-stardent-sysv$UNAME_RELEASE # Stardent Vistra i860-SVR4 + else # Add other i860-SVR4 vendors below as they are discovered. + GUESS=i860-unknown-sysv$UNAME_RELEASE # Unknown i860-SVR4 + fi + ;; + mini*:CTIX:SYS*5:*) + # "miniframe" + GUESS=m68010-convergent-sysv + ;; + mc68k:UNIX:SYSTEM5:3.51m) + GUESS=m68k-convergent-sysv + ;; + M680?0:D-NIX:5.3:*) + GUESS=m68k-diab-dnix + ;; + M68*:*:R3V[5678]*:*) + test -r /sysV68 && { echo 'm68k-motorola-sysv'; exit; } ;; + 3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0 | S7501*:*:4.0:3.0) + OS_REL='' + test -r /etc/.relid \ + && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` + /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ + && { echo i486-ncr-sysv4.3"$OS_REL"; exit; } + /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ + && { echo i586-ncr-sysv4.3"$OS_REL"; exit; } ;; + 3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*) + /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ + && { echo i486-ncr-sysv4; exit; } ;; + NCR*:*:4.2:* | MPRAS*:*:4.2:*) + OS_REL='.3' + test -r /etc/.relid \ + && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` + /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ + && { echo i486-ncr-sysv4.3"$OS_REL"; exit; } + /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ + && { echo i586-ncr-sysv4.3"$OS_REL"; exit; } + /bin/uname -p 2>/dev/null | /bin/grep pteron >/dev/null \ + && { echo i586-ncr-sysv4.3"$OS_REL"; exit; } ;; + m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*) + GUESS=m68k-unknown-lynxos$UNAME_RELEASE + ;; + mc68030:UNIX_System_V:4.*:*) + GUESS=m68k-atari-sysv4 + ;; + TSUNAMI:LynxOS:2.*:*) + GUESS=sparc-unknown-lynxos$UNAME_RELEASE + ;; + rs6000:LynxOS:2.*:*) + GUESS=rs6000-unknown-lynxos$UNAME_RELEASE + ;; + PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.[02]*:*) + GUESS=powerpc-unknown-lynxos$UNAME_RELEASE + ;; + SM[BE]S:UNIX_SV:*:*) + GUESS=mips-dde-sysv$UNAME_RELEASE + ;; + RM*:ReliantUNIX-*:*:*) + GUESS=mips-sni-sysv4 + ;; + RM*:SINIX-*:*:*) + GUESS=mips-sni-sysv4 + ;; + *:SINIX-*:*:*) + if uname -p 2>/dev/null >/dev/null ; then + UNAME_MACHINE=`(uname -p) 2>/dev/null` + GUESS=$UNAME_MACHINE-sni-sysv4 + else + GUESS=ns32k-sni-sysv + fi + ;; + PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort + # says + GUESS=i586-unisys-sysv4 + ;; + *:UNIX_System_V:4*:FTX*) + # From Gerald Hewes . + # How about differentiating between stratus architectures? -djm + GUESS=hppa1.1-stratus-sysv4 + ;; + *:*:*:FTX*) + # From seanf@swdc.stratus.com. + GUESS=i860-stratus-sysv4 + ;; + i*86:VOS:*:*) + # From Paul.Green@stratus.com. + GUESS=$UNAME_MACHINE-stratus-vos + ;; + *:VOS:*:*) + # From Paul.Green@stratus.com. + GUESS=hppa1.1-stratus-vos + ;; + mc68*:A/UX:*:*) + GUESS=m68k-apple-aux$UNAME_RELEASE + ;; + news*:NEWS-OS:6*:*) + GUESS=mips-sony-newsos6 + ;; + R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*) + if test -d /usr/nec; then + GUESS=mips-nec-sysv$UNAME_RELEASE + else + GUESS=mips-unknown-sysv$UNAME_RELEASE + fi + ;; + BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only. + GUESS=powerpc-be-beos + ;; + BeMac:BeOS:*:*) # BeOS running on Mac or Mac clone, PPC only. + GUESS=powerpc-apple-beos + ;; + BePC:BeOS:*:*) # BeOS running on Intel PC compatible. + GUESS=i586-pc-beos + ;; + BePC:Haiku:*:*) # Haiku running on Intel PC compatible. + GUESS=i586-pc-haiku + ;; + x86_64:Haiku:*:*) + GUESS=x86_64-unknown-haiku + ;; + SX-4:SUPER-UX:*:*) + GUESS=sx4-nec-superux$UNAME_RELEASE + ;; + SX-5:SUPER-UX:*:*) + GUESS=sx5-nec-superux$UNAME_RELEASE + ;; + SX-6:SUPER-UX:*:*) + GUESS=sx6-nec-superux$UNAME_RELEASE + ;; + SX-7:SUPER-UX:*:*) + GUESS=sx7-nec-superux$UNAME_RELEASE + ;; + SX-8:SUPER-UX:*:*) + GUESS=sx8-nec-superux$UNAME_RELEASE + ;; + SX-8R:SUPER-UX:*:*) + GUESS=sx8r-nec-superux$UNAME_RELEASE + ;; + SX-ACE:SUPER-UX:*:*) + GUESS=sxace-nec-superux$UNAME_RELEASE + ;; + Power*:Rhapsody:*:*) + GUESS=powerpc-apple-rhapsody$UNAME_RELEASE + ;; + *:Rhapsody:*:*) + GUESS=$UNAME_MACHINE-apple-rhapsody$UNAME_RELEASE + ;; + arm64:Darwin:*:*) + GUESS=aarch64-apple-darwin$UNAME_RELEASE + ;; + *:Darwin:*:*) + UNAME_PROCESSOR=`uname -p` + case $UNAME_PROCESSOR in + unknown) UNAME_PROCESSOR=powerpc ;; + esac + if command -v xcode-select > /dev/null 2> /dev/null && \ + ! xcode-select --print-path > /dev/null 2> /dev/null ; then + # Avoid executing cc if there is no toolchain installed as + # cc will be a stub that puts up a graphical alert + # prompting the user to install developer tools. + CC_FOR_BUILD=no_compiler_found + else + set_cc_for_build + fi + if test "$CC_FOR_BUILD" != no_compiler_found; then + if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \ + (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \ + grep IS_64BIT_ARCH >/dev/null + then + case $UNAME_PROCESSOR in + i386) UNAME_PROCESSOR=x86_64 ;; + powerpc) UNAME_PROCESSOR=powerpc64 ;; + esac + fi + # On 10.4-10.6 one might compile for PowerPC via gcc -arch ppc + if (echo '#ifdef __POWERPC__'; echo IS_PPC; echo '#endif') | \ + (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \ + grep IS_PPC >/dev/null + then + UNAME_PROCESSOR=powerpc + fi + elif test "$UNAME_PROCESSOR" = i386 ; then + # uname -m returns i386 or x86_64 + UNAME_PROCESSOR=$UNAME_MACHINE + fi + GUESS=$UNAME_PROCESSOR-apple-darwin$UNAME_RELEASE + ;; + *:procnto*:*:* | *:QNX:[0123456789]*:*) + UNAME_PROCESSOR=`uname -p` + if test "$UNAME_PROCESSOR" = x86; then + UNAME_PROCESSOR=i386 + UNAME_MACHINE=pc + fi + GUESS=$UNAME_PROCESSOR-$UNAME_MACHINE-nto-qnx$UNAME_RELEASE + ;; + *:QNX:*:4*) + GUESS=i386-pc-qnx + ;; + NEO-*:NONSTOP_KERNEL:*:*) + GUESS=neo-tandem-nsk$UNAME_RELEASE + ;; + NSE-*:NONSTOP_KERNEL:*:*) + GUESS=nse-tandem-nsk$UNAME_RELEASE + ;; + NSR-*:NONSTOP_KERNEL:*:*) + GUESS=nsr-tandem-nsk$UNAME_RELEASE + ;; + NSV-*:NONSTOP_KERNEL:*:*) + GUESS=nsv-tandem-nsk$UNAME_RELEASE + ;; + NSX-*:NONSTOP_KERNEL:*:*) + GUESS=nsx-tandem-nsk$UNAME_RELEASE + ;; + *:NonStop-UX:*:*) + GUESS=mips-compaq-nonstopux + ;; + BS2000:POSIX*:*:*) + GUESS=bs2000-siemens-sysv + ;; + DS/*:UNIX_System_V:*:*) + GUESS=$UNAME_MACHINE-$UNAME_SYSTEM-$UNAME_RELEASE + ;; + *:Plan9:*:*) + # "uname -m" is not consistent, so use $cputype instead. 386 + # is converted to i386 for consistency with other x86 + # operating systems. + if test "${cputype-}" = 386; then + UNAME_MACHINE=i386 + elif test "x${cputype-}" != x; then + UNAME_MACHINE=$cputype + fi + GUESS=$UNAME_MACHINE-unknown-plan9 + ;; + *:TOPS-10:*:*) + GUESS=pdp10-unknown-tops10 + ;; + *:TENEX:*:*) + GUESS=pdp10-unknown-tenex + ;; + KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*) + GUESS=pdp10-dec-tops20 + ;; + XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*) + GUESS=pdp10-xkl-tops20 + ;; + *:TOPS-20:*:*) + GUESS=pdp10-unknown-tops20 + ;; + *:ITS:*:*) + GUESS=pdp10-unknown-its + ;; + SEI:*:*:SEIUX) + GUESS=mips-sei-seiux$UNAME_RELEASE + ;; + *:DragonFly:*:*) + DRAGONFLY_REL=`echo "$UNAME_RELEASE" | sed -e 's/[-(].*//'` + GUESS=$UNAME_MACHINE-unknown-dragonfly$DRAGONFLY_REL + ;; + *:*VMS:*:*) + UNAME_MACHINE=`(uname -p) 2>/dev/null` + case $UNAME_MACHINE in + A*) GUESS=alpha-dec-vms ;; + I*) GUESS=ia64-dec-vms ;; + V*) GUESS=vax-dec-vms ;; + esac ;; + *:XENIX:*:SysV) + GUESS=i386-pc-xenix + ;; + i*86:skyos:*:*) + SKYOS_REL=`echo "$UNAME_RELEASE" | sed -e 's/ .*$//'` + GUESS=$UNAME_MACHINE-pc-skyos$SKYOS_REL + ;; + i*86:rdos:*:*) + GUESS=$UNAME_MACHINE-pc-rdos + ;; + i*86:Fiwix:*:*) + GUESS=$UNAME_MACHINE-pc-fiwix + ;; + *:AROS:*:*) + GUESS=$UNAME_MACHINE-unknown-aros + ;; + x86_64:VMkernel:*:*) + GUESS=$UNAME_MACHINE-unknown-esx + ;; + amd64:Isilon\ OneFS:*:*) + GUESS=x86_64-unknown-onefs + ;; + *:Unleashed:*:*) + GUESS=$UNAME_MACHINE-unknown-unleashed$UNAME_RELEASE + ;; +esac + +# Do we have a guess based on uname results? +if test "x$GUESS" != x; then + echo "$GUESS" + exit +fi + +# No uname command or uname output not recognized. +set_cc_for_build +cat > "$dummy.c" < +#include +#endif +#if defined(ultrix) || defined(_ultrix) || defined(__ultrix) || defined(__ultrix__) +#if defined (vax) || defined (__vax) || defined (__vax__) || defined(mips) || defined(__mips) || defined(__mips__) || defined(MIPS) || defined(__MIPS__) +#include +#if defined(_SIZE_T_) || defined(SIGLOST) +#include +#endif +#endif +#endif +main () +{ +#if defined (sony) +#if defined (MIPSEB) + /* BFD wants "bsd" instead of "newsos". Perhaps BFD should be changed, + I don't know.... */ + printf ("mips-sony-bsd\n"); exit (0); +#else +#include + printf ("m68k-sony-newsos%s\n", +#ifdef NEWSOS4 + "4" +#else + "" +#endif + ); exit (0); +#endif +#endif + +#if defined (NeXT) +#if !defined (__ARCHITECTURE__) +#define __ARCHITECTURE__ "m68k" +#endif + int version; + version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`; + if (version < 4) + printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version); + else + printf ("%s-next-openstep%d\n", __ARCHITECTURE__, version); + exit (0); +#endif + +#if defined (MULTIMAX) || defined (n16) +#if defined (UMAXV) + printf ("ns32k-encore-sysv\n"); exit (0); +#else +#if defined (CMU) + printf ("ns32k-encore-mach\n"); exit (0); +#else + printf ("ns32k-encore-bsd\n"); exit (0); +#endif +#endif +#endif + +#if defined (__386BSD__) + printf ("i386-pc-bsd\n"); exit (0); +#endif + +#if defined (sequent) +#if defined (i386) + printf ("i386-sequent-dynix\n"); exit (0); +#endif +#if defined (ns32000) + printf ("ns32k-sequent-dynix\n"); exit (0); +#endif +#endif + +#if defined (_SEQUENT_) + struct utsname un; + + uname(&un); + if (strncmp(un.version, "V2", 2) == 0) { + printf ("i386-sequent-ptx2\n"); exit (0); + } + if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */ + printf ("i386-sequent-ptx1\n"); exit (0); + } + printf ("i386-sequent-ptx\n"); exit (0); +#endif + +#if defined (vax) +#if !defined (ultrix) +#include +#if defined (BSD) +#if BSD == 43 + printf ("vax-dec-bsd4.3\n"); exit (0); +#else +#if BSD == 199006 + printf ("vax-dec-bsd4.3reno\n"); exit (0); +#else + printf ("vax-dec-bsd\n"); exit (0); +#endif +#endif +#else + printf ("vax-dec-bsd\n"); exit (0); +#endif +#else +#if defined(_SIZE_T_) || defined(SIGLOST) + struct utsname un; + uname (&un); + printf ("vax-dec-ultrix%s\n", un.release); exit (0); +#else + printf ("vax-dec-ultrix\n"); exit (0); +#endif +#endif +#endif +#if defined(ultrix) || defined(_ultrix) || defined(__ultrix) || defined(__ultrix__) +#if defined(mips) || defined(__mips) || defined(__mips__) || defined(MIPS) || defined(__MIPS__) +#if defined(_SIZE_T_) || defined(SIGLOST) + struct utsname *un; + uname (&un); + printf ("mips-dec-ultrix%s\n", un.release); exit (0); +#else + printf ("mips-dec-ultrix\n"); exit (0); +#endif +#endif +#endif + +#if defined (alliant) && defined (i860) + printf ("i860-alliant-bsd\n"); exit (0); +#endif + + exit (1); +} +EOF + +$CC_FOR_BUILD -o "$dummy" "$dummy.c" 2>/dev/null && SYSTEM_NAME=`"$dummy"` && + { echo "$SYSTEM_NAME"; exit; } + +# Apollos put the system type in the environment. +test -d /usr/apollo && { echo "$ISP-apollo-$SYSTYPE"; exit; } + +echo "$0: unable to guess system type" >&2 + +case $UNAME_MACHINE:$UNAME_SYSTEM in + mips:Linux | mips64:Linux) + # If we got here on MIPS GNU/Linux, output extra information. + cat >&2 <&2 <&2 </dev/null || echo unknown` +uname -r = `(uname -r) 2>/dev/null || echo unknown` +uname -s = `(uname -s) 2>/dev/null || echo unknown` +uname -v = `(uname -v) 2>/dev/null || echo unknown` + +/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null` +/bin/uname -X = `(/bin/uname -X) 2>/dev/null` + +hostinfo = `(hostinfo) 2>/dev/null` +/bin/universe = `(/bin/universe) 2>/dev/null` +/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null` +/bin/arch = `(/bin/arch) 2>/dev/null` +/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null` +/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null` + +UNAME_MACHINE = "$UNAME_MACHINE" +UNAME_RELEASE = "$UNAME_RELEASE" +UNAME_SYSTEM = "$UNAME_SYSTEM" +UNAME_VERSION = "$UNAME_VERSION" +EOF +fi + +exit 1 + +# Local variables: +# eval: (add-hook 'before-save-hook 'time-stamp) +# time-stamp-start: "timestamp='" +# time-stamp-format: "%:y-%02m-%02d" +# time-stamp-end: "'" +# End: diff --git a/third_party/json-c/config.h.win32 b/third_party/json-c/config.h similarity index 63% rename from third_party/json-c/config.h.win32 rename to third_party/json-c/config.h index 798343a93..10fecb96b 100644 --- a/third_party/json-c/config.h.win32 +++ b/third_party/json-c/config.h @@ -1,205 +1,211 @@ -/* config.h.in. Generated from configure.ac by autoheader. */ - -/* Enable RDRANR Hardware RNG Hash Seed */ -#undef ENABLE_RDRAND - -/* Define if .gnu.warning accepts long strings. */ -#undef HAS_GNU_WARNING_LONG - -/* Define to 1 if you have the declaration of `INFINITY', and to 0 if you - don't. */ -#if (defined(_MSC_VER) && _MSC_VER >= 1800) || defined(__MINGW32__) -#define HAVE_DECL_INFINITY 1 -#endif - -/* Define to 1 if you have the declaration of `isinf', and to 0 if you don't. - */ -#if (defined(_MSC_VER) && _MSC_VER >= 1800) || defined(__MINGW32__) -#define HAVE_DECL_ISINF 1 -#endif - -/* Define to 1 if you have the declaration of `isnan', and to 0 if you don't. - */ -#if (defined(_MSC_VER) && _MSC_VER >= 1800) || defined(__MINGW32__) -#define HAVE_DECL_ISNAN 1 -#endif - -/* Define to 1 if you have the declaration of `nan', and to 0 if you don't. */ -#if (defined(_MSC_VER) && _MSC_VER >= 1800) || defined(__MINGW32__) -#define HAVE_DECL_NAN 1 -#endif - -/* Define to 1 if you have the declaration of `_finite', and to 0 if you - don't. */ -#define HAVE_DECL__FINITE 1 - -/* Define to 1 if you have the declaration of `_isnan', and to 0 if you don't. - */ -#define HAVE_DECL__ISNAN 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_DLFCN_H 1 - -/* Define to 1 if you don't have `vprintf' but do have `_doprnt.' */ -#define HAVE_DOPRNT 1 - -/* Define to 1 if you have the header file. */ -#undef HAVE_ENDIAN_H - -/* Define to 1 if you have the header file. */ -#define HAVE_FCNTL_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_INTTYPES_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_LIMITS_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_LOCALE_H 1 - -/* Define to 1 if your system has a GNU libc compatible `malloc' function, and - to 0 otherwise. */ -#define HAVE_MALLOC 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_MEMORY_H 1 - -/* Define to 1 if you have the `open' function. */ -#define HAVE_OPEN 1 - -/* Define to 1 if your system has a GNU libc compatible `realloc' function, - and to 0 otherwise. */ -#define HAVE_REALLOC 1 - -/* Define to 1 if you have the `setlocale' function. */ -#define HAVE_SETLOCALE 1 - -/* Define to 1 if you have the `snprintf' function. */ -#if defined(__MINGW32__) -#define HAVE_SNPRINTF 1 -#else -#undef HAVE_SNPRINTF -#endif - -/* Define to 1 if you have the header file. */ -#define HAVE_STDARG_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STDINT_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STDLIB_H 1 - -/* Define to 1 if you have the `strcasecmp' function. */ -#define HAVE_STRCASECMP 1 - -/* Define to 1 if you have the `strdup' function. */ -#define HAVE_STRDUP 0 - -/* Define to 1 if you have the `strerror' function. */ -#define HAVE_STRERROR 1 - -/* Define to 1 if you have the header file. */ -#undef HAVE_STRINGS_H - -/* Define to 1 if you have the header file. */ -#define HAVE_STRING_H 1 - -/* Define to 1 if you have the `strncasecmp' function. */ -#if defined(__MINGW32__) -#define HAVE_STRNCASECMP 1 -#else -#undef HAVE_STRNCASECMP -#endif - -#cmakedefine HAVE_STRTOLL -#cmakedefine strtoll @cmake_strtoll@ - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYSLOG_H - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_CDEFS_H 1 - -/* Define to 1 if you have the header file. */ -#if defined(__MINGW32__) -#define HAVE_SYS_PARAM_H 1 -#else -#undef HAVE_SYS_PARAM_H -#endif - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_STAT_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_TYPES_H 1 - -/* Define to 1 if you have the header file. */ -#if defined(__MINGW32__) -#define HAVE_UNISTD_H 1 -#else -#undef HAVE_UNISTD_H -#endif - -/* Define to 1 if you have the `vasprintf' function. */ -#if defined(__MINGW32__) -#define HAVE_VASPRINTF 1 -#else -#undef HAVE_VASPRINTF -#endif - -/* Define to 1 if you have the `vprintf' function. */ -#define HAVE_VPRINTF 1 - -/* Define to 1 if you have the `vsnprintf' function. */ -#define HAVE_VSNPRINTF 1 - -/* Define to 1 if you have the `vsyslog' function. */ -#undef HAVE_VSYSLOG - -/* Define to the sub-directory in which libtool stores uninstalled libraries. - */ -#undef LT_OBJDIR - -/* Define to 1 if your C compiler doesn't accept -c and -o together. */ -/* #undef NO_MINUS_C_MINUS_O */ - -/* Name of package */ -#define PACKAGE "json-c" - -/* Define to the address where bug reports for this package should be sent. */ -#define PACKAGE_BUGREPORT "json-c@googlegroups.com" - -/* Define to the full name of this package. */ -#define PACKAGE_NAME "JSON C Library" - -/* Define to the full name and version of this package. */ -#define PACKAGE_STRING "JSON C Library 0.13.1" - -/* Define to the one symbol short name of this package. */ -#define PACKAGE_TARNAME "json-c" - -/* Define to the home page for this package. */ -#define PACKAGE_URL "https://github.com/json-c/json-c" - -/* Define to the version of this package. */ -#define PACKAGE_VERSION "0.13.1" - -/* Define to 1 if you have the ANSI C header files. */ -#define STDC_HEADERS 1 - -/* Version number of package */ -#define VERSION "0.13.1" - -/* Define to empty if `const' does not conform to ANSI C. */ -/* #undef const */ - -/* Define to rpl_malloc if the replacement function should be used. */ -/* #undef malloc */ - -/* Define to rpl_realloc if the replacement function should be used. */ -/* #undef realloc */ - -/* Define to `unsigned int' if does not define. */ -/* #undef size_t */ +/* config.h. Generated from config.h.in by configure. */ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* Enable RDRAND Hardware RNG Hash Seed */ +#define ENABLE_RDRAND 1 + +/* Enable partial threading support */ +#define ENABLE_THREADING 1 + +/* Has atomic builtins */ +#define HAVE_ATOMIC_BUILTINS 1 + +/* Define to 1 if you have the declaration of `INFINITY', and to 0 if you + don't. */ +#define HAVE_DECL_INFINITY 1 + +/* Define to 1 if you have the declaration of `isinf', and to 0 if you don't. + */ +#define HAVE_DECL_ISINF 1 + +/* Define to 1 if you have the declaration of `isnan', and to 0 if you don't. + */ +#define HAVE_DECL_ISNAN 1 + +/* Define to 1 if you have the declaration of `nan', and to 0 if you don't. */ +#define HAVE_DECL_NAN 1 + +/* Define to 1 if you have the declaration of `_finite', and to 0 if you + don't. */ +#define HAVE_DECL__FINITE 0 + +/* Define to 1 if you have the declaration of `_isnan', and to 0 if you don't. + */ +#define HAVE_DECL__ISNAN 0 + +/* Define to 1 if you have the header file. */ +#define HAVE_DLFCN_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_ENDIAN_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_FCNTL_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_FLOAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_LIMITS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_LOCALE_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_MEMORY_H 1 + +/* Define to 1 if you have the `open' function. */ +#define HAVE_OPEN 1 + +/* Define to 1 if you have the `realloc' function. */ +#define HAVE_REALLOC 1 + +/* Define to 1 if you have the `setlocale' function. */ +#define HAVE_SETLOCALE 1 + +/* Define to 1 if you have the `snprintf' function. */ +#define HAVE_SNPRINTF 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDARG_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDIO_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the `strcasecmp' function. */ +#define HAVE_STRCASECMP 1 + +/* Define to 1 if you have the `strdup' function. */ +#define HAVE_STRDUP 1 + +/* Define to 1 if you have the `strerror' function. */ +#define HAVE_STRERROR 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the `strncasecmp' function. */ +#define HAVE_STRNCASECMP 1 + +/* Define to 1 if you have the `strtoll' function. */ +#define HAVE_STRTOLL 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYSLOG_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_CDEFS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_PARAM_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_RESOURCE_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Define to 1 if you have the `uselocale' function. */ +#define HAVE_USELOCALE 1 + +/* Define to 1 if you have the `vasprintf' function. */ +#define HAVE_VASPRINTF 1 + +/* Define to 1 if you have the `vprintf' function. */ +#define HAVE_VPRINTF 1 + +/* Define to 1 if you have the `vsnprintf' function. */ +#define HAVE_VSNPRINTF 1 + +/* Define to 1 if you have the `vsyslog' function. */ +#define HAVE_VSYSLOG 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_XLOCALE_H */ + +/* Define to 1 if you have the `_doprnt' function. */ +/* #undef HAVE__DOPRNT */ + +/* Define to 1 if you have the `_strtoi64' function. */ +/* #undef HAVE__STRTOI64 */ + +/* Have __thread */ +#define HAVE___THREAD 1 + +/* Public define for json_inttypes.h */ +#define JSON_C_HAVE_INTTYPES_H 1 + +/* Define to the sub-directory where libtool stores uninstalled libraries. */ +#define LT_OBJDIR ".libs/" + +/* Name of package */ +#define PACKAGE "json-c" + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "json-c@googlegroups.com" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "json-c" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "json-c 0.17.0" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "json-c" + +/* Define to the home page for this package. */ +#define PACKAGE_URL "" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "0.17.0" + +/* The size of `int', as computed by sizeof. */ +#define SIZEOF_INT 4 + +/* The size of `int64_t', as computed by sizeof. */ +#define SIZEOF_INT64_T 8 + +/* The size of `long', as computed by sizeof. */ +#define SIZEOF_LONG 8 + +/* The size of `long long', as computed by sizeof. */ +#define SIZEOF_LONG_LONG 8 + +/* The size of `size_t', as computed by sizeof. */ +#define SIZEOF_SIZE_T 8 + +/* The size of `ssize_t', as computed by sizeof. */ +#define SIZEOF_SSIZE_T 8 + +/* Specifier for __thread */ +#define SPEC___THREAD __thread + +/* Define to 1 if you have the ANSI C header files */ +#define STDC_HEADERS 1 + +/* Version number of package */ +#define VERSION "0.17.0" + +/* Define to empty if `const' does not conform to ANSI C. */ +/* #undef const */ + +/* Define to `unsigned int' if does not define. */ +/* #undef size_t */ diff --git a/third_party/json-c/config.sub b/third_party/json-c/config.sub new file mode 100755 index 000000000..dba16e84c --- /dev/null +++ b/third_party/json-c/config.sub @@ -0,0 +1,1890 @@ +#! /bin/sh +# Configuration validation subroutine script. +# Copyright 1992-2022 Free Software Foundation, Inc. + +# shellcheck disable=SC2006,SC2268 # see below for rationale + +timestamp='2022-01-03' + +# This file is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, see . +# +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that +# program. This Exception is an additional permission under section 7 +# of the GNU General Public License, version 3 ("GPLv3"). + + +# Please send patches to . +# +# Configuration subroutine to validate and canonicalize a configuration type. +# Supply the specified configuration type as an argument. +# If it is invalid, we print an error message on stderr and exit with code 1. +# Otherwise, we print the canonical config type on stdout and succeed. + +# You can get the latest version of this script from: +# https://git.savannah.gnu.org/cgit/config.git/plain/config.sub + +# This file is supposed to be the same for all GNU packages +# and recognize all the CPU types, system types and aliases +# that are meaningful with *any* GNU software. +# Each package is responsible for reporting which valid configurations +# it does not support. The user should be able to distinguish +# a failure to support a valid configuration from a meaningless +# configuration. + +# The goal of this file is to map all the various variations of a given +# machine specification into a single specification in the form: +# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM +# or in some cases, the newer four-part form: +# CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM +# It is wrong to echo any other type of specification. + +# The "shellcheck disable" line above the timestamp inhibits complaints +# about features and limitations of the classic Bourne shell that were +# superseded or lifted in POSIX. However, this script identifies a wide +# variety of pre-POSIX systems that do not have POSIX shells at all, and +# even some reasonably current systems (Solaris 10 as case-in-point) still +# have a pre-POSIX /bin/sh. + +me=`echo "$0" | sed -e 's,.*/,,'` + +usage="\ +Usage: $0 [OPTION] CPU-MFR-OPSYS or ALIAS + +Canonicalize a configuration name. + +Options: + -h, --help print this help, then exit + -t, --time-stamp print date of last modification, then exit + -v, --version print version number, then exit + +Report bugs and patches to ." + +version="\ +GNU config.sub ($timestamp) + +Copyright 1992-2022 Free Software Foundation, Inc. + +This is free software; see the source for copying conditions. There is NO +warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." + +help=" +Try \`$me --help' for more information." + +# Parse command line +while test $# -gt 0 ; do + case $1 in + --time-stamp | --time* | -t ) + echo "$timestamp" ; exit ;; + --version | -v ) + echo "$version" ; exit ;; + --help | --h* | -h ) + echo "$usage"; exit ;; + -- ) # Stop option processing + shift; break ;; + - ) # Use stdin as input. + break ;; + -* ) + echo "$me: invalid option $1$help" >&2 + exit 1 ;; + + *local*) + # First pass through any local machine types. + echo "$1" + exit ;; + + * ) + break ;; + esac +done + +case $# in + 0) echo "$me: missing argument$help" >&2 + exit 1;; + 1) ;; + *) echo "$me: too many arguments$help" >&2 + exit 1;; +esac + +# Split fields of configuration type +# shellcheck disable=SC2162 +saved_IFS=$IFS +IFS="-" read field1 field2 field3 field4 <&2 + exit 1 + ;; + *-*-*-*) + basic_machine=$field1-$field2 + basic_os=$field3-$field4 + ;; + *-*-*) + # Ambiguous whether COMPANY is present, or skipped and KERNEL-OS is two + # parts + maybe_os=$field2-$field3 + case $maybe_os in + nto-qnx* | linux-* | uclinux-uclibc* \ + | uclinux-gnu* | kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* \ + | netbsd*-eabi* | kopensolaris*-gnu* | cloudabi*-eabi* \ + | storm-chaos* | os2-emx* | rtmk-nova*) + basic_machine=$field1 + basic_os=$maybe_os + ;; + android-linux) + basic_machine=$field1-unknown + basic_os=linux-android + ;; + *) + basic_machine=$field1-$field2 + basic_os=$field3 + ;; + esac + ;; + *-*) + # A lone config we happen to match not fitting any pattern + case $field1-$field2 in + decstation-3100) + basic_machine=mips-dec + basic_os= + ;; + *-*) + # Second component is usually, but not always the OS + case $field2 in + # Prevent following clause from handling this valid os + sun*os*) + basic_machine=$field1 + basic_os=$field2 + ;; + zephyr*) + basic_machine=$field1-unknown + basic_os=$field2 + ;; + # Manufacturers + dec* | mips* | sequent* | encore* | pc533* | sgi* | sony* \ + | att* | 7300* | 3300* | delta* | motorola* | sun[234]* \ + | unicom* | ibm* | next | hp | isi* | apollo | altos* \ + | convergent* | ncr* | news | 32* | 3600* | 3100* \ + | hitachi* | c[123]* | convex* | sun | crds | omron* | dg \ + | ultra | tti* | harris | dolphin | highlevel | gould \ + | cbm | ns | masscomp | apple | axis | knuth | cray \ + | microblaze* | sim | cisco \ + | oki | wec | wrs | winbond) + basic_machine=$field1-$field2 + basic_os= + ;; + *) + basic_machine=$field1 + basic_os=$field2 + ;; + esac + ;; + esac + ;; + *) + # Convert single-component short-hands not valid as part of + # multi-component configurations. + case $field1 in + 386bsd) + basic_machine=i386-pc + basic_os=bsd + ;; + a29khif) + basic_machine=a29k-amd + basic_os=udi + ;; + adobe68k) + basic_machine=m68010-adobe + basic_os=scout + ;; + alliant) + basic_machine=fx80-alliant + basic_os= + ;; + altos | altos3068) + basic_machine=m68k-altos + basic_os= + ;; + am29k) + basic_machine=a29k-none + basic_os=bsd + ;; + amdahl) + basic_machine=580-amdahl + basic_os=sysv + ;; + amiga) + basic_machine=m68k-unknown + basic_os= + ;; + amigaos | amigados) + basic_machine=m68k-unknown + basic_os=amigaos + ;; + amigaunix | amix) + basic_machine=m68k-unknown + basic_os=sysv4 + ;; + apollo68) + basic_machine=m68k-apollo + basic_os=sysv + ;; + apollo68bsd) + basic_machine=m68k-apollo + basic_os=bsd + ;; + aros) + basic_machine=i386-pc + basic_os=aros + ;; + aux) + basic_machine=m68k-apple + basic_os=aux + ;; + balance) + basic_machine=ns32k-sequent + basic_os=dynix + ;; + blackfin) + basic_machine=bfin-unknown + basic_os=linux + ;; + cegcc) + basic_machine=arm-unknown + basic_os=cegcc + ;; + convex-c1) + basic_machine=c1-convex + basic_os=bsd + ;; + convex-c2) + basic_machine=c2-convex + basic_os=bsd + ;; + convex-c32) + basic_machine=c32-convex + basic_os=bsd + ;; + convex-c34) + basic_machine=c34-convex + basic_os=bsd + ;; + convex-c38) + basic_machine=c38-convex + basic_os=bsd + ;; + cray) + basic_machine=j90-cray + basic_os=unicos + ;; + crds | unos) + basic_machine=m68k-crds + basic_os= + ;; + da30) + basic_machine=m68k-da30 + basic_os= + ;; + decstation | pmax | pmin | dec3100 | decstatn) + basic_machine=mips-dec + basic_os= + ;; + delta88) + basic_machine=m88k-motorola + basic_os=sysv3 + ;; + dicos) + basic_machine=i686-pc + basic_os=dicos + ;; + djgpp) + basic_machine=i586-pc + basic_os=msdosdjgpp + ;; + ebmon29k) + basic_machine=a29k-amd + basic_os=ebmon + ;; + es1800 | OSE68k | ose68k | ose | OSE) + basic_machine=m68k-ericsson + basic_os=ose + ;; + gmicro) + basic_machine=tron-gmicro + basic_os=sysv + ;; + go32) + basic_machine=i386-pc + basic_os=go32 + ;; + h8300hms) + basic_machine=h8300-hitachi + basic_os=hms + ;; + h8300xray) + basic_machine=h8300-hitachi + basic_os=xray + ;; + h8500hms) + basic_machine=h8500-hitachi + basic_os=hms + ;; + harris) + basic_machine=m88k-harris + basic_os=sysv3 + ;; + hp300 | hp300hpux) + basic_machine=m68k-hp + basic_os=hpux + ;; + hp300bsd) + basic_machine=m68k-hp + basic_os=bsd + ;; + hppaosf) + basic_machine=hppa1.1-hp + basic_os=osf + ;; + hppro) + basic_machine=hppa1.1-hp + basic_os=proelf + ;; + i386mach) + basic_machine=i386-mach + basic_os=mach + ;; + isi68 | isi) + basic_machine=m68k-isi + basic_os=sysv + ;; + m68knommu) + basic_machine=m68k-unknown + basic_os=linux + ;; + magnum | m3230) + basic_machine=mips-mips + basic_os=sysv + ;; + merlin) + basic_machine=ns32k-utek + basic_os=sysv + ;; + mingw64) + basic_machine=x86_64-pc + basic_os=mingw64 + ;; + mingw32) + basic_machine=i686-pc + basic_os=mingw32 + ;; + mingw32ce) + basic_machine=arm-unknown + basic_os=mingw32ce + ;; + monitor) + basic_machine=m68k-rom68k + basic_os=coff + ;; + morphos) + basic_machine=powerpc-unknown + basic_os=morphos + ;; + moxiebox) + basic_machine=moxie-unknown + basic_os=moxiebox + ;; + msdos) + basic_machine=i386-pc + basic_os=msdos + ;; + msys) + basic_machine=i686-pc + basic_os=msys + ;; + mvs) + basic_machine=i370-ibm + basic_os=mvs + ;; + nacl) + basic_machine=le32-unknown + basic_os=nacl + ;; + ncr3000) + basic_machine=i486-ncr + basic_os=sysv4 + ;; + netbsd386) + basic_machine=i386-pc + basic_os=netbsd + ;; + netwinder) + basic_machine=armv4l-rebel + basic_os=linux + ;; + news | news700 | news800 | news900) + basic_machine=m68k-sony + basic_os=newsos + ;; + news1000) + basic_machine=m68030-sony + basic_os=newsos + ;; + necv70) + basic_machine=v70-nec + basic_os=sysv + ;; + nh3000) + basic_machine=m68k-harris + basic_os=cxux + ;; + nh[45]000) + basic_machine=m88k-harris + basic_os=cxux + ;; + nindy960) + basic_machine=i960-intel + basic_os=nindy + ;; + mon960) + basic_machine=i960-intel + basic_os=mon960 + ;; + nonstopux) + basic_machine=mips-compaq + basic_os=nonstopux + ;; + os400) + basic_machine=powerpc-ibm + basic_os=os400 + ;; + OSE68000 | ose68000) + basic_machine=m68000-ericsson + basic_os=ose + ;; + os68k) + basic_machine=m68k-none + basic_os=os68k + ;; + paragon) + basic_machine=i860-intel + basic_os=osf + ;; + parisc) + basic_machine=hppa-unknown + basic_os=linux + ;; + psp) + basic_machine=mipsallegrexel-sony + basic_os=psp + ;; + pw32) + basic_machine=i586-unknown + basic_os=pw32 + ;; + rdos | rdos64) + basic_machine=x86_64-pc + basic_os=rdos + ;; + rdos32) + basic_machine=i386-pc + basic_os=rdos + ;; + rom68k) + basic_machine=m68k-rom68k + basic_os=coff + ;; + sa29200) + basic_machine=a29k-amd + basic_os=udi + ;; + sei) + basic_machine=mips-sei + basic_os=seiux + ;; + sequent) + basic_machine=i386-sequent + basic_os= + ;; + sps7) + basic_machine=m68k-bull + basic_os=sysv2 + ;; + st2000) + basic_machine=m68k-tandem + basic_os= + ;; + stratus) + basic_machine=i860-stratus + basic_os=sysv4 + ;; + sun2) + basic_machine=m68000-sun + basic_os= + ;; + sun2os3) + basic_machine=m68000-sun + basic_os=sunos3 + ;; + sun2os4) + basic_machine=m68000-sun + basic_os=sunos4 + ;; + sun3) + basic_machine=m68k-sun + basic_os= + ;; + sun3os3) + basic_machine=m68k-sun + basic_os=sunos3 + ;; + sun3os4) + basic_machine=m68k-sun + basic_os=sunos4 + ;; + sun4) + basic_machine=sparc-sun + basic_os= + ;; + sun4os3) + basic_machine=sparc-sun + basic_os=sunos3 + ;; + sun4os4) + basic_machine=sparc-sun + basic_os=sunos4 + ;; + sun4sol2) + basic_machine=sparc-sun + basic_os=solaris2 + ;; + sun386 | sun386i | roadrunner) + basic_machine=i386-sun + basic_os= + ;; + sv1) + basic_machine=sv1-cray + basic_os=unicos + ;; + symmetry) + basic_machine=i386-sequent + basic_os=dynix + ;; + t3e) + basic_machine=alphaev5-cray + basic_os=unicos + ;; + t90) + basic_machine=t90-cray + basic_os=unicos + ;; + toad1) + basic_machine=pdp10-xkl + basic_os=tops20 + ;; + tpf) + basic_machine=s390x-ibm + basic_os=tpf + ;; + udi29k) + basic_machine=a29k-amd + basic_os=udi + ;; + ultra3) + basic_machine=a29k-nyu + basic_os=sym1 + ;; + v810 | necv810) + basic_machine=v810-nec + basic_os=none + ;; + vaxv) + basic_machine=vax-dec + basic_os=sysv + ;; + vms) + basic_machine=vax-dec + basic_os=vms + ;; + vsta) + basic_machine=i386-pc + basic_os=vsta + ;; + vxworks960) + basic_machine=i960-wrs + basic_os=vxworks + ;; + vxworks68) + basic_machine=m68k-wrs + basic_os=vxworks + ;; + vxworks29k) + basic_machine=a29k-wrs + basic_os=vxworks + ;; + xbox) + basic_machine=i686-pc + basic_os=mingw32 + ;; + ymp) + basic_machine=ymp-cray + basic_os=unicos + ;; + *) + basic_machine=$1 + basic_os= + ;; + esac + ;; +esac + +# Decode 1-component or ad-hoc basic machines +case $basic_machine in + # Here we handle the default manufacturer of certain CPU types. It is in + # some cases the only manufacturer, in others, it is the most popular. + w89k) + cpu=hppa1.1 + vendor=winbond + ;; + op50n) + cpu=hppa1.1 + vendor=oki + ;; + op60c) + cpu=hppa1.1 + vendor=oki + ;; + ibm*) + cpu=i370 + vendor=ibm + ;; + orion105) + cpu=clipper + vendor=highlevel + ;; + mac | mpw | mac-mpw) + cpu=m68k + vendor=apple + ;; + pmac | pmac-mpw) + cpu=powerpc + vendor=apple + ;; + + # Recognize the various machine names and aliases which stand + # for a CPU type and a company and sometimes even an OS. + 3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc) + cpu=m68000 + vendor=att + ;; + 3b*) + cpu=we32k + vendor=att + ;; + bluegene*) + cpu=powerpc + vendor=ibm + basic_os=cnk + ;; + decsystem10* | dec10*) + cpu=pdp10 + vendor=dec + basic_os=tops10 + ;; + decsystem20* | dec20*) + cpu=pdp10 + vendor=dec + basic_os=tops20 + ;; + delta | 3300 | motorola-3300 | motorola-delta \ + | 3300-motorola | delta-motorola) + cpu=m68k + vendor=motorola + ;; + dpx2*) + cpu=m68k + vendor=bull + basic_os=sysv3 + ;; + encore | umax | mmax) + cpu=ns32k + vendor=encore + ;; + elxsi) + cpu=elxsi + vendor=elxsi + basic_os=${basic_os:-bsd} + ;; + fx2800) + cpu=i860 + vendor=alliant + ;; + genix) + cpu=ns32k + vendor=ns + ;; + h3050r* | hiux*) + cpu=hppa1.1 + vendor=hitachi + basic_os=hiuxwe2 + ;; + hp3k9[0-9][0-9] | hp9[0-9][0-9]) + cpu=hppa1.0 + vendor=hp + ;; + hp9k2[0-9][0-9] | hp9k31[0-9]) + cpu=m68000 + vendor=hp + ;; + hp9k3[2-9][0-9]) + cpu=m68k + vendor=hp + ;; + hp9k6[0-9][0-9] | hp6[0-9][0-9]) + cpu=hppa1.0 + vendor=hp + ;; + hp9k7[0-79][0-9] | hp7[0-79][0-9]) + cpu=hppa1.1 + vendor=hp + ;; + hp9k78[0-9] | hp78[0-9]) + # FIXME: really hppa2.0-hp + cpu=hppa1.1 + vendor=hp + ;; + hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893) + # FIXME: really hppa2.0-hp + cpu=hppa1.1 + vendor=hp + ;; + hp9k8[0-9][13679] | hp8[0-9][13679]) + cpu=hppa1.1 + vendor=hp + ;; + hp9k8[0-9][0-9] | hp8[0-9][0-9]) + cpu=hppa1.0 + vendor=hp + ;; + i*86v32) + cpu=`echo "$1" | sed -e 's/86.*/86/'` + vendor=pc + basic_os=sysv32 + ;; + i*86v4*) + cpu=`echo "$1" | sed -e 's/86.*/86/'` + vendor=pc + basic_os=sysv4 + ;; + i*86v) + cpu=`echo "$1" | sed -e 's/86.*/86/'` + vendor=pc + basic_os=sysv + ;; + i*86sol2) + cpu=`echo "$1" | sed -e 's/86.*/86/'` + vendor=pc + basic_os=solaris2 + ;; + j90 | j90-cray) + cpu=j90 + vendor=cray + basic_os=${basic_os:-unicos} + ;; + iris | iris4d) + cpu=mips + vendor=sgi + case $basic_os in + irix*) + ;; + *) + basic_os=irix4 + ;; + esac + ;; + miniframe) + cpu=m68000 + vendor=convergent + ;; + *mint | mint[0-9]* | *MiNT | *MiNT[0-9]*) + cpu=m68k + vendor=atari + basic_os=mint + ;; + news-3600 | risc-news) + cpu=mips + vendor=sony + basic_os=newsos + ;; + next | m*-next) + cpu=m68k + vendor=next + case $basic_os in + openstep*) + ;; + nextstep*) + ;; + ns2*) + basic_os=nextstep2 + ;; + *) + basic_os=nextstep3 + ;; + esac + ;; + np1) + cpu=np1 + vendor=gould + ;; + op50n-* | op60c-*) + cpu=hppa1.1 + vendor=oki + basic_os=proelf + ;; + pa-hitachi) + cpu=hppa1.1 + vendor=hitachi + basic_os=hiuxwe2 + ;; + pbd) + cpu=sparc + vendor=tti + ;; + pbb) + cpu=m68k + vendor=tti + ;; + pc532) + cpu=ns32k + vendor=pc532 + ;; + pn) + cpu=pn + vendor=gould + ;; + power) + cpu=power + vendor=ibm + ;; + ps2) + cpu=i386 + vendor=ibm + ;; + rm[46]00) + cpu=mips + vendor=siemens + ;; + rtpc | rtpc-*) + cpu=romp + vendor=ibm + ;; + sde) + cpu=mipsisa32 + vendor=sde + basic_os=${basic_os:-elf} + ;; + simso-wrs) + cpu=sparclite + vendor=wrs + basic_os=vxworks + ;; + tower | tower-32) + cpu=m68k + vendor=ncr + ;; + vpp*|vx|vx-*) + cpu=f301 + vendor=fujitsu + ;; + w65) + cpu=w65 + vendor=wdc + ;; + w89k-*) + cpu=hppa1.1 + vendor=winbond + basic_os=proelf + ;; + none) + cpu=none + vendor=none + ;; + leon|leon[3-9]) + cpu=sparc + vendor=$basic_machine + ;; + leon-*|leon[3-9]-*) + cpu=sparc + vendor=`echo "$basic_machine" | sed 's/-.*//'` + ;; + + *-*) + # shellcheck disable=SC2162 + saved_IFS=$IFS + IFS="-" read cpu vendor <&2 + exit 1 + ;; + esac + ;; +esac + +# Here we canonicalize certain aliases for manufacturers. +case $vendor in + digital*) + vendor=dec + ;; + commodore*) + vendor=cbm + ;; + *) + ;; +esac + +# Decode manufacturer-specific aliases for certain operating systems. + +if test x$basic_os != x +then + +# First recognize some ad-hoc cases, or perhaps split kernel-os, or else just +# set os. +case $basic_os in + gnu/linux*) + kernel=linux + os=`echo "$basic_os" | sed -e 's|gnu/linux|gnu|'` + ;; + os2-emx) + kernel=os2 + os=`echo "$basic_os" | sed -e 's|os2-emx|emx|'` + ;; + nto-qnx*) + kernel=nto + os=`echo "$basic_os" | sed -e 's|nto-qnx|qnx|'` + ;; + *-*) + # shellcheck disable=SC2162 + saved_IFS=$IFS + IFS="-" read kernel os <&2 + exit 1 + ;; +esac + +# As a final step for OS-related things, validate the OS-kernel combination +# (given a valid OS), if there is a kernel. +case $kernel-$os in + linux-gnu* | linux-dietlibc* | linux-android* | linux-newlib* \ + | linux-musl* | linux-relibc* | linux-uclibc* ) + ;; + uclinux-uclibc* ) + ;; + -dietlibc* | -newlib* | -musl* | -relibc* | -uclibc* ) + # These are just libc implementations, not actual OSes, and thus + # require a kernel. + echo "Invalid configuration \`$1': libc \`$os' needs explicit kernel." 1>&2 + exit 1 + ;; + kfreebsd*-gnu* | kopensolaris*-gnu*) + ;; + vxworks-simlinux | vxworks-simwindows | vxworks-spe) + ;; + nto-qnx*) + ;; + os2-emx) + ;; + *-eabi* | *-gnueabi*) + ;; + -*) + # Blank kernel with real OS is always fine. + ;; + *-*) + echo "Invalid configuration \`$1': Kernel \`$kernel' not known to work with OS \`$os'." 1>&2 + exit 1 + ;; +esac + +# Here we handle the case where we know the os, and the CPU type, but not the +# manufacturer. We pick the logical manufacturer. +case $vendor in + unknown) + case $cpu-$os in + *-riscix*) + vendor=acorn + ;; + *-sunos*) + vendor=sun + ;; + *-cnk* | *-aix*) + vendor=ibm + ;; + *-beos*) + vendor=be + ;; + *-hpux*) + vendor=hp + ;; + *-mpeix*) + vendor=hp + ;; + *-hiux*) + vendor=hitachi + ;; + *-unos*) + vendor=crds + ;; + *-dgux*) + vendor=dg + ;; + *-luna*) + vendor=omron + ;; + *-genix*) + vendor=ns + ;; + *-clix*) + vendor=intergraph + ;; + *-mvs* | *-opened*) + vendor=ibm + ;; + *-os400*) + vendor=ibm + ;; + s390-* | s390x-*) + vendor=ibm + ;; + *-ptx*) + vendor=sequent + ;; + *-tpf*) + vendor=ibm + ;; + *-vxsim* | *-vxworks* | *-windiss*) + vendor=wrs + ;; + *-aux*) + vendor=apple + ;; + *-hms*) + vendor=hitachi + ;; + *-mpw* | *-macos*) + vendor=apple + ;; + *-*mint | *-mint[0-9]* | *-*MiNT | *-MiNT[0-9]*) + vendor=atari + ;; + *-vos*) + vendor=stratus + ;; + esac + ;; +esac + +echo "$cpu-$vendor-${kernel:+$kernel-}$os" +exit + +# Local variables: +# eval: (add-hook 'before-save-hook 'time-stamp) +# time-stamp-start: "timestamp='" +# time-stamp-format: "%:y-%02m-%02d" +# time-stamp-end: "'" +# End: diff --git a/third_party/json-c/config/meson.build b/third_party/json-c/config/meson.build new file mode 100644 index 000000000..4cb286174 --- /dev/null +++ b/third_party/json-c/config/meson.build @@ -0,0 +1,136 @@ +# Copyright (c) 2022-2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. +# +# This software product is a proprietary product of NVIDIA CORPORATION & +# AFFILIATES (the "Company") and all right, title, and interest in and to the +# software product, including all associated intellectual property rights, are +# and shall remain exclusively with the Company. +# +# This software product is governed by the End User License Agreement +# provided with the software product. +# + +conf = configuration_data() +conf.set10('ENABLE_RDRAND', true) + +conf.set10('ENABLE_THREADING', true) + +check_headers = [ + 'dlfcn.h', + 'endian.h', + 'fcntl.h', + 'float.h', + 'inttypes.h', + 'limits.h', + 'locale.h', + 'memory.h', + 'stdarg.h', + 'stdint.h', + 'stdlib.h', + 'strings.h', + 'string.h', + 'syslog.h', + 'sys/cdefs.h', + 'sys/param.h', + 'sys/stat.h', + 'sys/types.h', + 'sys/resource.h', + 'unistd.h', + 'xlocale.h', +] + +foreach header : check_headers + if c_compiler.has_header(header) + conf.set10('HAVE_' + header.underscorify().to_upper(), true) + endif +endforeach + +stdc = ['stdlib.h', 'stdarg.h', 'string.h', 'float.h'] +have_stdc = true +foreach header : stdc + if not conf.has('HAVE_' + header.underscorify().to_upper()) + have_stdc = false + endif +endforeach +conf.set10('STDC_HEADERS', have_stdc) + +float_symbols = ['_isnan', '_finite'] +math_symbols = ['INFINITY', 'isinf', 'isnan', 'nan'] + +foreach symbol : float_symbols + if c_compiler.has_header_symbol('float.h', symbol) + conf.set10('HAVE_DECL_' + symbol.to_upper(), true) + endif +endforeach + +foreach symbol : math_symbols + if c_compiler.has_header_symbol('math.h', symbol) + conf.set10('HAVE_DECL_' + symbol.to_upper(), true) + endif +endforeach + +check_function = [ + 'snprintf', + 'vasprintf', + 'vsnprintf', + 'vprintf', + 'open', + 'realloc', + 'setlocale', + 'uselocale', + 'strcasecmp', + 'strncasecmp', + 'strdup', + 'strerror', + 'vsyslog', +] + +foreach function : check_function + if c_compiler.has_function(function) + conf.set10('HAVE_' + function.to_upper(), true) + endif +endforeach +conf.set10('HAVE_DOPRNT', c_compiler.has_function('_doprnt')) + +if c_compiler.get_id() == 'msvc' + if c_compiler.has_function('strtoll') + conf.set10('HAVE_STRTOLL', true) + conf.set('json_c_strtoll', 'strtoll') + elif c_compiler.has_function('_strtoi64') + conf.set10('HAVE_STRTOLL', true) + conf.set('json_c_strtoll', '_strtoi64') + endif +endif + +check_types = ['int', 'int64_t', 'long', 'long long', 'size_t', 'ssize_t'] +foreach type : check_types + size = c_compiler.sizeof(type, prefix: '#include ') + # W/A, since in windows the size of ssize_t can't be detected + if is_compiler_msvc and type == 'ssize_t' and size == -1 + size = c_compiler.sizeof('size_t', prefix: '#include ') + endif + conf.set('SIZEOF_' + type.underscorify().to_upper(), size) +endforeach + +if not is_compiler_msvc + if c_compiler.compiles('int main() { int i, x = 0; i = __sync_add_and_fetch(&x,1); return x; }') + conf.set10('HAVE_ATOMIC_BUILTINS', true) + endif +endif + +if c_compiler.compiles('__thread int x = 0; int main() { return 0; }') + conf.set10('HAVE___THREAD', true) +endif + +if conf.has('HAVE___THREAD') + conf.set('SPEC___THREAD', '__thread') +elif c_compiler.get_id() == 'msvc' + conf.set('SPEC___THREAD', '__declspec(thread)') +endif + +conf.set_quoted('VERSION', meson.project_version()) + +config_h = configure_file( + configuration: conf, + output: 'config.h', +) + diff --git a/third_party/json-c/configure.ac b/third_party/json-c/configure.ac index a1a0b3a0b..ab40b8166 100644 --- a/third_party/json-c/configure.ac +++ b/third_party/json-c/configure.ac @@ -1,64 +1,64 @@ AC_PREREQ(2.64) # Process this file with autoconf to produce a configure script. -AC_INIT([json-c], 0.13.1, [json-c@googlegroups.com]) +AC_INIT([json-c], 0.17.0, [json-c@googlegroups.com]) -AM_INIT_AUTOMAKE +AM_INIT_AUTOMAKE([foreign]) AC_CONFIG_MACRO_DIRS([autoconf-archive/m4]) AC_PROG_MAKE_SET - AC_CANONICAL_HOST +# Enable threading by default (as in Meson config) AC_ARG_ENABLE(threading, AS_HELP_STRING([--enable-threading], [Enable code to support partly multi-threaded use]), [if test x$enableval = xyes; then enable_threading=yes AC_DEFINE(ENABLE_THREADING, 1, [Enable partial threading support]) -fi]) - -if test "x$enable_threading" = "xyes"; then - AC_MSG_RESULT([Partial multi-threaded support enabled.]) -else - AC_MSG_RESULT([Multi-threaded support disabled. Use --enable-threading to enable.]) -fi +fi], +[enable_threading=yes + AC_DEFINE(ENABLE_THREADING, 1, [Enable partial threading support])]) +# Enable RDRAND by default (as in Meson config) AC_ARG_ENABLE(rdrand, AS_HELP_STRING([--enable-rdrand], [Enable RDRAND Hardware RNG Hash Seed generation on supported x86/x64 platforms.]), [if test x$enableval = xyes; then enable_rdrand=yes AC_DEFINE(ENABLE_RDRAND, 1, [Enable RDRAND Hardware RNG Hash Seed]) -fi]) - -if test "x$enable_rdrand" = "xyes"; then - AC_MSG_RESULT([RDRAND Hardware RNG Hash Seed enabled on supported x86/x64 platforms]) -else - AC_MSG_RESULT([RDRAND Hardware RNG Hash Seed disabled. Use --enable-rdrand to enable]) -fi +fi], +[enable_rdrand=yes + AC_DEFINE(ENABLE_RDRAND, 1, [Enable RDRAND Hardware RNG Hash Seed])]) # enable silent build by default m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) -# Checks for programs. - -# Checks for libraries. - -# Checks for header files. +# Checks for programs AM_PROG_CC_C_O AC_PROG_CC_C99 + +# Checks for header files AC_CONFIG_HEADER(config.h) AC_CONFIG_HEADER(json_config.h) AC_HEADER_STDC -AC_CHECK_HEADERS(fcntl.h limits.h strings.h syslog.h unistd.h [sys/cdefs.h] [sys/param.h] stdarg.h locale.h xlocale.h endian.h) + +# Check all headers from Meson config +AC_CHECK_HEADERS([dlfcn.h endian.h fcntl.h float.h inttypes.h limits.h locale.h memory.h stdarg.h stdint.h strings.h string.h syslog.h sys/cdefs.h sys/param.h sys/stat.h sys/types.h sys/resource.h unistd.h xlocale.h], [], [], []) + +# Special handling for inttypes.h (as in original) AC_CHECK_HEADER(inttypes.h,[AC_DEFINE([JSON_C_HAVE_INTTYPES_H],[1],[Public define for json_inttypes.h])]) -# Checks for typedefs, structures, and compiler characteristics. +# Check for STDC headers +AC_CHECK_HEADERS([stdlib.h stdarg.h string.h float.h], [], [], []) +AC_DEFINE(STDC_HEADERS, 1, [Define to 1 if you have the ANSI C header files]) + +# Checks for typedefs, structures, and compiler characteristics AC_C_CONST AC_TYPE_SIZE_T +# Check for __thread support AC_CACHE_CHECK([for __thread support], ac_cv___thread, [dnl AC_LINK_IFELSE([dnl AC_LANG_PROGRAM([[#undef __thread @@ -71,29 +71,14 @@ AS_IF([test "x$ac_cv___thread" != xno], AC_DEFINE(SPEC___THREAD, [__thread], [Specifier for __thread])] ) -# Checks for library functions. -AC_FUNC_VPRINTF -AC_FUNC_MEMCMP -AC_CHECK_FUNCS([realloc]) -AC_CHECK_FUNCS(strcasecmp strdup strerror snprintf vsnprintf vasprintf open vsyslog strncasecmp setlocale) -AC_CHECK_DECLS([INFINITY], [], [], [[#include ]]) -AC_CHECK_DECLS([nan], [], [], [[#include ]]) -AC_CHECK_DECLS([isnan], [], [], [[#include ]]) -AC_CHECK_DECLS([isinf], [], [], [[#include ]]) -AC_CHECK_DECLS([_isnan], [], [], [[#include ]]) -AC_CHECK_DECLS([_finite], [], [], [[#include ]]) +# Check for atomic builtins AC_MSG_CHECKING(for GCC atomic builtins) AC_LINK_IFELSE( [ AC_LANG_SOURCE([[ int main() { volatile unsigned int val = 1; - /* Note: __sync_val_compare_and_swap isn't checked here - * because it's protected by __GCC_HAVE_SYNC_COMPARE_AND_SWAP_, - * which is automatically defined by gcc. - */ __sync_add_and_fetch(&val, 1); - __sync_sub_and_fetch(&val, 1); return 0; } ]]) @@ -104,93 +89,40 @@ AC_LINK_IFELSE( ], [ AC_MSG_RESULT([no]) - AC_MSG_WARN([json-c will be built without atomic refcounts because atomic builtins are missing]) ]) -case "${host_os}" in - linux*) - AC_CHECK_FUNCS([uselocale]) - ;; - *) # Nothing - ;; -esac - -if test "$ac_cv_have_decl_isnan" = "yes" ; then - AC_TRY_LINK([#include ], [float f = 0.0; return isnan(f)], [], [LIBS="$LIBS -lm"]) -fi - -#check if .section.gnu.warning accepts long strings (for __warn_references) -AC_LANG_PUSH([C]) - -AC_MSG_CHECKING([if .gnu.warning accepts long strings]) -AC_LINK_IFELSE([AC_LANG_SOURCE([[ -extern void json_object_get(); -__asm__(".section .gnu.json_object_get,\n\t.ascii \"Please link against libjson-c instead of libjson\"\n\t.text"); +# Check for math functions and symbols +AC_CHECK_DECLS([INFINITY], [], [], [[#include ]]) +AC_CHECK_DECLS([nan], [], [], [[#include ]]) +AC_CHECK_DECLS([isnan], [], [], [[#include ]]) +AC_CHECK_DECLS([isinf], [], [], [[#include ]]) +AC_CHECK_DECLS([_isnan], [], [], [[#include ]]) +AC_CHECK_DECLS([_finite], [], [], [[#include ]]) -int main(int c,char* v) {return 0;} -]])], [ - AC_DEFINE(HAS_GNU_WARNING_LONG, 1, [Define if .gnu.warning accepts long strings.]) - AC_MSG_RESULT(yes) -], [ - AC_MSG_RESULT(no) -]) +# Check for functions +AC_CHECK_FUNCS([snprintf vasprintf vsnprintf vprintf open realloc setlocale uselocale strcasecmp strncasecmp strdup strerror vsyslog]) -AC_LANG_POP([C]) +# Check for _doprnt +AC_CHECK_FUNCS([_doprnt]) -LT_INIT - -# Check for the -Bsymbolic-functions linker flag -AC_ARG_ENABLE([Bsymbolic], - [AS_HELP_STRING([--disable-Bsymbolic], [Avoid linking with -Bsymbolic-function])], - [], - [enable_Bsymbolic=check]) - -AS_IF([test "x$enable_Bsymbolic" = "xcheck"], - [ - saved_LDFLAGS="${LDFLAGS}" - AC_MSG_CHECKING([for -Bsymbolic-functions linker flag]) - LDFLAGS=-Wl,-Bsymbolic-functions - AC_TRY_LINK([], [int main (void) { return 0; }], - [ - AC_MSG_RESULT([yes]) - enable_Bsymbolic=yes - ], - [ - AC_MSG_RESULT([no]) - enable_Bsymbolic=no - ]) - LDFLAGS="${saved_LDFLAGS}" - ]) - -AS_IF([test "x$enable_Bsymbolic" = "xyes"], [JSON_BSYMBOLIC_LDFLAGS=-Wl[,]-Bsymbolic-functions]) -AC_SUBST(JSON_BSYMBOLIC_LDFLAGS) - - -AC_LANG_PUSH([C]) -AC_MSG_CHECKING([for compatibility with _REENTRANT and toolchain headers]) -AC_LINK_IFELSE( -[ - AC_LANG_SOURCE([[ -/* uClibc toolchains without threading barf when _REENTRANT is defined */ -#define _REENTRANT 1 -#include -int main () -{ - return 0; -} -]])], [ - AC_MSG_RESULT(yes) - CFLAGS="$CFLAGS -D_REENTRANT" -], [ - AC_MSG_RESULT(no) -]) -AC_LANG_POP([C]) +# Check for strtoll variants (Windows compatibility) +AC_CHECK_FUNCS([strtoll _strtoi64]) +# Size checks AC_CHECK_SIZEOF([int]) AC_CHECK_SIZEOF([long]) AC_CHECK_SIZEOF([long long]) AC_CHECK_SIZEOF([size_t], [], [#include ]) AC_CHECK_SIZEOF([int64_t], [], [#include ]) +AC_CHECK_SIZEOF([ssize_t], [], [#include ]) + +# Link with math library if needed +if test "$ac_cv_have_decl_isnan" = "yes" ; then + AC_TRY_LINK([#include ], [float f = 0.0; return isnan(f)], [], [LIBS="$LIBS -lm"]) +fi + +# Initialize libtool +LT_INIT AC_CONFIG_FILES([ Makefile @@ -199,4 +131,3 @@ json-c-uninstalled.pc ]) AC_OUTPUT - diff --git a/third_party/json-c/debug.c b/third_party/json-c/debug.c index 4b5140aec..bb8c71f83 100644 --- a/third_party/json-c/debug.c +++ b/third_party/json-c/debug.c @@ -1,4 +1,6 @@ /* + * Original work: + * * $Id: debug.c,v 1.5 2006/01/26 02:16:28 mclark Exp $ * * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd. @@ -7,21 +9,33 @@ * This library is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See COPYING for details. * + * Modified Work: + * + * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. + * + * This software product is a proprietary product of NVIDIA CORPORATION & + * AFFILIATES (the "Company") and all right, title, and interest in and to the + * software product, including all associated intellectual property rights, are + * and shall remain exclusively with the Company. + * + * This software product is governed by the End User License Agreement + * provided with the software product. + * */ #include "config.h" +#include #include #include #include -#include #if HAVE_SYSLOG_H -# include +#include #endif /* HAVE_SYSLOG_H */ #if HAVE_UNISTD_H -# include +#include #endif /* HAVE_UNISTD_H */ #if HAVE_SYS_PARAM_H @@ -33,51 +47,64 @@ static int _syslog = 0; static int _debug = 0; -void mc_set_debug(int debug) { _debug = debug; } -int mc_get_debug(void) { return _debug; } +void doca_third_party_mc_set_debug(int debug) +{ + _debug = debug; +} +int doca_third_party_mc_get_debug(void) +{ + return _debug; +} -extern void mc_set_syslog(int syslog) +extern void doca_third_party_mc_set_syslog(int syslog) { - _syslog = syslog; + _syslog = syslog; } -void mc_debug(const char *msg, ...) +void doca_third_party_mc_debug(const char *msg, ...) { - va_list ap; - if(_debug) { - va_start(ap, msg); + va_list ap; + if (_debug) + { + va_start(ap, msg); #if HAVE_VSYSLOG - if(_syslog) { - vsyslog(LOG_DEBUG, msg, ap); - } else + if (_syslog) + { + vsyslog(LOG_DEBUG, msg, ap); + } + else #endif - vprintf(msg, ap); - va_end(ap); - } + vprintf(msg, ap); + va_end(ap); + } } -void mc_error(const char *msg, ...) +void doca_third_party_mc_error(const char *msg, ...) { - va_list ap; - va_start(ap, msg); + va_list ap; + va_start(ap, msg); #if HAVE_VSYSLOG - if(_syslog) { + if (_syslog) + { vsyslog(LOG_ERR, msg, ap); - } else + } + else #endif vfprintf(stderr, msg, ap); - va_end(ap); + va_end(ap); } -void mc_info(const char *msg, ...) +void doca_third_party_mc_info(const char *msg, ...) { - va_list ap; - va_start(ap, msg); + va_list ap; + va_start(ap, msg); #if HAVE_VSYSLOG - if(_syslog) { + if (_syslog) + { vsyslog(LOG_INFO, msg, ap); - } else + } + else #endif vfprintf(stderr, msg, ap); - va_end(ap); + va_end(ap); } diff --git a/third_party/json-c/debug.h b/third_party/json-c/debug.h index 07fcc380b..ab4adc5b5 100644 --- a/third_party/json-c/debug.h +++ b/third_party/json-c/debug.h @@ -14,8 +14,8 @@ * @file * @brief Do not use, json-c internal, may be changed or removed at any time. */ -#ifndef _DEBUG_H_ -#define _DEBUG_H_ +#ifndef _JSON_C_DEBUG_H_ +#define _JSON_C_DEBUG_H_ #include @@ -23,14 +23,22 @@ extern "C" { #endif -extern void mc_set_debug(int debug); -extern int mc_get_debug(void); +#ifndef JSON_EXPORT +#if defined(_MSC_VER) && defined(JSON_C_DLL) +#define JSON_EXPORT __declspec(dllexport) +#else +#define JSON_EXPORT extern +#endif +#endif + +JSON_EXPORT void doca_third_party_mc_set_debug(int debug); +JSON_EXPORT int doca_third_party_mc_get_debug(void); -extern void mc_set_syslog(int syslog); +JSON_EXPORT void doca_third_party_mc_set_syslog(int syslog); -extern void mc_debug(const char *msg, ...); -extern void mc_error(const char *msg, ...); -extern void mc_info(const char *msg, ...); +JSON_EXPORT void doca_third_party_mc_debug(const char *msg, ...); +JSON_EXPORT void doca_third_party_mc_error(const char *msg, ...); +JSON_EXPORT void doca_third_party_mc_info(const char *msg, ...); #ifndef __STRING #define __STRING(x) #x @@ -38,34 +46,49 @@ extern void mc_info(const char *msg, ...); #ifndef PARSER_BROKEN_FIXED -#define JASSERT(cond) do {} while(0) +#define JASSERT(cond) \ + do \ + { \ + } while (0) #else -#define JASSERT(cond) do { \ - if (!(cond)) { \ - mc_error("cjson assert failure %s:%d : cond \"" __STRING(cond) "failed\n", __FILE__, __LINE__); \ - *(int *)0 = 1;\ - abort(); \ - }\ - } while(0) +#define JASSERT(cond) \ + do \ + { \ + if (!(cond)) \ + { \ + mc_error("cjson assert failure %s:%d : cond \"" __STRING(cond) "failed\n", \ + __FILE__, __LINE__); \ + *(int *)0 = 1; \ + abort(); \ + } \ + } while (0) #endif -#define MC_ERROR(x, ...) mc_error(x, ##__VA_ARGS__) +#define MC_ERROR(x, ...) doca_third_party_mc_error(x, ##__VA_ARGS__) #ifdef MC_MAINTAINER_MODE -#define MC_SET_DEBUG(x) mc_set_debug(x) -#define MC_GET_DEBUG() mc_get_debug() -#define MC_SET_SYSLOG(x) mc_set_syslog(x) -#define MC_DEBUG(x, ...) mc_debug(x, ##__VA_ARGS__) -#define MC_INFO(x, ...) mc_info(x, ##__VA_ARGS__) +#define MC_SET_DEBUG(x) doca_third_party_mc_set_debug(x) +#define MC_GET_DEBUG() doca_third_party_mc_get_debug() +#define MC_SET_SYSLOG(x) doca_third_party_mc_set_syslog(x) +#define MC_DEBUG(x, ...) doca_third_party_mc_debug(x, ##__VA_ARGS__) +#define MC_INFO(x, ...) doca_third_party_mc_info(x, ##__VA_ARGS__) #else -#define MC_SET_DEBUG(x) if (0) mc_set_debug(x) +#define MC_SET_DEBUG(x) \ + if (0) \ + doca_third_party_mc_set_debug(x) #define MC_GET_DEBUG() (0) -#define MC_SET_SYSLOG(x) if (0) mc_set_syslog(x) -#define MC_DEBUG(x, ...) if (0) mc_debug(x, ##__VA_ARGS__) -#define MC_INFO(x, ...) if (0) mc_info(x, ##__VA_ARGS__) +#define MC_SET_SYSLOG(x) \ + if (0) \ + doca_third_party_mc_set_syslog(x) +#define MC_DEBUG(x, ...) \ + if (0) \ + doca_third_party_mc_debug(x, ##__VA_ARGS__) +#define MC_INFO(x, ...) \ + if (0) \ + doca_third_party_mc_info(x, ##__VA_ARGS__) #endif #ifdef __cplusplus diff --git a/third_party/json-c/depcomp b/third_party/json-c/depcomp new file mode 100755 index 000000000..715e34311 --- /dev/null +++ b/third_party/json-c/depcomp @@ -0,0 +1,791 @@ +#! /bin/sh +# depcomp - compile a program generating dependencies as side-effects + +scriptversion=2018-03-07.03; # UTC + +# Copyright (C) 1999-2021 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + +# Originally written by Alexandre Oliva . + +case $1 in + '') + echo "$0: No command. Try '$0 --help' for more information." 1>&2 + exit 1; + ;; + -h | --h*) + cat <<\EOF +Usage: depcomp [--help] [--version] PROGRAM [ARGS] + +Run PROGRAMS ARGS to compile a file, generating dependencies +as side-effects. + +Environment variables: + depmode Dependency tracking mode. + source Source file read by 'PROGRAMS ARGS'. + object Object file output by 'PROGRAMS ARGS'. + DEPDIR directory where to store dependencies. + depfile Dependency file to output. + tmpdepfile Temporary file to use when outputting dependencies. + libtool Whether libtool is used (yes/no). + +Report bugs to . +EOF + exit $? + ;; + -v | --v*) + echo "depcomp $scriptversion" + exit $? + ;; +esac + +# Get the directory component of the given path, and save it in the +# global variables '$dir'. Note that this directory component will +# be either empty or ending with a '/' character. This is deliberate. +set_dir_from () +{ + case $1 in + */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; + *) dir=;; + esac +} + +# Get the suffix-stripped basename of the given path, and save it the +# global variable '$base'. +set_base_from () +{ + base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` +} + +# If no dependency file was actually created by the compiler invocation, +# we still have to create a dummy depfile, to avoid errors with the +# Makefile "include basename.Plo" scheme. +make_dummy_depfile () +{ + echo "#dummy" > "$depfile" +} + +# Factor out some common post-processing of the generated depfile. +# Requires the auxiliary global variable '$tmpdepfile' to be set. +aix_post_process_depfile () +{ + # If the compiler actually managed to produce a dependency file, + # post-process it. + if test -f "$tmpdepfile"; then + # Each line is of the form 'foo.o: dependency.h'. + # Do two passes, one to just change these to + # $object: dependency.h + # and one to simply output + # dependency.h: + # which is needed to avoid the deleted-header problem. + { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" + sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" + } > "$depfile" + rm -f "$tmpdepfile" + else + make_dummy_depfile + fi +} + +# A tabulation character. +tab=' ' +# A newline character. +nl=' +' +# Character ranges might be problematic outside the C locale. +# These definitions help. +upper=ABCDEFGHIJKLMNOPQRSTUVWXYZ +lower=abcdefghijklmnopqrstuvwxyz +digits=0123456789 +alpha=${upper}${lower} + +if test -z "$depmode" || test -z "$source" || test -z "$object"; then + echo "depcomp: Variables source, object and depmode must be set" 1>&2 + exit 1 +fi + +# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. +depfile=${depfile-`echo "$object" | + sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} +tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} + +rm -f "$tmpdepfile" + +# Avoid interferences from the environment. +gccflag= dashmflag= + +# Some modes work just like other modes, but use different flags. We +# parameterize here, but still list the modes in the big case below, +# to make depend.m4 easier to write. Note that we *cannot* use a case +# here, because this file can only contain one case statement. +if test "$depmode" = hp; then + # HP compiler uses -M and no extra arg. + gccflag=-M + depmode=gcc +fi + +if test "$depmode" = dashXmstdout; then + # This is just like dashmstdout with a different argument. + dashmflag=-xM + depmode=dashmstdout +fi + +cygpath_u="cygpath -u -f -" +if test "$depmode" = msvcmsys; then + # This is just like msvisualcpp but w/o cygpath translation. + # Just convert the backslash-escaped backslashes to single forward + # slashes to satisfy depend.m4 + cygpath_u='sed s,\\\\,/,g' + depmode=msvisualcpp +fi + +if test "$depmode" = msvc7msys; then + # This is just like msvc7 but w/o cygpath translation. + # Just convert the backslash-escaped backslashes to single forward + # slashes to satisfy depend.m4 + cygpath_u='sed s,\\\\,/,g' + depmode=msvc7 +fi + +if test "$depmode" = xlc; then + # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. + gccflag=-qmakedep=gcc,-MF + depmode=gcc +fi + +case "$depmode" in +gcc3) +## gcc 3 implements dependency tracking that does exactly what +## we want. Yay! Note: for some reason libtool 1.4 doesn't like +## it if -MD -MP comes after the -MF stuff. Hmm. +## Unfortunately, FreeBSD c89 acceptance of flags depends upon +## the command line argument order; so add the flags where they +## appear in depend2.am. Note that the slowdown incurred here +## affects only configure: in makefiles, %FASTDEP% shortcuts this. + for arg + do + case $arg in + -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; + *) set fnord "$@" "$arg" ;; + esac + shift # fnord + shift # $arg + done + "$@" + stat=$? + if test $stat -ne 0; then + rm -f "$tmpdepfile" + exit $stat + fi + mv "$tmpdepfile" "$depfile" + ;; + +gcc) +## Note that this doesn't just cater to obsosete pre-3.x GCC compilers. +## but also to in-use compilers like IMB xlc/xlC and the HP C compiler. +## (see the conditional assignment to $gccflag above). +## There are various ways to get dependency output from gcc. Here's +## why we pick this rather obscure method: +## - Don't want to use -MD because we'd like the dependencies to end +## up in a subdir. Having to rename by hand is ugly. +## (We might end up doing this anyway to support other compilers.) +## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like +## -MM, not -M (despite what the docs say). Also, it might not be +## supported by the other compilers which use the 'gcc' depmode. +## - Using -M directly means running the compiler twice (even worse +## than renaming). + if test -z "$gccflag"; then + gccflag=-MD, + fi + "$@" -Wp,"$gccflag$tmpdepfile" + stat=$? + if test $stat -ne 0; then + rm -f "$tmpdepfile" + exit $stat + fi + rm -f "$depfile" + echo "$object : \\" > "$depfile" + # The second -e expression handles DOS-style file names with drive + # letters. + sed -e 's/^[^:]*: / /' \ + -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" +## This next piece of magic avoids the "deleted header file" problem. +## The problem is that when a header file which appears in a .P file +## is deleted, the dependency causes make to die (because there is +## typically no way to rebuild the header). We avoid this by adding +## dummy dependencies for each header file. Too bad gcc doesn't do +## this for us directly. +## Some versions of gcc put a space before the ':'. On the theory +## that the space means something, we add a space to the output as +## well. hp depmode also adds that space, but also prefixes the VPATH +## to the object. Take care to not repeat it in the output. +## Some versions of the HPUX 10.20 sed can't process this invocation +## correctly. Breaking it into two sed invocations is a workaround. + tr ' ' "$nl" < "$tmpdepfile" \ + | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ + | sed -e 's/$/ :/' >> "$depfile" + rm -f "$tmpdepfile" + ;; + +hp) + # This case exists only to let depend.m4 do its work. It works by + # looking at the text of this script. This case will never be run, + # since it is checked for above. + exit 1 + ;; + +sgi) + if test "$libtool" = yes; then + "$@" "-Wp,-MDupdate,$tmpdepfile" + else + "$@" -MDupdate "$tmpdepfile" + fi + stat=$? + if test $stat -ne 0; then + rm -f "$tmpdepfile" + exit $stat + fi + rm -f "$depfile" + + if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files + echo "$object : \\" > "$depfile" + # Clip off the initial element (the dependent). Don't try to be + # clever and replace this with sed code, as IRIX sed won't handle + # lines with more than a fixed number of characters (4096 in + # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; + # the IRIX cc adds comments like '#:fec' to the end of the + # dependency line. + tr ' ' "$nl" < "$tmpdepfile" \ + | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ + | tr "$nl" ' ' >> "$depfile" + echo >> "$depfile" + # The second pass generates a dummy entry for each header file. + tr ' ' "$nl" < "$tmpdepfile" \ + | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ + >> "$depfile" + else + make_dummy_depfile + fi + rm -f "$tmpdepfile" + ;; + +xlc) + # This case exists only to let depend.m4 do its work. It works by + # looking at the text of this script. This case will never be run, + # since it is checked for above. + exit 1 + ;; + +aix) + # The C for AIX Compiler uses -M and outputs the dependencies + # in a .u file. In older versions, this file always lives in the + # current directory. Also, the AIX compiler puts '$object:' at the + # start of each line; $object doesn't have directory information. + # Version 6 uses the directory in both cases. + set_dir_from "$object" + set_base_from "$object" + if test "$libtool" = yes; then + tmpdepfile1=$dir$base.u + tmpdepfile2=$base.u + tmpdepfile3=$dir.libs/$base.u + "$@" -Wc,-M + else + tmpdepfile1=$dir$base.u + tmpdepfile2=$dir$base.u + tmpdepfile3=$dir$base.u + "$@" -M + fi + stat=$? + if test $stat -ne 0; then + rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" + exit $stat + fi + + for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" + do + test -f "$tmpdepfile" && break + done + aix_post_process_depfile + ;; + +tcc) + # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 + # FIXME: That version still under development at the moment of writing. + # Make that this statement remains true also for stable, released + # versions. + # It will wrap lines (doesn't matter whether long or short) with a + # trailing '\', as in: + # + # foo.o : \ + # foo.c \ + # foo.h \ + # + # It will put a trailing '\' even on the last line, and will use leading + # spaces rather than leading tabs (at least since its commit 0394caf7 + # "Emit spaces for -MD"). + "$@" -MD -MF "$tmpdepfile" + stat=$? + if test $stat -ne 0; then + rm -f "$tmpdepfile" + exit $stat + fi + rm -f "$depfile" + # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. + # We have to change lines of the first kind to '$object: \'. + sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" + # And for each line of the second kind, we have to emit a 'dep.h:' + # dummy dependency, to avoid the deleted-header problem. + sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" + rm -f "$tmpdepfile" + ;; + +## The order of this option in the case statement is important, since the +## shell code in configure will try each of these formats in the order +## listed in this file. A plain '-MD' option would be understood by many +## compilers, so we must ensure this comes after the gcc and icc options. +pgcc) + # Portland's C compiler understands '-MD'. + # Will always output deps to 'file.d' where file is the root name of the + # source file under compilation, even if file resides in a subdirectory. + # The object file name does not affect the name of the '.d' file. + # pgcc 10.2 will output + # foo.o: sub/foo.c sub/foo.h + # and will wrap long lines using '\' : + # foo.o: sub/foo.c ... \ + # sub/foo.h ... \ + # ... + set_dir_from "$object" + # Use the source, not the object, to determine the base name, since + # that's sadly what pgcc will do too. + set_base_from "$source" + tmpdepfile=$base.d + + # For projects that build the same source file twice into different object + # files, the pgcc approach of using the *source* file root name can cause + # problems in parallel builds. Use a locking strategy to avoid stomping on + # the same $tmpdepfile. + lockdir=$base.d-lock + trap " + echo '$0: caught signal, cleaning up...' >&2 + rmdir '$lockdir' + exit 1 + " 1 2 13 15 + numtries=100 + i=$numtries + while test $i -gt 0; do + # mkdir is a portable test-and-set. + if mkdir "$lockdir" 2>/dev/null; then + # This process acquired the lock. + "$@" -MD + stat=$? + # Release the lock. + rmdir "$lockdir" + break + else + # If the lock is being held by a different process, wait + # until the winning process is done or we timeout. + while test -d "$lockdir" && test $i -gt 0; do + sleep 1 + i=`expr $i - 1` + done + fi + i=`expr $i - 1` + done + trap - 1 2 13 15 + if test $i -le 0; then + echo "$0: failed to acquire lock after $numtries attempts" >&2 + echo "$0: check lockdir '$lockdir'" >&2 + exit 1 + fi + + if test $stat -ne 0; then + rm -f "$tmpdepfile" + exit $stat + fi + rm -f "$depfile" + # Each line is of the form `foo.o: dependent.h', + # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. + # Do two passes, one to just change these to + # `$object: dependent.h' and one to simply `dependent.h:'. + sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" + # Some versions of the HPUX 10.20 sed can't process this invocation + # correctly. Breaking it into two sed invocations is a workaround. + sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ + | sed -e 's/$/ :/' >> "$depfile" + rm -f "$tmpdepfile" + ;; + +hp2) + # The "hp" stanza above does not work with aCC (C++) and HP's ia64 + # compilers, which have integrated preprocessors. The correct option + # to use with these is +Maked; it writes dependencies to a file named + # 'foo.d', which lands next to the object file, wherever that + # happens to be. + # Much of this is similar to the tru64 case; see comments there. + set_dir_from "$object" + set_base_from "$object" + if test "$libtool" = yes; then + tmpdepfile1=$dir$base.d + tmpdepfile2=$dir.libs/$base.d + "$@" -Wc,+Maked + else + tmpdepfile1=$dir$base.d + tmpdepfile2=$dir$base.d + "$@" +Maked + fi + stat=$? + if test $stat -ne 0; then + rm -f "$tmpdepfile1" "$tmpdepfile2" + exit $stat + fi + + for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" + do + test -f "$tmpdepfile" && break + done + if test -f "$tmpdepfile"; then + sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" + # Add 'dependent.h:' lines. + sed -ne '2,${ + s/^ *// + s/ \\*$// + s/$/:/ + p + }' "$tmpdepfile" >> "$depfile" + else + make_dummy_depfile + fi + rm -f "$tmpdepfile" "$tmpdepfile2" + ;; + +tru64) + # The Tru64 compiler uses -MD to generate dependencies as a side + # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. + # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put + # dependencies in 'foo.d' instead, so we check for that too. + # Subdirectories are respected. + set_dir_from "$object" + set_base_from "$object" + + if test "$libtool" = yes; then + # Libtool generates 2 separate objects for the 2 libraries. These + # two compilations output dependencies in $dir.libs/$base.o.d and + # in $dir$base.o.d. We have to check for both files, because + # one of the two compilations can be disabled. We should prefer + # $dir$base.o.d over $dir.libs/$base.o.d because the latter is + # automatically cleaned when .libs/ is deleted, while ignoring + # the former would cause a distcleancheck panic. + tmpdepfile1=$dir$base.o.d # libtool 1.5 + tmpdepfile2=$dir.libs/$base.o.d # Likewise. + tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 + "$@" -Wc,-MD + else + tmpdepfile1=$dir$base.d + tmpdepfile2=$dir$base.d + tmpdepfile3=$dir$base.d + "$@" -MD + fi + + stat=$? + if test $stat -ne 0; then + rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" + exit $stat + fi + + for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" + do + test -f "$tmpdepfile" && break + done + # Same post-processing that is required for AIX mode. + aix_post_process_depfile + ;; + +msvc7) + if test "$libtool" = yes; then + showIncludes=-Wc,-showIncludes + else + showIncludes=-showIncludes + fi + "$@" $showIncludes > "$tmpdepfile" + stat=$? + grep -v '^Note: including file: ' "$tmpdepfile" + if test $stat -ne 0; then + rm -f "$tmpdepfile" + exit $stat + fi + rm -f "$depfile" + echo "$object : \\" > "$depfile" + # The first sed program below extracts the file names and escapes + # backslashes for cygpath. The second sed program outputs the file + # name when reading, but also accumulates all include files in the + # hold buffer in order to output them again at the end. This only + # works with sed implementations that can handle large buffers. + sed < "$tmpdepfile" -n ' +/^Note: including file: *\(.*\)/ { + s//\1/ + s/\\/\\\\/g + p +}' | $cygpath_u | sort -u | sed -n ' +s/ /\\ /g +s/\(.*\)/'"$tab"'\1 \\/p +s/.\(.*\) \\/\1:/ +H +$ { + s/.*/'"$tab"'/ + G + p +}' >> "$depfile" + echo >> "$depfile" # make sure the fragment doesn't end with a backslash + rm -f "$tmpdepfile" + ;; + +msvc7msys) + # This case exists only to let depend.m4 do its work. It works by + # looking at the text of this script. This case will never be run, + # since it is checked for above. + exit 1 + ;; + +#nosideeffect) + # This comment above is used by automake to tell side-effect + # dependency tracking mechanisms from slower ones. + +dashmstdout) + # Important note: in order to support this mode, a compiler *must* + # always write the preprocessed file to stdout, regardless of -o. + "$@" || exit $? + + # Remove the call to Libtool. + if test "$libtool" = yes; then + while test "X$1" != 'X--mode=compile'; do + shift + done + shift + fi + + # Remove '-o $object'. + IFS=" " + for arg + do + case $arg in + -o) + shift + ;; + $object) + shift + ;; + *) + set fnord "$@" "$arg" + shift # fnord + shift # $arg + ;; + esac + done + + test -z "$dashmflag" && dashmflag=-M + # Require at least two characters before searching for ':' + # in the target name. This is to cope with DOS-style filenames: + # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. + "$@" $dashmflag | + sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" + rm -f "$depfile" + cat < "$tmpdepfile" > "$depfile" + # Some versions of the HPUX 10.20 sed can't process this sed invocation + # correctly. Breaking it into two sed invocations is a workaround. + tr ' ' "$nl" < "$tmpdepfile" \ + | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ + | sed -e 's/$/ :/' >> "$depfile" + rm -f "$tmpdepfile" + ;; + +dashXmstdout) + # This case only exists to satisfy depend.m4. It is never actually + # run, as this mode is specially recognized in the preamble. + exit 1 + ;; + +makedepend) + "$@" || exit $? + # Remove any Libtool call + if test "$libtool" = yes; then + while test "X$1" != 'X--mode=compile'; do + shift + done + shift + fi + # X makedepend + shift + cleared=no eat=no + for arg + do + case $cleared in + no) + set ""; shift + cleared=yes ;; + esac + if test $eat = yes; then + eat=no + continue + fi + case "$arg" in + -D*|-I*) + set fnord "$@" "$arg"; shift ;; + # Strip any option that makedepend may not understand. Remove + # the object too, otherwise makedepend will parse it as a source file. + -arch) + eat=yes ;; + -*|$object) + ;; + *) + set fnord "$@" "$arg"; shift ;; + esac + done + obj_suffix=`echo "$object" | sed 's/^.*\././'` + touch "$tmpdepfile" + ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" + rm -f "$depfile" + # makedepend may prepend the VPATH from the source file name to the object. + # No need to regex-escape $object, excess matching of '.' is harmless. + sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" + # Some versions of the HPUX 10.20 sed can't process the last invocation + # correctly. Breaking it into two sed invocations is a workaround. + sed '1,2d' "$tmpdepfile" \ + | tr ' ' "$nl" \ + | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ + | sed -e 's/$/ :/' >> "$depfile" + rm -f "$tmpdepfile" "$tmpdepfile".bak + ;; + +cpp) + # Important note: in order to support this mode, a compiler *must* + # always write the preprocessed file to stdout. + "$@" || exit $? + + # Remove the call to Libtool. + if test "$libtool" = yes; then + while test "X$1" != 'X--mode=compile'; do + shift + done + shift + fi + + # Remove '-o $object'. + IFS=" " + for arg + do + case $arg in + -o) + shift + ;; + $object) + shift + ;; + *) + set fnord "$@" "$arg" + shift # fnord + shift # $arg + ;; + esac + done + + "$@" -E \ + | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ + -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ + | sed '$ s: \\$::' > "$tmpdepfile" + rm -f "$depfile" + echo "$object : \\" > "$depfile" + cat < "$tmpdepfile" >> "$depfile" + sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" + rm -f "$tmpdepfile" + ;; + +msvisualcpp) + # Important note: in order to support this mode, a compiler *must* + # always write the preprocessed file to stdout. + "$@" || exit $? + + # Remove the call to Libtool. + if test "$libtool" = yes; then + while test "X$1" != 'X--mode=compile'; do + shift + done + shift + fi + + IFS=" " + for arg + do + case "$arg" in + -o) + shift + ;; + $object) + shift + ;; + "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") + set fnord "$@" + shift + shift + ;; + *) + set fnord "$@" "$arg" + shift + shift + ;; + esac + done + "$@" -E 2>/dev/null | + sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" + rm -f "$depfile" + echo "$object : \\" > "$depfile" + sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" + echo "$tab" >> "$depfile" + sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" + rm -f "$tmpdepfile" + ;; + +msvcmsys) + # This case exists only to let depend.m4 do its work. It works by + # looking at the text of this script. This case will never be run, + # since it is checked for above. + exit 1 + ;; + +none) + exec "$@" + ;; + +*) + echo "Unknown depmode $depmode" 1>&2 + exit 1 + ;; +esac + +exit 0 + +# Local Variables: +# mode: shell-script +# sh-indentation: 2 +# eval: (add-hook 'before-save-hook 'time-stamp) +# time-stamp-start: "scriptversion=" +# time-stamp-format: "%:y-%02m-%02d.%02H" +# time-stamp-time-zone: "UTC0" +# time-stamp-end: "; # UTC" +# End: diff --git a/third_party/json-c/doc/CMakeLists.txt b/third_party/json-c/doc/CMakeLists.txt new file mode 100644 index 000000000..4872d8e8a --- /dev/null +++ b/third_party/json-c/doc/CMakeLists.txt @@ -0,0 +1,16 @@ +# generate doxygen documentation for json-c API + +find_package(Doxygen) + +if (DOXYGEN_FOUND) + + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in + ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile) + message(STATUS "Wrote ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile") + + add_custom_target(doc + COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile) + +else (DOXYGEN_FOUND) + message("Warning: doxygen not found, the 'doc' target will not be included") +endif(DOXYGEN_FOUND) diff --git a/third_party/json-c/Doxyfile b/third_party/json-c/doc/Doxyfile.in similarity index 97% rename from third_party/json-c/Doxyfile rename to third_party/json-c/doc/Doxyfile.in index a7e6ac20e..46fc76ed9 100644 --- a/third_party/json-c/Doxyfile +++ b/third_party/json-c/doc/Doxyfile.in @@ -20,7 +20,7 @@ # This tag specifies the encoding used for all characters in the config file # that follow. The default is UTF-8 which is also the encoding used for all text # before the first occurrence of this tag. Doxygen uses libiconv (or the iconv -# built into libc) for the transcoding. See http://www.gnu.org/software/libiconv +# built into libc) for the transcoding. See https://www.gnu.org/software/libiconv # for the list of possible encodings. # The default value is: UTF-8. @@ -38,7 +38,7 @@ PROJECT_NAME = json-c # could be handy for archiving the generated documentation or if some version # control system is used. -PROJECT_NUMBER = 0.13.1 +PROJECT_NUMBER = @PROJECT_VERSION@ # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer a @@ -58,7 +58,7 @@ PROJECT_LOGO = # entered, it will be relative to the location where doxygen was started. If # left blank the current directory will be used. -OUTPUT_DIRECTORY = doc +OUTPUT_DIRECTORY = @CMAKE_CURRENT_BINARY_DIR@ # If the CREATE_SUBDIRS tag is set to YES, then doxygen will create 4096 sub- # directories (in 2 levels) under the output directory of each output format and @@ -152,7 +152,7 @@ FULL_PATH_NAMES = YES # will be relative from the directory where doxygen is started. # This tag requires that the tag FULL_PATH_NAMES is set to YES. -STRIP_FROM_PATH = +STRIP_FROM_PATH = @CMAKE_SOURCE_DIR@ # The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of the # path mentioned in the documentation of a class, which tells the reader which @@ -285,7 +285,7 @@ EXTENSION_MAPPING = # If the MARKDOWN_SUPPORT tag is enabled then doxygen pre-processes all comments # according to the Markdown format, which allows for more readable -# documentation. See http://daringfireball.net/projects/markdown/ for details. +# documentation. See https://daringfireball.net/projects/markdown/ for details. # The output of markdown processing is further processed by doxygen, so you can # mix doxygen, HTML, and XML commands with Markdown formatting. Disable only in # case of backward compatibilities issues. @@ -318,7 +318,7 @@ BUILTIN_STL_SUPPORT = NO CPP_CLI_SUPPORT = NO # Set the SIP_SUPPORT tag to YES if your project consists of sip (see: -# http://www.riverbankcomputing.co.uk/software/sip/intro) sources only. Doxygen +# https://www.riverbankcomputing.co.uk/software/sip/intro) sources only. Doxygen # will parse them like normal C++ but will assume all classes use public instead # of private inheritance when no explicit protection keyword is present. # The default value is: NO. @@ -427,7 +427,7 @@ EXTRACT_PACKAGE = NO # included in the documentation. # The default value is: NO. -EXTRACT_STATIC = NO +EXTRACT_STATIC = YES # If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) defined # locally in source files will be included in the documentation. If set to NO @@ -677,7 +677,7 @@ LAYOUT_FILE = # The CITE_BIB_FILES tag can be used to specify one or more bib files containing # the reference definitions. This must be a list of .bib files. The .bib # extension is automatically appended if omitted. This requires the bibtex tool -# to be installed. See also http://en.wikipedia.org/wiki/BibTeX for more info. +# to be installed. See also https://en.wikipedia.org/wiki/BibTeX for more info. # For LaTeX the style of the bibliography can be controlled using # LATEX_BIB_STYLE. To use this feature you need bibtex and perl available in the # search path. See also \cite for info how to create references. @@ -753,13 +753,12 @@ WARN_LOGFILE = # spaces. # Note: If this tag is empty the current directory is searched. -INPUT = README.md \ - . +INPUT = @CMAKE_SOURCE_DIR@ @CMAKE_BINARY_DIR@ # This tag can be used to specify the character encoding of the source files # that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses # libiconv (or the iconv built into libc) for the transcoding. See the libiconv -# documentation (see: http://www.gnu.org/software/libiconv) for the list of +# documentation (see: https://www.gnu.org/software/libiconv) for the list of # possible encodings. # The default value is: UTF-8. @@ -806,7 +805,13 @@ EXCLUDE_SYMLINKS = NO # Note that the wildcards are matched against the file with absolute path, so to # exclude all test directories for example use the pattern */test/* -EXCLUDE_PATTERNS = +EXCLUDE_PATTERNS = \ + */json_object_private.h \ + */debug.h \ + */*config.h \ + */random_seed.h \ + */strerror_*h \ + */*compat.h # The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names # (namespaces, classes, functions, etc.) that should be excluded from the @@ -817,7 +822,11 @@ EXCLUDE_PATTERNS = # Note that the wildcards are matched against the file with absolute path, so to # exclude all test directories use the pattern */test/* -EXCLUDE_SYMBOLS = +EXCLUDE_SYMBOLS = \ + _json_c_* \ + _LH_* \ + _printbuf_* \ + __STRING # The EXAMPLE_PATH tag can be used to specify one or more files or directories # that contain example code fragments that are included (see the \include @@ -860,7 +869,7 @@ IMAGE_PATH = # code is scanned, but not when the output code is generated. If lines are added # or removed, the anchors will not be placed correctly. -INPUT_FILTER = +INPUT_FILTER = @CMAKE_CURRENT_SOURCE_DIR@/fixup_markdown.sh # The FILTER_PATTERNS tag can be used to specify filters on a per file pattern # basis. Doxygen will compare the file name with each pattern and apply the @@ -891,7 +900,7 @@ FILTER_SOURCE_PATTERNS = # (index.html). This can be useful if you have a project on for instance GitHub # and want to reuse the introduction page also for the doxygen output. -USE_MDFILE_AS_MAINPAGE = +USE_MDFILE_AS_MAINPAGE = README.md #--------------------------------------------------------------------------- # Configuration options related to source browsing @@ -952,7 +961,7 @@ SOURCE_TOOLTIPS = YES # If the USE_HTAGS tag is set to YES then the references to source code will # point to the HTML generated by the htags(1) tool instead of doxygen built-in # source browser. The htags tool is part of GNU's global source tagging system -# (see http://www.gnu.org/software/global/global.html). You will need version +# (see https://www.gnu.org/software/global/global.html). You will need version # 4.8.6 or higher. # # To use it do the following: @@ -980,7 +989,7 @@ USE_HTAGS = NO VERBATIM_HEADERS = NO # If the CLANG_ASSISTED_PARSING tag is set to YES, then doxygen will use the -# clang parser (see: http://clang.llvm.org/) for more accurate parsing at the +# clang parser (see: https://clang.llvm.org/) for more accurate parsing at the # cost of reduced performance. This can be particularly helpful with template # rich C++ code for which doxygen's built-in parser lacks the necessary type # information. @@ -1094,7 +1103,7 @@ HTML_STYLESHEET = # cascading style sheets that are included after the standard style sheets # created by doxygen. Using this option one can overrule certain style aspects. # This is preferred over using HTML_STYLESHEET since it does not replace the -# standard style sheet and is therefor more robust against future updates. +# standard style sheet and is therefore more robust against future updates. # Doxygen will copy the style sheet files to the output directory. # Note: The order of the extra stylesheet files is of importance (e.g. the last # stylesheet in the list overrules the setting of the previous ones in the @@ -1116,7 +1125,7 @@ HTML_EXTRA_FILES = # The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. Doxygen # will adjust the colors in the stylesheet and background images according to # this color. Hue is specified as an angle on a colorwheel, see -# http://en.wikipedia.org/wiki/Hue for more information. For instance the value +# https://en.wikipedia.org/wiki/Hue for more information. For instance the value # 0 represents red, 60 is yellow, 120 is green, 180 is cyan, 240 is blue, 300 # purple, and 360 is red again. # Minimum value: 0, maximum value: 359, default value: 220. @@ -1174,12 +1183,13 @@ HTML_INDEX_NUM_ENTRIES = 100 # If the GENERATE_DOCSET tag is set to YES, additional index files will be # generated that can be used as input for Apple's Xcode 3 integrated development -# environment (see: http://developer.apple.com/tools/xcode/), introduced with +# environment (see: https://developer.apple.com/tools/xcode/), introduced with # OSX 10.5 (Leopard). To create a documentation set, doxygen will generate a # Makefile in the HTML output directory. Running make will produce the docset in # that directory and running make install will install the docset in # ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find it at -# startup. See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html +# startup. See +# https://developer.apple.com/library/archive/featuredarticles/DoxygenXcode/ # for more information. # The default value is: NO. # This tag requires that the tag GENERATE_HTML is set to YES. @@ -1295,7 +1305,7 @@ QCH_FILE = # The QHP_NAMESPACE tag specifies the namespace to use when generating Qt Help # Project output. For more information please see Qt Help Project / Namespace -# (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#namespace). +# (see: https://doc.qt.io/archives/qt-4.8/qthelpproject.html#namespace). # The default value is: org.doxygen.Project. # This tag requires that the tag GENERATE_QHP is set to YES. @@ -1303,8 +1313,8 @@ QHP_NAMESPACE = org.doxygen.Project # The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating Qt # Help Project output. For more information please see Qt Help Project / Virtual -# Folders (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#virtual- -# folders). +# Folders (see: +# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#virtual-folders). # The default value is: doc. # This tag requires that the tag GENERATE_QHP is set to YES. @@ -1312,23 +1322,23 @@ QHP_VIRTUAL_FOLDER = doc # If the QHP_CUST_FILTER_NAME tag is set, it specifies the name of a custom # filter to add. For more information please see Qt Help Project / Custom -# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom- -# filters). +# Filters (see: +# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#custom-filters). # This tag requires that the tag GENERATE_QHP is set to YES. QHP_CUST_FILTER_NAME = # The QHP_CUST_FILTER_ATTRS tag specifies the list of the attributes of the # custom filter to add. For more information please see Qt Help Project / Custom -# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom- -# filters). +# Filters (see: +# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#custom-filters). # This tag requires that the tag GENERATE_QHP is set to YES. QHP_CUST_FILTER_ATTRS = # The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this # project's filter section matches. Qt Help Project / Filter Attributes (see: -# http://qt-project.org/doc/qt-4.8/qthelpproject.html#filter-attributes). +# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#filter-attributes). # This tag requires that the tag GENERATE_QHP is set to YES. QHP_SECT_FILTER_ATTRS = @@ -1433,7 +1443,7 @@ FORMULA_FONTSIZE = 10 FORMULA_TRANSPARENT = YES # Enable the USE_MATHJAX option to render LaTeX formulas using MathJax (see -# http://www.mathjax.org) which uses client side Javascript for the rendering +# https://www.mathjax.org) which uses client side Javascript for the rendering # instead of using prerendered bitmaps. Use this if you do not have LaTeX # installed or if you want to formulas look prettier in the HTML output. When # enabled you may also need to install MathJax separately and configure the path @@ -1445,7 +1455,7 @@ USE_MATHJAX = NO # When MathJax is enabled you can set the default output format to be used for # the MathJax output. See the MathJax site (see: -# http://docs.mathjax.org/en/latest/output.html) for more details. +# https://docs.mathjax.org/en/latest/output/) for more details. # Possible values are: HTML-CSS (which is slower, but has the best # compatibility), NativeMML (i.e. MathML) and SVG. # The default value is: HTML-CSS. @@ -1460,11 +1470,11 @@ MATHJAX_FORMAT = HTML-CSS # MATHJAX_RELPATH should be ../mathjax. The default value points to the MathJax # Content Delivery Network so you can quickly see the result without installing # MathJax. However, it is strongly recommended to install a local copy of -# MathJax from http://www.mathjax.org before deployment. -# The default value is: http://cdn.mathjax.org/mathjax/latest. +# MathJax from https://www.mathjax.org before deployment. +# The default value is: https://cdn.mathjax.org/mathjax/latest. # This tag requires that the tag USE_MATHJAX is set to YES. -MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest +MATHJAX_RELPATH = https://cdn.mathjax.org/mathjax/latest # The MATHJAX_EXTENSIONS tag can be used to specify one or more MathJax # extension names that should be enabled during MathJax rendering. For example @@ -1475,7 +1485,7 @@ MATHJAX_EXTENSIONS = # The MATHJAX_CODEFILE tag can be used to specify a file with javascript pieces # of code that will be used on startup of the MathJax code. See the MathJax site -# (see: http://docs.mathjax.org/en/latest/output.html) for more details. For an +# (see: https://docs.mathjax.org/en/latest/output/) for more details. For an # example see the documentation. # This tag requires that the tag USE_MATHJAX is set to YES. @@ -1522,7 +1532,7 @@ SERVER_BASED_SEARCH = NO # # Doxygen ships with an example indexer ( doxyindexer) and search engine # (doxysearch.cgi) which are based on the open source search engine library -# Xapian (see: http://xapian.org/). +# Xapian (see: https://xapian.org/). # # See the section "External Indexing and Searching" for details. # The default value is: NO. @@ -1535,7 +1545,7 @@ EXTERNAL_SEARCH = NO # # Doxygen ships with an example indexer ( doxyindexer) and search engine # (doxysearch.cgi) which are based on the open source search engine library -# Xapian (see: http://xapian.org/). See the section "External Indexing and +# Xapian (see: https://xapian.org/). See the section "External Indexing and # Searching" for details. # This tag requires that the tag SEARCHENGINE is set to YES. @@ -1637,8 +1647,8 @@ EXTRA_PACKAGES = # Note: Only use a user-defined header if you know what you are doing! The # following commands have a special meaning inside the header: $title, # $datetime, $date, $doxygenversion, $projectname, $projectnumber, -# $projectbrief, $projectlogo. Doxygen will replace $title with the empy string, -# for the replacement values of the other commands the user is refered to +# $projectbrief, $projectlogo. Doxygen will replace $title with the empty string, +# for the replacement values of the other commands the user is referred to # HTML_HEADER. # This tag requires that the tag GENERATE_LATEX is set to YES. @@ -1708,7 +1718,7 @@ LATEX_SOURCE_CODE = NO # The LATEX_BIB_STYLE tag can be used to specify the style to use for the # bibliography, e.g. plainnat, or ieeetr. See -# http://en.wikipedia.org/wiki/BibTeX and \cite for more info. +# https://en.wikipedia.org/wiki/BibTeX and \cite for more info. # The default value is: plain. # This tag requires that the tag GENERATE_LATEX is set to YES. @@ -1975,7 +1985,9 @@ INCLUDE_FILE_PATTERNS = # recursively expanded use the := operator instead of the = operator. # This tag requires that the tag ENABLE_PREPROCESSING is set to YES. -PREDEFINED = THIS_FUNCTION_IS_DEPRECATED(f)=f +PREDEFINED = \ + _LH_INLINE=inline \ + JSON_C_CONST_FUNCTION(func)=func # If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this # tag can be used to specify a list of macro names that should be expanded. The @@ -2062,7 +2074,7 @@ CLASS_DIAGRAMS = YES # You can define message sequence charts within doxygen comments using the \msc # command. Doxygen will then run the mscgen tool (see: -# http://www.mcternan.me.uk/mscgen/)) to produce the chart and insert it in the +# https://www.mcternan.me.uk/mscgen/) to produce the chart and insert it in the # documentation. The MSCGEN_PATH tag allows you to specify the directory where # the mscgen tool resides. If left empty the tool is assumed to be found in the # default search path. @@ -2084,7 +2096,7 @@ HIDE_UNDOC_RELATIONS = YES # If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is # available from the path. This tool is part of Graphviz (see: -# http://www.graphviz.org/), a graph visualization toolkit from AT&T and Lucent +# https://www.graphviz.org/), a graph visualization toolkit from AT&T and Lucent # Bell Labs. The other options in this section have no effect if this option is # set to NO # The default value is: YES. diff --git a/third_party/json-c/doc/fixup_markdown.sh b/third_party/json-c/doc/fixup_markdown.sh new file mode 100755 index 000000000..452eb78ac --- /dev/null +++ b/third_party/json-c/doc/fixup_markdown.sh @@ -0,0 +1,6 @@ +#!/bin/sh +# +# Doxygen markdown doesn't support triple-backticks like github does. +# Convert all of those to space-prefixed blocks instead. +# +awk '/```/ { prefix=!prefix; print ""; next; } { if (prefix) { printf " "; } print $0; } ' "$@" diff --git a/third_party/json-c/fuzz/build.sh b/third_party/json-c/fuzz/build.sh index 30c3f779e..7a42e0b7e 100755 --- a/third_party/json-c/fuzz/build.sh +++ b/third_party/json-c/fuzz/build.sh @@ -5,7 +5,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, @@ -15,16 +15,38 @@ # ################################################################################ -./autogen.sh -./configure --enable-static --disable-shared -make -j$(nproc) all -ar rc json_c.a *.o +# This should be run from the top of the json-c source tree. -cp $SRC/*.dict $OUT/ +mkdir build +cd build +cmake -DBUILD_SHARED_LIBS=OFF .. +make -j$(nproc) +LIB=$(pwd)/libjson-c.a +cd .. + +# These seem to be set externally, but let's assign defaults to +# make it possible to at least partially test this standalone. +: ${SRC:=$(dirname "$0")} +: ${OUT:=$SRC/out} +: ${CXX:=gcc} +: ${CXXFLAGS:=} + +[ -d "$OUT" ] || mkdir "$OUT" +cp $SRC/*.dict $OUT/. + +# XXX this doesn't seem to make much sense, since $SRC is presumably +# the "fuzz" directory, which is _inside_ the json-c repo, rather than +# the other way around, but I'm just preserving existing behavior. -erh +INCS=$SRC/json-c +# Compat when testing standalone +[ -e "${INCS}" ] || ln -s .. "${INCS}" + +set -x +set -v for f in $SRC/*_fuzzer.cc; do fuzzer=$(basename "$f" _fuzzer.cc) - $CXX $CXXFLAGS -std=c++11 -I$SRC/json-c \ + $CXX $CXXFLAGS -std=c++11 -I$INCS \ $SRC/${fuzzer}_fuzzer.cc -o $OUT/${fuzzer}_fuzzer \ - -lFuzzingEngine $SRC/json-c/json_c.a + -lFuzzingEngine $LIB done diff --git a/third_party/json-c/fuzz/tokener_parse_ex_fuzzer.cc b/third_party/json-c/fuzz/tokener_parse_ex_fuzzer.cc index c0a1c3d84..5060473a5 100644 --- a/third_party/json-c/fuzz/tokener_parse_ex_fuzzer.cc +++ b/third_party/json-c/fuzz/tokener_parse_ex_fuzzer.cc @@ -1,13 +1,39 @@ +/* + * Original work: + * + * json-c (copyright was originally missing from this file) + * + * Modified Work: + * + * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. + * + * This software product is a proprietary product of NVIDIA CORPORATION & + * AFFILIATES (the "Company") and all right, title, and interest in and to the + * software product, including all associated intellectual property rights, are + * and shall remain exclusively with the Company. + * + * This software product is governed by the End User License Agreement + * provided with the software product. + * + */ + #include #include -extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - const char *data1 = reinterpret_cast(data); - json_tokener *tok = json_tokener_new(); - json_object *obj = json_tokener_parse_ex(tok, data1, size); +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + const char *data1 = reinterpret_cast(data); + json_tokener *tok = doca_third_party_json_tokener_new(); + json_object *obj = doca_third_party_json_tokener_parse_ex(tok, data1, size); + + doca_third_party_json_object_object_foreach(jobj, key, val) { + (void)doca_third_party_json_object_get_type(val); + (void)doca_third_party_json_object_get_string(val); + } + (void)doca_third_party_json_object_to_json_string(obj, JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_SPACED); - json_object_put(obj); - json_tokener_free(tok); - return 0; + doca_third_party_json_object_put(obj); + doca_third_party_json_tokener_free(tok); + return 0; } diff --git a/third_party/json-c/install-sh b/third_party/json-c/install-sh new file mode 100755 index 000000000..ec298b537 --- /dev/null +++ b/third_party/json-c/install-sh @@ -0,0 +1,541 @@ +#!/bin/sh +# install - install a program, script, or datafile + +scriptversion=2020-11-14.01; # UTC + +# This originates from X11R5 (mit/util/scripts/install.sh), which was +# later released in X11R6 (xc/config/util/install.sh) with the +# following copyright and license. +# +# Copyright (C) 1994 X Consortium +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- +# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# +# Except as contained in this notice, the name of the X Consortium shall not +# be used in advertising or otherwise to promote the sale, use or other deal- +# ings in this Software without prior written authorization from the X Consor- +# tium. +# +# +# FSF changes to this file are in the public domain. +# +# Calling this script install-sh is preferred over install.sh, to prevent +# 'make' implicit rules from creating a file called install from it +# when there is no Makefile. +# +# This script is compatible with the BSD install script, but was written +# from scratch. + +tab=' ' +nl=' +' +IFS=" $tab$nl" + +# Set DOITPROG to "echo" to test this script. + +doit=${DOITPROG-} +doit_exec=${doit:-exec} + +# Put in absolute file names if you don't have them in your path; +# or use environment vars. + +chgrpprog=${CHGRPPROG-chgrp} +chmodprog=${CHMODPROG-chmod} +chownprog=${CHOWNPROG-chown} +cmpprog=${CMPPROG-cmp} +cpprog=${CPPROG-cp} +mkdirprog=${MKDIRPROG-mkdir} +mvprog=${MVPROG-mv} +rmprog=${RMPROG-rm} +stripprog=${STRIPPROG-strip} + +posix_mkdir= + +# Desired mode of installed file. +mode=0755 + +# Create dirs (including intermediate dirs) using mode 755. +# This is like GNU 'install' as of coreutils 8.32 (2020). +mkdir_umask=22 + +backupsuffix= +chgrpcmd= +chmodcmd=$chmodprog +chowncmd= +mvcmd=$mvprog +rmcmd="$rmprog -f" +stripcmd= + +src= +dst= +dir_arg= +dst_arg= + +copy_on_change=false +is_target_a_directory=possibly + +usage="\ +Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE + or: $0 [OPTION]... SRCFILES... DIRECTORY + or: $0 [OPTION]... -t DIRECTORY SRCFILES... + or: $0 [OPTION]... -d DIRECTORIES... + +In the 1st form, copy SRCFILE to DSTFILE. +In the 2nd and 3rd, copy all SRCFILES to DIRECTORY. +In the 4th, create DIRECTORIES. + +Options: + --help display this help and exit. + --version display version info and exit. + + -c (ignored) + -C install only if different (preserve data modification time) + -d create directories instead of installing files. + -g GROUP $chgrpprog installed files to GROUP. + -m MODE $chmodprog installed files to MODE. + -o USER $chownprog installed files to USER. + -p pass -p to $cpprog. + -s $stripprog installed files. + -S SUFFIX attempt to back up existing files, with suffix SUFFIX. + -t DIRECTORY install into DIRECTORY. + -T report an error if DSTFILE is a directory. + +Environment variables override the default commands: + CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG + RMPROG STRIPPROG + +By default, rm is invoked with -f; when overridden with RMPROG, +it's up to you to specify -f if you want it. + +If -S is not specified, no backups are attempted. + +Email bug reports to bug-automake@gnu.org. +Automake home page: https://www.gnu.org/software/automake/ +" + +while test $# -ne 0; do + case $1 in + -c) ;; + + -C) copy_on_change=true;; + + -d) dir_arg=true;; + + -g) chgrpcmd="$chgrpprog $2" + shift;; + + --help) echo "$usage"; exit $?;; + + -m) mode=$2 + case $mode in + *' '* | *"$tab"* | *"$nl"* | *'*'* | *'?'* | *'['*) + echo "$0: invalid mode: $mode" >&2 + exit 1;; + esac + shift;; + + -o) chowncmd="$chownprog $2" + shift;; + + -p) cpprog="$cpprog -p";; + + -s) stripcmd=$stripprog;; + + -S) backupsuffix="$2" + shift;; + + -t) + is_target_a_directory=always + dst_arg=$2 + # Protect names problematic for 'test' and other utilities. + case $dst_arg in + -* | [=\(\)!]) dst_arg=./$dst_arg;; + esac + shift;; + + -T) is_target_a_directory=never;; + + --version) echo "$0 $scriptversion"; exit $?;; + + --) shift + break;; + + -*) echo "$0: invalid option: $1" >&2 + exit 1;; + + *) break;; + esac + shift +done + +# We allow the use of options -d and -T together, by making -d +# take the precedence; this is for compatibility with GNU install. + +if test -n "$dir_arg"; then + if test -n "$dst_arg"; then + echo "$0: target directory not allowed when installing a directory." >&2 + exit 1 + fi +fi + +if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then + # When -d is used, all remaining arguments are directories to create. + # When -t is used, the destination is already specified. + # Otherwise, the last argument is the destination. Remove it from $@. + for arg + do + if test -n "$dst_arg"; then + # $@ is not empty: it contains at least $arg. + set fnord "$@" "$dst_arg" + shift # fnord + fi + shift # arg + dst_arg=$arg + # Protect names problematic for 'test' and other utilities. + case $dst_arg in + -* | [=\(\)!]) dst_arg=./$dst_arg;; + esac + done +fi + +if test $# -eq 0; then + if test -z "$dir_arg"; then + echo "$0: no input file specified." >&2 + exit 1 + fi + # It's OK to call 'install-sh -d' without argument. + # This can happen when creating conditional directories. + exit 0 +fi + +if test -z "$dir_arg"; then + if test $# -gt 1 || test "$is_target_a_directory" = always; then + if test ! -d "$dst_arg"; then + echo "$0: $dst_arg: Is not a directory." >&2 + exit 1 + fi + fi +fi + +if test -z "$dir_arg"; then + do_exit='(exit $ret); exit $ret' + trap "ret=129; $do_exit" 1 + trap "ret=130; $do_exit" 2 + trap "ret=141; $do_exit" 13 + trap "ret=143; $do_exit" 15 + + # Set umask so as not to create temps with too-generous modes. + # However, 'strip' requires both read and write access to temps. + case $mode in + # Optimize common cases. + *644) cp_umask=133;; + *755) cp_umask=22;; + + *[0-7]) + if test -z "$stripcmd"; then + u_plus_rw= + else + u_plus_rw='% 200' + fi + cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; + *) + if test -z "$stripcmd"; then + u_plus_rw= + else + u_plus_rw=,u+rw + fi + cp_umask=$mode$u_plus_rw;; + esac +fi + +for src +do + # Protect names problematic for 'test' and other utilities. + case $src in + -* | [=\(\)!]) src=./$src;; + esac + + if test -n "$dir_arg"; then + dst=$src + dstdir=$dst + test -d "$dstdir" + dstdir_status=$? + # Don't chown directories that already exist. + if test $dstdir_status = 0; then + chowncmd="" + fi + else + + # Waiting for this to be detected by the "$cpprog $src $dsttmp" command + # might cause directories to be created, which would be especially bad + # if $src (and thus $dsttmp) contains '*'. + if test ! -f "$src" && test ! -d "$src"; then + echo "$0: $src does not exist." >&2 + exit 1 + fi + + if test -z "$dst_arg"; then + echo "$0: no destination specified." >&2 + exit 1 + fi + dst=$dst_arg + + # If destination is a directory, append the input filename. + if test -d "$dst"; then + if test "$is_target_a_directory" = never; then + echo "$0: $dst_arg: Is a directory" >&2 + exit 1 + fi + dstdir=$dst + dstbase=`basename "$src"` + case $dst in + */) dst=$dst$dstbase;; + *) dst=$dst/$dstbase;; + esac + dstdir_status=0 + else + dstdir=`dirname "$dst"` + test -d "$dstdir" + dstdir_status=$? + fi + fi + + case $dstdir in + */) dstdirslash=$dstdir;; + *) dstdirslash=$dstdir/;; + esac + + obsolete_mkdir_used=false + + if test $dstdir_status != 0; then + case $posix_mkdir in + '') + # With -d, create the new directory with the user-specified mode. + # Otherwise, rely on $mkdir_umask. + if test -n "$dir_arg"; then + mkdir_mode=-m$mode + else + mkdir_mode= + fi + + posix_mkdir=false + # The $RANDOM variable is not portable (e.g., dash). Use it + # here however when possible just to lower collision chance. + tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ + + trap ' + ret=$? + rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" 2>/dev/null + exit $ret + ' 0 + + # Because "mkdir -p" follows existing symlinks and we likely work + # directly in world-writeable /tmp, make sure that the '$tmpdir' + # directory is successfully created first before we actually test + # 'mkdir -p'. + if (umask $mkdir_umask && + $mkdirprog $mkdir_mode "$tmpdir" && + exec $mkdirprog $mkdir_mode -p -- "$tmpdir/a/b") >/dev/null 2>&1 + then + if test -z "$dir_arg" || { + # Check for POSIX incompatibilities with -m. + # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or + # other-writable bit of parent directory when it shouldn't. + # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. + test_tmpdir="$tmpdir/a" + ls_ld_tmpdir=`ls -ld "$test_tmpdir"` + case $ls_ld_tmpdir in + d????-?r-*) different_mode=700;; + d????-?--*) different_mode=755;; + *) false;; + esac && + $mkdirprog -m$different_mode -p -- "$test_tmpdir" && { + ls_ld_tmpdir_1=`ls -ld "$test_tmpdir"` + test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" + } + } + then posix_mkdir=: + fi + rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" + else + # Remove any dirs left behind by ancient mkdir implementations. + rmdir ./$mkdir_mode ./-p ./-- "$tmpdir" 2>/dev/null + fi + trap '' 0;; + esac + + if + $posix_mkdir && ( + umask $mkdir_umask && + $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" + ) + then : + else + + # mkdir does not conform to POSIX, + # or it failed possibly due to a race condition. Create the + # directory the slow way, step by step, checking for races as we go. + + case $dstdir in + /*) prefix='/';; + [-=\(\)!]*) prefix='./';; + *) prefix='';; + esac + + oIFS=$IFS + IFS=/ + set -f + set fnord $dstdir + shift + set +f + IFS=$oIFS + + prefixes= + + for d + do + test X"$d" = X && continue + + prefix=$prefix$d + if test -d "$prefix"; then + prefixes= + else + if $posix_mkdir; then + (umask $mkdir_umask && + $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break + # Don't fail if two instances are running concurrently. + test -d "$prefix" || exit 1 + else + case $prefix in + *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; + *) qprefix=$prefix;; + esac + prefixes="$prefixes '$qprefix'" + fi + fi + prefix=$prefix/ + done + + if test -n "$prefixes"; then + # Don't fail if two instances are running concurrently. + (umask $mkdir_umask && + eval "\$doit_exec \$mkdirprog $prefixes") || + test -d "$dstdir" || exit 1 + obsolete_mkdir_used=true + fi + fi + fi + + if test -n "$dir_arg"; then + { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && + { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && + { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || + test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 + else + + # Make a couple of temp file names in the proper directory. + dsttmp=${dstdirslash}_inst.$$_ + rmtmp=${dstdirslash}_rm.$$_ + + # Trap to clean up those temp files at exit. + trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 + + # Copy the file name to the temp name. + (umask $cp_umask && + { test -z "$stripcmd" || { + # Create $dsttmp read-write so that cp doesn't create it read-only, + # which would cause strip to fail. + if test -z "$doit"; then + : >"$dsttmp" # No need to fork-exec 'touch'. + else + $doit touch "$dsttmp" + fi + } + } && + $doit_exec $cpprog "$src" "$dsttmp") && + + # and set any options; do chmod last to preserve setuid bits. + # + # If any of these fail, we abort the whole thing. If we want to + # ignore errors from any of these, just make sure not to ignore + # errors from the above "$doit $cpprog $src $dsttmp" command. + # + { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && + { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && + { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && + { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && + + # If -C, don't bother to copy if it wouldn't change the file. + if $copy_on_change && + old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && + new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && + set -f && + set X $old && old=:$2:$4:$5:$6 && + set X $new && new=:$2:$4:$5:$6 && + set +f && + test "$old" = "$new" && + $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 + then + rm -f "$dsttmp" + else + # If $backupsuffix is set, and the file being installed + # already exists, attempt a backup. Don't worry if it fails, + # e.g., if mv doesn't support -f. + if test -n "$backupsuffix" && test -f "$dst"; then + $doit $mvcmd -f "$dst" "$dst$backupsuffix" 2>/dev/null + fi + + # Rename the file to the real destination. + $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || + + # The rename failed, perhaps because mv can't rename something else + # to itself, or perhaps because mv is so ancient that it does not + # support -f. + { + # Now remove or move aside any old file at destination location. + # We try this two ways since rm can't unlink itself on some + # systems and the destination file might be busy for other + # reasons. In this case, the final cleanup might fail but the new + # file should still install successfully. + { + test ! -f "$dst" || + $doit $rmcmd "$dst" 2>/dev/null || + { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && + { $doit $rmcmd "$rmtmp" 2>/dev/null; :; } + } || + { echo "$0: cannot unlink or rename $dst" >&2 + (exit 1); exit 1 + } + } && + + # Now rename the file to the real destination. + $doit $mvcmd "$dsttmp" "$dst" + } + fi || exit 1 + + trap '' 0 + fi +done + +# Local variables: +# eval: (add-hook 'before-save-hook 'time-stamp) +# time-stamp-start: "scriptversion=" +# time-stamp-format: "%:y-%02m-%02d.%02H" +# time-stamp-time-zone: "UTC0" +# time-stamp-end: "; # UTC" +# End: diff --git a/third_party/json-c/issues_closed_for_0.13.md b/third_party/json-c/issues_closed_for_0.13.md index a29e43705..f3e932c33 100644 --- a/third_party/json-c/issues_closed_for_0.13.md +++ b/third_party/json-c/issues_closed_for_0.13.md @@ -1,267 +1,270 @@ This list was created with: +``` curl https://api.github.com/search/issues?q="repo%3Ajson-c%2Fjson-c+closed%3A>2014-04-10+created%3A<2017-12-01&sort=created&order=asc&per_page=400&page=1" > issues1.out curl https://api.github.com/search/issues?q="repo%3Ajson-c%2Fjson-c+closed%3A>2014-04-10+created%3A<2017-12-01&sort=created&order=asc&per_page=400&page=2" > issues2.out curl https://api.github.com/search/issues?q="repo%3Ajson-c%2Fjson-c+closed%3A>2014-04-10+created%3A<2017-12-01&sort=created&order=asc&per_page=400&page=3" > issues3.out jq -r '.items[] | "[" + .title + "](" + .url + ")" | tostring' issues?.out > issues.md +sed -e's,^\[ *\(.*\)\](https://api.github.com/.*/\([0-9].*\)),[Issue #\2](https://github.com/json-c/json-c/issues/\2) - \1,' -i issues.md #... manual editing ... +``` ---- Issues and Pull Requests closed for the 0.13 release (since commit f84d9c, the 0.12 branch point, 2014-04-10) -[Make json_object_object_add() indicate success or failure, test fix](https://api.github.com/repos/json-c/json-c/issues/61) -[Build fixes (make dist and make distcheck)](https://api.github.com/repos/json-c/json-c/issues/113) -[Fixing build](https://api.github.com/repos/json-c/json-c/issues/124) -[Fix compile error(variable size set but not used) on g++4.6](https://api.github.com/repos/json-c/json-c/issues/125) -[Removed unused size variable.](https://api.github.com/repos/json-c/json-c/issues/126) -[remove unused `size` variable](https://api.github.com/repos/json-c/json-c/issues/127) -[Remove unused variable from json_tokenizer.c](https://api.github.com/repos/json-c/json-c/issues/128) -[Failed to compile under Ubuntu 13.10 32bit](https://api.github.com/repos/json-c/json-c/issues/130) -[undefined symbol: __sync_val_compare_and_swap_4 ](https://api.github.com/repos/json-c/json-c/issues/131) -[Remove unused variable 'size'](https://api.github.com/repos/json-c/json-c/issues/132) -[Update and rename README to README.md](https://api.github.com/repos/json-c/json-c/issues/133) -[Must remove variable size...](https://api.github.com/repos/json-c/json-c/issues/134) -[bits.h uses removed json_tokener_errors\[error\]](https://api.github.com/repos/json-c/json-c/issues/135) -[Error when running make check](https://api.github.com/repos/json-c/json-c/issues/136) -[config.h.in should not be in git](https://api.github.com/repos/json-c/json-c/issues/137) -[Can't build on RHEL 6.5 due to dependency on automake-1.14](https://api.github.com/repos/json-c/json-c/issues/138) -[Code bug in random_test.c evaluating same expression twice ](https://api.github.com/repos/json-c/json-c/issues/140) -[Removed duplicate check in random_seed test - bug #140](https://api.github.com/repos/json-c/json-c/issues/141) -[Please undeprecate json_object_object_get](https://api.github.com/repos/json-c/json-c/issues/142) -[Introduce json_object_from_fd](https://api.github.com/repos/json-c/json-c/issues/144) -[Handle % character properly](https://api.github.com/repos/json-c/json-c/issues/145) -[TAGS rename](https://api.github.com/repos/json-c/json-c/issues/146) -[Bump the soname](https://api.github.com/repos/json-c/json-c/issues/148) -[SONAME bump](https://api.github.com/repos/json-c/json-c/issues/149) -[Fix build using MinGW.](https://api.github.com/repos/json-c/json-c/issues/150) -[Remove json_type enum trailing comma](https://api.github.com/repos/json-c/json-c/issues/151) -[error while compiling json-c library version 0.11](https://api.github.com/repos/json-c/json-c/issues/152) -[improve doc for json_object_to_json_string()](https://api.github.com/repos/json-c/json-c/issues/153) -[double precision](https://api.github.com/repos/json-c/json-c/issues/154) -[add bsearch for arrays](https://api.github.com/repos/json-c/json-c/issues/155) -[Remove trailing whitespaces](https://api.github.com/repos/json-c/json-c/issues/156) -[JSON-C shall not exit on calloc fail.](https://api.github.com/repos/json-c/json-c/issues/157) -[while using json-c 0.11, I am facing strange crash issue in json_object_put.](https://api.github.com/repos/json-c/json-c/issues/158) -[json_tokener.c compile error](https://api.github.com/repos/json-c/json-c/issues/159) -[missing header file on windows??](https://api.github.com/repos/json-c/json-c/issues/160) -[Is there a way to append to file?](https://api.github.com/repos/json-c/json-c/issues/161) -[json_util: add directory check for POSIX distros](https://api.github.com/repos/json-c/json-c/issues/162) -[Fix Win32 build problems](https://api.github.com/repos/json-c/json-c/issues/163) -[made it compile and link on Widnows (as static library)](https://api.github.com/repos/json-c/json-c/issues/164) -[json_object_to_json_string_ext length](https://api.github.com/repos/json-c/json-c/issues/165) -[Can't build on Windows with Visual Studio 2010](https://api.github.com/repos/json-c/json-c/issues/167) -[Tightening the number parsing algorithm](https://api.github.com/repos/json-c/json-c/issues/168) -[Doesn't compile on ubuntu 14.04, 64bit](https://api.github.com/repos/json-c/json-c/issues/169) -[Generated files in repository](https://api.github.com/repos/json-c/json-c/issues/170) -[Update configuration for VS2010 and win64](https://api.github.com/repos/json-c/json-c/issues/171) -[Adding support for parsing octal numbers](https://api.github.com/repos/json-c/json-c/issues/172) -[json_parse_int64 doesn't work correctly at illumos](https://api.github.com/repos/json-c/json-c/issues/173) -[Adding JSON_C_TO_STRING_PRETTY_TAB flag](https://api.github.com/repos/json-c/json-c/issues/174) -[make check fails 4 tests with overflows when built with ASAN](https://api.github.com/repos/json-c/json-c/issues/175) -[Possible to delete an array element at a given idx ?](https://api.github.com/repos/json-c/json-c/issues/176) -[Fix compiler warnings](https://api.github.com/repos/json-c/json-c/issues/177) -[Unable to compile on CentOS5](https://api.github.com/repos/json-c/json-c/issues/178) -[Added array_list_del_idx and json_object_array_del_idx](https://api.github.com/repos/json-c/json-c/issues/179) -[Enable silent build by default](https://api.github.com/repos/json-c/json-c/issues/180) -[json_tokener_parse_ex accepts invalid JSON](https://api.github.com/repos/json-c/json-c/issues/181) -[Link against libm when needed](https://api.github.com/repos/json-c/json-c/issues/182) -[Apply compile warning fix to master branch](https://api.github.com/repos/json-c/json-c/issues/183) -[Use only GCC-specific flags when compiling with GCC](https://api.github.com/repos/json-c/json-c/issues/184) -[compile error](https://api.github.com/repos/json-c/json-c/issues/185) -[Syntax error](https://api.github.com/repos/json-c/json-c/issues/186) -[array_list_get_idx and negative indexes.](https://api.github.com/repos/json-c/json-c/issues/187) -[json_object_object_foreach warnings](https://api.github.com/repos/json-c/json-c/issues/188) -[noisy json_object_from_file: error opening file](https://api.github.com/repos/json-c/json-c/issues/189) -[warning: initialization discards const qualifier from pointer target type \[enabled by default\]](https://api.github.com/repos/json-c/json-c/issues/190) -[json_tokener_parse accepts invalid JSON {"key": "value" , }](https://api.github.com/repos/json-c/json-c/issues/192) -[Make serialization format of doubles configurable](https://api.github.com/repos/json-c/json-c/issues/193) -[Add utility function for comparing json_objects](https://api.github.com/repos/json-c/json-c/issues/194) -[Call uselocale instead of setlocale](https://api.github.com/repos/json-c/json-c/issues/195) -[Performance improvements](https://api.github.com/repos/json-c/json-c/issues/196) -[Time for a new release?](https://api.github.com/repos/json-c/json-c/issues/197) -[Fix possible memory leak and remove superfluous NULL checks before free()](https://api.github.com/repos/json-c/json-c/issues/198) -[Fix build in Visual Studio](https://api.github.com/repos/json-c/json-c/issues/199) -[Add build scripts for CI platforms](https://api.github.com/repos/json-c/json-c/issues/200) -[disable forward-slash escaping?](https://api.github.com/repos/json-c/json-c/issues/201) -[Array with objects support](https://api.github.com/repos/json-c/json-c/issues/202) -[Add source position/coordinates to API](https://api.github.com/repos/json-c/json-c/issues/203) -[json-c/json.h not found ](https://api.github.com/repos/json-c/json-c/issues/204) -[json-c Compiled with Visual Studios](https://api.github.com/repos/json-c/json-c/issues/205) -[what do i use in place of json_object_object_get?](https://api.github.com/repos/json-c/json-c/issues/206) -[Add support for property pairs directly added to arrays](https://api.github.com/repos/json-c/json-c/issues/207) -[Performance enhancements (mainly) to json_object_to_json_string()](https://api.github.com/repos/json-c/json-c/issues/208) -[fix regression from 2d549662be832da838aa063da2efa78ee3b99668](https://api.github.com/repos/json-c/json-c/issues/209) -[Use size_t for arrays](https://api.github.com/repos/json-c/json-c/issues/210) -[Atomic updates for the refcount](https://api.github.com/repos/json-c/json-c/issues/211) -[Refcount doesn't work between threads](https://api.github.com/repos/json-c/json-c/issues/212) -[fix to compile with microsoft visual c++ 2010](https://api.github.com/repos/json-c/json-c/issues/213) -[Some non-GNU systems support __sync_val_compare_and_swap](https://api.github.com/repos/json-c/json-c/issues/214) -[Build json-c for window 64 bit.](https://api.github.com/repos/json-c/json-c/issues/215) -[configure: check realloc with AC_CHECK_FUNCS() to fix cross-compilation.](https://api.github.com/repos/json-c/json-c/issues/216) -[Checking for functions in float.h](https://api.github.com/repos/json-c/json-c/issues/217) -[Use a macro to indicate C99 to the compiler](https://api.github.com/repos/json-c/json-c/issues/218) -[Fix various potential null ptr deref and int32 overflows](https://api.github.com/repos/json-c/json-c/issues/219) -[Add utility function for comparing json_objects](https://api.github.com/repos/json-c/json-c/issues/220) -[JSON_C_TO_STRING_NOSLASHESCAPE works incorrectly](https://api.github.com/repos/json-c/json-c/issues/221) -[Fix issue #221: JSON_C_TO_STRING_NOSLASHESCAPE works incorrectly](https://api.github.com/repos/json-c/json-c/issues/222) -[Clarify json_object_get_string documentation of NULL handling & return](https://api.github.com/repos/json-c/json-c/issues/223) -[json_tokener.c - all warnings being treated as errors](https://api.github.com/repos/json-c/json-c/issues/224) -[Hi, will you support clib as a "registry"?](https://api.github.com/repos/json-c/json-c/issues/225) -[Bump SOVERSION to 3](https://api.github.com/repos/json-c/json-c/issues/227) -[avoid double slashes from json](https://api.github.com/repos/json-c/json-c/issues/228) -[configure fails: checking size of size_t... configure: error: cannot determine a size for size_t](https://api.github.com/repos/json-c/json-c/issues/229) -[Use stdint.h to check for size_t size](https://api.github.com/repos/json-c/json-c/issues/230) -[Fix size_t size check for first-time builds](https://api.github.com/repos/json-c/json-c/issues/231) -[tests/tests1: fix printf format for size_t arguments](https://api.github.com/repos/json-c/json-c/issues/232) -[Include stddef.h in json_object.h](https://api.github.com/repos/json-c/json-c/issues/233) -[Add public API to use userdata independently of custom serializer](https://api.github.com/repos/json-c/json-c/issues/234) -[Undefined symbols Error for architecture x86_64 on Mac ](https://api.github.com/repos/json-c/json-c/issues/235) -[Building a project which uses json-c with flag -Wcast-qual causes compilation errors](https://api.github.com/repos/json-c/json-c/issues/236) -[handle escaped utf-8](https://api.github.com/repos/json-c/json-c/issues/237) -[linkhash.c: optimised the table_free path](https://api.github.com/repos/json-c/json-c/issues/238) -[initialize null terminator of new printbuf](https://api.github.com/repos/json-c/json-c/issues/239) -[Compile error: Variable set but not used](https://api.github.com/repos/json-c/json-c/issues/240) -[getting error in date string 19\/07\/2016, fixed for error 19/07/2016](https://api.github.com/repos/json-c/json-c/issues/241) -[json_tokener_parse error](https://api.github.com/repos/json-c/json-c/issues/242) -[Fix #165](https://api.github.com/repos/json-c/json-c/issues/243) -[Error while compiling source from RHEL5, could you please help me to fix this ](https://api.github.com/repos/json-c/json-c/issues/244) -[json-c compile in window xp](https://api.github.com/repos/json-c/json-c/issues/245) -[Mac: uselocale failed to build](https://api.github.com/repos/json-c/json-c/issues/246) -[json_object_array_del_idx function has segment fault error?](https://api.github.com/repos/json-c/json-c/issues/247) -[Minor changes in C source code](https://api.github.com/repos/json-c/json-c/issues/248) -[Improving README](https://api.github.com/repos/json-c/json-c/issues/249) -[Improving .gitignore](https://api.github.com/repos/json-c/json-c/issues/250) -[Adding a file for EditorConfig](https://api.github.com/repos/json-c/json-c/issues/251) -[Very minor changes not related to C source code](https://api.github.com/repos/json-c/json-c/issues/252) -[Adding a test with cppcheck for Travis CI](https://api.github.com/repos/json-c/json-c/issues/253) -[Very minor changes to some tests](https://api.github.com/repos/json-c/json-c/issues/254) -[Minor changes in C source code](https://api.github.com/repos/json-c/json-c/issues/255) -[Mailing list dead?](https://api.github.com/repos/json-c/json-c/issues/256) -[Defining a coding style](https://api.github.com/repos/json-c/json-c/issues/257) -[Enable CI services](https://api.github.com/repos/json-c/json-c/issues/258) -[Fails to parse valid json](https://api.github.com/repos/json-c/json-c/issues/259) -[Adding an object to itself](https://api.github.com/repos/json-c/json-c/issues/260) -[Lack of proper documentation](https://api.github.com/repos/json-c/json-c/issues/261) -[Add Cmakefile and fix compiler warning.](https://api.github.com/repos/json-c/json-c/issues/262) -[Compiler Warnings with VS2015](https://api.github.com/repos/json-c/json-c/issues/263) -[successed in simple test while failed in my project](https://api.github.com/repos/json-c/json-c/issues/264) -[Conformance report for reference](https://api.github.com/repos/json-c/json-c/issues/265) -[crash perhaps related to reference counting](https://api.github.com/repos/json-c/json-c/issues/266) -[Removes me as Win32 maintainer, because I'm not.](https://api.github.com/repos/json-c/json-c/issues/267) -[Documentation of json_object_to_json_string gives no information about memory management](https://api.github.com/repos/json-c/json-c/issues/268) -[json_object__set(json_object *o, value) API for value setting in json object private structure](https://api.github.com/repos/json-c/json-c/issues/269) -[new API json_object_new_double_f(doubel d,const char * fmt);](https://api.github.com/repos/json-c/json-c/issues/270) -[Cannot compile using CMake on macOS](https://api.github.com/repos/json-c/json-c/issues/271) -[fixed wrong object name in json_object_all_values_equal](https://api.github.com/repos/json-c/json-c/issues/273) -[Support for 64 bit pointers on Windows](https://api.github.com/repos/json-c/json-c/issues/274) -[Out-of-bounds read in json_tokener_parse_ex](https://api.github.com/repos/json-c/json-c/issues/275) -[ ./configure for centos release 6.7(final) failure](https://api.github.com/repos/json-c/json-c/issues/276) -[Json object set xxx](https://api.github.com/repos/json-c/json-c/issues/277) -[Serialization of double with no fractional component drops trailing zero](https://api.github.com/repos/json-c/json-c/issues/278) -[Segmentation fault in array_list_length()](https://api.github.com/repos/json-c/json-c/issues/279) -[Should json_object_array_get_idx check whether input obj is array? ](https://api.github.com/repos/json-c/json-c/issues/280) -[how to pretty print json-c? ](https://api.github.com/repos/json-c/json-c/issues/281) -[ignore temporary files](https://api.github.com/repos/json-c/json-c/issues/282) -[json_pointer: add first revision based on RFC 6901](https://api.github.com/repos/json-c/json-c/issues/283) -[Resusing json_tokener object](https://api.github.com/repos/json-c/json-c/issues/284) -[Revert "compat/strdup.h: move common compat check for strdup() to own](https://api.github.com/repos/json-c/json-c/issues/285) -[json_tokener_parse_ex() returns json_tokener_continue on zero-length string](https://api.github.com/repos/json-c/json-c/issues/286) -[json_pointer: extend setter & getter with printf() style arguments](https://api.github.com/repos/json-c/json-c/issues/287) -[Fix _GNU_SOURCE define for vasprintf](https://api.github.com/repos/json-c/json-c/issues/288) -[bugfix: floating point representaion without fractional part ](https://api.github.com/repos/json-c/json-c/issues/289) -[duplicate an json_object](https://api.github.com/repos/json-c/json-c/issues/290) -[isspace assert error](https://api.github.com/repos/json-c/json-c/issues/291) -[configure error "./configure: line 13121: syntax error near unexpected token `-Wall'"](https://api.github.com/repos/json-c/json-c/issues/292) -[how to make with bitcode for ios](https://api.github.com/repos/json-c/json-c/issues/293) -[Adding UTF-8 validation. Fixes #122](https://api.github.com/repos/json-c/json-c/issues/294) -[cross compile w/ mingw](https://api.github.com/repos/json-c/json-c/issues/295) -[Missing functions header in json_object.h](https://api.github.com/repos/json-c/json-c/issues/296) -[could not parse string to Json object? Like string str=\"helloworld;E\\test\\log\\;end\"](https://api.github.com/repos/json-c/json-c/issues/297) -[Building using CMake doesn't work](https://api.github.com/repos/json-c/json-c/issues/298) -[Improve json_object -> string performance](https://api.github.com/repos/json-c/json-c/issues/299) -[Running tests with MinGW build](https://api.github.com/repos/json-c/json-c/issues/300) -[How to deep copy json_object in C++ ?](https://api.github.com/repos/json-c/json-c/issues/301) -[json_tokener_parse_ex doesn't parse JSON values](https://api.github.com/repos/json-c/json-c/issues/302) -[fix doc in tokener header file](https://api.github.com/repos/json-c/json-c/issues/303) -[(.text+0x72846): undefined reference to `is_error'](https://api.github.com/repos/json-c/json-c/issues/304) -[Fix compilation without C-99 option](https://api.github.com/repos/json-c/json-c/issues/305) -[./configure: line 12748 -error=deprecated-declarations](https://api.github.com/repos/json-c/json-c/issues/306) -[Memory leak in json_tokener_parse](https://api.github.com/repos/json-c/json-c/issues/307) -[AM_PROG_LIBTOOL not found on Linux](https://api.github.com/repos/json-c/json-c/issues/308) -[GCC 7 reports various -Wimplicit-fallthrough= errors](https://api.github.com/repos/json-c/json-c/issues/309) -[Add FALLTHRU comment to handle GCC7 warnings.](https://api.github.com/repos/json-c/json-c/issues/310) -[Fix error C3688 when compiling on Visual Studio 2015](https://api.github.com/repos/json-c/json-c/issues/311) -[Fix CMake Build process improved for MinGW and MSYS2](https://api.github.com/repos/json-c/json-c/issues/312) -[VERBOSE=1 make check; tests/test_util_file.test.c and tests/test_util_file.expected out of sync](https://api.github.com/repos/json-c/json-c/issues/313) -[Passing -1 to json_tokener_parse_ex is possibly unsafe](https://api.github.com/repos/json-c/json-c/issues/315) -[Memory Returned by json_object_to_json_string not freed](https://api.github.com/repos/json-c/json-c/issues/316) -[json_object_get_string gives segmentation error](https://api.github.com/repos/json-c/json-c/issues/317) -[PVS-Studio static analyzer analyze results](https://api.github.com/repos/json-c/json-c/issues/318) -[Windows: Fix dynamic library build with Visual Studio](https://api.github.com/repos/json-c/json-c/issues/319) -[Can't compile in Mac OS X El Capitan](https://api.github.com/repos/json-c/json-c/issues/320) -[build,cmake: fix vasprintf implicit definition and generate both static & shared libs](https://api.github.com/repos/json-c/json-c/issues/321) -[can not link with libjson-c.a](https://api.github.com/repos/json-c/json-c/issues/322) -[implicit fallthrough detected by gcc 7.1](https://api.github.com/repos/json-c/json-c/issues/323) -[JsonPath like function?](https://api.github.com/repos/json-c/json-c/issues/324) -[Fix stack buffer overflow in json_object_double_to_json_string_format()](https://api.github.com/repos/json-c/json-c/issues/325) -[why json-c so hard to compile](https://api.github.com/repos/json-c/json-c/issues/327) -[json_object: implement json_object_deep_copy() function](https://api.github.com/repos/json-c/json-c/issues/328) -[build,cmake: build,cmake: rename libjson-c-static.a to libjson-c.a](https://api.github.com/repos/json-c/json-c/issues/329) -[tests: symlink basic tests to a single file that has the common code](https://api.github.com/repos/json-c/json-c/issues/330) -[Safe use of snprintf() / vsnprintf() for Visual studio, and thread-safety fix](https://api.github.com/repos/json-c/json-c/issues/331) -[Valgrind: invalid read after json_object_array_del_idx.](https://api.github.com/repos/json-c/json-c/issues/332) -[Replace obsolete AM_PROG_LIBTOOL](https://api.github.com/repos/json-c/json-c/issues/333) -[README.md: show build status tag from travis-ci.org](https://api.github.com/repos/json-c/json-c/issues/335) -[tests: fix tests in travis-ci.org](https://api.github.com/repos/json-c/json-c/issues/336) -[Synchronize "potentially racy" random seed in lh_char_hash()](https://api.github.com/repos/json-c/json-c/issues/337) -[implement json_object_int_inc(json_object *, int64_t)](https://api.github.com/repos/json-c/json-c/issues/338) -[Json schema validation](https://api.github.com/repos/json-c/json-c/issues/339) -[strerror_override: add extern "C" and JSON_EXPORT specifiers for Visual C++ compilers](https://api.github.com/repos/json-c/json-c/issues/340) -[character "/" parse as "\/"](https://api.github.com/repos/json-c/json-c/issues/341) -[ No such file or directory "/usr/include/json.h"](https://api.github.com/repos/json-c/json-c/issues/342) -[Can't parse json](https://api.github.com/repos/json-c/json-c/issues/343) -[Fix Mingw build](https://api.github.com/repos/json-c/json-c/issues/344) -[Fix make dist and make distcheck](https://api.github.com/repos/json-c/json-c/issues/345) -[Clamp double to int32 when narrowing in json_object_get_int.](https://api.github.com/repos/json-c/json-c/issues/346) -[MSVC linker error json_c_strerror](https://api.github.com/repos/json-c/json-c/issues/347) -[why](https://api.github.com/repos/json-c/json-c/issues/348) -[`missing` is missing?](https://api.github.com/repos/json-c/json-c/issues/349) -[stderror-override and disable-shared](https://api.github.com/repos/json-c/json-c/issues/350) -[SIZE_T_MAX redefined from limits.h](https://api.github.com/repos/json-c/json-c/issues/351) -[`INSTALL` overrides an automake script.](https://api.github.com/repos/json-c/json-c/issues/352) -[Documentation issues](https://api.github.com/repos/json-c/json-c/issues/353) -[Fixes #351 #352 #353 ](https://api.github.com/repos/json-c/json-c/issues/354) -[1.make it can been compiled with Visual Studio 2010 by modify the CMakeList.txt and others](https://api.github.com/repos/json-c/json-c/issues/355) -[VS2008 test test_util_file.cpp err!](https://api.github.com/repos/json-c/json-c/issues/356) -[__json_c_strerror incompatibility with link-time optimization](https://api.github.com/repos/json-c/json-c/issues/357) -[make issue](https://api.github.com/repos/json-c/json-c/issues/358) -[update CMakeLists.txt for compile with visual studio at least 2010](https://api.github.com/repos/json-c/json-c/issues/359) -[Use strtoll() to parse ints](https://api.github.com/repos/json-c/json-c/issues/360) -[Fix double to int cast overflow in json_object_get_int64.](https://api.github.com/repos/json-c/json-c/issues/361) -[CMake Package Config](https://api.github.com/repos/json-c/json-c/issues/362) -[Issue #338, add json_object_add_int functions](https://api.github.com/repos/json-c/json-c/issues/363) -[Cmake is Errir](https://api.github.com/repos/json-c/json-c/issues/364) -[added fallthrough for gcc7](https://api.github.com/repos/json-c/json-c/issues/365) -[how to check the json string,crash!](https://api.github.com/repos/json-c/json-c/issues/366) -[Is json-c support "redirect" semantic?](https://api.github.com/repos/json-c/json-c/issues/367) -[Add examples](https://api.github.com/repos/json-c/json-c/issues/368) -[How to build json-c library for android?](https://api.github.com/repos/json-c/json-c/issues/369) -[Compiling using clang-cl](https://api.github.com/repos/json-c/json-c/issues/370) -[Invalid parsing for Infinity with json-c 0.12](https://api.github.com/repos/json-c/json-c/issues/371) -[Json-c 0.12: Fixed Infinity bug](https://api.github.com/repos/json-c/json-c/issues/372) -[build: fix build on appveyor CI](https://api.github.com/repos/json-c/json-c/issues/373) -[Undefined symbols for architecture x86_64:](https://api.github.com/repos/json-c/json-c/issues/374) -[what would happened when json_object_object_add add the same key](https://api.github.com/repos/json-c/json-c/issues/375) -[Eclipse error ](https://api.github.com/repos/json-c/json-c/issues/376) -[on gcc 7.2.0 on my linux distribution with json-c 2013-04-02 source](https://api.github.com/repos/json-c/json-c/issues/377) -[ Eclipse: library (libjson-c) not found, but configured](https://api.github.com/repos/json-c/json-c/issues/378) -[error: this statement may fall through \[-Werror=implicit-fallthrough=\]](https://api.github.com/repos/json-c/json-c/issues/379) -[Build on Windows](https://api.github.com/repos/json-c/json-c/issues/380) -[Fix makedist](https://api.github.com/repos/json-c/json-c/issues/381) -[Memory leak for json_tokener_parse_ex for version 0.12.1](https://api.github.com/repos/json-c/json-c/issues/382) -[Fix a compiler warning.](https://api.github.com/repos/json-c/json-c/issues/383) -[Fix a VS 2015 compiler warnings.](https://api.github.com/repos/json-c/json-c/issues/384) +* [Issue #61](https://github.com/json-c/json-c/issues/61) - Make json_object_object_add() indicate success or failure, test fix \ +* [Issue #113](https://github.com/json-c/json-c/issues/113) - Build fixes (make dist and make distcheck) \ +* [Issue #124](https://github.com/json-c/json-c/issues/124) - Fixing build \ +* [Issue #125](https://github.com/json-c/json-c/issues/125) - Fix compile error(variable size set but not used) on g++4.6 \ +* [Issue #126](https://github.com/json-c/json-c/issues/126) - Removed unused size variable. \ +* [Issue #127](https://github.com/json-c/json-c/issues/127) - remove unused `size` variable \ +* [Issue #128](https://github.com/json-c/json-c/issues/128) - Remove unused variable from json_tokenizer.c \ +* [Issue #130](https://github.com/json-c/json-c/issues/130) - Failed to compile under Ubuntu 13.10 32bit \ +* [Issue #131](https://github.com/json-c/json-c/issues/131) - undefined symbol: __sync_val_compare_and_swap_4 \ +* [Issue #132](https://github.com/json-c/json-c/issues/132) - Remove unused variable 'size' \ +* [Issue #133](https://github.com/json-c/json-c/issues/133) - Update and rename README to README.md \ +* [Issue #134](https://github.com/json-c/json-c/issues/134) - Must remove variable size... \ +* [Issue #135](https://github.com/json-c/json-c/issues/135) - bits.h uses removed json_tokener_errors\[error\] \ +* [Issue #136](https://github.com/json-c/json-c/issues/136) - Error when running make check \ +* [Issue #137](https://github.com/json-c/json-c/issues/137) - config.h.in should not be in git \ +* [Issue #138](https://github.com/json-c/json-c/issues/138) - Can't build on RHEL 6.5 due to dependency on automake-1.14 \ +* [Issue #140](https://github.com/json-c/json-c/issues/140) - Code bug in random_test.c evaluating same expression twice \ +* [Issue #141](https://github.com/json-c/json-c/issues/141) - Removed duplicate check in random_seed test - bug #140 \ +* [Issue #142](https://github.com/json-c/json-c/issues/142) - Please undeprecate json_object_object_get \ +* [Issue #144](https://github.com/json-c/json-c/issues/144) - Introduce json_object_from_fd \ +* [Issue #145](https://github.com/json-c/json-c/issues/145) - Handle % character properly \ +* [Issue #146](https://github.com/json-c/json-c/issues/146) - TAGS rename \ +* [Issue #148](https://github.com/json-c/json-c/issues/148) - Bump the soname \ +* [Issue #149](https://github.com/json-c/json-c/issues/149) - SONAME bump \ +* [Issue #150](https://github.com/json-c/json-c/issues/150) - Fix build using MinGW. \ +* [Issue #151](https://github.com/json-c/json-c/issues/151) - Remove json_type enum trailing comma \ +* [Issue #152](https://github.com/json-c/json-c/issues/152) - error while compiling json-c library version 0.11 \ +* [Issue #153](https://github.com/json-c/json-c/issues/153) - improve doc for json_object_to_json_string() \ +* [Issue #154](https://github.com/json-c/json-c/issues/154) - double precision \ +* [Issue #155](https://github.com/json-c/json-c/issues/155) - add bsearch for arrays \ +* [Issue #156](https://github.com/json-c/json-c/issues/156) - Remove trailing whitespaces \ +* [Issue #157](https://github.com/json-c/json-c/issues/157) - JSON-C shall not exit on calloc fail. \ +* [Issue #158](https://github.com/json-c/json-c/issues/158) - while using json-c 0.11, I am facing strange crash issue in json_object_put. \ +* [Issue #159](https://github.com/json-c/json-c/issues/159) - json_tokener.c compile error \ +* [Issue #160](https://github.com/json-c/json-c/issues/160) - missing header file on windows?? \ +* [Issue #161](https://github.com/json-c/json-c/issues/161) - Is there a way to append to file? \ +* [Issue #162](https://github.com/json-c/json-c/issues/162) - json_util: add directory check for POSIX distros \ +* [Issue #163](https://github.com/json-c/json-c/issues/163) - Fix Win32 build problems \ +* [Issue #164](https://github.com/json-c/json-c/issues/164) - made it compile and link on Widnows (as static library) \ +* [Issue #165](https://github.com/json-c/json-c/issues/165) - json_object_to_json_string_ext length \ +* [Issue #167](https://github.com/json-c/json-c/issues/167) - Can't build on Windows with Visual Studio 2010 \ +* [Issue #168](https://github.com/json-c/json-c/issues/168) - Tightening the number parsing algorithm \ +* [Issue #169](https://github.com/json-c/json-c/issues/169) - Doesn't compile on ubuntu 14.04, 64bit \ +* [Issue #170](https://github.com/json-c/json-c/issues/170) - Generated files in repository \ +* [Issue #171](https://github.com/json-c/json-c/issues/171) - Update configuration for VS2010 and win64 \ +* [Issue #172](https://github.com/json-c/json-c/issues/172) - Adding support for parsing octal numbers \ +* [Issue #173](https://github.com/json-c/json-c/issues/173) - json_parse_int64 doesn't work correctly at illumos \ +* [Issue #174](https://github.com/json-c/json-c/issues/174) - Adding JSON_C_TO_STRING_PRETTY_TAB flag \ +* [Issue #175](https://github.com/json-c/json-c/issues/175) - make check fails 4 tests with overflows when built with ASAN \ +* [Issue #176](https://github.com/json-c/json-c/issues/176) - Possible to delete an array element at a given idx ? \ +* [Issue #177](https://github.com/json-c/json-c/issues/177) - Fix compiler warnings \ +* [Issue #178](https://github.com/json-c/json-c/issues/178) - Unable to compile on CentOS5 \ +* [Issue #179](https://github.com/json-c/json-c/issues/179) - Added array_list_del_idx and json_object_array_del_idx \ +* [Issue #180](https://github.com/json-c/json-c/issues/180) - Enable silent build by default \ +* [Issue #181](https://github.com/json-c/json-c/issues/181) - json_tokener_parse_ex accepts invalid JSON \ +* [Issue #182](https://github.com/json-c/json-c/issues/182) - Link against libm when needed \ +* [Issue #183](https://github.com/json-c/json-c/issues/183) - Apply compile warning fix to master branch \ +* [Issue #184](https://github.com/json-c/json-c/issues/184) - Use only GCC-specific flags when compiling with GCC \ +* [Issue #185](https://github.com/json-c/json-c/issues/185) - compile error \ +* [Issue #186](https://github.com/json-c/json-c/issues/186) - Syntax error \ +* [Issue #187](https://github.com/json-c/json-c/issues/187) - array_list_get_idx and negative indexes. \ +* [Issue #188](https://github.com/json-c/json-c/issues/188) - json_object_object_foreach warnings \ +* [Issue #189](https://github.com/json-c/json-c/issues/189) - noisy json_object_from_file: error opening file \ +* [Issue #190](https://github.com/json-c/json-c/issues/190) - warning: initialization discards const qualifier from pointer target type \[enabled by default\] \ +* [Issue #192](https://github.com/json-c/json-c/issues/192) - json_tokener_parse accepts invalid JSON {"key": "value" , } \ +* [Issue #193](https://github.com/json-c/json-c/issues/193) - Make serialization format of doubles configurable \ +* [Issue #194](https://github.com/json-c/json-c/issues/194) - Add utility function for comparing json_objects \ +* [Issue #195](https://github.com/json-c/json-c/issues/195) - Call uselocale instead of setlocale \ +* [Issue #196](https://github.com/json-c/json-c/issues/196) - Performance improvements \ +* [Issue #197](https://github.com/json-c/json-c/issues/197) - Time for a new release? \ +* [Issue #198](https://github.com/json-c/json-c/issues/198) - Fix possible memory leak and remove superfluous NULL checks before free() \ +* [Issue #199](https://github.com/json-c/json-c/issues/199) - Fix build in Visual Studio \ +* [Issue #200](https://github.com/json-c/json-c/issues/200) - Add build scripts for CI platforms \ +* [Issue #201](https://github.com/json-c/json-c/issues/201) - disable forward-slash escaping? \ +* [Issue #202](https://github.com/json-c/json-c/issues/202) - Array with objects support \ +* [Issue #203](https://github.com/json-c/json-c/issues/203) - Add source position/coordinates to API \ +* [Issue #204](https://github.com/json-c/json-c/issues/204) - json-c/json.h not found \ +* [Issue #205](https://github.com/json-c/json-c/issues/205) - json-c Compiled with Visual Studios \ +* [Issue #206](https://github.com/json-c/json-c/issues/206) - what do i use in place of json_object_object_get? \ +* [Issue #207](https://github.com/json-c/json-c/issues/207) - Add support for property pairs directly added to arrays \ +* [Issue #208](https://github.com/json-c/json-c/issues/208) - Performance enhancements (mainly) to json_object_to_json_string() \ +* [Issue #209](https://github.com/json-c/json-c/issues/209) - fix regression from 2d549662be832da838aa063da2efa78ee3b99668 \ +* [Issue #210](https://github.com/json-c/json-c/issues/210) - Use size_t for arrays \ +* [Issue #211](https://github.com/json-c/json-c/issues/211) - Atomic updates for the refcount \ +* [Issue #212](https://github.com/json-c/json-c/issues/212) - Refcount doesn't work between threads \ +* [Issue #213](https://github.com/json-c/json-c/issues/213) - fix to compile with microsoft visual c++ 2010 \ +* [Issue #214](https://github.com/json-c/json-c/issues/214) - Some non-GNU systems support __sync_val_compare_and_swap \ +* [Issue #215](https://github.com/json-c/json-c/issues/215) - Build json-c for window 64 bit. \ +* [Issue #216](https://github.com/json-c/json-c/issues/216) - configure: check realloc with AC_CHECK_FUNCS() to fix cross-compilation. \ +* [Issue #217](https://github.com/json-c/json-c/issues/217) - Checking for functions in float.h \ +* [Issue #218](https://github.com/json-c/json-c/issues/218) - Use a macro to indicate C99 to the compiler \ +* [Issue #219](https://github.com/json-c/json-c/issues/219) - Fix various potential null ptr deref and int32 overflows \ +* [Issue #220](https://github.com/json-c/json-c/issues/220) - Add utility function for comparing json_objects \ +* [Issue #221](https://github.com/json-c/json-c/issues/221) - JSON_C_TO_STRING_NOSLASHESCAPE works incorrectly \ +* [Issue #222](https://github.com/json-c/json-c/issues/222) - Fix issue #221: JSON_C_TO_STRING_NOSLASHESCAPE works incorrectly \ +* [Issue #223](https://github.com/json-c/json-c/issues/223) - Clarify json_object_get_string documentation of NULL handling & return \ +* [Issue #224](https://github.com/json-c/json-c/issues/224) - json_tokener.c - all warnings being treated as errors \ +* [Issue #225](https://github.com/json-c/json-c/issues/225) - Hi, will you support clib as a "registry"? \ +* [Issue #227](https://github.com/json-c/json-c/issues/227) - Bump SOVERSION to 3 \ +* [Issue #228](https://github.com/json-c/json-c/issues/228) - avoid double slashes from json \ +* [Issue #229](https://github.com/json-c/json-c/issues/229) - configure fails: checking size of size_t... configure: error: cannot determine a size for size_t \ +* [Issue #230](https://github.com/json-c/json-c/issues/230) - Use stdint.h to check for size_t size \ +* [Issue #231](https://github.com/json-c/json-c/issues/231) - Fix size_t size check for first-time builds \ +* [Issue #232](https://github.com/json-c/json-c/issues/232) - tests/tests1: fix printf format for size_t arguments \ +* [Issue #233](https://github.com/json-c/json-c/issues/233) - Include stddef.h in json_object.h \ +* [Issue #234](https://github.com/json-c/json-c/issues/234) - Add public API to use userdata independently of custom serializer \ +* [Issue #235](https://github.com/json-c/json-c/issues/235) - Undefined symbols Error for architecture x86_64 on Mac \ +* [Issue #236](https://github.com/json-c/json-c/issues/236) - Building a project which uses json-c with flag -Wcast-qual causes compilation errors \ +* [Issue #237](https://github.com/json-c/json-c/issues/237) - handle escaped utf-8 \ +* [Issue #238](https://github.com/json-c/json-c/issues/238) - linkhash.c: optimised the table_free path \ +* [Issue #239](https://github.com/json-c/json-c/issues/239) - initialize null terminator of new printbuf \ +* [Issue #240](https://github.com/json-c/json-c/issues/240) - Compile error: Variable set but not used \ +* [Issue #241](https://github.com/json-c/json-c/issues/241) - getting error in date string 19\/07\/2016, fixed for error 19/07/2016 \ +* [Issue #242](https://github.com/json-c/json-c/issues/242) - json_tokener_parse error \ +* [Issue #243](https://github.com/json-c/json-c/issues/243) - Fix #165 \ +* [Issue #244](https://github.com/json-c/json-c/issues/244) - Error while compiling source from RHEL5, could you please help me to fix this \ +* [Issue #245](https://github.com/json-c/json-c/issues/245) - json-c compile in window xp \ +* [Issue #246](https://github.com/json-c/json-c/issues/246) - Mac: uselocale failed to build \ +* [Issue #247](https://github.com/json-c/json-c/issues/247) - json_object_array_del_idx function has segment fault error? \ +* [Issue #248](https://github.com/json-c/json-c/issues/248) - Minor changes in C source code \ +* [Issue #249](https://github.com/json-c/json-c/issues/249) - Improving README \ +* [Issue #250](https://github.com/json-c/json-c/issues/250) - Improving .gitignore \ +* [Issue #251](https://github.com/json-c/json-c/issues/251) - Adding a file for EditorConfig \ +* [Issue #252](https://github.com/json-c/json-c/issues/252) - Very minor changes not related to C source code \ +* [Issue #253](https://github.com/json-c/json-c/issues/253) - Adding a test with cppcheck for Travis CI \ +* [Issue #254](https://github.com/json-c/json-c/issues/254) - Very minor changes to some tests \ +* [Issue #255](https://github.com/json-c/json-c/issues/255) - Minor changes in C source code \ +* [Issue #256](https://github.com/json-c/json-c/issues/256) - Mailing list dead? \ +* [Issue #257](https://github.com/json-c/json-c/issues/257) - Defining a coding style \ +* [Issue #258](https://github.com/json-c/json-c/issues/258) - Enable CI services \ +* [Issue #259](https://github.com/json-c/json-c/issues/259) - Fails to parse valid json \ +* [Issue #260](https://github.com/json-c/json-c/issues/260) - Adding an object to itself \ +* [Issue #261](https://github.com/json-c/json-c/issues/261) - Lack of proper documentation \ +* [Issue #262](https://github.com/json-c/json-c/issues/262) - Add Cmakefile and fix compiler warning. \ +* [Issue #263](https://github.com/json-c/json-c/issues/263) - Compiler Warnings with VS2015 \ +* [Issue #264](https://github.com/json-c/json-c/issues/264) - successed in simple test while failed in my project \ +* [Issue #265](https://github.com/json-c/json-c/issues/265) - Conformance report for reference \ +* [Issue #266](https://github.com/json-c/json-c/issues/266) - crash perhaps related to reference counting \ +* [Issue #267](https://github.com/json-c/json-c/issues/267) - Removes me as Win32 maintainer, because I'm not. \ +* [Issue #268](https://github.com/json-c/json-c/issues/268) - Documentation of json_object_to_json_string gives no information about memory management \ +* [Issue #269](https://github.com/json-c/json-c/issues/269) - json_object__set(json_object *o, value) API for value setting in json object private structure \ +* [Issue #270](https://github.com/json-c/json-c/issues/270) - new API json_object_new_double_f(doubel d,const char * fmt); \ +* [Issue #271](https://github.com/json-c/json-c/issues/271) - Cannot compile using CMake on macOS \ +* [Issue #273](https://github.com/json-c/json-c/issues/273) - fixed wrong object name in json_object_all_values_equal \ +* [Issue #274](https://github.com/json-c/json-c/issues/274) - Support for 64 bit pointers on Windows \ +* [Issue #275](https://github.com/json-c/json-c/issues/275) - Out-of-bounds read in json_tokener_parse_ex \ +* [Issue #276](https://github.com/json-c/json-c/issues/276) - ./configure for centos release 6.7(final) failure \ +* [Issue #277](https://github.com/json-c/json-c/issues/277) - Json object set xxx \ +* [Issue #278](https://github.com/json-c/json-c/issues/278) - Serialization of double with no fractional component drops trailing zero \ +* [Issue #279](https://github.com/json-c/json-c/issues/279) - Segmentation fault in array_list_length() \ +* [Issue #280](https://github.com/json-c/json-c/issues/280) - Should json_object_array_get_idx check whether input obj is array? \ +* [Issue #281](https://github.com/json-c/json-c/issues/281) - how to pretty print json-c? \ +* [Issue #282](https://github.com/json-c/json-c/issues/282) - ignore temporary files \ +* [Issue #283](https://github.com/json-c/json-c/issues/283) - json_pointer: add first revision based on RFC 6901 \ +* [Issue #284](https://github.com/json-c/json-c/issues/284) - Resusing json_tokener object \ +* [Issue #285](https://github.com/json-c/json-c/issues/285) - Revert "compat/strdup.h: move common compat check for strdup() to own \ +* [Issue #286](https://github.com/json-c/json-c/issues/286) - json_tokener_parse_ex() returns json_tokener_continue on zero-length string \ +* [Issue #287](https://github.com/json-c/json-c/issues/287) - json_pointer: extend setter & getter with printf() style arguments \ +* [Issue #288](https://github.com/json-c/json-c/issues/288) - Fix _GNU_SOURCE define for vasprintf \ +* [Issue #289](https://github.com/json-c/json-c/issues/289) - bugfix: floating point representaion without fractional part \ +* [Issue #290](https://github.com/json-c/json-c/issues/290) - duplicate an json_object \ +* [Issue #291](https://github.com/json-c/json-c/issues/291) - isspace assert error \ +* [Issue #292](https://github.com/json-c/json-c/issues/292) - configure error "./configure: line 13121: syntax error near unexpected token `-Wall'" \ +* [Issue #293](https://github.com/json-c/json-c/issues/293) - how to make with bitcode for ios \ +* [Issue #294](https://github.com/json-c/json-c/issues/294) - Adding UTF-8 validation. Fixes #122 \ +* [Issue #295](https://github.com/json-c/json-c/issues/295) - cross compile w/ mingw \ +* [Issue #296](https://github.com/json-c/json-c/issues/296) - Missing functions header in json_object.h \ +* [Issue #297](https://github.com/json-c/json-c/issues/297) - could not parse string to Json object? Like string str=\"helloworld;E\\test\\log\\;end\" \ +* [Issue #298](https://github.com/json-c/json-c/issues/298) - Building using CMake doesn't work \ +* [Issue #299](https://github.com/json-c/json-c/issues/299) - Improve json_object -> string performance \ +* [Issue #300](https://github.com/json-c/json-c/issues/300) - Running tests with MinGW build \ +* [Issue #301](https://github.com/json-c/json-c/issues/301) - How to deep copy json_object in C++ ? \ +* [Issue #302](https://github.com/json-c/json-c/issues/302) - json_tokener_parse_ex doesn't parse JSON values \ +* [Issue #303](https://github.com/json-c/json-c/issues/303) - fix doc in tokener header file \ +* [Issue #304](https://github.com/json-c/json-c/issues/304) - (.text+0x72846): undefined reference to `is_error' \ +* [Issue #305](https://github.com/json-c/json-c/issues/305) - Fix compilation without C-99 option \ +* [Issue #306](https://github.com/json-c/json-c/issues/306) - ./configure: line 12748 -error=deprecated-declarations \ +* [Issue #307](https://github.com/json-c/json-c/issues/307) - Memory leak in json_tokener_parse \ +* [Issue #308](https://github.com/json-c/json-c/issues/308) - AM_PROG_LIBTOOL not found on Linux \ +* [Issue #309](https://github.com/json-c/json-c/issues/309) - GCC 7 reports various -Wimplicit-fallthrough= errors \ +* [Issue #310](https://github.com/json-c/json-c/issues/310) - Add FALLTHRU comment to handle GCC7 warnings. \ +* [Issue #311](https://github.com/json-c/json-c/issues/311) - Fix error C3688 when compiling on Visual Studio 2015 \ +* [Issue #312](https://github.com/json-c/json-c/issues/312) - Fix CMake Build process improved for MinGW and MSYS2 \ +* [Issue #313](https://github.com/json-c/json-c/issues/313) - VERBOSE=1 make check; tests/test_util_file.test.c and tests/test_util_file.expected out of sync \ +* [Issue #315](https://github.com/json-c/json-c/issues/315) - Passing -1 to json_tokener_parse_ex is possibly unsafe \ +* [Issue #316](https://github.com/json-c/json-c/issues/316) - Memory Returned by json_object_to_json_string not freed \ +* [Issue #317](https://github.com/json-c/json-c/issues/317) - json_object_get_string gives segmentation error \ +* [Issue #318](https://github.com/json-c/json-c/issues/318) - PVS-Studio static analyzer analyze results \ +* [Issue #319](https://github.com/json-c/json-c/issues/319) - Windows: Fix dynamic library build with Visual Studio \ +* [Issue #320](https://github.com/json-c/json-c/issues/320) - Can't compile in Mac OS X El Capitan \ +* [Issue #321](https://github.com/json-c/json-c/issues/321) - build,cmake: fix vasprintf implicit definition and generate both static & shared libs \ +* [Issue #322](https://github.com/json-c/json-c/issues/322) - can not link with libjson-c.a \ +* [Issue #323](https://github.com/json-c/json-c/issues/323) - implicit fallthrough detected by gcc 7.1 \ +* [Issue #324](https://github.com/json-c/json-c/issues/324) - JsonPath like function? \ +* [Issue #325](https://github.com/json-c/json-c/issues/325) - Fix stack buffer overflow in json_object_double_to_json_string_format() \ +* [Issue #327](https://github.com/json-c/json-c/issues/327) - why json-c so hard to compile \ +* [Issue #328](https://github.com/json-c/json-c/issues/328) - json_object: implement json_object_deep_copy() function \ +* [Issue #329](https://github.com/json-c/json-c/issues/329) - build,cmake: build,cmake: rename libjson-c-static.a to libjson-c.a \ +* [Issue #330](https://github.com/json-c/json-c/issues/330) - tests: symlink basic tests to a single file that has the common code \ +* [Issue #331](https://github.com/json-c/json-c/issues/331) - Safe use of snprintf() / vsnprintf() for Visual studio, and thread-safety fix \ +* [Issue #332](https://github.com/json-c/json-c/issues/332) - Valgrind: invalid read after json_object_array_del_idx. \ +* [Issue #333](https://github.com/json-c/json-c/issues/333) - Replace obsolete AM_PROG_LIBTOOL \ +* [Issue #335](https://github.com/json-c/json-c/issues/335) - README.md: show build status tag from travis-ci.org \ +* [Issue #336](https://github.com/json-c/json-c/issues/336) - tests: fix tests in travis-ci.org \ +* [Issue #337](https://github.com/json-c/json-c/issues/337) - Synchronize "potentially racy" random seed in lh_char_hash() \ +* [Issue #338](https://github.com/json-c/json-c/issues/338) - implement json_object_int_inc(json_object *, int64_t) \ +* [Issue #339](https://github.com/json-c/json-c/issues/339) - Json schema validation \ +* [Issue #340](https://github.com/json-c/json-c/issues/340) - strerror_override: add extern "C" and JSON_EXPORT specifiers for Visual C++ compilers \ +* [Issue #341](https://github.com/json-c/json-c/issues/341) - character "/" parse as "\/" \ +* [Issue #342](https://github.com/json-c/json-c/issues/342) - No such file or directory "/usr/include/json.h" \ +* [Issue #343](https://github.com/json-c/json-c/issues/343) - Can't parse json \ +* [Issue #344](https://github.com/json-c/json-c/issues/344) - Fix Mingw build \ +* [Issue #345](https://github.com/json-c/json-c/issues/345) - Fix make dist and make distcheck \ +* [Issue #346](https://github.com/json-c/json-c/issues/346) - Clamp double to int32 when narrowing in json_object_get_int. \ +* [Issue #347](https://github.com/json-c/json-c/issues/347) - MSVC linker error json_c_strerror \ +* [Issue #348](https://github.com/json-c/json-c/issues/348) - why \ +* [Issue #349](https://github.com/json-c/json-c/issues/349) - `missing` is missing? \ +* [Issue #350](https://github.com/json-c/json-c/issues/350) - stderror-override and disable-shared \ +* [Issue #351](https://github.com/json-c/json-c/issues/351) - SIZE_T_MAX redefined from limits.h \ +* [Issue #352](https://github.com/json-c/json-c/issues/352) - `INSTALL` overrides an automake script. \ +* [Issue #353](https://github.com/json-c/json-c/issues/353) - Documentation issues \ +* [Issue #354](https://github.com/json-c/json-c/issues/354) - Fixes #351 #352 #353 \ +* [Issue #355](https://github.com/json-c/json-c/issues/355) - 1.make it can been compiled with Visual Studio 2010 by modify the CMakeList.txt and others \ +* [Issue #356](https://github.com/json-c/json-c/issues/356) - VS2008 test test_util_file.cpp err! \ +* [Issue #357](https://github.com/json-c/json-c/issues/357) - __json_c_strerror incompatibility with link-time optimization \ +* [Issue #358](https://github.com/json-c/json-c/issues/358) - make issue \ +* [Issue #359](https://github.com/json-c/json-c/issues/359) - update CMakeLists.txt for compile with visual studio at least 2010 \ +* [Issue #360](https://github.com/json-c/json-c/issues/360) - Use strtoll() to parse ints \ +* [Issue #361](https://github.com/json-c/json-c/issues/361) - Fix double to int cast overflow in json_object_get_int64. \ +* [Issue #362](https://github.com/json-c/json-c/issues/362) - CMake Package Config \ +* [Issue #363](https://github.com/json-c/json-c/issues/363) - Issue #338, add json_object_add_int functions \ +* [Issue #364](https://github.com/json-c/json-c/issues/364) - Cmake is Errir \ +* [Issue #365](https://github.com/json-c/json-c/issues/365) - added fallthrough for gcc7 \ +* [Issue #366](https://github.com/json-c/json-c/issues/366) - how to check the json string,crash! \ +* [Issue #367](https://github.com/json-c/json-c/issues/367) - Is json-c support "redirect" semantic? \ +* [Issue #368](https://github.com/json-c/json-c/issues/368) - Add examples \ +* [Issue #369](https://github.com/json-c/json-c/issues/369) - How to build json-c library for android? \ +* [Issue #370](https://github.com/json-c/json-c/issues/370) - Compiling using clang-cl \ +* [Issue #371](https://github.com/json-c/json-c/issues/371) - Invalid parsing for Infinity with json-c 0.12 \ +* [Issue #372](https://github.com/json-c/json-c/issues/372) - Json-c 0.12: Fixed Infinity bug \ +* [Issue #373](https://github.com/json-c/json-c/issues/373) - build: fix build on appveyor CI \ +* [Issue #374](https://github.com/json-c/json-c/issues/374) - Undefined symbols for architecture x86_64: \ +* [Issue #375](https://github.com/json-c/json-c/issues/375) - what would happened when json_object_object_add add the same key \ +* [Issue #376](https://github.com/json-c/json-c/issues/376) - Eclipse error \ +* [Issue #377](https://github.com/json-c/json-c/issues/377) - on gcc 7.2.0 on my linux distribution with json-c 2013-04-02 source \ +* [Issue #378](https://github.com/json-c/json-c/issues/378) - Eclipse: library (libjson-c) not found, but configured \ +* [Issue #379](https://github.com/json-c/json-c/issues/379) - error: this statement may fall through \[-Werror=implicit-fallthrough=\] \ +* [Issue #380](https://github.com/json-c/json-c/issues/380) - Build on Windows \ +* [Issue #381](https://github.com/json-c/json-c/issues/381) - Fix makedist \ +* [Issue #382](https://github.com/json-c/json-c/issues/382) - Memory leak for json_tokener_parse_ex for version 0.12.1 \ +* [Issue #383](https://github.com/json-c/json-c/issues/383) - Fix a compiler warning. \ +* [Issue #384](https://github.com/json-c/json-c/issues/384) - Fix a VS 2015 compiler warnings. \ diff --git a/third_party/json-c/issues_closed_for_0.14.md b/third_party/json-c/issues_closed_for_0.14.md new file mode 100644 index 000000000..65096f086 --- /dev/null +++ b/third_party/json-c/issues_closed_for_0.14.md @@ -0,0 +1,202 @@ +This list was created with: + +``` +curl https://api.github.com/search/issues?q="repo%3Ajson-c%2Fjson-c+closed%3A>2017-12-07+created%3A<2020-04-17&sort=created&order=asc&per_page=400&page=1" > issues1.out +curl https://api.github.com/search/issues?q="repo%3Ajson-c%2Fjson-c+closed%3A>2017-12-07+created%3A<2020-04-17&sort=created&order=asc&per_page=400&page=2" > issues2.out +curl https://api.github.com/search/issues?q="repo%3Ajson-c%2Fjson-c+closed%3A>2017-12-07+created%3A<2020-04-17&sort=created&order=asc&per_page=400&page=3" > issues3.out +jq -r '.items[] | "[" + .title + "](" + .url + ")" | tostring' issues?.out > issues.md +sed -e's,^\[ *\(.*\)\](https://api.github.com/.*/\([0-9].*\)),[Issue #\2](https://github.com/json-c/json-c/issues/\2) - \1,' -i issues.md +#... manual editing ... +``` + +---- + +Issues and Pull Requests closed for the 0.14 release (since commit d582d3a(2017-12-07) to a911439(2020-04-17)) + + +* [Issue #122](https://github.com/json-c/json-c/issues/122) - Add utf-8 validation when parsing strings. \ +* [Issue #139](https://github.com/json-c/json-c/issues/139) - json_object_from_file cannot accept max_depth \ +* [Issue #143](https://github.com/json-c/json-c/issues/143) - RFE / enhancement for full 64-bit signed/unsigned support \ +* [Issue #147](https://github.com/json-c/json-c/issues/147) - Please introduce soname bump if API changed \ +* [Issue #166](https://github.com/json-c/json-c/issues/166) - Need a way to specify nesting depth when opening JSON file \ +* [Issue #226](https://github.com/json-c/json-c/issues/226) - There is no json_object_new_null() \ +* [Issue #314](https://github.com/json-c/json-c/issues/314) - new release ? \ +* [Issue #326](https://github.com/json-c/json-c/issues/326) - Please extend api json_object_get_uint64 \ +* [Issue #334](https://github.com/json-c/json-c/issues/334) - Switch json-c builds to use CMake \ +* [Issue #386](https://github.com/json-c/json-c/issues/386) - Makefile: Add ACLOCAL_AMFLAGS \ +* [Issue #387](https://github.com/json-c/json-c/issues/387) - doc: Use other doxygen feature to specify mainpage \ +* [Issue #388](https://github.com/json-c/json-c/issues/388) - json_object: Add size_t json_object_sizeof() \ +* [Issue #389](https://github.com/json-c/json-c/issues/389) - json_object: Avoid double free (and thus a segfault) when ref_count gets < 0 \ +* [Issue #390](https://github.com/json-c/json-c/issues/390) - json_object: Add const size_t json_c_object_sizeof() \ +* [Issue #391](https://github.com/json-c/json-c/issues/391) - Fix non-GNUC define for JSON_C_CONST_FUNCTION \ +* [Issue #392](https://github.com/json-c/json-c/issues/392) - json_object: Avoid invalid free (and thus a segfault) when ref_count gets < 0 \ +* [Issue #393](https://github.com/json-c/json-c/issues/393) - json_object_private: Use unsigned 32-bit integer type for refcount \ +* [Issue #394](https://github.com/json-c/json-c/issues/394) - Problem serializing double \ +* [Issue #395](https://github.com/json-c/json-c/issues/395) - Key gets modified if it contains "\" \ +* [Issue #396](https://github.com/json-c/json-c/issues/396) - Build failure with no threads uClibc toolchain \ +* [Issue #397](https://github.com/json-c/json-c/issues/397) - update json object with key. \ +* [Issue #398](https://github.com/json-c/json-c/issues/398) - Build failed. \ +* [Issue #399](https://github.com/json-c/json-c/issues/399) - Avoid uninitialized variable warnings \ +* [Issue #400](https://github.com/json-c/json-c/issues/400) - How to generate static lib (.a) \ +* [Issue #401](https://github.com/json-c/json-c/issues/401) - Warnings with Valgrind \ +* [Issue #402](https://github.com/json-c/json-c/issues/402) - Add fuzzers from OSS-Fuzz \ +* [Issue #403](https://github.com/json-c/json-c/issues/403) - Segmentation fault when double quotes is used \ +* [Issue #404](https://github.com/json-c/json-c/issues/404) - valgrind: memory leak \ +* [Issue #405](https://github.com/json-c/json-c/issues/405) - Missing API to determine an object is empty \ +* [Issue #406](https://github.com/json-c/json-c/issues/406) - Undefine NDEBUG for tests \ +* [Issue #407](https://github.com/json-c/json-c/issues/407) - json_tokener_parse is crash \ +* [Issue #408](https://github.com/json-c/json-c/issues/408) - bug in array_list_del_idx when array_list_length()==1 \ +* [Issue #410](https://github.com/json-c/json-c/issues/410) - Fixed typos \ +* [Issue #411](https://github.com/json-c/json-c/issues/411) - Crash- signal SIGSEGV, Segmentation fault. ../sysdeps/x86_64/strlen.S: No such file or directory. \ +* [Issue #412](https://github.com/json-c/json-c/issues/412) - json_type changes during inter process communication. \ +* [Issue #413](https://github.com/json-c/json-c/issues/413) - how to read object of type `json_object *` in c++ \ +* [Issue #414](https://github.com/json-c/json-c/issues/414) - [Question] How JSON-c stores the serialized data in memory? \ +* [Issue #415](https://github.com/json-c/json-c/issues/415) - Resolve windows name conflict \ +* [Issue #416](https://github.com/json-c/json-c/issues/416) - segmentation fault in json_tokener_parse \ +* [Issue #417](https://github.com/json-c/json-c/issues/417) - json_tokener_parse json_object_object_get_ex with string value which is json string \ +* [Issue #418](https://github.com/json-c/json-c/issues/418) - json_object_from_* return value documented incorrectly \ +* [Issue #419](https://github.com/json-c/json-c/issues/419) - Suggestion: document (and define) that json_object_put() accepts NULL pointer to object \ +* [Issue #420](https://github.com/json-c/json-c/issues/420) - arraylist: Fixed names of parameters for callback function \ +* [Issue #421](https://github.com/json-c/json-c/issues/421) - install json_object_iterator.h header file \ +* [Issue #422](https://github.com/json-c/json-c/issues/422) - json_object_get_double() does not set errno when there is no valid conversion \ +* [Issue #423](https://github.com/json-c/json-c/issues/423) - memory leak \ +* [Issue #424](https://github.com/json-c/json-c/issues/424) - Parse string contains "\" or "/" errors \ +* [Issue #425](https://github.com/json-c/json-c/issues/425) - what this is? \ +* [Issue #426](https://github.com/json-c/json-c/issues/426) - __deprecated not supported on clang. \ +* [Issue #427](https://github.com/json-c/json-c/issues/427) - CMake: builds involving this target will not be correct \ +* [Issue #430](https://github.com/json-c/json-c/issues/430) - json_object_object_del() and Segmentation fault \ +* [Issue #431](https://github.com/json-c/json-c/issues/431) - cmake: Bump required version \ +* [Issue #432](https://github.com/json-c/json-c/issues/432) - The real CMake support. \ +* [Issue #433](https://github.com/json-c/json-c/issues/433) - The real CMake support. \ +* [Issue #434](https://github.com/json-c/json-c/issues/434) - The real CMake support \ +* [Issue #435](https://github.com/json-c/json-c/issues/435) - json_object_object_del() segmentation fault \ +* [Issue #436](https://github.com/json-c/json-c/issues/436) - Improve pkgconfig setting \ +* [Issue #437](https://github.com/json-c/json-c/issues/437) - Bad link in README.md \ +* [Issue #438](https://github.com/json-c/json-c/issues/438) - Bad link in README.html \ +* [Issue #439](https://github.com/json-c/json-c/issues/439) - reserved identifier violation \ +* [Issue #440](https://github.com/json-c/json-c/issues/440) - Use of angle brackets around file names for include statements \ +* [Issue #441](https://github.com/json-c/json-c/issues/441) - fix c flag loss during cmake building \ +* [Issue #442](https://github.com/json-c/json-c/issues/442) - error in configure file \ +* [Issue #443](https://github.com/json-c/json-c/issues/443) - remove pretty spaces when using pretty tabs \ +* [Issue #444](https://github.com/json-c/json-c/issues/444) - Document refcount of json_tokener_parse_ex return \ +* [Issue #445](https://github.com/json-c/json-c/issues/445) - Add missing "make check" target to cmake config \ +* [Issue #446](https://github.com/json-c/json-c/issues/446) - Forward slashes get escaped \ +* [Issue #448](https://github.com/json-c/json-c/issues/448) - Buffer overflow in json-c \ +* [Issue #449](https://github.com/json-c/json-c/issues/449) - Need of json_type_int64 returned by json_object_get_type() \ +* [Issue #450](https://github.com/json-c/json-c/issues/450) - Allow use json-c cmake as subproject \ +* [Issue #452](https://github.com/json-c/json-c/issues/452) - Update README.md \ +* [Issue #453](https://github.com/json-c/json-c/issues/453) - Fixed misalignment in JSON string due to space after \n being printed... \ +* [Issue #454](https://github.com/json-c/json-c/issues/454) - json_object_private: save 8 bytes in struct json_object in 64-bit arc… \ +* [Issue #455](https://github.com/json-c/json-c/issues/455) - index.html:fix dead link \ +* [Issue #456](https://github.com/json-c/json-c/issues/456) - STYLE.txt:remove executable permissions \ +* [Issue #457](https://github.com/json-c/json-c/issues/457) - .gitignore:add build directory \ +* [Issue #458](https://github.com/json-c/json-c/issues/458) - README.md:fix dead "file.html" link \ +* [Issue #459](https://github.com/json-c/json-c/issues/459) - README.html:fix link to Doxygen docs, remove WIN32 link \ +* [Issue #460](https://github.com/json-c/json-c/issues/460) - No docs for json_object_new_string_len() \ +* [Issue #461](https://github.com/json-c/json-c/issues/461) - json_object.c:set errno in json_object_get_double() \ +* [Issue #462](https://github.com/json-c/json-c/issues/462) - json_object.h:document json_object_new_string_len() \ +* [Issue #463](https://github.com/json-c/json-c/issues/463) - please check newlocale api first argument valuse. \ +* [Issue #465](https://github.com/json-c/json-c/issues/465) - CMakeLists.txt doesn't contain json_object_iterator.h which json.h includes \ +* [Issue #466](https://github.com/json-c/json-c/issues/466) - configure:3610: error: C compiler cannot create executables \ +* [Issue #467](https://github.com/json-c/json-c/issues/467) - Fix compiler warnings \ +* [Issue #468](https://github.com/json-c/json-c/issues/468) - Fix compiler warnings \ +* [Issue #469](https://github.com/json-c/json-c/issues/469) - Build under alpine with pecl install & docker-php-ext-enable? \ +* [Issue #470](https://github.com/json-c/json-c/issues/470) - cfuhash_foreach_remove doesn't upate cfuhash_num_entries \ +* [Issue #472](https://github.com/json-c/json-c/issues/472) - Segmentation fault in json_object_iter_begin \ +* [Issue #473](https://github.com/json-c/json-c/issues/473) - Convert ChangeLog to valid UTF-8 encoding. \ +* [Issue #474](https://github.com/json-c/json-c/issues/474) - Installation directories empty with CMake in pkg-config. \ +* [Issue #475](https://github.com/json-c/json-c/issues/475) - improvement proposal for json_object_object_foreach \ +* [Issue #477](https://github.com/json-c/json-c/issues/477) - Hang/Crash with large strings \ +* [Issue #478](https://github.com/json-c/json-c/issues/478) - json_object_get_string_len returns 0 when value is number \ +* [Issue #479](https://github.com/json-c/json-c/issues/479) - I want to use it in iOS or Android but I can't compile \ +* [Issue #480](https://github.com/json-c/json-c/issues/480) - json-c-0.12.1 failed making from source code \ +* [Issue #481](https://github.com/json-c/json-c/issues/481) - error while loading shared libraries: libjson-c.so.4 \ +* [Issue #482](https://github.com/json-c/json-c/issues/482) - Error "double free or corruption" after free() \ +* [Issue #483](https://github.com/json-c/json-c/issues/483) - compatible with rarely-used Chinese characters in GBK charset \ +* [Issue #485](https://github.com/json-c/json-c/issues/485) - Install CMake module files \ +* [Issue #486](https://github.com/json-c/json-c/issues/486) - In the case of negative double value, it is formatted without including ".0" \ +* [Issue #488](https://github.com/json-c/json-c/issues/488) - Some APIs are not exported when built as shared lib on Win32 \ +* [Issue #489](https://github.com/json-c/json-c/issues/489) - Don't use -Werror by default \ +* [Issue #490](https://github.com/json-c/json-c/issues/490) - do not compile with -Werror by default \ +* [Issue #491](https://github.com/json-c/json-c/issues/491) - build: add option --disable-werror to configure \ +* [Issue #492](https://github.com/json-c/json-c/issues/492) - lack some quick usage in readme \ +* [Issue #494](https://github.com/json-c/json-c/issues/494) - Code generator? \ +* [Issue #495](https://github.com/json-c/json-c/issues/495) - README.md:fix 2 typos \ +* [Issue #496](https://github.com/json-c/json-c/issues/496) - json_pointer.h:suggest minor grammar improvement for pointer doc \ +* [Issue #497](https://github.com/json-c/json-c/issues/497) - add common header for all tests \ +* [Issue #498](https://github.com/json-c/json-c/issues/498) - double_serializer_test fails (with valgrind) \ +* [Issue #499](https://github.com/json-c/json-c/issues/499) - .travis.yml:test on more recent clang and gcc versions \ +* [Issue #500](https://github.com/json-c/json-c/issues/500) - test/Makefile.am:add missing deps for test1 and test2 \ +* [Issue #501](https://github.com/json-c/json-c/issues/501) - undefine NDEBUG for tests \ +* [Issue #502](https://github.com/json-c/json-c/issues/502) - configure error \ +* [Issue #503](https://github.com/json-c/json-c/issues/503) - json-c retuns OK when Invalid json string is passed \ +* [Issue #504](https://github.com/json-c/json-c/issues/504) - json_object_put coredump \ +* [Issue #505](https://github.com/json-c/json-c/issues/505) - Add vcpkg installation instructions \ +* [Issue #506](https://github.com/json-c/json-c/issues/506) - Cannot parse more than one object \ +* [Issue #509](https://github.com/json-c/json-c/issues/509) - Sometimes a double value is not serialized \ +* [Issue #510](https://github.com/json-c/json-c/issues/510) - Bump so-name and improve CMake \ +* [Issue #511](https://github.com/json-c/json-c/issues/511) - Reduce lines for better optimization \ +* [Issue #512](https://github.com/json-c/json-c/issues/512) - Properly append to CMAKE_C_FLAGS string \ +* [Issue #513](https://github.com/json-c/json-c/issues/513) - What does `userdata` means?And what is the case we can use it? \ +* [Issue #514](https://github.com/json-c/json-c/issues/514) - Json c 0.13 \ +* [Issue #515](https://github.com/json-c/json-c/issues/515) - Mies suomesta fixes segfaults and logic errors \ +* [Issue #516](https://github.com/json-c/json-c/issues/516) - Lja slight mods \ +* [Issue #518](https://github.com/json-c/json-c/issues/518) - Escape character "\\003\", get unexpected value \ +* [Issue #519](https://github.com/json-c/json-c/issues/519) - Add test case obj token \ +* [Issue #520](https://github.com/json-c/json-c/issues/520) - Adding type uint64 \ +* [Issue #521](https://github.com/json-c/json-c/issues/521) - build cmake windows 10 \ +* [Issue #522](https://github.com/json-c/json-c/issues/522) - update json_visit testcase \ +* [Issue #523](https://github.com/json-c/json-c/issues/523) - update tsetcase for tokener_c \ +* [Issue #524](https://github.com/json-c/json-c/issues/524) - Increase coverage \ +* [Issue #525](https://github.com/json-c/json-c/issues/525) - update pointer test case \ +* [Issue #526](https://github.com/json-c/json-c/issues/526) - Increased the test coverage of printbuf.c 82% to 92%. \ +* [Issue #527](https://github.com/json-c/json-c/issues/527) - Arraylist testcase \ +* [Issue #528](https://github.com/json-c/json-c/issues/528) - Solve issue #108. Skip \u0000 while parsing. \ +* [Issue #529](https://github.com/json-c/json-c/issues/529) - Increased the test coverage of json_c_version.c 0% to 100%. \ +* [Issue #530](https://github.com/json-c/json-c/issues/530) - validate utf-8 string before parse \ +* [Issue #531](https://github.com/json-c/json-c/issues/531) - validate utf-8 string \ +* [Issue #532](https://github.com/json-c/json-c/issues/532) - json_object_object_get_ex returning the original object \ +* [Issue #533](https://github.com/json-c/json-c/issues/533) - Fix "make check" \ +* [Issue #535](https://github.com/json-c/json-c/issues/535) - short string optimization: excessive array length \ +* [Issue #536](https://github.com/json-c/json-c/issues/536) - add json_object_new_null() \ +* [Issue #538](https://github.com/json-c/json-c/issues/538) - update shortstring and arraylist parameters \ +* [Issue #539](https://github.com/json-c/json-c/issues/539) - double serializes to the old value after set_double \ +* [Issue #541](https://github.com/json-c/json-c/issues/541) - add coveralls auto tool to json-c \ +* [Issue #542](https://github.com/json-c/json-c/issues/542) - add uint64 data to json-c \ +* [Issue #543](https://github.com/json-c/json-c/issues/543) - Readme \ +* [Issue #544](https://github.com/json-c/json-c/issues/544) - Increase distcheck target in cmake \ +* [Issue #545](https://github.com/json-c/json-c/issues/545) - add doc target in cmake \ +* [Issue #546](https://github.com/json-c/json-c/issues/546) - Add uninstall target in cmake \ +* [Issue #547](https://github.com/json-c/json-c/issues/547) - modify json-c default build type, and fix up the assert() errors in t… \ +* [Issue #548](https://github.com/json-c/json-c/issues/548) - Solve some problems about cmake build type (debug/release) \ +* [Issue #549](https://github.com/json-c/json-c/issues/549) - lib installation issues \ +* [Issue #550](https://github.com/json-c/json-c/issues/550) - Format codes with clang-format tool? \ +* [Issue #551](https://github.com/json-c/json-c/issues/551) - Allow hexadecimal number format convention parsing \ +* [Issue #553](https://github.com/json-c/json-c/issues/553) - Fix/clang ubsan \ +* [Issue #554](https://github.com/json-c/json-c/issues/554) - RFC 8259 compatibility mode \ +* [Issue #555](https://github.com/json-c/json-c/issues/555) - Format json-c with clang-format tool \ +* [Issue #556](https://github.com/json-c/json-c/issues/556) - Fixes various Wreturn-type and Wimplicit-fallthrough errors on Mingw-w64 \ +* [Issue #557](https://github.com/json-c/json-c/issues/557) - Add option in CMAKE to not build documentation \ +* [Issue #558](https://github.com/json-c/json-c/issues/558) - modify the doc target message \ +* [Issue #559](https://github.com/json-c/json-c/issues/559) - json_c_visit() not exported on Windows \ +* [Issue #560](https://github.com/json-c/json-c/issues/560) - error: implicit declaration of function '_strtoi64' \ +* [Issue #561](https://github.com/json-c/json-c/issues/561) - add the badge in README.md and test the coveralls \ +* [Issue #562](https://github.com/json-c/json-c/issues/562) - Bugfix and testcases supplements \ +* [Issue #563](https://github.com/json-c/json-c/issues/563) - Changed order of calloc args to match stdlib \ +* [Issue #564](https://github.com/json-c/json-c/issues/564) - Remove autogenerated files \ +* [Issue #565](https://github.com/json-c/json-c/issues/565) - test the CI and ignore this PR \ +* [Issue #566](https://github.com/json-c/json-c/issues/566) - add the json_types.h to Makefile.am \ +* [Issue #567](https://github.com/json-c/json-c/issues/567) - Install json_types.h with autotools build as well. \ +* [Issue #568](https://github.com/json-c/json-c/issues/568) - Adding better support to MinGW \ +* [Issue #569](https://github.com/json-c/json-c/issues/569) - Handling of -Bsymbolic-function in CMakeLists.txt is deficient \ +* [Issue #571](https://github.com/json-c/json-c/issues/571) - CMake: Bump SONAME to 5. \ +* [Issue #572](https://github.com/json-c/json-c/issues/572) - Small fixes to CMakeLists \ +* [Issue #573](https://github.com/json-c/json-c/issues/573) - Fix coveralls submission. \ +* [Issue #574](https://github.com/json-c/json-c/issues/574) - autogen.sh missing from repository \ +* [Issue #575](https://github.com/json-c/json-c/issues/575) - Small cosmetics. \ +* [Issue #576](https://github.com/json-c/json-c/issues/576) - Test coverage for json_c_version. \ +* [Issue #577](https://github.com/json-c/json-c/issues/577) - Be verbose on failing json_c_version test. \ +* [Issue #578](https://github.com/json-c/json-c/issues/578) - CMake: Install pkgconfig file in proper location by default \ +* [Issue #579](https://github.com/json-c/json-c/issues/579) - Enforce strict prototypes. \ +* [Issue #580](https://github.com/json-c/json-c/issues/580) - Fix CMake tests for enforced strict prototypes. \ +* [Issue #581](https://github.com/json-c/json-c/issues/581) - CMakeLists: do not enforce strict prototypes on Windows. \ diff --git a/third_party/json-c/issues_closed_for_0.15.md b/third_party/json-c/issues_closed_for_0.15.md new file mode 100644 index 000000000..8c7f2f6a7 --- /dev/null +++ b/third_party/json-c/issues_closed_for_0.15.md @@ -0,0 +1,85 @@ +This list was created with: + +``` +curl "https://api.github.com/search/issues?q=repo%3Ajson-c%2Fjson-c+closed%3A>2020-04-18+created%3A<2020-07-23&sort=created&order=asc&per_page=100&page=1" > issues1.out +jq -r '.items[] | "[" + .title + "](" + .url + ")" | tostring' issues?.out > issues.md +sed -e's,^\[ *\(.*\)\](https://api.github.com/.*/\([0-9].*\)),* [Issue #\2](https://github.com/json-c/json-c/issues/\2) - \1,' -i issues.md +#... manual editing ... + +``` + +---- + +Issues and Pull Requests closed for the 0.15 release +(since commit 31ab57ca, the 0.14 branch point, 2020-04-19) + +* [Issue #428](https://github.com/json-c/json-c/issues/428) - Added new_null() function +* [Issue #429](https://github.com/json-c/json-c/issues/429) - Conflict of interest between JSON_C_TO_STRING_SPACED and JSON_C_TO_STRING_PRETTY +* [Issue #451](https://github.com/json-c/json-c/issues/451) - Add option to disable HAVE___THREAD +* [Issue #471](https://github.com/json-c/json-c/issues/471) - create folders with mode 0755 when building +* [Issue #476](https://github.com/json-c/json-c/issues/476) - Add new function named json_object_new_string_noalloc +* [Issue #484](https://github.com/json-c/json-c/issues/484) - Add support for uint64 +* [Issue #487](https://github.com/json-c/json-c/issues/487) - Any plans to make new release? (0.14) +* [Issue #493](https://github.com/json-c/json-c/issues/493) - Kdopen rename library +* [Issue #507](https://github.com/json-c/json-c/issues/507) - Double value -1.0 converts to integer in json_object_to_json_string() +* [Issue #508](https://github.com/json-c/json-c/issues/508) - Recommend enabling the `-fPIC` compiler flag by default +* [Issue #517](https://github.com/json-c/json-c/issues/517) - Lja mods +* [Issue #534](https://github.com/json-c/json-c/issues/534) - Both json-c and json-glib have json_object_get_type() +* [Issue #584](https://github.com/json-c/json-c/issues/584) - CMake: SOVERSION and the major library VERSION need to be in lockstep. +* [Issue #585](https://github.com/json-c/json-c/issues/585) - CMake: Do not install config.h, as it is not a public header file. +* [Issue #586](https://github.com/json-c/json-c/issues/586) - 10796 Segmentation fault +* [Issue #588](https://github.com/json-c/json-c/issues/588) - Broken RDRAND causes infinite looping +* [Issue #589](https://github.com/json-c/json-c/issues/589) - Detect broken RDRAND during initialization +* [Issue #590](https://github.com/json-c/json-c/issues/590) - Fix segmentation fault in CPUID check +* [Issue #591](https://github.com/json-c/json-c/issues/591) - Update README.md +* [Issue #592](https://github.com/json-c/json-c/issues/592) - Prevent out of boundary write on malicious input +* [Issue #593](https://github.com/json-c/json-c/issues/593) - Building both static and shared libraries +* [Issue #594](https://github.com/json-c/json-c/issues/594) - Some subsequent call of lh_get_hash not working +* [Issue #595](https://github.com/json-c/json-c/issues/595) - Support to build both static and shared libraries +* [Issue #596](https://github.com/json-c/json-c/issues/596) - QA Notice: Package triggers severe warnings +* [Issue #597](https://github.com/json-c/json-c/issues/597) - json_parse demo: fix and use usage() function +* [Issue #598](https://github.com/json-c/json-c/issues/598) - Turning off shared libs causes target duplication or build error +* [Issue #599](https://github.com/json-c/json-c/issues/599) - cannot add more than 11 objects. Is this a known issue? +* [Issue #600](https://github.com/json-c/json-c/issues/600) - Library name conflicts on Windows are back again +* [Issue #601](https://github.com/json-c/json-c/issues/601) - json_tokener_parse() in master sets errno=1 "Operation not permitted" +* [Issue #602](https://github.com/json-c/json-c/issues/602) - fix json_parse_uint64() internal error checking with errno +* [Issue #603](https://github.com/json-c/json-c/issues/603) - Backport of fixes from master branch. +* [Issue #604](https://github.com/json-c/json-c/issues/604) - commit f2e991a3419ee4078e8915e840b1a0d9003b349e breaks cross-compilation with mingw +* [Issue #605](https://github.com/json-c/json-c/issues/605) - Update to 0.15 release +* [Issue #606](https://github.com/json-c/json-c/issues/606) - Improved support for IBM operating systems +* [Issue #607](https://github.com/json-c/json-c/issues/607) - json-c-0.13.x: Fix CVE-2020-12762 - json-c through 0.14 has an integer overflow and out-of-bounds write ... +* [Issue #608](https://github.com/json-c/json-c/issues/608) - json-c-0.14: Fix CVE-2020-12762 - json-c through 0.14 has an integer overflow and out-of-bounds write ... +* [Issue #609](https://github.com/json-c/json-c/issues/609) - use unsigned types for sizes in lh_table and entries +* [Issue #610](https://github.com/json-c/json-c/issues/610) - let's not call lh_table_resize with INT_MAX +* [Issue #611](https://github.com/json-c/json-c/issues/611) - json-c-0.12.x: Fix CVE-2020-12762 - json-c through 0.14 has an integer overflow and out-of-bounds write ... +* [Issue #613](https://github.com/json-c/json-c/issues/613) - json-c-0.10: Fix CVE-2020-12762 - json-c through 0.14 has an integer overflow and out-of-bounds write ... +* [Issue #614](https://github.com/json-c/json-c/issues/614) - Prevent truncation on custom double formatters. +* [Issue #615](https://github.com/json-c/json-c/issues/615) - New release with security fix +* [Issue #616](https://github.com/json-c/json-c/issues/616) - Parsing fails if UTF-16 low surrogate pair is not in same chunk is the high pair +* [Issue #617](https://github.com/json-c/json-c/issues/617) - Add an option to disable the use of thread-local storage. +* [Issue #618](https://github.com/json-c/json-c/issues/618) - test_deep_copy: Fix assertion value. +* [Issue #619](https://github.com/json-c/json-c/issues/619) - CMake: Fix out-of-tree build for Doxygen documentation. +* [Issue #621](https://github.com/json-c/json-c/issues/621) - json-c and jansson libraries have symbol conflicts +* [Issue #622](https://github.com/json-c/json-c/issues/622) - doc: Move Doxyfile into doc subdir. +* [Issue #623](https://github.com/json-c/json-c/issues/623) - json_tokener_parse : Segmentation fault +* [Issue #626](https://github.com/json-c/json-c/issues/626) - Fixes for cmake 2.8.12 + link issue on AIX 6.1/cc 11.01 +* [Issue #627](https://github.com/json-c/json-c/issues/627) - Compat fixes +* [Issue #628](https://github.com/json-c/json-c/issues/628) - get_cryptgenrandom_seed: compat with old windows + fallback +* [Issue #629](https://github.com/json-c/json-c/issues/629) - [0.12] Remove the Visual Studio project file +* [Issue #630](https://github.com/json-c/json-c/issues/630) - Linking with Windows MINGW not working +* [Issue #632](https://github.com/json-c/json-c/issues/632) - Json object split +* [Issue #633](https://github.com/json-c/json-c/issues/633) - fix issue 616: support the surrogate pair in split file. +* [Issue #634](https://github.com/json-c/json-c/issues/634) - Issue #508: `-fPIC` to link libjson-c.a with libs +* [Issue #635](https://github.com/json-c/json-c/issues/635) - expression has no effect warning in json_tokener.c +* [Issue #636](https://github.com/json-c/json-c/issues/636) - json_object_get_string free str memory +* [Issue #637](https://github.com/json-c/json-c/issues/637) - json_object_put() has 'double free or corruption (out) ' +* [Issue #638](https://github.com/json-c/json-c/issues/638) - json-c/json_object.c:50:2: error: #error Unable to determine size of ssize_t +* [Issue #639](https://github.com/json-c/json-c/issues/639) - build: Add a symbol version to all exported symbols +* [Issue #640](https://github.com/json-c/json-c/issues/640) - Fix build issues with SSIZE_MAX on 64bit Linux +* [Issue #641](https://github.com/json-c/json-c/issues/641) - Formal verification of your test suite +* [Issue #642](https://github.com/json-c/json-c/issues/642) - Please provide more precise informations about when to call json_object_put +* [Issue #643](https://github.com/json-c/json-c/issues/643) - not able to compare with string +* [Issue #644](https://github.com/json-c/json-c/issues/644) - Why src->_userdata not checked before calling strdup? +* [Issue #645](https://github.com/json-c/json-c/issues/645) - Misuse of tolower() in json_tokener.c +* [Issue #646](https://github.com/json-c/json-c/issues/646) - Cast to unsigned char instead of int when calling tolower (Fixes #645) + diff --git a/third_party/json-c/issues_closed_for_0.16.md b/third_party/json-c/issues_closed_for_0.16.md new file mode 100644 index 000000000..290967d52 --- /dev/null +++ b/third_party/json-c/issues_closed_for_0.16.md @@ -0,0 +1,107 @@ +This list was created with: + +``` +PREV=2020-07-23 +NOW=2022-04-13 +curl "https://api.github.com/search/issues?q=repo%3Ajson-c%2Fjson-c+closed%3A>${PREV}+created%3A<${NOW}&sort=created&order=asc&per_page=100&page=1" > issues1.out +jq -r '.items[] | "[" + .title + "](" + .url + ")" | tostring' issues?.out > issues.md +sed -e's,^\[ *\(.*\)\](https://api.github.com/.*/\([0-9].*\)),* [Issue #\2](https://github.com/json-c/json-c/issues/\2) - \1,' -i issues.md +cat issues.md >> issues_closed_for_0.16.md +``` + +* [Issue #464](https://github.com/json-c/json-c/issues/464) - Speed up parsing and object creation +* [Issue #540](https://github.com/json-c/json-c/issues/540) - request: json_init_library +* [Issue #631](https://github.com/json-c/json-c/issues/631) - New 0.14 release requests +* [Issue #647](https://github.com/json-c/json-c/issues/647) - "cmake -DCMAKE_BUILD_TYPE=Release" fails with error: 'cint64' may be used uninitialized +* [Issue #648](https://github.com/json-c/json-c/issues/648) - Fix "may be used uninitialized" Release build failure +* [Issue #649](https://github.com/json-c/json-c/issues/649) - json-c tag 0.15 tarball contains a file doc/Doxyfile and generated doxygen files in doc/html +* [Issue #650](https://github.com/json-c/json-c/issues/650) - README: fix spelling errors +* [Issue #651](https://github.com/json-c/json-c/issues/651) - Getrandom +* [Issue #652](https://github.com/json-c/json-c/issues/652) - Waste memory +* [Issue #653](https://github.com/json-c/json-c/issues/653) - Make the documentation build reproducibly +* [Issue #654](https://github.com/json-c/json-c/issues/654) - A stack-buffer-overflow in json_parse.c:89:44 +* [Issue #655](https://github.com/json-c/json-c/issues/655) - json_parse: Fix read past end of buffer +* [Issue #656](https://github.com/json-c/json-c/issues/656) - Fixed warnings +* [Issue #657](https://github.com/json-c/json-c/issues/657) - Use GRND_NONBLOCK with getrandom. +* [Issue #658](https://github.com/json-c/json-c/issues/658) - json_object_get_boolean() returns wrong result for objects and arrays +* [Issue #659](https://github.com/json-c/json-c/issues/659) - fix json_object_get_boolean() to behave like documented +* [Issue #660](https://github.com/json-c/json-c/issues/660) - Validate size arguments in arraylist functions. +* [Issue #661](https://github.com/json-c/json-c/issues/661) - Cleanup of some code parts +* [Issue #662](https://github.com/json-c/json-c/issues/662) - Prevent signed overflow in get_time_seed +* [Issue #663](https://github.com/json-c/json-c/issues/663) - Properly format errnos in _json_c_strerror +* [Issue #664](https://github.com/json-c/json-c/issues/664) - Limit strings at INT_MAX length +* [Issue #665](https://github.com/json-c/json-c/issues/665) - Handle more allocation failures in json_tokener* functions +* [Issue #666](https://github.com/json-c/json-c/issues/666) - test1 json_object_new_array_ext test is failing +* [Issue #667](https://github.com/json-c/json-c/issues/667) - Fixed test1 regression. +* [Issue #670](https://github.com/json-c/json-c/issues/670) - Created Stone-Paper-Scissor Game by C language +* [Issue #672](https://github.com/json-c/json-c/issues/672) - Calling exit() after failure to generate random seed +* [Issue #673](https://github.com/json-c/json-c/issues/673) - switchcasemenuproject +* [Issue #674](https://github.com/json-c/json-c/issues/674) - random_seed: on error, continue to next method +* [Issue #682](https://github.com/json-c/json-c/issues/682) - libjson-c-dev vs libjson-c3 +* [Issue #683](https://github.com/json-c/json-c/issues/683) - [Question] Is it possible to clear a ptr of json_object? +* [Issue #684](https://github.com/json-c/json-c/issues/684) - json_tokener_parse_verbose failed with core dump +* [Issue #685](https://github.com/json-c/json-c/issues/685) - json_tokener_parse memory leak? +* [Issue #689](https://github.com/json-c/json-c/issues/689) - fix compilation with clang +* [Issue #690](https://github.com/json-c/json-c/issues/690) - "1," produces an object with int 1; "1" produces a null object +* [Issue #691](https://github.com/json-c/json-c/issues/691) - failed tests +* [Issue #692](https://github.com/json-c/json-c/issues/692) - patch to add arc4random +* [Issue #693](https://github.com/json-c/json-c/issues/693) - Optional parameter for packing as array +* [Issue #694](https://github.com/json-c/json-c/issues/694) - fix invalid unsigned arithmetic. +* [Issue #695](https://github.com/json-c/json-c/issues/695) - /tmp/json-c/random_seed.c:327:6: error +* [Issue #696](https://github.com/json-c/json-c/issues/696) - To avoid target exe file export JSON functions. +* [Issue #697](https://github.com/json-c/json-c/issues/697) - json_object_get_string() return value truncated when assigning it to a pointer type in Win32 App +* [Issue #698](https://github.com/json-c/json-c/issues/698) - Feature request: set allocator +* [Issue #699](https://github.com/json-c/json-c/issues/699) - Linking to libjson-c Issue +* [Issue #700](https://github.com/json-c/json-c/issues/700) - Fix unused variable for Win32 build in random_seed.c +* [Issue #701](https://github.com/json-c/json-c/issues/701) - [RFC] json_pointer: allow the feature to be disabled +* [Issue #703](https://github.com/json-c/json-c/issues/703) - Fix vasprintf fallback +* [Issue #706](https://github.com/json-c/json-c/issues/706) - Check __STDC_VERSION__ is defined before checking its value +* [Issue #707](https://github.com/json-c/json-c/issues/707) - How to build json-c-0.15 for arm arch +* [Issue #708](https://github.com/json-c/json-c/issues/708) - direct access to elements +* [Issue #709](https://github.com/json-c/json-c/issues/709) - Include guards not namespaced / build errors for debug.h with openNDS +* [Issue #710](https://github.com/json-c/json-c/issues/710) - 'file system sandbox blocked mmap()' error on iOS +* [Issue #711](https://github.com/json-c/json-c/issues/711) - creating a json object +* [Issue #712](https://github.com/json-c/json-c/issues/712) - building json-c using cmake for ESP32 +* [Issue #713](https://github.com/json-c/json-c/issues/713) - When value converted to char* can not compare it with another value +* [Issue #714](https://github.com/json-c/json-c/issues/714) - Add AfterCaseLabel to .clang-format +* [Issue #716](https://github.com/json-c/json-c/issues/716) - Fixed cmake command +* [Issue #717](https://github.com/json-c/json-c/issues/717) - Cmake is able delete all files by "clean" target +* [Issue #718](https://github.com/json-c/json-c/issues/718) - CMake create uninstall target if unix generator is used +* [Issue #719](https://github.com/json-c/json-c/issues/719) - Parsing multiple JSON strings +* [Issue #722](https://github.com/json-c/json-c/issues/722) - Fix use-after-free in json_tokener_new_ex() +* [Issue #723](https://github.com/json-c/json-c/issues/723) - if set __stdcall (/Gz) +* [Issue #724](https://github.com/json-c/json-c/issues/724) - #723 +* [Issue #725](https://github.com/json-c/json-c/issues/725) - json_object_from_file() execution segment error +* [Issue #726](https://github.com/json-c/json-c/issues/726) - fix cmake version for tests +* [Issue #727](https://github.com/json-c/json-c/issues/727) - Really use prefix JSON_C_OBJECT_ADD_ +* [Issue #728](https://github.com/json-c/json-c/issues/728) - DRAFT PROPOSAL - Add option JSON_C_OBJECT_ADD_IF_NOT_NULL +* [Issue #729](https://github.com/json-c/json-c/issues/729) - * don't assume includedir +* [Issue #731](https://github.com/json-c/json-c/issues/731) - Json-c Error +* [Issue #732](https://github.com/json-c/json-c/issues/732) - Fix/static include dirs +* [Issue #734](https://github.com/json-c/json-c/issues/734) - Newer appveyor config for VS2022 etc... +* [Issue #735](https://github.com/json-c/json-c/issues/735) - Add policy_max to minimum required cmake version +* [Issue #736](https://github.com/json-c/json-c/issues/736) - json_object.c:308: json_object_put: Assertion `jso->_ref_count > 0' failed +* [Issue #737](https://github.com/json-c/json-c/issues/737) - Fix typo in README +* [Issue #738](https://github.com/json-c/json-c/issues/738) - General question - Is there an SLA for handling newly detected security issues? +* [Issue #739](https://github.com/json-c/json-c/issues/739) - json_escape_str(): avoid harmless unsigned integer overflow +* [Issue #741](https://github.com/json-c/json-c/issues/741) - json_type_to_name(): use correct printf() formatter +* [Issue #742](https://github.com/json-c/json-c/issues/742) - json_object_copy_serializer_data(): add assertion +* [Issue #743](https://github.com/json-c/json-c/issues/743) - Cmd adb root +* [Issue #744](https://github.com/json-c/json-c/issues/744) - Close file on error path. +* [Issue #745](https://github.com/json-c/json-c/issues/745) - vasprintf(): avoid out of memory accesses +* [Issue #746](https://github.com/json-c/json-c/issues/746) - Fix typos in code comments and ChangeLog +* [Issue #747](https://github.com/json-c/json-c/issues/747) - json_object_put: Assertion `jso->_ref_count > 0' failed +* [Issue #748](https://github.com/json-c/json-c/issues/748) - sprintbuf(): test for all vsnprintf error values +* [Issue #749](https://github.com/json-c/json-c/issues/749) - sprintbuf(): handle printbuf_memappend errors +* [Issue #750](https://github.com/json-c/json-c/issues/750) - printbuf_memset(): set gaps to zero +* [Issue #751](https://github.com/json-c/json-c/issues/751) - printbuf: do not allow invalid arguments +* [Issue #752](https://github.com/json-c/json-c/issues/752) - Fix typos +* [Issue #753](https://github.com/json-c/json-c/issues/753) - CTest failed in MSVC build +* [Issue #754](https://github.com/json-c/json-c/issues/754) - Minor improvements to documentation +* [Issue #755](https://github.com/json-c/json-c/issues/755) - Fix error messages +* [Issue #758](https://github.com/json-c/json-c/issues/758) - Preserve context if out of memory +* [Issue #760](https://github.com/json-c/json-c/issues/760) - Code style: removed unneeded double-quotes +* [Issue #761](https://github.com/json-c/json-c/issues/761) - Last commit merged to master breaks compilation +* [Issue #762](https://github.com/json-c/json-c/issues/762) - how to merge two jsons by json-c +* [Issue #763](https://github.com/json-c/json-c/issues/763) - Question: sort_fn arguments +* [Issue #764](https://github.com/json-c/json-c/issues/764) - Make test fail on test case test_util_file diff --git a/third_party/json-c/issues_closed_for_0.17.md b/third_party/json-c/issues_closed_for_0.17.md new file mode 100644 index 000000000..080f063a9 --- /dev/null +++ b/third_party/json-c/issues_closed_for_0.17.md @@ -0,0 +1,88 @@ +This list was created with: + +``` +PREV=2022-04-13 +NOW=2023-08-12 +curl "https://api.github.com/search/issues?q=repo%3Ajson-c%2Fjson-c+closed%3A>${PREV}+created%3A<${NOW}&sort=created&order=asc&per_page=100&page=1" > issues1.out +jq -r '.items[] | "[" + .title + "](" + .url + ")" | tostring' issues?.out > issues.md +sed -e's,^\[ *\(.*\)\](https://api.github.com/.*/\([0-9].*\)),* [Issue #\2](https://github.com/json-c/json-c/issues/\2) - \1,' -i issues.md +cat issues.md >> issues_closed_for_0.17.md +``` + +* [Issue #191](https://github.com/json-c/json-c/issues/191) - Override int64 to only display uint64 strings +* [Issue #537](https://github.com/json-c/json-c/issues/537) - Replace '\0' only when parsing key, not change data in value. +* [Issue #570](https://github.com/json-c/json-c/issues/570) - Figure out what needs to be done with Android.configure.mk +* [Issue #587](https://github.com/json-c/json-c/issues/587) - Store the hashValue to avoid repeating the hash calculation during the hash resize. +* [Issue #612](https://github.com/json-c/json-c/issues/612) - json-c-0.11: Fix CVE-2020-12762 - json-c through 0.14 has an integer overflow and out-of-bounds write ... +* [Issue #620](https://github.com/json-c/json-c/issues/620) - Introduce json_object_new_string_{ext,noalloc}(). +* [Issue #624](https://github.com/json-c/json-c/issues/624) - json-c-0.14: Detect broken RDRAND during initialization. +* [Issue #625](https://github.com/json-c/json-c/issues/625) - json-c-0.13.x: Detect broken RDRAND during initialization. +* [Issue #668](https://github.com/json-c/json-c/issues/668) - Memory usage regression due to newlocal() on older FreeBSD releases +* [Issue #676](https://github.com/json-c/json-c/issues/676) - dereferencing type-punned pointer might break strict-aliasing rules [-Werror=strict-aliasing] +* [Issue #677](https://github.com/json-c/json-c/issues/677) - Naming conflict when using both json-c and jansson +* [Issue #679](https://github.com/json-c/json-c/issues/679) - Let json-c be used with obsolete compilers +* [Issue #681](https://github.com/json-c/json-c/issues/681) - json_tokener_parse_ex: `null` (4 bytes) only parses as valid JSON when passed with null terminator (5 bytes). Documentation issue? +* [Issue #686](https://github.com/json-c/json-c/issues/686) - Remove dependency on libM::getrandom +* [Issue #687](https://github.com/json-c/json-c/issues/687) - Does not build on Apple Silicon M1 +* [Issue #688](https://github.com/json-c/json-c/issues/688) - json-c-0.15-nodoc.tar.gz build fails +* [Issue #702](https://github.com/json-c/json-c/issues/702) - json_patch: add first implementation only with patch application +* [Issue #704](https://github.com/json-c/json-c/issues/704) - add json_object_array_insert_idx() + test-cases + fix json_pointer doc-strings +* [Issue #705](https://github.com/json-c/json-c/issues/705) - segmentation fault on json-c parsing methods in cross compiled target +* [Issue #721](https://github.com/json-c/json-c/issues/721) - cmake test fails with building json-c with icc +* [Issue #730](https://github.com/json-c/json-c/issues/730) - Need a comparison with other JSON libraries in C +* [Issue #733](https://github.com/json-c/json-c/issues/733) - Official release? 1.0? +* [Issue #756](https://github.com/json-c/json-c/issues/756) - Question: Is there any way to build this with Gnu Make? +* [Issue #757](https://github.com/json-c/json-c/issues/757) - json_object_from_fd_ex: fail if file is too large +* [Issue #759](https://github.com/json-c/json-c/issues/759) - json_tokener_parse_ex: handle out of memory errors +* [Issue #766](https://github.com/json-c/json-c/issues/766) - Some people have trouble with undefined references to arc4random +* [Issue #767](https://github.com/json-c/json-c/issues/767) - How to create a character array using json-c +* [Issue #768](https://github.com/json-c/json-c/issues/768) - commits from May 30, 2022 killed my docker build process +* [Issue #769](https://github.com/json-c/json-c/issues/769) - Issue #768 +* [Issue #770](https://github.com/json-c/json-c/issues/770) - json_parse.c:170:13: error: this statement may fall through +* [Issue #771](https://github.com/json-c/json-c/issues/771) - fix fallthough warning +* [Issue #772](https://github.com/json-c/json-c/issues/772) - add JSON_C_TO_STRING_COLOR option +* [Issue #773](https://github.com/json-c/json-c/issues/773) - problem with u_int64_t +* [Issue #774](https://github.com/json-c/json-c/issues/774) - The function add_compile_options was added to CMake version 2.8.12 and later but your minimum is 2.8 which will not work +* [Issue #775](https://github.com/json-c/json-c/issues/775) - list(TRANSFORM ...) is not available prior to CMake 3.12. +* [Issue #776](https://github.com/json-c/json-c/issues/776) - Fix typo +* [Issue #777](https://github.com/json-c/json-c/issues/777) - Don't try to change locale when libc only supports the C locale +* [Issue #778](https://github.com/json-c/json-c/issues/778) - Do not insert newlines when converting empty arrays to json string and JSON_C_TO_STRING_PRETTY is used +* [Issue #779](https://github.com/json-c/json-c/issues/779) - Fix compiling for Android +* [Issue #780](https://github.com/json-c/json-c/issues/780) - Memory Leak when setting empty strings when c_string.pdata is used +* [Issue #781](https://github.com/json-c/json-c/issues/781) - Fix memory leak with emtpy strings in json_object_set_string +* [Issue #782](https://github.com/json-c/json-c/issues/782) - Fix typos found by codespell +* [Issue #783](https://github.com/json-c/json-c/issues/783) - Fix build with clang-15+ +* [Issue #784](https://github.com/json-c/json-c/issues/784) - get_time_seed(): silence warning emitted by Coverity Scan static analyzer +* [Issue #786](https://github.com/json-c/json-c/issues/786) - ghpages update was not published for json-c-0.16 +* [Issue #787](https://github.com/json-c/json-c/issues/787) - -static linker flag result in building failed +* [Issue #788](https://github.com/json-c/json-c/issues/788) - Clear sensitive information. +* [Issue #789](https://github.com/json-c/json-c/issues/789) - Unnecessary struct declaration and unsafe function usage +* [Issue #790](https://github.com/json-c/json-c/issues/790) - Small update to README file +* [Issue #791](https://github.com/json-c/json-c/issues/791) - json_object_object_foreach not ISO-C compliant +* [Issue #792](https://github.com/json-c/json-c/issues/792) - ` json_object_get_int` does not set `EINVAL` on invalid string +* [Issue #794](https://github.com/json-c/json-c/issues/794) - replaced +* [Issue #796](https://github.com/json-c/json-c/issues/796) - Added Test for get int functions +* [Issue #797](https://github.com/json-c/json-c/issues/797) - make uninstall +* [Issue #798](https://github.com/json-c/json-c/issues/798) - API to deal with enums is missing +* [Issue #799](https://github.com/json-c/json-c/issues/799) - json_object_put: Assertion `jso->_ref_count > 0' failed. +* [Issue #800](https://github.com/json-c/json-c/issues/800) - String converted to scientific notation +* [Issue #801](https://github.com/json-c/json-c/issues/801) - #error You do not have strncasecmp on your system. +* [Issue #802](https://github.com/json-c/json-c/issues/802) - Problem: modern CMake warns about version 2.8 +* [Issue #803](https://github.com/json-c/json-c/issues/803) - Problem: confusing error message in snprintf_compat.h +* [Issue #804](https://github.com/json-c/json-c/issues/804) - Problem: cmake 3.25.1 warns about CMP0042 not being set +* [Issue #806](https://github.com/json-c/json-c/issues/806) - The problem is libjson-c.dylib incompatible with OS version +* [Issue #807](https://github.com/json-c/json-c/issues/807) - json simple parse syntax +* [Issue #808](https://github.com/json-c/json-c/issues/808) - iOS Build using cmake fails due to 64 to 32bits conversion precision loss +* [Issue #809](https://github.com/json-c/json-c/issues/809) - Feature request json_object_new_uint() +* [Issue #810](https://github.com/json-c/json-c/issues/810) - docs: update to Internet Standard reference +* [Issue #811](https://github.com/json-c/json-c/issues/811) - dependence on execution character set +* [Issue #812](https://github.com/json-c/json-c/issues/812) - Duplicate symbol when compiling with clang-cl +* [Issue #813](https://github.com/json-c/json-c/issues/813) - Build apps only in project itself. +* [Issue #814](https://github.com/json-c/json-c/issues/814) - Code execution order +* [Issue #816](https://github.com/json-c/json-c/issues/816) - Hi I need to generate libjson-c.so.3 and libjson-c.so.3.0.1, please help with steps +* [Issue #818](https://github.com/json-c/json-c/issues/818) - error: a function declaration without a prototype is deprecated in all versions of C +* [Issue #819](https://github.com/json-c/json-c/issues/819) - build with intel 2023 fails on vasprintf +* [Issue #820](https://github.com/json-c/json-c/issues/820) - ISO C forbids in +* [Issue #821](https://github.com/json-c/json-c/issues/821) - Any release planing for 0.17? +* [Issue #822](https://github.com/json-c/json-c/issues/822) - Added option to disable app build +* [Issue #823](https://github.com/json-c/json-c/issues/823) - Symbol not found during linking stage of libjson-c.so diff --git a/third_party/json-c/json-c-uninstalled.pc b/third_party/json-c/json-c-uninstalled.pc new file mode 100644 index 000000000..71ffb81e4 --- /dev/null +++ b/third_party/json-c/json-c-uninstalled.pc @@ -0,0 +1,10 @@ +prefix= +exec_prefix= +libdir=/.autodirect/mtrswgwork/tcabouly/tmp/libxlio/third_party/json-c +includedir=/.autodirect/mtrswgwork/tcabouly/tmp/libxlio/third_party/json-c + +Name: json-c +Description: JSON library in C +Version: 0.17.0 +Libs: -L${libdir} -ljson-c +Cflags: -I${includedir} diff --git a/third_party/json-c/json-c-uninstalled.pc.in b/third_party/json-c/json-c-uninstalled.pc.in index dab2bab5c..2f164a3e5 100644 --- a/third_party/json-c/json-c-uninstalled.pc.in +++ b/third_party/json-c/json-c-uninstalled.pc.in @@ -3,9 +3,8 @@ exec_prefix= libdir=@abs_top_builddir@ includedir=@abs_top_srcdir@ -Name: json -Description: JSON implementation in C -Version: @VERSION@ -Requires: -Libs: -L@abs_top_builddir@ -ljson-c -Cflags: -I@abs_top_srcdir@ +Name: json-c +Description: JSON library in C +Version: @PACKAGE_VERSION@ +Libs: -L${libdir} -ljson-c +Cflags: -I${includedir} diff --git a/third_party/json-c/json-c.pc b/third_party/json-c/json-c.pc new file mode 100644 index 000000000..493db1f02 --- /dev/null +++ b/third_party/json-c/json-c.pc @@ -0,0 +1,10 @@ +prefix=/usr/local +exec_prefix=${prefix} +libdir=${exec_prefix}/lib +includedir=${prefix}/include + +Name: json-c +Description: JSON library in C +Version: 0.17.0 +Libs: -L${libdir} -ljson-c +Cflags: -I${includedir}/json-c diff --git a/third_party/json-c/json-c.pc.in b/third_party/json-c/json-c.pc.in index 074378be8..4a4681bba 100644 --- a/third_party/json-c/json-c.pc.in +++ b/third_party/json-c/json-c.pc.in @@ -4,9 +4,7 @@ libdir=@libdir@ includedir=@includedir@ Name: json-c -Description: A JSON implementation in C -Version: @VERSION@ -Requires: -Libs.private: @LIBS@ +Description: JSON library in C +Version: @PACKAGE_VERSION@ Libs: -L${libdir} -ljson-c -Cflags: -I${includedir}/json-c +Cflags: -I${includedir}/json-c \ No newline at end of file diff --git a/third_party/json-c/json-c.sym b/third_party/json-c/json-c.sym new file mode 100644 index 000000000..102edcdb8 --- /dev/null +++ b/third_party/json-c/json-c.sym @@ -0,0 +1,196 @@ +/* + * Original work: + * + * json-c (copyright was originally missing from this file) + * + * Modified Work: + * + * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. + * + * This software product is a proprietary product of NVIDIA CORPORATION & + * AFFILIATES (the "Company") and all right, title, and interest in and to the + * software product, including all associated intellectual property rights, are + * and shall remain exclusively with the Company. + * + * This software product is governed by the End User License Agreement + * provided with the software product. + * + */ + +/* + * Symbol versioning for libjson-c. + * All exported symbols must be listed here. + * + * See + * https://software.intel.com/sites/default/files/m/a/1/e/dsohowto.pdf + */ + +/* + * Symbols in JSONC_PRIVATE are exported for historical + * reasons, but should not be used outside of json-c. + */ +JSONC_PRIVATE { + doca_third_party_array_list_add; + doca_third_party_array_list_del_idx; + doca_third_party_array_list_free; + doca_third_party_array_list_new; + doca_third_party_array_list_put_idx; + doca_third_party_array_list_sort; + doca_third_party_json_hex_chars; + doca_third_party_json_parse_double; + doca_third_party_json_parse_int64; + doca_third_party_json_parse_uint64; + doca_third_party_lh_table_delete; + doca_third_party_lh_table_delete_entry; + doca_third_party_lh_table_free; + doca_third_party_lh_table_insert; + doca_third_party_lh_table_insert_w_hash; + doca_third_party_lh_table_new; + doca_third_party_lh_table_resize; + doca_third_party_mc_debug; + doca_third_party_mc_error; + doca_third_party_mc_get_debug; + doca_third_party_mc_info; + doca_third_party_mc_set_debug; + doca_third_party_mc_set_syslog; + doca_third_party_printbuf_free; + doca_third_party_printbuf_memappend; + doca_third_party_printbuf_memset; + doca_third_party_printbuf_new; + doca_third_party_printbuf_reset; + doca_third_party_sprintbuf; + # Used by tests: + doca_third_party__json_c_strerror; +}; + +JSONC_0.14 { + global: + doca_third_party_doca_third_party_array_list_bsearch; + doca_third_party_doca_third_party_array_list_get_idx; + doca_third_party_doca_third_party_array_list_length; + doca_third_party_doca_third_party_json_c_get_random_seed; + doca_third_party_json_c_object_sizeof; + doca_third_party_json_c_set_serialization_double_format; + doca_third_party_json_c_shallow_copy_default; + doca_third_party_json_c_version; + doca_third_party_json_c_version_num; + doca_third_party_json_c_visit; + doca_third_party_json_global_set_string_hash; + doca_third_party_json_number_chars; + doca_third_party_json_object_array_add; + doca_third_party_json_object_array_bsearch; + doca_third_party_json_object_array_del_idx; + doca_third_party_json_object_array_get_idx; + doca_third_party_json_object_array_length; + doca_third_party_json_object_array_put_idx; + doca_third_party_json_object_array_sort; + doca_third_party_json_object_deep_copy; + doca_third_party_json_object_double_to_json_string; + doca_third_party_json_object_equal; + doca_third_party_json_object_free_userdata; + doca_third_party_json_object_from_fd; + doca_third_party_json_object_from_fd_ex; + doca_third_party_json_object_from_file; + doca_third_party_json_object_get; + doca_third_party_json_object_get_array; + doca_third_party_json_object_get_boolean; + doca_third_party_json_object_get_double; + doca_third_party_json_object_get_int64; + doca_third_party_json_object_get_int; + doca_third_party_json_object_get_object; + doca_third_party_json_object_get_string; + doca_third_party_json_object_get_string_len; + doca_third_party_json_object_get_type; + doca_third_party_json_object_get_uint64; + doca_third_party_json_object_get_userdata; + doca_third_party_json_object_int_inc; + doca_third_party_json_object_is_type; + doca_third_party_json_object_iter_begin; + doca_third_party_json_object_iter_end; + doca_third_party_json_object_iter_equal; + doca_third_party_json_object_iter_init_default; + doca_third_party_json_object_iter_next; + doca_third_party_json_object_iter_peek_name; + doca_third_party_json_object_iter_peek_value; + doca_third_party_json_object_new_array; + doca_third_party_json_object_new_boolean; + doca_third_party_json_object_new_double; + doca_third_party_json_object_new_double_s; + doca_third_party_json_object_new_int64; + doca_third_party_json_object_new_int; + doca_third_party_json_object_new_null; + doca_third_party_json_object_new_object; + doca_third_party_json_object_new_string; + doca_third_party_json_object_new_string_len; + doca_third_party_json_object_new_uint64; + doca_third_party_json_object_object_add; + doca_third_party_json_object_object_add_ex; + doca_third_party_json_object_object_del; + doca_third_party_json_object_object_get; + doca_third_party_json_object_object_get_ex; + doca_third_party_json_object_object_length; + doca_third_party_json_object_put; + doca_third_party_json_object_set_boolean; + doca_third_party_json_object_set_double; + doca_third_party_json_object_set_int64; + doca_third_party_json_object_set_int; + doca_third_party_json_object_set_serializer; + doca_third_party_json_object_set_string; + doca_third_party_json_object_set_string_len; + doca_third_party_json_object_set_uint64; + doca_third_party_json_object_set_userdata; + doca_third_party_json_object_to_fd; + doca_third_party_json_object_to_file; + doca_third_party_json_object_to_file_ext; + doca_third_party_json_object_to_json_string; + doca_third_party_json_object_to_json_string_ext; + doca_third_party_json_object_to_json_string_length; + doca_third_party_json_object_userdata_to_json_string; + doca_third_party_json_pointer_get; + doca_third_party_json_pointer_getf; + doca_third_party_json_pointer_set; + doca_third_party_json_pointer_setf; + doca_third_party_json_tokener_error_desc; + doca_third_party_json_tokener_free; + doca_third_party_json_tokener_get_error; + doca_third_party_json_tokener_get_parse_end; + doca_third_party_json_tokener_new; + doca_third_party_json_tokener_new_ex; + doca_third_party_json_tokener_parse; + doca_third_party_json_tokener_parse_ex; + doca_third_party_json_tokener_parse_verbose; + doca_third_party_json_tokener_reset; + doca_third_party_json_tokener_set_flags; + doca_third_party_json_type_to_name; + doca_third_party_json_util_get_last_err; + doca_third_party_lh_char_equal; + doca_third_party_lh_kchar_table_new; + doca_third_party_lh_kptr_table_new; + doca_third_party_lh_ptr_equal; + doca_third_party_lh_table_length; + doca_third_party_lh_table_lookup_entry; + doca_third_party_lh_table_lookup_entry_w_hash; + doca_third_party_lh_table_lookup_ex; + + local: + *; +}; + +JSONC_0.15 { + global: + doca_third_party_array_list_new2; + doca_third_party_array_list_shrink; + doca_third_party_json_object_array_shrink; + doca_third_party_json_object_new_array_ext; +} JSONC_0.14; + +JSONC_0.16 { +# No new symbols in 0.16 +} JSONC_0.15; + +JSONC_0.17 { + global: + doca_third_party_json_object_array_insert_idx; + doca_third_party_json_patch_apply; +# array_list_insert_idx is intentionally not exported +} JSONC_0.16; diff --git a/third_party/json-c/json-c/json.h b/third_party/json-c/json-c/json.h new file mode 100644 index 000000000..1c73048da --- /dev/null +++ b/third_party/json-c/json-c/json.h @@ -0,0 +1,58 @@ +/* + * Original work: + * + * $Id: json.h,v 1.6 2006/01/26 02:16:28 mclark Exp $ + * + * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd. + * Michael Clark + * Copyright (c) 2009 Hewlett-Packard Development Company, L.P. + * + * This library is free software; you can redistribute it and/or modify + * it under the terms of the MIT license. See COPYING for details. + * + * Modified Work: + * + * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. + * + * This software product is a proprietary product of NVIDIA CORPORATION & + * AFFILIATES (the "Company") and all right, title, and interest in and to the + * software product, including all associated intellectual property rights, are + * and shall remain exclusively with the Company. + * + * This software product is governed by the End User License Agreement + * provided with the software product. + * + */ + +/** + * This is a workaround header so that other modules will include + * as if they are using upstream, and will still find our file. + */ + +#ifdef _json_h_ +#error "regular" json-c is in the include path and will conflict with the version of DOCA! +#endif + +#ifndef _doca_json_h_ +#define _doca_json_h_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "arraylist.h" +#include "debug.h" +#include "json_c_version.h" +#include "json_object.h" +#include "json_object_iterator.h" +#include "json_patch.h" +#include "json_pointer.h" +#include "json_tokener.h" +#include "json_util.h" +#include "linkhash.h" + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/third_party/json-c/json.h b/third_party/json-c/json.h index fc2daddee..50c649164 100644 --- a/third_party/json-c/json.h +++ b/third_party/json-c/json.h @@ -1,4 +1,6 @@ /* + * Original work: + * * $Id: json.h,v 1.6 2006/01/26 02:16:28 mclark Exp $ * * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd. @@ -8,28 +10,46 @@ * This library is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See COPYING for details. * + * Modified Work: + * + * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. + * + * This software product is a proprietary product of NVIDIA CORPORATION & + * AFFILIATES (the "Company") and all right, title, and interest in and to the + * software product, including all associated intellectual property rights, are + * and shall remain exclusively with the Company. + * + * This software product is governed by the End User License Agreement + * provided with the software product. + * */ /** * @file * @brief A convenience header that may be included instead of other individual ones. */ -#ifndef _json_h_ -#define _json_h_ + +#ifdef _json_h_ +#error "regular" json-c is in the include path and will conflict with the version of DOCA! +#endif + +#ifndef _doca_json_h_ +#define _doca_json_h_ #ifdef __cplusplus extern "C" { #endif -#include "debug.h" -#include "linkhash.h" #include "arraylist.h" -#include "json_util.h" +#include "debug.h" +#include "json_c_version.h" #include "json_object.h" +#include "json_object_iterator.h" +#include "json_patch.h" #include "json_pointer.h" #include "json_tokener.h" -#include "json_object_iterator.h" -#include "json_c_version.h" +#include "json_util.h" +#include "linkhash.h" #ifdef __cplusplus } diff --git a/third_party/json-c/json.h.cmakein b/third_party/json-c/json.h.cmakein new file mode 100644 index 000000000..227132071 --- /dev/null +++ b/third_party/json-c/json.h.cmakein @@ -0,0 +1,39 @@ +/* + * $Id: json.h,v 1.6 2006/01/26 02:16:28 mclark Exp $ + * + * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd. + * Michael Clark + * Copyright (c) 2009 Hewlett-Packard Development Company, L.P. + * + * This library is free software; you can redistribute it and/or modify + * it under the terms of the MIT license. See COPYING for details. + * + */ + +/** + * @file + * @brief A convenience header that may be included instead of other individual ones. + */ +#ifndef _json_h_ +#define _json_h_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "arraylist.h" +#include "debug.h" +#include "json_c_version.h" +#include "json_object.h" +#include "json_object_iterator.h" +@JSON_H_JSON_PATCH@ +@JSON_H_JSON_POINTER@ +#include "json_tokener.h" +#include "json_util.h" +#include "linkhash.h" + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/third_party/json-c/json_c_version.c b/third_party/json-c/json_c_version.c index 13eb18855..c0429b2c2 100644 --- a/third_party/json-c/json_c_version.c +++ b/third_party/json-c/json_c_version.c @@ -1,20 +1,35 @@ /* + * Original work: + * * Copyright (c) 2012 Eric Haszlakiewicz * * This library is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See COPYING for details. + * + * Modified Work: + * + * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. + * + * This software product is a proprietary product of NVIDIA CORPORATION & + * AFFILIATES (the "Company") and all right, title, and interest in and to the + * software product, including all associated intellectual property rights, are + * and shall remain exclusively with the Company. + * + * This software product is governed by the End User License Agreement + * provided with the software product. + * */ + #include "config.h" #include "json_c_version.h" -const char *json_c_version(void) +const char *doca_third_party_json_c_version(void) { return JSON_C_VERSION; } -int json_c_version_num(void) +int doca_third_party_json_c_version_num(void) { return JSON_C_VERSION_NUM; } - diff --git a/third_party/json-c/json_c_version.h b/third_party/json-c/json_c_version.h index 98838be94..a00d63e99 100644 --- a/third_party/json-c/json_c_version.h +++ b/third_party/json-c/json_c_version.h @@ -1,8 +1,23 @@ /* + * Original work: + * * Copyright (c) 2012,2017 Eric Haszlakiewicz * * This library is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See COPYING for details. + * + * Modified Work: + * + * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. + * + * This software product is a proprietary product of NVIDIA CORPORATION & + * AFFILIATES (the "Company") and all right, title, and interest in and to the + * software product, including all associated intellectual property rights, are + * and shall remain exclusively with the Company. + * + * This software product is governed by the End User License Agreement + * provided with the software product. + * */ /** @@ -12,19 +27,30 @@ #ifndef _json_c_version_h_ #define _json_c_version_h_ +#ifdef __cplusplus +extern "C" { +#endif + #define JSON_C_MAJOR_VERSION 0 -#define JSON_C_MINOR_VERSION 13 -#define JSON_C_MICRO_VERSION 01 -#define JSON_C_VERSION_NUM ((JSON_C_MAJOR_VERSION << 16) | \ - (JSON_C_MINOR_VERSION << 8) | \ - JSON_C_MICRO_VERSION) -#define JSON_C_VERSION "0.13.1" +#define JSON_C_MINOR_VERSION 17 +#define JSON_C_MICRO_VERSION 0 +#define JSON_C_VERSION_NUM \ + ((JSON_C_MAJOR_VERSION << 16) | (JSON_C_MINOR_VERSION << 8) | JSON_C_MICRO_VERSION) +#define JSON_C_VERSION "0.17" + +#ifndef JSON_EXPORT +#if defined(_MSC_VER) && defined(JSON_C_DLL) +#define JSON_EXPORT __declspec(dllexport) +#else +#define JSON_EXPORT extern +#endif +#endif /** * @see JSON_C_VERSION * @return the version of the json-c library as a string */ -const char *json_c_version(void); /* Returns JSON_C_VERSION */ +JSON_EXPORT const char *doca_third_party_json_c_version(void); /* Returns JSON_C_VERSION */ /** * The json-c version encoded into an int, with the low order 8 bits @@ -35,6 +61,10 @@ const char *json_c_version(void); /* Returns JSON_C_VERSION */ * @see JSON_C_VERSION_NUM * @return the version of the json-c library as an int */ -int json_c_version_num(void); /* Returns JSON_C_VERSION_NUM */ +JSON_EXPORT int doca_third_party_json_c_version_num(void); /* Returns JSON_C_VERSION_NUM */ + +#ifdef __cplusplus +} +#endif #endif diff --git a/third_party/json-c/json_config.h b/third_party/json-c/json_config.h index 965ff1c37..fed2e03ed 100644 --- a/third_party/json-c/json_config.h +++ b/third_party/json-c/json_config.h @@ -1,4 +1,162 @@ /* json_config.h. Generated from json_config.h.in by configure. */ - /* Define to 1 if you have the header file. */ #define JSON_C_HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_DLFCN_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_ENDIAN_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_FCNTL_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_FLOAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_LIMITS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_LOCALE_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_MEMORY_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDARG_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYSLOG_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_CDEFS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_PARAM_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_RESOURCE_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_XLOCALE_H */ + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Define to 1 if you have the `snprintf' function. */ +#define HAVE_SNPRINTF 1 + +/* Define to 1 if you have the `vasprintf' function. */ +#define HAVE_VASPRINTF 1 + +/* Define to 1 if you have the `vsnprintf' function. */ +#define HAVE_VSNPRINTF 1 + +/* Define to 1 if you have the `vprintf' function. */ +#define HAVE_VPRINTF 1 + +/* Define to 1 if you have the `open' function. */ +#define HAVE_OPEN 1 + +/* Define to 1 if you have the `realloc' function. */ +#define HAVE_REALLOC 1 + +/* Define to 1 if you have the `setlocale' function. */ +#define HAVE_SETLOCALE 1 + +/* Define to 1 if you have the `uselocale' function. */ +#define HAVE_USELOCALE 1 + +/* Define to 1 if you have the `strcasecmp' function. */ +#define HAVE_STRCASECMP 1 + +/* Define to 1 if you have the `strncasecmp' function. */ +#define HAVE_STRNCASECMP 1 + +/* Define to 1 if you have the `strdup' function. */ +#define HAVE_STRDUP 1 + +/* Define to 1 if you have the `strerror' function. */ +#define HAVE_STRERROR 1 + +/* Define to 1 if you have the `vsyslog' function. */ +#define HAVE_VSYSLOG 1 + +/* Define to 1 if you have the `_doprnt' function. */ +/* #undef HAVE_DOPRNT */ + +/* Define to 1 if you have the `strtoll' function. */ +#define HAVE_STRTOLL 1 + +/* Define to 1 if you have the `_strtoi64' function. */ +/* #undef HAVE_STRTOI64 */ + +/* Define to 1 if you have the `__thread' keyword. */ +#define HAVE___THREAD 1 + +/* Define to 1 if you have atomic builtins. */ +#define HAVE_ATOMIC_BUILTINS 1 + +/* Define to 1 if you have the declaration of `INFINITY', and to 0 if you don't. */ +#define HAVE_DECL_INFINITY 1 + +/* Define to 1 if you have the declaration of `nan', and to 0 if you don't. */ +#define HAVE_DECL_NAN 1 + +/* Define to 1 if you have the declaration of `isnan', and to 0 if you don't. */ +#define HAVE_DECL_ISNAN 1 + +/* Define to 1 if you have the declaration of `isinf', and to 0 if you don't. */ +#define HAVE_DECL_ISINF 1 + +/* Define to 1 if you have the declaration of `_isnan', and to 0 if you don't. */ +#define HAVE_DECL__ISNAN 0 + +/* Define to 1 if you have the declaration of `_finite', and to 0 if you don't. */ +#define HAVE_DECL__FINITE 0 + +/* The size of `int', as computed by sizeof. */ +#define SIZEOF_INT 4 + +/* The size of `long', as computed by sizeof. */ +#define SIZEOF_LONG 8 + +/* The size of `long long', as computed by sizeof. */ +#define SIZEOF_LONG_LONG 8 + +/* The size of `size_t', as computed by sizeof. */ +#define SIZEOF_SIZE_T 8 + +/* The size of `int64_t', as computed by sizeof. */ +#define SIZEOF_INT64_T 8 + +/* The size of `ssize_t', as computed by sizeof. */ +#define SIZEOF_SSIZE_T 8 + +/* Define to the specifier for __thread. */ +#define SPEC___THREAD __thread + +/* Define to the function name for strtoll. */ +/* #undef json_c_strtoll */ diff --git a/third_party/json-c/json_config.h.in b/third_party/json-c/json_config.h.in index 7888e0217..4f67d887d 100644 --- a/third_party/json-c/json_config.h.in +++ b/third_party/json-c/json_config.h.in @@ -1,3 +1,161 @@ - /* Define to 1 if you have the header file. */ #undef JSON_C_HAVE_INTTYPES_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_DLFCN_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_ENDIAN_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_FCNTL_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_FLOAT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_LIMITS_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_LOCALE_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_MEMORY_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STDARG_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STDINT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STDLIB_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STRINGS_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STRING_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYSLOG_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_CDEFS_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_PARAM_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_STAT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_TYPES_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_RESOURCE_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_UNISTD_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_XLOCALE_H + +/* Define to 1 if you have the ANSI C header files. */ +#undef STDC_HEADERS + +/* Define to 1 if you have the `snprintf' function. */ +#undef HAVE_SNPRINTF + +/* Define to 1 if you have the `vasprintf' function. */ +#undef HAVE_VASPRINTF + +/* Define to 1 if you have the `vsnprintf' function. */ +#undef HAVE_VSNPRINTF + +/* Define to 1 if you have the `vprintf' function. */ +#undef HAVE_VPRINTF + +/* Define to 1 if you have the `open' function. */ +#undef HAVE_OPEN + +/* Define to 1 if you have the `realloc' function. */ +#undef HAVE_REALLOC + +/* Define to 1 if you have the `setlocale' function. */ +#undef HAVE_SETLOCALE + +/* Define to 1 if you have the `uselocale' function. */ +#undef HAVE_USELOCALE + +/* Define to 1 if you have the `strcasecmp' function. */ +#undef HAVE_STRCASECMP + +/* Define to 1 if you have the `strncasecmp' function. */ +#undef HAVE_STRNCASECMP + +/* Define to 1 if you have the `strdup' function. */ +#undef HAVE_STRDUP + +/* Define to 1 if you have the `strerror' function. */ +#undef HAVE_STRERROR + +/* Define to 1 if you have the `vsyslog' function. */ +#undef HAVE_VSYSLOG + +/* Define to 1 if you have the `_doprnt' function. */ +#undef HAVE_DOPRNT + +/* Define to 1 if you have the `strtoll' function. */ +#undef HAVE_STRTOLL + +/* Define to 1 if you have the `_strtoi64' function. */ +#undef HAVE_STRTOI64 + +/* Define to 1 if you have the `__thread' keyword. */ +#undef HAVE___THREAD + +/* Define to 1 if you have atomic builtins. */ +#undef HAVE_ATOMIC_BUILTINS + +/* Define to 1 if you have the declaration of `INFINITY', and to 0 if you don't. */ +#undef HAVE_DECL_INFINITY + +/* Define to 1 if you have the declaration of `nan', and to 0 if you don't. */ +#undef HAVE_DECL_NAN + +/* Define to 1 if you have the declaration of `isnan', and to 0 if you don't. */ +#undef HAVE_DECL_ISNAN + +/* Define to 1 if you have the declaration of `isinf', and to 0 if you don't. */ +#undef HAVE_DECL_ISINF + +/* Define to 1 if you have the declaration of `_isnan', and to 0 if you don't. */ +#undef HAVE_DECL__ISNAN + +/* Define to 1 if you have the declaration of `_finite', and to 0 if you don't. */ +#undef HAVE_DECL__FINITE + +/* The size of `int', as computed by sizeof. */ +#undef SIZEOF_INT + +/* The size of `long', as computed by sizeof. */ +#undef SIZEOF_LONG + +/* The size of `long long', as computed by sizeof. */ +#undef SIZEOF_LONG_LONG + +/* The size of `size_t', as computed by sizeof. */ +#undef SIZEOF_SIZE_T + +/* The size of `int64_t', as computed by sizeof. */ +#undef SIZEOF_INT64_T + +/* The size of `ssize_t', as computed by sizeof. */ +#undef SIZEOF_SSIZE_T + +/* Define to the specifier for __thread. */ +#undef SPEC___THREAD + +/* Define to the function name for strtoll. */ +#undef json_c_strtoll \ No newline at end of file diff --git a/third_party/json-c/json_inttypes.h b/third_party/json-c/json_inttypes.h index 3854913fc..a33a31f10 100644 --- a/third_party/json-c/json_inttypes.h +++ b/third_party/json-c/json_inttypes.h @@ -13,11 +13,25 @@ #include #else +#ifdef JSON_C_HAVE_STDINT_H #include +#else +/* Really only valid for old MS compilers, VS2008 and earlier: */ +typedef __int32 int32_t; +typedef unsigned __int32 uint32_t; +typedef __int64 int64_t; +typedef unsigned __int64 uint64_t; +#endif #define PRId64 "I64d" #define SCNd64 "I64d" +#define PRIu64 "I64u" + +#endif +#if defined(_MSC_VER) +#include +typedef SSIZE_T ssize_t; #endif #endif diff --git a/third_party/json-c/json_object.c b/third_party/json-c/json_object.c index 9a6a40873..97649fbc0 100644 --- a/third_party/json-c/json_object.c +++ b/third_party/json-c/json_object.c @@ -1,5 +1,5 @@ /* - * $Id: json_object.c,v 1.17 2006/07/25 03:24:50 mclark Exp $ + * Original work: * * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd. * Michael Clark @@ -8,6 +8,18 @@ * This library is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See COPYING for details. * + * Modified Work: + * + * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. + * + * This software product is a proprietary product of NVIDIA CORPORATION & + * AFFILIATES (the "Company") and all right, title, and interest in and to the + * software product, including all associated intellectual property rights, are + * and shall remain exclusively with the Company. + * + * This software product is governed by the End User License Agreement + * provided with the software product. + * */ #include "config.h" @@ -15,37 +27,131 @@ #include "strerror_override.h" #include -#include +#ifdef HAVE_LIMITS_H +#include +#endif +#include +#include #include #include -#include #include -#include -#include "debug.h" -#include "printbuf.h" -#include "linkhash.h" #include "arraylist.h" +#include "debug.h" #include "json_inttypes.h" #include "json_object.h" #include "json_object_private.h" #include "json_util.h" +#include "linkhash.h" #include "math_compat.h" -#include "strdup_compat.h" +#include "printbuf.h" #include "snprintf_compat.h" +#include "strdup_compat.h" + +/* Avoid ctype.h and locale overhead */ +#define is_plain_digit(c) ((c) >= '0' && (c) <= '9') #if SIZEOF_LONG_LONG != SIZEOF_INT64_T -#error "The long long type isn't 64-bits" +#error The long long type is not 64-bits +#endif + +#ifndef SSIZE_T_MAX +#if SIZEOF_SSIZE_T == SIZEOF_INT +#define SSIZE_T_MAX INT_MAX +#elif SIZEOF_SSIZE_T == SIZEOF_LONG +#define SSIZE_T_MAX LONG_MAX +#elif SIZEOF_SSIZE_T == SIZEOF_LONG_LONG +#define SSIZE_T_MAX LLONG_MAX +#else +#error Unable to determine size of ssize_t +#endif #endif -// Don't define this. It's not thread-safe. -/* #define REFCOUNT_DEBUG 1 */ +const char *doca_third_party_json_number_chars = + "0123456789.+-eE"; /* Unused, but part of public API, drop for 1.0 */ +const char *doca_third_party_json_hex_chars = "0123456789abcdefABCDEF"; -const char *json_number_chars = "0123456789.+-eE"; -const char *json_hex_chars = "0123456789abcdefABCDEF"; +static void json_object_generic_delete(struct json_object *jso); -static void json_object_generic_delete(struct json_object* jso); -static struct json_object* json_object_new(enum json_type o_type); +#if defined(_MSC_VER) && (_MSC_VER <= 1800) +/* VS2013 doesn't know about "inline" */ +#define inline __inline +#elif defined(AIX_CC) +#define inline +#endif + +/* define colors */ +#define ANSI_COLOR_RESET "\033[0m" +#define ANSI_COLOR_FG_GREEN "\033[0;32m" +#define ANSI_COLOR_FG_BLUE "\033[0;34m" +#define ANSI_COLOR_FG_MAGENTA "\033[0;35m" + +/* + * Helper functions to more safely cast to a particular type of json_object + */ +static inline struct json_object_object *JC_OBJECT(struct json_object *jso) +{ + return (void *)jso; +} +static inline const struct json_object_object *JC_OBJECT_C(const struct json_object *jso) +{ + return (const void *)jso; +} +static inline struct json_object_array *JC_ARRAY(struct json_object *jso) +{ + return (void *)jso; +} +static inline const struct json_object_array *JC_ARRAY_C(const struct json_object *jso) +{ + return (const void *)jso; +} +static inline struct json_object_boolean *JC_BOOL(struct json_object *jso) +{ + return (void *)jso; +} +static inline const struct json_object_boolean *JC_BOOL_C(const struct json_object *jso) +{ + return (const void *)jso; +} +static inline struct json_object_double *JC_DOUBLE(struct json_object *jso) +{ + return (void *)jso; +} +static inline const struct json_object_double *JC_DOUBLE_C(const struct json_object *jso) +{ + return (const void *)jso; +} +static inline struct json_object_int *JC_INT(struct json_object *jso) +{ + return (void *)jso; +} +static inline const struct json_object_int *JC_INT_C(const struct json_object *jso) +{ + return (const void *)jso; +} +static inline struct json_object_string *JC_STRING(struct json_object *jso) +{ + return (void *)jso; +} +static inline const struct json_object_string *JC_STRING_C(const struct json_object *jso) +{ + return (const void *)jso; +} + +#define JC_CONCAT(a, b) a##b +#define JC_CONCAT3(a, b, c) a##b##c + +#define JSON_OBJECT_NEW(jtype) \ + (struct JC_CONCAT(json_object_, jtype) *)json_object_new( \ + JC_CONCAT(json_type_, jtype), sizeof(struct JC_CONCAT(json_object_, jtype)), \ + &JC_CONCAT3(json_object_, jtype, _to_json_string)) + +static inline struct json_object *json_object_new(enum json_type o_type, size_t alloc_size, + json_object_to_json_string_fn *to_json_string); + +static void json_object_object_delete(struct json_object *jso_base); +static void json_object_string_delete(struct json_object *jso); +static void json_object_array_delete(struct json_object *jso); static json_object_to_json_string_fn json_object_object_to_json_string; static json_object_to_json_string_fn json_object_boolean_to_json_string; @@ -53,64 +159,54 @@ static json_object_to_json_string_fn json_object_double_to_json_string_default; static json_object_to_json_string_fn json_object_int_to_json_string; static json_object_to_json_string_fn json_object_string_to_json_string; static json_object_to_json_string_fn json_object_array_to_json_string; +static json_object_to_json_string_fn _json_object_userdata_to_json_string; +#ifndef JSON_NORETURN +#if defined(_MSC_VER) +#define JSON_NORETURN __declspec(noreturn) +#elif defined(__OS400__) +#define JSON_NORETURN +#else +/* 'cold' attribute is for optimization, telling the computer this code + * path is unlikely. + */ +#define JSON_NORETURN __attribute__((noreturn, cold)) +#endif +#endif +/** + * Abort and optionally print a message on standard error. + * This should be used rather than assert() for unconditional abortion + * (in particular for code paths which are never supposed to be run). + * */ +JSON_NORETURN static void json_abort(const char *message); -/* ref count debugging */ - -#ifdef REFCOUNT_DEBUG - -static struct lh_table *json_object_table; - -static void json_object_init(void) __attribute__ ((constructor)); -static void json_object_init(void) { - MC_DEBUG("json_object_init: creating object table\n"); - json_object_table = lh_kptr_table_new(128, NULL); -} - -static void json_object_fini(void) __attribute__ ((destructor)); -static void json_object_fini(void) +/* helper for accessing the optimized string data component in json_object + */ +static inline char *get_string_component_mutable(struct json_object *jso) { - struct lh_entry *ent; - if (MC_GET_DEBUG()) + if (JC_STRING_C(jso)->len < 0) { - if (json_object_table->count) - { - MC_DEBUG("json_object_fini: %d referenced objects at exit\n", - json_object_table->count); - lh_foreach(json_object_table, ent) - { - struct json_object* obj = - (struct json_object*) lh_entry_v(ent); - MC_DEBUG("\t%s:%p\n", - json_type_to_name(obj->o_type), obj); - } - } + /* Due to json_object_set_string(), we might have a pointer */ + return JC_STRING(jso)->c_string.pdata; } - MC_DEBUG("json_object_fini: freeing object table\n"); - lh_table_free(json_object_table); + return JC_STRING(jso)->c_string.idata; } -#endif /* REFCOUNT_DEBUG */ - - -/* helper for accessing the optimized string data component in json_object - */ -static const char * -get_string_component(const struct json_object *jso) +static inline const char *get_string_component(const struct json_object *jso) { - return (jso->o.c_string.len < LEN_DIRECT_STRING_DATA) ? - jso->o.c_string.str.data : jso->o.c_string.str.ptr; + return get_string_component_mutable((void *)(uintptr_t)(const void *)jso); } /* string escaping */ -static int json_escape_str(struct printbuf *pb, const char *str, int len, int flags) +static int json_escape_str(struct printbuf *pb, const char *str, size_t len, int flags) { - int pos = 0, start_offset = 0; + size_t pos = 0, start_offset = 0; unsigned char c; - while (len--) + while (len) { + --len; c = str[pos]; - switch(c) + switch (c) { case '\b': case '\n': @@ -120,68 +216,78 @@ static int json_escape_str(struct printbuf *pb, const char *str, int len, int fl case '"': case '\\': case '/': - if((flags & JSON_C_TO_STRING_NOSLASHESCAPE) && c == '/') + if ((flags & JSON_C_TO_STRING_NOSLASHESCAPE) && c == '/') { pos++; break; } - if(pos - start_offset > 0) - printbuf_memappend(pb, str + start_offset, pos - start_offset); - - if(c == '\b') printbuf_memappend(pb, "\\b", 2); - else if(c == '\n') printbuf_memappend(pb, "\\n", 2); - else if(c == '\r') printbuf_memappend(pb, "\\r", 2); - else if(c == '\t') printbuf_memappend(pb, "\\t", 2); - else if(c == '\f') printbuf_memappend(pb, "\\f", 2); - else if(c == '"') printbuf_memappend(pb, "\\\"", 2); - else if(c == '\\') printbuf_memappend(pb, "\\\\", 2); - else if(c == '/') printbuf_memappend(pb, "\\/", 2); + if (pos > start_offset) + doca_third_party_printbuf_memappend(pb, str + start_offset, pos - start_offset); + + if (c == '\b') + doca_third_party_printbuf_memappend(pb, "\\b", 2); + else if (c == '\n') + doca_third_party_printbuf_memappend(pb, "\\n", 2); + else if (c == '\r') + doca_third_party_printbuf_memappend(pb, "\\r", 2); + else if (c == '\t') + doca_third_party_printbuf_memappend(pb, "\\t", 2); + else if (c == '\f') + doca_third_party_printbuf_memappend(pb, "\\f", 2); + else if (c == '"') + doca_third_party_printbuf_memappend(pb, "\\\"", 2); + else if (c == '\\') + doca_third_party_printbuf_memappend(pb, "\\\\", 2); + else if (c == '/') + doca_third_party_printbuf_memappend(pb, "\\/", 2); start_offset = ++pos; break; default: - if(c < ' ') + if (c < ' ') { char sbuf[7]; - if(pos - start_offset > 0) - printbuf_memappend(pb, - str + start_offset, - pos - start_offset); - snprintf(sbuf, sizeof(sbuf), - "\\u00%c%c", - json_hex_chars[c >> 4], - json_hex_chars[c & 0xf]); - printbuf_memappend_fast(pb, sbuf, (int) sizeof(sbuf) - 1); + if (pos > start_offset) + doca_third_party_printbuf_memappend(pb, str + start_offset, + pos - start_offset); + snprintf(sbuf, sizeof(sbuf), "\\u00%c%c", doca_third_party_json_hex_chars[c >> 4], + doca_third_party_json_hex_chars[c & 0xf]); + printbuf_memappend_fast(pb, sbuf, (int)sizeof(sbuf) - 1); start_offset = ++pos; - } else + } + else pos++; } } - if (pos - start_offset > 0) - printbuf_memappend(pb, str + start_offset, pos - start_offset); + if (pos > start_offset) + doca_third_party_printbuf_memappend(pb, str + start_offset, pos - start_offset); return 0; } - /* reference counting */ -extern struct json_object* json_object_get(struct json_object *jso) +struct json_object *doca_third_party_json_object_get(struct json_object *jso) { - if (!jso) return jso; + if (!jso) + return jso; + + // Don't overflow the refcounter. + assert(jso->_ref_count < UINT32_MAX); #if defined(HAVE_ATOMIC_BUILTINS) && defined(ENABLE_THREADING) __sync_add_and_fetch(&jso->_ref_count, 1); #else ++jso->_ref_count; -#endif +#endif return jso; } -int json_object_put(struct json_object *jso) +int doca_third_party_json_object_put(struct json_object *jso) { - if(!jso) return 0; + if (!jso) + return 0; /* Avoid invalid free and crash explicitly instead of (silently) * segfaulting. @@ -190,76 +296,80 @@ int json_object_put(struct json_object *jso) #if defined(HAVE_ATOMIC_BUILTINS) && defined(ENABLE_THREADING) /* Note: this only allow the refcount to remain correct - * when multiple threads are adjusting it. It is still an error + * when multiple threads are adjusting it. It is still an error * for a thread to decrement the refcount if it doesn't "own" it, * as that can result in the thread that loses the race to 0 * operating on an already-freed object. */ - if (__sync_sub_and_fetch(&jso->_ref_count, 1) > 0) return 0; + if (__sync_sub_and_fetch(&jso->_ref_count, 1) > 0) + return 0; #else - if (--jso->_ref_count > 0) return 0; + if (--jso->_ref_count > 0) + return 0; #endif if (jso->_user_delete) jso->_user_delete(jso, jso->_userdata); - jso->_delete(jso); + switch (jso->o_type) + { + case json_type_object: json_object_object_delete(jso); break; + case json_type_array: json_object_array_delete(jso); break; + case json_type_string: json_object_string_delete(jso); break; + default: json_object_generic_delete(jso); break; + } return 1; } - /* generic object construction and destruction parts */ -static void json_object_generic_delete(struct json_object* jso) +static void json_object_generic_delete(struct json_object *jso) { -#ifdef REFCOUNT_DEBUG - MC_DEBUG("json_object_delete_%s: %p\n", - json_type_to_name(jso->o_type), jso); - lh_table_delete(json_object_table, jso); -#endif /* REFCOUNT_DEBUG */ - printbuf_free(jso->_pb); + doca_third_party_printbuf_free(jso->_pb); free(jso); } -static struct json_object* json_object_new(enum json_type o_type) +static inline struct json_object *json_object_new(enum json_type o_type, size_t alloc_size, + json_object_to_json_string_fn *to_json_string) { struct json_object *jso; - jso = (struct json_object*)calloc(sizeof(struct json_object), 1); + jso = (struct json_object *)malloc(alloc_size); if (!jso) return NULL; + jso->o_type = o_type; jso->_ref_count = 1; - jso->_delete = &json_object_generic_delete; -#ifdef REFCOUNT_DEBUG - lh_table_insert(json_object_table, jso, jso); - MC_DEBUG("json_object_new_%s: %p\n", json_type_to_name(jso->o_type), jso); -#endif /* REFCOUNT_DEBUG */ + jso->_to_json_string = to_json_string; + jso->_pb = NULL; + jso->_user_delete = NULL; + jso->_userdata = NULL; + //jso->... // Type-specific fields must be set by caller + return jso; } - /* type checking functions */ -int json_object_is_type(const struct json_object *jso, enum json_type type) +int doca_third_party_json_object_is_type(const struct json_object *jso, enum json_type type) { if (!jso) return (type == json_type_null); return (jso->o_type == type); } -enum json_type json_object_get_type(const struct json_object *jso) +enum json_type doca_third_party_json_object_get_type(const struct json_object *jso) { if (!jso) return json_type_null; return jso->o_type; } -void* json_object_get_userdata(json_object *jso) { +void *doca_third_party_json_object_get_userdata(json_object *jso) +{ return jso ? jso->_userdata : NULL; } -void json_object_set_userdata(json_object *jso, void *userdata, - json_object_delete_fn *user_delete) +void doca_third_party_json_object_set_userdata(json_object *jso, void *userdata, json_object_delete_fn *user_delete) { // Can't return failure, so abort if we can't perform the operation. assert(jso != NULL); @@ -274,30 +384,24 @@ void json_object_set_userdata(json_object *jso, void *userdata, /* set a custom conversion to string */ -void json_object_set_serializer(json_object *jso, - json_object_to_json_string_fn *to_string_func, - void *userdata, - json_object_delete_fn *user_delete) +void doca_third_party_json_object_set_serializer(json_object *jso, json_object_to_json_string_fn *to_string_func, + void *userdata, json_object_delete_fn *user_delete) { - json_object_set_userdata(jso, userdata, user_delete); + doca_third_party_json_object_set_userdata(jso, userdata, user_delete); if (to_string_func == NULL) { // Reset to the standard serialization function - switch(jso->o_type) + switch (jso->o_type) { - case json_type_null: - jso->_to_json_string = NULL; - break; + case json_type_null: jso->_to_json_string = NULL; break; case json_type_boolean: jso->_to_json_string = &json_object_boolean_to_json_string; break; case json_type_double: jso->_to_json_string = &json_object_double_to_json_string_default; break; - case json_type_int: - jso->_to_json_string = &json_object_int_to_json_string; - break; + case json_type_int: jso->_to_json_string = &json_object_int_to_json_string; break; case json_type_object: jso->_to_json_string = &json_object_object_to_json_string; break; @@ -314,10 +418,9 @@ void json_object_set_serializer(json_object *jso, jso->_to_json_string = to_string_func; } - /* extended conversion to string */ -const char* json_object_to_json_string_length(struct json_object *jso, int flags, size_t *length) +const char *doca_third_party_json_object_to_json_string_length(struct json_object *jso, int flags, size_t *length) { const char *r = NULL; size_t s = 0; @@ -327,11 +430,11 @@ const char* json_object_to_json_string_length(struct json_object *jso, int flags s = 4; r = "null"; } - else if ((jso->_pb) || (jso->_pb = printbuf_new())) + else if ((jso->_pb) || (jso->_pb = doca_third_party_printbuf_new())) { - printbuf_reset(jso->_pb); + doca_third_party_printbuf_reset(jso->_pb); - if(jso->_to_json_string(jso, jso->_pb, 0, flags) >= 0) + if (jso->_to_json_string(jso, jso->_pb, 0, flags) >= 0) { s = (size_t)jso->_pb->bpos; r = jso->_pb->buf; @@ -343,16 +446,16 @@ const char* json_object_to_json_string_length(struct json_object *jso, int flags return r; } -const char* json_object_to_json_string_ext(struct json_object *jso, int flags) +const char *doca_third_party_json_object_to_json_string_ext(struct json_object *jso, int flags) { - return json_object_to_json_string_length(jso, flags, NULL); + return doca_third_party_json_object_to_json_string_length(jso, flags, NULL); } /* backwards-compatible conversion to string */ -const char* json_object_to_json_string(struct json_object *jso) +const char *doca_third_party_json_object_to_json_string(struct json_object *jso) { - return json_object_to_json_string_ext(jso, JSON_C_TO_STRING_SPACED); + return doca_third_party_json_object_to_json_string_ext(jso, JSON_C_TO_STRING_SPACED); } static void indent(struct printbuf *pb, int level, int flags) @@ -361,126 +464,127 @@ static void indent(struct printbuf *pb, int level, int flags) { if (flags & JSON_C_TO_STRING_PRETTY_TAB) { - printbuf_memset(pb, -1, '\t', level); + doca_third_party_printbuf_memset(pb, -1, '\t', level); } else { - printbuf_memset(pb, -1, ' ', level * 2); + doca_third_party_printbuf_memset(pb, -1, ' ', level * 2); } } } /* json_object_object */ -static int json_object_object_to_json_string(struct json_object* jso, - struct printbuf *pb, - int level, - int flags) +static int json_object_object_to_json_string(struct json_object *jso, struct printbuf *pb, + int level, int flags) { int had_children = 0; struct json_object_iter iter; printbuf_strappend(pb, "{" /*}*/); - if (flags & JSON_C_TO_STRING_PRETTY) - printbuf_strappend(pb, "\n"); - json_object_object_foreachC(jso, iter) + doca_third_party_json_object_object_foreachC(jso, iter) { if (had_children) { printbuf_strappend(pb, ","); - if (flags & JSON_C_TO_STRING_PRETTY) - printbuf_strappend(pb, "\n"); } + if (flags & JSON_C_TO_STRING_PRETTY) + printbuf_strappend(pb, "\n"); had_children = 1; - if (flags & JSON_C_TO_STRING_SPACED) + if (flags & JSON_C_TO_STRING_SPACED && !(flags & JSON_C_TO_STRING_PRETTY)) printbuf_strappend(pb, " "); - indent(pb, level+1, flags); + indent(pb, level + 1, flags); + if (flags & JSON_C_TO_STRING_COLOR) + printbuf_strappend(pb, ANSI_COLOR_FG_BLUE); + printbuf_strappend(pb, "\""); json_escape_str(pb, iter.key, strlen(iter.key), flags); + printbuf_strappend(pb, "\""); + + if (flags & JSON_C_TO_STRING_COLOR) + printbuf_strappend(pb, ANSI_COLOR_RESET); + if (flags & JSON_C_TO_STRING_SPACED) - printbuf_strappend(pb, "\": "); + printbuf_strappend(pb, ": "); else - printbuf_strappend(pb, "\":"); - if(iter.val == NULL) + printbuf_strappend(pb, ":"); + + if (iter.val == NULL) { + if (flags & JSON_C_TO_STRING_COLOR) + printbuf_strappend(pb, ANSI_COLOR_FG_MAGENTA); printbuf_strappend(pb, "null"); - else - if (iter.val->_to_json_string(iter.val, pb, level+1,flags) < 0) - return -1; + if (flags & JSON_C_TO_STRING_COLOR) + printbuf_strappend(pb, ANSI_COLOR_RESET); + } else if (iter.val->_to_json_string(iter.val, pb, level + 1, flags) < 0) + return -1; } - if (flags & JSON_C_TO_STRING_PRETTY) + if ((flags & JSON_C_TO_STRING_PRETTY) && had_children) { - if (had_children) - printbuf_strappend(pb, "\n"); - indent(pb,level,flags); + printbuf_strappend(pb, "\n"); + indent(pb, level, flags); } - if (flags & JSON_C_TO_STRING_SPACED) + if (flags & JSON_C_TO_STRING_SPACED && !(flags & JSON_C_TO_STRING_PRETTY)) return printbuf_strappend(pb, /*{*/ " }"); else return printbuf_strappend(pb, /*{*/ "}"); } - static void json_object_lh_entry_free(struct lh_entry *ent) { - if (!ent->k_is_constant) + if (!lh_entry_k_is_constant(ent)) free(lh_entry_k(ent)); - json_object_put((struct json_object*)lh_entry_v(ent)); + doca_third_party_json_object_put((struct json_object *)lh_entry_v(ent)); } -static void json_object_object_delete(struct json_object* jso) +static void json_object_object_delete(struct json_object *jso_base) { - lh_table_free(jso->o.c_object); - json_object_generic_delete(jso); + doca_third_party_lh_table_free(JC_OBJECT(jso_base)->c_object); + json_object_generic_delete(jso_base); } -struct json_object* json_object_new_object(void) +struct json_object *doca_third_party_json_object_new_object(void) { - struct json_object *jso = json_object_new(json_type_object); + struct json_object_object *jso = JSON_OBJECT_NEW(object); if (!jso) return NULL; - jso->_delete = &json_object_object_delete; - jso->_to_json_string = &json_object_object_to_json_string; - jso->o.c_object = lh_kchar_table_new(JSON_OBJECT_DEF_HASH_ENTRIES, - &json_object_lh_entry_free); - if (!jso->o.c_object) + jso->c_object = + doca_third_party_lh_kchar_table_new(JSON_OBJECT_DEF_HASH_ENTRIES, &json_object_lh_entry_free); + if (!jso->c_object) { - json_object_generic_delete(jso); + json_object_generic_delete(&jso->base); errno = ENOMEM; return NULL; } - return jso; + return &jso->base; } -struct lh_table* json_object_get_object(const struct json_object *jso) +struct lh_table *doca_third_party_json_object_get_object(const struct json_object *jso) { if (!jso) return NULL; - switch(jso->o_type) + switch (jso->o_type) { - case json_type_object: - return jso->o.c_object; - default: - return NULL; + case json_type_object: return JC_OBJECT_C(jso)->c_object; + default: return NULL; } } -int json_object_object_add_ex(struct json_object* jso, - const char *const key, - struct json_object *const val, - const unsigned opts) +int doca_third_party_json_object_object_add_ex(struct json_object *jso, const char *const key, + struct json_object *const val, const unsigned opts) { struct json_object *existing_value = NULL; struct lh_entry *existing_entry; unsigned long hash; - assert(json_object_get_type(jso) == json_type_object); + assert(doca_third_party_json_object_get_type(jso) == json_type_object); // We lookup the entry and replace the value, rather than just deleting // and re-adding it, so the existing key remains valid. - hash = lh_get_hash(jso->o.c_object, (const void *)key); - existing_entry = (opts & JSON_C_OBJECT_ADD_KEY_IS_NEW) ? NULL : - lh_table_lookup_entry_w_hash(jso->o.c_object, - (const void *)key, hash); + hash = lh_get_hash(JC_OBJECT(jso)->c_object, (const void *)key); + existing_entry = + (opts & JSON_C_OBJECT_ADD_KEY_IS_NEW) + ? NULL + : doca_third_party_lh_table_lookup_entry_w_hash(JC_OBJECT(jso)->c_object, (const void *)key, hash); // The caller must avoid creating loops in the object tree, but do a // quick check anyway to make sure we're not creating a trivial loop. @@ -489,251 +593,366 @@ int json_object_object_add_ex(struct json_object* jso, if (!existing_entry) { - const void *const k = (opts & JSON_C_OBJECT_KEY_IS_CONSTANT) ? - (const void *)key : strdup(key); + const void *const k = + (opts & JSON_C_OBJECT_ADD_CONSTANT_KEY) ? (const void *)key : strdup(key); if (k == NULL) return -1; - return lh_table_insert_w_hash(jso->o.c_object, k, val, hash, opts); + return doca_third_party_lh_table_insert_w_hash(JC_OBJECT(jso)->c_object, k, val, hash, opts); } - existing_value = (json_object *) lh_entry_v(existing_entry); + existing_value = (json_object *)lh_entry_v(existing_entry); if (existing_value) - json_object_put(existing_value); - existing_entry->v = val; + doca_third_party_json_object_put(existing_value); + lh_entry_set_val(existing_entry, val); return 0; } -int json_object_object_add(struct json_object* jso, const char *key, - struct json_object *val) +int doca_third_party_json_object_object_add(struct json_object *jso, const char *key, struct json_object *val) { - return json_object_object_add_ex(jso, key, val, 0); + return doca_third_party_json_object_object_add_ex(jso, key, val, 0); } - -int json_object_object_length(const struct json_object *jso) +int doca_third_party_json_object_object_length(const struct json_object *jso) { - assert(json_object_get_type(jso) == json_type_object); - return lh_table_length(jso->o.c_object); + assert(doca_third_party_json_object_get_type(jso) == json_type_object); + return doca_third_party_lh_table_length(JC_OBJECT_C(jso)->c_object); } -size_t json_c_object_sizeof(void) +size_t doca_third_party_json_c_object_sizeof(void) { return sizeof(struct json_object); } -struct json_object* json_object_object_get(const struct json_object* jso, - const char *key) +struct json_object *doca_third_party_json_object_object_get(const struct json_object *jso, const char *key) { struct json_object *result = NULL; - json_object_object_get_ex(jso, key, &result); + doca_third_party_json_object_object_get_ex(jso, key, &result); return result; } -json_bool json_object_object_get_ex(const struct json_object* jso, const char *key, - struct json_object **value) +json_bool doca_third_party_json_object_object_get_ex(const struct json_object *jso, const char *key, + struct json_object **value) { if (value != NULL) *value = NULL; if (NULL == jso) - return FALSE; + return 0; - switch(jso->o_type) + switch (jso->o_type) { case json_type_object: - return lh_table_lookup_ex(jso->o.c_object, (const void *) key, - (void**) value); + return doca_third_party_lh_table_lookup_ex(JC_OBJECT_C(jso)->c_object, (const void *)key, + (void **)value); default: if (value != NULL) *value = NULL; - return FALSE; + return 0; } } -void json_object_object_del(struct json_object* jso, const char *key) +void doca_third_party_json_object_object_del(struct json_object *jso, const char *key) { - assert(json_object_get_type(jso) == json_type_object); - lh_table_delete(jso->o.c_object, key); + assert(doca_third_party_json_object_get_type(jso) == json_type_object); + doca_third_party_lh_table_delete(JC_OBJECT(jso)->c_object, key); } - /* json_object_boolean */ -static int json_object_boolean_to_json_string(struct json_object* jso, - struct printbuf *pb, - int level, - int flags) +static int json_object_boolean_to_json_string(struct json_object *jso, struct printbuf *pb, + int level, int flags) { - if (jso->o.c_boolean) - return printbuf_strappend(pb, "true"); - return printbuf_strappend(pb, "false"); + int ret; + + if (flags & JSON_C_TO_STRING_COLOR) + printbuf_strappend(pb, ANSI_COLOR_FG_MAGENTA); + + if (JC_BOOL(jso)->c_boolean) + ret = printbuf_strappend(pb, "true"); + else + ret = printbuf_strappend(pb, "false"); + if (ret > -1 && flags & JSON_C_TO_STRING_COLOR) + return printbuf_strappend(pb, ANSI_COLOR_RESET); + return ret; } -struct json_object* json_object_new_boolean(json_bool b) +struct json_object *doca_third_party_json_object_new_boolean(json_bool b) { - struct json_object *jso = json_object_new(json_type_boolean); + struct json_object_boolean *jso = JSON_OBJECT_NEW(boolean); if (!jso) return NULL; - jso->_to_json_string = &json_object_boolean_to_json_string; - jso->o.c_boolean = b; - return jso; + jso->c_boolean = b; + return &jso->base; } -json_bool json_object_get_boolean(const struct json_object *jso) +json_bool doca_third_party_json_object_get_boolean(const struct json_object *jso) { if (!jso) - return FALSE; - switch(jso->o_type) + return 0; + switch (jso->o_type) { - case json_type_boolean: - return jso->o.c_boolean; + case json_type_boolean: return JC_BOOL_C(jso)->c_boolean; case json_type_int: - return (jso->o.c_int64 != 0); - case json_type_double: - return (jso->o.c_double != 0); - case json_type_string: - return (jso->o.c_string.len != 0); - default: - return FALSE; + switch (JC_INT_C(jso)->cint_type) + { + case json_object_int_type_int64: return (JC_INT_C(jso)->cint.c_int64 != 0); + case json_object_int_type_uint64: return (JC_INT_C(jso)->cint.c_uint64 != 0); + default: json_abort("invalid cint_type"); + } + case json_type_double: return (JC_DOUBLE_C(jso)->c_double != 0); + case json_type_string: return (JC_STRING_C(jso)->len != 0); + default: return 0; } } -int json_object_set_boolean(struct json_object *jso,json_bool new_value){ - if (!jso || jso->o_type!=json_type_boolean) +int doca_third_party_json_object_set_boolean(struct json_object *jso, json_bool new_value) +{ + if (!jso || jso->o_type != json_type_boolean) return 0; - jso->o.c_boolean=new_value; + JC_BOOL(jso)->c_boolean = new_value; return 1; } - /* json_object_int */ -static int json_object_int_to_json_string(struct json_object* jso, - struct printbuf *pb, - int level, - int flags) +static int json_object_int_to_json_string(struct json_object *jso, struct printbuf *pb, int level, + int flags) { /* room for 19 digits, the sign char, and a null term */ char sbuf[21]; - snprintf(sbuf, sizeof(sbuf), "%" PRId64, jso->o.c_int64); - return printbuf_memappend (pb, sbuf, strlen(sbuf)); + if (JC_INT(jso)->cint_type == json_object_int_type_int64) + snprintf(sbuf, sizeof(sbuf), "%" PRId64, JC_INT(jso)->cint.c_int64); + else + snprintf(sbuf, sizeof(sbuf), "%" PRIu64, JC_INT(jso)->cint.c_uint64); + return doca_third_party_printbuf_memappend(pb, sbuf, strlen(sbuf)); } -struct json_object* json_object_new_int(int32_t i) +struct json_object *doca_third_party_json_object_new_int(int32_t i) { - struct json_object *jso = json_object_new(json_type_int); - if (!jso) - return NULL; - jso->_to_json_string = &json_object_int_to_json_string; - jso->o.c_int64 = i; - return jso; + return doca_third_party_json_object_new_int64(i); } -int32_t json_object_get_int(const struct json_object *jso) +int32_t doca_third_party_json_object_get_int(const struct json_object *jso) { - int64_t cint64; - enum json_type o_type; + int64_t cint64 = 0; + double cdouble; + enum json_type o_type; - if(!jso) return 0; + if (!jso) + return 0; - o_type = jso->o_type; - cint64 = jso->o.c_int64; + o_type = jso->o_type; + if (o_type == json_type_int) + { + const struct json_object_int *jsoint = JC_INT_C(jso); + if (jsoint->cint_type == json_object_int_type_int64) + { + cint64 = jsoint->cint.c_int64; + } + else + { + if (jsoint->cint.c_uint64 >= INT64_MAX) + cint64 = INT64_MAX; + else + cint64 = (int64_t)jsoint->cint.c_uint64; + } + } + else if (o_type == json_type_string) + { + /* + * Parse strings into 64-bit numbers, then use the + * 64-to-32-bit number handling below. + */ + if (doca_third_party_json_parse_int64(get_string_component(jso), &cint64) != 0) + return 0; /* whoops, it didn't work. */ + o_type = json_type_int; + } - if (o_type == json_type_string) - { - /* - * Parse strings into 64-bit numbers, then use the - * 64-to-32-bit number handling below. - */ - if (json_parse_int64(get_string_component(jso), &cint64) != 0) - return 0; /* whoops, it didn't work. */ - o_type = json_type_int; - } - - switch(o_type) { - case json_type_int: - /* Make sure we return the correct values for out of range numbers. */ - if (cint64 <= INT32_MIN) - return INT32_MIN; - if (cint64 >= INT32_MAX) - return INT32_MAX; - return (int32_t) cint64; - case json_type_double: - if (jso->o.c_double <= INT32_MIN) - return INT32_MIN; - if (jso->o.c_double >= INT32_MAX) - return INT32_MAX; - return (int32_t)jso->o.c_double; - case json_type_boolean: - return jso->o.c_boolean; - default: - return 0; - } -} - -int json_object_set_int(struct json_object *jso,int new_value){ - if (!jso || jso->o_type!=json_type_int) - return 0; - jso->o.c_int64=new_value; - return 1; + switch (o_type) + { + case json_type_int: + /* Make sure we return the correct values for out of range numbers. */ + if (cint64 <= INT32_MIN) + return INT32_MIN; + if (cint64 >= INT32_MAX) + return INT32_MAX; + return (int32_t)cint64; + case json_type_double: + cdouble = JC_DOUBLE_C(jso)->c_double; + if (cdouble <= INT32_MIN) + return INT32_MIN; + if (cdouble >= INT32_MAX) + return INT32_MAX; + return (int32_t)cdouble; + case json_type_boolean: return JC_BOOL_C(jso)->c_boolean; + default: return 0; + } } -struct json_object* json_object_new_int64(int64_t i) +int doca_third_party_json_object_set_int(struct json_object *jso, int new_value) { - struct json_object *jso = json_object_new(json_type_int); + return doca_third_party_json_object_set_int64(jso, (int64_t)new_value); +} + +struct json_object *doca_third_party_json_object_new_int64(int64_t i) +{ + struct json_object_int *jso = JSON_OBJECT_NEW(int); if (!jso) return NULL; - jso->_to_json_string = &json_object_int_to_json_string; - jso->o.c_int64 = i; - return jso; + jso->cint.c_int64 = i; + jso->cint_type = json_object_int_type_int64; + return &jso->base; +} + +struct json_object *doca_third_party_json_object_new_uint64(uint64_t i) +{ + struct json_object_int *jso = JSON_OBJECT_NEW(int); + if (!jso) + return NULL; + jso->cint.c_uint64 = i; + jso->cint_type = json_object_int_type_uint64; + return &jso->base; } -int64_t json_object_get_int64(const struct json_object *jso) +int64_t doca_third_party_json_object_get_int64(const struct json_object *jso) { int64_t cint; if (!jso) return 0; - switch(jso->o_type) + switch (jso->o_type) { case json_type_int: - return jso->o.c_int64; + { + const struct json_object_int *jsoint = JC_INT_C(jso); + switch (jsoint->cint_type) + { + case json_object_int_type_int64: return jsoint->cint.c_int64; + case json_object_int_type_uint64: + if (jsoint->cint.c_uint64 >= INT64_MAX) + return INT64_MAX; + return (int64_t)jsoint->cint.c_uint64; + default: json_abort("invalid cint_type"); + } + } case json_type_double: - if (jso->o.c_double >= (double)INT64_MAX) + // INT64_MAX can't be exactly represented as a double + // so cast to tell the compiler it's ok to round up. + if (JC_DOUBLE_C(jso)->c_double >= (double)INT64_MAX) return INT64_MAX; - if (jso->o.c_double <= (double)INT64_MIN) + if (JC_DOUBLE_C(jso)->c_double <= INT64_MIN) return INT64_MIN; - return (int64_t)jso->o.c_double; - case json_type_boolean: - return jso->o.c_boolean; + return (int64_t)JC_DOUBLE_C(jso)->c_double; + case json_type_boolean: return JC_BOOL_C(jso)->c_boolean; case json_type_string: - if (json_parse_int64(get_string_component(jso), &cint) == 0) + if (doca_third_party_json_parse_int64(get_string_component(jso), &cint) == 0) return cint; /* FALLTHRU */ - default: + default: return 0; + } +} + +uint64_t doca_third_party_json_object_get_uint64(const struct json_object *jso) +{ + uint64_t cuint; + + if (!jso) return 0; + switch (jso->o_type) + { + case json_type_int: + { + const struct json_object_int *jsoint = JC_INT_C(jso); + switch (jsoint->cint_type) + { + case json_object_int_type_int64: + if (jsoint->cint.c_int64 < 0) + return 0; + return (uint64_t)jsoint->cint.c_int64; + case json_object_int_type_uint64: return jsoint->cint.c_uint64; + default: json_abort("invalid cint_type"); + } + } + case json_type_double: + // UINT64_MAX can't be exactly represented as a double + // so cast to tell the compiler it's ok to round up. + if (JC_DOUBLE_C(jso)->c_double >= (double)UINT64_MAX) + return UINT64_MAX; + if (JC_DOUBLE_C(jso)->c_double < 0) + return 0; + return (uint64_t)JC_DOUBLE_C(jso)->c_double; + case json_type_boolean: return JC_BOOL_C(jso)->c_boolean; + case json_type_string: + if (doca_third_party_json_parse_uint64(get_string_component(jso), &cuint) == 0) + return cuint; + /* FALLTHRU */ + default: return 0; } } -int json_object_set_int64(struct json_object *jso,int64_t new_value){ - if (!jso || jso->o_type!=json_type_int) +int doca_third_party_json_object_set_int64(struct json_object *jso, int64_t new_value) +{ + if (!jso || jso->o_type != json_type_int) return 0; - jso->o.c_int64=new_value; + JC_INT(jso)->cint.c_int64 = new_value; + JC_INT(jso)->cint_type = json_object_int_type_int64; return 1; } -int json_object_int_inc(struct json_object *jso, int64_t val) { +int doca_third_party_json_object_set_uint64(struct json_object *jso, uint64_t new_value) +{ if (!jso || jso->o_type != json_type_int) return 0; - if (val > 0 && jso->o.c_int64 > INT64_MAX - val) { - jso->o.c_int64 = INT64_MAX; - } else if (val < 0 && jso->o.c_int64 < INT64_MIN - val) { - jso->o.c_int64 = INT64_MIN; - } else { - jso->o.c_int64 += val; - } + JC_INT(jso)->cint.c_uint64 = new_value; + JC_INT(jso)->cint_type = json_object_int_type_uint64; return 1; } +int doca_third_party_json_object_int_inc(struct json_object *jso, int64_t val) +{ + struct json_object_int *jsoint; + if (!jso || jso->o_type != json_type_int) + return 0; + jsoint = JC_INT(jso); + switch (jsoint->cint_type) + { + case json_object_int_type_int64: + if (val > 0 && jsoint->cint.c_int64 > INT64_MAX - val) + { + jsoint->cint.c_uint64 = (uint64_t)jsoint->cint.c_int64 + (uint64_t)val; + jsoint->cint_type = json_object_int_type_uint64; + } + else if (val < 0 && jsoint->cint.c_int64 < INT64_MIN - val) + { + jsoint->cint.c_int64 = INT64_MIN; + } + else + { + jsoint->cint.c_int64 += val; + } + return 1; + case json_object_int_type_uint64: + if (val > 0 && jsoint->cint.c_uint64 > UINT64_MAX - (uint64_t)val) + { + jsoint->cint.c_uint64 = UINT64_MAX; + } + else if (val < 0 && jsoint->cint.c_uint64 < (uint64_t)(-val)) + { + jsoint->cint.c_int64 = (int64_t)jsoint->cint.c_uint64 + val; + jsoint->cint_type = json_object_int_type_int64; + } + else if (val < 0 && jsoint->cint.c_uint64 >= (uint64_t)(-val)) + { + jsoint->cint.c_uint64 -= (uint64_t)(-val); + } + else + { + jsoint->cint.c_uint64 += val; + } + return 1; + default: json_abort("invalid cint_type"); + } +} + /* json_object_double */ #if defined(HAVE___THREAD) @@ -742,7 +961,7 @@ static SPEC___THREAD char *tls_serialization_float_format = NULL; #endif static char *global_serialization_float_format = NULL; -int json_c_set_serialization_double_format(const char *double_format, int global_or_thread) +int doca_third_party_json_c_set_serialization_double_format(const char *double_format, int global_or_thread) { if (global_or_thread == JSON_C_OPTION_GLOBAL) { @@ -755,7 +974,21 @@ int json_c_set_serialization_double_format(const char *double_format, int global #endif if (global_serialization_float_format) free(global_serialization_float_format); - global_serialization_float_format = double_format ? strdup(double_format) : NULL; + if (double_format) + { + char *p = strdup(double_format); + if (p == NULL) + { + doca_third_party__json_c_set_last_err("json_c_set_serialization_double_format: " + "out of memory\n"); + return -1; + } + global_serialization_float_format = p; + } + else + { + global_serialization_float_format = NULL; + } } else if (global_or_thread == JSON_C_OPTION_THREAD) { @@ -765,40 +998,54 @@ int json_c_set_serialization_double_format(const char *double_format, int global free(tls_serialization_float_format); tls_serialization_float_format = NULL; } - tls_serialization_float_format = double_format ? strdup(double_format) : NULL; + if (double_format) + { + char *p = strdup(double_format); + if (p == NULL) + { + doca_third_party__json_c_set_last_err("json_c_set_serialization_double_format: " + "out of memory\n"); + return -1; + } + tls_serialization_float_format = p; + } + else + { + tls_serialization_float_format = NULL; + } #else - _json_c_set_last_err("json_c_set_option: not compiled with __thread support\n"); + doca_third_party__json_c_set_last_err("json_c_set_serialization_double_format: not compiled " + "with __thread support\n"); return -1; #endif } else { - _json_c_set_last_err("json_c_set_option: invalid global_or_thread value: %d\n", global_or_thread); + doca_third_party__json_c_set_last_err("json_c_set_serialization_double_format: invalid " + "global_or_thread value: %d\n", global_or_thread); return -1; } return 0; } - -static int json_object_double_to_json_string_format(struct json_object* jso, - struct printbuf *pb, - int level, - int flags, - const char *format) +static int json_object_double_to_json_string_format(struct json_object *jso, struct printbuf *pb, + int level, int flags, const char *format) { + struct json_object_double *jsodbl = JC_DOUBLE(jso); char buf[128], *p, *q; int size; /* Although JSON RFC does not support - NaN or Infinity as numeric values - ECMA 262 section 9.8.1 defines - how to handle these cases as strings */ - if (isnan(jso->o.c_double)) + * NaN or Infinity as numeric values + * ECMA 262 section 9.8.1 defines + * how to handle these cases as strings + */ + if (isnan(jsodbl->c_double)) { size = snprintf(buf, sizeof(buf), "NaN"); } - else if (isinf(jso->o.c_double)) + else if (isinf(jsodbl->c_double)) { - if(jso->o.c_double > 0) + if (jsodbl->c_double > 0) size = snprintf(buf, sizeof(buf), "Infinity"); else size = snprintf(buf, sizeof(buf), "-Infinity"); @@ -807,6 +1054,7 @@ static int json_object_double_to_json_string_format(struct json_object* jso, { const char *std_format = "%.17g"; int format_drops_decimals = 0; + int looks_numeric = 0; if (!format) { @@ -815,12 +1063,12 @@ static int json_object_double_to_json_string_format(struct json_object* jso, format = tls_serialization_float_format; else #endif - if (global_serialization_float_format) + if (global_serialization_float_format) format = global_serialization_float_format; else format = std_format; } - size = snprintf(buf, sizeof(buf), format, jso->o.c_double); + size = snprintf(buf, sizeof(buf), format, jsodbl->c_double); if (size < 0) return -1; @@ -834,11 +1082,12 @@ static int json_object_double_to_json_string_format(struct json_object* jso, if (format == std_format || strstr(format, ".0f") == NULL) format_drops_decimals = 1; - if (size < (int)sizeof(buf) - 2 && - isdigit((int)buf[0]) && /* Looks like *some* kind of number */ - !p && /* Has no decimal point */ + looks_numeric = /* Looks like *some* kind of number */ + is_plain_digit(buf[0]) || (size > 1 && buf[0] == '-' && is_plain_digit(buf[1])); + + if (size < (int)sizeof(buf) - 2 && looks_numeric && !p && /* Has no decimal point */ strchr(buf, 'e') == NULL && /* Not scientific notation */ - format_drops_decimals) + format_drops_decimals) { // Ensure it looks like a float, even if snprintf didn't, // unless a custom format is set to omit the decimal. @@ -849,12 +1098,15 @@ static int json_object_double_to_json_string_format(struct json_object* jso, { /* last useful digit, always keep 1 zero */ p++; - for (q=p ; *q ; q++) { - if (*q!='0') p=q; + for (q = p; *q; q++) + { + if (*q != '0') + p = q; } /* drop trailing zeroes */ - *(++p) = 0; - size = p-buf; + if (*p != 0) + *(++p) = 0; + size = p - buf; } } // although unlikely, snprintf can fail @@ -865,42 +1117,43 @@ static int json_object_double_to_json_string_format(struct json_object* jso, // The standard formats are guaranteed not to overrun the buffer, // but if a custom one happens to do so, just silently truncate. size = sizeof(buf) - 1; - printbuf_memappend(pb, buf, size); + doca_third_party_printbuf_memappend(pb, buf, size); return size; } -static int json_object_double_to_json_string_default(struct json_object* jso, - struct printbuf *pb, - int level, - int flags) +static int json_object_double_to_json_string_default(struct json_object *jso, struct printbuf *pb, + int level, int flags) { - return json_object_double_to_json_string_format(jso, pb, level, flags, - NULL); + return json_object_double_to_json_string_format(jso, pb, level, flags, NULL); +} + +static int json_object_double_to_json_string(struct json_object *jso, struct printbuf *pb, int level, + int flags) +{ + return doca_third_party_json_object_double_to_json_string(jso, pb, level, flags); } -int json_object_double_to_json_string(struct json_object* jso, - struct printbuf *pb, - int level, - int flags) +int doca_third_party_json_object_double_to_json_string(struct json_object *jso, struct printbuf *pb, int level, + int flags) { return json_object_double_to_json_string_format(jso, pb, level, flags, - (const char *)jso->_userdata); + (const char *)jso->_userdata); } -struct json_object* json_object_new_double(double d) +struct json_object *doca_third_party_json_object_new_double(double d) { - struct json_object *jso = json_object_new(json_type_double); + struct json_object_double *jso = JSON_OBJECT_NEW(double); if (!jso) return NULL; - jso->_to_json_string = &json_object_double_to_json_string_default; - jso->o.c_double = d; - return jso; + jso->base._to_json_string = &json_object_double_to_json_string_default; + jso->c_double = d; + return &jso->base; } -struct json_object* json_object_new_double_s(double d, const char *ds) +struct json_object *doca_third_party_json_object_new_double_s(double d, const char *ds) { char *new_ds; - struct json_object *jso = json_object_new_double(d); + struct json_object *jso = doca_third_party_json_object_new_double(d); if (!jso) return NULL; @@ -911,381 +1164,465 @@ struct json_object* json_object_new_double_s(double d, const char *ds) errno = ENOMEM; return NULL; } - json_object_set_serializer(jso, json_object_userdata_to_json_string, - new_ds, json_object_free_userdata); + doca_third_party_json_object_set_serializer(jso, _json_object_userdata_to_json_string, new_ds, + doca_third_party_json_object_free_userdata); return jso; } -int json_object_userdata_to_json_string(struct json_object *jso, - struct printbuf *pb, int level, int flags) +/* + * A wrapper around json_object_userdata_to_json_string() used only + * by json_object_new_double_s() just so json_object_set_double() can + * detect when it needs to reset the serializer to the default. + */ +static int _json_object_userdata_to_json_string(struct json_object *jso, struct printbuf *pb, + int level, int flags) +{ + return doca_third_party_json_object_userdata_to_json_string(jso, pb, level, flags); +} + +int doca_third_party_json_object_userdata_to_json_string(struct json_object *jso, struct printbuf *pb, int level, + int flags) { int userdata_len = strlen((const char *)jso->_userdata); - printbuf_memappend(pb, (const char *)jso->_userdata, userdata_len); + doca_third_party_printbuf_memappend(pb, (const char *)jso->_userdata, userdata_len); return userdata_len; } -void json_object_free_userdata(struct json_object *jso, void *userdata) +void doca_third_party_json_object_free_userdata(struct json_object *jso, void *userdata) { free(userdata); } -double json_object_get_double(const struct json_object *jso) -{ - double cdouble; - char *errPtr = NULL; - - if(!jso) return 0.0; - switch(jso->o_type) { - case json_type_double: - return jso->o.c_double; - case json_type_int: - return jso->o.c_int64; - case json_type_boolean: - return jso->o.c_boolean; - case json_type_string: - errno = 0; - cdouble = strtod(get_string_component(jso), &errPtr); - - /* if conversion stopped at the first character, return 0.0 */ - if (errPtr == get_string_component(jso)) - return 0.0; - - /* - * Check that the conversion terminated on something sensible - * - * For example, { "pay" : 123AB } would parse as 123. - */ - if (*errPtr != '\0') - return 0.0; - - /* - * If strtod encounters a string which would exceed the - * capacity of a double, it returns +/- HUGE_VAL and sets - * errno to ERANGE. But +/- HUGE_VAL is also a valid result - * from a conversion, so we need to check errno. - * - * Underflow also sets errno to ERANGE, but it returns 0 in - * that case, which is what we will return anyway. - * - * See CERT guideline ERR30-C - */ - if ((HUGE_VAL == cdouble || -HUGE_VAL == cdouble) && - (ERANGE == errno)) - cdouble = 0.0; - return cdouble; - default: - return 0.0; - } -} - -int json_object_set_double(struct json_object *jso,double new_value){ - if (!jso || jso->o_type!=json_type_double) +double doca_third_party_json_object_get_double(const struct json_object *jso) +{ + double cdouble; + char *errPtr = NULL; + + if (!jso) + return 0.0; + switch (jso->o_type) + { + case json_type_double: return JC_DOUBLE_C(jso)->c_double; + case json_type_int: + switch (JC_INT_C(jso)->cint_type) + { + case json_object_int_type_int64: return JC_INT_C(jso)->cint.c_int64; + case json_object_int_type_uint64: return JC_INT_C(jso)->cint.c_uint64; + default: json_abort("invalid cint_type"); + } + case json_type_boolean: return JC_BOOL_C(jso)->c_boolean; + case json_type_string: + errno = 0; + cdouble = strtod(get_string_component(jso), &errPtr); + + /* if conversion stopped at the first character, return 0.0 */ + if (errPtr == get_string_component(jso)) + { + errno = EINVAL; + return 0.0; + } + + /* + * Check that the conversion terminated on something sensible + * + * For example, { "pay" : 123AB } would parse as 123. + */ + if (*errPtr != '\0') + { + errno = EINVAL; + return 0.0; + } + + /* + * If strtod encounters a string which would exceed the + * capacity of a double, it returns +/- HUGE_VAL and sets + * errno to ERANGE. But +/- HUGE_VAL is also a valid result + * from a conversion, so we need to check errno. + * + * Underflow also sets errno to ERANGE, but it returns 0 in + * that case, which is what we will return anyway. + * + * See CERT guideline ERR30-C + */ + if ((HUGE_VAL == cdouble || -HUGE_VAL == cdouble) && (ERANGE == errno)) + cdouble = 0.0; + return cdouble; + default: errno = EINVAL; return 0.0; + } +} + +int doca_third_party_json_object_set_double(struct json_object *jso, double new_value) +{ + if (!jso || jso->o_type != json_type_double) return 0; - jso->o.c_double=new_value; + JC_DOUBLE(jso)->c_double = new_value; + if (jso->_to_json_string == &_json_object_userdata_to_json_string) + doca_third_party_json_object_set_serializer(jso, NULL, NULL, NULL); return 1; } /* json_object_string */ -static int json_object_string_to_json_string(struct json_object* jso, - struct printbuf *pb, - int level, - int flags) +static int json_object_string_to_json_string(struct json_object *jso, struct printbuf *pb, + int level, int flags) { + ssize_t len = JC_STRING(jso)->len; + if (flags & JSON_C_TO_STRING_COLOR) + printbuf_strappend(pb, ANSI_COLOR_FG_GREEN); printbuf_strappend(pb, "\""); - json_escape_str(pb, get_string_component(jso), jso->o.c_string.len, flags); + json_escape_str(pb, get_string_component(jso), len < 0 ? -(ssize_t)len : len, flags); printbuf_strappend(pb, "\""); + if (flags & JSON_C_TO_STRING_COLOR) + printbuf_strappend(pb, ANSI_COLOR_RESET); return 0; } -static void json_object_string_delete(struct json_object* jso) +static void json_object_string_delete(struct json_object *jso) { - if(jso->o.c_string.len >= LEN_DIRECT_STRING_DATA) - free(jso->o.c_string.str.ptr); + if (JC_STRING(jso)->len < 0) + free(JC_STRING(jso)->c_string.pdata); json_object_generic_delete(jso); } -struct json_object* json_object_new_string(const char *s) +static struct json_object *_json_object_new_string(const char *s, const size_t len) { - struct json_object *jso = json_object_new(json_type_string); + size_t objsize; + struct json_object_string *jso; + + /* + * Structures Actual memory layout + * ------------------- -------------------- + * [json_object_string [json_object_string + * [json_object] [json_object] + * ...other fields... ...other fields... + * c_string] len + * bytes + * of + * string + * data + * \0] + */ + if (len > (SSIZE_T_MAX - (sizeof(*jso) - sizeof(jso->c_string)) - 1)) + return NULL; + objsize = (sizeof(*jso) - sizeof(jso->c_string)) + len + 1; + if (len < sizeof(void *)) + // We need a minimum size to support json_object_set_string() mutability + // so we can stuff a pointer into pdata :( + objsize += sizeof(void *) - len; + + jso = (struct json_object_string *)json_object_new(json_type_string, objsize, + &json_object_string_to_json_string); + if (!jso) return NULL; - jso->_delete = &json_object_string_delete; - jso->_to_json_string = &json_object_string_to_json_string; - jso->o.c_string.len = strlen(s); - if(jso->o.c_string.len < LEN_DIRECT_STRING_DATA) { - memcpy(jso->o.c_string.str.data, s, jso->o.c_string.len); - } else { - jso->o.c_string.str.ptr = strdup(s); - if (!jso->o.c_string.str.ptr) - { - json_object_generic_delete(jso); - errno = ENOMEM; - return NULL; - } - } - return jso; + jso->len = len; + memcpy(jso->c_string.idata, s, len); + // Cast below needed for Clang UB sanitizer + ((char *)jso->c_string.idata)[len] = '\0'; + return &jso->base; } -struct json_object* json_object_new_string_len(const char *s, int len) +struct json_object *doca_third_party_json_object_new_string(const char *s) { - char *dstbuf; - struct json_object *jso = json_object_new(json_type_string); - if (!jso) - return NULL; - jso->_delete = &json_object_string_delete; - jso->_to_json_string = &json_object_string_to_json_string; - if(len < LEN_DIRECT_STRING_DATA) { - dstbuf = jso->o.c_string.str.data; - } else { - jso->o.c_string.str.ptr = (char*)malloc(len + 1); - if (!jso->o.c_string.str.ptr) - { - json_object_generic_delete(jso); - errno = ENOMEM; - return NULL; - } - dstbuf = jso->o.c_string.str.ptr; - } - memcpy(dstbuf, (const void *)s, len); - dstbuf[len] = '\0'; - jso->o.c_string.len = len; - return jso; + return _json_object_new_string(s, strlen(s)); +} + +struct json_object *doca_third_party_json_object_new_string_len(const char *s, const int len) +{ + return _json_object_new_string(s, len); } -const char* json_object_get_string(struct json_object *jso) +const char *doca_third_party_json_object_get_string(struct json_object *jso) { if (!jso) return NULL; - switch(jso->o_type) + switch (jso->o_type) { - case json_type_string: - return get_string_component(jso); - default: - return json_object_to_json_string(jso); + case json_type_string: return get_string_component(jso); + default: return doca_third_party_json_object_to_json_string(jso); } } -int json_object_get_string_len(const struct json_object *jso) +static inline ssize_t _json_object_get_string_len(const struct json_object_string *jso) +{ + ssize_t len; + len = jso->len; + return (len < 0) ? -(ssize_t)len : len; +} +int doca_third_party_json_object_get_string_len(const struct json_object *jso) { if (!jso) return 0; - switch(jso->o_type) + switch (jso->o_type) { - case json_type_string: - return jso->o.c_string.len; - default: - return 0; + case json_type_string: return _json_object_get_string_len(JC_STRING_C(jso)); + default: return 0; } } -int json_object_set_string(json_object* jso, const char* s) { - return json_object_set_string_len(jso, s, (int)(strlen(s))); -} +static int _json_object_set_string_len(json_object *jso, const char *s, size_t len) +{ + char *dstbuf; + ssize_t curlen; + ssize_t newlen; + if (jso == NULL || jso->o_type != json_type_string) + return 0; + + if (len >= INT_MAX - 1) + // jso->len is a signed ssize_t, so it can't hold the + // full size_t range. json_object_get_string_len returns + // length as int, cap length at INT_MAX. + return 0; -int json_object_set_string_len(json_object* jso, const char* s, int len){ - char *dstbuf; - if (jso==NULL || jso->o_type!=json_type_string) return 0; - if (leno.c_string.str.data; - if (jso->o.c_string.len>=LEN_DIRECT_STRING_DATA) free(jso->o.c_string.str.ptr); - } else { - dstbuf=(char *)malloc(len+1); - if (dstbuf==NULL) return 0; - if (jso->o.c_string.len>=LEN_DIRECT_STRING_DATA) free(jso->o.c_string.str.ptr); - jso->o.c_string.str.ptr=dstbuf; + curlen = JC_STRING(jso)->len; + if (curlen < 0) { + if (len == 0) { + free(JC_STRING(jso)->c_string.pdata); + JC_STRING(jso)->len = curlen = 0; + } else { + curlen = -curlen; + } + } + + newlen = len; + dstbuf = get_string_component_mutable(jso); + + if ((ssize_t)len > curlen) + { + // We have no way to return the new ptr from realloc(jso, newlen) + // and we have no way of knowing whether there's extra room available + // so we need to stuff a pointer in to pdata :( + dstbuf = (char *)malloc(len + 1); + if (dstbuf == NULL) + return 0; + if (JC_STRING(jso)->len < 0) + free(JC_STRING(jso)->c_string.pdata); + JC_STRING(jso)->c_string.pdata = dstbuf; + newlen = -(ssize_t)len; } - jso->o.c_string.len=len; + else if (JC_STRING(jso)->len < 0) + { + // We've got enough room in the separate allocated buffer, + // so use it as-is and continue to indicate that pdata is used. + newlen = -(ssize_t)len; + } + memcpy(dstbuf, (const void *)s, len); dstbuf[len] = '\0'; - return 1; + JC_STRING(jso)->len = newlen; + return 1; +} + +int doca_third_party_json_object_set_string(json_object *jso, const char *s) +{ + return _json_object_set_string_len(jso, s, strlen(s)); +} + +int doca_third_party_json_object_set_string_len(json_object *jso, const char *s, int len) +{ + return _json_object_set_string_len(jso, s, len); } /* json_object_array */ -static int json_object_array_to_json_string(struct json_object* jso, - struct printbuf *pb, - int level, +static int json_object_array_to_json_string(struct json_object *jso, struct printbuf *pb, int level, int flags) { int had_children = 0; size_t ii; printbuf_strappend(pb, "["); - if (flags & JSON_C_TO_STRING_PRETTY) - printbuf_strappend(pb, "\n"); - for(ii=0; ii < json_object_array_length(jso); ii++) + for (ii = 0; ii < doca_third_party_json_object_array_length(jso); ii++) { struct json_object *val; if (had_children) { printbuf_strappend(pb, ","); - if (flags & JSON_C_TO_STRING_PRETTY) - printbuf_strappend(pb, "\n"); } + if (flags & JSON_C_TO_STRING_PRETTY) + printbuf_strappend(pb, "\n"); had_children = 1; - if (flags & JSON_C_TO_STRING_SPACED) + if (flags & JSON_C_TO_STRING_SPACED && !(flags & JSON_C_TO_STRING_PRETTY)) printbuf_strappend(pb, " "); indent(pb, level + 1, flags); - val = json_object_array_get_idx(jso, ii); - if(val == NULL) + val = doca_third_party_json_object_array_get_idx(jso, ii); + if (val == NULL) { + + if (flags & JSON_C_TO_STRING_COLOR) + printbuf_strappend(pb, ANSI_COLOR_FG_MAGENTA); printbuf_strappend(pb, "null"); - else - if (val->_to_json_string(val, pb, level+1, flags) < 0) - return -1; + if (flags & JSON_C_TO_STRING_COLOR) + printbuf_strappend(pb, ANSI_COLOR_RESET); + + } else if (val->_to_json_string(val, pb, level + 1, flags) < 0) + return -1; } - if (flags & JSON_C_TO_STRING_PRETTY) + if ((flags & JSON_C_TO_STRING_PRETTY) && had_children) { - if (had_children) - printbuf_strappend(pb, "\n"); - indent(pb,level,flags); + printbuf_strappend(pb, "\n"); + indent(pb, level, flags); } - if (flags & JSON_C_TO_STRING_SPACED) + if (flags & JSON_C_TO_STRING_SPACED && !(flags & JSON_C_TO_STRING_PRETTY)) return printbuf_strappend(pb, " ]"); return printbuf_strappend(pb, "]"); } static void json_object_array_entry_free(void *data) { - json_object_put((struct json_object*)data); + doca_third_party_json_object_put((struct json_object *)data); } -static void json_object_array_delete(struct json_object* jso) +static void json_object_array_delete(struct json_object *jso) { - array_list_free(jso->o.c_array); + doca_third_party_array_list_free(JC_ARRAY(jso)->c_array); json_object_generic_delete(jso); } -struct json_object* json_object_new_array(void) +struct json_object *doca_third_party_json_object_new_array(void) +{ + return doca_third_party_json_object_new_array_ext(ARRAY_LIST_DEFAULT_SIZE); +} +struct json_object *doca_third_party_json_object_new_array_ext(int initial_size) { - struct json_object *jso = json_object_new(json_type_array); + struct json_object_array *jso = JSON_OBJECT_NEW(array); if (!jso) return NULL; - jso->_delete = &json_object_array_delete; - jso->_to_json_string = &json_object_array_to_json_string; - jso->o.c_array = array_list_new(&json_object_array_entry_free); - if(jso->o.c_array == NULL) + jso->c_array = doca_third_party_array_list_new2(&json_object_array_entry_free, initial_size); + if (jso->c_array == NULL) { - free(jso); - return NULL; + free(jso); + return NULL; } - return jso; + return &jso->base; } -struct array_list* json_object_get_array(const struct json_object *jso) +struct array_list *doca_third_party_json_object_get_array(const struct json_object *jso) { if (!jso) return NULL; - switch(jso->o_type) + switch (jso->o_type) { - case json_type_array: - return jso->o.c_array; - default: - return NULL; + case json_type_array: return JC_ARRAY_C(jso)->c_array; + default: return NULL; } } -void json_object_array_sort(struct json_object *jso, - int(*sort_fn)(const void *, const void *)) +void doca_third_party_json_object_array_sort(struct json_object *jso, int (*sort_fn)(const void *, const void *)) { - assert(json_object_get_type(jso) == json_type_array); - array_list_sort(jso->o.c_array, sort_fn); + assert(doca_third_party_json_object_get_type(jso) == json_type_array); + doca_third_party_array_list_sort(JC_ARRAY(jso)->c_array, sort_fn); } -struct json_object* json_object_array_bsearch( - const struct json_object *key, - const struct json_object *jso, - int (*sort_fn)(const void *, const void *)) +struct json_object *doca_third_party_json_object_array_bsearch(const struct json_object *key, + const struct json_object *jso, + int (*sort_fn)(const void *, const void *)) { struct json_object **result; - assert(json_object_get_type(jso) == json_type_array); - result = (struct json_object **)array_list_bsearch( - (const void **)(void *)&key, jso->o.c_array, sort_fn); + assert(doca_third_party_json_object_get_type(jso) == json_type_array); + result = (struct json_object **)doca_third_party_array_list_bsearch((const void **)(void *)&key, + JC_ARRAY_C(jso)->c_array, sort_fn); if (!result) return NULL; return *result; } -size_t json_object_array_length(const struct json_object *jso) +size_t doca_third_party_json_object_array_length(const struct json_object *jso) +{ + assert(doca_third_party_json_object_get_type(jso) == json_type_array); + return doca_third_party_array_list_length(JC_ARRAY_C(jso)->c_array); +} + +int doca_third_party_json_object_array_add(struct json_object *jso, struct json_object *val) { - assert(json_object_get_type(jso) == json_type_array); - return array_list_length(jso->o.c_array); + assert(doca_third_party_json_object_get_type(jso) == json_type_array); + return doca_third_party_array_list_add(JC_ARRAY(jso)->c_array, val); } -int json_object_array_add(struct json_object *jso,struct json_object *val) +int doca_third_party_json_object_array_insert_idx(struct json_object *jso, size_t idx, struct json_object *val) { - assert(json_object_get_type(jso) == json_type_array); - return array_list_add(jso->o.c_array, val); + assert(doca_third_party_json_object_get_type(jso) == json_type_array); + return doca_third_party_array_list_insert_idx(JC_ARRAY(jso)->c_array, idx, val); } -int json_object_array_put_idx(struct json_object *jso, size_t idx, - struct json_object *val) +int doca_third_party_json_object_array_put_idx(struct json_object *jso, size_t idx, struct json_object *val) { - assert(json_object_get_type(jso) == json_type_array); - return array_list_put_idx(jso->o.c_array, idx, val); + assert(doca_third_party_json_object_get_type(jso) == json_type_array); + return doca_third_party_array_list_put_idx(JC_ARRAY(jso)->c_array, idx, val); } -int json_object_array_del_idx(struct json_object *jso, size_t idx, size_t count) +int doca_third_party_json_object_array_del_idx(struct json_object *jso, size_t idx, size_t count) { - assert(json_object_get_type(jso) == json_type_array); - return array_list_del_idx(jso->o.c_array, idx, count); + assert(doca_third_party_json_object_get_type(jso) == json_type_array); + return doca_third_party_array_list_del_idx(JC_ARRAY(jso)->c_array, idx, count); } -struct json_object* json_object_array_get_idx(const struct json_object *jso, - size_t idx) +struct json_object *doca_third_party_json_object_array_get_idx(const struct json_object *jso, size_t idx) { - assert(json_object_get_type(jso) == json_type_array); - return (struct json_object*)array_list_get_idx(jso->o.c_array, idx); + assert(doca_third_party_json_object_get_type(jso) == json_type_array); + return (struct json_object *)doca_third_party_array_list_get_idx(JC_ARRAY_C(jso)->c_array, idx); } -static int json_array_equal(struct json_object* jso1, - struct json_object* jso2) +static int json_array_equal(struct json_object *jso1, struct json_object *jso2) { size_t len, i; - len = json_object_array_length(jso1); - if (len != json_object_array_length(jso2)) + len = doca_third_party_json_object_array_length(jso1); + if (len != doca_third_party_json_object_array_length(jso2)) return 0; - for (i = 0; i < len; i++) { - if (!json_object_equal(json_object_array_get_idx(jso1, i), - json_object_array_get_idx(jso2, i))) + for (i = 0; i < len; i++) + { + if (!doca_third_party_json_object_equal(doca_third_party_json_object_array_get_idx(jso1, i), + doca_third_party_json_object_array_get_idx(jso2, i))) return 0; } return 1; } -static int json_object_all_values_equal(struct json_object* jso1, - struct json_object* jso2) +int doca_third_party_json_object_array_shrink(struct json_object *jso, int empty_slots) +{ + if (empty_slots < 0) + json_abort("json_object_array_shrink called with negative empty_slots"); + return doca_third_party_array_list_shrink(JC_ARRAY(jso)->c_array, empty_slots); +} + +struct json_object *doca_third_party_json_object_new_null(void) +{ + return NULL; +} + +static int json_object_all_values_equal(struct json_object *jso1, struct json_object *jso2) { struct json_object_iter iter; struct json_object *sub; - assert(json_object_get_type(jso1) == json_type_object); - assert(json_object_get_type(jso2) == json_type_object); + assert(doca_third_party_json_object_get_type(jso1) == json_type_object); + assert(doca_third_party_json_object_get_type(jso2) == json_type_object); /* Iterate over jso1 keys and see if they exist and are equal in jso2 */ - json_object_object_foreachC(jso1, iter) { - if (!lh_table_lookup_ex(jso2->o.c_object, (void*)iter.key, - (void**)(void *)&sub)) + doca_third_party_json_object_object_foreachC(jso1, iter) + { + if (!doca_third_party_lh_table_lookup_ex(JC_OBJECT(jso2)->c_object, (void *)iter.key, + (void **)(void *)&sub)) return 0; - if (!json_object_equal(iter.val, sub)) + if (!doca_third_party_json_object_equal(iter.val, sub)) return 0; - } + } /* Iterate over jso2 keys to see if any exist that are not in jso1 */ - json_object_object_foreachC(jso2, iter) { - if (!lh_table_lookup_ex(jso1->o.c_object, (void*)iter.key, - (void**)(void *)&sub)) + doca_third_party_json_object_object_foreachC(jso2, iter) + { + if (!doca_third_party_lh_table_lookup_ex(JC_OBJECT(jso1)->c_object, (void *)iter.key, + (void **)(void *)&sub)) return 0; - } + } return 1; } -int json_object_equal(struct json_object* jso1, struct json_object* jso2) +int doca_third_party_json_object_equal(struct json_object *jso1, struct json_object *jso2) { if (jso1 == jso2) return 1; @@ -1296,30 +1633,45 @@ int json_object_equal(struct json_object* jso1, struct json_object* jso2) if (jso1->o_type != jso2->o_type) return 0; - switch(jso1->o_type) { - case json_type_boolean: - return (jso1->o.c_boolean == jso2->o.c_boolean); + switch (jso1->o_type) + { + case json_type_boolean: return (JC_BOOL(jso1)->c_boolean == JC_BOOL(jso2)->c_boolean); - case json_type_double: - return (jso1->o.c_double == jso2->o.c_double); + case json_type_double: return (JC_DOUBLE(jso1)->c_double == JC_DOUBLE(jso2)->c_double); - case json_type_int: - return (jso1->o.c_int64 == jso2->o.c_int64); + case json_type_int: + { + struct json_object_int *int1 = JC_INT(jso1); + struct json_object_int *int2 = JC_INT(jso2); + if (int1->cint_type == json_object_int_type_int64) + { + if (int2->cint_type == json_object_int_type_int64) + return (int1->cint.c_int64 == int2->cint.c_int64); + if (int1->cint.c_int64 < 0) + return 0; + return ((uint64_t)int1->cint.c_int64 == int2->cint.c_uint64); + } + // else jso1 is a uint64 + if (int2->cint_type == json_object_int_type_uint64) + return (int1->cint.c_uint64 == int2->cint.c_uint64); + if (int2->cint.c_int64 < 0) + return 0; + return (int1->cint.c_uint64 == (uint64_t)int2->cint.c_int64); + } - case json_type_string: - return (jso1->o.c_string.len == jso2->o.c_string.len && - memcmp(get_string_component(jso1), - get_string_component(jso2), - jso1->o.c_string.len) == 0); + case json_type_string: + { + return (_json_object_get_string_len(JC_STRING(jso1)) == + _json_object_get_string_len(JC_STRING(jso2)) && + memcmp(get_string_component(jso1), get_string_component(jso2), + _json_object_get_string_len(JC_STRING(jso1))) == 0); + } - case json_type_object: - return json_object_all_values_equal(jso1, jso2); + case json_type_object: return json_object_all_values_equal(jso1, jso2); - case json_type_array: - return json_array_equal(jso1, jso2); + case json_type_array: return json_array_equal(jso1, jso2); - case json_type_null: - return 1; + case json_type_null: return 1; }; return 0; @@ -1330,21 +1682,31 @@ static int json_object_copy_serializer_data(struct json_object *src, struct json if (!src->_userdata && !src->_user_delete) return 0; - if (dst->_to_json_string == json_object_userdata_to_json_string) + if (dst->_to_json_string == doca_third_party_json_object_userdata_to_json_string || + dst->_to_json_string == _json_object_userdata_to_json_string) { - dst->_userdata = strdup(src->_userdata); + char *p; + assert(src->_userdata); + p = strdup(src->_userdata); + if (p == NULL) + { + doca_third_party__json_c_set_last_err("json_object_copy_serializer_data: out of memory\n"); + return -1; + } + dst->_userdata = p; } // else if ... other supported serializers ... else { - _json_c_set_last_err("json_object_deep_copy: unable to copy unknown serializer data: %p\n", dst->_to_json_string); + doca_third_party__json_c_set_last_err( + "json_object_copy_serializer_data: unable to copy unknown serializer data: " + "%p\n", (void *)dst->_to_json_string); return -1; } dst->_user_delete = src->_user_delete; return 0; } - /** * The default shallow copy implementation. Simply creates a new object of the same * type but does *not* copy over _userdata nor retain any custom serializer. @@ -1353,39 +1715,42 @@ static int json_object_copy_serializer_data(struct json_object *src, struct json * * This always returns -1 or 1. It will never return 2 since it does not copy the serializer. */ -int json_c_shallow_copy_default(json_object *src, json_object *parent, const char *key, size_t index, json_object **dst) +int doca_third_party_json_c_shallow_copy_default(json_object *src, json_object *parent, const char *key, + size_t index, json_object **dst) { - switch (src->o_type) { - case json_type_boolean: - *dst = json_object_new_boolean(src->o.c_boolean); - break; + switch (src->o_type) + { + case json_type_boolean: *dst = doca_third_party_json_object_new_boolean(JC_BOOL(src)->c_boolean); break; - case json_type_double: - *dst = json_object_new_double(src->o.c_double); - break; + case json_type_double: *dst = doca_third_party_json_object_new_double(JC_DOUBLE(src)->c_double); break; case json_type_int: - *dst = json_object_new_int64(src->o.c_int64); + switch (JC_INT(src)->cint_type) + { + case json_object_int_type_int64: + *dst = doca_third_party_json_object_new_int64(JC_INT(src)->cint.c_int64); + break; + case json_object_int_type_uint64: + *dst = doca_third_party_json_object_new_uint64(JC_INT(src)->cint.c_uint64); + break; + default: json_abort("invalid cint_type"); + } break; case json_type_string: - *dst = json_object_new_string(get_string_component(src)); + *dst = doca_third_party_json_object_new_string_len(get_string_component(src), + _json_object_get_string_len(JC_STRING(src))); break; - case json_type_object: - *dst = json_object_new_object(); - break; + case json_type_object: *dst = doca_third_party_json_object_new_object(); break; - case json_type_array: - *dst = json_object_new_array(); - break; + case json_type_array: *dst = doca_third_party_json_object_new_array(); break; - default: - errno = EINVAL; - return -1; + default: errno = EINVAL; return -1; } - if (!*dst) { + if (!*dst) + { errno = ENOMEM; return -1; } @@ -1400,7 +1765,10 @@ int json_c_shallow_copy_default(json_object *src, json_object *parent, const cha * * Note: caller is responsible for freeing *dst if this fails and returns -1. */ -static int json_object_deep_copy_recursive(struct json_object *src, struct json_object *parent, const char *key_in_parent, size_t index_in_parent, struct json_object **dst, json_c_shallow_copy_fn *shallow_copy) +static int json_object_deep_copy_recursive(struct json_object *src, struct json_object *parent, + const char *key_in_parent, size_t index_in_parent, + struct json_object **dst, + json_c_shallow_copy_fn *shallow_copy) { struct json_object_iter iter; size_t src_array_len, ii; @@ -1415,44 +1783,49 @@ static int json_object_deep_copy_recursive(struct json_object *src, struct json_ } assert(*dst != NULL); - switch (src->o_type) { + switch (src->o_type) + { case json_type_object: - json_object_object_foreachC(src, iter) { + doca_third_party_json_object_object_foreachC(src, iter) + { struct json_object *jso = NULL; /* This handles the `json_type_null` case */ if (!iter.val) jso = NULL; - else if (json_object_deep_copy_recursive(iter.val, src, iter.key, -1, &jso, shallow_copy) < 0) + else if (json_object_deep_copy_recursive(iter.val, src, iter.key, UINT_MAX, + &jso, shallow_copy) < 0) { - json_object_put(jso); + doca_third_party_json_object_put(jso); return -1; } - if (json_object_object_add(*dst, iter.key, jso) < 0) + if (doca_third_party_json_object_object_add(*dst, iter.key, jso) < 0) { - json_object_put(jso); + doca_third_party_json_object_put(jso); return -1; } } break; case json_type_array: - src_array_len = json_object_array_length(src); - for (ii = 0; ii < src_array_len; ii++) { + src_array_len = doca_third_party_json_object_array_length(src); + for (ii = 0; ii < src_array_len; ii++) + { struct json_object *jso = NULL; - struct json_object *jso1 = json_object_array_get_idx(src, ii); + struct json_object *jso1 = doca_third_party_json_object_array_get_idx(src, ii); /* This handles the `json_type_null` case */ if (!jso1) jso = NULL; - else if (json_object_deep_copy_recursive(jso1, src, NULL, ii, &jso, shallow_copy) < 0) + else if (json_object_deep_copy_recursive(jso1, src, NULL, ii, &jso, + shallow_copy) < 0) { - json_object_put(jso); + doca_third_party_json_object_put(jso); return -1; } - if (json_object_array_add(*dst, jso) < 0) + if (doca_third_party_json_object_array_add(*dst, jso) < 0) { - json_object_put(jso); + doca_third_party_json_object_put(jso); return -1; } } @@ -1469,25 +1842,34 @@ static int json_object_deep_copy_recursive(struct json_object *src, struct json_ return 0; } -int json_object_deep_copy(struct json_object *src, struct json_object **dst, json_c_shallow_copy_fn *shallow_copy) +int doca_third_party_json_object_deep_copy(struct json_object *src, struct json_object **dst, + json_c_shallow_copy_fn *shallow_copy) { int rc; /* Check if arguments are sane ; *dst must not point to a non-NULL object */ - if (!src || !dst || *dst) { + if (!src || !dst || *dst) + { errno = EINVAL; return -1; } if (shallow_copy == NULL) - shallow_copy = json_c_shallow_copy_default; + shallow_copy = doca_third_party_json_c_shallow_copy_default; - rc = json_object_deep_copy_recursive(src, NULL, NULL, -1, dst, shallow_copy); - if (rc < 0) { - json_object_put(*dst); + rc = json_object_deep_copy_recursive(src, NULL, NULL, UINT_MAX, dst, shallow_copy); + if (rc < 0) + { + doca_third_party_json_object_put(*dst); *dst = NULL; } return rc; } +static void json_abort(const char *message) +{ + if (message != NULL) + fprintf(stderr, "json-c aborts with error: %s\n", message); + abort(); +} diff --git a/third_party/json-c/json_object.h b/third_party/json-c/json_object.h index 073d80c61..73c33bc75 100644 --- a/third_party/json-c/json_object.h +++ b/third_party/json-c/json_object.h @@ -1,4 +1,6 @@ /* + * Original work: + * * $Id: json_object.h,v 1.12 2006/01/30 23:07:57 mclark Exp $ * * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd. @@ -8,6 +10,18 @@ * This library is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See COPYING for details. * + * Modified Work: + * + * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. + * + * This software product is a proprietary product of NVIDIA CORPORATION & + * AFFILIATES (the "Company") and all right, title, and interest in and to the + * software product, including all associated intellectual property rights, are + * and shall remain exclusively with the Company. + * + * This software product is governed by the End User License Agreement + * provided with the software product. + * */ /** @@ -17,32 +31,18 @@ #ifndef _json_object_h_ #define _json_object_h_ -#ifdef __GNUC__ -#define THIS_FUNCTION_IS_DEPRECATED(func) func __attribute__ ((deprecated)) -#elif defined(_MSC_VER) -#define THIS_FUNCTION_IS_DEPRECATED(func) __declspec(deprecated) func -#elif defined(__clang__) -#define THIS_FUNCTION_IS_DEPRECATED(func) func __deprecated -#else -#define THIS_FUNCTION_IS_DEPRECATED(func) func -#endif - #ifdef __GNUC__ #define JSON_C_CONST_FUNCTION(func) func __attribute__((const)) #else #define JSON_C_CONST_FUNCTION(func) func #endif -#if defined(_MSC_VER) -#define JSON_EXPORT __declspec(dllexport) -#else -#define JSON_EXPORT extern -#endif - -#include #include "json_inttypes.h" +#include "json_types.h" #include "printbuf.h" +#include + #ifdef __cplusplus extern "C" { #endif @@ -54,22 +54,22 @@ extern "C" { * json_object_to_file_ext() functions which causes the output * to have no extra whitespace or formatting applied. */ -#define JSON_C_TO_STRING_PLAIN 0 +#define JSON_C_TO_STRING_PLAIN 0 /** * A flag for the json_object_to_json_string_ext() and * json_object_to_file_ext() functions which causes the output to have * minimal whitespace inserted to make things slightly more readable. */ -#define JSON_C_TO_STRING_SPACED (1<<0) +#define JSON_C_TO_STRING_SPACED (1 << 0) /** * A flag for the json_object_to_json_string_ext() and * json_object_to_file_ext() functions which causes * the output to be formatted. * - * See the "Two Space Tab" option at http://jsonformatter.curiousconcept.com/ + * See the "Two Space Tab" option at https://jsonformatter.curiousconcept.com/ * for an example of the format. */ -#define JSON_C_TO_STRING_PRETTY (1<<1) +#define JSON_C_TO_STRING_PRETTY (1 << 1) /** * A flag for the json_object_to_json_string_ext() and * json_object_to_file_ext() functions which causes @@ -77,28 +77,37 @@ extern "C" { * * Instead of a "Two Space Tab" this gives a single tab character. */ -#define JSON_C_TO_STRING_PRETTY_TAB (1<<3) +#define JSON_C_TO_STRING_PRETTY_TAB (1 << 3) /** * A flag to drop trailing zero for float values */ -#define JSON_C_TO_STRING_NOZERO (1<<2) +#define JSON_C_TO_STRING_NOZERO (1 << 2) /** * Don't escape forward slashes. */ -#define JSON_C_TO_STRING_NOSLASHESCAPE (1<<4) +#define JSON_C_TO_STRING_NOSLASHESCAPE (1 << 4) + +/** + * A flag for the json_object_to_json_string_ext() and + * json_object_to_file_ext() functions which causes + * the output to be formatted. + * + * Use color for printing json. + */ +#define JSON_C_TO_STRING_COLOR (1 << 5) /** * A flag for the json_object_object_add_ex function which * causes the value to be added without a check if it already exists. - * Note: it is the responsibilty of the caller to ensure that no + * Note: it is the responsibility of the caller to ensure that no * key is added multiple times. If this is done, results are * unpredictable. While this option is somewhat dangerous, it * permits potentially large performance savings in code that * knows for sure the key values are unique (e.g. because the * code adds a well-known set of constant key values). */ -#define JSON_C_OBJECT_ADD_KEY_IS_NEW (1<<1) +#define JSON_C_OBJECT_ADD_KEY_IS_NEW (1 << 1) /** * A flag for the json_object_object_add_ex function which * flags the key as being constant memory. This means that @@ -114,15 +123,17 @@ extern "C" { * key is given as a real constant value in the function * call, e.g. as in * json_object_object_add_ex(obj, "ip", json, - * JSON_C_OBJECT_KEY_IS_CONSTANT); + * JSON_C_OBJECT_ADD_CONSTANT_KEY); */ -#define JSON_C_OBJECT_KEY_IS_CONSTANT (1<<2) - -#undef FALSE -#define FALSE ((json_bool)0) - -#undef TRUE -#define TRUE ((json_bool)1) +#define JSON_C_OBJECT_ADD_CONSTANT_KEY (1 << 2) +/** + * This flag is an alias to JSON_C_OBJECT_ADD_CONSTANT_KEY. + * Historically, this flag was used first and the new name + * JSON_C_OBJECT_ADD_CONSTANT_KEY was introduced for version + * 0.16.00 in order to have regular naming. + * Use of this flag is now legacy. + */ +#define JSON_C_OBJECT_KEY_IS_CONSTANT JSON_C_OBJECT_ADD_CONSTANT_KEY /** * Set the global value of an option, which will apply to all @@ -140,70 +151,48 @@ extern "C" { */ #define JSON_C_OPTION_THREAD (1) -/** - * A structure to use with json_object_object_foreachC() loops. - * Contains key, val and entry members. - */ -struct json_object_iter -{ - char *key; - struct json_object *val; - struct lh_entry *entry; -}; -typedef struct json_object_iter json_object_iter; - -typedef int json_bool; - -/** - * @brief The core type for all type of JSON objects handled by json-c - */ -typedef struct json_object json_object; - -/** - * Type of custom user delete functions. See json_object_set_serializer. - */ -typedef void (json_object_delete_fn)(struct json_object *jso, void *userdata); - -/** - * Type of a custom serialization function. See json_object_set_serializer. - */ -typedef int (json_object_to_json_string_fn)(struct json_object *jso, - struct printbuf *pb, - int level, - int flags); - -/* supported object types */ - -typedef enum json_type { - /* If you change this, be sure to update json_type_to_name() too */ - json_type_null, - json_type_boolean, - json_type_double, - json_type_int, - json_type_object, - json_type_array, - json_type_string -} json_type; - /* reference counting functions */ /** - * Increment the reference count of json_object, thereby grabbing shared - * ownership of obj. + * Increment the reference count of json_object, thereby taking ownership of it. + * + * Cases where you might need to increase the refcount include: + * - Using an object field or array index (retrieved through + * `json_object_object_get()` or `json_object_array_get_idx()`) + * beyond the lifetime of the parent object. + * - Detaching an object field or array index from its parent object + * (using `json_object_object_del()` or `json_object_array_del_idx()`) + * - Sharing a json_object with multiple (not necessarily parallel) threads + * of execution that all expect to free it (with `json_object_put()`) when + * they're done. * * @param obj the json_object instance + * @see json_object_put() + * @see json_object_object_get() + * @see json_object_array_get_idx() */ -JSON_EXPORT struct json_object* json_object_get(struct json_object *obj); +JSON_EXPORT struct json_object *doca_third_party_json_object_get(struct json_object *obj); /** * Decrement the reference count of json_object and free if it reaches zero. + * * You must have ownership of obj prior to doing this or you will cause an - * imbalance in the reference count. + * imbalance in the reference count, leading to a classic use-after-free bug. + * In particular, you normally do not need to call `json_object_put()` on the + * json_object returned by `json_object_object_get()` or `json_object_array_get_idx()`. + * + * Just like after calling `free()` on a block of memory, you must not use + * `obj` after calling `json_object_put()` on it or any object that it + * is a member of (unless you know you've called `json_object_get(obj)` to + * explicitly increment the refcount). + * + * NULL may be passed, which which case this is a no-op. * * @param obj the json_object instance * @returns 1 if the object was freed. + * @see json_object_get() */ -JSON_EXPORT int json_object_put(struct json_object *obj); +JSON_EXPORT int doca_third_party_json_object_put(struct json_object *obj); /** * Check if the json_object is of a given type @@ -217,7 +206,7 @@ JSON_EXPORT int json_object_put(struct json_object *obj); json_type_array, json_type_string */ -JSON_EXPORT int json_object_is_type(const struct json_object *obj, enum json_type type); +JSON_EXPORT int doca_third_party_json_object_is_type(const struct json_object *obj, enum json_type type); /** * Get the type of the json_object. See also json_type_to_name() to turn this @@ -233,8 +222,7 @@ JSON_EXPORT int json_object_is_type(const struct json_object *obj, enum json_typ json_type_array, json_type_string */ -JSON_EXPORT enum json_type json_object_get_type(const struct json_object *obj); - +JSON_EXPORT enum json_type doca_third_party_json_object_get_type(const struct json_object *obj); /** Stringify object to json format. * Equivalent to json_object_to_json_string_ext(obj, JSON_C_TO_STRING_SPACED) @@ -245,7 +233,7 @@ JSON_EXPORT enum json_type json_object_get_type(const struct json_object *obj); * @param obj the json_object instance * @returns a string in JSON format */ -JSON_EXPORT const char* json_object_to_json_string(struct json_object *obj); +JSON_EXPORT const char *doca_third_party_json_object_to_json_string(struct json_object *obj); /** Stringify object to json format * @see json_object_to_json_string() for details on how to free string. @@ -253,8 +241,7 @@ JSON_EXPORT const char* json_object_to_json_string(struct json_object *obj); * @param flags formatting options, see JSON_C_TO_STRING_PRETTY and other constants * @returns a string in JSON format */ -JSON_EXPORT const char* json_object_to_json_string_ext(struct json_object *obj, int -flags); +JSON_EXPORT const char *doca_third_party_json_object_to_json_string_ext(struct json_object *obj, int flags); /** Stringify object to json format * @see json_object_to_json_string() for details on how to free string. @@ -263,8 +250,8 @@ flags); * @param length a pointer where, if not NULL, the length (without null) is stored * @returns a string in JSON format and the length if not NULL */ -JSON_EXPORT const char* json_object_to_json_string_length(struct json_object *obj, int -flags, size_t *length); +JSON_EXPORT const char *doca_third_party_json_object_to_json_string_length(struct json_object *obj, int flags, + size_t *length); /** * Returns the userdata set by json_object_set_userdata() or @@ -272,7 +259,7 @@ flags, size_t *length); * * @param jso the object to return the userdata for */ -JSON_EXPORT void* json_object_get_userdata(json_object *jso); +JSON_EXPORT void *doca_third_party_json_object_get_userdata(json_object *jso); /** * Set an opaque userdata value for an object @@ -299,8 +286,8 @@ JSON_EXPORT void* json_object_get_userdata(json_object *jso); * @param userdata an optional opaque cookie * @param user_delete an optional function from freeing userdata */ -JSON_EXPORT void json_object_set_userdata(json_object *jso, void *userdata, - json_object_delete_fn *user_delete); +JSON_EXPORT void doca_third_party_json_object_set_userdata(json_object *jso, void *userdata, + json_object_delete_fn *user_delete); /** * Set a custom serialization function to be used when this particular object @@ -332,10 +319,9 @@ JSON_EXPORT void json_object_set_userdata(json_object *jso, void *userdata, * @param userdata an optional opaque cookie * @param user_delete an optional function from freeing userdata */ -JSON_EXPORT void json_object_set_serializer(json_object *jso, - json_object_to_json_string_fn *to_string_func, - void *userdata, - json_object_delete_fn *user_delete); +JSON_EXPORT void doca_third_party_json_object_set_serializer(json_object *jso, + json_object_to_json_string_fn *to_string_func, + void *userdata, json_object_delete_fn *user_delete); #ifdef __clang__ /* @@ -354,7 +340,7 @@ JSON_EXPORT void json_object_set_serializer(json_object *jso, * @param jso unused * @param userdata the pointer that is passed to free(). */ -json_object_delete_fn json_object_free_userdata; +JSON_EXPORT json_object_delete_fn doca_third_party_json_object_free_userdata; /** * Copy the jso->_userdata string over to pb as-is. @@ -365,14 +351,13 @@ json_object_delete_fn json_object_free_userdata; * @param level Ignored. * @param flags Ignored. */ -json_object_to_json_string_fn json_object_userdata_to_json_string; +JSON_EXPORT json_object_to_json_string_fn doca_third_party_json_object_userdata_to_json_string; #ifdef __clang__ /* } */ #pragma clang diagnostic pop #endif - /* object type methods */ /** Create a new empty object with a reference count of 1. The caller of @@ -385,35 +370,41 @@ json_object_to_json_string_fn json_object_userdata_to_json_string; * * @returns a json_object of type json_type_object */ -JSON_EXPORT struct json_object* json_object_new_object(void); +JSON_EXPORT struct json_object *doca_third_party_json_object_new_object(void); /** Get the hashtable of a json_object of type json_type_object * @param obj the json_object instance * @returns a linkhash */ -JSON_EXPORT struct lh_table* json_object_get_object(const struct json_object *obj); +JSON_EXPORT struct lh_table *doca_third_party_json_object_get_object(const struct json_object *obj); /** Get the size of an object in terms of the number of fields it has. * @param obj the json_object whose length to return */ -JSON_EXPORT int json_object_object_length(const struct json_object* obj); +JSON_EXPORT int doca_third_party_json_object_object_length(const struct json_object *obj); /** Get the sizeof (struct json_object). * @returns a size_t with the sizeof (struct json_object) */ -JSON_C_CONST_FUNCTION(JSON_EXPORT size_t json_c_object_sizeof(void)); +JSON_C_CONST_FUNCTION(JSON_EXPORT size_t doca_third_party_json_c_object_sizeof(void)); /** Add an object field to a json_object of type json_type_object * - * The reference count will *not* be incremented. This is to make adding - * fields to objects in code more compact. If you want to retain a reference - * to an added object, independent of the lifetime of obj, you must wrap the - * passed object with json_object_get. + * The reference count of `val` will *not* be incremented, in effect + * transferring ownership that object to `obj`, and thus `val` will be + * freed when `obj` is. (i.e. through `json_object_put(obj)`) + * + * If you want to retain a reference to the added object, independent + * of the lifetime of obj, you must increment the refcount with + * `json_object_get(val)` (and later release it with json_object_put()). + * + * Since ownership transfers to `obj`, you must make sure + * that you do in fact have ownership over `val`. For instance, + * json_object_new_object() will give you ownership until you transfer it, + * whereas json_object_object_get() does not. * - * Upon calling this, the ownership of val transfers to obj. Thus you must - * make sure that you do in fact have ownership over this object. For instance, - * json_object_new_object will give you ownership until you transfer it, - * whereas json_object_object_get does not. + * Any previous object stored under `key` in `obj` will have its refcount + * decremented, and be freed normally if that drops to zero. * * @param obj the json_object instance * @param key the object field name (a private copy will be duplicated) @@ -422,8 +413,8 @@ JSON_C_CONST_FUNCTION(JSON_EXPORT size_t json_c_object_sizeof(void)); * @return On success, 0 is returned. * On error, a negative value is returned. */ -JSON_EXPORT int json_object_object_add(struct json_object* obj, const char *key, - struct json_object *val); +JSON_EXPORT int doca_third_party_json_object_object_add(struct json_object *obj, const char *key, + struct json_object *val); /** Add an object field to a json_object of type json_type_object * @@ -435,20 +426,18 @@ JSON_EXPORT int json_object_object_add(struct json_object* obj, const char *key, * @param obj the json_object instance * @param key the object field name (a private copy will be duplicated) * @param val a json_object or NULL member to associate with the given field - * @param opts process-modifying options. To specify multiple options, use - * arithmetic or (OPT1|OPT2) + * @param opts process-modifying options. To specify multiple options, use + * (OPT1|OPT2) */ -JSON_EXPORT int json_object_object_add_ex(struct json_object* obj, - const char *const key, - struct json_object *const val, - const unsigned opts); +JSON_EXPORT int doca_third_party_json_object_object_add_ex(struct json_object *obj, const char *const key, + struct json_object *const val, const unsigned opts); /** Get the json_object associate with a given object field. * Deprecated/discouraged: used json_object_object_get_ex instead. * * This returns NULL if the field is found but its value is null, or if * the field is not found, or if obj is not a json_type_object. If you - * need to distinguis between these cases, use json_object_object_get_ex(). + * need to distinguish between these cases, use json_object_object_get_ex(). * * *No* reference counts will be changed. There is no need to manually adjust * reference counts through the json_object_put/json_object_get methods unless @@ -464,8 +453,8 @@ JSON_EXPORT int json_object_object_add_ex(struct json_object* obj, * @param key the object field name * @returns the json_object associated with the given field name */ -JSON_EXPORT struct json_object* json_object_object_get(const struct json_object* obj, - const char *key); +JSON_EXPORT struct json_object *doca_third_party_json_object_object_get(const struct json_object *obj, + const char *key); /** Get the json_object associated with a given object field. * @@ -485,9 +474,8 @@ JSON_EXPORT struct json_object* json_object_object_get(const struct json_object* * It is safe to pass a NULL value. * @returns whether or not the key exists */ -JSON_EXPORT json_bool json_object_object_get_ex(const struct json_object* obj, - const char *key, - struct json_object **value); +JSON_EXPORT json_bool doca_third_party_json_object_object_get_ex(const struct json_object *obj, const char *key, + struct json_object **value); /** Delete the given json_object field * @@ -498,7 +486,7 @@ JSON_EXPORT json_bool json_object_object_get_ex(const struct json_object* obj, * @param obj the json_object instance * @param key the object field name */ -JSON_EXPORT void json_object_object_del(struct json_object* obj, const char *key); +JSON_EXPORT void doca_third_party_json_object_object_del(struct json_object *obj, const char *key); /** * Iterate through all keys and values of an object. @@ -513,63 +501,82 @@ JSON_EXPORT void json_object_object_del(struct json_object* obj, const char *key * @param val the local name for the json_object* object variable defined in * the body */ -#if defined(__GNUC__) && !defined(__STRICT_ANSI__) && __STDC_VERSION__ >= 199901L - -# define json_object_object_foreach(obj,key,val) \ - char *key = NULL; \ - struct json_object *val __attribute__((__unused__)) = NULL; \ - for(struct lh_entry *entry ## key = json_object_get_object(obj)->head, *entry_next ## key = NULL; \ - ({ if(entry ## key) { \ - key = (char*)lh_entry_k(entry ## key); \ - val = (struct json_object*)lh_entry_v(entry ## key); \ - entry_next ## key = entry ## key->next; \ - } ; entry ## key; }); \ - entry ## key = entry_next ## key ) +#if defined(__GNUC__) && !defined(__STRICT_ANSI__) && (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) + +#define doca_third_party_json_object_object_foreach(obj, key, val) \ + char *key = NULL; \ + struct json_object *val __attribute__((__unused__)) = NULL; \ + for (struct lh_entry *entry##key = lh_table_head(doca_third_party_json_object_get_object(obj)), \ + *entry_next##key = NULL; \ + ({ \ + if (entry##key) \ + { \ + key = (char *)lh_entry_k(entry##key); \ + val = (struct json_object *)lh_entry_v(entry##key); \ + entry_next##key = lh_entry_next(entry##key); \ + }; \ + entry##key; \ + }); \ + entry##key = entry_next##key) #else /* ANSI C or MSC */ -# define json_object_object_foreach(obj,key,val) \ - char *key = NULL;\ - struct json_object *val = NULL; \ - struct lh_entry *entry ## key; \ - struct lh_entry *entry_next ## key = NULL; \ - for(entry ## key = json_object_get_object(obj)->head; \ - (entry ## key ? ( \ - key = (char*)lh_entry_k(entry ## key), \ - val = (struct json_object*)lh_entry_v(entry ## key), \ - entry_next ## key = entry ## key->next, \ - entry ## key) : 0); \ - entry ## key = entry_next ## key) - -#endif /* defined(__GNUC__) && !defined(__STRICT_ANSI__) && __STDC_VERSION__ >= 199901L */ +#define doca_third_party_json_object_object_foreach(obj, key, val) \ + char *key = NULL; \ + struct json_object *val = NULL; \ + struct lh_entry *entry##key; \ + struct lh_entry *entry_next##key = NULL; \ + for (entry##key = lh_table_head(doca_third_party_json_object_get_object(obj)); \ + (entry##key ? (key = (char *)lh_entry_k(entry##key), \ + val = (struct json_object *)lh_entry_v(entry##key), \ + entry_next##key = lh_entry_next(entry##key), entry##key) \ + : 0); \ + entry##key = entry_next##key) + +#endif /* defined(__GNUC__) && !defined(__STRICT_ANSI__) && (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) */ /** Iterate through all keys and values of an object (ANSI C Safe) * @param obj the json_object instance * @param iter the object iterator, use type json_object_iter */ -#define json_object_object_foreachC(obj,iter) \ - for(iter.entry = json_object_get_object(obj)->head; \ - (iter.entry ? (iter.key = (char*)lh_entry_k(iter.entry), iter.val = (struct json_object*)lh_entry_v(iter.entry), iter.entry) : 0); \ - iter.entry = iter.entry->next) +#define doca_third_party_json_object_object_foreachC(obj, iter) \ + for (iter.entry = lh_table_head(doca_third_party_json_object_get_object(obj)); \ + (iter.entry ? (iter.key = (char *)lh_entry_k(iter.entry), \ + iter.val = (struct json_object *)lh_entry_v(iter.entry), iter.entry) \ + : 0); \ + iter.entry = lh_entry_next(iter.entry)) /* Array type methods */ /** Create a new empty json_object of type json_type_array + * with 32 slots allocated. + * If you know the array size you'll need ahead of time, use + * json_object_new_array_ext() instead. + * @see json_object_new_array_ext() + * @see json_object_array_shrink() + * @returns a json_object of type json_type_array + */ +JSON_EXPORT struct json_object *doca_third_party_json_object_new_array(void); + +/** Create a new empty json_object of type json_type_array + * with the desired number of slots allocated. + * @see json_object_array_shrink() + * @param initial_size the number of slots to allocate * @returns a json_object of type json_type_array */ -JSON_EXPORT struct json_object* json_object_new_array(void); +JSON_EXPORT struct json_object *doca_third_party_json_object_new_array_ext(int initial_size); /** Get the arraylist of a json_object of type json_type_array * @param obj the json_object instance * @returns an arraylist */ -JSON_EXPORT struct array_list* json_object_get_array(const struct json_object *obj); +JSON_EXPORT struct array_list *doca_third_party_json_object_get_array(const struct json_object *obj); /** Get the length of a json_object of type json_type_array * @param obj the json_object instance * @returns an int */ -JSON_EXPORT size_t json_object_array_length(const struct json_object *obj); +JSON_EXPORT size_t doca_third_party_json_object_array_length(const struct json_object *obj); /** Sorts the elements of jso of type json_type_array * @@ -579,7 +586,8 @@ JSON_EXPORT size_t json_object_array_length(const struct json_object *obj); * @param jso the json_object instance * @param sort_fn a sorting function */ -JSON_EXPORT void json_object_array_sort(struct json_object *jso, int(*sort_fn)(const void *, const void *)); +JSON_EXPORT void doca_third_party_json_object_array_sort(struct json_object *jso, + int (*sort_fn)(const void *, const void *)); /** Binary search a sorted array for a specified key object. * @@ -595,10 +603,9 @@ JSON_EXPORT void json_object_array_sort(struct json_object *jso, int(*sort_fn)(c * * @return the wanted json_object instance */ -JSON_EXPORT struct json_object* json_object_array_bsearch( - const struct json_object *key, - const struct json_object *jso, - int (*sort_fn)(const void *, const void *)); +JSON_EXPORT struct json_object * +doca_third_party_json_object_array_bsearch(const struct json_object *key, const struct json_object *jso, + int (*sort_fn)(const void *, const void *)); /** Add an element to the end of a json_object of type json_type_array * @@ -609,8 +616,7 @@ JSON_EXPORT struct json_object* json_object_array_bsearch( * @param obj the json_object instance * @param val the json_object to be added */ -JSON_EXPORT int json_object_array_add(struct json_object *obj, - struct json_object *val); +JSON_EXPORT int doca_third_party_json_object_array_add(struct json_object *obj, struct json_object *val); /** Insert or replace an element at a specified index in an array (a json_object of type json_type_array) * @@ -627,21 +633,48 @@ JSON_EXPORT int json_object_array_add(struct json_object *obj, * @param idx the index to insert the element at * @param val the json_object to be added */ -JSON_EXPORT int json_object_array_put_idx(struct json_object *obj, size_t idx, - struct json_object *val); +JSON_EXPORT int doca_third_party_json_object_array_put_idx(struct json_object *obj, size_t idx, + struct json_object *val); + +/** Insert an element at a specified index in an array (a json_object of type json_type_array) + * + * The reference count will *not* be incremented. This is to make adding + * fields to objects in code more compact. If you want to retain a reference + * to an added object you must wrap the passed object with json_object_get + * + * The array size will be automatically be expanded to the size of the + * index if the index is larger than the current size. + * If the index is within the existing array limits, then the element will be + * inserted and all elements will be shifted. This is the only difference between + * this function and json_object_array_put_idx(). + * + * @param obj the json_object instance + * @param idx the index to insert the element at + * @param val the json_object to be added + */ +JSON_EXPORT int doca_third_party_json_object_array_insert_idx(struct json_object *obj, size_t idx, + struct json_object *val); -/** Get the element at specificed index of the array (a json_object of type json_type_array) +/** Get the element at specified index of array `obj` (which must be a json_object of type json_type_array) + * + * *No* reference counts will be changed, and ownership of the returned + * object remains with `obj`. See json_object_object_get() for additional + * implications of this behavior. + * + * Calling this with anything other than a json_type_array will trigger + * an assert. + * * @param obj the json_object instance * @param idx the index to get the element at * @returns the json_object at the specified index (or NULL) */ -JSON_EXPORT struct json_object* json_object_array_get_idx(const struct json_object *obj, - size_t idx); +JSON_EXPORT struct json_object *doca_third_party_json_object_array_get_idx(const struct json_object *obj, + size_t idx); /** Delete an elements from a specified index in an array (a json_object of type json_type_array) * * The reference count will be decremented for each of the deleted objects. If there - * are no more owners of an element that is being deleted, then the value is + * are no more owners of an element that is being deleted, then the value is * freed. Otherwise, the reference to the value will remain in memory. * * @param obj the json_object instance @@ -649,42 +682,50 @@ JSON_EXPORT struct json_object* json_object_array_get_idx(const struct json_obje * @param count the number of elements to delete * @returns 0 if the elements were successfully deleted */ -JSON_EXPORT int json_object_array_del_idx(struct json_object *obj, size_t idx, size_t count); +JSON_EXPORT int doca_third_party_json_object_array_del_idx(struct json_object *obj, size_t idx, size_t count); + +/** + * Shrink the internal memory allocation of the array to just + * enough to fit the number of elements in it, plus empty_slots. + * + * @param jso the json_object instance, must be json_type_array + * @param empty_slots the number of empty slots to leave allocated + */ +JSON_EXPORT int doca_third_party_json_object_array_shrink(struct json_object *jso, int empty_slots); /* json_bool type methods */ /** Create a new empty json_object of type json_type_boolean - * @param b a json_bool TRUE or FALSE (1 or 0) + * @param b a json_bool 1 or 0 * @returns a json_object of type json_type_boolean */ -JSON_EXPORT struct json_object* json_object_new_boolean(json_bool b); +JSON_EXPORT struct json_object *doca_third_party_json_object_new_boolean(json_bool b); /** Get the json_bool value of a json_object * * The type is coerced to a json_bool if the passed object is not a json_bool. - * integer and double objects will return FALSE if there value is zero - * or TRUE otherwise. If the passed object is a string it will return - * TRUE if it has a non zero length. If any other object type is passed - * TRUE will be returned if the object is not NULL. + * integer and double objects will return 0 if there value is zero + * or 1 otherwise. If the passed object is a string it will return + * 1 if it has a non zero length. + * If any other object type is passed 0 will be returned, even non-empty + * json_type_array and json_type_object objects. * * @param obj the json_object instance * @returns a json_bool */ -JSON_EXPORT json_bool json_object_get_boolean(const struct json_object *obj); - +JSON_EXPORT json_bool doca_third_party_json_object_get_boolean(const struct json_object *obj); /** Set the json_bool value of a json_object - * - * The type of obj is checked to be a json_type_boolean and 0 is returned + * + * The type of obj is checked to be a json_type_boolean and 0 is returned * if it is not without any further actions. If type of obj is json_type_boolean - * the obect value is chaned to new_value + * the object value is changed to new_value * * @param obj the json_object instance * @param new_value the value to be set * @returns 1 if value is set correctly, 0 otherwise */ -JSON_EXPORT int json_object_set_boolean(struct json_object *obj,json_bool new_value); - +JSON_EXPORT int doca_third_party_json_object_set_boolean(struct json_object *obj, json_bool new_value); /* int type methods */ @@ -694,15 +735,19 @@ JSON_EXPORT int json_object_set_boolean(struct json_object *obj,json_bool new_va * @param i the integer * @returns a json_object of type json_type_int */ -JSON_EXPORT struct json_object* json_object_new_int(int32_t i); - +JSON_EXPORT struct json_object *doca_third_party_json_object_new_int(int32_t i); /** Create a new empty json_object of type json_type_int * @param i the integer * @returns a json_object of type json_type_int */ -JSON_EXPORT struct json_object* json_object_new_int64(int64_t i); +JSON_EXPORT struct json_object *doca_third_party_json_object_new_int64(int64_t i); +/** Create a new empty json_object of type json_type_uint + * @param i the integer + * @returns a json_object of type json_type_uint + */ +JSON_EXPORT struct json_object *doca_third_party_json_object_new_uint64(uint64_t i); /** Get the int value of a json_object * @@ -718,19 +763,19 @@ JSON_EXPORT struct json_object* json_object_new_int64(int64_t i); * @param obj the json_object instance * @returns an int */ -JSON_EXPORT int32_t json_object_get_int(const struct json_object *obj); +JSON_EXPORT int32_t doca_third_party_json_object_get_int(const struct json_object *obj); /** Set the int value of a json_object - * - * The type of obj is checked to be a json_type_int and 0 is returned + * + * The type of obj is checked to be a json_type_int and 0 is returned * if it is not without any further actions. If type of obj is json_type_int - * the obect value is changed to new_value + * the object value is changed to new_value * * @param obj the json_object instance * @param new_value the value to be set * @returns 1 if value is set correctly, 0 otherwise */ -JSON_EXPORT int json_object_set_int(struct json_object *obj,int new_value); +JSON_EXPORT int doca_third_party_json_object_set_int(struct json_object *obj, int new_value); /** Increment a json_type_int object by the given amount, which may be negative. * @@ -744,10 +789,9 @@ JSON_EXPORT int json_object_set_int(struct json_object *obj,int new_value); * * @param obj the json_object instance * @param val the value to add - * @returns 1 if the increment succeded, 0 otherwise + * @returns 1 if the increment succeeded, 0 otherwise */ -JSON_EXPORT int json_object_int_inc(struct json_object *obj, int64_t val); - +JSON_EXPORT int doca_third_party_json_object_int_inc(struct json_object *obj, int64_t val); /** Get the int value of a json_object * @@ -762,20 +806,46 @@ JSON_EXPORT int json_object_int_inc(struct json_object *obj, int64_t val); * @param obj the json_object instance * @returns an int64 */ -JSON_EXPORT int64_t json_object_get_int64(const struct json_object *obj); +JSON_EXPORT int64_t doca_third_party_json_object_get_int64(const struct json_object *obj); +/** Get the uint value of a json_object + * + * The type is coerced to a uint64 if the passed object is not a uint64. + * double objects will return their uint64 conversion. Strings will be + * parsed as an uint64. If no conversion exists then 0 is returned. + * + * NOTE: Set errno to 0 directly before a call to this function to determine + * whether or not conversion was successful (it does not clear the value for + * you). + * + * @param obj the json_object instance + * @returns an uint64 + */ +JSON_EXPORT uint64_t doca_third_party_json_object_get_uint64(const struct json_object *obj); /** Set the int64_t value of a json_object - * - * The type of obj is checked to be a json_type_int and 0 is returned + * + * The type of obj is checked to be a json_type_int and 0 is returned * if it is not without any further actions. If type of obj is json_type_int - * the obect value is chaned to new_value + * the object value is changed to new_value + * + * @param obj the json_object instance + * @param new_value the value to be set + * @returns 1 if value is set correctly, 0 otherwise + */ +JSON_EXPORT int doca_third_party_json_object_set_int64(struct json_object *obj, int64_t new_value); + +/** Set the uint64_t value of a json_object + * + * The type of obj is checked to be a json_type_uint and 0 is returned + * if it is not without any further actions. If type of obj is json_type_uint + * the object value is changed to new_value * * @param obj the json_object instance * @param new_value the value to be set * @returns 1 if value is set correctly, 0 otherwise */ -JSON_EXPORT int json_object_set_int64(struct json_object *obj,int64_t new_value); +JSON_EXPORT int doca_third_party_json_object_set_uint64(struct json_object *obj, uint64_t new_value); /* double type methods */ @@ -786,7 +856,7 @@ JSON_EXPORT int json_object_set_int64(struct json_object *obj,int64_t new_value) * @param d the double * @returns a json_object of type json_type_double */ -JSON_EXPORT struct json_object* json_object_new_double(double d); +JSON_EXPORT struct json_object *doca_third_party_json_object_new_double(double d); /** * Create a new json_object of type json_type_double, using @@ -804,7 +874,8 @@ JSON_EXPORT struct json_object* json_object_new_double(double d); * The userdata field is used to store the string representation, so it * can't be used for other data if this function is used. * - * An equivalent sequence of calls is: + * A roughly equivalent sequence of calls, with the difference being that + * the serialization function won't be reset by json_object_set_double(), is: * @code * jso = json_object_new_double(d); * json_object_set_serializer(jso, json_object_userdata_to_json_string, @@ -814,7 +885,7 @@ JSON_EXPORT struct json_object* json_object_new_double(double d); * @param d the numeric value of the double. * @param ds the string representation of the double. This will be copied. */ -JSON_EXPORT struct json_object* json_object_new_double_s(double d, const char *ds); +JSON_EXPORT struct json_object *doca_third_party_json_object_new_double_s(double d, const char *ds); /** * Set a global or thread-local json-c option, depending on whether @@ -828,9 +899,8 @@ JSON_EXPORT struct json_object* json_object_new_double_s(double d, const char *d * * @return -1 on errors, 0 on success. */ -int json_c_set_serialization_double_format(const char *double_format, int global_or_thread); - - +JSON_EXPORT int doca_third_party_json_c_set_serialization_double_format(const char *double_format, + int global_or_thread); /** Serialize a json_object of type json_type_double to a string. * @@ -851,10 +921,8 @@ int json_c_set_serialization_double_format(const char *double_format, int global * @param level Ignored. * @param flags Ignored. */ -JSON_EXPORT int json_object_double_to_json_string(struct json_object* jso, - struct printbuf *pb, - int level, - int flags); +JSON_EXPORT int doca_third_party_json_object_double_to_json_string(struct json_object *jso, struct printbuf *pb, + int level, int flags); /** Get the double floating point value of a json_object * @@ -879,22 +947,22 @@ JSON_EXPORT int json_object_double_to_json_string(struct json_object* jso, * @param obj the json_object instance * @returns a double floating point number */ -JSON_EXPORT double json_object_get_double(const struct json_object *obj); - +JSON_EXPORT double doca_third_party_json_object_get_double(const struct json_object *obj); /** Set the double value of a json_object - * - * The type of obj is checked to be a json_type_double and 0 is returned + * + * The type of obj is checked to be a json_type_double and 0 is returned * if it is not without any further actions. If type of obj is json_type_double - * the obect value is chaned to new_value + * the object value is changed to new_value + * + * If the object was created with json_object_new_double_s(), the serialization + * function is reset to the default and the cached serialized value is cleared. * * @param obj the json_object instance * @param new_value the value to be set * @returns 1 if value is set correctly, 0 otherwise */ -JSON_EXPORT int json_object_set_double(struct json_object *obj,double new_value); - - +JSON_EXPORT int doca_third_party_json_object_set_double(struct json_object *obj, double new_value); /* string type methods */ @@ -904,10 +972,21 @@ JSON_EXPORT int json_object_set_double(struct json_object *obj,double new_value) * * @param s the string * @returns a json_object of type json_type_string + * @see json_object_new_string_len() */ -JSON_EXPORT struct json_object* json_object_new_string(const char *s); +JSON_EXPORT struct json_object *doca_third_party_json_object_new_string(const char *s); -JSON_EXPORT struct json_object* json_object_new_string_len(const char *s, int len); +/** Create a new empty json_object of type json_type_string and allocate + * len characters for the new string. + * + * A copy of the string is made and the memory is managed by the json_object + * + * @param s the string + * @param len max length of the new string + * @returns a json_object of type json_type_string + * @see json_object_new_string() + */ +JSON_EXPORT struct json_object *doca_third_party_json_object_new_string_len(const char *s, const int len); /** Get the string value of a json_object * @@ -925,7 +1004,7 @@ JSON_EXPORT struct json_object* json_object_new_string_len(const char *s, int le * @param obj the json_object instance * @returns a string or NULL */ -JSON_EXPORT const char* json_object_get_string(struct json_object *obj); +JSON_EXPORT const char *doca_third_party_json_object_get_string(struct json_object *obj); /** Get the string length of a json_object * @@ -935,27 +1014,32 @@ JSON_EXPORT const char* json_object_get_string(struct json_object *obj); * @param obj the json_object instance * @returns int */ -JSON_EXPORT int json_object_get_string_len(const struct json_object *obj); - +JSON_EXPORT int doca_third_party_json_object_get_string_len(const struct json_object *obj); /** Set the string value of a json_object with zero terminated strings * equivalent to json_object_set_string_len (obj, new_value, strlen(new_value)) * @returns 1 if value is set correctly, 0 otherwise */ -JSON_EXPORT int json_object_set_string(json_object* obj, const char* new_value); +JSON_EXPORT int doca_third_party_json_object_set_string(json_object *obj, const char *new_value); /** Set the string value of a json_object str - * - * The type of obj is checked to be a json_type_string and 0 is returned + * + * The type of obj is checked to be a json_type_string and 0 is returned * if it is not without any further actions. If type of obj is json_type_string - * the obect value is chaned to new_value + * the object value is changed to new_value * * @param obj the json_object instance - * @param new_value the value to be set; Since string legth is given in len this need not be zero terminated + * @param new_value the value to be set; Since string length is given in len this need not be zero terminated * @param len the length of new_value * @returns 1 if value is set correctly, 0 otherwise */ -JSON_EXPORT int json_object_set_string_len(json_object* obj, const char* new_value, int len); +JSON_EXPORT int doca_third_party_json_object_set_string_len(json_object *obj, const char *new_value, int len); + +/** This method exists only to provide a complementary function + * along the lines of the other json_object_new_* functions. + * It always returns NULL, and it is entirely acceptable to simply use NULL directly. + */ +JSON_EXPORT struct json_object *doca_third_party_json_object_new_null(void); /** Check if two json_object's are equal * @@ -974,8 +1058,7 @@ JSON_EXPORT int json_object_set_string_len(json_object* obj, const char* new_val * @param obj2 the second json_object instance * @returns whether both objects are equal or not */ -JSON_EXPORT int json_object_equal(struct json_object *obj1, - struct json_object *obj2); +JSON_EXPORT int doca_third_party_json_object_equal(struct json_object *obj1, struct json_object *obj2); /** * Perform a shallow copy of src into *dst as part of an overall json_object_deep_copy(). @@ -985,17 +1068,18 @@ JSON_EXPORT int json_object_equal(struct json_object *obj1, * When shallow_copy is called *dst will be NULL, and must be non-NULL when it returns. * src will never be NULL. * - * If shallow_copy sets the serializer on an object, return 2 to indicate to + * If shallow_copy sets the serializer on an object, return 2 to indicate to * json_object_deep_copy that it should not attempt to use the standard userdata * copy function. * * @return On success 1 or 2, -1 on errors */ -typedef int (json_c_shallow_copy_fn)(json_object *src, json_object *parent, const char *key, size_t index, json_object **dst); +typedef int(json_c_shallow_copy_fn)(json_object *src, json_object *parent, const char *key, + size_t index, json_object **dst); /** * The default shallow copy implementation for use with json_object_deep_copy(). - * This simply calls the appropriate json_object_new_() function and + * This simply calls the appropriate json_object_new_() function and * copies over the serializer function (_to_json_string internal field of * the json_object structure) but not any _userdata or _user_delete values. * @@ -1005,7 +1089,7 @@ typedef int (json_c_shallow_copy_fn)(json_object *src, json_object *parent, cons * * @return 1 on success, -1 on errors, but never 2. */ -json_c_shallow_copy_fn json_c_shallow_copy_default; +JSON_EXPORT json_c_shallow_copy_fn doca_third_party_json_c_shallow_copy_default; /** * Copy the contents of the JSON object. @@ -1022,11 +1106,12 @@ json_c_shallow_copy_fn json_c_shallow_copy_default; * when custom serializers are in use. See also * json_object set_serializer. * - * @returns 0 if the copy went well, -1 if an error occured during copy + * @returns 0 if the copy went well, -1 if an error occurred during copy * or if the destination pointer is non-NULL */ -JSON_EXPORT int json_object_deep_copy(struct json_object *src, struct json_object **dst, json_c_shallow_copy_fn *shallow_copy); +JSON_EXPORT int doca_third_party_json_object_deep_copy(struct json_object *src, struct json_object **dst, + json_c_shallow_copy_fn *shallow_copy); #ifdef __cplusplus } #endif diff --git a/third_party/json-c/json_object_iterator.c b/third_party/json-c/json_object_iterator.c index f8d69ab36..259142da0 100644 --- a/third_party/json-c/json_object_iterator.c +++ b/third_party/json-c/json_object_iterator.c @@ -1,15 +1,33 @@ /** ******************************************************************************* * @file json_object_iterator.c -* -* Copyright (c) 2009-2012 Hewlett-Packard Development Company, L.P. -* -* This library is free software; you can redistribute it and/or modify -* it under the terms of the MIT license. See COPYING for details. -* ******************************************************************************* */ +/* + * Original work: + * + * Copyright (c) 2009-2012 Hewlett-Packard Development Company, L.P. + * + * This library is free software; you can redistribute it and/or modify + * it under the terms of the MIT license. See COPYING for details. + * + * Modified Work: + * + * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. + * + * This software product is a proprietary product of NVIDIA CORPORATION & + * AFFILIATES (the "Company") and all right, title, and interest in and to the + * software product, including all associated intellectual property rights, are + * and shall remain exclusively with the Company. + * + * This software product is governed by the End User License Agreement + * provided with the software product. + * + */ + +#include "config.h" + #include #include "json.h" @@ -53,111 +71,100 @@ /// Our current representation of the "end" iterator; /// /// @note May not always be NULL -static const void* kObjectEndIterValue = NULL; +static const void *kObjectEndIterValue = NULL; /** * **************************************************************************** */ -struct json_object_iterator -json_object_iter_begin(struct json_object* obj) +struct json_object_iterator doca_third_party_json_object_iter_begin(struct json_object *obj) { - struct json_object_iterator iter; - struct lh_table* pTable; - - /// @note json_object_get_object will return NULL if passed NULL - /// or a non-json_type_object instance - pTable = json_object_get_object(obj); - JASSERT(NULL != pTable); - - /// @note For a pair-less Object, head is NULL, which matches our - /// definition of the "end" iterator - iter.opaque_ = pTable->head; - return iter; + struct json_object_iterator iter; + struct lh_table *pTable; + + /// @note json_object_get_object will return NULL if passed NULL + /// or a non-json_type_object instance + pTable = doca_third_party_json_object_get_object(obj); + JASSERT(NULL != pTable); + + /// @note For a pair-less Object, head is NULL, which matches our + /// definition of the "end" iterator + iter.opaque_ = lh_table_head(pTable); + return iter; } /** * **************************************************************************** */ -struct json_object_iterator -json_object_iter_end(const struct json_object* obj) +struct json_object_iterator doca_third_party_json_object_iter_end(const struct json_object *obj) { - struct json_object_iterator iter; + struct json_object_iterator iter; - JASSERT(NULL != obj); - JASSERT(json_object_is_type(obj, json_type_object)); + JASSERT(NULL != obj); + JASSERT(doca_third_party_json_object_is_type(obj, json_type_object)); - iter.opaque_ = kObjectEndIterValue; + iter.opaque_ = kObjectEndIterValue; - return iter; + return iter; } /** * **************************************************************************** */ -void -json_object_iter_next(struct json_object_iterator* iter) +void doca_third_party_json_object_iter_next(struct json_object_iterator *iter) { - JASSERT(NULL != iter); - JASSERT(kObjectEndIterValue != iter->opaque_); + JASSERT(NULL != iter); + JASSERT(kObjectEndIterValue != iter->opaque_); - iter->opaque_ = ((const struct lh_entry *)iter->opaque_)->next; + iter->opaque_ = lh_entry_next(((const struct lh_entry *)iter->opaque_)); } - /** * **************************************************************************** */ -const char* -json_object_iter_peek_name(const struct json_object_iterator* iter) +const char *doca_third_party_json_object_iter_peek_name(const struct json_object_iterator *iter) { - JASSERT(NULL != iter); - JASSERT(kObjectEndIterValue != iter->opaque_); + JASSERT(NULL != iter); + JASSERT(kObjectEndIterValue != iter->opaque_); - return (const char*)(((const struct lh_entry *)iter->opaque_)->k); + return (const char *)(((const struct lh_entry *)iter->opaque_)->k); } - /** * **************************************************************************** */ -struct json_object* -json_object_iter_peek_value(const struct json_object_iterator* iter) +struct json_object *doca_third_party_json_object_iter_peek_value(const struct json_object_iterator *iter) { - JASSERT(NULL != iter); - JASSERT(kObjectEndIterValue != iter->opaque_); + JASSERT(NULL != iter); + JASSERT(kObjectEndIterValue != iter->opaque_); - return (struct json_object*)lh_entry_v((const struct lh_entry *)iter->opaque_); + return (struct json_object *)lh_entry_v((const struct lh_entry *)iter->opaque_); } - /** * **************************************************************************** */ -json_bool -json_object_iter_equal(const struct json_object_iterator* iter1, - const struct json_object_iterator* iter2) +json_bool doca_third_party_json_object_iter_equal(const struct json_object_iterator *iter1, + const struct json_object_iterator *iter2) { - JASSERT(NULL != iter1); - JASSERT(NULL != iter2); + JASSERT(NULL != iter1); + JASSERT(NULL != iter2); - return (iter1->opaque_ == iter2->opaque_); + return (iter1->opaque_ == iter2->opaque_); } - /** * **************************************************************************** */ -struct json_object_iterator -json_object_iter_init_default(void) +struct json_object_iterator doca_third_party_json_object_iter_init_default(void) { - struct json_object_iterator iter; + struct json_object_iterator iter; - /** - * @note Make this a negative, invalid value, such that - * accidental access to it would likely be trapped by the - * hardware as an invalid address. - */ - iter.opaque_ = NULL; + /** + * @note Make this a negative, invalid value, such that + * accidental access to it would likely be trapped by the + * hardware as an invalid address. + */ + iter.opaque_ = NULL; - return iter; + return iter; } diff --git a/third_party/json-c/json_object_iterator.h b/third_party/json-c/json_object_iterator.h index f226cbd52..ba02aceb8 100644 --- a/third_party/json-c/json_object_iterator.h +++ b/third_party/json-c/json_object_iterator.h @@ -1,12 +1,29 @@ +/* + * Original work: + * + * Copyright (c) 2009-2012 Hewlett-Packard Development Company, L.P. + * + * This library is free software; you can redistribute it and/or modify + * it under the terms of the MIT license. See COPYING for details. + * + * Modified Work: + * + * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. + * + * This software product is a proprietary product of NVIDIA CORPORATION & + * AFFILIATES (the "Company") and all right, title, and interest in and to the + * software product, including all associated intellectual property rights, are + * and shall remain exclusively with the Company. + * + * This software product is governed by the End User License Agreement + * provided with the software product. + * + */ + /** ******************************************************************************* * @file json_object_iterator.h * -* Copyright (c) 2009-2012 Hewlett-Packard Development Company, L.P. -* -* This library is free software; you can redistribute it and/or modify -* it under the terms of the MIT license. See COPYING for details. -* * @brief An API for iterating over json_type_object objects, * styled to be familiar to C++ programmers. * Unlike json_object_object_foreach() and @@ -20,10 +37,10 @@ ******************************************************************************* */ - #ifndef JSON_OBJECT_ITERATOR_H #define JSON_OBJECT_ITERATOR_H +#include "json_types.h" #include #ifdef __cplusplus @@ -39,17 +56,16 @@ struct json_object_iter_info_; * The opaque iterator that references a name/value pair within * a JSON Object instance or the "end" iterator value. */ -struct json_object_iterator { - const void* opaque_; +struct json_object_iterator +{ + const void *opaque_; }; - /** * forward declaration of json-c's JSON value instance structure */ struct json_object; - /** * Initializes an iterator structure to a "default" value that * is convenient for initializing an iterator variable to a @@ -72,8 +88,7 @@ struct json_object; * * @return json_object_iterator */ -struct json_object_iterator -json_object_iter_init_default(void); +JSON_EXPORT struct json_object_iterator doca_third_party_json_object_iter_init_default(void); /** Retrieves an iterator to the first pair of the JSON Object. * @@ -106,8 +121,7 @@ json_object_iter_init_default(void); * * @endcode */ -struct json_object_iterator -json_object_iter_begin(struct json_object* obj); +JSON_EXPORT struct json_object_iterator doca_third_party_json_object_iter_begin(struct json_object *obj); /** Retrieves the iterator that represents the position beyond the * last pair of the given JSON Object instance. @@ -137,8 +151,7 @@ json_object_iter_begin(struct json_object* obj); * (i.e., NOT the last pair, but "beyond the last * pair" value) */ -struct json_object_iterator -json_object_iter_end(const struct json_object* obj); +JSON_EXPORT struct json_object_iterator doca_third_party_json_object_iter_end(const struct json_object *obj); /** Returns an iterator to the next pair, if any * @@ -155,9 +168,7 @@ json_object_iter_end(const struct json_object* obj); * of json_object_iter_end() for the same JSON Object * instance. */ -void -json_object_iter_next(struct json_object_iterator* iter); - +JSON_EXPORT void doca_third_party_json_object_iter_next(struct json_object_iterator *iter); /** Returns a const pointer to the name of the pair referenced * by the given iterator. @@ -174,9 +185,7 @@ json_object_iter_next(struct json_object_iterator* iter); * deleted or modified, and MUST NOT be modified or * freed by the user. */ -const char* -json_object_iter_peek_name(const struct json_object_iterator* iter); - +JSON_EXPORT const char *doca_third_party_json_object_iter_peek_name(const struct json_object_iterator *iter); /** Returns a pointer to the json-c instance representing the * value of the referenced name/value pair, without altering @@ -197,9 +206,8 @@ json_object_iter_peek_name(const struct json_object_iterator* iter); * the JSON Null value as a NULL json_object instance * pointer. */ -struct json_object* -json_object_iter_peek_value(const struct json_object_iterator* iter); - +JSON_EXPORT struct json_object * +doca_third_party_json_object_iter_peek_value(const struct json_object_iterator *iter); /** Tests two iterators for equality. Typically used to test * for end of iteration by comparing an iterator to the @@ -227,14 +235,11 @@ json_object_iter_peek_value(const struct json_object_iterator* iter); * reference the same name/value pair or are both at * "end"); zero if they are not equal. */ -json_bool -json_object_iter_equal(const struct json_object_iterator* iter1, - const struct json_object_iterator* iter2); - +JSON_EXPORT json_bool doca_third_party_json_object_iter_equal(const struct json_object_iterator *iter1, + const struct json_object_iterator *iter2); #ifdef __cplusplus } #endif - #endif /* JSON_OBJECT_ITERATOR_H */ diff --git a/third_party/json-c/json_object_private.h b/third_party/json-c/json_object_private.h index 53be70db0..652969ece 100644 --- a/third_party/json-c/json_object_private.h +++ b/third_party/json-c/json_object_private.h @@ -1,4 +1,6 @@ /* + * Original work: + * * $Id: json_object_private.h,v 1.4 2006/01/26 02:16:28 mclark Exp $ * * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd. @@ -7,6 +9,18 @@ * This library is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See COPYING for details. * + * Modified Work: + * + * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. + * + * This software product is a proprietary product of NVIDIA CORPORATION & + * AFFILIATES (the "Company") and all right, title, and interest in and to the + * software product, including all associated intellectual property rights, are + * and shall remain exclusively with the Company. + * + * This software product is governed by the End User License Agreement + * provided with the software product. + * */ /** @@ -20,42 +34,85 @@ extern "C" { #endif -#define LEN_DIRECT_STRING_DATA 32 /**< how many bytes are directly stored in json_object for strings? */ +struct json_object; +#include "json_inttypes.h" +#include "json_types.h" + +#ifdef HAVE_UNISTD_H +#include +#endif /* HAVE_UNISTD_H */ -typedef void (json_object_private_delete_fn)(struct json_object *o); +#ifdef _MSC_VER +#include +typedef SSIZE_T ssize_t; +#endif + +/* json object int type, support extension*/ +typedef enum json_object_int_type +{ + json_object_int_type_int64, + json_object_int_type_uint64 +} json_object_int_type; struct json_object { - enum json_type o_type; - json_object_private_delete_fn *_delete; - json_object_to_json_string_fn *_to_json_string; - int _ref_count; - struct printbuf *_pb; - union data { - json_bool c_boolean; - double c_double; - int64_t c_int64; - struct lh_table *c_object; - struct array_list *c_array; - struct { - union { - /* optimize: if we have small strings, we can store them - * directly. This saves considerable CPU cycles AND memory. - */ - char *ptr; - char data[LEN_DIRECT_STRING_DATA]; - } str; - int len; - } c_string; - } o; - json_object_delete_fn *_user_delete; - void *_userdata; + enum json_type o_type; + uint32_t _ref_count; + json_object_to_json_string_fn *_to_json_string; + struct printbuf *_pb; + json_object_delete_fn *_user_delete; + void *_userdata; + // Actually longer, always malloc'd as some more-specific type. + // The rest of a struct json_object_${o_type} follows +}; + +struct json_object_object +{ + struct json_object base; + struct lh_table *c_object; +}; +struct json_object_array +{ + struct json_object base; + struct array_list *c_array; +}; + +struct json_object_boolean +{ + struct json_object base; + json_bool c_boolean; +}; +struct json_object_double +{ + struct json_object base; + double c_double; +}; +struct json_object_int +{ + struct json_object base; + enum json_object_int_type cint_type; + union + { + int64_t c_int64; + uint64_t c_uint64; + } cint; +}; +struct json_object_string +{ + struct json_object base; + ssize_t len; // Signed b/c negative lengths indicate data is a pointer + // Consider adding an "alloc" field here, if json_object_set_string calls + // to expand the length of a string are common operations to perform. + union + { + char idata[1]; // Immediate data. Actually longer + char *pdata; // Only when len < 0 + } c_string; }; -void _json_c_set_last_err(const char *err_fmt, ...); +void doca_third_party__json_c_set_last_err(const char *err_fmt, ...); -extern const char *json_number_chars; -extern const char *json_hex_chars; +extern const char *doca_third_party_json_hex_chars; #ifdef __cplusplus } diff --git a/third_party/json-c/json_patch.c b/third_party/json-c/json_patch.c new file mode 100644 index 000000000..f8a04e55f --- /dev/null +++ b/third_party/json-c/json_patch.c @@ -0,0 +1,377 @@ +/* + * Original work: + * + * Copyright (c) 2021 Alexandru Ardelean. + * Copyright (c) 2023 Eric Hawicz + * + * This is free software; you can redistribute it and/or modify + * it under the terms of the MIT license. See COPYING for details. + * + * Modified Work: + * + * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. + * + * This software product is a proprietary product of NVIDIA CORPORATION & + * AFFILIATES (the "Company") and all right, title, and interest in and to the + * software product, including all associated intellectual property rights, are + * and shall remain exclusively with the Company. + * + * This software product is governed by the End User License Agreement + * provided with the software product. + * + */ + +#include "config.h" + +#include +#include +#include + +#include "json_object_private.h" +#include "json_patch.h" +#include "json_pointer_private.h" + +#include +#ifndef SIZE_T_MAX +#if SIZEOF_SIZE_T == SIZEOF_INT +#define SIZE_T_MAX UINT_MAX +#elif SIZEOF_SIZE_T == SIZEOF_LONG +#define SIZE_T_MAX ULONG_MAX +#elif SIZEOF_SIZE_T == SIZEOF_LONG_LONG +#define SIZE_T_MAX ULLONG_MAX +#else +#error Unable to determine size of size_t +#endif +#endif + +#define _set_err(_errval, _errmsg) \ + do \ + { \ + patch_error->errno_code = (_errval); \ + patch_error->errmsg = (_errmsg); \ + errno = 0; /* To avoid confusion */ \ + } while (0) + +#define _set_err_from_ptrget(_errval, _fieldname) \ + do \ + { \ + patch_error->errno_code = (_errval); \ + patch_error->errmsg = (_errval) == ENOENT \ + ? "Did not find element referenced by " _fieldname \ + " field" \ + : "Invalid " _fieldname " field"; \ + errno = 0; /* To avoid confusion */ \ + } while (0) + +/** + * JavaScript Object Notation (JSON) Patch + * RFC 6902 - https://tools.ietf.org/html/rfc6902 + */ + +static int json_patch_apply_test(struct json_object **res, struct json_object *patch_elem, + const char *path, struct json_patch_error *patch_error) +{ + struct json_object *value1, *value2; + + if (!doca_third_party_json_object_object_get_ex(patch_elem, "value", &value1)) + { + _set_err(EINVAL, "Patch object does not contain a 'value' field"); + return -1; + } + + if (doca_third_party_json_pointer_get(*res, path, &value2)) + { + _set_err_from_ptrget(errno, "path"); + return -1; + } + + if (!doca_third_party_json_object_equal(value1, value2)) + { + _set_err(ENOENT, + "Value of element referenced by 'path' field did not match 'value' field"); + return -1; + } + + return 0; +} + +static int __json_patch_apply_remove(struct json_pointer_get_result *jpres) +{ + if (doca_third_party_json_object_is_type(jpres->parent, json_type_array)) + { + return doca_third_party_json_object_array_del_idx(jpres->parent, + jpres->index_in_parent, 1); + } + else if (jpres->parent && jpres->key_in_parent) + { + doca_third_party_json_object_object_del(jpres->parent, jpres->key_in_parent); + return 0; + } + else + { + // We're removing the root object + (void)doca_third_party_json_object_put(jpres->obj); + jpres->obj = NULL; + return 0; + } +} + +static int json_patch_apply_remove(struct json_object **res, const char *path, + struct json_patch_error *patch_error) +{ + struct json_pointer_get_result jpres; + int rc; + + if (doca_third_party_json_pointer_get_internal(*res, path, &jpres)) + { + _set_err_from_ptrget(errno, "path"); + return -1; + } + + rc = __json_patch_apply_remove(&jpres); + if (rc < 0) + _set_err(EINVAL, "Unable to remove path referenced by 'path' field"); + // This means we removed and freed the root object, i.e. *res + if (jpres.parent == NULL) + *res = NULL; + return rc; +} + +// callback for json_pointer_set_with_array_cb() +static int json_object_array_insert_idx_cb(struct json_object *parent, size_t idx, + struct json_object *value, void *priv) +{ + int rc; + int *add = priv; + + if (idx > doca_third_party_json_object_array_length(parent)) + { + // Note: will propagate back out through json_pointer_set_with_array_cb() + errno = EINVAL; + return -1; + } + + if (*add) + rc = doca_third_party_json_object_array_insert_idx(parent, idx, value); + else + rc = doca_third_party_json_object_array_put_idx(parent, idx, value); + if (rc < 0) + errno = EINVAL; + return rc; +} + +static int json_patch_apply_add_replace(struct json_object **res, struct json_object *patch_elem, + const char *path, int add, + struct json_patch_error *patch_error) +{ + struct json_object *value; + int rc; + + if (!doca_third_party_json_object_object_get_ex(patch_elem, "value", &value)) + { + _set_err(EINVAL, "Patch object does not contain a 'value' field"); + return -1; + } + /* if this is a replace op, then we need to make sure it exists before replacing */ + if (!add && doca_third_party_json_pointer_get(*res, path, NULL)) + { + _set_err_from_ptrget(errno, "path"); + return -1; + } + + rc = doca_third_party_json_pointer_set_with_array_cb( + res, path, doca_third_party_json_object_get(value), json_object_array_insert_idx_cb, + &add); + if (rc) + { + _set_err(errno, "Failed to set value at path referenced by 'path' field"); + doca_third_party_json_object_put(value); + } + + return rc; +} + +// callback for json_pointer_set_with_array_cb() +static int json_object_array_move_cb(struct json_object *parent, size_t idx, + struct json_object *value, void *priv) +{ + int rc; + struct json_pointer_get_result *from = priv; + size_t len = doca_third_party_json_object_array_length(parent); + + /** + * If it's the same array parent, it means that we removed + * and element from it, so the length is temporarily reduced + * by 1, which means that if we try to move an element to + * the last position, we need to check the current length + 1 + */ + if (parent == from->parent) + len++; + + if (idx > len) + { + // Note: will propagate back out through json_pointer_set_with_array_cb() + errno = EINVAL; + return -1; + } + + rc = doca_third_party_json_object_array_insert_idx(parent, idx, value); + if (rc < 0) + errno = EINVAL; + return rc; +} + +static int json_patch_apply_move_copy(struct json_object **res, struct json_object *patch_elem, + const char *path, int move, + struct json_patch_error *patch_error) +{ + json_pointer_array_set_cb array_set_cb; + struct json_pointer_get_result from; + struct json_object *jfrom; + const char *from_s; + size_t from_s_len; + int rc; + + if (!doca_third_party_json_object_object_get_ex(patch_elem, "from", &jfrom)) + { + _set_err(EINVAL, "Patch does not contain a 'from' field"); + return -1; + } + + from_s = doca_third_party_json_object_get_string(jfrom); + + from_s_len = strlen(from_s); + if (strncmp(from_s, path, from_s_len) == 0) + { + /** + * If lengths match, it's a noop, if they don't, + * then we're trying to move a parent under a child + * which is not allowed as per RFC 6902 section 4.4 + * The "from" location MUST NOT be a proper prefix of the "path" + * location; i.e., a location cannot be moved into one of its children. + */ + if (from_s_len == strlen(path)) + return 0; + _set_err(EINVAL, "Invalid attempt to move parent under a child"); + return -1; + } + + rc = doca_third_party_json_pointer_get_internal(*res, from_s, &from); + if (rc) + { + _set_err_from_ptrget(errno, "from"); + return rc; + } + + // Note: it's impossible for json_pointer to find the root obj, due + // to the path check above, so from.parent is guaranteed non-NULL + doca_third_party_json_object_get(from.obj); + + if (!move) + { + array_set_cb = json_object_array_insert_idx_cb; + } + else + { + rc = __json_patch_apply_remove(&from); + if (rc < 0) + { + doca_third_party_json_object_put(from.obj); + return rc; + } + array_set_cb = json_object_array_move_cb; + } + + rc =doca_third_party_json_pointer_set_with_array_cb(res, path, from.obj, array_set_cb, + &from); + if (rc) + { + _set_err(errno, "Failed to set value at path referenced by 'path' field"); + doca_third_party_json_object_put(from.obj); + } + + return rc; +} + +int doca_third_party_json_patch_apply(struct json_object *copy_from, struct json_object *patch, + struct json_object **base, + struct json_patch_error *patch_error) +{ + size_t ii; + int rc = 0; + struct json_patch_error placeholder; + + if (!patch_error) + patch_error = &placeholder; + + patch_error->patch_failure_idx = SIZE_T_MAX; + patch_error->errno_code = 0; + + if (base == NULL || (*base == NULL && copy_from == NULL) || + (*base != NULL && copy_from != NULL)) + { + _set_err(EFAULT, "Exactly one of *base or copy_from must be non-NULL"); + return -1; + } + + if (!doca_third_party_json_object_is_type(patch, json_type_array)) + { + _set_err(EFAULT, "Patch object is not of type json_type_array"); + return -1; + } + + if (copy_from != NULL) + { + if (doca_third_party_json_object_deep_copy(copy_from, base, NULL) < 0) + { + _set_err(ENOMEM, "Unable to copy copy_from using json_object_deep_copy()"); + return -1; + } + } + + /* Go through all operations ; apply them on res */ + for (ii = 0; ii < doca_third_party_json_object_array_length(patch); ii++) + { + struct json_object *jop, *jpath; + struct json_object *patch_elem = + doca_third_party_json_object_array_get_idx(patch, ii); + const char *op, *path; + + patch_error->patch_failure_idx = ii; + + if (!doca_third_party_json_object_object_get_ex(patch_elem, "op", &jop)) + { + _set_err(EINVAL, "Patch object does not contain 'op' field"); + return -1; + } + op = doca_third_party_json_object_get_string(jop); + if (!doca_third_party_json_object_object_get_ex(patch_elem, "path", &jpath)) + { + _set_err(EINVAL, "Patch object does not contain 'path' field"); + return -1; + } + path = doca_third_party_json_object_get_string(jpath); // Note: empty string is ok! + + if (!strcmp(op, "test")) + rc = json_patch_apply_test(base, patch_elem, path, patch_error); + else if (!strcmp(op, "remove")) + rc = json_patch_apply_remove(base, path, patch_error); + else if (!strcmp(op, "add")) + rc = json_patch_apply_add_replace(base, patch_elem, path, 1, patch_error); + else if (!strcmp(op, "replace")) + rc = json_patch_apply_add_replace(base, patch_elem, path, 0, patch_error); + else if (!strcmp(op, "move")) + rc = json_patch_apply_move_copy(base, patch_elem, path, 1, patch_error); + else if (!strcmp(op, "copy")) + rc = json_patch_apply_move_copy(base, patch_elem, path, 0, patch_error); + else + { + _set_err(EINVAL, "Patch object has invalid 'op' field"); + return -1; + } + if (rc < 0) + break; + } + + return rc; +} diff --git a/third_party/json-c/json_patch.h b/third_party/json-c/json_patch.h new file mode 100644 index 000000000..e6a7a3b33 --- /dev/null +++ b/third_party/json-c/json_patch.h @@ -0,0 +1,94 @@ +/* + * Original work: + * + * Copyright (c) 2021 Alexadru Ardelean. + * + * This is free software; you can redistribute it and/or modify + * it under the terms of the MIT license. See COPYING for details. + * + * Modified Work: + * + * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. + * + * This software product is a proprietary product of NVIDIA CORPORATION & + * AFFILIATES (the "Company") and all right, title, and interest in and to the + * software product, including all associated intellectual property rights, are + * and shall remain exclusively with the Company. + * + * This software product is governed by the End User License Agreement + * provided with the software product. + * + */ + +/** + * @file + * @brief JSON Patch (RFC 6902) implementation for manipulating JSON objects + */ +#ifndef _json_patch_h_ +#define _json_patch_h_ + +#include "json_pointer.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Details of an error that occurred during json_patch_apply() + */ +struct json_patch_error { + /** + * An errno value indicating what kind of error occurred. + * Possible values include: + * - ENOENT - A path referenced in the operation does not exist. + * - EINVAL - An invalid operation or with invalid path was attempted + * - ENOMEM - Unable to allocate memory + * - EFAULT - Invalid arguments were passed to json_patch_apply() + * (i.e. a C API error, vs. a data error like EINVAL) + */ + int errno_code; + + /** + * The index into the patch array of the operation that failed, + * or SIZE_T_MAX for overall errors. + */ + size_t patch_failure_idx; + + /** + * A human readable error message. + * Allocated from static storage, does not need to be freed. + */ + const char *errmsg; +}; + +/** + * Apply the JSON patch to the base object. + * The patch object must be formatted as per RFC 6902, i.e. + * a json_type_array containing patch operations. + * If the patch is not correctly formatted, an error will + * be returned. + * + * The json_object at *base will be modified in place. + * Exactly one of *base or copy_from must be non-NULL. + * If *base is NULL, a new copy of copy_from will allocated and populated + * using json_object_deep_copy(). In this case json_object_put() _must_ be + * used to free *base even if the overall patching operation fails. + * + * If anything fails during patching a negative value will be returned, + * and patch_error (if non-NULL) will be populated with error details. + * + * @param base a pointer to the JSON object which to patch + * @param patch the JSON object that describes the patch to be applied + * @param copy_from a JSON object to copy to *base + * @param patch_error optional, details about errors + * + * @return negative if an error (or not found), or 0 if patch completely applied + */ +JSON_EXPORT int doca_third_party_json_patch_apply(struct json_object *copy_from, struct json_object *patch, + struct json_object **base, struct json_patch_error *patch_error); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/third_party/json-c/json_pointer.c b/third_party/json-c/json_pointer.c index 2b2a9ef50..2f988c528 100644 --- a/third_party/json-c/json_pointer.c +++ b/third_party/json-c/json_pointer.c @@ -1,9 +1,23 @@ /* - * Copyright (c) 2016 Alexandru Ardelean. + * Original work: + * + * Copyright (c) 2016 Alexadru Ardelean. * * This is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See COPYING for details. * + * Modified Work: + * + * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. + * + * This software product is a proprietary product of NVIDIA CORPORATION & + * AFFILIATES (the "Company") and all right, title, and interest in and to the + * software product, including all associated intellectual property rights, are + * and shall remain exclusively with the Company. + * + * This software product is governed by the End User License Agreement + * provided with the software product. + * */ #include "config.h" @@ -14,12 +28,16 @@ #include #include #include -#include +#include "json_object_private.h" #include "json_pointer.h" +#include "json_pointer_private.h" #include "strdup_compat.h" #include "vasprintf_compat.h" +/* Avoid ctype.h and locale overhead */ +#define is_plain_digit(c) ((c) >= '0' && (c) <= '9') + /** * JavaScript Object Notation (JSON) Pointer * RFC 6901 - https://tools.ietf.org/html/rfc6901 @@ -27,10 +45,12 @@ static void string_replace_all_occurrences_with_char(char *s, const char *occur, char repl_char) { - int slen = strlen(s); - int skip = strlen(occur) - 1; /* length of the occurence, minus the char we're replacing */ + size_t slen = strlen(s); + size_t skip = + strlen(occur) - 1; /* length of the occurrence, minus the char we're replacing */ char *p = s; - while ((p = strstr(p, occur))) { + while ((p = strstr(p, occur))) + { *p = repl_char; p++; slen -= skip; @@ -38,55 +58,61 @@ static void string_replace_all_occurrences_with_char(char *s, const char *occur, } } -static int is_valid_index(struct json_object *jo, const char *path, int32_t *idx) +static int is_valid_index(const char *path, size_t *idx) { - int i, len = strlen(path); - /* this code-path optimizes a bit, for when we reference the 0-9 index range in a JSON array - and because leading zeros not allowed */ - if (len == 1) { - if (isdigit((int)path[0])) { + size_t i, len = strlen(path); + /* this code-path optimizes a bit, for when we reference the 0-9 index range + * in a JSON array and because leading zeros not allowed + */ + if (len == 1) + { + if (is_plain_digit(path[0])) + { *idx = (path[0] - '0'); - goto check_oob; + return 1; } errno = EINVAL; return 0; } /* leading zeros not allowed per RFC */ - if (path[0] == '0') { + if (path[0] == '0') + { errno = EINVAL; return 0; } /* RFC states base-10 decimals */ - for (i = 0; i < len; i++) { - if (!isdigit((int)path[i])) { + for (i = 0; i < len; i++) + { + if (!is_plain_digit(path[i])) + { errno = EINVAL; return 0; } } - *idx = strtol(path, NULL, 10); - if (*idx < 0) { - errno = EINVAL; - return 0; - } -check_oob: - len = json_object_array_length(jo); - if (*idx >= len) { - errno = ENOENT; - return 0; - } + // We know it's all digits, so the only error case here is overflow, + // but ULLONG_MAX will be longer than any array length so that's ok. + *idx = strtoull(path, NULL, 10); return 1; } -static int json_pointer_get_single_path(struct json_object *obj, char *path, struct json_object **value) +static int json_pointer_get_single_path(struct json_object *obj, char *path, + struct json_object **value, size_t *idx) { - if (json_object_is_type(obj, json_type_array)) { - int32_t idx; - if (!is_valid_index(obj, path, &idx)) + if (doca_third_party_json_object_is_type(obj, json_type_array)) + { + if (!is_valid_index(path, idx)) return -1; - obj = json_object_array_get_idx(obj, idx); - if (obj) { + if (*idx >= doca_third_party_json_object_array_length(obj)) + { + errno = ENOENT; + return -1; + } + + obj = doca_third_party_json_object_array_get_idx(obj, *idx); + if (obj) + { if (value) *value = obj; return 0; @@ -100,7 +126,8 @@ static int json_pointer_get_single_path(struct json_object *obj, char *path, str string_replace_all_occurrences_with_char(path, "~1", '/'); string_replace_all_occurrences_with_char(path, "~0", '~'); - if (!json_object_object_get_ex(obj, path, value)) { + if (!doca_third_party_json_object_object_get_ex(obj, path, value)) + { errno = ENOENT; return -1; } @@ -108,42 +135,51 @@ static int json_pointer_get_single_path(struct json_object *obj, char *path, str return 0; } -static int json_pointer_set_single_path( - struct json_object *parent, - const char *path, - struct json_object *value) +static int json_object_array_put_idx_cb(struct json_object *parent, size_t idx, + struct json_object *value, void *priv) +{ + return doca_third_party_json_object_array_put_idx(parent, idx, value); +} + +static int json_pointer_set_single_path(struct json_object *parent, const char *path, + struct json_object *value, + json_pointer_array_set_cb array_set_cb, void *priv) { - if (json_object_is_type(parent, json_type_array)) { - int32_t idx; + if (doca_third_party_json_object_is_type(parent, json_type_array)) + { + size_t idx; /* RFC (Chapter 4) states that '-' may be used to add new elements to an array */ if (path[0] == '-' && path[1] == '\0') - return json_object_array_add(parent, value); - if (!is_valid_index(parent, path, &idx)) + return doca_third_party_json_object_array_add(parent, value); + if (!is_valid_index(path, &idx)) return -1; - return json_object_array_put_idx(parent, idx, value); + return array_set_cb(parent, idx, value, priv); } /* path replacements should have been done in json_pointer_get_single_path(), - and we should still be good here */ - if (json_object_is_type(parent, json_type_object)) - return json_object_object_add(parent, path, value); - - /* Getting here means that we tried to "dereference" a primitive JSON type (like string, int, bool). - i.e. add a sub-object to it */ + * and we should still be good here + */ + if (doca_third_party_json_object_is_type(parent, json_type_object)) + return doca_third_party_json_object_object_add(parent, path, value); + + /* Getting here means that we tried to "dereference" a primitive JSON type + * (like string, int, bool).i.e. add a sub-object to it + */ errno = ENOENT; return -1; } -static int json_pointer_get_recursive( - struct json_object *obj, - char *path, - struct json_object **value) +static int json_pointer_result_get_recursive(struct json_object *obj, char *path, + struct json_pointer_get_result *res) { + struct json_object *parent_obj = obj; + size_t idx = 0; /* Resolve compile warning in old GCC versions */ char *endp; int rc; /* All paths (on each recursion level must have a leading '/' */ - if (path[0] != '/') { + if (path[0] != '/') + { errno = EINVAL; return -1; } @@ -154,55 +190,108 @@ static int json_pointer_get_recursive( *endp = '\0'; /* If we err-ed here, return here */ - if ((rc = json_pointer_get_single_path(obj, path, &obj))) + if ((rc = json_pointer_get_single_path(obj, path, &obj, &idx))) return rc; - if (endp) { - *endp = '/'; /* Put the slash back, so that the sanity check passes on next recursion level */ - return json_pointer_get_recursive(obj, endp, value); + if (endp) + { + /* Put the slash back, so that the sanity check passes on next recursion level */ + *endp = '/'; + return json_pointer_result_get_recursive(obj, endp, res); } /* We should be at the end of the recursion here */ + if (res) + { + res->parent = parent_obj; + res->obj = obj; + if (doca_third_party_json_object_is_type(res->parent, json_type_array)) + res->index_in_parent = idx; + else + res->key_in_parent = path; + } + + return 0; +} + +static int json_pointer_object_get_recursive(struct json_object *obj, char *path, + struct json_object **value) +{ + struct json_pointer_get_result res; + int rc; + + rc = json_pointer_result_get_recursive(obj, path, &res); + if (rc) + return rc; + if (value) - *value = obj; + *value = res.obj; return 0; } -int json_pointer_get(struct json_object *obj, const char *path, struct json_object **res) +int doca_third_party_json_pointer_get_internal(struct json_object *obj, const char *path, + struct json_pointer_get_result *res) { char *path_copy = NULL; int rc; - if (!obj || !path) { + if (!obj || !path) + { errno = EINVAL; return -1; } - if (path[0] == '\0') { - if (res) - *res = obj; + if (path[0] == '\0') + { + res->parent = NULL; + res->obj = obj; + res->key_in_parent = NULL; + res->index_in_parent = -1; return 0; } /* pass a working copy to the recursive call */ - if (!(path_copy = strdup(path))) { + if (!(path_copy = strdup(path))) + { errno = ENOMEM; return -1; } - rc = json_pointer_get_recursive(obj, path_copy, res); + rc = json_pointer_result_get_recursive(obj, path_copy, res); + /* re-map the path string to the const-path string */ + if (rc == 0 && doca_third_party_json_object_is_type(res->parent, json_type_object) && + res->key_in_parent) + res->key_in_parent = path + (res->key_in_parent - path_copy); free(path_copy); return rc; } -int json_pointer_getf(struct json_object *obj, struct json_object **res, const char *path_fmt, ...) +int doca_third_party_json_pointer_get(struct json_object *obj, const char *path, + struct json_object **res) +{ + struct json_pointer_get_result jpres; + int rc; + + rc = doca_third_party_json_pointer_get_internal(obj, path, &jpres); + if (rc) + return rc; + + if (res) + *res = jpres.obj; + + return 0; +} + +int doca_third_party_json_pointer_getf(struct json_object *obj, struct json_object **res, + const char *path_fmt, ...) { char *path_copy = NULL; int rc = 0; va_list args; - if (!obj || !path_fmt) { + if (!obj || !path_fmt) + { errno = EINVAL; return -1; } @@ -214,65 +303,82 @@ int json_pointer_getf(struct json_object *obj, struct json_object **res, const c if (rc < 0) return rc; - if (path_copy[0] == '\0') { + if (path_copy[0] == '\0') + { if (res) *res = obj; goto out; } - rc = json_pointer_get_recursive(obj, path_copy, res); + rc = json_pointer_object_get_recursive(obj, path_copy, res); out: free(path_copy); return rc; } -int json_pointer_set(struct json_object **obj, const char *path, struct json_object *value) +int doca_third_party_json_pointer_set_with_array_cb(struct json_object **obj, const char *path, + struct json_object *value, + json_pointer_array_set_cb array_set_cb, + void *priv) { const char *endp; char *path_copy = NULL; struct json_object *set = NULL; int rc; - if (!obj || !path) { + if (!obj || !path) + { errno = EINVAL; return -1; } - if (path[0] == '\0') { - json_object_put(*obj); + if (path[0] == '\0') + { + doca_third_party_json_object_put(*obj); *obj = value; return 0; } - if (path[0] != '/') { + if (path[0] != '/') + { errno = EINVAL; return -1; } /* If there's only 1 level to set, stop here */ - if ((endp = strrchr(path, '/')) == path) { + if ((endp = strrchr(path, '/')) == path) + { path++; - return json_pointer_set_single_path(*obj, path, value); + return json_pointer_set_single_path(*obj, path, value, array_set_cb, priv); } /* pass a working copy to the recursive call */ - if (!(path_copy = strdup(path))) { + if (!(path_copy = strdup(path))) + { errno = ENOMEM; return -1; } path_copy[endp - path] = '\0'; - rc = json_pointer_get_recursive(*obj, path_copy, &set); + rc = json_pointer_object_get_recursive(*obj, path_copy, &set); free(path_copy); if (rc) return rc; endp++; - return json_pointer_set_single_path(set, endp, value); + return json_pointer_set_single_path(set, endp, value, array_set_cb, priv); } -int json_pointer_setf(struct json_object **obj, struct json_object *value, const char *path_fmt, ...) +int doca_third_party_json_pointer_set(struct json_object **obj, const char *path, + struct json_object *value) +{ + return doca_third_party_json_pointer_set_with_array_cb(obj, path, value, + json_object_array_put_idx_cb, NULL); +} + +int doca_third_party_json_pointer_setf(struct json_object **obj, struct json_object *value, + const char *path_fmt, ...) { char *endp; char *path_copy = NULL; @@ -280,7 +386,8 @@ int json_pointer_setf(struct json_object **obj, struct json_object *value, const va_list args; int rc = 0; - if (!obj || !path_fmt) { + if (!obj || !path_fmt) + { errno = EINVAL; return -1; } @@ -293,35 +400,37 @@ int json_pointer_setf(struct json_object **obj, struct json_object *value, const if (rc < 0) return rc; - if (path_copy[0] == '\0') { - json_object_put(*obj); + if (path_copy[0] == '\0') + { + doca_third_party_json_object_put(*obj); *obj = value; goto out; } - if (path_copy[0] != '/') { + if (path_copy[0] != '/') + { errno = EINVAL; rc = -1; goto out; } /* If there's only 1 level to set, stop here */ - if ((endp = strrchr(path_copy, '/')) == path_copy) { + if ((endp = strrchr(path_copy, '/')) == path_copy) + { set = *obj; goto set_single_path; } *endp = '\0'; - rc = json_pointer_get_recursive(*obj, path_copy, &set); + rc = json_pointer_object_get_recursive(*obj, path_copy, &set); if (rc) goto out; set_single_path: endp++; - rc = json_pointer_set_single_path(set, endp, value); + rc = json_pointer_set_single_path(set, endp, value, json_object_array_put_idx_cb, NULL); out: free(path_copy); return rc; } - diff --git a/third_party/json-c/json_pointer.h b/third_party/json-c/json_pointer.h index b8746c0c9..ee9a4791a 100644 --- a/third_party/json-c/json_pointer.h +++ b/third_party/json-c/json_pointer.h @@ -1,9 +1,23 @@ /* + * Original work: + * * Copyright (c) 2016 Alexadru Ardelean. * * This is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See COPYING for details. * + * Modified Work: + * + * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. + * + * This software product is a proprietary product of NVIDIA CORPORATION & + * AFFILIATES (the "Company") and all right, title, and interest in and to the + * software product, including all associated intellectual property rights, are + * and shall remain exclusively with the Company. + * + * This software product is governed by the End User License Agreement + * provided with the software product. + * */ /** @@ -32,37 +46,36 @@ extern "C" { * Internally, this is equivalent to doing a series of 'json_object_object_get()' * and 'json_object_array_get_idx()' along the given 'path'. * - * Note that the 'path' string supports 'printf()' type arguments, so, whatever - * is added after the 'res' param will be treated as an argument for 'path' - * Example: json_pointer_get(obj, "/foo/%d/%s", &res, 0, bar) - * This means, that you need to escape '%' with '%%' (just like in printf()) - * * @param obj the json_object instance/tree from where to retrieve sub-objects * @param path a (RFC6901) string notation for the sub-object to retrieve - * @param res a pointer where to store a reference to the json_object + * @param res a pointer that stores a reference to the json_object * associated with the given path * * @return negative if an error (or not found), or 0 if succeeded */ -int json_pointer_get(struct json_object *obj, const char *path, struct json_object **res); +JSON_EXPORT int doca_third_party_json_pointer_get(struct json_object *obj, const char *path, + struct json_object **res); /** * This is a variant of 'json_pointer_get()' that supports printf() style arguments. * - * Example: json_pointer_getf(obj, res, "/foo/%d/%s", 0, bak) + * Variable arguments go after the 'path_fmt' parameter. + * + * Example: json_pointer_getf(obj, res, "/foo/%d/%s", 0, "bar") * This also means that you need to escape '%' with '%%' (just like in printf()) * * Please take into consideration all recommended 'printf()' format security * aspects when using this function. * * @param obj the json_object instance/tree to which to add a sub-object - * @param res a pointer where to store a reference to the json_object + * @param res a pointer that stores a reference to the json_object * associated with the given path * @param path_fmt a printf() style format for the path * * @return negative if an error (or not found), or 0 if succeeded */ -int json_pointer_getf(struct json_object *obj, struct json_object **res, const char *path_fmt, ...); +JSON_EXPORT int doca_third_party_json_pointer_getf(struct json_object *obj, struct json_object **res, + const char *path_fmt, ...); /** * Sets JSON object 'value' in the 'obj' tree at the location specified @@ -82,23 +95,21 @@ int json_pointer_getf(struct json_object *obj, struct json_object **res, const c * That also implies that 'json_pointer_set()' does not do any refcount incrementing. * (Just that single decrement that was mentioned above). * - * Note that the 'path' string supports 'printf()' type arguments, so, whatever - * is added after the 'value' param will be treated as an argument for 'path' - * Example: json_pointer_set(obj, "/foo/%d/%s", value, 0, bak) - * This means, that you need to escape '%' with '%%' (just like in printf()) - * * @param obj the json_object instance/tree to which to add a sub-object * @param path a (RFC6901) string notation for the sub-object to set in the tree * @param value object to set at path * * @return negative if an error (or not found), or 0 if succeeded */ -int json_pointer_set(struct json_object **obj, const char *path, struct json_object *value); +JSON_EXPORT int doca_third_party_json_pointer_set(struct json_object **obj, const char *path, + struct json_object *value); /** * This is a variant of 'json_pointer_set()' that supports printf() style arguments. * - * Example: json_pointer_setf(obj, value, "/foo/%d/%s", 0, bak) + * Variable arguments go after the 'path_fmt' parameter. + * + * Example: json_pointer_setf(obj, value, "/foo/%d/%s", 0, "bar") * This also means that you need to escape '%' with '%%' (just like in printf()) * * Please take into consideration all recommended 'printf()' format security @@ -110,8 +121,8 @@ int json_pointer_set(struct json_object **obj, const char *path, struct json_obj * * @return negative if an error (or not found), or 0 if succeeded */ -int json_pointer_setf(struct json_object **obj, struct json_object *value, const char *path_fmt, ...); - +JSON_EXPORT int doca_third_party_json_pointer_setf(struct json_object **obj, struct json_object *value, + const char *path_fmt, ...); #ifdef __cplusplus } diff --git a/third_party/json-c/json_pointer_private.h b/third_party/json-c/json_pointer_private.h new file mode 100644 index 000000000..076300996 --- /dev/null +++ b/third_party/json-c/json_pointer_private.h @@ -0,0 +1,58 @@ +/* + * Original work: + * + * Copyright (c) 2023 Eric Hawicz + * + * This library is free software; you can redistribute it and/or modify + * it under the terms of the MIT license. See COPYING for details. + * + * Modified Work: + * + * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. + * + * This software product is a proprietary product of NVIDIA CORPORATION & + * AFFILIATES (the "Company") and all right, title, and interest in and to the + * software product, including all associated intellectual property rights, are + * and shall remain exclusively with the Company. + * + * This software product is governed by the End User License Agreement + * provided with the software product. + * + */ + +/** + * @file + * @brief Do not use, json-c internal, may be changed or removed at any time. + */ +#ifndef _json_pointer_private_h_ +#define _json_pointer_private_h_ + +#ifdef __cplusplus +extern "C" { +#endif + +struct json_pointer_get_result { + struct json_object *parent; + struct json_object *obj; + // The key of the found object; only valid when parent is json_type_object + // Caution: re-uses tail end of the `path` argument to json_pointer_get_internal + const char *key_in_parent; + // the index of the found object; only valid when parent is json_type_array + uint32_t index_in_parent; +}; + +int doca_third_party_json_pointer_get_internal(struct json_object *obj, const char *path, + struct json_pointer_get_result *res); + +typedef int(*json_pointer_array_set_cb)(json_object *parent, size_t idx, + json_object *value, void *priv); + +int doca_third_party_json_pointer_set_with_array_cb(struct json_object **obj, const char *path, + struct json_object *value, + json_pointer_array_set_cb array_set_cb, void *priv); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/third_party/json-c/json_tokener.c b/third_party/json-c/json_tokener.c index 449a82da6..0f1a00a08 100644 --- a/third_party/json-c/json_tokener.c +++ b/third_party/json-c/json_tokener.c @@ -1,4 +1,6 @@ /* + * Original work: + * * $Id: json_tokener.c,v 1.20 2006/07/25 03:24:50 mclark Exp $ * * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd. @@ -10,28 +12,41 @@ * * Copyright (c) 2008-2009 Yahoo! Inc. All rights reserved. * The copyrights to the contents of this file are licensed under the MIT License - * (http://www.opensource.org/licenses/mit-license.php) + * (https://www.opensource.org/licenses/mit-license.php) + * + * Modified Work: + * + * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. + * + * This software product is a proprietary product of NVIDIA CORPORATION & + * AFFILIATES (the "Company") and all right, title, and interest in and to the + * software product, including all associated intellectual property rights, are + * and shall remain exclusively with the Company. + * + * This software product is governed by the End User License Agreement + * provided with the software product. + * */ #include "config.h" -#include #include "math_compat.h" +#include +#include +#include +#include +#include #include #include -#include -#include #include -#include #include "debug.h" -#include "printbuf.h" -#include "arraylist.h" #include "json_inttypes.h" #include "json_object.h" #include "json_object_private.h" #include "json_tokener.h" #include "json_util.h" +#include "printbuf.h" #include "strdup_compat.h" #ifdef HAVE_LOCALE_H @@ -40,16 +55,42 @@ #ifdef HAVE_XLOCALE_H #include #endif +#ifdef HAVE_STRINGS_H +#include +#endif /* HAVE_STRINGS_H */ -#define jt_hexdigit(x) (((x) <= '9') ? (x) - '0' : ((x) & 7) + 9) +#define jt_hexdigit(x) (((x) <= '9') ? (x) - '0' : ((x)&7) + 9) #if !HAVE_STRNCASECMP && defined(_MSC_VER) - /* MSC has the version as _strnicmp */ -# define strncasecmp _strnicmp +/* MSC has the version as _strnicmp */ +#define strncasecmp _strnicmp #elif !HAVE_STRNCASECMP -# error You do not have strncasecmp on your system. +#error You do not have strncasecmp on your system. #endif /* HAVE_STRNCASECMP */ +#if defined(_MSC_VER) && (_MSC_VER <= 1800) +/* VS2013 doesn't know about "inline" */ +#define inline __inline +#elif defined(AIX_CC) +#define inline +#endif + +/* The following helper functions are used to speed up parsing. They + * are faster than their ctype counterparts because they assume that + * the input is in ASCII and that the locale is set to "C". The + * compiler will also inline these functions, providing an additional + * speedup by saving on function calls. + */ +static inline int is_ws_char(char c) +{ + return c == ' ' || c == '\t' || c == '\n' || c == '\r'; +} + +static inline int is_hex_char(char c) +{ + return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f'); +} + /* Use C99 NAN by default; if not available, nan("") should work too. */ #ifndef NAN #define NAN nan("") @@ -58,7 +99,8 @@ static const char json_null_str[] = "null"; static const int json_null_str_len = sizeof(json_null_str) - 1; static const char json_inf_str[] = "Infinity"; -static const char json_inf_str_lower[] = "infinity"; +/* Swapped case "Infinity" to avoid need to call tolower() on input chars: */ +static const char json_inf_str_invert[] = "iNFINITY"; static const unsigned int json_inf_str_len = sizeof(json_inf_str) - 1; static const char json_nan_str[] = "NaN"; static const int json_nan_str_len = sizeof(json_nan_str) - 1; @@ -67,27 +109,39 @@ static const int json_true_str_len = sizeof(json_true_str) - 1; static const char json_false_str[] = "false"; static const int json_false_str_len = sizeof(json_false_str) - 1; -static const char* json_tokener_errors[] = { - "success", - "continue", - "nesting too deep", - "unexpected end of data", - "unexpected character", - "null expected", - "boolean expected", - "number expected", - "array value separator ',' expected", - "quoted object property name expected", - "object property name separator ':' expected", - "object value separator ',' expected", - "invalid string sequence", - "expected comment", - "buffer size overflow" +/* clang-format off */ +static const char *json_tokener_errors[] = { + "success", + "continue", + "nesting too deep", + "unexpected end of data", + "unexpected character", + "null expected", + "boolean expected", + "number expected", + "array value separator ',' expected", + "quoted object property name expected", + "object property name separator ':' expected", + "object value separator ',' expected", + "invalid string sequence", + "expected comment", + "invalid utf-8 string", + "buffer size overflow", + "out of memory" }; +/* clang-format on */ + +/** + * validete the utf-8 string in strict model. + * if not utf-8 format, return err. + */ +static json_bool json_tokener_validate_utf8(const char c, unsigned int *nBytes); -const char *json_tokener_error_desc(enum json_tokener_error jerr) +static int json_tokener_parse_double(const char *buf, int len, double *retval); + +const char *doca_third_party_json_tokener_error_desc(enum json_tokener_error jerr) { - int jerr_int = (int) jerr; + int jerr_int = (int)jerr; if (jerr_int < 0 || jerr_int >= (int)(sizeof(json_tokener_errors) / sizeof(json_tokener_errors[0]))) return "Unknown error, " @@ -95,101 +149,120 @@ const char *json_tokener_error_desc(enum json_tokener_error jerr) return json_tokener_errors[jerr]; } -enum json_tokener_error json_tokener_get_error(struct json_tokener *tok) +enum json_tokener_error doca_third_party_json_tokener_get_error(struct json_tokener *tok) { return tok->err; } /* Stuff for decoding unicode sequences */ -#define IS_HIGH_SURROGATE(uc) (((uc) & 0xFC00) == 0xD800) -#define IS_LOW_SURROGATE(uc) (((uc) & 0xFC00) == 0xDC00) -#define DECODE_SURROGATE_PAIR(hi,lo) ((((hi) & 0x3FF) << 10) + ((lo) & 0x3FF) + 0x10000) -static unsigned char utf8_replacement_char[3] = { 0xEF, 0xBF, 0xBD }; +#define IS_HIGH_SURROGATE(uc) (((uc)&0xFC00) == 0xD800) +#define IS_LOW_SURROGATE(uc) (((uc)&0xFC00) == 0xDC00) +#define DECODE_SURROGATE_PAIR(hi, lo) ((((hi)&0x3FF) << 10) + ((lo)&0x3FF) + 0x10000) +static unsigned char utf8_replacement_char[3] = {0xEF, 0xBF, 0xBD}; -struct json_tokener* json_tokener_new_ex(int depth) +struct json_tokener *doca_third_party_json_tokener_new_ex(int depth) { - struct json_tokener *tok; - - tok = (struct json_tokener*)calloc(1, sizeof(struct json_tokener)); - if (!tok) return NULL; - tok->stack = (struct json_tokener_srec *) calloc(depth, - sizeof(struct json_tokener_srec)); - if (!tok->stack) { - free(tok); - return NULL; - } - tok->pb = printbuf_new(); - tok->max_depth = depth; - json_tokener_reset(tok); - return tok; + struct json_tokener *tok; + + tok = (struct json_tokener *)calloc(1, sizeof(struct json_tokener)); + if (!tok) + return NULL; + tok->stack = (struct json_tokener_srec *)calloc(depth, sizeof(struct json_tokener_srec)); + if (!tok->stack) + { + free(tok); + return NULL; + } + tok->pb = doca_third_party_printbuf_new(); + if (!tok->pb) + { + free(tok->stack); + free(tok); + return NULL; + } + tok->max_depth = depth; + doca_third_party_json_tokener_reset(tok); + return tok; } -struct json_tokener* json_tokener_new(void) +struct json_tokener *doca_third_party_json_tokener_new(void) { - return json_tokener_new_ex(JSON_TOKENER_DEFAULT_DEPTH); + return doca_third_party_json_tokener_new_ex(JSON_TOKENER_DEFAULT_DEPTH); } -void json_tokener_free(struct json_tokener *tok) +void doca_third_party_json_tokener_free(struct json_tokener *tok) { - json_tokener_reset(tok); - if (tok->pb) printbuf_free(tok->pb); - free(tok->stack); - free(tok); + doca_third_party_json_tokener_reset(tok); + if (tok->pb) + doca_third_party_printbuf_free(tok->pb); + free(tok->stack); + free(tok); } static void json_tokener_reset_level(struct json_tokener *tok, int depth) { - tok->stack[depth].state = json_tokener_state_eatws; - tok->stack[depth].saved_state = json_tokener_state_start; - json_object_put(tok->stack[depth].current); - tok->stack[depth].current = NULL; - free(tok->stack[depth].obj_field_name); - tok->stack[depth].obj_field_name = NULL; + tok->stack[depth].state = json_tokener_state_eatws; + tok->stack[depth].saved_state = json_tokener_state_start; + doca_third_party_json_object_put(tok->stack[depth].current); + tok->stack[depth].current = NULL; + free(tok->stack[depth].obj_field_name); + tok->stack[depth].obj_field_name = NULL; } -void json_tokener_reset(struct json_tokener *tok) +void doca_third_party_json_tokener_reset(struct json_tokener *tok) { - int i; - if (!tok) - return; - - for(i = tok->depth; i >= 0; i--) - json_tokener_reset_level(tok, i); - tok->depth = 0; - tok->err = json_tokener_success; + int i; + if (!tok) + return; + + for (i = tok->depth; i >= 0; i--) + json_tokener_reset_level(tok, i); + tok->depth = 0; + tok->err = json_tokener_success; } -struct json_object* json_tokener_parse(const char *str) +struct json_object *doca_third_party_json_tokener_parse(const char *str) { - enum json_tokener_error jerr_ignored; - struct json_object* obj; - obj = json_tokener_parse_verbose(str, &jerr_ignored); - return obj; + enum json_tokener_error jerr_ignored; + struct json_object *obj; + obj = doca_third_party_json_tokener_parse_verbose(str, &jerr_ignored); + return obj; } -struct json_object* json_tokener_parse_verbose(const char *str, - enum json_tokener_error *error) +struct json_object *doca_third_party_json_tokener_parse_verbose(const char *str, + enum json_tokener_error *error) { - struct json_tokener* tok; - struct json_object* obj; - - tok = json_tokener_new(); - if (!tok) - return NULL; - obj = json_tokener_parse_ex(tok, str, -1); - *error = tok->err; - if(tok->err != json_tokener_success) { + struct json_tokener *tok; + struct json_object *obj; + + tok = doca_third_party_json_tokener_new(); + if (!tok) + return NULL; + obj = doca_third_party_json_tokener_parse_ex(tok, str, -1); + *error = tok->err; + if (tok->err != json_tokener_success +#if 0 + /* This would be a more sensible default, and cause parsing + * things like "null123" to fail when the caller can't know + * where the parsing left off, but starting to fail would + * be a notable behaviour change. Save for a 1.0 release. + */ + || json_tokener_get_parse_end(tok) != strlen(str) +#endif + ) + + { if (obj != NULL) - json_object_put(obj); - obj = NULL; - } + doca_third_party_json_object_put(obj); + obj = NULL; + } - json_tokener_free(tok); - return obj; + doca_third_party_json_tokener_free(tok); + return obj; } -#define state tok->stack[tok->depth].state -#define saved_state tok->stack[tok->depth].saved_state +#define state tok->stack[tok->depth].state +#define saved_state tok->stack[tok->depth].saved_state #define current tok->stack[tok->depth].current #define obj_field_name tok->stack[tok->depth].obj_field_name @@ -209,789 +282,1115 @@ struct json_object* json_tokener_parse_verbose(const char *str, /* PEEK_CHAR(dest, tok) macro: * Peeks at the current char and stores it in dest. * Returns 1 on success, sets tok->err and returns 0 if no more chars. - * Implicit inputs: str, len vars + * Implicit inputs: str, len, nBytesp vars */ -#define PEEK_CHAR(dest, tok) \ - (((tok)->char_offset == len) ? \ - (((tok)->depth == 0 && \ - state == json_tokener_state_eatws && \ - saved_state == json_tokener_state_finish \ - ) ? \ - (((tok)->err = json_tokener_success), 0) \ - : \ - (((tok)->err = json_tokener_continue), 0) \ - ) : \ - (((dest) = *str), 1) \ - ) +#define PEEK_CHAR(dest, tok) \ + (((tok)->char_offset == len) \ + ? (((tok)->depth == 0 && state == json_tokener_state_eatws && \ + saved_state == json_tokener_state_finish) \ + ? (((tok)->err = json_tokener_success), 0) \ + : (((tok)->err = json_tokener_continue), 0)) \ + : (((tok->flags & JSON_TOKENER_VALIDATE_UTF8) && \ + (!json_tokener_validate_utf8(*str, nBytesp))) \ + ? ((tok->err = json_tokener_error_parse_utf8_string), 0) \ + : (((dest) = *str), 1))) /* ADVANCE_CHAR() macro: - * Incrementes str & tok->char_offset. - * For convenience of existing conditionals, returns the old value of c (0 on eof) + * Increments str & tok->char_offset. + * For convenience of existing conditionals, returns the old value of c (0 on eof). * Implicit inputs: c var */ -#define ADVANCE_CHAR(str, tok) \ - ( ++(str), ((tok)->char_offset)++, c) +#define ADVANCE_CHAR(str, tok) (++(str), ((tok)->char_offset)++, c) +/* printbuf_memappend_checked(p, s, l) macro: + * Add string s of length l to printbuffer p. + * If operation fails abort parse operation with memory error. + */ +#define printbuf_memappend_checked(p, s, l) \ + do \ + { \ + if (doca_third_party_printbuf_memappend((p), (s), (l)) < 0) \ + { \ + tok->err = json_tokener_error_memory; \ + goto out; \ + } \ + } while (0) /* End optimization macro defs */ - -struct json_object* json_tokener_parse_ex(struct json_tokener *tok, - const char *str, int len) +struct json_object *doca_third_party_json_tokener_parse_ex(struct json_tokener *tok, + const char *str, int len) { - struct json_object *obj = NULL; - char c = '\1'; -#ifdef HAVE_USELOCALE - locale_t oldlocale = uselocale(NULL); - locale_t newloc; -#elif defined(HAVE_SETLOCALE) - char *oldlocale = NULL; -#endif - - tok->char_offset = 0; - tok->err = json_tokener_success; - - /* this interface is presently not 64-bit clean due to the int len argument - and the internal printbuf interface that takes 32-bit int len arguments - so the function limits the maximum string size to INT32_MAX (2GB). - If the function is called with len == -1 then strlen is called to check - the string length is less than INT32_MAX (2GB) */ - if ((len < -1) || (len == -1 && strlen(str) > INT32_MAX)) { - tok->err = json_tokener_error_size; - return NULL; - } + struct json_object *obj = NULL; + char c = '\1'; + unsigned int nBytes = 0; + unsigned int *nBytesp = &nBytes; #ifdef HAVE_USELOCALE - { - locale_t duploc = duplocale(oldlocale); - newloc = newlocale(LC_NUMERIC, "C", duploc); - // XXX at least Debian 8.4 has a bug in newlocale where it doesn't - // change the decimal separator unless you set LC_TIME! - if (newloc) - { - duploc = newloc; // original duploc has been freed by newlocale() - newloc = newlocale(LC_TIME, "C", duploc); - } - if (newloc == NULL) - { - freelocale(duploc); - return NULL; - } - uselocale(newloc); - } + locale_t oldlocale = uselocale(NULL); + locale_t newloc; #elif defined(HAVE_SETLOCALE) - { - char *tmplocale; - tmplocale = setlocale(LC_NUMERIC, NULL); - if (tmplocale) oldlocale = strdup(tmplocale); - setlocale(LC_NUMERIC, "C"); - } + char *oldlocale = NULL; #endif - while (PEEK_CHAR(c, tok)) { - - redo_char: - switch(state) { - - case json_tokener_state_eatws: - /* Advance until we change state */ - while (isspace((int)c)) { - if ((!ADVANCE_CHAR(str, tok)) || (!PEEK_CHAR(c, tok))) - goto out; - } - if(c == '/' && !(tok->flags & JSON_TOKENER_STRICT)) { - printbuf_reset(tok->pb); - printbuf_memappend_fast(tok->pb, &c, 1); - state = json_tokener_state_comment_start; - } else { - state = saved_state; - goto redo_char; - } - break; - - case json_tokener_state_start: - switch(c) { - case '{': - state = json_tokener_state_eatws; - saved_state = json_tokener_state_object_field_start; - current = json_object_new_object(); - if(current == NULL) - goto out; - break; - case '[': - state = json_tokener_state_eatws; - saved_state = json_tokener_state_array; - current = json_object_new_array(); - if(current == NULL) - goto out; - break; - case 'I': - case 'i': - state = json_tokener_state_inf; - printbuf_reset(tok->pb); - tok->st_pos = 0; - goto redo_char; - case 'N': - case 'n': - state = json_tokener_state_null; // or NaN - printbuf_reset(tok->pb); - tok->st_pos = 0; - goto redo_char; - case '\'': - if (tok->flags & JSON_TOKENER_STRICT) { - /* in STRICT mode only double-quote are allowed */ - tok->err = json_tokener_error_parse_unexpected; - goto out; - } - /* FALLTHRU */ - case '"': - state = json_tokener_state_string; - printbuf_reset(tok->pb); - tok->quote_char = c; - break; - case 'T': - case 't': - case 'F': - case 'f': - state = json_tokener_state_boolean; - printbuf_reset(tok->pb); - tok->st_pos = 0; - goto redo_char; - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case '-': - state = json_tokener_state_number; - printbuf_reset(tok->pb); - tok->is_double = 0; - goto redo_char; - default: - tok->err = json_tokener_error_parse_unexpected; - goto out; - } - break; - - case json_tokener_state_finish: - if(tok->depth == 0) goto out; - obj = json_object_get(current); - json_tokener_reset_level(tok, tok->depth); - tok->depth--; - goto redo_char; - - case json_tokener_state_inf: /* aka starts with 'i' (or 'I', or "-i", or "-I") */ - { - /* If we were guaranteed to have len set, then we could (usually) handle - * the entire "Infinity" check in a single strncmp (strncasecmp), but - * since len might be -1 (i.e. "read until \0"), we need to check it - * a character at a time. - * Trying to handle it both ways would make this code considerably more - * complicated with likely little performance benefit. + tok->char_offset = 0; + tok->err = json_tokener_success; + + /* this interface is presently not 64-bit clean due to the int len argument + * and the internal printbuf interface that takes 32-bit int len arguments + * so the function limits the maximum string size to INT32_MAX (2GB). + * If the function is called with len == -1 then strlen is called to check + * the string length is less than INT32_MAX (2GB) */ - int is_negative = 0; - const char *_json_inf_str = json_inf_str; - if (!(tok->flags & JSON_TOKENER_STRICT)) - _json_inf_str = json_inf_str_lower; + if ((len < -1) || (len == -1 && strlen(str) > INT32_MAX)) + { + tok->err = json_tokener_error_size; + return NULL; + } - /* Note: tok->st_pos must be 0 when state is set to json_tokener_state_inf */ - while (tok->st_pos < (int)json_inf_str_len) +#ifdef HAVE_USELOCALE { - char inf_char = *str; - if (!(tok->flags & JSON_TOKENER_STRICT)) - inf_char = tolower((int)*str); - if (inf_char != _json_inf_str[tok->st_pos]) + locale_t duploc = duplocale(oldlocale); + newloc = newlocale(LC_NUMERIC_MASK, "C", duploc); + if (newloc == NULL) { - tok->err = json_tokener_error_parse_unexpected; - goto out; - } - tok->st_pos++; - (void)ADVANCE_CHAR(str, tok); - if (!PEEK_CHAR(c, tok)) - { - /* out of input chars, for now at least */ - goto out; + freelocale(duploc); + return NULL; } +#ifdef NEWLOCALE_NEEDS_FREELOCALE + // Older versions of FreeBSD (<12.4) don't free the locale + // passed to newlocale(), so do it here + freelocale(duploc); +#endif + uselocale(newloc); } - /* We checked the full length of "Infinity", so create the object. - * When handling -Infinity, the number parsing code will have dropped - * the "-" into tok->pb for us, so check it now. - */ - if (printbuf_length(tok->pb) > 0 && *(tok->pb->buf) == '-') +#elif defined(HAVE_SETLOCALE) { - is_negative = 1; - } - current = json_object_new_double(is_negative - ? -INFINITY : INFINITY); - if (current == NULL) - goto out; - saved_state = json_tokener_state_finish; - state = json_tokener_state_eatws; - goto redo_char; - - } - break; - case json_tokener_state_null: /* aka starts with 'n' */ - { - int size; - int size_nan; - printbuf_memappend_fast(tok->pb, &c, 1); - size = json_min(tok->st_pos+1, json_null_str_len); - size_nan = json_min(tok->st_pos+1, json_nan_str_len); - if((!(tok->flags & JSON_TOKENER_STRICT) && - strncasecmp(json_null_str, tok->pb->buf, size) == 0) - || (strncmp(json_null_str, tok->pb->buf, size) == 0) - ) { - if (tok->st_pos == json_null_str_len) { - current = NULL; - saved_state = json_tokener_state_finish; - state = json_tokener_state_eatws; - goto redo_char; - } + char *tmplocale; + tmplocale = setlocale(LC_NUMERIC, NULL); + if (tmplocale) + { + oldlocale = strdup(tmplocale); + if (oldlocale == NULL) + return NULL; + } + setlocale(LC_NUMERIC, "C"); } - else if ((!(tok->flags & JSON_TOKENER_STRICT) && - strncasecmp(json_nan_str, tok->pb->buf, size_nan) == 0) || - (strncmp(json_nan_str, tok->pb->buf, size_nan) == 0) - ) +#endif + + while (PEEK_CHAR(c, tok)) // Note: c might be '\0' ! { - if (tok->st_pos == json_nan_str_len) + + redo_char: + switch (state) { - current = json_object_new_double(NAN); + + case json_tokener_state_eatws: + /* Advance until we change state */ + while (is_ws_char(c)) + { + if ((!ADVANCE_CHAR(str, tok)) || (!PEEK_CHAR(c, tok))) + goto out; + } + if (c == '/' && !(tok->flags & JSON_TOKENER_STRICT)) + { + doca_third_party_printbuf_reset(tok->pb); + printbuf_memappend_checked(tok->pb, &c, 1); + state = json_tokener_state_comment_start; + } + else + { + state = saved_state; + goto redo_char; + } + break; + + case json_tokener_state_start: + switch (c) + { + case '{': + state = json_tokener_state_eatws; + saved_state = json_tokener_state_object_field_start; + current = doca_third_party_json_object_new_object(); + if (current == NULL) + { + tok->err = json_tokener_error_memory; + goto out; + } + break; + case '[': + state = json_tokener_state_eatws; + saved_state = json_tokener_state_array; + current = doca_third_party_json_object_new_array(); + if (current == NULL) + { + tok->err = json_tokener_error_memory; + goto out; + } + break; + case 'I': + case 'i': + state = json_tokener_state_inf; + doca_third_party_printbuf_reset(tok->pb); + tok->st_pos = 0; + goto redo_char; + case 'N': + case 'n': + state = json_tokener_state_null; // or NaN + doca_third_party_printbuf_reset(tok->pb); + tok->st_pos = 0; + goto redo_char; + case '\'': + if (tok->flags & JSON_TOKENER_STRICT) + { + /* in STRICT mode only double-quote are allowed */ + tok->err = json_tokener_error_parse_unexpected; + goto out; + } + /* FALLTHRU */ + case '"': + state = json_tokener_state_string; + doca_third_party_printbuf_reset(tok->pb); + tok->quote_char = c; + break; + case 'T': + case 't': + case 'F': + case 'f': + state = json_tokener_state_boolean; + doca_third_party_printbuf_reset(tok->pb); + tok->st_pos = 0; + goto redo_char; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case '-': + state = json_tokener_state_number; + doca_third_party_printbuf_reset(tok->pb); + tok->is_double = 0; + goto redo_char; + default: tok->err = json_tokener_error_parse_unexpected; goto out; + } + break; + + case json_tokener_state_finish: + if (tok->depth == 0) + goto out; + obj = doca_third_party_json_object_get(current); + json_tokener_reset_level(tok, tok->depth); + tok->depth--; + goto redo_char; + + case json_tokener_state_inf: /* aka starts with 'i' (or 'I', or "-i", or "-I") */ + { + /* If we were guaranteed to have len set, then we could (usually) handle + * the entire "Infinity" check in a single strncmp (strncasecmp), but + * since len might be -1 (i.e. "read until \0"), we need to check it + * a character at a time. + * Trying to handle it both ways would make this code considerably more + * complicated with likely little performance benefit. + */ + int is_negative = 0; + + /* Note: tok->st_pos must be 0 when state is set to json_tokener_state_inf */ + while (tok->st_pos < (int)json_inf_str_len) + { + char inf_char = *str; + if (inf_char != json_inf_str[tok->st_pos] && + ((tok->flags & JSON_TOKENER_STRICT) || + inf_char != json_inf_str_invert[tok->st_pos])) + { + tok->err = json_tokener_error_parse_unexpected; + goto out; + } + tok->st_pos++; + (void)ADVANCE_CHAR(str, tok); + if (!PEEK_CHAR(c, tok)) + { + /* out of input chars, for now at least */ + goto out; + } + } + /* We checked the full length of "Infinity", so create the object. + * When handling -Infinity, the number parsing code will have dropped + * the "-" into tok->pb for us, so check it now. + */ + if (printbuf_length(tok->pb) > 0 && *(tok->pb->buf) == '-') + { + is_negative = 1; + } + current = doca_third_party_json_object_new_double(is_negative ? -INFINITY + : INFINITY); if (current == NULL) - goto out; + { + tok->err = json_tokener_error_memory; + goto out; + } saved_state = json_tokener_state_finish; state = json_tokener_state_eatws; goto redo_char; } - } else { - tok->err = json_tokener_error_parse_null; - goto out; - } - tok->st_pos++; - } - break; - - case json_tokener_state_comment_start: - if(c == '*') { - state = json_tokener_state_comment; - } else if(c == '/') { - state = json_tokener_state_comment_eol; - } else { - tok->err = json_tokener_error_parse_comment; - goto out; - } - printbuf_memappend_fast(tok->pb, &c, 1); - break; - - case json_tokener_state_comment: - { - /* Advance until we change state */ - const char *case_start = str; - while(c != '*') { - if (!ADVANCE_CHAR(str, tok) || !PEEK_CHAR(c, tok)) { - printbuf_memappend_fast(tok->pb, case_start, str-case_start); - goto out; - } - } - printbuf_memappend_fast(tok->pb, case_start, 1+str-case_start); - state = json_tokener_state_comment_end; - } - break; - - case json_tokener_state_comment_eol: - { - /* Advance until we change state */ - const char *case_start = str; - while(c != '\n') { - if (!ADVANCE_CHAR(str, tok) || !PEEK_CHAR(c, tok)) { - printbuf_memappend_fast(tok->pb, case_start, str-case_start); - goto out; - } - } - printbuf_memappend_fast(tok->pb, case_start, str-case_start); - MC_DEBUG("json_tokener_comment: %s\n", tok->pb->buf); - state = json_tokener_state_eatws; - } - break; - - case json_tokener_state_comment_end: - printbuf_memappend_fast(tok->pb, &c, 1); - if(c == '/') { - MC_DEBUG("json_tokener_comment: %s\n", tok->pb->buf); - state = json_tokener_state_eatws; - } else { - state = json_tokener_state_comment; - } - break; - - case json_tokener_state_string: - { - /* Advance until we change state */ - const char *case_start = str; - while(1) { - if(c == tok->quote_char) { - printbuf_memappend_fast(tok->pb, case_start, str-case_start); - current = json_object_new_string_len(tok->pb->buf, tok->pb->bpos); - if(current == NULL) - goto out; - saved_state = json_tokener_state_finish; - state = json_tokener_state_eatws; - break; - } else if(c == '\\') { - printbuf_memappend_fast(tok->pb, case_start, str-case_start); - saved_state = json_tokener_state_string; - state = json_tokener_state_string_escape; - break; - } - if (!ADVANCE_CHAR(str, tok) || !PEEK_CHAR(c, tok)) { - printbuf_memappend_fast(tok->pb, case_start, str-case_start); - goto out; - } - } - } - break; - - case json_tokener_state_string_escape: - switch(c) { - case '"': - case '\\': - case '/': - printbuf_memappend_fast(tok->pb, &c, 1); - state = saved_state; - break; - case 'b': - case 'n': - case 'r': - case 't': - case 'f': - if(c == 'b') printbuf_memappend_fast(tok->pb, "\b", 1); - else if(c == 'n') printbuf_memappend_fast(tok->pb, "\n", 1); - else if(c == 'r') printbuf_memappend_fast(tok->pb, "\r", 1); - else if(c == 't') printbuf_memappend_fast(tok->pb, "\t", 1); - else if(c == 'f') printbuf_memappend_fast(tok->pb, "\f", 1); - state = saved_state; - break; - case 'u': - tok->ucs_char = 0; - tok->st_pos = 0; - state = json_tokener_state_escape_unicode; - break; - default: - tok->err = json_tokener_error_parse_string; - goto out; - } - break; - - case json_tokener_state_escape_unicode: - { - unsigned int got_hi_surrogate = 0; - - /* Handle a 4-byte sequence, or two sequences if a surrogate pair */ - while(1) { - if (c && strchr(json_hex_chars, c)) { - tok->ucs_char += ((unsigned int)jt_hexdigit(c) << ((3-tok->st_pos++)*4)); - if(tok->st_pos == 4) { - unsigned char unescaped_utf[4]; - - if (got_hi_surrogate) { - if (IS_LOW_SURROGATE(tok->ucs_char)) { - /* Recalculate the ucs_char, then fall thru to process normally */ - tok->ucs_char = DECODE_SURROGATE_PAIR(got_hi_surrogate, tok->ucs_char); - } else { - /* Hi surrogate was not followed by a low surrogate */ - /* Replace the hi and process the rest normally */ - printbuf_memappend_fast(tok->pb, (char*)utf8_replacement_char, 3); - } - got_hi_surrogate = 0; - } - - if (tok->ucs_char < 0x80) { - unescaped_utf[0] = tok->ucs_char; - printbuf_memappend_fast(tok->pb, (char*)unescaped_utf, 1); - } else if (tok->ucs_char < 0x800) { - unescaped_utf[0] = 0xc0 | (tok->ucs_char >> 6); - unescaped_utf[1] = 0x80 | (tok->ucs_char & 0x3f); - printbuf_memappend_fast(tok->pb, (char*)unescaped_utf, 2); - } else if (IS_HIGH_SURROGATE(tok->ucs_char)) { - /* Got a high surrogate. Remember it and look for the - * the beginning of another sequence, which should be the - * low surrogate. - */ - got_hi_surrogate = tok->ucs_char; - /* Not at end, and the next two chars should be "\u" */ - if ((len == -1 || len > (tok->char_offset + 2)) && - // str[0] != '0' && // implied by json_hex_chars, above. - (str[1] == '\\') && - (str[2] == 'u')) - { - /* Advance through the 16 bit surrogate, and move on to the - * next sequence. The next step is to process the following - * characters. - */ - if( !ADVANCE_CHAR(str, tok) || !ADVANCE_CHAR(str, tok) ) { - printbuf_memappend_fast(tok->pb, - (char*) utf8_replacement_char, 3); - } - /* Advance to the first char of the next sequence and - * continue processing with the next sequence. - */ - if (!ADVANCE_CHAR(str, tok) || !PEEK_CHAR(c, tok)) { - printbuf_memappend_fast(tok->pb, - (char*) utf8_replacement_char, 3); - goto out; - } - tok->ucs_char = 0; - tok->st_pos = 0; - continue; /* other json_tokener_state_escape_unicode */ - } else { - /* Got a high surrogate without another sequence following - * it. Put a replacement char in for the hi surrogate - * and pretend we finished. - */ - printbuf_memappend_fast(tok->pb, - (char*) utf8_replacement_char, 3); - } - } else if (IS_LOW_SURROGATE(tok->ucs_char)) { - /* Got a low surrogate not preceded by a high */ - printbuf_memappend_fast(tok->pb, (char*)utf8_replacement_char, 3); - } else if (tok->ucs_char < 0x10000) { - unescaped_utf[0] = 0xe0 | (tok->ucs_char >> 12); - unescaped_utf[1] = 0x80 | ((tok->ucs_char >> 6) & 0x3f); - unescaped_utf[2] = 0x80 | (tok->ucs_char & 0x3f); - printbuf_memappend_fast(tok->pb, (char*)unescaped_utf, 3); - } else if (tok->ucs_char < 0x110000) { - unescaped_utf[0] = 0xf0 | ((tok->ucs_char >> 18) & 0x07); - unescaped_utf[1] = 0x80 | ((tok->ucs_char >> 12) & 0x3f); - unescaped_utf[2] = 0x80 | ((tok->ucs_char >> 6) & 0x3f); - unescaped_utf[3] = 0x80 | (tok->ucs_char & 0x3f); - printbuf_memappend_fast(tok->pb, (char*)unescaped_utf, 4); - } else { - /* Don't know what we got--insert the replacement char */ - printbuf_memappend_fast(tok->pb, (char*)utf8_replacement_char, 3); - } - state = saved_state; break; - } - } else { - tok->err = json_tokener_error_parse_string; - goto out; - } - if (!ADVANCE_CHAR(str, tok) || !PEEK_CHAR(c, tok)) { - if (got_hi_surrogate) /* Clean up any pending chars */ - printbuf_memappend_fast(tok->pb, (char*)utf8_replacement_char, 3); - goto out; - } - } - } - break; - - case json_tokener_state_boolean: - { - int size1, size2; - printbuf_memappend_fast(tok->pb, &c, 1); - size1 = json_min(tok->st_pos+1, json_true_str_len); - size2 = json_min(tok->st_pos+1, json_false_str_len); - if((!(tok->flags & JSON_TOKENER_STRICT) && - strncasecmp(json_true_str, tok->pb->buf, size1) == 0) - || (strncmp(json_true_str, tok->pb->buf, size1) == 0) - ) { - if(tok->st_pos == json_true_str_len) { - current = json_object_new_boolean(1); - if(current == NULL) - goto out; - saved_state = json_tokener_state_finish; - state = json_tokener_state_eatws; - goto redo_char; - } - } else if((!(tok->flags & JSON_TOKENER_STRICT) && - strncasecmp(json_false_str, tok->pb->buf, size2) == 0) - || (strncmp(json_false_str, tok->pb->buf, size2) == 0)) { - if(tok->st_pos == json_false_str_len) { - current = json_object_new_boolean(0); - if(current == NULL) - goto out; - saved_state = json_tokener_state_finish; - state = json_tokener_state_eatws; - goto redo_char; - } - } else { - tok->err = json_tokener_error_parse_boolean; - goto out; - } - tok->st_pos++; - } - break; - - case json_tokener_state_number: - { - /* Advance until we change state */ - const char *case_start = str; - int case_len=0; - int is_exponent=0; - int negativesign_next_possible_location=1; - while(c && strchr(json_number_chars, c)) { - ++case_len; - - /* non-digit characters checks */ - /* note: since the main loop condition to get here was - an input starting with 0-9 or '-', we are - protected from input starting with '.' or - e/E. */ - if (c == '.') { - if (tok->is_double != 0) { - /* '.' can only be found once, and out of the exponent part. - Thus, if the input is already flagged as double, it - is invalid. */ - tok->err = json_tokener_error_parse_number; - goto out; - } - tok->is_double = 1; - } - if (c == 'e' || c == 'E') { - if (is_exponent != 0) { - /* only one exponent possible */ - tok->err = json_tokener_error_parse_number; - goto out; - } - is_exponent = 1; - tok->is_double = 1; - /* the exponent part can begin with a negative sign */ - negativesign_next_possible_location = case_len + 1; - } - if (c == '-' && case_len != negativesign_next_possible_location) { - /* If the negative sign is not where expected (ie - start of input or start of exponent part), the - input is invalid. */ - tok->err = json_tokener_error_parse_number; - goto out; - } - - if (!ADVANCE_CHAR(str, tok) || !PEEK_CHAR(c, tok)) { - printbuf_memappend_fast(tok->pb, case_start, case_len); - goto out; - } - } - if (case_len>0) - printbuf_memappend_fast(tok->pb, case_start, case_len); + case json_tokener_state_null: /* aka starts with 'n' */ + { + int size; + int size_nan; + printbuf_memappend_checked(tok->pb, &c, 1); + size = json_min(tok->st_pos + 1, json_null_str_len); + size_nan = json_min(tok->st_pos + 1, json_nan_str_len); + if ((!(tok->flags & JSON_TOKENER_STRICT) && + strncasecmp(json_null_str, tok->pb->buf, size) == 0) || + (strncmp(json_null_str, tok->pb->buf, size) == 0)) + { + if (tok->st_pos == json_null_str_len) + { + current = NULL; + saved_state = json_tokener_state_finish; + state = json_tokener_state_eatws; + goto redo_char; + } + } + else if ((!(tok->flags & JSON_TOKENER_STRICT) && + strncasecmp(json_nan_str, tok->pb->buf, size_nan) == 0) || + (strncmp(json_nan_str, tok->pb->buf, size_nan) == 0)) + { + if (tok->st_pos == json_nan_str_len) + { + current = doca_third_party_json_object_new_double(NAN); + if (current == NULL) + { + tok->err = json_tokener_error_memory; + goto out; + } + saved_state = json_tokener_state_finish; + state = json_tokener_state_eatws; + goto redo_char; + } + } + else + { + tok->err = json_tokener_error_parse_null; + goto out; + } + tok->st_pos++; + } + break; - // Check for -Infinity - if (tok->pb->buf[0] == '-' && case_len <= 1 && - (c == 'i' || c == 'I')) - { - state = json_tokener_state_inf; - tok->st_pos = 0; - goto redo_char; - } - } - { - int64_t num64; - double numd; - if (!tok->is_double && json_parse_int64(tok->pb->buf, &num64) == 0) { - if (num64 && tok->pb->buf[0]=='0' && - (tok->flags & JSON_TOKENER_STRICT)) { - /* in strict mode, number must not start with 0 */ - tok->err = json_tokener_error_parse_number; - goto out; + case json_tokener_state_comment_start: + if (c == '*') + { + state = json_tokener_state_comment; + } + else if (c == '/') + { + state = json_tokener_state_comment_eol; + } + else + { + tok->err = json_tokener_error_parse_comment; + goto out; + } + printbuf_memappend_checked(tok->pb, &c, 1); + break; + + case json_tokener_state_comment: + { + /* Advance until we change state */ + const char *case_start = str; + while (c != '*') + { + if (!ADVANCE_CHAR(str, tok) || !PEEK_CHAR(c, tok)) + { + printbuf_memappend_checked(tok->pb, case_start, + str - case_start); + goto out; + } + } + printbuf_memappend_checked(tok->pb, case_start, 1 + str - case_start); + state = json_tokener_state_comment_end; + } + break; + + case json_tokener_state_comment_eol: + { + /* Advance until we change state */ + const char *case_start = str; + while (c != '\n') + { + if (!ADVANCE_CHAR(str, tok) || !PEEK_CHAR(c, tok)) + { + printbuf_memappend_checked(tok->pb, case_start, + str - case_start); + goto out; + } + } + printbuf_memappend_checked(tok->pb, case_start, str - case_start); + MC_DEBUG("json_tokener_comment: %s\n", tok->pb->buf); + state = json_tokener_state_eatws; + } + break; + + case json_tokener_state_comment_end: + printbuf_memappend_checked(tok->pb, &c, 1); + if (c == '/') + { + MC_DEBUG("json_tokener_comment: %s\n", tok->pb->buf); + state = json_tokener_state_eatws; + } + else + { + state = json_tokener_state_comment; + } + break; + + case json_tokener_state_string: + { + /* Advance until we change state */ + const char *case_start = str; + while (1) + { + if (c == tok->quote_char) + { + printbuf_memappend_checked(tok->pb, case_start, + str - case_start); + current = doca_third_party_json_object_new_string_len( + tok->pb->buf, tok->pb->bpos); + if (current == NULL) + { + tok->err = json_tokener_error_memory; + goto out; + } + saved_state = json_tokener_state_finish; + state = json_tokener_state_eatws; + break; + } + else if (c == '\\') + { + printbuf_memappend_checked(tok->pb, case_start, + str - case_start); + saved_state = json_tokener_state_string; + state = json_tokener_state_string_escape; + break; + } + if (!ADVANCE_CHAR(str, tok) || !PEEK_CHAR(c, tok)) + { + printbuf_memappend_checked(tok->pb, case_start, + str - case_start); + goto out; + } + } + } + break; + + case json_tokener_state_string_escape: + switch (c) + { + case '"': + case '\\': + case '/': + printbuf_memappend_checked(tok->pb, &c, 1); + state = saved_state; + break; + case 'b': + case 'n': + case 'r': + case 't': + case 'f': + if (c == 'b') + printbuf_memappend_checked(tok->pb, "\b", 1); + else if (c == 'n') + printbuf_memappend_checked(tok->pb, "\n", 1); + else if (c == 'r') + printbuf_memappend_checked(tok->pb, "\r", 1); + else if (c == 't') + printbuf_memappend_checked(tok->pb, "\t", 1); + else if (c == 'f') + printbuf_memappend_checked(tok->pb, "\f", 1); + state = saved_state; + break; + case 'u': + tok->ucs_char = 0; + tok->st_pos = 0; + state = json_tokener_state_escape_unicode; + break; + default: tok->err = json_tokener_error_parse_string; goto out; + } + break; + + // =================================================== + + case json_tokener_state_escape_unicode: + { + /* Handle a 4-byte \uNNNN sequence, or two sequences if a surrogate pair */ + while (1) + { + if (!c || !is_hex_char(c)) + { + tok->err = json_tokener_error_parse_string; + goto out; + } + tok->ucs_char |= + ((unsigned int)jt_hexdigit(c) << ((3 - tok->st_pos) * 4)); + tok->st_pos++; + if (tok->st_pos >= 4) + break; + + (void)ADVANCE_CHAR(str, tok); + if (!PEEK_CHAR(c, tok)) + { + /* + * We're out of characters in the current call to + * json_tokener_parse(), but a subsequent call might + * provide us with more, so leave our current state + * as-is (including tok->high_surrogate) and return. + */ + goto out; + } + } + tok->st_pos = 0; + + /* Now, we have a full \uNNNN sequence in tok->ucs_char */ + + /* If the *previous* sequence was a high surrogate ... */ + if (tok->high_surrogate) + { + if (IS_LOW_SURROGATE(tok->ucs_char)) + { + /* Recalculate the ucs_char, then fall thru to process normally */ + tok->ucs_char = DECODE_SURROGATE_PAIR(tok->high_surrogate, + tok->ucs_char); + } + else + { + /* High surrogate was not followed by a low surrogate + * Replace the high and process the rest normally + */ + printbuf_memappend_checked( + tok->pb, (char *)utf8_replacement_char, 3); + } + tok->high_surrogate = 0; + } + + if (tok->ucs_char < 0x80) + { + unsigned char unescaped_utf[1]; + unescaped_utf[0] = tok->ucs_char; + printbuf_memappend_checked(tok->pb, (char *)unescaped_utf, 1); + } + else if (tok->ucs_char < 0x800) + { + unsigned char unescaped_utf[2]; + unescaped_utf[0] = 0xc0 | (tok->ucs_char >> 6); + unescaped_utf[1] = 0x80 | (tok->ucs_char & 0x3f); + printbuf_memappend_checked(tok->pb, (char *)unescaped_utf, 2); + } + else if (IS_HIGH_SURROGATE(tok->ucs_char)) + { + /* + * The next two characters should be \u, HOWEVER, + * we can't simply peek ahead here, because the + * characters we need might not be passed to us + * until a subsequent call to json_tokener_parse. + * Instead, transition through a couple of states. + * (now): + * _escape_unicode => _unicode_need_escape + * (see a '\\' char): + * _unicode_need_escape => _unicode_need_u + * (see a 'u' char): + * _unicode_need_u => _escape_unicode + * ...and we'll end up back around here. + */ + tok->high_surrogate = tok->ucs_char; + tok->ucs_char = 0; + state = json_tokener_state_escape_unicode_need_escape; + break; + } + else if (IS_LOW_SURROGATE(tok->ucs_char)) + { + /* Got a low surrogate not preceded by a high */ + printbuf_memappend_checked(tok->pb, (char *)utf8_replacement_char, + 3); + } + else if (tok->ucs_char < 0x10000) + { + unsigned char unescaped_utf[3]; + unescaped_utf[0] = 0xe0 | (tok->ucs_char >> 12); + unescaped_utf[1] = 0x80 | ((tok->ucs_char >> 6) & 0x3f); + unescaped_utf[2] = 0x80 | (tok->ucs_char & 0x3f); + printbuf_memappend_checked(tok->pb, (char *)unescaped_utf, 3); + } + else if (tok->ucs_char < 0x110000) + { + unsigned char unescaped_utf[4]; + unescaped_utf[0] = 0xf0 | ((tok->ucs_char >> 18) & 0x07); + unescaped_utf[1] = 0x80 | ((tok->ucs_char >> 12) & 0x3f); + unescaped_utf[2] = 0x80 | ((tok->ucs_char >> 6) & 0x3f); + unescaped_utf[3] = 0x80 | (tok->ucs_char & 0x3f); + printbuf_memappend_checked(tok->pb, (char *)unescaped_utf, 4); + } + else + { + /* Don't know what we got--insert the replacement char */ + printbuf_memappend_checked(tok->pb, (char *)utf8_replacement_char, + 3); + } + state = saved_state; // i.e. _state_string or _state_object_field + } + break; + + case json_tokener_state_escape_unicode_need_escape: + // We get here after processing a high_surrogate + // require a '\\' char + if (!c || c != '\\') + { + /* Got a high surrogate without another sequence following + * it. Put a replacement char in for the high surrogate + * and pop back up to _state_string or _state_object_field. + */ + printbuf_memappend_checked(tok->pb, (char *)utf8_replacement_char, + 3); + tok->high_surrogate = 0; + tok->ucs_char = 0; + tok->st_pos = 0; + state = saved_state; + goto redo_char; + } + state = json_tokener_state_escape_unicode_need_u; + break; + + case json_tokener_state_escape_unicode_need_u: + /* We already had a \ char, check that it's \u */ + if (!c || c != 'u') + { + /* Got a high surrogate with some non-unicode escape + * sequence following it. + * Put a replacement char in for the high surrogate + * and handle the escape sequence normally. + */ + printbuf_memappend_checked(tok->pb, (char *)utf8_replacement_char, + 3); + tok->high_surrogate = 0; + tok->ucs_char = 0; + tok->st_pos = 0; + state = json_tokener_state_string_escape; + goto redo_char; + } + state = json_tokener_state_escape_unicode; + break; + + // =================================================== + + case json_tokener_state_boolean: + { + int size1, size2; + printbuf_memappend_checked(tok->pb, &c, 1); + size1 = json_min(tok->st_pos + 1, json_true_str_len); + size2 = json_min(tok->st_pos + 1, json_false_str_len); + if ((!(tok->flags & JSON_TOKENER_STRICT) && + strncasecmp(json_true_str, tok->pb->buf, size1) == 0) || + (strncmp(json_true_str, tok->pb->buf, size1) == 0)) + { + if (tok->st_pos == json_true_str_len) + { + current = doca_third_party_json_object_new_boolean(1); + if (current == NULL) + { + tok->err = json_tokener_error_memory; + goto out; + } + saved_state = json_tokener_state_finish; + state = json_tokener_state_eatws; + goto redo_char; + } + } + else if ((!(tok->flags & JSON_TOKENER_STRICT) && + strncasecmp(json_false_str, tok->pb->buf, size2) == 0) || + (strncmp(json_false_str, tok->pb->buf, size2) == 0)) + { + if (tok->st_pos == json_false_str_len) + { + current = doca_third_party_json_object_new_boolean(0); + if (current == NULL) + { + tok->err = json_tokener_error_memory; + goto out; + } + saved_state = json_tokener_state_finish; + state = json_tokener_state_eatws; + goto redo_char; + } + } + else + { + tok->err = json_tokener_error_parse_boolean; + goto out; + } + tok->st_pos++; + } + break; + + case json_tokener_state_number: + { + /* Advance until we change state */ + const char *case_start = str; + int case_len = 0; + int is_exponent = 0; + int neg_sign_ok = 1; + int pos_sign_ok = 0; + if (printbuf_length(tok->pb) > 0) + { + /* We don't save all state from the previous incremental parse + so we need to re-generate it based on the saved string so far. + */ + char *e_loc = strchr(tok->pb->buf, 'e'); + if (!e_loc) + e_loc = strchr(tok->pb->buf, 'E'); + if (e_loc) + { + char *last_saved_char = + &tok->pb->buf[printbuf_length(tok->pb) - 1]; + is_exponent = 1; + pos_sign_ok = neg_sign_ok = 1; + /* If the "e" isn't at the end, we can't start with a '-' */ + if (e_loc != last_saved_char) + { + neg_sign_ok = 0; + pos_sign_ok = 0; + } + // else leave it set to 1, i.e. start of the new input + } + } + + while (c && ((c >= '0' && c <= '9') || + (!is_exponent && (c == 'e' || c == 'E')) || + (neg_sign_ok && c == '-') || (pos_sign_ok && c == '+') || + (!tok->is_double && c == '.'))) + { + pos_sign_ok = neg_sign_ok = 0; + ++case_len; + + /* non-digit characters checks */ + /* note: since the main loop condition to get here was + * an input starting with 0-9 or '-', we are + * protected from input starting with '.' or + * e/E. + */ + switch (c) + { + case '.': + tok->is_double = 1; + pos_sign_ok = 1; + neg_sign_ok = 1; + break; + case 'e': /* FALLTHRU */ + case 'E': + is_exponent = 1; + tok->is_double = 1; + /* the exponent part can begin with a negative sign */ + pos_sign_ok = neg_sign_ok = 1; + break; + default: break; + } + + if (!ADVANCE_CHAR(str, tok) || !PEEK_CHAR(c, tok)) + { + printbuf_memappend_checked(tok->pb, case_start, case_len); + goto out; + } + } + /* + Now we know c isn't a valid number char, but check whether + it might have been intended to be, and return a potentially + more understandable error right away. + However, if we're at the top-level, use the number as-is + because c can be part of a new object to parse on the + next call to json_tokener_parse(). + */ + if (tok->depth > 0 && c != ',' && c != ']' && c != '}' && c != '/' && + c != 'I' && c != 'i' && !is_ws_char(c)) + { + tok->err = json_tokener_error_parse_number; + goto out; + } + if (case_len > 0) + printbuf_memappend_checked(tok->pb, case_start, case_len); + + // Check for -Infinity + if (tok->pb->buf[0] == '-' && case_len <= 1 && (c == 'i' || c == 'I')) + { + state = json_tokener_state_inf; + tok->st_pos = 0; + goto redo_char; + } + if (tok->is_double && !(tok->flags & JSON_TOKENER_STRICT)) + { + /* Trim some chars off the end, to allow things + like "123e+" to parse ok. */ + while (printbuf_length(tok->pb) > 1) + { + char last_char = tok->pb->buf[printbuf_length(tok->pb) - 1]; + if (last_char != 'e' && last_char != 'E' && + last_char != '-' && last_char != '+') + { + break; + } + tok->pb->buf[printbuf_length(tok->pb) - 1] = '\0'; + printbuf_length(tok->pb)--; + } + } + } + { + int64_t num64; + uint64_t numuint64; + double numd; + if (!tok->is_double && tok->pb->buf[0] == '-' && + doca_third_party_json_parse_int64(tok->pb->buf, &num64) == 0) + { + if (errno == ERANGE && (tok->flags & JSON_TOKENER_STRICT)) + { + tok->err = json_tokener_error_parse_number; + goto out; + } + current = doca_third_party_json_object_new_int64(num64); + if (current == NULL) + { + tok->err = json_tokener_error_memory; + goto out; + } + } + else if (!tok->is_double && tok->pb->buf[0] != '-' && + doca_third_party_json_parse_uint64(tok->pb->buf, + &numuint64) == 0) + { + if (errno == ERANGE && (tok->flags & JSON_TOKENER_STRICT)) + { + tok->err = json_tokener_error_parse_number; + goto out; + } + if (numuint64 && tok->pb->buf[0] == '0' && + (tok->flags & JSON_TOKENER_STRICT)) + { + tok->err = json_tokener_error_parse_number; + goto out; + } + if (numuint64 <= INT64_MAX) + { + num64 = (uint64_t)numuint64; + current = + doca_third_party_json_object_new_int64(num64); + if (current == NULL) + { + tok->err = json_tokener_error_memory; + goto out; + } + } + else + { + current = doca_third_party_json_object_new_uint64( + numuint64); + if (current == NULL) + { + tok->err = json_tokener_error_memory; + goto out; + } + } + } + else if (tok->is_double && + json_tokener_parse_double( + tok->pb->buf, printbuf_length(tok->pb), &numd) == 0) + { + current = doca_third_party_json_object_new_double_s( + numd, tok->pb->buf); + if (current == NULL) + { + tok->err = json_tokener_error_memory; + goto out; + } + } + else + { + tok->err = json_tokener_error_parse_number; + goto out; + } + saved_state = json_tokener_state_finish; + state = json_tokener_state_eatws; + goto redo_char; + } + break; + + case json_tokener_state_array_after_sep: + case json_tokener_state_array: + if (c == ']') + { + // Minimize memory usage; assume parsed objs are unlikely to be changed + doca_third_party_json_object_array_shrink(current, 0); + + if (state == json_tokener_state_array_after_sep && + (tok->flags & JSON_TOKENER_STRICT)) + { + tok->err = json_tokener_error_parse_unexpected; + goto out; + } + saved_state = json_tokener_state_finish; + state = json_tokener_state_eatws; + } + else + { + if (tok->depth >= tok->max_depth - 1) + { + tok->err = json_tokener_error_depth; + goto out; + } + state = json_tokener_state_array_add; + tok->depth++; + json_tokener_reset_level(tok, tok->depth); + goto redo_char; + } + break; + + case json_tokener_state_array_add: + if (doca_third_party_json_object_array_add(current, obj) != 0) + { + tok->err = json_tokener_error_memory; + goto out; + } + saved_state = json_tokener_state_array_sep; + state = json_tokener_state_eatws; + goto redo_char; + + case json_tokener_state_array_sep: + if (c == ']') + { + // Minimize memory usage; assume parsed objs are unlikely to be changed + doca_third_party_json_object_array_shrink(current, 0); + + saved_state = json_tokener_state_finish; + state = json_tokener_state_eatws; + } + else if (c == ',') + { + saved_state = json_tokener_state_array_after_sep; + state = json_tokener_state_eatws; + } + else + { + tok->err = json_tokener_error_parse_array; + goto out; + } + break; + + case json_tokener_state_object_field_start: + case json_tokener_state_object_field_start_after_sep: + if (c == '}') + { + if (state == json_tokener_state_object_field_start_after_sep && + (tok->flags & JSON_TOKENER_STRICT)) + { + tok->err = json_tokener_error_parse_unexpected; + goto out; + } + saved_state = json_tokener_state_finish; + state = json_tokener_state_eatws; + } + else if (c == '"' || c == '\'') + { + tok->quote_char = c; + doca_third_party_printbuf_reset(tok->pb); + state = json_tokener_state_object_field; + } + else + { + tok->err = json_tokener_error_parse_object_key_name; + goto out; + } + break; + + case json_tokener_state_object_field: + { + /* Advance until we change state */ + const char *case_start = str; + while (1) + { + if (c == tok->quote_char) + { + printbuf_memappend_checked(tok->pb, case_start, + str - case_start); + obj_field_name = strdup(tok->pb->buf); + if (obj_field_name == NULL) + { + tok->err = json_tokener_error_memory; + goto out; + } + saved_state = json_tokener_state_object_field_end; + state = json_tokener_state_eatws; + break; + } + else if (c == '\\') + { + printbuf_memappend_checked(tok->pb, case_start, + str - case_start); + saved_state = json_tokener_state_object_field; + state = json_tokener_state_string_escape; + break; + } + if (!ADVANCE_CHAR(str, tok) || !PEEK_CHAR(c, tok)) + { + printbuf_memappend_checked(tok->pb, case_start, + str - case_start); + goto out; + } + } } - current = json_object_new_int64(num64); - if(current == NULL) - goto out; + break; + + case json_tokener_state_object_field_end: + if (c == ':') + { + saved_state = json_tokener_state_object_value; + state = json_tokener_state_eatws; + } + else + { + tok->err = json_tokener_error_parse_object_key_sep; + goto out; + } + break; + + case json_tokener_state_object_value: + if (tok->depth >= tok->max_depth - 1) + { + tok->err = json_tokener_error_depth; + goto out; + } + state = json_tokener_state_object_value_add; + tok->depth++; + json_tokener_reset_level(tok, tok->depth); + goto redo_char; + + case json_tokener_state_object_value_add: + doca_third_party_json_object_object_add(current, obj_field_name, obj); + free(obj_field_name); + obj_field_name = NULL; + saved_state = json_tokener_state_object_sep; + state = json_tokener_state_eatws; + goto redo_char; + + case json_tokener_state_object_sep: + /* { */ + if (c == '}') + { + saved_state = json_tokener_state_finish; + state = json_tokener_state_eatws; + } + else if (c == ',') + { + saved_state = json_tokener_state_object_field_start_after_sep; + state = json_tokener_state_eatws; + } + else + { + tok->err = json_tokener_error_parse_object_value_sep; + goto out; + } + break; + } + (void)ADVANCE_CHAR(str, tok); + if (!c) // This is the char *before* advancing + break; + } /* while(PEEK_CHAR) */ + +out: + if ((tok->flags & JSON_TOKENER_VALIDATE_UTF8) && (nBytes != 0)) + { + tok->err = json_tokener_error_parse_utf8_string; } - else if(tok->is_double && json_parse_double(tok->pb->buf, &numd) == 0) + if (c && (state == json_tokener_state_finish) && (tok->depth == 0) && + (tok->flags & (JSON_TOKENER_STRICT | JSON_TOKENER_ALLOW_TRAILING_CHARS)) == + JSON_TOKENER_STRICT) { - current = json_object_new_double_s(numd, tok->pb->buf); - if(current == NULL) - goto out; - } else { - tok->err = json_tokener_error_parse_number; - goto out; - } - saved_state = json_tokener_state_finish; - state = json_tokener_state_eatws; - goto redo_char; - } - break; - - case json_tokener_state_array_after_sep: - case json_tokener_state_array: - if(c == ']') { - if (state == json_tokener_state_array_after_sep && - (tok->flags & JSON_TOKENER_STRICT)) - { - tok->err = json_tokener_error_parse_unexpected; - goto out; - } - saved_state = json_tokener_state_finish; - state = json_tokener_state_eatws; - } else { - if(tok->depth >= tok->max_depth-1) { - tok->err = json_tokener_error_depth; - goto out; + /* unexpected char after JSON data */ + tok->err = json_tokener_error_parse_unexpected; } - state = json_tokener_state_array_add; - tok->depth++; - json_tokener_reset_level(tok, tok->depth); - goto redo_char; - } - break; - - case json_tokener_state_array_add: - if( json_object_array_add(current, obj) != 0 ) - goto out; - saved_state = json_tokener_state_array_sep; - state = json_tokener_state_eatws; - goto redo_char; - - case json_tokener_state_array_sep: - if(c == ']') { - saved_state = json_tokener_state_finish; - state = json_tokener_state_eatws; - } else if(c == ',') { - saved_state = json_tokener_state_array_after_sep; - state = json_tokener_state_eatws; - } else { - tok->err = json_tokener_error_parse_array; - goto out; - } - break; - - case json_tokener_state_object_field_start: - case json_tokener_state_object_field_start_after_sep: - if(c == '}') { - if (state == json_tokener_state_object_field_start_after_sep && - (tok->flags & JSON_TOKENER_STRICT)) - { - tok->err = json_tokener_error_parse_unexpected; - goto out; - } - saved_state = json_tokener_state_finish; - state = json_tokener_state_eatws; - } else if (c == '"' || c == '\'') { - tok->quote_char = c; - printbuf_reset(tok->pb); - state = json_tokener_state_object_field; - } else { - tok->err = json_tokener_error_parse_object_key_name; - goto out; - } - break; - - case json_tokener_state_object_field: - { - /* Advance until we change state */ - const char *case_start = str; - while(1) { - if(c == tok->quote_char) { - printbuf_memappend_fast(tok->pb, case_start, str-case_start); - obj_field_name = strdup(tok->pb->buf); - saved_state = json_tokener_state_object_field_end; - state = json_tokener_state_eatws; - break; - } else if(c == '\\') { - printbuf_memappend_fast(tok->pb, case_start, str-case_start); - saved_state = json_tokener_state_object_field; - state = json_tokener_state_string_escape; - break; - } - if (!ADVANCE_CHAR(str, tok) || !PEEK_CHAR(c, tok)) { - printbuf_memappend_fast(tok->pb, case_start, str-case_start); - goto out; - } + if (!c) + { + /* We hit an eof char (0) */ + if (state != json_tokener_state_finish && saved_state != json_tokener_state_finish) + tok->err = json_tokener_error_parse_eof; } - } - break; - - case json_tokener_state_object_field_end: - if(c == ':') { - saved_state = json_tokener_state_object_value; - state = json_tokener_state_eatws; - } else { - tok->err = json_tokener_error_parse_object_key_sep; - goto out; - } - break; - - case json_tokener_state_object_value: - if(tok->depth >= tok->max_depth-1) { - tok->err = json_tokener_error_depth; - goto out; - } - state = json_tokener_state_object_value_add; - tok->depth++; - json_tokener_reset_level(tok, tok->depth); - goto redo_char; - - case json_tokener_state_object_value_add: - json_object_object_add(current, obj_field_name, obj); - free(obj_field_name); - obj_field_name = NULL; - saved_state = json_tokener_state_object_sep; - state = json_tokener_state_eatws; - goto redo_char; - - case json_tokener_state_object_sep: - /* { */ - if(c == '}') { - saved_state = json_tokener_state_finish; - state = json_tokener_state_eatws; - } else if(c == ',') { - saved_state = json_tokener_state_object_field_start_after_sep; - state = json_tokener_state_eatws; - } else { - tok->err = json_tokener_error_parse_object_value_sep; - goto out; - } - break; - - } - if (!ADVANCE_CHAR(str, tok)) - goto out; - } /* while(PEEK_CHAR) */ - - out: - if (c && - (state == json_tokener_state_finish) && - (tok->depth == 0) && - (tok->flags & JSON_TOKENER_STRICT)) { - /* unexpected char after JSON data */ - tok->err = json_tokener_error_parse_unexpected; - } - if (!c) { /* We hit an eof char (0) */ - if(state != json_tokener_state_finish && - saved_state != json_tokener_state_finish) - tok->err = json_tokener_error_parse_eof; - } #ifdef HAVE_USELOCALE - uselocale(oldlocale); - freelocale(newloc); + uselocale(oldlocale); + freelocale(newloc); #elif defined(HAVE_SETLOCALE) - setlocale(LC_NUMERIC, oldlocale); - free(oldlocale); + setlocale(LC_NUMERIC, oldlocale); + free(oldlocale); #endif - if (tok->err == json_tokener_success) - { - json_object *ret = json_object_get(current); - int ii; + if (tok->err == json_tokener_success) + { + json_object *ret = doca_third_party_json_object_get(current); + int ii; - /* Partially reset, so we parse additional objects on subsequent calls. */ - for(ii = tok->depth; ii >= 0; ii--) - json_tokener_reset_level(tok, ii); - return ret; - } + /* Partially reset, so we parse additional objects on subsequent calls. */ + for (ii = tok->depth; ii >= 0; ii--) + json_tokener_reset_level(tok, ii); + return ret; + } + + MC_DEBUG("json_tokener_parse_ex: error %s at offset %d\n", json_tokener_errors[tok->err], + tok->char_offset); + return NULL; +} - MC_DEBUG("json_tokener_parse_ex: error %s at offset %d\n", - json_tokener_errors[tok->err], tok->char_offset); - return NULL; +static json_bool json_tokener_validate_utf8(const char c, unsigned int *nBytes) +{ + unsigned char chr = c; + if (*nBytes == 0) + { + if (chr >= 0x80) + { + if ((chr & 0xe0) == 0xc0) + *nBytes = 1; + else if ((chr & 0xf0) == 0xe0) + *nBytes = 2; + else if ((chr & 0xf8) == 0xf0) + *nBytes = 3; + else + return 0; + } + } + else + { + if ((chr & 0xC0) != 0x80) + return 0; + (*nBytes)--; + } + return 1; } -void json_tokener_set_flags(struct json_tokener *tok, int flags) +void doca_third_party_json_tokener_set_flags(struct json_tokener *tok, int flags) { tok->flags = flags; } + +size_t doca_third_party_json_tokener_get_parse_end(struct json_tokener *tok) +{ + assert(tok->char_offset >= 0); /* Drop this line when char_offset becomes a size_t */ + return (size_t)tok->char_offset; +} + +static int json_tokener_parse_double(const char *buf, int len, double *retval) +{ + char *end; + *retval = strtod(buf, &end); + if (buf + len == end) + return 0; // It worked + return 1; +} diff --git a/third_party/json-c/json_tokener.h b/third_party/json-c/json_tokener.h index ed272b673..52b8ad5e3 100644 --- a/third_party/json-c/json_tokener.h +++ b/third_party/json-c/json_tokener.h @@ -1,4 +1,6 @@ /* + * Original work: + * * $Id: json_tokener.h,v 1.10 2006/07/25 03:24:50 mclark Exp $ * * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd. @@ -7,6 +9,18 @@ * This library is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See COPYING for details. * + * Modified Work: + * + * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. + * + * This software product is a proprietary product of NVIDIA CORPORATION & + * AFFILIATES (the "Company") and all right, title, and interest in and to the + * software product, including all associated intellectual property rights, are + * and shall remain exclusively with the Company. + * + * This software product is governed by the End User License Agreement + * provided with the software product. + * */ /** @@ -16,80 +30,126 @@ #ifndef _json_tokener_h_ #define _json_tokener_h_ -#include #include "json_object.h" +#include #ifdef __cplusplus extern "C" { #endif -enum json_tokener_error { - json_tokener_success, - json_tokener_continue, - json_tokener_error_depth, - json_tokener_error_parse_eof, - json_tokener_error_parse_unexpected, - json_tokener_error_parse_null, - json_tokener_error_parse_boolean, - json_tokener_error_parse_number, - json_tokener_error_parse_array, - json_tokener_error_parse_object_key_name, - json_tokener_error_parse_object_key_sep, - json_tokener_error_parse_object_value_sep, - json_tokener_error_parse_string, - json_tokener_error_parse_comment, - json_tokener_error_size +enum json_tokener_error +{ + json_tokener_success, + json_tokener_continue, + json_tokener_error_depth, + json_tokener_error_parse_eof, + json_tokener_error_parse_unexpected, + json_tokener_error_parse_null, + json_tokener_error_parse_boolean, + json_tokener_error_parse_number, + json_tokener_error_parse_array, + json_tokener_error_parse_object_key_name, + json_tokener_error_parse_object_key_sep, + json_tokener_error_parse_object_value_sep, + json_tokener_error_parse_string, + json_tokener_error_parse_comment, + json_tokener_error_parse_utf8_string, + json_tokener_error_memory, + json_tokener_error_size }; -enum json_tokener_state { - json_tokener_state_eatws, - json_tokener_state_start, - json_tokener_state_finish, - json_tokener_state_null, - json_tokener_state_comment_start, - json_tokener_state_comment, - json_tokener_state_comment_eol, - json_tokener_state_comment_end, - json_tokener_state_string, - json_tokener_state_string_escape, - json_tokener_state_escape_unicode, - json_tokener_state_boolean, - json_tokener_state_number, - json_tokener_state_array, - json_tokener_state_array_add, - json_tokener_state_array_sep, - json_tokener_state_object_field_start, - json_tokener_state_object_field, - json_tokener_state_object_field_end, - json_tokener_state_object_value, - json_tokener_state_object_value_add, - json_tokener_state_object_sep, - json_tokener_state_array_after_sep, - json_tokener_state_object_field_start_after_sep, - json_tokener_state_inf +/** + * @deprecated Don't use this outside of json_tokener.c, it will be made private in a future release. + */ +enum json_tokener_state +{ + json_tokener_state_eatws, + json_tokener_state_start, + json_tokener_state_finish, + json_tokener_state_null, + json_tokener_state_comment_start, + json_tokener_state_comment, + json_tokener_state_comment_eol, + json_tokener_state_comment_end, + json_tokener_state_string, + json_tokener_state_string_escape, + json_tokener_state_escape_unicode, + json_tokener_state_escape_unicode_need_escape, + json_tokener_state_escape_unicode_need_u, + json_tokener_state_boolean, + json_tokener_state_number, + json_tokener_state_array, + json_tokener_state_array_add, + json_tokener_state_array_sep, + json_tokener_state_object_field_start, + json_tokener_state_object_field, + json_tokener_state_object_field_end, + json_tokener_state_object_value, + json_tokener_state_object_value_add, + json_tokener_state_object_sep, + json_tokener_state_array_after_sep, + json_tokener_state_object_field_start_after_sep, + json_tokener_state_inf }; +/** + * @deprecated Don't use this outside of json_tokener.c, it will be made private in a future release. + */ struct json_tokener_srec { - enum json_tokener_state state, saved_state; - struct json_object *obj; - struct json_object *current; - char *obj_field_name; + enum json_tokener_state state, saved_state; + struct json_object *obj; + struct json_object *current; + char *obj_field_name; }; #define JSON_TOKENER_DEFAULT_DEPTH 32 +/** + * Internal state of the json parser. + * Do not access any fields of this structure directly. + * Its definition is published due to historical limitations + * in the json tokener API, and will be changed to be an opaque + * type in the future. + */ struct json_tokener { - char *str; - struct printbuf *pb; - int max_depth, depth, is_double, st_pos, char_offset; - enum json_tokener_error err; - unsigned int ucs_char; - char quote_char; - struct json_tokener_srec *stack; - int flags; + /** + * @deprecated Do not access any of these fields outside of json_tokener.c + */ + char *str; + struct printbuf *pb; + int max_depth, depth, is_double, st_pos; + /** + * @deprecated See json_tokener_get_parse_end() instead. + */ + int char_offset; + /** + * @deprecated See json_tokener_get_error() instead. + */ + enum json_tokener_error err; + unsigned int ucs_char, high_surrogate; + char quote_char; + struct json_tokener_srec *stack; + int flags; }; + +/** + * Return the offset of the byte after the last byte parsed + * relative to the start of the most recent string passed in + * to json_tokener_parse_ex(). i.e. this is where parsing + * would start again if the input contains another JSON object + * after the currently parsed one. + * + * Note that when multiple parse calls are issued, this is *not* the + * total number of characters parsed. + * + * In the past this would have been accessed as tok->char_offset. + * + * See json_tokener_parse_ex() for an example of how to use this. + */ +JSON_EXPORT size_t doca_third_party_json_tokener_get_parse_end(struct json_tokener *tok); + /** * @deprecated Unused in json-c code */ @@ -101,11 +161,36 @@ typedef struct json_tokener json_tokener; * restrictive from one release to the next, causing your * code to fail on previously working input. * + * Note that setting this will also effectively disable parsing + * of multiple json objects in a single character stream + * (e.g. {"foo":123}{"bar":234}); if you want to allow that + * also set JSON_TOKENER_ALLOW_TRAILING_CHARS + * * This flag is not set by default. * * @see json_tokener_set_flags() */ -#define JSON_TOKENER_STRICT 0x01 +#define JSON_TOKENER_STRICT 0x01 + +/** + * Use with JSON_TOKENER_STRICT to allow trailing characters after the + * first parsed object. + * + * @see json_tokener_set_flags() + */ +#define JSON_TOKENER_ALLOW_TRAILING_CHARS 0x02 + +/** + * Cause json_tokener_parse_ex() to validate that input is UTF8. + * If this flag is specified and validation fails, then + * json_tokener_get_error(tok) will return + * json_tokener_error_parse_utf8_string + * + * This flag is not set by default. + * + * @see json_tokener_set_flags() + */ +#define JSON_TOKENER_VALIDATE_UTF8 0x10 /** * Given an error previously returned by json_tokener_get_error(), @@ -113,7 +198,7 @@ typedef struct json_tokener json_tokener; * * @return a generic error message is returned if an invalid error value is provided. */ -const char *json_tokener_error_desc(enum json_tokener_error jerr); +JSON_EXPORT const char *doca_third_party_json_tokener_error_desc(enum json_tokener_error jerr); /** * Retrieve the error caused by the last call to json_tokener_parse_ex(), @@ -122,21 +207,55 @@ const char *json_tokener_error_desc(enum json_tokener_error jerr); * When parsing a JSON string in pieces, if the tokener is in the middle * of parsing this will return json_tokener_continue. * - * See also json_tokener_error_desc(). + * @see json_tokener_error_desc(). */ -JSON_EXPORT enum json_tokener_error json_tokener_get_error(struct json_tokener *tok); +JSON_EXPORT enum json_tokener_error doca_third_party_json_tokener_get_error(struct json_tokener *tok); -JSON_EXPORT struct json_tokener* json_tokener_new(void); -JSON_EXPORT struct json_tokener* json_tokener_new_ex(int depth); -JSON_EXPORT void json_tokener_free(struct json_tokener *tok); -JSON_EXPORT void json_tokener_reset(struct json_tokener *tok); -JSON_EXPORT struct json_object* json_tokener_parse(const char *str); -JSON_EXPORT struct json_object* json_tokener_parse_verbose(const char *str, enum json_tokener_error *error); +/** + * Allocate a new json_tokener. + * When done using that to parse objects, free it with json_tokener_free(). + * See json_tokener_parse_ex() for usage details. + */ +JSON_EXPORT struct json_tokener *doca_third_party_json_tokener_new(void); + +/** + * Allocate a new json_tokener with a custom max nesting depth. + * @see JSON_TOKENER_DEFAULT_DEPTH + */ +JSON_EXPORT struct json_tokener *doca_third_party_json_tokener_new_ex(int depth); + +/** + * Free a json_tokener previously allocated with json_tokener_new(). + */ +JSON_EXPORT void doca_third_party_json_tokener_free(struct json_tokener *tok); + +/** + * Reset the state of a json_tokener, to prepare to parse a + * brand new JSON object. + */ +JSON_EXPORT void doca_third_party_json_tokener_reset(struct json_tokener *tok); + +/** + * Parse a json_object out of the string `str`. + * + * If you need more control over how the parsing occurs, + * see json_tokener_parse_ex(). + */ +JSON_EXPORT struct json_object *doca_third_party_json_tokener_parse(const char *str); + +/** + * Parser a json_object out of the string `str`, but if it fails + * return the error in `*error`. + * @see json_tokener_parse() + * @see json_tokener_parse_ex() + */ +JSON_EXPORT struct json_object *doca_third_party_json_tokener_parse_verbose(const char *str, + enum json_tokener_error *error); /** * Set flags that control how parsing will be done. */ -JSON_EXPORT void json_tokener_set_flags(struct json_tokener *tok, int flags); +JSON_EXPORT void doca_third_party_json_tokener_set_flags(struct json_tokener *tok, int flags); /** * Parse a string and return a non-NULL json_object if a valid JSON value @@ -151,26 +270,32 @@ JSON_EXPORT void json_tokener_set_flags(struct json_tokener *tok, int flags); * * If json_tokener_parse_ex() returns NULL and the error is anything other than * json_tokener_continue, a fatal error has occurred and parsing must be - * halted. Then, the tok object must not be reused until json_tokener_reset() is - * called. + * halted. Then, the tok object must not be reused until json_tokener_reset() + * is called. * * When a valid JSON value is parsed, a non-NULL json_object will be - * returned. Also, json_tokener_get_error() will return json_tokener_success. - * Be sure to check the type with json_object_is_type() or - * json_object_get_type() before using the object. + * returned, with a reference count of one which belongs to the caller. Also, + * json_tokener_get_error() will return json_tokener_success. Be sure to check + * the type with json_object_is_type() or json_object_get_type() before using + * the object. * - * @b XXX this shouldn't use internal fields: * Trailing characters after the parsed value do not automatically cause an * error. It is up to the caller to decide whether to treat this as an * error or to handle the additional characters, perhaps by parsing another * json value starting from that point. * - * Extra characters can be detected by comparing the tok->char_offset against + * If the caller knows that they are at the end of their input, the length + * passed MUST include the final '\0' character, so values with no inherent + * end (i.e. numbers) can be properly parsed, rather than just returning + * json_tokener_continue. + * + * Extra characters can be detected by comparing the value returned by + * json_tokener_get_parse_end() against * the length of the last len parameter passed in. * * The tokener does \b not maintain an internal buffer so the caller is - * responsible for calling json_tokener_parse_ex with an appropriate str - * parameter starting with the extra characters. + * responsible for a subsequent call to json_tokener_parse_ex with an + * appropriate str parameter starting with the extra characters. * * This interface is presently not 64-bit clean due to the int len argument * so the function limits the maximum string size to INT32_MAX (2GB). @@ -186,6 +311,8 @@ enum json_tokener_error jerr; do { mystring = ... // get JSON string, e.g. read from file, etc... stringlen = strlen(mystring); + if (end_of_input) + stringlen++; // Include the '\0' if we know we're at the end of input jobj = json_tokener_parse_ex(tok, mystring, stringlen); } while ((jerr = json_tokener_get_error(tok)) == json_tokener_continue); if (jerr != json_tokener_success) @@ -193,7 +320,7 @@ if (jerr != json_tokener_success) fprintf(stderr, "Error: %s\n", json_tokener_error_desc(jerr)); // Handle errors, as appropriate for your application. } -if (tok->char_offset < stringlen) // XXX shouldn't access internal fields +if (json_tokener_get_parse_end(tok) < stringlen) { // Handle extra characters after parsed object as desired. // e.g. issue an error, parse another object from that point, etc... @@ -206,8 +333,8 @@ if (tok->char_offset < stringlen) // XXX shouldn't access internal fields * @param str an string with any valid JSON expression, or portion of. This does not need to be null terminated. * @param len the length of str */ -JSON_EXPORT struct json_object* json_tokener_parse_ex(struct json_tokener *tok, - const char *str, int len); +JSON_EXPORT struct json_object *doca_third_party_json_tokener_parse_ex(struct json_tokener *tok, const char *str, + int len); #ifdef __cplusplus } diff --git a/third_party/json-c/json_types.h b/third_party/json-c/json_types.h new file mode 100644 index 000000000..b7e55ada8 --- /dev/null +++ b/third_party/json-c/json_types.h @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2020 Eric Hawicz + * + * This library is free software; you can redistribute it and/or modify + * it under the terms of the MIT license. See COPYING for details. + */ + +#ifndef _json_types_h_ +#define _json_types_h_ + +/** + * @file + * @brief Basic types used in a few places in json-c, but you should include "json_object.h" instead. + */ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JSON_EXPORT +#if defined(_MSC_VER) && defined(JSON_C_DLL) +#define JSON_EXPORT __declspec(dllexport) +#else +#define JSON_EXPORT extern +#endif +#endif + +struct printbuf; + +/** + * A structure to use with json_object_object_foreachC() loops. + * Contains key, val and entry members. + */ +struct json_object_iter +{ + char *key; + struct json_object *val; + struct lh_entry *entry; +}; +typedef struct json_object_iter json_object_iter; + +typedef int json_bool; + +/** + * @brief The core type for all type of JSON objects handled by json-c + */ +typedef struct json_object json_object; + +/** + * Type of custom user delete functions. See json_object_set_serializer. + */ +typedef void(json_object_delete_fn)(struct json_object *jso, void *userdata); + +/** + * Type of a custom serialization function. See json_object_set_serializer. + */ +typedef int(json_object_to_json_string_fn)(struct json_object *jso, struct printbuf *pb, int level, + int flags); + +/* supported object types */ + +typedef enum json_type +{ + /* If you change this, be sure to update json_type_to_name() too */ + json_type_null, + json_type_boolean, + json_type_double, + json_type_int, + json_type_object, + json_type_array, + json_type_string +} json_type; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/third_party/json-c/json_util.c b/third_party/json-c/json_util.c index ad7704a94..7d2dbf88e 100644 --- a/third_party/json-c/json_util.c +++ b/third_party/json-c/json_util.c @@ -1,4 +1,6 @@ /* + * Original work: + * * $Id: json_util.c,v 1.4 2006/01/30 23:07:57 mclark Exp $ * * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd. @@ -7,6 +9,18 @@ * This library is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See COPYING for details. * + * Modified Work: + * + * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. + * + * This software product is a proprietary product of NVIDIA CORPORATION & + * AFFILIATES (the "Company") and all right, title, and interest in and to the + * software product, including all associated intellectual property rights, are + * and shall remain exclusively with the Company. + * + * This software product is governed by the End User License Agreement + * provided with the software product. + * */ #include "config.h" @@ -14,13 +28,12 @@ #include "strerror_override.h" +#include #include +#include #include #include -#include -#include #include -#include #ifdef HAVE_SYS_TYPES_H #include @@ -35,44 +48,40 @@ #endif /* HAVE_FCNTL_H */ #ifdef HAVE_UNISTD_H -# include +#include #endif /* HAVE_UNISTD_H */ #ifdef WIN32 -# if MSC_VER < 1800 -/* strtoll is available only since Visual Studio 2013 */ -# define strtoll _strtoi64 -# endif -# define WIN32_LEAN_AND_MEAN -# include -# include +#define WIN32_LEAN_AND_MEAN +#include +#include #endif /* defined(WIN32) */ #if !defined(HAVE_OPEN) && defined(WIN32) -# define open _open +#define open _open #endif #include "snprintf_compat.h" #include "debug.h" -#include "printbuf.h" #include "json_inttypes.h" #include "json_object.h" #include "json_tokener.h" #include "json_util.h" +#include "printbuf.h" static int _json_object_to_fd(int fd, struct json_object *obj, int flags, const char *filename); static char _last_err[256] = ""; -const char *json_util_get_last_err() +const char *doca_third_party_json_util_get_last_err(void) { if (_last_err[0] == '\0') return NULL; return _last_err; } -void _json_c_set_last_err(const char *err_fmt, ...) +void doca_third_party__json_c_set_last_err(const char *err_fmt, ...) { va_list ap; va_start(ap, err_fmt); @@ -81,60 +90,103 @@ void _json_c_set_last_err(const char *err_fmt, ...) va_end(ap); } -struct json_object* json_object_from_fd(int fd) +struct json_object *doca_third_party_json_object_from_fd(int fd) { - struct printbuf *pb; - struct json_object *obj; - char buf[JSON_FILE_BUF_SIZE]; - int ret; - - if(!(pb = printbuf_new())) { - _json_c_set_last_err("json_object_from_file: printbuf_new failed\n"); - return NULL; - } - while((ret = read(fd, buf, JSON_FILE_BUF_SIZE)) > 0) { - printbuf_memappend(pb, buf, ret); - } - if(ret < 0) { - _json_c_set_last_err("json_object_from_fd: error reading fd %d: %s\n", fd, strerror(errno)); - printbuf_free(pb); - return NULL; - } - obj = json_tokener_parse(pb->buf); - printbuf_free(pb); - return obj; + return doca_third_party_json_object_from_fd_ex(fd, -1); +} +struct json_object *doca_third_party_json_object_from_fd_ex(int fd, int in_depth) +{ + struct printbuf *pb; + struct json_object *obj; + char buf[JSON_FILE_BUF_SIZE]; + ssize_t ret; + int depth = JSON_TOKENER_DEFAULT_DEPTH; + json_tokener *tok; + + if (!(pb = doca_third_party_printbuf_new())) + { + doca_third_party__json_c_set_last_err("json_object_from_fd_ex: printbuf_new failed\n"); + return NULL; + } + + if (in_depth != -1) + depth = in_depth; + tok = doca_third_party_json_tokener_new_ex(depth); + if (!tok) + { + doca_third_party__json_c_set_last_err( + "json_object_from_fd_ex: unable to allocate json_tokener(depth=%d): %s\n", + depth, strerror(errno)); + doca_third_party_printbuf_free(pb); + return NULL; + } + + while ((ret = read(fd, buf, sizeof(buf))) > 0) + { + if (doca_third_party_printbuf_memappend(pb, buf, ret) < 0) + { +#if JSON_FILE_BUF_SIZE > INT_MAX +#error "Can't append more than INT_MAX bytes at a time" +#endif + doca_third_party__json_c_set_last_err( + "json_object_from_fd_ex: failed to printbuf_memappend after reading %d+%d bytes: %s", printbuf_length(pb), (int)ret, strerror(errno)); + doca_third_party_json_tokener_free(tok); + doca_third_party_printbuf_free(pb); + return NULL; + } + } + if (ret < 0) + { + doca_third_party__json_c_set_last_err("json_object_from_fd_ex: error reading fd %d: %s\n", fd, + strerror(errno)); + doca_third_party_json_tokener_free(tok); + doca_third_party_printbuf_free(pb); + return NULL; + } + + obj = doca_third_party_json_tokener_parse_ex(tok, pb->buf, printbuf_length(pb)); + if (obj == NULL) + doca_third_party__json_c_set_last_err("json_tokener_parse_ex failed: %s\n", + doca_third_party_json_tokener_error_desc(doca_third_party_json_tokener_get_error(tok))); + + doca_third_party_json_tokener_free(tok); + doca_third_party_printbuf_free(pb); + return obj; } -struct json_object* json_object_from_file(const char *filename) +struct json_object *doca_third_party_json_object_from_file(const char *filename) { - struct json_object *obj; - int fd; - - if((fd = open(filename, O_RDONLY)) < 0) { - _json_c_set_last_err("json_object_from_file: error opening file %s: %s\n", - filename, strerror(errno)); - return NULL; - } - obj = json_object_from_fd(fd); - close(fd); - return obj; + struct json_object *obj; + int fd; + + if ((fd = open(filename, O_RDONLY)) < 0) + { + doca_third_party__json_c_set_last_err("json_object_from_file: error opening file %s: %s\n", + filename, strerror(errno)); + return NULL; + } + obj = doca_third_party_json_object_from_fd(fd); + close(fd); + return obj; } /* extended "format and write to file" function */ -int json_object_to_file_ext(const char *filename, struct json_object *obj, int flags) +int doca_third_party_json_object_to_file_ext(const char *filename, struct json_object *obj, int flags) { int fd, ret; int saved_errno; - if (!obj) { - _json_c_set_last_err("json_object_to_file: object is null\n"); + if (!obj) + { + doca_third_party__json_c_set_last_err("json_object_to_file_ext: object is null\n"); return -1; } - if ((fd = open(filename, O_WRONLY | O_TRUNC | O_CREAT, 0644)) < 0) { - _json_c_set_last_err("json_object_to_file: error opening file %s: %s\n", - filename, strerror(errno)); + if ((fd = open(filename, O_WRONLY | O_TRUNC | O_CREAT, 0644)) < 0) + { + doca_third_party__json_c_set_last_err("json_object_to_file_ext: error opening file %s: %s\n", + filename, strerror(errno)); return -1; } ret = _json_object_to_fd(fd, obj, flags, filename); @@ -144,10 +196,11 @@ int json_object_to_file_ext(const char *filename, struct json_object *obj, int f return ret; } -int json_object_to_fd(int fd, struct json_object *obj, int flags) +int doca_third_party_json_object_to_fd(int fd, struct json_object *obj, int flags) { - if (!obj) { - _json_c_set_last_err("json_object_to_fd: object is null\n"); + if (!obj) + { + doca_third_party__json_c_set_last_err("json_object_to_fd: object is null\n"); return -1; } @@ -155,27 +208,30 @@ int json_object_to_fd(int fd, struct json_object *obj, int flags) } static int _json_object_to_fd(int fd, struct json_object *obj, int flags, const char *filename) { - int ret; + ssize_t ret; const char *json_str; - unsigned int wpos, wsize; + size_t wpos, wsize; filename = filename ? filename : "(fd)"; - if (!(json_str = json_object_to_json_string_ext(obj,flags))) { + if (!(json_str = doca_third_party_json_object_to_json_string_ext(obj, flags))) + { return -1; } - wsize = (unsigned int)(strlen(json_str) & UINT_MAX); /* CAW: probably unnecessary, but the most 64bit safe */ + wsize = strlen(json_str); wpos = 0; - while(wpos < wsize) { - if((ret = write(fd, json_str + wpos, wsize-wpos)) < 0) { - _json_c_set_last_err("json_object_to_file: error writing file %s: %s\n", - filename, strerror(errno)); - return -1; + while (wpos < wsize) + { + if ((ret = write(fd, json_str + wpos, wsize - wpos)) < 0) + { + doca_third_party__json_c_set_last_err("json_object_to_fd: error writing file %s: %s\n", + filename, strerror(errno)); + return -1; } /* because of the above check for ret < 0, we can safely cast and add */ - wpos += (unsigned int)ret; + wpos += (size_t)ret; } return 0; @@ -183,19 +239,20 @@ static int _json_object_to_fd(int fd, struct json_object *obj, int flags, const // backwards compatible "format and write to file" function -int json_object_to_file(const char *filename, struct json_object *obj) +int doca_third_party_json_object_to_file(const char *filename, struct json_object *obj) { - return json_object_to_file_ext(filename, obj, JSON_C_TO_STRING_PLAIN); + return doca_third_party_json_object_to_file_ext(filename, obj, JSON_C_TO_STRING_PLAIN); } -int json_parse_double(const char *buf, double *retval) +// Deprecated json_parse_double function. See json_tokener_parse_double instead. +int doca_third_party_json_parse_double(const char *buf, double *retval) { - char *end; - *retval = strtod(buf, &end); - return end == buf ? 1 : 0; + char *end; + *retval = strtod(buf, &end); + return end == buf ? 1 : 0; } -int json_parse_int64(const char *buf, int64_t *retval) +int doca_third_party_json_parse_int64(const char *buf, int64_t *retval) { char *end = NULL; int64_t val; @@ -204,11 +261,38 @@ int json_parse_int64(const char *buf, int64_t *retval) val = strtoll(buf, &end, 10); if (end != buf) *retval = val; - return ((val == 0 && errno != 0) || (end == buf)) ? 1 : 0; + if ((val == 0 && errno != 0) || (end == buf)) + { + errno = EINVAL; + return 1; + } + return 0; +} + +int doca_third_party_json_parse_uint64(const char *buf, uint64_t *retval) +{ + char *end = NULL; + uint64_t val; + + errno = 0; + while (*buf == ' ') + buf++; + if (*buf == '-') + return 1; /* error: uint cannot be negative */ + + val = strtoull(buf, &end, 10); + if (end != buf) + *retval = val; + if ((val == 0 && errno != 0) || (end == buf)) + { + errno = EINVAL; + return 1; + } + return 0; } #ifndef HAVE_REALLOC -void* rpl_realloc(void* p, size_t n) +void *rpl_realloc(void *p, size_t n) { if (n == 0) n = 1; @@ -218,26 +302,28 @@ void* rpl_realloc(void* p, size_t n) } #endif -#define NELEM(a) (sizeof(a) / sizeof(a[0])) -static const char* json_type_name[] = { - /* If you change this, be sure to update the enum json_type definition too */ - "null", - "boolean", - "double", - "int", - "object", - "array", - "string", +#define NELEM(a) (sizeof(a) / sizeof(a[0])) +/* clang-format off */ +static const char *json_type_name[] = { + /* If you change this, be sure to update the enum json_type definition too */ + "null", + "boolean", + "double", + "int", + "object", + "array", + "string", }; +/* clang-format on */ -const char *json_type_to_name(enum json_type o_type) +const char *doca_third_party_json_type_to_name(enum json_type o_type) { int o_type_int = (int)o_type; if (o_type_int < 0 || o_type_int >= (int)NELEM(json_type_name)) { - _json_c_set_last_err("json_type_to_name: type %d is out of range [0,%d]\n", o_type, NELEM(json_type_name)); + doca_third_party__json_c_set_last_err("json_type_to_name: type %d is out of range [0,%u]\n", o_type, + (unsigned)NELEM(json_type_name)); return NULL; } return json_type_name[o_type]; } - diff --git a/third_party/json-c/json_util.h b/third_party/json-c/json_util.h index e065f60c6..ef86cf286 100644 --- a/third_party/json-c/json_util.h +++ b/third_party/json-c/json_util.h @@ -1,4 +1,6 @@ /* + * Original work: + * * $Id: json_util.h,v 1.4 2006/01/30 23:07:57 mclark Exp $ * * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd. @@ -7,26 +9,38 @@ * This library is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See COPYING for details. * + * Modified Work: + * + * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. + * + * This software product is a proprietary product of NVIDIA CORPORATION & + * AFFILIATES (the "Company") and all right, title, and interest in and to the + * software product, including all associated intellectual property rights, are + * and shall remain exclusively with the Company. + * + * This software product is governed by the End User License Agreement + * provided with the software product. + * */ + /** * @file * @brief Miscllaneous utility functions and macros. - */ + */ #ifndef _json_util_h_ #define _json_util_h_ #include "json_object.h" #ifndef json_min -#define json_min(a,b) ((a) < (b) ? (a) : (b)) +#define json_min(a, b) ((a) < (b) ? (a) : (b)) #endif #ifndef json_max -#define json_max(a,b) ((a) > (b) ? (a) : (b)) +#define json_max(a, b) ((a) > (b) ? (a) : (b)) #endif - #ifdef __cplusplus extern "C" { #endif @@ -38,9 +52,9 @@ extern "C" { * Read the full contents of the given file, then convert it to a * json_object using json_tokener_parse(). * - * Returns -1 if something fails. See json_util_get_last_err() for details. + * Returns NULL on failure. See json_util_get_last_err() for details. */ -extern struct json_object* json_object_from_file(const char *filename); +JSON_EXPORT struct json_object *doca_third_party_json_object_from_file(const char *filename); /** * Create a JSON object from already opened file descriptor. @@ -50,9 +64,21 @@ extern struct json_object* json_object_from_file(const char *filename); * Note, that the fd must be readable at the actual position, i.e. * use lseek(fd, 0, SEEK_SET) before. * - * Returns -1 if something fails. See json_util_get_last_err() for details. + * The depth argument specifies the maximum object depth to pass to + * json_tokener_new_ex(). When depth == -1, JSON_TOKENER_DEFAULT_DEPTH + * is used instead. + * + * Returns NULL on failure. See json_util_get_last_err() for details. */ -extern struct json_object* json_object_from_fd(int fd); +JSON_EXPORT struct json_object *doca_third_party_json_object_from_fd_ex(int fd, int depth); + +/** + * Create a JSON object from an already opened file descriptor, using + * the default maximum object depth. (JSON_TOKENER_DEFAULT_DEPTH) + * + * See json_object_from_fd_ex() for details. + */ +JSON_EXPORT struct json_object *doca_third_party_json_object_from_fd(int fd); /** * Equivalent to: @@ -60,7 +86,7 @@ extern struct json_object* json_object_from_fd(int fd); * * Returns -1 if something fails. See json_util_get_last_err() for details. */ -extern int json_object_to_file(const char *filename, struct json_object *obj); +JSON_EXPORT int doca_third_party_json_object_to_file(const char *filename, struct json_object *obj); /** * Open and truncate the given file, creating it if necessary, then @@ -68,7 +94,7 @@ extern int json_object_to_file(const char *filename, struct json_object *obj); * * Returns -1 if something fails. See json_util_get_last_err() for details. */ -extern int json_object_to_file_ext(const char *filename, struct json_object *obj, int flags); +JSON_EXPORT int doca_third_party_json_object_to_file_ext(const char *filename, struct json_object *obj, int flags); /** * Convert the json_object to a string and write it to the file descriptor. @@ -80,24 +106,37 @@ extern int json_object_to_file_ext(const char *filename, struct json_object *obj * @param flags flags to pass to json_object_to_json_string_ext() * @return -1 if something fails. See json_util_get_last_err() for details. */ -extern int json_object_to_fd(int fd, struct json_object *obj, int flags); +JSON_EXPORT int doca_third_party_json_object_to_fd(int fd, struct json_object *obj, int flags); /** * Return the last error from various json-c functions, including: * json_object_to_file{,_ext}, json_object_to_fd() or * json_object_from_{file,fd}, or NULL if there is none. */ -const char *json_util_get_last_err(void); - +JSON_EXPORT const char *doca_third_party_json_util_get_last_err(void); -extern int json_parse_int64(const char *buf, int64_t *retval); -extern int json_parse_double(const char *buf, double *retval); +/** + * A parsing helper for integer values. Returns 0 on success, + * with the parsed value assigned to *retval. Overflow/underflow + * are NOT considered errors, but errno will be set to ERANGE, + * just like the strtol/strtoll functions do. + */ +JSON_EXPORT int doca_third_party_json_parse_int64(const char *buf, int64_t *retval); +/** + * A parsing help for integer values, providing one extra bit of + * magnitude beyond json_parse_int64(). + */ +JSON_EXPORT int doca_third_party_json_parse_uint64(const char *buf, uint64_t *retval); +/** + * @deprecated + */ +JSON_EXPORT int doca_third_party_json_parse_double(const char *buf, double *retval); /** * Return a string describing the type of the object. * e.g. "int", or "object", etc... */ -extern const char *json_type_to_name(enum json_type o_type); +JSON_EXPORT const char *doca_third_party_json_type_to_name(enum json_type o_type); #ifdef __cplusplus } diff --git a/third_party/json-c/json_visit.c b/third_party/json-c/json_visit.c index 1126ff8d7..25baedba0 100644 --- a/third_party/json-c/json_visit.c +++ b/third_party/json-c/json_visit.c @@ -1,8 +1,23 @@ /* + * Original work: + * * Copyright (c) 2016 Eric Haszlakiewicz * * This is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See COPYING for details. + * + * Modified Work: + * + * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. + * + * This software product is a proprietary product of NVIDIA CORPORATION & + * AFFILIATES (the "Company") and all right, title, and interest in and to the + * software product, including all associated intellectual property rights, are + * and shall remain exclusively with the Company. + * + * This software product is governed by the End User License Agreement + * provided with the software product. + * */ #include @@ -13,45 +28,39 @@ #include "json_visit.h" #include "linkhash.h" -static int _json_c_visit(json_object *jso, json_object *parent_jso, - const char *jso_key, size_t *jso_index, - json_c_visit_userfunc *userfunc, void *userarg); +static int _json_c_visit(json_object *jso, json_object *parent_jso, const char *jso_key, + size_t *jso_index, json_c_visit_userfunc *userfunc, void *userarg); -int json_c_visit(json_object *jso, int future_flags, - json_c_visit_userfunc *userfunc, void *userarg) +int doca_third_party_json_c_visit(json_object *jso, int future_flags, json_c_visit_userfunc *userfunc, void *userarg) { int ret = _json_c_visit(jso, NULL, NULL, NULL, userfunc, userarg); - switch(ret) + switch (ret) { case JSON_C_VISIT_RETURN_CONTINUE: case JSON_C_VISIT_RETURN_SKIP: case JSON_C_VISIT_RETURN_POP: - case JSON_C_VISIT_RETURN_STOP: - return 0; - default: - return JSON_C_VISIT_RETURN_ERROR; + case JSON_C_VISIT_RETURN_STOP: return 0; + default: return JSON_C_VISIT_RETURN_ERROR; } } -static int _json_c_visit(json_object *jso, json_object *parent_jso, - const char *jso_key, size_t *jso_index, - json_c_visit_userfunc *userfunc, void *userarg) +static int _json_c_visit(json_object *jso, json_object *parent_jso, const char *jso_key, + size_t *jso_index, json_c_visit_userfunc *userfunc, void *userarg) { int userret = userfunc(jso, 0, parent_jso, jso_key, jso_index, userarg); - switch(userret) + switch (userret) { - case JSON_C_VISIT_RETURN_CONTINUE: - break; + case JSON_C_VISIT_RETURN_CONTINUE: break; case JSON_C_VISIT_RETURN_SKIP: case JSON_C_VISIT_RETURN_POP: case JSON_C_VISIT_RETURN_STOP: - case JSON_C_VISIT_RETURN_ERROR: - return userret; + case JSON_C_VISIT_RETURN_ERROR: return userret; default: - fprintf(stderr, "ERROR: invalid return value from json_c_visit userfunc: %d\n", userret); + fprintf(stderr, "ERROR: invalid return value from json_c_visit userfunc: %d\n", + userret); return JSON_C_VISIT_RETURN_ERROR; } - switch(json_object_get_type(jso)) + switch (doca_third_party_json_object_get_type(jso)) { case json_type_null: case json_type_boolean: @@ -63,18 +72,19 @@ static int _json_c_visit(json_object *jso, json_object *parent_jso, case json_type_object: { - json_object_object_foreach(jso, key, child) + doca_third_party_json_object_object_foreach(jso, key, child) { userret = _json_c_visit(child, jso, key, NULL, userfunc, userarg); if (userret == JSON_C_VISIT_RETURN_POP) break; if (userret == JSON_C_VISIT_RETURN_STOP || - userret == JSON_C_VISIT_RETURN_ERROR) + userret == JSON_C_VISIT_RETURN_ERROR) return userret; if (userret != JSON_C_VISIT_RETURN_CONTINUE && - userret != JSON_C_VISIT_RETURN_SKIP) + userret != JSON_C_VISIT_RETURN_SKIP) { - fprintf(stderr, "INTERNAL ERROR: _json_c_visit returned %d\n", userret); + fprintf(stderr, "INTERNAL ERROR: _json_c_visit returned %d\n", + userret); return JSON_C_VISIT_RETURN_ERROR; } } @@ -82,28 +92,30 @@ static int _json_c_visit(json_object *jso, json_object *parent_jso, } case json_type_array: { - size_t array_len = json_object_array_length(jso); + size_t array_len = doca_third_party_json_object_array_length(jso); size_t ii; for (ii = 0; ii < array_len; ii++) { - json_object *child = json_object_array_get_idx(jso, ii); + json_object *child = doca_third_party_json_object_array_get_idx(jso, ii); userret = _json_c_visit(child, jso, NULL, &ii, userfunc, userarg); if (userret == JSON_C_VISIT_RETURN_POP) break; if (userret == JSON_C_VISIT_RETURN_STOP || - userret == JSON_C_VISIT_RETURN_ERROR) + userret == JSON_C_VISIT_RETURN_ERROR) return userret; if (userret != JSON_C_VISIT_RETURN_CONTINUE && - userret != JSON_C_VISIT_RETURN_SKIP) + userret != JSON_C_VISIT_RETURN_SKIP) { - fprintf(stderr, "INTERNAL ERROR: _json_c_visit returned %d\n", userret); + fprintf(stderr, "INTERNAL ERROR: _json_c_visit returned %d\n", + userret); return JSON_C_VISIT_RETURN_ERROR; } } break; } default: - fprintf(stderr, "INTERNAL ERROR: _json_c_visit found object of unknown type: %d\n", json_object_get_type(jso)); + fprintf(stderr, "INTERNAL ERROR: _json_c_visit found object of unknown type: %d\n", + doca_third_party_json_object_get_type(jso)); return JSON_C_VISIT_RETURN_ERROR; } @@ -112,22 +124,20 @@ static int _json_c_visit(json_object *jso, json_object *parent_jso, // Non-container types will have already returned before this point. userret = userfunc(jso, JSON_C_VISIT_SECOND, parent_jso, jso_key, jso_index, userarg); - switch(userret) + switch (userret) { case JSON_C_VISIT_RETURN_SKIP: case JSON_C_VISIT_RETURN_POP: - // These are not really sensible during JSON_C_VISIT_SECOND, + // These are not really sensible during JSON_C_VISIT_SECOND, // but map them to JSON_C_VISIT_CONTINUE anyway. // FALLTHROUGH - case JSON_C_VISIT_RETURN_CONTINUE: - return JSON_C_VISIT_RETURN_CONTINUE; + case JSON_C_VISIT_RETURN_CONTINUE: return JSON_C_VISIT_RETURN_CONTINUE; case JSON_C_VISIT_RETURN_STOP: - case JSON_C_VISIT_RETURN_ERROR: - return userret; + case JSON_C_VISIT_RETURN_ERROR: return userret; default: - fprintf(stderr, "ERROR: invalid return value from json_c_visit userfunc: %d\n", userret); + fprintf(stderr, "ERROR: invalid return value from json_c_visit userfunc: %d\n", + userret); return JSON_C_VISIT_RETURN_ERROR; } // NOTREACHED } - diff --git a/third_party/json-c/json_visit.h b/third_party/json-c/json_visit.h index b147d99eb..848913f47 100644 --- a/third_party/json-c/json_visit.h +++ b/third_party/json-c/json_visit.h @@ -1,3 +1,21 @@ +/* + * Original work: + * + * json-c (copyright was originally missing from this file) + * + * Modified Work: + * + * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. + * + * This software product is a proprietary product of NVIDIA CORPORATION & + * AFFILIATES (the "Company") and all right, title, and interest in and to the + * software product, including all associated intellectual property rights, are + * and shall remain exclusively with the Company. + * + * This software product is governed by the End User License Agreement + * provided with the software product. + * + */ #ifndef _json_c_json_visit_h_ #define _json_c_json_visit_h_ @@ -8,9 +26,12 @@ */ #include "json_object.h" -typedef int (json_c_visit_userfunc)(json_object *jso, int flags, - json_object *parent_jso, const char *jso_key, - size_t *jso_index, void *userarg); +#ifdef __cplusplus +extern "C" { +#endif + +typedef int(json_c_visit_userfunc)(json_object *jso, int flags, json_object *parent_jso, + const char *jso_key, size_t *jso_index, void *userarg); /** * Visit each object in the JSON hierarchy starting at jso. @@ -26,20 +47,20 @@ typedef int (json_c_visit_userfunc)(json_object *jso, int flags, * userfunc must return one of the defined return values, to indicate * whether and how to continue visiting nodes, or one of various ways to stop. * - * Returns 0 if nodes were visited successfully, even if some were + * Returns 0 if nodes were visited successfully, even if some were * intentionally skipped due to what userfunc returned. * Returns <0 if an error occurred during iteration, including if * userfunc returned JSON_C_VISIT_RETURN_ERROR. */ -int json_c_visit(json_object *jso, int future_flags, - json_c_visit_userfunc *userfunc, void *userarg); +JSON_EXPORT int doca_third_party_json_c_visit(json_object *jso, int future_flags, json_c_visit_userfunc *userfunc, + void *userarg); /** * Passed to json_c_visit_userfunc as one of the flags values to indicate * that this is the second time a container (array or object) is being * called, after all of it's members have been iterated over. */ -#define JSON_C_VISIT_SECOND 0x02 +#define JSON_C_VISIT_SECOND 0x02 /** * This json_c_visit_userfunc return value indicates that iteration @@ -47,7 +68,6 @@ int json_c_visit(json_object *jso, int future_flags, */ #define JSON_C_VISIT_RETURN_CONTINUE 0 - /** * This json_c_visit_userfunc return value indicates that iteration * over the members of the current object should be skipped. @@ -60,7 +80,7 @@ int json_c_visit(json_object *jso, int future_flags, * This json_c_visit_userfunc return value indicates that iteration * of the fields/elements of the containing object should stop * and continue "popped up" a level of the object hierarchy. - * For example, returning this when handling arg will result in + * For example, returning this when handling arg will result in * arg3 and any other fields being skipped. The next call to userfunc * will be the JSON_C_VISIT_SECOND call on "foo", followed by a userfunc * call on "bar". @@ -92,4 +112,8 @@ int json_c_visit(json_object *jso, int future_flags, */ #define JSON_C_VISIT_RETURN_ERROR -1 +#ifdef __cplusplus +} +#endif + #endif /* _json_c_json_visit_h_ */ diff --git a/third_party/json-c/libjson.c b/third_party/json-c/libjson.c index b19df42f7..83d0a87fd 100644 --- a/third_party/json-c/libjson.c +++ b/third_party/json-c/libjson.c @@ -7,13 +7,13 @@ #ifndef __warn_references -#if defined(__GNUC__) && defined (HAS_GNU_WARNING_LONG) +#if defined(__GNUC__) && defined(HAS_GNU_WARNING_LONG) -#define __warn_references(sym,msg) \ - __asm__(".section .gnu" #sym ",\n\t.ascii \"" msg "\"\n\t.text"); +#define __warn_references(sym, msg) \ + __asm__(".section .gnu" #sym ",\n\t.ascii \"" msg "\"\n\t.text"); #else -#define __warn_references(sym,msg) /* nothing */ +#define __warn_references(sym, msg) /* nothing */ #endif #endif diff --git a/third_party/json-c/linkhash.c b/third_party/json-c/linkhash.c index 5497061a8..b9174e4c2 100644 --- a/third_party/json-c/linkhash.c +++ b/third_party/json-c/linkhash.c @@ -1,4 +1,6 @@ /* + * Original work: + * * $Id: linkhash.c,v 1.4 2006/01/26 02:16:28 mclark Exp $ * * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd. @@ -8,75 +10,78 @@ * This library is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See COPYING for details. * + * Modified Work: + * + * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. + * + * This software product is a proprietary product of NVIDIA CORPORATION & + * AFFILIATES (the "Company") and all right, title, and interest in and to the + * software product, including all associated intellectual property rights, are + * and shall remain exclusively with the Company. + * + * This software product is governed by the End User License Agreement + * provided with the software product. + * */ #include "config.h" -#include -#include -#include +#include +#include #include #include -#include +#include +#include +#include #ifdef HAVE_ENDIAN_H -# include /* attempt to define endianness */ +#include /* attempt to define endianness */ #endif #if defined(_MSC_VER) || defined(__MINGW32__) -# define WIN32_LEAN_AND_MEAN -# include /* Get InterlockedCompareExchange */ +#define WIN32_LEAN_AND_MEAN +#include /* Get InterlockedCompareExchange */ #endif -#include "random_seed.h" #include "linkhash.h" +#include "random_seed.h" /* hash functions */ static unsigned long lh_char_hash(const void *k); static unsigned long lh_perllike_str_hash(const void *k); static lh_hash_fn *char_hash_fn = lh_char_hash; -int -json_global_set_string_hash(const int h) +/* comparison functions */ +int doca_third_party_lh_char_equal(const void *k1, const void *k2); +int doca_third_party_lh_ptr_equal(const void *k1, const void *k2); + +int doca_third_party_json_global_set_string_hash(const int h) { - switch(h) { - case JSON_C_STR_HASH_DFLT: - char_hash_fn = lh_char_hash; - break; - case JSON_C_STR_HASH_PERLLIKE: - char_hash_fn = lh_perllike_str_hash; - break; - default: - return -1; + switch (h) + { + case JSON_C_STR_HASH_DFLT: char_hash_fn = lh_char_hash; break; + case JSON_C_STR_HASH_PERLLIKE: char_hash_fn = lh_perllike_str_hash; break; + default: return -1; } return 0; } -void lh_abort(const char *msg, ...) -{ - va_list ap; - va_start(ap, msg); - vprintf(msg, ap); - va_end(ap); - exit(1); -} - static unsigned long lh_ptr_hash(const void *k) { /* CAW: refactored to be 64bit nice */ return (unsigned long)((((ptrdiff_t)k * LH_PRIME) >> 4) & ULONG_MAX); } -int lh_ptr_equal(const void *k1, const void *k2) +int doca_third_party_lh_ptr_equal(const void *k1, const void *k2) { return (k1 == k2); } /* * hashlittle from lookup3.c, by Bob Jenkins, May 2006, Public Domain. - * http://burtleburtle.net/bob/c/lookup3.c + * https://burtleburtle.net/bob/c/lookup3.c * minor modifications to make functions static so no symbols are exported - * minor mofifications to compile with -Werror + * minor modifications to compile with -Werror */ /* @@ -90,7 +95,7 @@ if SELF_TEST is defined. You can use this free for any purpose. It's in the public domain. It has no warranty. You probably want to use hashlittle(). hashlittle() and hashbig() -hash byte arrays. hashlittle() is is faster than hashbig() on +hash byte arrays. hashlittle() is faster than hashbig() on little-endian machines. Intel and AMD are little-endian machines. On second thought, you probably want hashlittle2(), which is identical to hashlittle() except it returns two 32-bit hashes for the price of one. @@ -119,25 +124,23 @@ on 1 byte), but shoehorning those bytes into integers efficiently is messy. * My best guess at if you are big-endian or little-endian. This may * need adjustment. */ -#if (defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && \ - __BYTE_ORDER == __LITTLE_ENDIAN) || \ - (defined(i386) || defined(__i386__) || defined(__i486__) || \ - defined(__i586__) || defined(__i686__) || defined(vax) || defined(MIPSEL)) -# define HASH_LITTLE_ENDIAN 1 -# define HASH_BIG_ENDIAN 0 -#elif (defined(__BYTE_ORDER) && defined(__BIG_ENDIAN) && \ - __BYTE_ORDER == __BIG_ENDIAN) || \ - (defined(sparc) || defined(POWERPC) || defined(mc68000) || defined(sel)) -# define HASH_LITTLE_ENDIAN 0 -# define HASH_BIG_ENDIAN 1 +#if (defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && __BYTE_ORDER == __LITTLE_ENDIAN) || \ + (defined(i386) || defined(__i386__) || defined(__i486__) || defined(__i586__) || \ + defined(__i686__) || defined(vax) || defined(MIPSEL)) +#define HASH_LITTLE_ENDIAN 1 +#define HASH_BIG_ENDIAN 0 +#elif (defined(__BYTE_ORDER) && defined(__BIG_ENDIAN) && __BYTE_ORDER == __BIG_ENDIAN) || \ + (defined(sparc) || defined(POWERPC) || defined(mc68000) || defined(sel)) +#define HASH_LITTLE_ENDIAN 0 +#define HASH_BIG_ENDIAN 1 #else -# define HASH_LITTLE_ENDIAN 0 -# define HASH_BIG_ENDIAN 0 +#define HASH_LITTLE_ENDIAN 0 +#define HASH_BIG_ENDIAN 0 #endif -#define hashsize(n) ((uint32_t)1<<(n)) -#define hashmask(n) (hashsize(n)-1) -#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k)))) +#define hashsize(n) ((uint32_t)1 << (n)) +#define hashmask(n) (hashsize(n) - 1) +#define rot(x, k) (((x) << (k)) | ((x) >> (32 - (k)))) /* ------------------------------------------------------------------------------- @@ -167,7 +170,7 @@ satisfy this are 14 9 3 7 17 3 Well, "9 15 3 18 27 15" didn't quite get 32 bits diffing for "differ" defined as + with a one-bit base and a two-bit delta. I -used http://burtleburtle.net/bob/hash/avalanche.html to choose +used https://burtleburtle.net/bob/hash/avalanche.html to choose the operations, constants, and arrangements of the variables. This does not achieve avalanche. There are input bits of (a,b,c) @@ -183,15 +186,17 @@ on, and rotates are much kinder to the top and bottom bits, so I used rotates. ------------------------------------------------------------------------------- */ +/* clang-format off */ #define mix(a,b,c) \ { \ - a -= c; a ^= rot(c, 4); c += b; \ - b -= a; b ^= rot(a, 6); a += c; \ - c -= b; c ^= rot(b, 8); b += a; \ - a -= c; a ^= rot(c,16); c += b; \ - b -= a; b ^= rot(a,19); a += c; \ - c -= b; c ^= rot(b, 4); b += a; \ + a -= c; a ^= rot(c, 4); c += b; \ + b -= a; b ^= rot(a, 6); a += c; \ + c -= b; c ^= rot(b, 8); b += a; \ + a -= c; a ^= rot(c,16); c += b; \ + b -= a; b ^= rot(a,19); a += c; \ + c -= b; c ^= rot(b, 4); b += a; \ } +/* clang-format on */ /* ------------------------------------------------------------------------------- @@ -218,17 +223,18 @@ and these came close: 11 8 15 26 3 22 24 ------------------------------------------------------------------------------- */ +/* clang-format off */ #define final(a,b,c) \ { \ - c ^= b; c -= rot(b,14); \ - a ^= c; a -= rot(c,11); \ - b ^= a; b -= rot(a,25); \ - c ^= b; c -= rot(b,16); \ - a ^= c; a -= rot(c,4); \ - b ^= a; b -= rot(a,14); \ - c ^= b; c -= rot(b,24); \ + c ^= b; c -= rot(b,14); \ + a ^= c; a -= rot(c,11); \ + b ^= a; b -= rot(a,25); \ + c ^= b; c -= rot(b,16); \ + a ^= c; a -= rot(c,4); \ + b ^= a; b -= rot(a,14); \ + c ^= b; c -= rot(b,24); \ } - +/* clang-format on */ /* ------------------------------------------------------------------------------- @@ -257,197 +263,208 @@ acceptable. Do NOT use for cryptographic purposes. ------------------------------------------------------------------------------- */ -static uint32_t hashlittle( const void *key, size_t length, uint32_t initval) +/* clang-format off */ +static uint32_t hashlittle(const void *key, size_t length, uint32_t initval) { - uint32_t a,b,c; /* internal state */ - union { const void *ptr; size_t i; } u; /* needed for Mac Powerbook G4 */ - - /* Set up the internal state */ - a = b = c = 0xdeadbeef + ((uint32_t)length) + initval; - - u.ptr = key; - if (HASH_LITTLE_ENDIAN && ((u.i & 0x3) == 0)) { - const uint32_t *k = (const uint32_t *)key; /* read 32-bit chunks */ - - /*------ all but last block: aligned reads and affect 32 bits of (a,b,c) */ - while (length > 12) - { - a += k[0]; - b += k[1]; - c += k[2]; - mix(a,b,c); - length -= 12; - k += 3; - } - - /*----------------------------- handle the last (probably partial) block */ - /* - * "k[2]&0xffffff" actually reads beyond the end of the string, but - * then masks off the part it's not allowed to read. Because the - * string is aligned, the masked-off tail is in the same word as the - * rest of the string. Every machine with memory protection I've seen - * does it on word boundaries, so is OK with this. But VALGRIND will - * still catch it and complain. The masking trick does make the hash - * noticably faster for short strings (like English words). - * AddressSanitizer is similarly picky about overrunning - * the buffer. (http://clang.llvm.org/docs/AddressSanitizer.html - */ + uint32_t a,b,c; /* internal state */ + union + { + const void *ptr; + size_t i; + } u; /* needed for Mac Powerbook G4 */ + + /* Set up the internal state */ + a = b = c = 0xdeadbeef + ((uint32_t)length) + initval; + + u.ptr = key; + if (HASH_LITTLE_ENDIAN && ((u.i & 0x3) == 0)) { + const uint32_t *k = (const uint32_t *)key; /* read 32-bit chunks */ + + /*------ all but last block: aligned reads and affect 32 bits of (a,b,c) */ + while (length > 12) + { + a += k[0]; + b += k[1]; + c += k[2]; + mix(a,b,c); + length -= 12; + k += 3; + } + + /*----------------------------- handle the last (probably partial) block */ + /* + * "k[2]&0xffffff" actually reads beyond the end of the string, but + * then masks off the part it's not allowed to read. Because the + * string is aligned, the masked-off tail is in the same word as the + * rest of the string. Every machine with memory protection I've seen + * does it on word boundaries, so is OK with this. But VALGRIND will + * still catch it and complain. The masking trick does make the hash + * noticeably faster for short strings (like English words). + * AddressSanitizer is similarly picky about overrunning + * the buffer. (https://clang.llvm.org/docs/AddressSanitizer.html) + */ #ifdef VALGRIND -# define PRECISE_MEMORY_ACCESS 1 +#define PRECISE_MEMORY_ACCESS 1 #elif defined(__SANITIZE_ADDRESS__) /* GCC's ASAN */ -# define PRECISE_MEMORY_ACCESS 1 +#define PRECISE_MEMORY_ACCESS 1 #elif defined(__has_feature) -# if __has_feature(address_sanitizer) /* Clang's ASAN */ -# define PRECISE_MEMORY_ACCESS 1 -# endif +#if __has_feature(address_sanitizer) /* Clang's ASAN */ +#define PRECISE_MEMORY_ACCESS 1 +#endif #endif #ifndef PRECISE_MEMORY_ACCESS - switch(length) - { - case 12: c+=k[2]; b+=k[1]; a+=k[0]; break; - case 11: c+=k[2]&0xffffff; b+=k[1]; a+=k[0]; break; - case 10: c+=k[2]&0xffff; b+=k[1]; a+=k[0]; break; - case 9 : c+=k[2]&0xff; b+=k[1]; a+=k[0]; break; - case 8 : b+=k[1]; a+=k[0]; break; - case 7 : b+=k[1]&0xffffff; a+=k[0]; break; - case 6 : b+=k[1]&0xffff; a+=k[0]; break; - case 5 : b+=k[1]&0xff; a+=k[0]; break; - case 4 : a+=k[0]; break; - case 3 : a+=k[0]&0xffffff; break; - case 2 : a+=k[0]&0xffff; break; - case 1 : a+=k[0]&0xff; break; - case 0 : return c; /* zero length strings require no mixing */ - } + switch(length) + { + case 12: c+=k[2]; b+=k[1]; a+=k[0]; break; + case 11: c+=k[2]&0xffffff; b+=k[1]; a+=k[0]; break; + case 10: c+=k[2]&0xffff; b+=k[1]; a+=k[0]; break; + case 9 : c+=k[2]&0xff; b+=k[1]; a+=k[0]; break; + case 8 : b+=k[1]; a+=k[0]; break; + case 7 : b+=k[1]&0xffffff; a+=k[0]; break; + case 6 : b+=k[1]&0xffff; a+=k[0]; break; + case 5 : b+=k[1]&0xff; a+=k[0]; break; + case 4 : a+=k[0]; break; + case 3 : a+=k[0]&0xffffff; break; + case 2 : a+=k[0]&0xffff; break; + case 1 : a+=k[0]&0xff; break; + case 0 : return c; /* zero length strings require no mixing */ + } #else /* make valgrind happy */ - const uint8_t *k8 = (const uint8_t *)k; - switch(length) - { - case 12: c+=k[2]; b+=k[1]; a+=k[0]; break; - case 11: c+=((uint32_t)k8[10])<<16; /* fall through */ - case 10: c+=((uint32_t)k8[9])<<8; /* fall through */ - case 9 : c+=k8[8]; /* fall through */ - case 8 : b+=k[1]; a+=k[0]; break; - case 7 : b+=((uint32_t)k8[6])<<16; /* fall through */ - case 6 : b+=((uint32_t)k8[5])<<8; /* fall through */ - case 5 : b+=k8[4]; /* fall through */ - case 4 : a+=k[0]; break; - case 3 : a+=((uint32_t)k8[2])<<16; /* fall through */ - case 2 : a+=((uint32_t)k8[1])<<8; /* fall through */ - case 1 : a+=k8[0]; break; - case 0 : return c; - } + const uint8_t *k8 = (const uint8_t *)k; + switch(length) + { + case 12: c+=k[2]; b+=k[1]; a+=k[0]; break; + case 11: c+=((uint32_t)k8[10])<<16; /* fall through */ + case 10: c+=((uint32_t)k8[9])<<8; /* fall through */ + case 9 : c+=k8[8]; /* fall through */ + case 8 : b+=k[1]; a+=k[0]; break; + case 7 : b+=((uint32_t)k8[6])<<16; /* fall through */ + case 6 : b+=((uint32_t)k8[5])<<8; /* fall through */ + case 5 : b+=k8[4]; /* fall through */ + case 4 : a+=k[0]; break; + case 3 : a+=((uint32_t)k8[2])<<16; /* fall through */ + case 2 : a+=((uint32_t)k8[1])<<8; /* fall through */ + case 1 : a+=k8[0]; break; + case 0 : return c; + } #endif /* !valgrind */ - } else if (HASH_LITTLE_ENDIAN && ((u.i & 0x1) == 0)) { - const uint16_t *k = (const uint16_t *)key; /* read 16-bit chunks */ - const uint8_t *k8; - - /*--------------- all but last block: aligned reads and different mixing */ - while (length > 12) - { - a += k[0] + (((uint32_t)k[1])<<16); - b += k[2] + (((uint32_t)k[3])<<16); - c += k[4] + (((uint32_t)k[5])<<16); - mix(a,b,c); - length -= 12; - k += 6; - } - - /*----------------------------- handle the last (probably partial) block */ - k8 = (const uint8_t *)k; - switch(length) - { - case 12: c+=k[4]+(((uint32_t)k[5])<<16); - b+=k[2]+(((uint32_t)k[3])<<16); - a+=k[0]+(((uint32_t)k[1])<<16); - break; - case 11: c+=((uint32_t)k8[10])<<16; /* fall through */ - case 10: c+=k[4]; - b+=k[2]+(((uint32_t)k[3])<<16); - a+=k[0]+(((uint32_t)k[1])<<16); - break; - case 9 : c+=k8[8]; /* fall through */ - case 8 : b+=k[2]+(((uint32_t)k[3])<<16); - a+=k[0]+(((uint32_t)k[1])<<16); - break; - case 7 : b+=((uint32_t)k8[6])<<16; /* fall through */ - case 6 : b+=k[2]; - a+=k[0]+(((uint32_t)k[1])<<16); - break; - case 5 : b+=k8[4]; /* fall through */ - case 4 : a+=k[0]+(((uint32_t)k[1])<<16); - break; - case 3 : a+=((uint32_t)k8[2])<<16; /* fall through */ - case 2 : a+=k[0]; - break; - case 1 : a+=k8[0]; - break; - case 0 : return c; /* zero length requires no mixing */ - } - - } else { /* need to read the key one byte at a time */ - const uint8_t *k = (const uint8_t *)key; - - /*--------------- all but the last block: affect some 32 bits of (a,b,c) */ - while (length > 12) - { - a += k[0]; - a += ((uint32_t)k[1])<<8; - a += ((uint32_t)k[2])<<16; - a += ((uint32_t)k[3])<<24; - b += k[4]; - b += ((uint32_t)k[5])<<8; - b += ((uint32_t)k[6])<<16; - b += ((uint32_t)k[7])<<24; - c += k[8]; - c += ((uint32_t)k[9])<<8; - c += ((uint32_t)k[10])<<16; - c += ((uint32_t)k[11])<<24; - mix(a,b,c); - length -= 12; - k += 12; - } - - /*-------------------------------- last block: affect all 32 bits of (c) */ - switch(length) /* all the case statements fall through */ - { - case 12: c+=((uint32_t)k[11])<<24; /* FALLTHRU */ - case 11: c+=((uint32_t)k[10])<<16; /* FALLTHRU */ - case 10: c+=((uint32_t)k[9])<<8; /* FALLTHRU */ - case 9 : c+=k[8]; /* FALLTHRU */ - case 8 : b+=((uint32_t)k[7])<<24; /* FALLTHRU */ - case 7 : b+=((uint32_t)k[6])<<16; /* FALLTHRU */ - case 6 : b+=((uint32_t)k[5])<<8; /* FALLTHRU */ - case 5 : b+=k[4]; /* FALLTHRU */ - case 4 : a+=((uint32_t)k[3])<<24; /* FALLTHRU */ - case 3 : a+=((uint32_t)k[2])<<16; /* FALLTHRU */ - case 2 : a+=((uint32_t)k[1])<<8; /* FALLTHRU */ - case 1 : a+=k[0]; - break; - case 0 : return c; - } - } + } + else if (HASH_LITTLE_ENDIAN && ((u.i & 0x1) == 0)) + { + const uint16_t *k = (const uint16_t *)key; /* read 16-bit chunks */ + const uint8_t *k8; + + /*--------------- all but last block: aligned reads and different mixing */ + while (length > 12) + { + a += k[0] + (((uint32_t)k[1])<<16); + b += k[2] + (((uint32_t)k[3])<<16); + c += k[4] + (((uint32_t)k[5])<<16); + mix(a,b,c); + length -= 12; + k += 6; + } - final(a,b,c); - return c; + /*----------------------------- handle the last (probably partial) block */ + k8 = (const uint8_t *)k; + switch(length) + { + case 12: c+=k[4]+(((uint32_t)k[5])<<16); + b+=k[2]+(((uint32_t)k[3])<<16); + a+=k[0]+(((uint32_t)k[1])<<16); + break; + case 11: c+=((uint32_t)k8[10])<<16; /* fall through */ + case 10: c+=k[4]; + b+=k[2]+(((uint32_t)k[3])<<16); + a+=k[0]+(((uint32_t)k[1])<<16); + break; + case 9 : c+=k8[8]; /* fall through */ + case 8 : b+=k[2]+(((uint32_t)k[3])<<16); + a+=k[0]+(((uint32_t)k[1])<<16); + break; + case 7 : b+=((uint32_t)k8[6])<<16; /* fall through */ + case 6 : b+=k[2]; + a+=k[0]+(((uint32_t)k[1])<<16); + break; + case 5 : b+=k8[4]; /* fall through */ + case 4 : a+=k[0]+(((uint32_t)k[1])<<16); + break; + case 3 : a+=((uint32_t)k8[2])<<16; /* fall through */ + case 2 : a+=k[0]; + break; + case 1 : a+=k8[0]; + break; + case 0 : return c; /* zero length requires no mixing */ + } + + } + else + { + /* need to read the key one byte at a time */ + const uint8_t *k = (const uint8_t *)key; + + /*--------------- all but the last block: affect some 32 bits of (a,b,c) */ + while (length > 12) + { + a += k[0]; + a += ((uint32_t)k[1])<<8; + a += ((uint32_t)k[2])<<16; + a += ((uint32_t)k[3])<<24; + b += k[4]; + b += ((uint32_t)k[5])<<8; + b += ((uint32_t)k[6])<<16; + b += ((uint32_t)k[7])<<24; + c += k[8]; + c += ((uint32_t)k[9])<<8; + c += ((uint32_t)k[10])<<16; + c += ((uint32_t)k[11])<<24; + mix(a,b,c); + length -= 12; + k += 12; + } + + /*-------------------------------- last block: affect all 32 bits of (c) */ + switch(length) /* all the case statements fall through */ + { + case 12: c+=((uint32_t)k[11])<<24; /* FALLTHRU */ + case 11: c+=((uint32_t)k[10])<<16; /* FALLTHRU */ + case 10: c+=((uint32_t)k[9])<<8; /* FALLTHRU */ + case 9 : c+=k[8]; /* FALLTHRU */ + case 8 : b+=((uint32_t)k[7])<<24; /* FALLTHRU */ + case 7 : b+=((uint32_t)k[6])<<16; /* FALLTHRU */ + case 6 : b+=((uint32_t)k[5])<<8; /* FALLTHRU */ + case 5 : b+=k[4]; /* FALLTHRU */ + case 4 : a+=((uint32_t)k[3])<<24; /* FALLTHRU */ + case 3 : a+=((uint32_t)k[2])<<16; /* FALLTHRU */ + case 2 : a+=((uint32_t)k[1])<<8; /* FALLTHRU */ + case 1 : a+=k[0]; + break; + case 0 : return c; + } + } + + final(a,b,c); + return c; } +/* clang-format on */ -/* a simple hash function similiar to what perl does for strings. - * for good results, the string should not be excessivly large. +/* a simple hash function similar to what perl does for strings. + * for good results, the string should not be excessively large. */ -static unsigned long lh_perllike_str_hash(const void *k) +static unsigned long lh_perllike_str_hash(const void *k) { - const char *rkey = (const char *)k; - unsigned hashval = 1; + const char *rkey = (const char *)k; + unsigned hashval = 1; - while (*rkey) - hashval = hashval * 33 + *rkey++; + while (*rkey) + hashval = hashval * 33 + *rkey++; - return hashval; + return hashval; } static unsigned long lh_char_hash(const void *k) @@ -459,10 +476,11 @@ static unsigned long lh_char_hash(const void *k) #endif static volatile RANDOM_SEED_TYPE random_seed = -1; - if (random_seed == -1) { + if (random_seed == -1) + { RANDOM_SEED_TYPE seed; - /* we can't use -1 as it is the unitialized sentinel */ - while ((seed = json_c_get_random_seed()) == -1); + /* we can't use -1 as it is the uninitialized sentinel */ + while ((seed = doca_third_party_json_c_get_random_seed()) == -1) {} #if SIZEOF_INT == 8 && defined __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 #define USE_SYNC_COMPARE_AND_SWAP 1 #endif @@ -477,34 +495,34 @@ static unsigned long lh_char_hash(const void *k) #elif defined _MSC_VER || defined __MINGW32__ InterlockedCompareExchange(&random_seed, seed, -1); #else -//#warning "racy random seed initializtion if used by multiple threads" + //#warning "racy random seed initialization if used by multiple threads" random_seed = seed; /* potentially racy */ #endif } - return hashlittle((const char*)k, strlen((const char*)k), random_seed); + return hashlittle((const char *)k, strlen((const char *)k), (uint32_t)random_seed); } -int lh_char_equal(const void *k1, const void *k2) +int doca_third_party_lh_char_equal(const void *k1, const void *k2) { - return (strcmp((const char*)k1, (const char*)k2) == 0); + return (strcmp((const char *)k1, (const char *)k2) == 0); } -struct lh_table* lh_table_new(int size, - lh_entry_free_fn *free_fn, - lh_hash_fn *hash_fn, - lh_equal_fn *equal_fn) +struct lh_table *doca_third_party_lh_table_new(int size, lh_entry_free_fn *free_fn, lh_hash_fn *hash_fn, + lh_equal_fn *equal_fn) { int i; struct lh_table *t; - t = (struct lh_table*)calloc(1, sizeof(struct lh_table)); + /* Allocate space for elements to avoid divisions by zero. */ + assert(size > 0); + t = (struct lh_table *)calloc(1, sizeof(struct lh_table)); if (!t) return NULL; t->count = 0; t->size = size; - t->table = (struct lh_entry*)calloc(size, sizeof(struct lh_entry)); + t->table = (struct lh_entry *)calloc(size, sizeof(struct lh_entry)); if (!t->table) { free(t); @@ -513,28 +531,27 @@ struct lh_table* lh_table_new(int size, t->free_fn = free_fn; t->hash_fn = hash_fn; t->equal_fn = equal_fn; - for(i = 0; i < size; i++) t->table[i].k = LH_EMPTY; + for (i = 0; i < size; i++) + t->table[i].k = LH_EMPTY; return t; } -struct lh_table* lh_kchar_table_new(int size, - lh_entry_free_fn *free_fn) +struct lh_table *doca_third_party_lh_kchar_table_new(int size, lh_entry_free_fn *free_fn) { - return lh_table_new(size, free_fn, char_hash_fn, lh_char_equal); + return doca_third_party_lh_table_new(size, free_fn, char_hash_fn, doca_third_party_lh_char_equal); } -struct lh_table* lh_kptr_table_new(int size, - lh_entry_free_fn *free_fn) +struct lh_table *doca_third_party_lh_kptr_table_new(int size, lh_entry_free_fn *free_fn) { - return lh_table_new(size, free_fn, lh_ptr_hash, lh_ptr_equal); + return doca_third_party_lh_table_new(size, free_fn, lh_ptr_hash, doca_third_party_lh_ptr_equal); } -int lh_table_resize(struct lh_table *t, int new_size) +int doca_third_party_lh_table_resize(struct lh_table *t, int new_size) { struct lh_table *new_t; struct lh_entry *ent; - new_t = lh_table_new(new_size, NULL, t->hash_fn, t->equal_fn); + new_t = doca_third_party_lh_table_new(new_size, NULL, t->hash_fn, t->equal_fn); if (new_t == NULL) return -1; @@ -543,10 +560,10 @@ int lh_table_resize(struct lh_table *t, int new_size) unsigned long h = lh_get_hash(new_t, ent->k); unsigned int opts = 0; if (ent->k_is_constant) - opts = JSON_C_OBJECT_KEY_IS_CONSTANT; - if (lh_table_insert_w_hash(new_t, ent->k, ent->v, h, opts) != 0) + opts = JSON_C_OBJECT_ADD_CONSTANT_KEY; + if (doca_third_party_lh_table_insert_w_hash(new_t, ent->k, ent->v, h, opts) != 0) { - lh_table_free(new_t); + doca_third_party_lh_table_free(new_t); return -1; } } @@ -560,42 +577,53 @@ int lh_table_resize(struct lh_table *t, int new_size) return 0; } -void lh_table_free(struct lh_table *t) +void doca_third_party_lh_table_free(struct lh_table *t) { struct lh_entry *c; - if(t->free_fn) { - for(c = t->head; c != NULL; c = c->next) + if (t->free_fn) + { + for (c = t->head; c != NULL; c = c->next) t->free_fn(c); } free(t->table); free(t); } - -int lh_table_insert_w_hash(struct lh_table *t, const void *k, const void *v, const unsigned long h, const unsigned opts) +int doca_third_party_lh_table_insert_w_hash(struct lh_table *t, const void *k, const void *v, const unsigned long h, + const unsigned opts) { unsigned long n; if (t->count >= t->size * LH_LOAD_FACTOR) - if (lh_table_resize(t, t->size * 2) != 0) + { + /* Avoid signed integer overflow with large tables. */ + int new_size = (t->size > INT_MAX / 2) ? INT_MAX : (t->size * 2); + if (t->size == INT_MAX || doca_third_party_lh_table_resize(t, new_size) != 0) return -1; + } n = h % t->size; - while( 1 ) { - if(t->table[n].k == LH_EMPTY || t->table[n].k == LH_FREED) break; - if ((int)++n == t->size) n = 0; + while (1) + { + if (t->table[n].k == LH_EMPTY || t->table[n].k == LH_FREED) + break; + if ((int)++n == t->size) + n = 0; } t->table[n].k = k; - t->table[n].k_is_constant = (opts & JSON_C_OBJECT_KEY_IS_CONSTANT); + t->table[n].k_is_constant = (opts & JSON_C_OBJECT_ADD_CONSTANT_KEY); t->table[n].v = v; t->count++; - if(t->head == NULL) { + if (t->head == NULL) + { t->head = t->tail = &t->table[n]; t->table[n].next = t->table[n].prev = NULL; - } else { + } + else + { t->tail->next = &t->table[n]; t->table[n].prev = t->tail; t->table[n].next = NULL; @@ -604,71 +632,83 @@ int lh_table_insert_w_hash(struct lh_table *t, const void *k, const void *v, con return 0; } -int lh_table_insert(struct lh_table *t, const void *k, const void *v) +int doca_third_party_lh_table_insert(struct lh_table *t, const void *k, const void *v) { - return lh_table_insert_w_hash(t, k, v, lh_get_hash(t, k), 0); + return doca_third_party_lh_table_insert_w_hash(t, k, v, lh_get_hash(t, k), 0); } - -struct lh_entry* lh_table_lookup_entry_w_hash(struct lh_table *t, const void *k, const unsigned long h) +struct lh_entry *doca_third_party_lh_table_lookup_entry_w_hash(struct lh_table *t, const void *k, + const unsigned long h) { unsigned long n = h % t->size; int count = 0; - while( count < t->size ) { - if(t->table[n].k == LH_EMPTY) return NULL; - if(t->table[n].k != LH_FREED && - t->equal_fn(t->table[n].k, k)) return &t->table[n]; - if ((int)++n == t->size) n = 0; + while (count < t->size) + { + if (t->table[n].k == LH_EMPTY) + return NULL; + if (t->table[n].k != LH_FREED && t->equal_fn(t->table[n].k, k)) + return &t->table[n]; + if ((int)++n == t->size) + n = 0; count++; } return NULL; } -struct lh_entry* lh_table_lookup_entry(struct lh_table *t, const void *k) -{ - return lh_table_lookup_entry_w_hash(t, k, lh_get_hash(t, k)); -} - -const void* lh_table_lookup(struct lh_table *t, const void *k) +struct lh_entry *doca_third_party_lh_table_lookup_entry(struct lh_table *t, const void *k) { - void *result; - lh_table_lookup_ex(t, k, &result); - return result; + return doca_third_party_lh_table_lookup_entry_w_hash(t, k, lh_get_hash(t, k)); } -json_bool lh_table_lookup_ex(struct lh_table* t, const void* k, void **v) +json_bool doca_third_party_lh_table_lookup_ex(struct lh_table *t, const void *k, void **v) { - struct lh_entry *e = lh_table_lookup_entry(t, k); - if (e != NULL) { - if (v != NULL) *v = lh_entry_v(e); - return TRUE; /* key found */ + struct lh_entry *e = doca_third_party_lh_table_lookup_entry(t, k); + if (e != NULL) + { + if (v != NULL) + *v = lh_entry_v(e); + return 1; /* key found */ } - if (v != NULL) *v = NULL; - return FALSE; /* key not found */ + if (v != NULL) + *v = NULL; + return 0; /* key not found */ } -int lh_table_delete_entry(struct lh_table *t, struct lh_entry *e) +int doca_third_party_lh_table_delete_entry(struct lh_table *t, struct lh_entry *e) { - ptrdiff_t n = (ptrdiff_t)(e - t->table); /* CAW: fixed to be 64bit nice, still need the crazy negative case... */ + /* CAW: fixed to be 64bit nice, still need the crazy negative case... */ + ptrdiff_t n = (ptrdiff_t)(e - t->table); /* CAW: this is bad, really bad, maybe stack goes other direction on this machine... */ - if(n < 0) { return -2; } + if (n < 0) + { + return -2; + } - if(t->table[n].k == LH_EMPTY || t->table[n].k == LH_FREED) return -1; + if (t->table[n].k == LH_EMPTY || t->table[n].k == LH_FREED) + return -1; t->count--; - if(t->free_fn) t->free_fn(e); + if (t->free_fn) + t->free_fn(e); t->table[n].v = NULL; t->table[n].k = LH_FREED; - if(t->tail == &t->table[n] && t->head == &t->table[n]) { + if (t->tail == &t->table[n] && t->head == &t->table[n]) + { t->head = t->tail = NULL; - } else if (t->head == &t->table[n]) { + } + else if (t->head == &t->table[n]) + { t->head->next->prev = NULL; t->head = t->head->next; - } else if (t->tail == &t->table[n]) { + } + else if (t->tail == &t->table[n]) + { t->tail->prev->next = NULL; t->tail = t->tail->prev; - } else { + } + else + { t->table[n].prev->next = t->table[n].next; t->table[n].next->prev = t->table[n].prev; } @@ -676,15 +716,15 @@ int lh_table_delete_entry(struct lh_table *t, struct lh_entry *e) return 0; } - -int lh_table_delete(struct lh_table *t, const void *k) +int doca_third_party_lh_table_delete(struct lh_table *t, const void *k) { - struct lh_entry *e = lh_table_lookup_entry(t, k); - if(!e) return -1; - return lh_table_delete_entry(t, e); + struct lh_entry *e = doca_third_party_lh_table_lookup_entry(t, k); + if (!e) + return -1; + return doca_third_party_lh_table_delete_entry(t, e); } -int lh_table_length(struct lh_table *t) +int doca_third_party_lh_table_length(struct lh_table *t) { return t->count; } diff --git a/third_party/json-c/linkhash.h b/third_party/json-c/linkhash.h index 9c2f5c1b2..2635181e7 100644 --- a/third_party/json-c/linkhash.h +++ b/third_party/json-c/linkhash.h @@ -1,4 +1,6 @@ /* + * Original work: + * * $Id: linkhash.h,v 1.6 2006/01/30 23:07:57 mclark Exp $ * * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd. @@ -8,6 +10,18 @@ * This library is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See COPYING for details. * + * Modified Work: + * + * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. + * + * This software product is a proprietary product of NVIDIA CORPORATION & + * AFFILIATES (the "Company") and all right, title, and interest in and to the + * software product, including all associated intellectual property rights, are + * and shall remain exclusively with the Company. + * + * This software product is governed by the End User License Agreement + * provided with the software product. + * */ /** @@ -16,8 +30,8 @@ * this is exposed by the json_object_get_object() function and within the * json_object_iter type, it is not recommended for direct use. */ -#ifndef _linkhash_h_ -#define _linkhash_h_ +#ifndef _json_c_linkhash_h_ +#define _json_c_linkhash_h_ #include "json_object.h" @@ -40,12 +54,12 @@ extern "C" { /** * sentinel pointer value for empty slots */ -#define LH_EMPTY (void*)-1 +#define LH_EMPTY (void *)-1 /** * sentinel pointer value for freed slots */ -#define LH_FREED (void*)-2 +#define LH_FREED (void *)-2 /** * default string hash function @@ -62,91 +76,110 @@ extern "C" { * Must be one of the JSON_C_STR_HASH_* values. * @returns 0 - ok, -1 if parameter was invalid */ -int json_global_set_string_hash(const int h); +int doca_third_party_json_global_set_string_hash(const int h); struct lh_entry; /** * callback function prototypes */ -typedef void (lh_entry_free_fn) (struct lh_entry *e); +typedef void(lh_entry_free_fn)(struct lh_entry *e); /** * callback function prototypes */ -typedef unsigned long (lh_hash_fn) (const void *k); +typedef unsigned long(lh_hash_fn)(const void *k); /** * callback function prototypes */ -typedef int (lh_equal_fn) (const void *k1, const void *k2); +typedef int(lh_equal_fn)(const void *k1, const void *k2); /** - * An entry in the hash table + * An entry in the hash table. Outside of linkhash.c, treat this as opaque. */ -struct lh_entry { +struct lh_entry +{ /** - * The key. Use lh_entry_k() instead of accessing this directly. + * The key. + * @deprecated Use lh_entry_k() instead of accessing this directly. */ const void *k; /** * A flag for users of linkhash to know whether or not they * need to free k. + * @deprecated use lh_entry_k_is_constant() instead. */ int k_is_constant; /** - * The value. Use lh_entry_v() instead of accessing this directly. + * The value. + * @deprecated Use lh_entry_v() instead of accessing this directly. */ const void *v; /** - * The next entry + * The next entry. + * @deprecated Use lh_entry_next() instead of accessing this directly. */ struct lh_entry *next; /** * The previous entry. + * @deprecated Use lh_entry_prev() instead of accessing this directly. */ struct lh_entry *prev; }; - /** - * The hash table structure. + * The hash table structure. Outside of linkhash.c, treat this as opaque. */ -struct lh_table { +struct lh_table +{ /** * Size of our hash. + * @deprecated do not use outside of linkhash.c */ int size; /** * Numbers of entries. + * @deprecated Use lh_table_length() instead. */ int count; /** * The first entry. + * @deprecated Use lh_table_head() instead. */ struct lh_entry *head; /** * The last entry. + * @deprecated Do not use, may be removed in a future release. */ struct lh_entry *tail; + /** + * Internal storage of the actual table of entries. + * @deprecated do not use outside of linkhash.c + */ struct lh_entry *table; /** - * A pointer onto the function responsible for freeing an entry. + * A pointer to the function responsible for freeing an entry. + * @deprecated do not use outside of linkhash.c */ lh_entry_free_fn *free_fn; + /** + * @deprecated do not use outside of linkhash.c + */ lh_hash_fn *hash_fn; + /** + * @deprecated do not use outside of linkhash.c + */ lh_equal_fn *equal_fn; }; typedef struct lh_table lh_table; - /** * Convenience list iterator. */ -#define lh_foreach(table, entry) \ -for(entry = table->head; entry; entry = entry->next) +#define lh_foreach(table, entry) for (entry = doca_third_party_lh_table_head(table); entry; entry = doca_third_party_lh_entry_next(entry)) /** * lh_foreach_safe allows calling of deletion routine while iterating. @@ -156,9 +189,7 @@ for(entry = table->head; entry; entry = entry->next) * @param tmp a struct lh_entry * variable to hold a temporary pointer to the next element */ #define lh_foreach_safe(table, entry, tmp) \ -for(entry = table->head; entry && ((tmp = entry->next) || 1); entry = tmp) - - + for (entry = doca_third_party_lh_table_head(table); entry && ((tmp = doca_third_party_lh_entry_next(entry)) || 1); entry = tmp) /** * Create a new linkhash table. @@ -178,10 +209,8 @@ for(entry = table->head; entry && ((tmp = entry->next) || 1); entry = tmp) * @return On success, a pointer to the new linkhash table is returned. * On error, a null pointer is returned. */ -extern struct lh_table* lh_table_new(int size, - lh_entry_free_fn *free_fn, - lh_hash_fn *hash_fn, - lh_equal_fn *equal_fn); +extern struct lh_table *doca_third_party_lh_table_new(int size, lh_entry_free_fn *free_fn, lh_hash_fn *hash_fn, + lh_equal_fn *equal_fn); /** * Convenience function to create a new linkhash table with char keys. @@ -191,9 +220,7 @@ extern struct lh_table* lh_table_new(int size, * @return On success, a pointer to the new linkhash table is returned. * On error, a null pointer is returned. */ -extern struct lh_table* lh_kchar_table_new(int size, - lh_entry_free_fn *free_fn); - +extern struct lh_table *doca_third_party_lh_kchar_table_new(int size, lh_entry_free_fn *free_fn); /** * Convenience function to create a new linkhash table with ptr keys. @@ -203,9 +230,7 @@ extern struct lh_table* lh_kchar_table_new(int size, * @return On success, a pointer to the new linkhash table is returned. * On error, a null pointer is returned. */ -extern struct lh_table* lh_kptr_table_new(int size, - lh_entry_free_fn *free_fn); - +extern struct lh_table *doca_third_party_lh_kptr_table_new(int size, lh_entry_free_fn *free_fn); /** * Free a linkhash table. @@ -215,8 +240,7 @@ extern struct lh_table* lh_kptr_table_new(int size, * * @param t table to free. */ -extern void lh_table_free(struct lh_table *t); - +extern void doca_third_party_lh_table_free(struct lh_table *t); /** * Insert a record into the table. @@ -228,8 +252,7 @@ extern void lh_table_free(struct lh_table *t); * @return On success, 0 is returned. * On error, a negative value is returned. */ -extern int lh_table_insert(struct lh_table *t, const void *k, const void *v); - +extern int doca_third_party_lh_table_insert(struct lh_table *t, const void *k, const void *v); /** * Insert a record into the table using a precalculated key hash. @@ -242,11 +265,11 @@ extern int lh_table_insert(struct lh_table *t, const void *k, const void *v); * @param k a pointer to the key to insert. * @param v a pointer to the value to insert. * @param h hash value of the key to insert - * @param opts if set to JSON_C_OBJECT_KEY_IS_CONSTANT, sets lh_entry.k_is_constant + * @param opts if set to JSON_C_OBJECT_ADD_CONSTANT_KEY, sets lh_entry.k_is_constant * so t's free function knows to avoid freeing the key. */ -extern int lh_table_insert_w_hash(struct lh_table *t, const void *k, const void *v, const unsigned long h, const unsigned opts); - +extern int doca_third_party_lh_table_insert_w_hash(struct lh_table *t, const void *k, const void *v, + const unsigned long h, const unsigned opts); /** * Lookup a record in the table. @@ -255,7 +278,7 @@ extern int lh_table_insert_w_hash(struct lh_table *t, const void *k, const void * @param k a pointer to the key to lookup * @return a pointer to the record structure of the value or NULL if it does not exist. */ -extern struct lh_entry* lh_table_lookup_entry(struct lh_table *t, const void *k); +extern struct lh_entry *doca_third_party_lh_table_lookup_entry(struct lh_table *t, const void *k); /** * Lookup a record in the table using a precalculated key hash. @@ -269,17 +292,8 @@ extern struct lh_entry* lh_table_lookup_entry(struct lh_table *t, const void *k) * @param h hash value of the key to lookup * @return a pointer to the record structure of the value or NULL if it does not exist. */ -extern struct lh_entry* lh_table_lookup_entry_w_hash(struct lh_table *t, const void *k, const unsigned long h); - -/** - * Lookup a record into the table. - * - * @param t the table to lookup - * @param k a pointer to the key to lookup - * @return a pointer to the found value or NULL if it does not exist. - * @deprecated Use lh_table_lookup_ex() instead. - */ -THIS_FUNCTION_IS_DEPRECATED(extern const void* lh_table_lookup(struct lh_table *t, const void *k)); +extern struct lh_entry *doca_third_party_lh_table_lookup_entry_w_hash(struct lh_table *t, const void *k, + const unsigned long h); /** * Lookup a record in the table. @@ -289,7 +303,7 @@ THIS_FUNCTION_IS_DEPRECATED(extern const void* lh_table_lookup(struct lh_table * * @param v a pointer to a where to store the found value (set to NULL if it doesn't exist). * @return whether or not the key was found */ -extern json_bool lh_table_lookup_ex(struct lh_table *t, const void *k, void **v); +extern json_bool doca_third_party_lh_table_lookup_ex(struct lh_table *t, const void *k, void **v); /** * Delete a record from the table. @@ -301,8 +315,7 @@ extern json_bool lh_table_lookup_ex(struct lh_table *t, const void *k, void **v) * @return 0 if the item was deleted. * @return -1 if it was not found. */ -extern int lh_table_delete_entry(struct lh_table *t, struct lh_entry *e); - +extern int doca_third_party_lh_table_delete_entry(struct lh_table *t, struct lh_entry *e); /** * Delete a record from the table. @@ -314,24 +327,12 @@ extern int lh_table_delete_entry(struct lh_table *t, struct lh_entry *e); * @return 0 if the item was deleted. * @return -1 if it was not found. */ -extern int lh_table_delete(struct lh_table *t, const void *k); - -extern int lh_table_length(struct lh_table *t); +extern int doca_third_party_lh_table_delete(struct lh_table *t, const void *k); /** - * Prints a message to stdout, - * then exits the program with an exit code of 1. - * - * @param msg Message format string, like for printf. - * @param ... Format args. - * - * @deprecated Since it is not a good idea to exit the entire program - * because of an internal library failure, json-c will no longer - * use this function internally. - * However, because its interface is public, it will remain part of - * the API on the off chance of legacy software using it externally. + * Return the number of entries in the table. */ -THIS_FUNCTION_IS_DEPRECATED(void lh_abort(const char *msg, ...)); +extern int doca_third_party_lh_table_length(struct lh_table *t); /** * Resizes the specified table. @@ -342,23 +343,31 @@ THIS_FUNCTION_IS_DEPRECATED(void lh_abort(const char *msg, ...)); * @return On success, 0 is returned. * On error, a negative value is returned. */ -int lh_table_resize(struct lh_table *t, int new_size); - +int doca_third_party_lh_table_resize(struct lh_table *t, int new_size); /** * @deprecated Don't use this outside of linkhash.h: */ -#if !defined(_MSC_VER) || (_MSC_VER > 1800) +#if (defined(AIX_CC) || (defined(_MSC_VER) && (_MSC_VER <= 1800)) ) /* VS2010 can't handle inline funcs, so skip it there */ -#define _LH_INLINE inline -#else #define _LH_INLINE +#else +#define _LH_INLINE inline #endif +/** + * Return the first entry in the lh_table. + * @see lh_entry_next() + */ +static _LH_INLINE struct lh_entry *lh_table_head(const lh_table *t) +{ + return t->head; +} + /** * Calculate the hash of a key for a given table. * - * This is an exension to support functions that need to calculate + * This is an extension to support functions that need to calculate * the hash several times and allows them to do it just once and then pass * in the hash to all utility functions. Depending on use case, this can be a * considerable performance improvement. @@ -371,7 +380,6 @@ static _LH_INLINE unsigned long lh_get_hash(const struct lh_table *t, const void return t->hash_fn(k); } -#undef _LH_INLINE /** * @deprecated Don't use this outside of linkhash.h: @@ -387,9 +395,22 @@ static _LH_INLINE unsigned long lh_get_hash(const struct lh_table *t, const void * * lh_entry.k is const to indicate and help ensure that linkhash itself doesn't modify * it, but callers are allowed to do what they want with it. - * See also lh_entry.k_is_constant + * @see lh_entry_k_is_constant() */ -#define lh_entry_k(entry) _LH_UNCONST((entry)->k) +static _LH_INLINE void *lh_entry_k(const struct lh_entry *e) +{ + return _LH_UNCONST(e->k); +} + +/** + * Returns 1 if the key for the given entry is constant, and thus + * does not need to be freed when the lh_entry is freed. + * @see lh_table_insert_w_hash() + */ +static _LH_INLINE int lh_entry_k_is_constant(const struct lh_entry *e) +{ + return e->k_is_constant; +} /** * Return a non-const version of lh_entry.v. @@ -397,7 +418,41 @@ static _LH_INLINE unsigned long lh_get_hash(const struct lh_table *t, const void * v is const to indicate and help ensure that linkhash itself doesn't modify * it, but callers are allowed to do what they want with it. */ -#define lh_entry_v(entry) _LH_UNCONST((entry)->v) +static _LH_INLINE void *lh_entry_v(const struct lh_entry *e) +{ + return _LH_UNCONST(e->v); +} + +/** + * Change the value for an entry. The caller is responsible for freeing + * the previous value. + */ +static _LH_INLINE void lh_entry_set_val(struct lh_entry *e, void *newval) +{ + e->v = newval; +} + +/** + * Return the next element, or NULL if there is no next element. + * @see lh_table_head() + * @see lh_entry_prev() + */ +static _LH_INLINE struct lh_entry *lh_entry_next(const struct lh_entry *e) +{ + return e->next; +} + +/** + * Return the previous element, or NULL if there is no previous element. + * @see lh_table_head() + * @see lh_entry_next() + */ +static _LH_INLINE struct lh_entry *lh_entry_prev(const struct lh_entry *e) +{ + return e->prev; +} + +#undef _LH_INLINE #ifdef __cplusplus } diff --git a/third_party/json-c/ltmain.sh b/third_party/json-c/ltmain.sh new file mode 100755 index 000000000..540a92ab5 --- /dev/null +++ b/third_party/json-c/ltmain.sh @@ -0,0 +1,11251 @@ +#! /bin/sh +## DO NOT EDIT - This file generated from ./build-aux/ltmain.in +## by inline-source v2014-01-03.01 + +# libtool (GNU libtool) 2.4.6 +# Provide generalized library-building support services. +# Written by Gordon Matzigkeit , 1996 + +# Copyright (C) 1996-2015 Free Software Foundation, Inc. +# This is free software; see the source for copying conditions. There is NO +# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +# GNU Libtool is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# As a special exception to the GNU General Public License, +# if you distribute this file as part of a program or library that +# is built using GNU Libtool, you may include this file under the +# same distribution terms that you use for the rest of that program. +# +# GNU Libtool is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + + +PROGRAM=libtool +PACKAGE=libtool +VERSION="2.4.6 Debian-2.4.6-15build2" +package_revision=2.4.6 + + +## ------ ## +## Usage. ## +## ------ ## + +# Run './libtool --help' for help with using this script from the +# command line. + + +## ------------------------------- ## +## User overridable command paths. ## +## ------------------------------- ## + +# After configure completes, it has a better idea of some of the +# shell tools we need than the defaults used by the functions shared +# with bootstrap, so set those here where they can still be over- +# ridden by the user, but otherwise take precedence. + +: ${AUTOCONF="autoconf"} +: ${AUTOMAKE="automake"} + + +## -------------------------- ## +## Source external libraries. ## +## -------------------------- ## + +# Much of our low-level functionality needs to be sourced from external +# libraries, which are installed to $pkgauxdir. + +# Set a version string for this script. +scriptversion=2015-01-20.17; # UTC + +# General shell script boiler plate, and helper functions. +# Written by Gary V. Vaughan, 2004 + +# Copyright (C) 2004-2015 Free Software Foundation, Inc. +# This is free software; see the source for copying conditions. There is NO +# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. + +# As a special exception to the GNU General Public License, if you distribute +# this file as part of a program or library that is built using GNU Libtool, +# you may include this file under the same distribution terms that you use +# for the rest of that program. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNES FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Please report bugs or propose patches to gary@gnu.org. + + +## ------ ## +## Usage. ## +## ------ ## + +# Evaluate this file near the top of your script to gain access to +# the functions and variables defined here: +# +# . `echo "$0" | ${SED-sed} 's|[^/]*$||'`/build-aux/funclib.sh +# +# If you need to override any of the default environment variable +# settings, do that before evaluating this file. + + +## -------------------- ## +## Shell normalisation. ## +## -------------------- ## + +# Some shells need a little help to be as Bourne compatible as possible. +# Before doing anything else, make sure all that help has been provided! + +DUALCASE=1; export DUALCASE # for MKS sh +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then : + emulate sh + NULLCMD=: + # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +else + case `(set -o) 2>/dev/null` in *posix*) set -o posix ;; esac +fi + +# NLS nuisances: We save the old values in case they are required later. +_G_user_locale= +_G_safe_locale= +for _G_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES +do + eval "if test set = \"\${$_G_var+set}\"; then + save_$_G_var=\$$_G_var + $_G_var=C + export $_G_var + _G_user_locale=\"$_G_var=\\\$save_\$_G_var; \$_G_user_locale\" + _G_safe_locale=\"$_G_var=C; \$_G_safe_locale\" + fi" +done + +# CDPATH. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + +# Make sure IFS has a sensible default +sp=' ' +nl=' +' +IFS="$sp $nl" + +# There are apparently some retarded systems that use ';' as a PATH separator! +if test "${PATH_SEPARATOR+set}" != set; then + PATH_SEPARATOR=: + (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && { + (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 || + PATH_SEPARATOR=';' + } +fi + + + +## ------------------------- ## +## Locate command utilities. ## +## ------------------------- ## + + +# func_executable_p FILE +# ---------------------- +# Check that FILE is an executable regular file. +func_executable_p () +{ + test -f "$1" && test -x "$1" +} + + +# func_path_progs PROGS_LIST CHECK_FUNC [PATH] +# -------------------------------------------- +# Search for either a program that responds to --version with output +# containing "GNU", or else returned by CHECK_FUNC otherwise, by +# trying all the directories in PATH with each of the elements of +# PROGS_LIST. +# +# CHECK_FUNC should accept the path to a candidate program, and +# set $func_check_prog_result if it truncates its output less than +# $_G_path_prog_max characters. +func_path_progs () +{ + _G_progs_list=$1 + _G_check_func=$2 + _G_PATH=${3-"$PATH"} + + _G_path_prog_max=0 + _G_path_prog_found=false + _G_save_IFS=$IFS; IFS=${PATH_SEPARATOR-:} + for _G_dir in $_G_PATH; do + IFS=$_G_save_IFS + test -z "$_G_dir" && _G_dir=. + for _G_prog_name in $_G_progs_list; do + for _exeext in '' .EXE; do + _G_path_prog=$_G_dir/$_G_prog_name$_exeext + func_executable_p "$_G_path_prog" || continue + case `"$_G_path_prog" --version 2>&1` in + *GNU*) func_path_progs_result=$_G_path_prog _G_path_prog_found=: ;; + *) $_G_check_func $_G_path_prog + func_path_progs_result=$func_check_prog_result + ;; + esac + $_G_path_prog_found && break 3 + done + done + done + IFS=$_G_save_IFS + test -z "$func_path_progs_result" && { + echo "no acceptable sed could be found in \$PATH" >&2 + exit 1 + } +} + + +# We want to be able to use the functions in this file before configure +# has figured out where the best binaries are kept, which means we have +# to search for them ourselves - except when the results are already set +# where we skip the searches. + +# Unless the user overrides by setting SED, search the path for either GNU +# sed, or the sed that truncates its output the least. +test -z "$SED" && { + _G_sed_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/ + for _G_i in 1 2 3 4 5 6 7; do + _G_sed_script=$_G_sed_script$nl$_G_sed_script + done + echo "$_G_sed_script" 2>/dev/null | sed 99q >conftest.sed + _G_sed_script= + + func_check_prog_sed () + { + _G_path_prog=$1 + + _G_count=0 + printf 0123456789 >conftest.in + while : + do + cat conftest.in conftest.in >conftest.tmp + mv conftest.tmp conftest.in + cp conftest.in conftest.nl + echo '' >> conftest.nl + "$_G_path_prog" -f conftest.sed conftest.out 2>/dev/null || break + diff conftest.out conftest.nl >/dev/null 2>&1 || break + _G_count=`expr $_G_count + 1` + if test "$_G_count" -gt "$_G_path_prog_max"; then + # Best one so far, save it but keep looking for a better one + func_check_prog_result=$_G_path_prog + _G_path_prog_max=$_G_count + fi + # 10*(2^10) chars as input seems more than enough + test 10 -lt "$_G_count" && break + done + rm -f conftest.in conftest.tmp conftest.nl conftest.out + } + + func_path_progs "sed gsed" func_check_prog_sed $PATH:/usr/xpg4/bin + rm -f conftest.sed + SED=$func_path_progs_result +} + + +# Unless the user overrides by setting GREP, search the path for either GNU +# grep, or the grep that truncates its output the least. +test -z "$GREP" && { + func_check_prog_grep () + { + _G_path_prog=$1 + + _G_count=0 + _G_path_prog_max=0 + printf 0123456789 >conftest.in + while : + do + cat conftest.in conftest.in >conftest.tmp + mv conftest.tmp conftest.in + cp conftest.in conftest.nl + echo 'GREP' >> conftest.nl + "$_G_path_prog" -e 'GREP$' -e '-(cannot match)-' conftest.out 2>/dev/null || break + diff conftest.out conftest.nl >/dev/null 2>&1 || break + _G_count=`expr $_G_count + 1` + if test "$_G_count" -gt "$_G_path_prog_max"; then + # Best one so far, save it but keep looking for a better one + func_check_prog_result=$_G_path_prog + _G_path_prog_max=$_G_count + fi + # 10*(2^10) chars as input seems more than enough + test 10 -lt "$_G_count" && break + done + rm -f conftest.in conftest.tmp conftest.nl conftest.out + } + + func_path_progs "grep ggrep" func_check_prog_grep $PATH:/usr/xpg4/bin + GREP=$func_path_progs_result +} + + +## ------------------------------- ## +## User overridable command paths. ## +## ------------------------------- ## + +# All uppercase variable names are used for environment variables. These +# variables can be overridden by the user before calling a script that +# uses them if a suitable command of that name is not already available +# in the command search PATH. + +: ${CP="cp -f"} +: ${ECHO="printf %s\n"} +: ${EGREP="$GREP -E"} +: ${FGREP="$GREP -F"} +: ${LN_S="ln -s"} +: ${MAKE="make"} +: ${MKDIR="mkdir"} +: ${MV="mv -f"} +: ${RM="rm -f"} +: ${SHELL="${CONFIG_SHELL-/bin/sh}"} + + +## -------------------- ## +## Useful sed snippets. ## +## -------------------- ## + +sed_dirname='s|/[^/]*$||' +sed_basename='s|^.*/||' + +# Sed substitution that helps us do robust quoting. It backslashifies +# metacharacters that are still active within double-quoted strings. +sed_quote_subst='s|\([`"$\\]\)|\\\1|g' + +# Same as above, but do not quote variable references. +sed_double_quote_subst='s/\(["`\\]\)/\\\1/g' + +# Sed substitution that turns a string into a regex matching for the +# string literally. +sed_make_literal_regex='s|[].[^$\\*\/]|\\&|g' + +# Sed substitution that converts a w32 file name or path +# that contains forward slashes, into one that contains +# (escaped) backslashes. A very naive implementation. +sed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g' + +# Re-'\' parameter expansions in output of sed_double_quote_subst that +# were '\'-ed in input to the same. If an odd number of '\' preceded a +# '$' in input to sed_double_quote_subst, that '$' was protected from +# expansion. Since each input '\' is now two '\'s, look for any number +# of runs of four '\'s followed by two '\'s and then a '$'. '\' that '$'. +_G_bs='\\' +_G_bs2='\\\\' +_G_bs4='\\\\\\\\' +_G_dollar='\$' +sed_double_backslash="\ + s/$_G_bs4/&\\ +/g + s/^$_G_bs2$_G_dollar/$_G_bs&/ + s/\\([^$_G_bs]\\)$_G_bs2$_G_dollar/\\1$_G_bs2$_G_bs$_G_dollar/g + s/\n//g" + + +## ----------------- ## +## Global variables. ## +## ----------------- ## + +# Except for the global variables explicitly listed below, the following +# functions in the '^func_' namespace, and the '^require_' namespace +# variables initialised in the 'Resource management' section, sourcing +# this file will not pollute your global namespace with anything +# else. There's no portable way to scope variables in Bourne shell +# though, so actually running these functions will sometimes place +# results into a variable named after the function, and often use +# temporary variables in the '^_G_' namespace. If you are careful to +# avoid using those namespaces casually in your sourcing script, things +# should continue to work as you expect. And, of course, you can freely +# overwrite any of the functions or variables defined here before +# calling anything to customize them. + +EXIT_SUCCESS=0 +EXIT_FAILURE=1 +EXIT_MISMATCH=63 # $? = 63 is used to indicate version mismatch to missing. +EXIT_SKIP=77 # $? = 77 is used to indicate a skipped test to automake. + +# Allow overriding, eg assuming that you follow the convention of +# putting '$debug_cmd' at the start of all your functions, you can get +# bash to show function call trace with: +# +# debug_cmd='echo "${FUNCNAME[0]} $*" >&2' bash your-script-name +debug_cmd=${debug_cmd-":"} +exit_cmd=: + +# By convention, finish your script with: +# +# exit $exit_status +# +# so that you can set exit_status to non-zero if you want to indicate +# something went wrong during execution without actually bailing out at +# the point of failure. +exit_status=$EXIT_SUCCESS + +# Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh +# is ksh but when the shell is invoked as "sh" and the current value of +# the _XPG environment variable is not equal to 1 (one), the special +# positional parameter $0, within a function call, is the name of the +# function. +progpath=$0 + +# The name of this program. +progname=`$ECHO "$progpath" |$SED "$sed_basename"` + +# Make sure we have an absolute progpath for reexecution: +case $progpath in + [\\/]*|[A-Za-z]:\\*) ;; + *[\\/]*) + progdir=`$ECHO "$progpath" |$SED "$sed_dirname"` + progdir=`cd "$progdir" && pwd` + progpath=$progdir/$progname + ;; + *) + _G_IFS=$IFS + IFS=${PATH_SEPARATOR-:} + for progdir in $PATH; do + IFS=$_G_IFS + test -x "$progdir/$progname" && break + done + IFS=$_G_IFS + test -n "$progdir" || progdir=`pwd` + progpath=$progdir/$progname + ;; +esac + + +## ----------------- ## +## Standard options. ## +## ----------------- ## + +# The following options affect the operation of the functions defined +# below, and should be set appropriately depending on run-time para- +# meters passed on the command line. + +opt_dry_run=false +opt_quiet=false +opt_verbose=false + +# Categories 'all' and 'none' are always available. Append any others +# you will pass as the first argument to func_warning from your own +# code. +warning_categories= + +# By default, display warnings according to 'opt_warning_types'. Set +# 'warning_func' to ':' to elide all warnings, or func_fatal_error to +# treat the next displayed warning as a fatal error. +warning_func=func_warn_and_continue + +# Set to 'all' to display all warnings, 'none' to suppress all +# warnings, or a space delimited list of some subset of +# 'warning_categories' to display only the listed warnings. +opt_warning_types=all + + +## -------------------- ## +## Resource management. ## +## -------------------- ## + +# This section contains definitions for functions that each ensure a +# particular resource (a file, or a non-empty configuration variable for +# example) is available, and if appropriate to extract default values +# from pertinent package files. Call them using their associated +# 'require_*' variable to ensure that they are executed, at most, once. +# +# It's entirely deliberate that calling these functions can set +# variables that don't obey the namespace limitations obeyed by the rest +# of this file, in order that that they be as useful as possible to +# callers. + + +# require_term_colors +# ------------------- +# Allow display of bold text on terminals that support it. +require_term_colors=func_require_term_colors +func_require_term_colors () +{ + $debug_cmd + + test -t 1 && { + # COLORTERM and USE_ANSI_COLORS environment variables take + # precedence, because most terminfo databases neglect to describe + # whether color sequences are supported. + test -n "${COLORTERM+set}" && : ${USE_ANSI_COLORS="1"} + + if test 1 = "$USE_ANSI_COLORS"; then + # Standard ANSI escape sequences + tc_reset='' + tc_bold=''; tc_standout='' + tc_red=''; tc_green='' + tc_blue=''; tc_cyan='' + else + # Otherwise trust the terminfo database after all. + test -n "`tput sgr0 2>/dev/null`" && { + tc_reset=`tput sgr0` + test -n "`tput bold 2>/dev/null`" && tc_bold=`tput bold` + tc_standout=$tc_bold + test -n "`tput smso 2>/dev/null`" && tc_standout=`tput smso` + test -n "`tput setaf 1 2>/dev/null`" && tc_red=`tput setaf 1` + test -n "`tput setaf 2 2>/dev/null`" && tc_green=`tput setaf 2` + test -n "`tput setaf 4 2>/dev/null`" && tc_blue=`tput setaf 4` + test -n "`tput setaf 5 2>/dev/null`" && tc_cyan=`tput setaf 5` + } + fi + } + + require_term_colors=: +} + + +## ----------------- ## +## Function library. ## +## ----------------- ## + +# This section contains a variety of useful functions to call in your +# scripts. Take note of the portable wrappers for features provided by +# some modern shells, which will fall back to slower equivalents on +# less featureful shells. + + +# func_append VAR VALUE +# --------------------- +# Append VALUE onto the existing contents of VAR. + + # We should try to minimise forks, especially on Windows where they are + # unreasonably slow, so skip the feature probes when bash or zsh are + # being used: + if test set = "${BASH_VERSION+set}${ZSH_VERSION+set}"; then + : ${_G_HAVE_ARITH_OP="yes"} + : ${_G_HAVE_XSI_OPS="yes"} + # The += operator was introduced in bash 3.1 + case $BASH_VERSION in + [12].* | 3.0 | 3.0*) ;; + *) + : ${_G_HAVE_PLUSEQ_OP="yes"} + ;; + esac + fi + + # _G_HAVE_PLUSEQ_OP + # Can be empty, in which case the shell is probed, "yes" if += is + # useable or anything else if it does not work. + test -z "$_G_HAVE_PLUSEQ_OP" \ + && (eval 'x=a; x+=" b"; test "a b" = "$x"') 2>/dev/null \ + && _G_HAVE_PLUSEQ_OP=yes + +if test yes = "$_G_HAVE_PLUSEQ_OP" +then + # This is an XSI compatible shell, allowing a faster implementation... + eval 'func_append () + { + $debug_cmd + + eval "$1+=\$2" + }' +else + # ...otherwise fall back to using expr, which is often a shell builtin. + func_append () + { + $debug_cmd + + eval "$1=\$$1\$2" + } +fi + + +# func_append_quoted VAR VALUE +# ---------------------------- +# Quote VALUE and append to the end of shell variable VAR, separated +# by a space. +if test yes = "$_G_HAVE_PLUSEQ_OP"; then + eval 'func_append_quoted () + { + $debug_cmd + + func_quote_for_eval "$2" + eval "$1+=\\ \$func_quote_for_eval_result" + }' +else + func_append_quoted () + { + $debug_cmd + + func_quote_for_eval "$2" + eval "$1=\$$1\\ \$func_quote_for_eval_result" + } +fi + + +# func_append_uniq VAR VALUE +# -------------------------- +# Append unique VALUE onto the existing contents of VAR, assuming +# entries are delimited by the first character of VALUE. For example: +# +# func_append_uniq options " --another-option option-argument" +# +# will only append to $options if " --another-option option-argument " +# is not already present somewhere in $options already (note spaces at +# each end implied by leading space in second argument). +func_append_uniq () +{ + $debug_cmd + + eval _G_current_value='`$ECHO $'$1'`' + _G_delim=`expr "$2" : '\(.\)'` + + case $_G_delim$_G_current_value$_G_delim in + *"$2$_G_delim"*) ;; + *) func_append "$@" ;; + esac +} + + +# func_arith TERM... +# ------------------ +# Set func_arith_result to the result of evaluating TERMs. + test -z "$_G_HAVE_ARITH_OP" \ + && (eval 'test 2 = $(( 1 + 1 ))') 2>/dev/null \ + && _G_HAVE_ARITH_OP=yes + +if test yes = "$_G_HAVE_ARITH_OP"; then + eval 'func_arith () + { + $debug_cmd + + func_arith_result=$(( $* )) + }' +else + func_arith () + { + $debug_cmd + + func_arith_result=`expr "$@"` + } +fi + + +# func_basename FILE +# ------------------ +# Set func_basename_result to FILE with everything up to and including +# the last / stripped. +if test yes = "$_G_HAVE_XSI_OPS"; then + # If this shell supports suffix pattern removal, then use it to avoid + # forking. Hide the definitions single quotes in case the shell chokes + # on unsupported syntax... + _b='func_basename_result=${1##*/}' + _d='case $1 in + */*) func_dirname_result=${1%/*}$2 ;; + * ) func_dirname_result=$3 ;; + esac' + +else + # ...otherwise fall back to using sed. + _b='func_basename_result=`$ECHO "$1" |$SED "$sed_basename"`' + _d='func_dirname_result=`$ECHO "$1" |$SED "$sed_dirname"` + if test "X$func_dirname_result" = "X$1"; then + func_dirname_result=$3 + else + func_append func_dirname_result "$2" + fi' +fi + +eval 'func_basename () +{ + $debug_cmd + + '"$_b"' +}' + + +# func_dirname FILE APPEND NONDIR_REPLACEMENT +# ------------------------------------------- +# Compute the dirname of FILE. If nonempty, add APPEND to the result, +# otherwise set result to NONDIR_REPLACEMENT. +eval 'func_dirname () +{ + $debug_cmd + + '"$_d"' +}' + + +# func_dirname_and_basename FILE APPEND NONDIR_REPLACEMENT +# -------------------------------------------------------- +# Perform func_basename and func_dirname in a single function +# call: +# dirname: Compute the dirname of FILE. If nonempty, +# add APPEND to the result, otherwise set result +# to NONDIR_REPLACEMENT. +# value returned in "$func_dirname_result" +# basename: Compute filename of FILE. +# value retuned in "$func_basename_result" +# For efficiency, we do not delegate to the functions above but instead +# duplicate the functionality here. +eval 'func_dirname_and_basename () +{ + $debug_cmd + + '"$_b"' + '"$_d"' +}' + + +# func_echo ARG... +# ---------------- +# Echo program name prefixed message. +func_echo () +{ + $debug_cmd + + _G_message=$* + + func_echo_IFS=$IFS + IFS=$nl + for _G_line in $_G_message; do + IFS=$func_echo_IFS + $ECHO "$progname: $_G_line" + done + IFS=$func_echo_IFS +} + + +# func_echo_all ARG... +# -------------------- +# Invoke $ECHO with all args, space-separated. +func_echo_all () +{ + $ECHO "$*" +} + + +# func_echo_infix_1 INFIX ARG... +# ------------------------------ +# Echo program name, followed by INFIX on the first line, with any +# additional lines not showing INFIX. +func_echo_infix_1 () +{ + $debug_cmd + + $require_term_colors + + _G_infix=$1; shift + _G_indent=$_G_infix + _G_prefix="$progname: $_G_infix: " + _G_message=$* + + # Strip color escape sequences before counting printable length + for _G_tc in "$tc_reset" "$tc_bold" "$tc_standout" "$tc_red" "$tc_green" "$tc_blue" "$tc_cyan" + do + test -n "$_G_tc" && { + _G_esc_tc=`$ECHO "$_G_tc" | $SED "$sed_make_literal_regex"` + _G_indent=`$ECHO "$_G_indent" | $SED "s|$_G_esc_tc||g"` + } + done + _G_indent="$progname: "`echo "$_G_indent" | $SED 's|.| |g'`" " ## exclude from sc_prohibit_nested_quotes + + func_echo_infix_1_IFS=$IFS + IFS=$nl + for _G_line in $_G_message; do + IFS=$func_echo_infix_1_IFS + $ECHO "$_G_prefix$tc_bold$_G_line$tc_reset" >&2 + _G_prefix=$_G_indent + done + IFS=$func_echo_infix_1_IFS +} + + +# func_error ARG... +# ----------------- +# Echo program name prefixed message to standard error. +func_error () +{ + $debug_cmd + + $require_term_colors + + func_echo_infix_1 " $tc_standout${tc_red}error$tc_reset" "$*" >&2 +} + + +# func_fatal_error ARG... +# ----------------------- +# Echo program name prefixed message to standard error, and exit. +func_fatal_error () +{ + $debug_cmd + + func_error "$*" + exit $EXIT_FAILURE +} + + +# func_grep EXPRESSION FILENAME +# ----------------------------- +# Check whether EXPRESSION matches any line of FILENAME, without output. +func_grep () +{ + $debug_cmd + + $GREP "$1" "$2" >/dev/null 2>&1 +} + + +# func_len STRING +# --------------- +# Set func_len_result to the length of STRING. STRING may not +# start with a hyphen. + test -z "$_G_HAVE_XSI_OPS" \ + && (eval 'x=a/b/c; + test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \ + && _G_HAVE_XSI_OPS=yes + +if test yes = "$_G_HAVE_XSI_OPS"; then + eval 'func_len () + { + $debug_cmd + + func_len_result=${#1} + }' +else + func_len () + { + $debug_cmd + + func_len_result=`expr "$1" : ".*" 2>/dev/null || echo $max_cmd_len` + } +fi + + +# func_mkdir_p DIRECTORY-PATH +# --------------------------- +# Make sure the entire path to DIRECTORY-PATH is available. +func_mkdir_p () +{ + $debug_cmd + + _G_directory_path=$1 + _G_dir_list= + + if test -n "$_G_directory_path" && test : != "$opt_dry_run"; then + + # Protect directory names starting with '-' + case $_G_directory_path in + -*) _G_directory_path=./$_G_directory_path ;; + esac + + # While some portion of DIR does not yet exist... + while test ! -d "$_G_directory_path"; do + # ...make a list in topmost first order. Use a colon delimited + # list incase some portion of path contains whitespace. + _G_dir_list=$_G_directory_path:$_G_dir_list + + # If the last portion added has no slash in it, the list is done + case $_G_directory_path in */*) ;; *) break ;; esac + + # ...otherwise throw away the child directory and loop + _G_directory_path=`$ECHO "$_G_directory_path" | $SED -e "$sed_dirname"` + done + _G_dir_list=`$ECHO "$_G_dir_list" | $SED 's|:*$||'` + + func_mkdir_p_IFS=$IFS; IFS=: + for _G_dir in $_G_dir_list; do + IFS=$func_mkdir_p_IFS + # mkdir can fail with a 'File exist' error if two processes + # try to create one of the directories concurrently. Don't + # stop in that case! + $MKDIR "$_G_dir" 2>/dev/null || : + done + IFS=$func_mkdir_p_IFS + + # Bail out if we (or some other process) failed to create a directory. + test -d "$_G_directory_path" || \ + func_fatal_error "Failed to create '$1'" + fi +} + + +# func_mktempdir [BASENAME] +# ------------------------- +# Make a temporary directory that won't clash with other running +# libtool processes, and avoids race conditions if possible. If +# given, BASENAME is the basename for that directory. +func_mktempdir () +{ + $debug_cmd + + _G_template=${TMPDIR-/tmp}/${1-$progname} + + if test : = "$opt_dry_run"; then + # Return a directory name, but don't create it in dry-run mode + _G_tmpdir=$_G_template-$$ + else + + # If mktemp works, use that first and foremost + _G_tmpdir=`mktemp -d "$_G_template-XXXXXXXX" 2>/dev/null` + + if test ! -d "$_G_tmpdir"; then + # Failing that, at least try and use $RANDOM to avoid a race + _G_tmpdir=$_G_template-${RANDOM-0}$$ + + func_mktempdir_umask=`umask` + umask 0077 + $MKDIR "$_G_tmpdir" + umask $func_mktempdir_umask + fi + + # If we're not in dry-run mode, bomb out on failure + test -d "$_G_tmpdir" || \ + func_fatal_error "cannot create temporary directory '$_G_tmpdir'" + fi + + $ECHO "$_G_tmpdir" +} + + +# func_normal_abspath PATH +# ------------------------ +# Remove doubled-up and trailing slashes, "." path components, +# and cancel out any ".." path components in PATH after making +# it an absolute path. +func_normal_abspath () +{ + $debug_cmd + + # These SED scripts presuppose an absolute path with a trailing slash. + _G_pathcar='s|^/\([^/]*\).*$|\1|' + _G_pathcdr='s|^/[^/]*||' + _G_removedotparts=':dotsl + s|/\./|/|g + t dotsl + s|/\.$|/|' + _G_collapseslashes='s|/\{1,\}|/|g' + _G_finalslash='s|/*$|/|' + + # Start from root dir and reassemble the path. + func_normal_abspath_result= + func_normal_abspath_tpath=$1 + func_normal_abspath_altnamespace= + case $func_normal_abspath_tpath in + "") + # Empty path, that just means $cwd. + func_stripname '' '/' "`pwd`" + func_normal_abspath_result=$func_stripname_result + return + ;; + # The next three entries are used to spot a run of precisely + # two leading slashes without using negated character classes; + # we take advantage of case's first-match behaviour. + ///*) + # Unusual form of absolute path, do nothing. + ;; + //*) + # Not necessarily an ordinary path; POSIX reserves leading '//' + # and for example Cygwin uses it to access remote file shares + # over CIFS/SMB, so we conserve a leading double slash if found. + func_normal_abspath_altnamespace=/ + ;; + /*) + # Absolute path, do nothing. + ;; + *) + # Relative path, prepend $cwd. + func_normal_abspath_tpath=`pwd`/$func_normal_abspath_tpath + ;; + esac + + # Cancel out all the simple stuff to save iterations. We also want + # the path to end with a slash for ease of parsing, so make sure + # there is one (and only one) here. + func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \ + -e "$_G_removedotparts" -e "$_G_collapseslashes" -e "$_G_finalslash"` + while :; do + # Processed it all yet? + if test / = "$func_normal_abspath_tpath"; then + # If we ascended to the root using ".." the result may be empty now. + if test -z "$func_normal_abspath_result"; then + func_normal_abspath_result=/ + fi + break + fi + func_normal_abspath_tcomponent=`$ECHO "$func_normal_abspath_tpath" | $SED \ + -e "$_G_pathcar"` + func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \ + -e "$_G_pathcdr"` + # Figure out what to do with it + case $func_normal_abspath_tcomponent in + "") + # Trailing empty path component, ignore it. + ;; + ..) + # Parent dir; strip last assembled component from result. + func_dirname "$func_normal_abspath_result" + func_normal_abspath_result=$func_dirname_result + ;; + *) + # Actual path component, append it. + func_append func_normal_abspath_result "/$func_normal_abspath_tcomponent" + ;; + esac + done + # Restore leading double-slash if one was found on entry. + func_normal_abspath_result=$func_normal_abspath_altnamespace$func_normal_abspath_result +} + + +# func_notquiet ARG... +# -------------------- +# Echo program name prefixed message only when not in quiet mode. +func_notquiet () +{ + $debug_cmd + + $opt_quiet || func_echo ${1+"$@"} + + # A bug in bash halts the script if the last line of a function + # fails when set -e is in force, so we need another command to + # work around that: + : +} + + +# func_relative_path SRCDIR DSTDIR +# -------------------------------- +# Set func_relative_path_result to the relative path from SRCDIR to DSTDIR. +func_relative_path () +{ + $debug_cmd + + func_relative_path_result= + func_normal_abspath "$1" + func_relative_path_tlibdir=$func_normal_abspath_result + func_normal_abspath "$2" + func_relative_path_tbindir=$func_normal_abspath_result + + # Ascend the tree starting from libdir + while :; do + # check if we have found a prefix of bindir + case $func_relative_path_tbindir in + $func_relative_path_tlibdir) + # found an exact match + func_relative_path_tcancelled= + break + ;; + $func_relative_path_tlibdir*) + # found a matching prefix + func_stripname "$func_relative_path_tlibdir" '' "$func_relative_path_tbindir" + func_relative_path_tcancelled=$func_stripname_result + if test -z "$func_relative_path_result"; then + func_relative_path_result=. + fi + break + ;; + *) + func_dirname $func_relative_path_tlibdir + func_relative_path_tlibdir=$func_dirname_result + if test -z "$func_relative_path_tlibdir"; then + # Have to descend all the way to the root! + func_relative_path_result=../$func_relative_path_result + func_relative_path_tcancelled=$func_relative_path_tbindir + break + fi + func_relative_path_result=../$func_relative_path_result + ;; + esac + done + + # Now calculate path; take care to avoid doubling-up slashes. + func_stripname '' '/' "$func_relative_path_result" + func_relative_path_result=$func_stripname_result + func_stripname '/' '/' "$func_relative_path_tcancelled" + if test -n "$func_stripname_result"; then + func_append func_relative_path_result "/$func_stripname_result" + fi + + # Normalisation. If bindir is libdir, return '.' else relative path. + if test -n "$func_relative_path_result"; then + func_stripname './' '' "$func_relative_path_result" + func_relative_path_result=$func_stripname_result + fi + + test -n "$func_relative_path_result" || func_relative_path_result=. + + : +} + + +# func_quote_for_eval ARG... +# -------------------------- +# Aesthetically quote ARGs to be evaled later. +# This function returns two values: +# i) func_quote_for_eval_result +# double-quoted, suitable for a subsequent eval +# ii) func_quote_for_eval_unquoted_result +# has all characters that are still active within double +# quotes backslashified. +func_quote_for_eval () +{ + $debug_cmd + + func_quote_for_eval_unquoted_result= + func_quote_for_eval_result= + while test 0 -lt $#; do + case $1 in + *[\\\`\"\$]*) + _G_unquoted_arg=`printf '%s\n' "$1" |$SED "$sed_quote_subst"` ;; + *) + _G_unquoted_arg=$1 ;; + esac + if test -n "$func_quote_for_eval_unquoted_result"; then + func_append func_quote_for_eval_unquoted_result " $_G_unquoted_arg" + else + func_append func_quote_for_eval_unquoted_result "$_G_unquoted_arg" + fi + + case $_G_unquoted_arg in + # Double-quote args containing shell metacharacters to delay + # word splitting, command substitution and variable expansion + # for a subsequent eval. + # Many Bourne shells cannot handle close brackets correctly + # in scan sets, so we specify it separately. + *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") + _G_quoted_arg=\"$_G_unquoted_arg\" + ;; + *) + _G_quoted_arg=$_G_unquoted_arg + ;; + esac + + if test -n "$func_quote_for_eval_result"; then + func_append func_quote_for_eval_result " $_G_quoted_arg" + else + func_append func_quote_for_eval_result "$_G_quoted_arg" + fi + shift + done +} + + +# func_quote_for_expand ARG +# ------------------------- +# Aesthetically quote ARG to be evaled later; same as above, +# but do not quote variable references. +func_quote_for_expand () +{ + $debug_cmd + + case $1 in + *[\\\`\"]*) + _G_arg=`$ECHO "$1" | $SED \ + -e "$sed_double_quote_subst" -e "$sed_double_backslash"` ;; + *) + _G_arg=$1 ;; + esac + + case $_G_arg in + # Double-quote args containing shell metacharacters to delay + # word splitting and command substitution for a subsequent eval. + # Many Bourne shells cannot handle close brackets correctly + # in scan sets, so we specify it separately. + *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") + _G_arg=\"$_G_arg\" + ;; + esac + + func_quote_for_expand_result=$_G_arg +} + + +# func_stripname PREFIX SUFFIX NAME +# --------------------------------- +# strip PREFIX and SUFFIX from NAME, and store in func_stripname_result. +# PREFIX and SUFFIX must not contain globbing or regex special +# characters, hashes, percent signs, but SUFFIX may contain a leading +# dot (in which case that matches only a dot). +if test yes = "$_G_HAVE_XSI_OPS"; then + eval 'func_stripname () + { + $debug_cmd + + # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are + # positional parameters, so assign one to ordinary variable first. + func_stripname_result=$3 + func_stripname_result=${func_stripname_result#"$1"} + func_stripname_result=${func_stripname_result%"$2"} + }' +else + func_stripname () + { + $debug_cmd + + case $2 in + .*) func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%\\\\$2\$%%"`;; + *) func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%$2\$%%"`;; + esac + } +fi + + +# func_show_eval CMD [FAIL_EXP] +# ----------------------------- +# Unless opt_quiet is true, then output CMD. Then, if opt_dryrun is +# not true, evaluate CMD. If the evaluation of CMD fails, and FAIL_EXP +# is given, then evaluate it. +func_show_eval () +{ + $debug_cmd + + _G_cmd=$1 + _G_fail_exp=${2-':'} + + func_quote_for_expand "$_G_cmd" + eval "func_notquiet $func_quote_for_expand_result" + + $opt_dry_run || { + eval "$_G_cmd" + _G_status=$? + if test 0 -ne "$_G_status"; then + eval "(exit $_G_status); $_G_fail_exp" + fi + } +} + + +# func_show_eval_locale CMD [FAIL_EXP] +# ------------------------------------ +# Unless opt_quiet is true, then output CMD. Then, if opt_dryrun is +# not true, evaluate CMD. If the evaluation of CMD fails, and FAIL_EXP +# is given, then evaluate it. Use the saved locale for evaluation. +func_show_eval_locale () +{ + $debug_cmd + + _G_cmd=$1 + _G_fail_exp=${2-':'} + + $opt_quiet || { + func_quote_for_expand "$_G_cmd" + eval "func_echo $func_quote_for_expand_result" + } + + $opt_dry_run || { + eval "$_G_user_locale + $_G_cmd" + _G_status=$? + eval "$_G_safe_locale" + if test 0 -ne "$_G_status"; then + eval "(exit $_G_status); $_G_fail_exp" + fi + } +} + + +# func_tr_sh +# ---------- +# Turn $1 into a string suitable for a shell variable name. +# Result is stored in $func_tr_sh_result. All characters +# not in the set a-zA-Z0-9_ are replaced with '_'. Further, +# if $1 begins with a digit, a '_' is prepended as well. +func_tr_sh () +{ + $debug_cmd + + case $1 in + [0-9]* | *[!a-zA-Z0-9_]*) + func_tr_sh_result=`$ECHO "$1" | $SED -e 's/^\([0-9]\)/_\1/' -e 's/[^a-zA-Z0-9_]/_/g'` + ;; + * ) + func_tr_sh_result=$1 + ;; + esac +} + + +# func_verbose ARG... +# ------------------- +# Echo program name prefixed message in verbose mode only. +func_verbose () +{ + $debug_cmd + + $opt_verbose && func_echo "$*" + + : +} + + +# func_warn_and_continue ARG... +# ----------------------------- +# Echo program name prefixed warning message to standard error. +func_warn_and_continue () +{ + $debug_cmd + + $require_term_colors + + func_echo_infix_1 "${tc_red}warning$tc_reset" "$*" >&2 +} + + +# func_warning CATEGORY ARG... +# ---------------------------- +# Echo program name prefixed warning message to standard error. Warning +# messages can be filtered according to CATEGORY, where this function +# elides messages where CATEGORY is not listed in the global variable +# 'opt_warning_types'. +func_warning () +{ + $debug_cmd + + # CATEGORY must be in the warning_categories list! + case " $warning_categories " in + *" $1 "*) ;; + *) func_internal_error "invalid warning category '$1'" ;; + esac + + _G_category=$1 + shift + + case " $opt_warning_types " in + *" $_G_category "*) $warning_func ${1+"$@"} ;; + esac +} + + +# func_sort_ver VER1 VER2 +# ----------------------- +# 'sort -V' is not generally available. +# Note this deviates from the version comparison in automake +# in that it treats 1.5 < 1.5.0, and treats 1.4.4a < 1.4-p3a +# but this should suffice as we won't be specifying old +# version formats or redundant trailing .0 in bootstrap.conf. +# If we did want full compatibility then we should probably +# use m4_version_compare from autoconf. +func_sort_ver () +{ + $debug_cmd + + printf '%s\n%s\n' "$1" "$2" \ + | sort -t. -k 1,1n -k 2,2n -k 3,3n -k 4,4n -k 5,5n -k 6,6n -k 7,7n -k 8,8n -k 9,9n +} + +# func_lt_ver PREV CURR +# --------------------- +# Return true if PREV and CURR are in the correct order according to +# func_sort_ver, otherwise false. Use it like this: +# +# func_lt_ver "$prev_ver" "$proposed_ver" || func_fatal_error "..." +func_lt_ver () +{ + $debug_cmd + + test "x$1" = x`func_sort_ver "$1" "$2" | $SED 1q` +} + + +# Local variables: +# mode: shell-script +# sh-indentation: 2 +# eval: (add-hook 'before-save-hook 'time-stamp) +# time-stamp-pattern: "10/scriptversion=%:y-%02m-%02d.%02H; # UTC" +# time-stamp-time-zone: "UTC" +# End: +#! /bin/sh + +# Set a version string for this script. +scriptversion=2015-10-07.11; # UTC + +# A portable, pluggable option parser for Bourne shell. +# Written by Gary V. Vaughan, 2010 + +# Copyright (C) 2010-2015 Free Software Foundation, Inc. +# This is free software; see the source for copying conditions. There is NO +# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Please report bugs or propose patches to gary@gnu.org. + + +## ------ ## +## Usage. ## +## ------ ## + +# This file is a library for parsing options in your shell scripts along +# with assorted other useful supporting features that you can make use +# of too. +# +# For the simplest scripts you might need only: +# +# #!/bin/sh +# . relative/path/to/funclib.sh +# . relative/path/to/options-parser +# scriptversion=1.0 +# func_options ${1+"$@"} +# eval set dummy "$func_options_result"; shift +# ...rest of your script... +# +# In order for the '--version' option to work, you will need to have a +# suitably formatted comment like the one at the top of this file +# starting with '# Written by ' and ending with '# warranty; '. +# +# For '-h' and '--help' to work, you will also need a one line +# description of your script's purpose in a comment directly above the +# '# Written by ' line, like the one at the top of this file. +# +# The default options also support '--debug', which will turn on shell +# execution tracing (see the comment above debug_cmd below for another +# use), and '--verbose' and the func_verbose function to allow your script +# to display verbose messages only when your user has specified +# '--verbose'. +# +# After sourcing this file, you can plug processing for additional +# options by amending the variables from the 'Configuration' section +# below, and following the instructions in the 'Option parsing' +# section further down. + +## -------------- ## +## Configuration. ## +## -------------- ## + +# You should override these variables in your script after sourcing this +# file so that they reflect the customisations you have added to the +# option parser. + +# The usage line for option parsing errors and the start of '-h' and +# '--help' output messages. You can embed shell variables for delayed +# expansion at the time the message is displayed, but you will need to +# quote other shell meta-characters carefully to prevent them being +# expanded when the contents are evaled. +usage='$progpath [OPTION]...' + +# Short help message in response to '-h' and '--help'. Add to this or +# override it after sourcing this library to reflect the full set of +# options your script accepts. +usage_message="\ + --debug enable verbose shell tracing + -W, --warnings=CATEGORY + report the warnings falling in CATEGORY [all] + -v, --verbose verbosely report processing + --version print version information and exit + -h, --help print short or long help message and exit +" + +# Additional text appended to 'usage_message' in response to '--help'. +long_help_message=" +Warning categories include: + 'all' show all warnings + 'none' turn off all the warnings + 'error' warnings are treated as fatal errors" + +# Help message printed before fatal option parsing errors. +fatal_help="Try '\$progname --help' for more information." + + + +## ------------------------- ## +## Hook function management. ## +## ------------------------- ## + +# This section contains functions for adding, removing, and running hooks +# to the main code. A hook is just a named list of of function, that can +# be run in order later on. + +# func_hookable FUNC_NAME +# ----------------------- +# Declare that FUNC_NAME will run hooks added with +# 'func_add_hook FUNC_NAME ...'. +func_hookable () +{ + $debug_cmd + + func_append hookable_fns " $1" +} + + +# func_add_hook FUNC_NAME HOOK_FUNC +# --------------------------------- +# Request that FUNC_NAME call HOOK_FUNC before it returns. FUNC_NAME must +# first have been declared "hookable" by a call to 'func_hookable'. +func_add_hook () +{ + $debug_cmd + + case " $hookable_fns " in + *" $1 "*) ;; + *) func_fatal_error "'$1' does not accept hook functions." ;; + esac + + eval func_append ${1}_hooks '" $2"' +} + + +# func_remove_hook FUNC_NAME HOOK_FUNC +# ------------------------------------ +# Remove HOOK_FUNC from the list of functions called by FUNC_NAME. +func_remove_hook () +{ + $debug_cmd + + eval ${1}_hooks='`$ECHO "\$'$1'_hooks" |$SED "s| '$2'||"`' +} + + +# func_run_hooks FUNC_NAME [ARG]... +# --------------------------------- +# Run all hook functions registered to FUNC_NAME. +# It is assumed that the list of hook functions contains nothing more +# than a whitespace-delimited list of legal shell function names, and +# no effort is wasted trying to catch shell meta-characters or preserve +# whitespace. +func_run_hooks () +{ + $debug_cmd + + _G_rc_run_hooks=false + + case " $hookable_fns " in + *" $1 "*) ;; + *) func_fatal_error "'$1' does not support hook funcions.n" ;; + esac + + eval _G_hook_fns=\$$1_hooks; shift + + for _G_hook in $_G_hook_fns; do + if eval $_G_hook '"$@"'; then + # store returned options list back into positional + # parameters for next 'cmd' execution. + eval _G_hook_result=\$${_G_hook}_result + eval set dummy "$_G_hook_result"; shift + _G_rc_run_hooks=: + fi + done + + $_G_rc_run_hooks && func_run_hooks_result=$_G_hook_result +} + + + +## --------------- ## +## Option parsing. ## +## --------------- ## + +# In order to add your own option parsing hooks, you must accept the +# full positional parameter list in your hook function, you may remove/edit +# any options that you action, and then pass back the remaining unprocessed +# options in '_result', escaped suitably for +# 'eval'. In this case you also must return $EXIT_SUCCESS to let the +# hook's caller know that it should pay attention to +# '_result'. Returning $EXIT_FAILURE signalizes that +# arguments are left untouched by the hook and therefore caller will ignore the +# result variable. +# +# Like this: +# +# my_options_prep () +# { +# $debug_cmd +# +# # Extend the existing usage message. +# usage_message=$usage_message' +# -s, --silent don'\''t print informational messages +# ' +# # No change in '$@' (ignored completely by this hook). There is +# # no need to do the equivalent (but slower) action: +# # func_quote_for_eval ${1+"$@"} +# # my_options_prep_result=$func_quote_for_eval_result +# false +# } +# func_add_hook func_options_prep my_options_prep +# +# +# my_silent_option () +# { +# $debug_cmd +# +# args_changed=false +# +# # Note that for efficiency, we parse as many options as we can +# # recognise in a loop before passing the remainder back to the +# # caller on the first unrecognised argument we encounter. +# while test $# -gt 0; do +# opt=$1; shift +# case $opt in +# --silent|-s) opt_silent=: +# args_changed=: +# ;; +# # Separate non-argument short options: +# -s*) func_split_short_opt "$_G_opt" +# set dummy "$func_split_short_opt_name" \ +# "-$func_split_short_opt_arg" ${1+"$@"} +# shift +# args_changed=: +# ;; +# *) # Make sure the first unrecognised option "$_G_opt" +# # is added back to "$@", we could need that later +# # if $args_changed is true. +# set dummy "$_G_opt" ${1+"$@"}; shift; break ;; +# esac +# done +# +# if $args_changed; then +# func_quote_for_eval ${1+"$@"} +# my_silent_option_result=$func_quote_for_eval_result +# fi +# +# $args_changed +# } +# func_add_hook func_parse_options my_silent_option +# +# +# my_option_validation () +# { +# $debug_cmd +# +# $opt_silent && $opt_verbose && func_fatal_help "\ +# '--silent' and '--verbose' options are mutually exclusive." +# +# false +# } +# func_add_hook func_validate_options my_option_validation +# +# You'll also need to manually amend $usage_message to reflect the extra +# options you parse. It's preferable to append if you can, so that +# multiple option parsing hooks can be added safely. + + +# func_options_finish [ARG]... +# ---------------------------- +# Finishing the option parse loop (call 'func_options' hooks ATM). +func_options_finish () +{ + $debug_cmd + + _G_func_options_finish_exit=false + if func_run_hooks func_options ${1+"$@"}; then + func_options_finish_result=$func_run_hooks_result + _G_func_options_finish_exit=: + fi + + $_G_func_options_finish_exit +} + + +# func_options [ARG]... +# --------------------- +# All the functions called inside func_options are hookable. See the +# individual implementations for details. +func_hookable func_options +func_options () +{ + $debug_cmd + + _G_rc_options=false + + for my_func in options_prep parse_options validate_options options_finish + do + if eval func_$my_func '${1+"$@"}'; then + eval _G_res_var='$'"func_${my_func}_result" + eval set dummy "$_G_res_var" ; shift + _G_rc_options=: + fi + done + + # Save modified positional parameters for caller. As a top-level + # options-parser function we always need to set the 'func_options_result' + # variable (regardless the $_G_rc_options value). + if $_G_rc_options; then + func_options_result=$_G_res_var + else + func_quote_for_eval ${1+"$@"} + func_options_result=$func_quote_for_eval_result + fi + + $_G_rc_options +} + + +# func_options_prep [ARG]... +# -------------------------- +# All initialisations required before starting the option parse loop. +# Note that when calling hook functions, we pass through the list of +# positional parameters. If a hook function modifies that list, and +# needs to propagate that back to rest of this script, then the complete +# modified list must be put in 'func_run_hooks_result' before +# returning $EXIT_SUCCESS (otherwise $EXIT_FAILURE is returned). +func_hookable func_options_prep +func_options_prep () +{ + $debug_cmd + + # Option defaults: + opt_verbose=false + opt_warning_types= + + _G_rc_options_prep=false + if func_run_hooks func_options_prep ${1+"$@"}; then + _G_rc_options_prep=: + # save modified positional parameters for caller + func_options_prep_result=$func_run_hooks_result + fi + + $_G_rc_options_prep +} + + +# func_parse_options [ARG]... +# --------------------------- +# The main option parsing loop. +func_hookable func_parse_options +func_parse_options () +{ + $debug_cmd + + func_parse_options_result= + + _G_rc_parse_options=false + # this just eases exit handling + while test $# -gt 0; do + # Defer to hook functions for initial option parsing, so they + # get priority in the event of reusing an option name. + if func_run_hooks func_parse_options ${1+"$@"}; then + eval set dummy "$func_run_hooks_result"; shift + _G_rc_parse_options=: + fi + + # Break out of the loop if we already parsed every option. + test $# -gt 0 || break + + _G_match_parse_options=: + _G_opt=$1 + shift + case $_G_opt in + --debug|-x) debug_cmd='set -x' + func_echo "enabling shell trace mode" + $debug_cmd + ;; + + --no-warnings|--no-warning|--no-warn) + set dummy --warnings none ${1+"$@"} + shift + ;; + + --warnings|--warning|-W) + if test $# = 0 && func_missing_arg $_G_opt; then + _G_rc_parse_options=: + break + fi + case " $warning_categories $1" in + *" $1 "*) + # trailing space prevents matching last $1 above + func_append_uniq opt_warning_types " $1" + ;; + *all) + opt_warning_types=$warning_categories + ;; + *none) + opt_warning_types=none + warning_func=: + ;; + *error) + opt_warning_types=$warning_categories + warning_func=func_fatal_error + ;; + *) + func_fatal_error \ + "unsupported warning category: '$1'" + ;; + esac + shift + ;; + + --verbose|-v) opt_verbose=: ;; + --version) func_version ;; + -\?|-h) func_usage ;; + --help) func_help ;; + + # Separate optargs to long options (plugins may need this): + --*=*) func_split_equals "$_G_opt" + set dummy "$func_split_equals_lhs" \ + "$func_split_equals_rhs" ${1+"$@"} + shift + ;; + + # Separate optargs to short options: + -W*) + func_split_short_opt "$_G_opt" + set dummy "$func_split_short_opt_name" \ + "$func_split_short_opt_arg" ${1+"$@"} + shift + ;; + + # Separate non-argument short options: + -\?*|-h*|-v*|-x*) + func_split_short_opt "$_G_opt" + set dummy "$func_split_short_opt_name" \ + "-$func_split_short_opt_arg" ${1+"$@"} + shift + ;; + + --) _G_rc_parse_options=: ; break ;; + -*) func_fatal_help "unrecognised option: '$_G_opt'" ;; + *) set dummy "$_G_opt" ${1+"$@"}; shift + _G_match_parse_options=false + break + ;; + esac + + $_G_match_parse_options && _G_rc_parse_options=: + done + + + if $_G_rc_parse_options; then + # save modified positional parameters for caller + func_quote_for_eval ${1+"$@"} + func_parse_options_result=$func_quote_for_eval_result + fi + + $_G_rc_parse_options +} + + +# func_validate_options [ARG]... +# ------------------------------ +# Perform any sanity checks on option settings and/or unconsumed +# arguments. +func_hookable func_validate_options +func_validate_options () +{ + $debug_cmd + + _G_rc_validate_options=false + + # Display all warnings if -W was not given. + test -n "$opt_warning_types" || opt_warning_types=" $warning_categories" + + if func_run_hooks func_validate_options ${1+"$@"}; then + # save modified positional parameters for caller + func_validate_options_result=$func_run_hooks_result + _G_rc_validate_options=: + fi + + # Bail if the options were screwed! + $exit_cmd $EXIT_FAILURE + + $_G_rc_validate_options +} + + + +## ----------------- ## +## Helper functions. ## +## ----------------- ## + +# This section contains the helper functions used by the rest of the +# hookable option parser framework in ascii-betical order. + + +# func_fatal_help ARG... +# ---------------------- +# Echo program name prefixed message to standard error, followed by +# a help hint, and exit. +func_fatal_help () +{ + $debug_cmd + + eval \$ECHO \""Usage: $usage"\" + eval \$ECHO \""$fatal_help"\" + func_error ${1+"$@"} + exit $EXIT_FAILURE +} + + +# func_help +# --------- +# Echo long help message to standard output and exit. +func_help () +{ + $debug_cmd + + func_usage_message + $ECHO "$long_help_message" + exit 0 +} + + +# func_missing_arg ARGNAME +# ------------------------ +# Echo program name prefixed message to standard error and set global +# exit_cmd. +func_missing_arg () +{ + $debug_cmd + + func_error "Missing argument for '$1'." + exit_cmd=exit +} + + +# func_split_equals STRING +# ------------------------ +# Set func_split_equals_lhs and func_split_equals_rhs shell variables after +# splitting STRING at the '=' sign. +test -z "$_G_HAVE_XSI_OPS" \ + && (eval 'x=a/b/c; + test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \ + && _G_HAVE_XSI_OPS=yes + +if test yes = "$_G_HAVE_XSI_OPS" +then + # This is an XSI compatible shell, allowing a faster implementation... + eval 'func_split_equals () + { + $debug_cmd + + func_split_equals_lhs=${1%%=*} + func_split_equals_rhs=${1#*=} + test "x$func_split_equals_lhs" = "x$1" \ + && func_split_equals_rhs= + }' +else + # ...otherwise fall back to using expr, which is often a shell builtin. + func_split_equals () + { + $debug_cmd + + func_split_equals_lhs=`expr "x$1" : 'x\([^=]*\)'` + func_split_equals_rhs= + test "x$func_split_equals_lhs" = "x$1" \ + || func_split_equals_rhs=`expr "x$1" : 'x[^=]*=\(.*\)$'` + } +fi #func_split_equals + + +# func_split_short_opt SHORTOPT +# ----------------------------- +# Set func_split_short_opt_name and func_split_short_opt_arg shell +# variables after splitting SHORTOPT after the 2nd character. +if test yes = "$_G_HAVE_XSI_OPS" +then + # This is an XSI compatible shell, allowing a faster implementation... + eval 'func_split_short_opt () + { + $debug_cmd + + func_split_short_opt_arg=${1#??} + func_split_short_opt_name=${1%"$func_split_short_opt_arg"} + }' +else + # ...otherwise fall back to using expr, which is often a shell builtin. + func_split_short_opt () + { + $debug_cmd + + func_split_short_opt_name=`expr "x$1" : 'x-\(.\)'` + func_split_short_opt_arg=`expr "x$1" : 'x-.\(.*\)$'` + } +fi #func_split_short_opt + + +# func_usage +# ---------- +# Echo short help message to standard output and exit. +func_usage () +{ + $debug_cmd + + func_usage_message + $ECHO "Run '$progname --help |${PAGER-more}' for full usage" + exit 0 +} + + +# func_usage_message +# ------------------ +# Echo short help message to standard output. +func_usage_message () +{ + $debug_cmd + + eval \$ECHO \""Usage: $usage"\" + echo + $SED -n 's|^# || + /^Written by/{ + x;p;x + } + h + /^Written by/q' < "$progpath" + echo + eval \$ECHO \""$usage_message"\" +} + + +# func_version +# ------------ +# Echo version message to standard output and exit. +func_version () +{ + $debug_cmd + + printf '%s\n' "$progname $scriptversion" + $SED -n ' + /(C)/!b go + :more + /\./!{ + N + s|\n# | | + b more + } + :go + /^# Written by /,/# warranty; / { + s|^# || + s|^# *$|| + s|\((C)\)[ 0-9,-]*[ ,-]\([1-9][0-9]* \)|\1 \2| + p + } + /^# Written by / { + s|^# || + p + } + /^warranty; /q' < "$progpath" + + exit $? +} + + +# Local variables: +# mode: shell-script +# sh-indentation: 2 +# eval: (add-hook 'before-save-hook 'time-stamp) +# time-stamp-pattern: "10/scriptversion=%:y-%02m-%02d.%02H; # UTC" +# time-stamp-time-zone: "UTC" +# End: + +# Set a version string. +scriptversion='(GNU libtool) 2.4.6' + + +# func_echo ARG... +# ---------------- +# Libtool also displays the current mode in messages, so override +# funclib.sh func_echo with this custom definition. +func_echo () +{ + $debug_cmd + + _G_message=$* + + func_echo_IFS=$IFS + IFS=$nl + for _G_line in $_G_message; do + IFS=$func_echo_IFS + $ECHO "$progname${opt_mode+: $opt_mode}: $_G_line" + done + IFS=$func_echo_IFS +} + + +# func_warning ARG... +# ------------------- +# Libtool warnings are not categorized, so override funclib.sh +# func_warning with this simpler definition. +func_warning () +{ + $debug_cmd + + $warning_func ${1+"$@"} +} + + +## ---------------- ## +## Options parsing. ## +## ---------------- ## + +# Hook in the functions to make sure our own options are parsed during +# the option parsing loop. + +usage='$progpath [OPTION]... [MODE-ARG]...' + +# Short help message in response to '-h'. +usage_message="Options: + --config show all configuration variables + --debug enable verbose shell tracing + -n, --dry-run display commands without modifying any files + --features display basic configuration information and exit + --mode=MODE use operation mode MODE + --no-warnings equivalent to '-Wnone' + --preserve-dup-deps don't remove duplicate dependency libraries + --quiet, --silent don't print informational messages + --tag=TAG use configuration variables from tag TAG + -v, --verbose print more informational messages than default + --version print version information + -W, --warnings=CATEGORY report the warnings falling in CATEGORY [all] + -h, --help, --help-all print short, long, or detailed help message +" + +# Additional text appended to 'usage_message' in response to '--help'. +func_help () +{ + $debug_cmd + + func_usage_message + $ECHO "$long_help_message + +MODE must be one of the following: + + clean remove files from the build directory + compile compile a source file into a libtool object + execute automatically set library path, then run a program + finish complete the installation of libtool libraries + install install libraries or executables + link create a library or an executable + uninstall remove libraries from an installed directory + +MODE-ARGS vary depending on the MODE. When passed as first option, +'--mode=MODE' may be abbreviated as 'MODE' or a unique abbreviation of that. +Try '$progname --help --mode=MODE' for a more detailed description of MODE. + +When reporting a bug, please describe a test case to reproduce it and +include the following information: + + host-triplet: $host + shell: $SHELL + compiler: $LTCC + compiler flags: $LTCFLAGS + linker: $LD (gnu? $with_gnu_ld) + version: $progname $scriptversion Debian-2.4.6-15build2 + automake: `($AUTOMAKE --version) 2>/dev/null |$SED 1q` + autoconf: `($AUTOCONF --version) 2>/dev/null |$SED 1q` + +Report bugs to . +GNU libtool home page: . +General help using GNU software: ." + exit 0 +} + + +# func_lo2o OBJECT-NAME +# --------------------- +# Transform OBJECT-NAME from a '.lo' suffix to the platform specific +# object suffix. + +lo2o=s/\\.lo\$/.$objext/ +o2lo=s/\\.$objext\$/.lo/ + +if test yes = "$_G_HAVE_XSI_OPS"; then + eval 'func_lo2o () + { + case $1 in + *.lo) func_lo2o_result=${1%.lo}.$objext ;; + * ) func_lo2o_result=$1 ;; + esac + }' + + # func_xform LIBOBJ-OR-SOURCE + # --------------------------- + # Transform LIBOBJ-OR-SOURCE from a '.o' or '.c' (or otherwise) + # suffix to a '.lo' libtool-object suffix. + eval 'func_xform () + { + func_xform_result=${1%.*}.lo + }' +else + # ...otherwise fall back to using sed. + func_lo2o () + { + func_lo2o_result=`$ECHO "$1" | $SED "$lo2o"` + } + + func_xform () + { + func_xform_result=`$ECHO "$1" | $SED 's|\.[^.]*$|.lo|'` + } +fi + + +# func_fatal_configuration ARG... +# ------------------------------- +# Echo program name prefixed message to standard error, followed by +# a configuration failure hint, and exit. +func_fatal_configuration () +{ + func__fatal_error ${1+"$@"} \ + "See the $PACKAGE documentation for more information." \ + "Fatal configuration error." +} + + +# func_config +# ----------- +# Display the configuration for all the tags in this script. +func_config () +{ + re_begincf='^# ### BEGIN LIBTOOL' + re_endcf='^# ### END LIBTOOL' + + # Default configuration. + $SED "1,/$re_begincf CONFIG/d;/$re_endcf CONFIG/,\$d" < "$progpath" + + # Now print the configurations for the tags. + for tagname in $taglist; do + $SED -n "/$re_begincf TAG CONFIG: $tagname\$/,/$re_endcf TAG CONFIG: $tagname\$/p" < "$progpath" + done + + exit $? +} + + +# func_features +# ------------- +# Display the features supported by this script. +func_features () +{ + echo "host: $host" + if test yes = "$build_libtool_libs"; then + echo "enable shared libraries" + else + echo "disable shared libraries" + fi + if test yes = "$build_old_libs"; then + echo "enable static libraries" + else + echo "disable static libraries" + fi + + exit $? +} + + +# func_enable_tag TAGNAME +# ----------------------- +# Verify that TAGNAME is valid, and either flag an error and exit, or +# enable the TAGNAME tag. We also add TAGNAME to the global $taglist +# variable here. +func_enable_tag () +{ + # Global variable: + tagname=$1 + + re_begincf="^# ### BEGIN LIBTOOL TAG CONFIG: $tagname\$" + re_endcf="^# ### END LIBTOOL TAG CONFIG: $tagname\$" + sed_extractcf=/$re_begincf/,/$re_endcf/p + + # Validate tagname. + case $tagname in + *[!-_A-Za-z0-9,/]*) + func_fatal_error "invalid tag name: $tagname" + ;; + esac + + # Don't test for the "default" C tag, as we know it's + # there but not specially marked. + case $tagname in + CC) ;; + *) + if $GREP "$re_begincf" "$progpath" >/dev/null 2>&1; then + taglist="$taglist $tagname" + + # Evaluate the configuration. Be careful to quote the path + # and the sed script, to avoid splitting on whitespace, but + # also don't use non-portable quotes within backquotes within + # quotes we have to do it in 2 steps: + extractedcf=`$SED -n -e "$sed_extractcf" < "$progpath"` + eval "$extractedcf" + else + func_error "ignoring unknown tag $tagname" + fi + ;; + esac +} + + +# func_check_version_match +# ------------------------ +# Ensure that we are using m4 macros, and libtool script from the same +# release of libtool. +func_check_version_match () +{ + if test "$package_revision" != "$macro_revision"; then + if test "$VERSION" != "$macro_version"; then + if test -z "$macro_version"; then + cat >&2 <<_LT_EOF +$progname: Version mismatch error. This is $PACKAGE $VERSION, but the +$progname: definition of this LT_INIT comes from an older release. +$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION +$progname: and run autoconf again. +_LT_EOF + else + cat >&2 <<_LT_EOF +$progname: Version mismatch error. This is $PACKAGE $VERSION, but the +$progname: definition of this LT_INIT comes from $PACKAGE $macro_version. +$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION +$progname: and run autoconf again. +_LT_EOF + fi + else + cat >&2 <<_LT_EOF +$progname: Version mismatch error. This is $PACKAGE $VERSION, revision $package_revision, +$progname: but the definition of this LT_INIT comes from revision $macro_revision. +$progname: You should recreate aclocal.m4 with macros from revision $package_revision +$progname: of $PACKAGE $VERSION and run autoconf again. +_LT_EOF + fi + + exit $EXIT_MISMATCH + fi +} + + +# libtool_options_prep [ARG]... +# ----------------------------- +# Preparation for options parsed by libtool. +libtool_options_prep () +{ + $debug_mode + + # Option defaults: + opt_config=false + opt_dlopen= + opt_dry_run=false + opt_help=false + opt_mode= + opt_preserve_dup_deps=false + opt_quiet=false + + nonopt= + preserve_args= + + _G_rc_lt_options_prep=: + + # Shorthand for --mode=foo, only valid as the first argument + case $1 in + clean|clea|cle|cl) + shift; set dummy --mode clean ${1+"$@"}; shift + ;; + compile|compil|compi|comp|com|co|c) + shift; set dummy --mode compile ${1+"$@"}; shift + ;; + execute|execut|execu|exec|exe|ex|e) + shift; set dummy --mode execute ${1+"$@"}; shift + ;; + finish|finis|fini|fin|fi|f) + shift; set dummy --mode finish ${1+"$@"}; shift + ;; + install|instal|insta|inst|ins|in|i) + shift; set dummy --mode install ${1+"$@"}; shift + ;; + link|lin|li|l) + shift; set dummy --mode link ${1+"$@"}; shift + ;; + uninstall|uninstal|uninsta|uninst|unins|unin|uni|un|u) + shift; set dummy --mode uninstall ${1+"$@"}; shift + ;; + *) + _G_rc_lt_options_prep=false + ;; + esac + + if $_G_rc_lt_options_prep; then + # Pass back the list of options. + func_quote_for_eval ${1+"$@"} + libtool_options_prep_result=$func_quote_for_eval_result + fi + + $_G_rc_lt_options_prep +} +func_add_hook func_options_prep libtool_options_prep + + +# libtool_parse_options [ARG]... +# --------------------------------- +# Provide handling for libtool specific options. +libtool_parse_options () +{ + $debug_cmd + + _G_rc_lt_parse_options=false + + # Perform our own loop to consume as many options as possible in + # each iteration. + while test $# -gt 0; do + _G_match_lt_parse_options=: + _G_opt=$1 + shift + case $_G_opt in + --dry-run|--dryrun|-n) + opt_dry_run=: + ;; + + --config) func_config ;; + + --dlopen|-dlopen) + opt_dlopen="${opt_dlopen+$opt_dlopen +}$1" + shift + ;; + + --preserve-dup-deps) + opt_preserve_dup_deps=: ;; + + --features) func_features ;; + + --finish) set dummy --mode finish ${1+"$@"}; shift ;; + + --help) opt_help=: ;; + + --help-all) opt_help=': help-all' ;; + + --mode) test $# = 0 && func_missing_arg $_G_opt && break + opt_mode=$1 + case $1 in + # Valid mode arguments: + clean|compile|execute|finish|install|link|relink|uninstall) ;; + + # Catch anything else as an error + *) func_error "invalid argument for $_G_opt" + exit_cmd=exit + break + ;; + esac + shift + ;; + + --no-silent|--no-quiet) + opt_quiet=false + func_append preserve_args " $_G_opt" + ;; + + --no-warnings|--no-warning|--no-warn) + opt_warning=false + func_append preserve_args " $_G_opt" + ;; + + --no-verbose) + opt_verbose=false + func_append preserve_args " $_G_opt" + ;; + + --silent|--quiet) + opt_quiet=: + opt_verbose=false + func_append preserve_args " $_G_opt" + ;; + + --tag) test $# = 0 && func_missing_arg $_G_opt && break + opt_tag=$1 + func_append preserve_args " $_G_opt $1" + func_enable_tag "$1" + shift + ;; + + --verbose|-v) opt_quiet=false + opt_verbose=: + func_append preserve_args " $_G_opt" + ;; + + # An option not handled by this hook function: + *) set dummy "$_G_opt" ${1+"$@"} ; shift + _G_match_lt_parse_options=false + break + ;; + esac + $_G_match_lt_parse_options && _G_rc_lt_parse_options=: + done + + if $_G_rc_lt_parse_options; then + # save modified positional parameters for caller + func_quote_for_eval ${1+"$@"} + libtool_parse_options_result=$func_quote_for_eval_result + fi + + $_G_rc_lt_parse_options +} +func_add_hook func_parse_options libtool_parse_options + + + +# libtool_validate_options [ARG]... +# --------------------------------- +# Perform any sanity checks on option settings and/or unconsumed +# arguments. +libtool_validate_options () +{ + # save first non-option argument + if test 0 -lt $#; then + nonopt=$1 + shift + fi + + # preserve --debug + test : = "$debug_cmd" || func_append preserve_args " --debug" + + case $host in + # Solaris2 added to fix http://debbugs.gnu.org/cgi/bugreport.cgi?bug=16452 + # see also: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59788 + *cygwin* | *mingw* | *pw32* | *cegcc* | *solaris2* | *os2*) + # don't eliminate duplications in $postdeps and $predeps + opt_duplicate_compiler_generated_deps=: + ;; + *) + opt_duplicate_compiler_generated_deps=$opt_preserve_dup_deps + ;; + esac + + $opt_help || { + # Sanity checks first: + func_check_version_match + + test yes != "$build_libtool_libs" \ + && test yes != "$build_old_libs" \ + && func_fatal_configuration "not configured to build any kind of library" + + # Darwin sucks + eval std_shrext=\"$shrext_cmds\" + + # Only execute mode is allowed to have -dlopen flags. + if test -n "$opt_dlopen" && test execute != "$opt_mode"; then + func_error "unrecognized option '-dlopen'" + $ECHO "$help" 1>&2 + exit $EXIT_FAILURE + fi + + # Change the help message to a mode-specific one. + generic_help=$help + help="Try '$progname --help --mode=$opt_mode' for more information." + } + + # Pass back the unparsed argument list + func_quote_for_eval ${1+"$@"} + libtool_validate_options_result=$func_quote_for_eval_result +} +func_add_hook func_validate_options libtool_validate_options + + +# Process options as early as possible so that --help and --version +# can return quickly. +func_options ${1+"$@"} +eval set dummy "$func_options_result"; shift + + + +## ----------- ## +## Main. ## +## ----------- ## + +magic='%%%MAGIC variable%%%' +magic_exe='%%%MAGIC EXE variable%%%' + +# Global variables. +extracted_archives= +extracted_serial=0 + +# If this variable is set in any of the actions, the command in it +# will be execed at the end. This prevents here-documents from being +# left over by shells. +exec_cmd= + + +# A function that is used when there is no print builtin or printf. +func_fallback_echo () +{ + eval 'cat <<_LTECHO_EOF +$1 +_LTECHO_EOF' +} + +# func_generated_by_libtool +# True iff stdin has been generated by Libtool. This function is only +# a basic sanity check; it will hardly flush out determined imposters. +func_generated_by_libtool_p () +{ + $GREP "^# Generated by .*$PACKAGE" > /dev/null 2>&1 +} + +# func_lalib_p file +# True iff FILE is a libtool '.la' library or '.lo' object file. +# This function is only a basic sanity check; it will hardly flush out +# determined imposters. +func_lalib_p () +{ + test -f "$1" && + $SED -e 4q "$1" 2>/dev/null | func_generated_by_libtool_p +} + +# func_lalib_unsafe_p file +# True iff FILE is a libtool '.la' library or '.lo' object file. +# This function implements the same check as func_lalib_p without +# resorting to external programs. To this end, it redirects stdin and +# closes it afterwards, without saving the original file descriptor. +# As a safety measure, use it only where a negative result would be +# fatal anyway. Works if 'file' does not exist. +func_lalib_unsafe_p () +{ + lalib_p=no + if test -f "$1" && test -r "$1" && exec 5<&0 <"$1"; then + for lalib_p_l in 1 2 3 4 + do + read lalib_p_line + case $lalib_p_line in + \#\ Generated\ by\ *$PACKAGE* ) lalib_p=yes; break;; + esac + done + exec 0<&5 5<&- + fi + test yes = "$lalib_p" +} + +# func_ltwrapper_script_p file +# True iff FILE is a libtool wrapper script +# This function is only a basic sanity check; it will hardly flush out +# determined imposters. +func_ltwrapper_script_p () +{ + test -f "$1" && + $lt_truncate_bin < "$1" 2>/dev/null | func_generated_by_libtool_p +} + +# func_ltwrapper_executable_p file +# True iff FILE is a libtool wrapper executable +# This function is only a basic sanity check; it will hardly flush out +# determined imposters. +func_ltwrapper_executable_p () +{ + func_ltwrapper_exec_suffix= + case $1 in + *.exe) ;; + *) func_ltwrapper_exec_suffix=.exe ;; + esac + $GREP "$magic_exe" "$1$func_ltwrapper_exec_suffix" >/dev/null 2>&1 +} + +# func_ltwrapper_scriptname file +# Assumes file is an ltwrapper_executable +# uses $file to determine the appropriate filename for a +# temporary ltwrapper_script. +func_ltwrapper_scriptname () +{ + func_dirname_and_basename "$1" "" "." + func_stripname '' '.exe' "$func_basename_result" + func_ltwrapper_scriptname_result=$func_dirname_result/$objdir/${func_stripname_result}_ltshwrapper +} + +# func_ltwrapper_p file +# True iff FILE is a libtool wrapper script or wrapper executable +# This function is only a basic sanity check; it will hardly flush out +# determined imposters. +func_ltwrapper_p () +{ + func_ltwrapper_script_p "$1" || func_ltwrapper_executable_p "$1" +} + + +# func_execute_cmds commands fail_cmd +# Execute tilde-delimited COMMANDS. +# If FAIL_CMD is given, eval that upon failure. +# FAIL_CMD may read-access the current command in variable CMD! +func_execute_cmds () +{ + $debug_cmd + + save_ifs=$IFS; IFS='~' + for cmd in $1; do + IFS=$sp$nl + eval cmd=\"$cmd\" + IFS=$save_ifs + func_show_eval "$cmd" "${2-:}" + done + IFS=$save_ifs +} + + +# func_source file +# Source FILE, adding directory component if necessary. +# Note that it is not necessary on cygwin/mingw to append a dot to +# FILE even if both FILE and FILE.exe exist: automatic-append-.exe +# behavior happens only for exec(3), not for open(2)! Also, sourcing +# 'FILE.' does not work on cygwin managed mounts. +func_source () +{ + $debug_cmd + + case $1 in + */* | *\\*) . "$1" ;; + *) . "./$1" ;; + esac +} + + +# func_resolve_sysroot PATH +# Replace a leading = in PATH with a sysroot. Store the result into +# func_resolve_sysroot_result +func_resolve_sysroot () +{ + func_resolve_sysroot_result=$1 + case $func_resolve_sysroot_result in + =*) + func_stripname '=' '' "$func_resolve_sysroot_result" + func_resolve_sysroot_result=$lt_sysroot$func_stripname_result + ;; + esac +} + +# func_replace_sysroot PATH +# If PATH begins with the sysroot, replace it with = and +# store the result into func_replace_sysroot_result. +func_replace_sysroot () +{ + case $lt_sysroot:$1 in + ?*:"$lt_sysroot"*) + func_stripname "$lt_sysroot" '' "$1" + func_replace_sysroot_result='='$func_stripname_result + ;; + *) + # Including no sysroot. + func_replace_sysroot_result=$1 + ;; + esac +} + +# func_infer_tag arg +# Infer tagged configuration to use if any are available and +# if one wasn't chosen via the "--tag" command line option. +# Only attempt this if the compiler in the base compile +# command doesn't match the default compiler. +# arg is usually of the form 'gcc ...' +func_infer_tag () +{ + $debug_cmd + + if test -n "$available_tags" && test -z "$tagname"; then + CC_quoted= + for arg in $CC; do + func_append_quoted CC_quoted "$arg" + done + CC_expanded=`func_echo_all $CC` + CC_quoted_expanded=`func_echo_all $CC_quoted` + case $@ in + # Blanks in the command may have been stripped by the calling shell, + # but not from the CC environment variable when configure was run. + " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \ + " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*) ;; + # Blanks at the start of $base_compile will cause this to fail + # if we don't check for them as well. + *) + for z in $available_tags; do + if $GREP "^# ### BEGIN LIBTOOL TAG CONFIG: $z$" < "$progpath" > /dev/null; then + # Evaluate the configuration. + eval "`$SED -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$z'$/,/^# ### END LIBTOOL TAG CONFIG: '$z'$/p' < $progpath`" + CC_quoted= + for arg in $CC; do + # Double-quote args containing other shell metacharacters. + func_append_quoted CC_quoted "$arg" + done + CC_expanded=`func_echo_all $CC` + CC_quoted_expanded=`func_echo_all $CC_quoted` + case "$@ " in + " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \ + " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*) + # The compiler in the base compile command matches + # the one in the tagged configuration. + # Assume this is the tagged configuration we want. + tagname=$z + break + ;; + esac + fi + done + # If $tagname still isn't set, then no tagged configuration + # was found and let the user know that the "--tag" command + # line option must be used. + if test -z "$tagname"; then + func_echo "unable to infer tagged configuration" + func_fatal_error "specify a tag with '--tag'" +# else +# func_verbose "using $tagname tagged configuration" + fi + ;; + esac + fi +} + + + +# func_write_libtool_object output_name pic_name nonpic_name +# Create a libtool object file (analogous to a ".la" file), +# but don't create it if we're doing a dry run. +func_write_libtool_object () +{ + write_libobj=$1 + if test yes = "$build_libtool_libs"; then + write_lobj=\'$2\' + else + write_lobj=none + fi + + if test yes = "$build_old_libs"; then + write_oldobj=\'$3\' + else + write_oldobj=none + fi + + $opt_dry_run || { + cat >${write_libobj}T </dev/null` + if test "$?" -eq 0 && test -n "$func_convert_core_file_wine_to_w32_tmp"; then + func_convert_core_file_wine_to_w32_result=`$ECHO "$func_convert_core_file_wine_to_w32_tmp" | + $SED -e "$sed_naive_backslashify"` + else + func_convert_core_file_wine_to_w32_result= + fi + fi +} +# end: func_convert_core_file_wine_to_w32 + + +# func_convert_core_path_wine_to_w32 ARG +# Helper function used by path conversion functions when $build is *nix, and +# $host is mingw, cygwin, or some other w32 environment. Relies on a correctly +# configured wine environment available, with the winepath program in $build's +# $PATH. Assumes ARG has no leading or trailing path separator characters. +# +# ARG is path to be converted from $build format to win32. +# Result is available in $func_convert_core_path_wine_to_w32_result. +# Unconvertible file (directory) names in ARG are skipped; if no directory names +# are convertible, then the result may be empty. +func_convert_core_path_wine_to_w32 () +{ + $debug_cmd + + # unfortunately, winepath doesn't convert paths, only file names + func_convert_core_path_wine_to_w32_result= + if test -n "$1"; then + oldIFS=$IFS + IFS=: + for func_convert_core_path_wine_to_w32_f in $1; do + IFS=$oldIFS + func_convert_core_file_wine_to_w32 "$func_convert_core_path_wine_to_w32_f" + if test -n "$func_convert_core_file_wine_to_w32_result"; then + if test -z "$func_convert_core_path_wine_to_w32_result"; then + func_convert_core_path_wine_to_w32_result=$func_convert_core_file_wine_to_w32_result + else + func_append func_convert_core_path_wine_to_w32_result ";$func_convert_core_file_wine_to_w32_result" + fi + fi + done + IFS=$oldIFS + fi +} +# end: func_convert_core_path_wine_to_w32 + + +# func_cygpath ARGS... +# Wrapper around calling the cygpath program via LT_CYGPATH. This is used when +# when (1) $build is *nix and Cygwin is hosted via a wine environment; or (2) +# $build is MSYS and $host is Cygwin, or (3) $build is Cygwin. In case (1) or +# (2), returns the Cygwin file name or path in func_cygpath_result (input +# file name or path is assumed to be in w32 format, as previously converted +# from $build's *nix or MSYS format). In case (3), returns the w32 file name +# or path in func_cygpath_result (input file name or path is assumed to be in +# Cygwin format). Returns an empty string on error. +# +# ARGS are passed to cygpath, with the last one being the file name or path to +# be converted. +# +# Specify the absolute *nix (or w32) name to cygpath in the LT_CYGPATH +# environment variable; do not put it in $PATH. +func_cygpath () +{ + $debug_cmd + + if test -n "$LT_CYGPATH" && test -f "$LT_CYGPATH"; then + func_cygpath_result=`$LT_CYGPATH "$@" 2>/dev/null` + if test "$?" -ne 0; then + # on failure, ensure result is empty + func_cygpath_result= + fi + else + func_cygpath_result= + func_error "LT_CYGPATH is empty or specifies non-existent file: '$LT_CYGPATH'" + fi +} +#end: func_cygpath + + +# func_convert_core_msys_to_w32 ARG +# Convert file name or path ARG from MSYS format to w32 format. Return +# result in func_convert_core_msys_to_w32_result. +func_convert_core_msys_to_w32 () +{ + $debug_cmd + + # awkward: cmd appends spaces to result + func_convert_core_msys_to_w32_result=`( cmd //c echo "$1" ) 2>/dev/null | + $SED -e 's/[ ]*$//' -e "$sed_naive_backslashify"` +} +#end: func_convert_core_msys_to_w32 + + +# func_convert_file_check ARG1 ARG2 +# Verify that ARG1 (a file name in $build format) was converted to $host +# format in ARG2. Otherwise, emit an error message, but continue (resetting +# func_to_host_file_result to ARG1). +func_convert_file_check () +{ + $debug_cmd + + if test -z "$2" && test -n "$1"; then + func_error "Could not determine host file name corresponding to" + func_error " '$1'" + func_error "Continuing, but uninstalled executables may not work." + # Fallback: + func_to_host_file_result=$1 + fi +} +# end func_convert_file_check + + +# func_convert_path_check FROM_PATHSEP TO_PATHSEP FROM_PATH TO_PATH +# Verify that FROM_PATH (a path in $build format) was converted to $host +# format in TO_PATH. Otherwise, emit an error message, but continue, resetting +# func_to_host_file_result to a simplistic fallback value (see below). +func_convert_path_check () +{ + $debug_cmd + + if test -z "$4" && test -n "$3"; then + func_error "Could not determine the host path corresponding to" + func_error " '$3'" + func_error "Continuing, but uninstalled executables may not work." + # Fallback. This is a deliberately simplistic "conversion" and + # should not be "improved". See libtool.info. + if test "x$1" != "x$2"; then + lt_replace_pathsep_chars="s|$1|$2|g" + func_to_host_path_result=`echo "$3" | + $SED -e "$lt_replace_pathsep_chars"` + else + func_to_host_path_result=$3 + fi + fi +} +# end func_convert_path_check + + +# func_convert_path_front_back_pathsep FRONTPAT BACKPAT REPL ORIG +# Modifies func_to_host_path_result by prepending REPL if ORIG matches FRONTPAT +# and appending REPL if ORIG matches BACKPAT. +func_convert_path_front_back_pathsep () +{ + $debug_cmd + + case $4 in + $1 ) func_to_host_path_result=$3$func_to_host_path_result + ;; + esac + case $4 in + $2 ) func_append func_to_host_path_result "$3" + ;; + esac +} +# end func_convert_path_front_back_pathsep + + +################################################## +# $build to $host FILE NAME CONVERSION FUNCTIONS # +################################################## +# invoked via '$to_host_file_cmd ARG' +# +# In each case, ARG is the path to be converted from $build to $host format. +# Result will be available in $func_to_host_file_result. + + +# func_to_host_file ARG +# Converts the file name ARG from $build format to $host format. Return result +# in func_to_host_file_result. +func_to_host_file () +{ + $debug_cmd + + $to_host_file_cmd "$1" +} +# end func_to_host_file + + +# func_to_tool_file ARG LAZY +# converts the file name ARG from $build format to toolchain format. Return +# result in func_to_tool_file_result. If the conversion in use is listed +# in (the comma separated) LAZY, no conversion takes place. +func_to_tool_file () +{ + $debug_cmd + + case ,$2, in + *,"$to_tool_file_cmd",*) + func_to_tool_file_result=$1 + ;; + *) + $to_tool_file_cmd "$1" + func_to_tool_file_result=$func_to_host_file_result + ;; + esac +} +# end func_to_tool_file + + +# func_convert_file_noop ARG +# Copy ARG to func_to_host_file_result. +func_convert_file_noop () +{ + func_to_host_file_result=$1 +} +# end func_convert_file_noop + + +# func_convert_file_msys_to_w32 ARG +# Convert file name ARG from (mingw) MSYS to (mingw) w32 format; automatic +# conversion to w32 is not available inside the cwrapper. Returns result in +# func_to_host_file_result. +func_convert_file_msys_to_w32 () +{ + $debug_cmd + + func_to_host_file_result=$1 + if test -n "$1"; then + func_convert_core_msys_to_w32 "$1" + func_to_host_file_result=$func_convert_core_msys_to_w32_result + fi + func_convert_file_check "$1" "$func_to_host_file_result" +} +# end func_convert_file_msys_to_w32 + + +# func_convert_file_cygwin_to_w32 ARG +# Convert file name ARG from Cygwin to w32 format. Returns result in +# func_to_host_file_result. +func_convert_file_cygwin_to_w32 () +{ + $debug_cmd + + func_to_host_file_result=$1 + if test -n "$1"; then + # because $build is cygwin, we call "the" cygpath in $PATH; no need to use + # LT_CYGPATH in this case. + func_to_host_file_result=`cygpath -m "$1"` + fi + func_convert_file_check "$1" "$func_to_host_file_result" +} +# end func_convert_file_cygwin_to_w32 + + +# func_convert_file_nix_to_w32 ARG +# Convert file name ARG from *nix to w32 format. Requires a wine environment +# and a working winepath. Returns result in func_to_host_file_result. +func_convert_file_nix_to_w32 () +{ + $debug_cmd + + func_to_host_file_result=$1 + if test -n "$1"; then + func_convert_core_file_wine_to_w32 "$1" + func_to_host_file_result=$func_convert_core_file_wine_to_w32_result + fi + func_convert_file_check "$1" "$func_to_host_file_result" +} +# end func_convert_file_nix_to_w32 + + +# func_convert_file_msys_to_cygwin ARG +# Convert file name ARG from MSYS to Cygwin format. Requires LT_CYGPATH set. +# Returns result in func_to_host_file_result. +func_convert_file_msys_to_cygwin () +{ + $debug_cmd + + func_to_host_file_result=$1 + if test -n "$1"; then + func_convert_core_msys_to_w32 "$1" + func_cygpath -u "$func_convert_core_msys_to_w32_result" + func_to_host_file_result=$func_cygpath_result + fi + func_convert_file_check "$1" "$func_to_host_file_result" +} +# end func_convert_file_msys_to_cygwin + + +# func_convert_file_nix_to_cygwin ARG +# Convert file name ARG from *nix to Cygwin format. Requires Cygwin installed +# in a wine environment, working winepath, and LT_CYGPATH set. Returns result +# in func_to_host_file_result. +func_convert_file_nix_to_cygwin () +{ + $debug_cmd + + func_to_host_file_result=$1 + if test -n "$1"; then + # convert from *nix to w32, then use cygpath to convert from w32 to cygwin. + func_convert_core_file_wine_to_w32 "$1" + func_cygpath -u "$func_convert_core_file_wine_to_w32_result" + func_to_host_file_result=$func_cygpath_result + fi + func_convert_file_check "$1" "$func_to_host_file_result" +} +# end func_convert_file_nix_to_cygwin + + +############################################# +# $build to $host PATH CONVERSION FUNCTIONS # +############################################# +# invoked via '$to_host_path_cmd ARG' +# +# In each case, ARG is the path to be converted from $build to $host format. +# The result will be available in $func_to_host_path_result. +# +# Path separators are also converted from $build format to $host format. If +# ARG begins or ends with a path separator character, it is preserved (but +# converted to $host format) on output. +# +# All path conversion functions are named using the following convention: +# file name conversion function : func_convert_file_X_to_Y () +# path conversion function : func_convert_path_X_to_Y () +# where, for any given $build/$host combination the 'X_to_Y' value is the +# same. If conversion functions are added for new $build/$host combinations, +# the two new functions must follow this pattern, or func_init_to_host_path_cmd +# will break. + + +# func_init_to_host_path_cmd +# Ensures that function "pointer" variable $to_host_path_cmd is set to the +# appropriate value, based on the value of $to_host_file_cmd. +to_host_path_cmd= +func_init_to_host_path_cmd () +{ + $debug_cmd + + if test -z "$to_host_path_cmd"; then + func_stripname 'func_convert_file_' '' "$to_host_file_cmd" + to_host_path_cmd=func_convert_path_$func_stripname_result + fi +} + + +# func_to_host_path ARG +# Converts the path ARG from $build format to $host format. Return result +# in func_to_host_path_result. +func_to_host_path () +{ + $debug_cmd + + func_init_to_host_path_cmd + $to_host_path_cmd "$1" +} +# end func_to_host_path + + +# func_convert_path_noop ARG +# Copy ARG to func_to_host_path_result. +func_convert_path_noop () +{ + func_to_host_path_result=$1 +} +# end func_convert_path_noop + + +# func_convert_path_msys_to_w32 ARG +# Convert path ARG from (mingw) MSYS to (mingw) w32 format; automatic +# conversion to w32 is not available inside the cwrapper. Returns result in +# func_to_host_path_result. +func_convert_path_msys_to_w32 () +{ + $debug_cmd + + func_to_host_path_result=$1 + if test -n "$1"; then + # Remove leading and trailing path separator characters from ARG. MSYS + # behavior is inconsistent here; cygpath turns them into '.;' and ';.'; + # and winepath ignores them completely. + func_stripname : : "$1" + func_to_host_path_tmp1=$func_stripname_result + func_convert_core_msys_to_w32 "$func_to_host_path_tmp1" + func_to_host_path_result=$func_convert_core_msys_to_w32_result + func_convert_path_check : ";" \ + "$func_to_host_path_tmp1" "$func_to_host_path_result" + func_convert_path_front_back_pathsep ":*" "*:" ";" "$1" + fi +} +# end func_convert_path_msys_to_w32 + + +# func_convert_path_cygwin_to_w32 ARG +# Convert path ARG from Cygwin to w32 format. Returns result in +# func_to_host_file_result. +func_convert_path_cygwin_to_w32 () +{ + $debug_cmd + + func_to_host_path_result=$1 + if test -n "$1"; then + # See func_convert_path_msys_to_w32: + func_stripname : : "$1" + func_to_host_path_tmp1=$func_stripname_result + func_to_host_path_result=`cygpath -m -p "$func_to_host_path_tmp1"` + func_convert_path_check : ";" \ + "$func_to_host_path_tmp1" "$func_to_host_path_result" + func_convert_path_front_back_pathsep ":*" "*:" ";" "$1" + fi +} +# end func_convert_path_cygwin_to_w32 + + +# func_convert_path_nix_to_w32 ARG +# Convert path ARG from *nix to w32 format. Requires a wine environment and +# a working winepath. Returns result in func_to_host_file_result. +func_convert_path_nix_to_w32 () +{ + $debug_cmd + + func_to_host_path_result=$1 + if test -n "$1"; then + # See func_convert_path_msys_to_w32: + func_stripname : : "$1" + func_to_host_path_tmp1=$func_stripname_result + func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1" + func_to_host_path_result=$func_convert_core_path_wine_to_w32_result + func_convert_path_check : ";" \ + "$func_to_host_path_tmp1" "$func_to_host_path_result" + func_convert_path_front_back_pathsep ":*" "*:" ";" "$1" + fi +} +# end func_convert_path_nix_to_w32 + + +# func_convert_path_msys_to_cygwin ARG +# Convert path ARG from MSYS to Cygwin format. Requires LT_CYGPATH set. +# Returns result in func_to_host_file_result. +func_convert_path_msys_to_cygwin () +{ + $debug_cmd + + func_to_host_path_result=$1 + if test -n "$1"; then + # See func_convert_path_msys_to_w32: + func_stripname : : "$1" + func_to_host_path_tmp1=$func_stripname_result + func_convert_core_msys_to_w32 "$func_to_host_path_tmp1" + func_cygpath -u -p "$func_convert_core_msys_to_w32_result" + func_to_host_path_result=$func_cygpath_result + func_convert_path_check : : \ + "$func_to_host_path_tmp1" "$func_to_host_path_result" + func_convert_path_front_back_pathsep ":*" "*:" : "$1" + fi +} +# end func_convert_path_msys_to_cygwin + + +# func_convert_path_nix_to_cygwin ARG +# Convert path ARG from *nix to Cygwin format. Requires Cygwin installed in a +# a wine environment, working winepath, and LT_CYGPATH set. Returns result in +# func_to_host_file_result. +func_convert_path_nix_to_cygwin () +{ + $debug_cmd + + func_to_host_path_result=$1 + if test -n "$1"; then + # Remove leading and trailing path separator characters from + # ARG. msys behavior is inconsistent here, cygpath turns them + # into '.;' and ';.', and winepath ignores them completely. + func_stripname : : "$1" + func_to_host_path_tmp1=$func_stripname_result + func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1" + func_cygpath -u -p "$func_convert_core_path_wine_to_w32_result" + func_to_host_path_result=$func_cygpath_result + func_convert_path_check : : \ + "$func_to_host_path_tmp1" "$func_to_host_path_result" + func_convert_path_front_back_pathsep ":*" "*:" : "$1" + fi +} +# end func_convert_path_nix_to_cygwin + + +# func_dll_def_p FILE +# True iff FILE is a Windows DLL '.def' file. +# Keep in sync with _LT_DLL_DEF_P in libtool.m4 +func_dll_def_p () +{ + $debug_cmd + + func_dll_def_p_tmp=`$SED -n \ + -e 's/^[ ]*//' \ + -e '/^\(;.*\)*$/d' \ + -e 's/^\(EXPORTS\|LIBRARY\)\([ ].*\)*$/DEF/p' \ + -e q \ + "$1"` + test DEF = "$func_dll_def_p_tmp" +} + + +# func_mode_compile arg... +func_mode_compile () +{ + $debug_cmd + + # Get the compilation command and the source file. + base_compile= + srcfile=$nonopt # always keep a non-empty value in "srcfile" + suppress_opt=yes + suppress_output= + arg_mode=normal + libobj= + later= + pie_flag= + + for arg + do + case $arg_mode in + arg ) + # do not "continue". Instead, add this to base_compile + lastarg=$arg + arg_mode=normal + ;; + + target ) + libobj=$arg + arg_mode=normal + continue + ;; + + normal ) + # Accept any command-line options. + case $arg in + -o) + test -n "$libobj" && \ + func_fatal_error "you cannot specify '-o' more than once" + arg_mode=target + continue + ;; + + -pie | -fpie | -fPIE) + func_append pie_flag " $arg" + continue + ;; + + -shared | -static | -prefer-pic | -prefer-non-pic) + func_append later " $arg" + continue + ;; + + -no-suppress) + suppress_opt=no + continue + ;; + + -Xcompiler) + arg_mode=arg # the next one goes into the "base_compile" arg list + continue # The current "srcfile" will either be retained or + ;; # replaced later. I would guess that would be a bug. + + -Wc,*) + func_stripname '-Wc,' '' "$arg" + args=$func_stripname_result + lastarg= + save_ifs=$IFS; IFS=, + for arg in $args; do + IFS=$save_ifs + func_append_quoted lastarg "$arg" + done + IFS=$save_ifs + func_stripname ' ' '' "$lastarg" + lastarg=$func_stripname_result + + # Add the arguments to base_compile. + func_append base_compile " $lastarg" + continue + ;; + + *) + # Accept the current argument as the source file. + # The previous "srcfile" becomes the current argument. + # + lastarg=$srcfile + srcfile=$arg + ;; + esac # case $arg + ;; + esac # case $arg_mode + + # Aesthetically quote the previous argument. + func_append_quoted base_compile "$lastarg" + done # for arg + + case $arg_mode in + arg) + func_fatal_error "you must specify an argument for -Xcompile" + ;; + target) + func_fatal_error "you must specify a target with '-o'" + ;; + *) + # Get the name of the library object. + test -z "$libobj" && { + func_basename "$srcfile" + libobj=$func_basename_result + } + ;; + esac + + # Recognize several different file suffixes. + # If the user specifies -o file.o, it is replaced with file.lo + case $libobj in + *.[cCFSifmso] | \ + *.ada | *.adb | *.ads | *.asm | \ + *.c++ | *.cc | *.ii | *.class | *.cpp | *.cxx | \ + *.[fF][09]? | *.for | *.java | *.go | *.obj | *.sx | *.cu | *.cup) + func_xform "$libobj" + libobj=$func_xform_result + ;; + esac + + case $libobj in + *.lo) func_lo2o "$libobj"; obj=$func_lo2o_result ;; + *) + func_fatal_error "cannot determine name of library object from '$libobj'" + ;; + esac + + func_infer_tag $base_compile + + for arg in $later; do + case $arg in + -shared) + test yes = "$build_libtool_libs" \ + || func_fatal_configuration "cannot build a shared library" + build_old_libs=no + continue + ;; + + -static) + build_libtool_libs=no + build_old_libs=yes + continue + ;; + + -prefer-pic) + pic_mode=yes + continue + ;; + + -prefer-non-pic) + pic_mode=no + continue + ;; + esac + done + + func_quote_for_eval "$libobj" + test "X$libobj" != "X$func_quote_for_eval_result" \ + && $ECHO "X$libobj" | $GREP '[]~#^*{};<>?"'"'"' &()|`$[]' \ + && func_warning "libobj name '$libobj' may not contain shell special characters." + func_dirname_and_basename "$obj" "/" "" + objname=$func_basename_result + xdir=$func_dirname_result + lobj=$xdir$objdir/$objname + + test -z "$base_compile" && \ + func_fatal_help "you must specify a compilation command" + + # Delete any leftover library objects. + if test yes = "$build_old_libs"; then + removelist="$obj $lobj $libobj ${libobj}T" + else + removelist="$lobj $libobj ${libobj}T" + fi + + # On Cygwin there's no "real" PIC flag so we must build both object types + case $host_os in + cygwin* | mingw* | pw32* | os2* | cegcc*) + pic_mode=default + ;; + esac + if test no = "$pic_mode" && test pass_all != "$deplibs_check_method"; then + # non-PIC code in shared libraries is not supported + pic_mode=default + fi + + # Calculate the filename of the output object if compiler does + # not support -o with -c + if test no = "$compiler_c_o"; then + output_obj=`$ECHO "$srcfile" | $SED 's%^.*/%%; s%\.[^.]*$%%'`.$objext + lockfile=$output_obj.lock + else + output_obj= + need_locks=no + lockfile= + fi + + # Lock this critical section if it is needed + # We use this script file to make the link, it avoids creating a new file + if test yes = "$need_locks"; then + until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do + func_echo "Waiting for $lockfile to be removed" + sleep 2 + done + elif test warn = "$need_locks"; then + if test -f "$lockfile"; then + $ECHO "\ +*** ERROR, $lockfile exists and contains: +`cat $lockfile 2>/dev/null` + +This indicates that another process is trying to use the same +temporary object file, and libtool could not work around it because +your compiler does not support '-c' and '-o' together. If you +repeat this compilation, it may succeed, by chance, but you had better +avoid parallel builds (make -j) in this platform, or get a better +compiler." + + $opt_dry_run || $RM $removelist + exit $EXIT_FAILURE + fi + func_append removelist " $output_obj" + $ECHO "$srcfile" > "$lockfile" + fi + + $opt_dry_run || $RM $removelist + func_append removelist " $lockfile" + trap '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE' 1 2 15 + + func_to_tool_file "$srcfile" func_convert_file_msys_to_w32 + srcfile=$func_to_tool_file_result + func_quote_for_eval "$srcfile" + qsrcfile=$func_quote_for_eval_result + + # Only build a PIC object if we are building libtool libraries. + if test yes = "$build_libtool_libs"; then + # Without this assignment, base_compile gets emptied. + fbsd_hideous_sh_bug=$base_compile + + if test no != "$pic_mode"; then + command="$base_compile $qsrcfile $pic_flag" + else + # Don't build PIC code + command="$base_compile $qsrcfile" + fi + + func_mkdir_p "$xdir$objdir" + + if test -z "$output_obj"; then + # Place PIC objects in $objdir + func_append command " -o $lobj" + fi + + func_show_eval_locale "$command" \ + 'test -n "$output_obj" && $RM $removelist; exit $EXIT_FAILURE' + + if test warn = "$need_locks" && + test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then + $ECHO "\ +*** ERROR, $lockfile contains: +`cat $lockfile 2>/dev/null` + +but it should contain: +$srcfile + +This indicates that another process is trying to use the same +temporary object file, and libtool could not work around it because +your compiler does not support '-c' and '-o' together. If you +repeat this compilation, it may succeed, by chance, but you had better +avoid parallel builds (make -j) in this platform, or get a better +compiler." + + $opt_dry_run || $RM $removelist + exit $EXIT_FAILURE + fi + + # Just move the object if needed, then go on to compile the next one + if test -n "$output_obj" && test "X$output_obj" != "X$lobj"; then + func_show_eval '$MV "$output_obj" "$lobj"' \ + 'error=$?; $opt_dry_run || $RM $removelist; exit $error' + fi + + # Allow error messages only from the first compilation. + if test yes = "$suppress_opt"; then + suppress_output=' >/dev/null 2>&1' + fi + fi + + # Only build a position-dependent object if we build old libraries. + if test yes = "$build_old_libs"; then + if test yes != "$pic_mode"; then + # Don't build PIC code + command="$base_compile $qsrcfile$pie_flag" + else + command="$base_compile $qsrcfile $pic_flag" + fi + if test yes = "$compiler_c_o"; then + func_append command " -o $obj" + fi + + # Suppress compiler output if we already did a PIC compilation. + func_append command "$suppress_output" + func_show_eval_locale "$command" \ + '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE' + + if test warn = "$need_locks" && + test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then + $ECHO "\ +*** ERROR, $lockfile contains: +`cat $lockfile 2>/dev/null` + +but it should contain: +$srcfile + +This indicates that another process is trying to use the same +temporary object file, and libtool could not work around it because +your compiler does not support '-c' and '-o' together. If you +repeat this compilation, it may succeed, by chance, but you had better +avoid parallel builds (make -j) in this platform, or get a better +compiler." + + $opt_dry_run || $RM $removelist + exit $EXIT_FAILURE + fi + + # Just move the object if needed + if test -n "$output_obj" && test "X$output_obj" != "X$obj"; then + func_show_eval '$MV "$output_obj" "$obj"' \ + 'error=$?; $opt_dry_run || $RM $removelist; exit $error' + fi + fi + + $opt_dry_run || { + func_write_libtool_object "$libobj" "$objdir/$objname" "$objname" + + # Unlock the critical section if it was locked + if test no != "$need_locks"; then + removelist=$lockfile + $RM "$lockfile" + fi + } + + exit $EXIT_SUCCESS +} + +$opt_help || { + test compile = "$opt_mode" && func_mode_compile ${1+"$@"} +} + +func_mode_help () +{ + # We need to display help for each of the modes. + case $opt_mode in + "") + # Generic help is extracted from the usage comments + # at the start of this file. + func_help + ;; + + clean) + $ECHO \ +"Usage: $progname [OPTION]... --mode=clean RM [RM-OPTION]... FILE... + +Remove files from the build directory. + +RM is the name of the program to use to delete files associated with each FILE +(typically '/bin/rm'). RM-OPTIONS are options (such as '-f') to be passed +to RM. + +If FILE is a libtool library, object or program, all the files associated +with it are deleted. Otherwise, only FILE itself is deleted using RM." + ;; + + compile) + $ECHO \ +"Usage: $progname [OPTION]... --mode=compile COMPILE-COMMAND... SOURCEFILE + +Compile a source file into a libtool library object. + +This mode accepts the following additional options: + + -o OUTPUT-FILE set the output file name to OUTPUT-FILE + -no-suppress do not suppress compiler output for multiple passes + -prefer-pic try to build PIC objects only + -prefer-non-pic try to build non-PIC objects only + -shared do not build a '.o' file suitable for static linking + -static only build a '.o' file suitable for static linking + -Wc,FLAG pass FLAG directly to the compiler + +COMPILE-COMMAND is a command to be used in creating a 'standard' object file +from the given SOURCEFILE. + +The output file name is determined by removing the directory component from +SOURCEFILE, then substituting the C source code suffix '.c' with the +library object suffix, '.lo'." + ;; + + execute) + $ECHO \ +"Usage: $progname [OPTION]... --mode=execute COMMAND [ARGS]... + +Automatically set library path, then run a program. + +This mode accepts the following additional options: + + -dlopen FILE add the directory containing FILE to the library path + +This mode sets the library path environment variable according to '-dlopen' +flags. + +If any of the ARGS are libtool executable wrappers, then they are translated +into their corresponding uninstalled binary, and any of their required library +directories are added to the library path. + +Then, COMMAND is executed, with ARGS as arguments." + ;; + + finish) + $ECHO \ +"Usage: $progname [OPTION]... --mode=finish [LIBDIR]... + +Complete the installation of libtool libraries. + +Each LIBDIR is a directory that contains libtool libraries. + +The commands that this mode executes may require superuser privileges. Use +the '--dry-run' option if you just want to see what would be executed." + ;; + + install) + $ECHO \ +"Usage: $progname [OPTION]... --mode=install INSTALL-COMMAND... + +Install executables or libraries. + +INSTALL-COMMAND is the installation command. The first component should be +either the 'install' or 'cp' program. + +The following components of INSTALL-COMMAND are treated specially: + + -inst-prefix-dir PREFIX-DIR Use PREFIX-DIR as a staging area for installation + +The rest of the components are interpreted as arguments to that command (only +BSD-compatible install options are recognized)." + ;; + + link) + $ECHO \ +"Usage: $progname [OPTION]... --mode=link LINK-COMMAND... + +Link object files or libraries together to form another library, or to +create an executable program. + +LINK-COMMAND is a command using the C compiler that you would use to create +a program from several object files. + +The following components of LINK-COMMAND are treated specially: + + -all-static do not do any dynamic linking at all + -avoid-version do not add a version suffix if possible + -bindir BINDIR specify path to binaries directory (for systems where + libraries must be found in the PATH setting at runtime) + -dlopen FILE '-dlpreopen' FILE if it cannot be dlopened at runtime + -dlpreopen FILE link in FILE and add its symbols to lt_preloaded_symbols + -export-dynamic allow symbols from OUTPUT-FILE to be resolved with dlsym(3) + -export-symbols SYMFILE + try to export only the symbols listed in SYMFILE + -export-symbols-regex REGEX + try to export only the symbols matching REGEX + -LLIBDIR search LIBDIR for required installed libraries + -lNAME OUTPUT-FILE requires the installed library libNAME + -module build a library that can dlopened + -no-fast-install disable the fast-install mode + -no-install link a not-installable executable + -no-undefined declare that a library does not refer to external symbols + -o OUTPUT-FILE create OUTPUT-FILE from the specified objects + -objectlist FILE use a list of object files found in FILE to specify objects + -os2dllname NAME force a short DLL name on OS/2 (no effect on other OSes) + -precious-files-regex REGEX + don't remove output files matching REGEX + -release RELEASE specify package release information + -rpath LIBDIR the created library will eventually be installed in LIBDIR + -R[ ]LIBDIR add LIBDIR to the runtime path of programs and libraries + -shared only do dynamic linking of libtool libraries + -shrext SUFFIX override the standard shared library file extension + -static do not do any dynamic linking of uninstalled libtool libraries + -static-libtool-libs + do not do any dynamic linking of libtool libraries + -version-info CURRENT[:REVISION[:AGE]] + specify library version info [each variable defaults to 0] + -weak LIBNAME declare that the target provides the LIBNAME interface + -Wc,FLAG + -Xcompiler FLAG pass linker-specific FLAG directly to the compiler + -Wl,FLAG + -Xlinker FLAG pass linker-specific FLAG directly to the linker + -XCClinker FLAG pass link-specific FLAG to the compiler driver (CC) + +All other options (arguments beginning with '-') are ignored. + +Every other argument is treated as a filename. Files ending in '.la' are +treated as uninstalled libtool libraries, other files are standard or library +object files. + +If the OUTPUT-FILE ends in '.la', then a libtool library is created, +only library objects ('.lo' files) may be specified, and '-rpath' is +required, except when creating a convenience library. + +If OUTPUT-FILE ends in '.a' or '.lib', then a standard library is created +using 'ar' and 'ranlib', or on Windows using 'lib'. + +If OUTPUT-FILE ends in '.lo' or '.$objext', then a reloadable object file +is created, otherwise an executable program is created." + ;; + + uninstall) + $ECHO \ +"Usage: $progname [OPTION]... --mode=uninstall RM [RM-OPTION]... FILE... + +Remove libraries from an installation directory. + +RM is the name of the program to use to delete files associated with each FILE +(typically '/bin/rm'). RM-OPTIONS are options (such as '-f') to be passed +to RM. + +If FILE is a libtool library, all the files associated with it are deleted. +Otherwise, only FILE itself is deleted using RM." + ;; + + *) + func_fatal_help "invalid operation mode '$opt_mode'" + ;; + esac + + echo + $ECHO "Try '$progname --help' for more information about other modes." +} + +# Now that we've collected a possible --mode arg, show help if necessary +if $opt_help; then + if test : = "$opt_help"; then + func_mode_help + else + { + func_help noexit + for opt_mode in compile link execute install finish uninstall clean; do + func_mode_help + done + } | $SED -n '1p; 2,$s/^Usage:/ or: /p' + { + func_help noexit + for opt_mode in compile link execute install finish uninstall clean; do + echo + func_mode_help + done + } | + $SED '1d + /^When reporting/,/^Report/{ + H + d + } + $x + /information about other modes/d + /more detailed .*MODE/d + s/^Usage:.*--mode=\([^ ]*\) .*/Description of \1 mode:/' + fi + exit $? +fi + + +# func_mode_execute arg... +func_mode_execute () +{ + $debug_cmd + + # The first argument is the command name. + cmd=$nonopt + test -z "$cmd" && \ + func_fatal_help "you must specify a COMMAND" + + # Handle -dlopen flags immediately. + for file in $opt_dlopen; do + test -f "$file" \ + || func_fatal_help "'$file' is not a file" + + dir= + case $file in + *.la) + func_resolve_sysroot "$file" + file=$func_resolve_sysroot_result + + # Check to see that this really is a libtool archive. + func_lalib_unsafe_p "$file" \ + || func_fatal_help "'$lib' is not a valid libtool archive" + + # Read the libtool library. + dlname= + library_names= + func_source "$file" + + # Skip this library if it cannot be dlopened. + if test -z "$dlname"; then + # Warn if it was a shared library. + test -n "$library_names" && \ + func_warning "'$file' was not linked with '-export-dynamic'" + continue + fi + + func_dirname "$file" "" "." + dir=$func_dirname_result + + if test -f "$dir/$objdir/$dlname"; then + func_append dir "/$objdir" + else + if test ! -f "$dir/$dlname"; then + func_fatal_error "cannot find '$dlname' in '$dir' or '$dir/$objdir'" + fi + fi + ;; + + *.lo) + # Just add the directory containing the .lo file. + func_dirname "$file" "" "." + dir=$func_dirname_result + ;; + + *) + func_warning "'-dlopen' is ignored for non-libtool libraries and objects" + continue + ;; + esac + + # Get the absolute pathname. + absdir=`cd "$dir" && pwd` + test -n "$absdir" && dir=$absdir + + # Now add the directory to shlibpath_var. + if eval "test -z \"\$$shlibpath_var\""; then + eval "$shlibpath_var=\"\$dir\"" + else + eval "$shlibpath_var=\"\$dir:\$$shlibpath_var\"" + fi + done + + # This variable tells wrapper scripts just to set shlibpath_var + # rather than running their programs. + libtool_execute_magic=$magic + + # Check if any of the arguments is a wrapper script. + args= + for file + do + case $file in + -* | *.la | *.lo ) ;; + *) + # Do a test to see if this is really a libtool program. + if func_ltwrapper_script_p "$file"; then + func_source "$file" + # Transform arg to wrapped name. + file=$progdir/$program + elif func_ltwrapper_executable_p "$file"; then + func_ltwrapper_scriptname "$file" + func_source "$func_ltwrapper_scriptname_result" + # Transform arg to wrapped name. + file=$progdir/$program + fi + ;; + esac + # Quote arguments (to preserve shell metacharacters). + func_append_quoted args "$file" + done + + if $opt_dry_run; then + # Display what would be done. + if test -n "$shlibpath_var"; then + eval "\$ECHO \"\$shlibpath_var=\$$shlibpath_var\"" + echo "export $shlibpath_var" + fi + $ECHO "$cmd$args" + exit $EXIT_SUCCESS + else + if test -n "$shlibpath_var"; then + # Export the shlibpath_var. + eval "export $shlibpath_var" + fi + + # Restore saved environment variables + for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES + do + eval "if test \"\${save_$lt_var+set}\" = set; then + $lt_var=\$save_$lt_var; export $lt_var + else + $lt_unset $lt_var + fi" + done + + # Now prepare to actually exec the command. + exec_cmd=\$cmd$args + fi +} + +test execute = "$opt_mode" && func_mode_execute ${1+"$@"} + + +# func_mode_finish arg... +func_mode_finish () +{ + $debug_cmd + + libs= + libdirs= + admincmds= + + for opt in "$nonopt" ${1+"$@"} + do + if test -d "$opt"; then + func_append libdirs " $opt" + + elif test -f "$opt"; then + if func_lalib_unsafe_p "$opt"; then + func_append libs " $opt" + else + func_warning "'$opt' is not a valid libtool archive" + fi + + else + func_fatal_error "invalid argument '$opt'" + fi + done + + if test -n "$libs"; then + if test -n "$lt_sysroot"; then + sysroot_regex=`$ECHO "$lt_sysroot" | $SED "$sed_make_literal_regex"` + sysroot_cmd="s/\([ ']\)$sysroot_regex/\1/g;" + else + sysroot_cmd= + fi + + # Remove sysroot references + if $opt_dry_run; then + for lib in $libs; do + echo "removing references to $lt_sysroot and '=' prefixes from $lib" + done + else + tmpdir=`func_mktempdir` + for lib in $libs; do + $SED -e "$sysroot_cmd s/\([ ']-[LR]\)=/\1/g; s/\([ ']\)=/\1/g" $lib \ + > $tmpdir/tmp-la + mv -f $tmpdir/tmp-la $lib + done + ${RM}r "$tmpdir" + fi + fi + + if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then + for libdir in $libdirs; do + if test -n "$finish_cmds"; then + # Do each command in the finish commands. + func_execute_cmds "$finish_cmds" 'admincmds="$admincmds +'"$cmd"'"' + fi + if test -n "$finish_eval"; then + # Do the single finish_eval. + eval cmds=\"$finish_eval\" + $opt_dry_run || eval "$cmds" || func_append admincmds " + $cmds" + fi + done + fi + + # Exit here if they wanted silent mode. + $opt_quiet && exit $EXIT_SUCCESS + + if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then + echo "----------------------------------------------------------------------" + echo "Libraries have been installed in:" + for libdir in $libdirs; do + $ECHO " $libdir" + done + echo + echo "If you ever happen to want to link against installed libraries" + echo "in a given directory, LIBDIR, you must either use libtool, and" + echo "specify the full pathname of the library, or use the '-LLIBDIR'" + echo "flag during linking and do at least one of the following:" + if test -n "$shlibpath_var"; then + echo " - add LIBDIR to the '$shlibpath_var' environment variable" + echo " during execution" + fi + if test -n "$runpath_var"; then + echo " - add LIBDIR to the '$runpath_var' environment variable" + echo " during linking" + fi + if test -n "$hardcode_libdir_flag_spec"; then + libdir=LIBDIR + eval flag=\"$hardcode_libdir_flag_spec\" + + $ECHO " - use the '$flag' linker flag" + fi + if test -n "$admincmds"; then + $ECHO " - have your system administrator run these commands:$admincmds" + fi + if test -f /etc/ld.so.conf; then + echo " - have your system administrator add LIBDIR to '/etc/ld.so.conf'" + fi + echo + + echo "See any operating system documentation about shared libraries for" + case $host in + solaris2.[6789]|solaris2.1[0-9]) + echo "more information, such as the ld(1), crle(1) and ld.so(8) manual" + echo "pages." + ;; + *) + echo "more information, such as the ld(1) and ld.so(8) manual pages." + ;; + esac + echo "----------------------------------------------------------------------" + fi + exit $EXIT_SUCCESS +} + +test finish = "$opt_mode" && func_mode_finish ${1+"$@"} + + +# func_mode_install arg... +func_mode_install () +{ + $debug_cmd + + # There may be an optional sh(1) argument at the beginning of + # install_prog (especially on Windows NT). + if test "$SHELL" = "$nonopt" || test /bin/sh = "$nonopt" || + # Allow the use of GNU shtool's install command. + case $nonopt in *shtool*) :;; *) false;; esac + then + # Aesthetically quote it. + func_quote_for_eval "$nonopt" + install_prog="$func_quote_for_eval_result " + arg=$1 + shift + else + install_prog= + arg=$nonopt + fi + + # The real first argument should be the name of the installation program. + # Aesthetically quote it. + func_quote_for_eval "$arg" + func_append install_prog "$func_quote_for_eval_result" + install_shared_prog=$install_prog + case " $install_prog " in + *[\\\ /]cp\ *) install_cp=: ;; + *) install_cp=false ;; + esac + + # We need to accept at least all the BSD install flags. + dest= + files= + opts= + prev= + install_type= + isdir=false + stripme= + no_mode=: + for arg + do + arg2= + if test -n "$dest"; then + func_append files " $dest" + dest=$arg + continue + fi + + case $arg in + -d) isdir=: ;; + -f) + if $install_cp; then :; else + prev=$arg + fi + ;; + -g | -m | -o) + prev=$arg + ;; + -s) + stripme=" -s" + continue + ;; + -*) + ;; + *) + # If the previous option needed an argument, then skip it. + if test -n "$prev"; then + if test X-m = "X$prev" && test -n "$install_override_mode"; then + arg2=$install_override_mode + no_mode=false + fi + prev= + else + dest=$arg + continue + fi + ;; + esac + + # Aesthetically quote the argument. + func_quote_for_eval "$arg" + func_append install_prog " $func_quote_for_eval_result" + if test -n "$arg2"; then + func_quote_for_eval "$arg2" + fi + func_append install_shared_prog " $func_quote_for_eval_result" + done + + test -z "$install_prog" && \ + func_fatal_help "you must specify an install program" + + test -n "$prev" && \ + func_fatal_help "the '$prev' option requires an argument" + + if test -n "$install_override_mode" && $no_mode; then + if $install_cp; then :; else + func_quote_for_eval "$install_override_mode" + func_append install_shared_prog " -m $func_quote_for_eval_result" + fi + fi + + if test -z "$files"; then + if test -z "$dest"; then + func_fatal_help "no file or destination specified" + else + func_fatal_help "you must specify a destination" + fi + fi + + # Strip any trailing slash from the destination. + func_stripname '' '/' "$dest" + dest=$func_stripname_result + + # Check to see that the destination is a directory. + test -d "$dest" && isdir=: + if $isdir; then + destdir=$dest + destname= + else + func_dirname_and_basename "$dest" "" "." + destdir=$func_dirname_result + destname=$func_basename_result + + # Not a directory, so check to see that there is only one file specified. + set dummy $files; shift + test "$#" -gt 1 && \ + func_fatal_help "'$dest' is not a directory" + fi + case $destdir in + [\\/]* | [A-Za-z]:[\\/]*) ;; + *) + for file in $files; do + case $file in + *.lo) ;; + *) + func_fatal_help "'$destdir' must be an absolute directory name" + ;; + esac + done + ;; + esac + + # This variable tells wrapper scripts just to set variables rather + # than running their programs. + libtool_install_magic=$magic + + staticlibs= + future_libdirs= + current_libdirs= + for file in $files; do + + # Do each installation. + case $file in + *.$libext) + # Do the static libraries later. + func_append staticlibs " $file" + ;; + + *.la) + func_resolve_sysroot "$file" + file=$func_resolve_sysroot_result + + # Check to see that this really is a libtool archive. + func_lalib_unsafe_p "$file" \ + || func_fatal_help "'$file' is not a valid libtool archive" + + library_names= + old_library= + relink_command= + func_source "$file" + + # Add the libdir to current_libdirs if it is the destination. + if test "X$destdir" = "X$libdir"; then + case "$current_libdirs " in + *" $libdir "*) ;; + *) func_append current_libdirs " $libdir" ;; + esac + else + # Note the libdir as a future libdir. + case "$future_libdirs " in + *" $libdir "*) ;; + *) func_append future_libdirs " $libdir" ;; + esac + fi + + func_dirname "$file" "/" "" + dir=$func_dirname_result + func_append dir "$objdir" + + if test -n "$relink_command"; then + # Determine the prefix the user has applied to our future dir. + inst_prefix_dir=`$ECHO "$destdir" | $SED -e "s%$libdir\$%%"` + + # Don't allow the user to place us outside of our expected + # location b/c this prevents finding dependent libraries that + # are installed to the same prefix. + # At present, this check doesn't affect windows .dll's that + # are installed into $libdir/../bin (currently, that works fine) + # but it's something to keep an eye on. + test "$inst_prefix_dir" = "$destdir" && \ + func_fatal_error "error: cannot install '$file' to a directory not ending in $libdir" + + if test -n "$inst_prefix_dir"; then + # Stick the inst_prefix_dir data into the link command. + relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%-inst-prefix-dir $inst_prefix_dir%"` + else + relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%%"` + fi + + func_warning "relinking '$file'" + func_show_eval "$relink_command" \ + 'func_fatal_error "error: relink '\''$file'\'' with the above command before installing it"' + fi + + # See the names of the shared library. + set dummy $library_names; shift + if test -n "$1"; then + realname=$1 + shift + + srcname=$realname + test -n "$relink_command" && srcname=${realname}T + + # Install the shared library and build the symlinks. + func_show_eval "$install_shared_prog $dir/$srcname $destdir/$realname" \ + 'exit $?' + tstripme=$stripme + case $host_os in + cygwin* | mingw* | pw32* | cegcc*) + case $realname in + *.dll.a) + tstripme= + ;; + esac + ;; + os2*) + case $realname in + *_dll.a) + tstripme= + ;; + esac + ;; + esac + if test -n "$tstripme" && test -n "$striplib"; then + func_show_eval "$striplib $destdir/$realname" 'exit $?' + fi + + if test "$#" -gt 0; then + # Delete the old symlinks, and create new ones. + # Try 'ln -sf' first, because the 'ln' binary might depend on + # the symlink we replace! Solaris /bin/ln does not understand -f, + # so we also need to try rm && ln -s. + for linkname + do + test "$linkname" != "$realname" \ + && func_show_eval "(cd $destdir && { $LN_S -f $realname $linkname || { $RM $linkname && $LN_S $realname $linkname; }; })" + done + fi + + # Do each command in the postinstall commands. + lib=$destdir/$realname + func_execute_cmds "$postinstall_cmds" 'exit $?' + fi + + # Install the pseudo-library for information purposes. + func_basename "$file" + name=$func_basename_result + instname=$dir/${name}i + func_show_eval "$install_prog $instname $destdir/$name" 'exit $?' + + # Maybe install the static library, too. + test -n "$old_library" && func_append staticlibs " $dir/$old_library" + ;; + + *.lo) + # Install (i.e. copy) a libtool object. + + # Figure out destination file name, if it wasn't already specified. + if test -n "$destname"; then + destfile=$destdir/$destname + else + func_basename "$file" + destfile=$func_basename_result + destfile=$destdir/$destfile + fi + + # Deduce the name of the destination old-style object file. + case $destfile in + *.lo) + func_lo2o "$destfile" + staticdest=$func_lo2o_result + ;; + *.$objext) + staticdest=$destfile + destfile= + ;; + *) + func_fatal_help "cannot copy a libtool object to '$destfile'" + ;; + esac + + # Install the libtool object if requested. + test -n "$destfile" && \ + func_show_eval "$install_prog $file $destfile" 'exit $?' + + # Install the old object if enabled. + if test yes = "$build_old_libs"; then + # Deduce the name of the old-style object file. + func_lo2o "$file" + staticobj=$func_lo2o_result + func_show_eval "$install_prog \$staticobj \$staticdest" 'exit $?' + fi + exit $EXIT_SUCCESS + ;; + + *) + # Figure out destination file name, if it wasn't already specified. + if test -n "$destname"; then + destfile=$destdir/$destname + else + func_basename "$file" + destfile=$func_basename_result + destfile=$destdir/$destfile + fi + + # If the file is missing, and there is a .exe on the end, strip it + # because it is most likely a libtool script we actually want to + # install + stripped_ext= + case $file in + *.exe) + if test ! -f "$file"; then + func_stripname '' '.exe' "$file" + file=$func_stripname_result + stripped_ext=.exe + fi + ;; + esac + + # Do a test to see if this is really a libtool program. + case $host in + *cygwin* | *mingw*) + if func_ltwrapper_executable_p "$file"; then + func_ltwrapper_scriptname "$file" + wrapper=$func_ltwrapper_scriptname_result + else + func_stripname '' '.exe' "$file" + wrapper=$func_stripname_result + fi + ;; + *) + wrapper=$file + ;; + esac + if func_ltwrapper_script_p "$wrapper"; then + notinst_deplibs= + relink_command= + + func_source "$wrapper" + + # Check the variables that should have been set. + test -z "$generated_by_libtool_version" && \ + func_fatal_error "invalid libtool wrapper script '$wrapper'" + + finalize=: + for lib in $notinst_deplibs; do + # Check to see that each library is installed. + libdir= + if test -f "$lib"; then + func_source "$lib" + fi + libfile=$libdir/`$ECHO "$lib" | $SED 's%^.*/%%g'` + if test -n "$libdir" && test ! -f "$libfile"; then + func_warning "'$lib' has not been installed in '$libdir'" + finalize=false + fi + done + + relink_command= + func_source "$wrapper" + + outputname= + if test no = "$fast_install" && test -n "$relink_command"; then + $opt_dry_run || { + if $finalize; then + tmpdir=`func_mktempdir` + func_basename "$file$stripped_ext" + file=$func_basename_result + outputname=$tmpdir/$file + # Replace the output file specification. + relink_command=`$ECHO "$relink_command" | $SED 's%@OUTPUT@%'"$outputname"'%g'` + + $opt_quiet || { + func_quote_for_expand "$relink_command" + eval "func_echo $func_quote_for_expand_result" + } + if eval "$relink_command"; then : + else + func_error "error: relink '$file' with the above command before installing it" + $opt_dry_run || ${RM}r "$tmpdir" + continue + fi + file=$outputname + else + func_warning "cannot relink '$file'" + fi + } + else + # Install the binary that we compiled earlier. + file=`$ECHO "$file$stripped_ext" | $SED "s%\([^/]*\)$%$objdir/\1%"` + fi + fi + + # remove .exe since cygwin /usr/bin/install will append another + # one anyway + case $install_prog,$host in + */usr/bin/install*,*cygwin*) + case $file:$destfile in + *.exe:*.exe) + # this is ok + ;; + *.exe:*) + destfile=$destfile.exe + ;; + *:*.exe) + func_stripname '' '.exe' "$destfile" + destfile=$func_stripname_result + ;; + esac + ;; + esac + func_show_eval "$install_prog\$stripme \$file \$destfile" 'exit $?' + $opt_dry_run || if test -n "$outputname"; then + ${RM}r "$tmpdir" + fi + ;; + esac + done + + for file in $staticlibs; do + func_basename "$file" + name=$func_basename_result + + # Set up the ranlib parameters. + oldlib=$destdir/$name + func_to_tool_file "$oldlib" func_convert_file_msys_to_w32 + tool_oldlib=$func_to_tool_file_result + + func_show_eval "$install_prog \$file \$oldlib" 'exit $?' + + if test -n "$stripme" && test -n "$old_striplib"; then + func_show_eval "$old_striplib $tool_oldlib" 'exit $?' + fi + + # Do each command in the postinstall commands. + func_execute_cmds "$old_postinstall_cmds" 'exit $?' + done + + test -n "$future_libdirs" && \ + func_warning "remember to run '$progname --finish$future_libdirs'" + + if test -n "$current_libdirs"; then + # Maybe just do a dry run. + $opt_dry_run && current_libdirs=" -n$current_libdirs" + exec_cmd='$SHELL "$progpath" $preserve_args --finish$current_libdirs' + else + exit $EXIT_SUCCESS + fi +} + +test install = "$opt_mode" && func_mode_install ${1+"$@"} + + +# func_generate_dlsyms outputname originator pic_p +# Extract symbols from dlprefiles and create ${outputname}S.o with +# a dlpreopen symbol table. +func_generate_dlsyms () +{ + $debug_cmd + + my_outputname=$1 + my_originator=$2 + my_pic_p=${3-false} + my_prefix=`$ECHO "$my_originator" | $SED 's%[^a-zA-Z0-9]%_%g'` + my_dlsyms= + + if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then + if test -n "$NM" && test -n "$global_symbol_pipe"; then + my_dlsyms=${my_outputname}S.c + else + func_error "not configured to extract global symbols from dlpreopened files" + fi + fi + + if test -n "$my_dlsyms"; then + case $my_dlsyms in + "") ;; + *.c) + # Discover the nlist of each of the dlfiles. + nlist=$output_objdir/$my_outputname.nm + + func_show_eval "$RM $nlist ${nlist}S ${nlist}T" + + # Parse the name list into a source file. + func_verbose "creating $output_objdir/$my_dlsyms" + + $opt_dry_run || $ECHO > "$output_objdir/$my_dlsyms" "\ +/* $my_dlsyms - symbol resolution table for '$my_outputname' dlsym emulation. */ +/* Generated by $PROGRAM (GNU $PACKAGE) $VERSION */ + +#ifdef __cplusplus +extern \"C\" { +#endif + +#if defined __GNUC__ && (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4)) || (__GNUC__ > 4)) +#pragma GCC diagnostic ignored \"-Wstrict-prototypes\" +#endif + +/* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests. */ +#if defined _WIN32 || defined __CYGWIN__ || defined _WIN32_WCE +/* DATA imports from DLLs on WIN32 can't be const, because runtime + relocations are performed -- see ld's documentation on pseudo-relocs. */ +# define LT_DLSYM_CONST +#elif defined __osf__ +/* This system does not cope well with relocations in const data. */ +# define LT_DLSYM_CONST +#else +# define LT_DLSYM_CONST const +#endif + +#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0) + +/* External symbol declarations for the compiler. */\ +" + + if test yes = "$dlself"; then + func_verbose "generating symbol list for '$output'" + + $opt_dry_run || echo ': @PROGRAM@ ' > "$nlist" + + # Add our own program objects to the symbol list. + progfiles=`$ECHO "$objs$old_deplibs" | $SP2NL | $SED "$lo2o" | $NL2SP` + for progfile in $progfiles; do + func_to_tool_file "$progfile" func_convert_file_msys_to_w32 + func_verbose "extracting global C symbols from '$func_to_tool_file_result'" + $opt_dry_run || eval "$NM $func_to_tool_file_result | $global_symbol_pipe >> '$nlist'" + done + + if test -n "$exclude_expsyms"; then + $opt_dry_run || { + eval '$EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T' + eval '$MV "$nlist"T "$nlist"' + } + fi + + if test -n "$export_symbols_regex"; then + $opt_dry_run || { + eval '$EGREP -e "$export_symbols_regex" "$nlist" > "$nlist"T' + eval '$MV "$nlist"T "$nlist"' + } + fi + + # Prepare the list of exported symbols + if test -z "$export_symbols"; then + export_symbols=$output_objdir/$outputname.exp + $opt_dry_run || { + $RM $export_symbols + eval "$SED -n -e '/^: @PROGRAM@ $/d' -e 's/^.* \(.*\)$/\1/p' "'< "$nlist" > "$export_symbols"' + case $host in + *cygwin* | *mingw* | *cegcc* ) + eval "echo EXPORTS "'> "$output_objdir/$outputname.def"' + eval 'cat "$export_symbols" >> "$output_objdir/$outputname.def"' + ;; + esac + } + else + $opt_dry_run || { + eval "$SED -e 's/\([].[*^$]\)/\\\\\1/g' -e 's/^/ /' -e 's/$/$/'"' < "$export_symbols" > "$output_objdir/$outputname.exp"' + eval '$GREP -f "$output_objdir/$outputname.exp" < "$nlist" > "$nlist"T' + eval '$MV "$nlist"T "$nlist"' + case $host in + *cygwin* | *mingw* | *cegcc* ) + eval "echo EXPORTS "'> "$output_objdir/$outputname.def"' + eval 'cat "$nlist" >> "$output_objdir/$outputname.def"' + ;; + esac + } + fi + fi + + for dlprefile in $dlprefiles; do + func_verbose "extracting global C symbols from '$dlprefile'" + func_basename "$dlprefile" + name=$func_basename_result + case $host in + *cygwin* | *mingw* | *cegcc* ) + # if an import library, we need to obtain dlname + if func_win32_import_lib_p "$dlprefile"; then + func_tr_sh "$dlprefile" + eval "curr_lafile=\$libfile_$func_tr_sh_result" + dlprefile_dlbasename= + if test -n "$curr_lafile" && func_lalib_p "$curr_lafile"; then + # Use subshell, to avoid clobbering current variable values + dlprefile_dlname=`source "$curr_lafile" && echo "$dlname"` + if test -n "$dlprefile_dlname"; then + func_basename "$dlprefile_dlname" + dlprefile_dlbasename=$func_basename_result + else + # no lafile. user explicitly requested -dlpreopen . + $sharedlib_from_linklib_cmd "$dlprefile" + dlprefile_dlbasename=$sharedlib_from_linklib_result + fi + fi + $opt_dry_run || { + if test -n "$dlprefile_dlbasename"; then + eval '$ECHO ": $dlprefile_dlbasename" >> "$nlist"' + else + func_warning "Could not compute DLL name from $name" + eval '$ECHO ": $name " >> "$nlist"' + fi + func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32 + eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe | + $SED -e '/I __imp/d' -e 's/I __nm_/D /;s/_nm__//' >> '$nlist'" + } + else # not an import lib + $opt_dry_run || { + eval '$ECHO ": $name " >> "$nlist"' + func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32 + eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'" + } + fi + ;; + *) + $opt_dry_run || { + eval '$ECHO ": $name " >> "$nlist"' + func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32 + eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'" + } + ;; + esac + done + + $opt_dry_run || { + # Make sure we have at least an empty file. + test -f "$nlist" || : > "$nlist" + + if test -n "$exclude_expsyms"; then + $EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T + $MV "$nlist"T "$nlist" + fi + + # Try sorting and uniquifying the output. + if $GREP -v "^: " < "$nlist" | + if sort -k 3 /dev/null 2>&1; then + sort -k 3 + else + sort +2 + fi | + uniq > "$nlist"S; then + : + else + $GREP -v "^: " < "$nlist" > "$nlist"S + fi + + if test -f "$nlist"S; then + eval "$global_symbol_to_cdecl"' < "$nlist"S >> "$output_objdir/$my_dlsyms"' + else + echo '/* NONE */' >> "$output_objdir/$my_dlsyms" + fi + + func_show_eval '$RM "${nlist}I"' + if test -n "$global_symbol_to_import"; then + eval "$global_symbol_to_import"' < "$nlist"S > "$nlist"I' + fi + + echo >> "$output_objdir/$my_dlsyms" "\ + +/* The mapping between symbol names and symbols. */ +typedef struct { + const char *name; + void *address; +} lt_dlsymlist; +extern LT_DLSYM_CONST lt_dlsymlist +lt_${my_prefix}_LTX_preloaded_symbols[];\ +" + + if test -s "$nlist"I; then + echo >> "$output_objdir/$my_dlsyms" "\ +static void lt_syminit(void) +{ + LT_DLSYM_CONST lt_dlsymlist *symbol = lt_${my_prefix}_LTX_preloaded_symbols; + for (; symbol->name; ++symbol) + {" + $SED 's/.*/ if (STREQ (symbol->name, \"&\")) symbol->address = (void *) \&&;/' < "$nlist"I >> "$output_objdir/$my_dlsyms" + echo >> "$output_objdir/$my_dlsyms" "\ + } +}" + fi + echo >> "$output_objdir/$my_dlsyms" "\ +LT_DLSYM_CONST lt_dlsymlist +lt_${my_prefix}_LTX_preloaded_symbols[] = +{ {\"$my_originator\", (void *) 0}," + + if test -s "$nlist"I; then + echo >> "$output_objdir/$my_dlsyms" "\ + {\"@INIT@\", (void *) <_syminit}," + fi + + case $need_lib_prefix in + no) + eval "$global_symbol_to_c_name_address" < "$nlist" >> "$output_objdir/$my_dlsyms" + ;; + *) + eval "$global_symbol_to_c_name_address_lib_prefix" < "$nlist" >> "$output_objdir/$my_dlsyms" + ;; + esac + echo >> "$output_objdir/$my_dlsyms" "\ + {0, (void *) 0} +}; + +/* This works around a problem in FreeBSD linker */ +#ifdef FREEBSD_WORKAROUND +static const void *lt_preloaded_setup() { + return lt_${my_prefix}_LTX_preloaded_symbols; +} +#endif + +#ifdef __cplusplus +} +#endif\ +" + } # !$opt_dry_run + + pic_flag_for_symtable= + case "$compile_command " in + *" -static "*) ;; + *) + case $host in + # compiling the symbol table file with pic_flag works around + # a FreeBSD bug that causes programs to crash when -lm is + # linked before any other PIC object. But we must not use + # pic_flag when linking with -static. The problem exists in + # FreeBSD 2.2.6 and is fixed in FreeBSD 3.1. + *-*-freebsd2.*|*-*-freebsd3.0*|*-*-freebsdelf3.0*) + pic_flag_for_symtable=" $pic_flag -DFREEBSD_WORKAROUND" ;; + *-*-hpux*) + pic_flag_for_symtable=" $pic_flag" ;; + *) + $my_pic_p && pic_flag_for_symtable=" $pic_flag" + ;; + esac + ;; + esac + symtab_cflags= + for arg in $LTCFLAGS; do + case $arg in + -pie | -fpie | -fPIE) ;; + *) func_append symtab_cflags " $arg" ;; + esac + done + + # Now compile the dynamic symbol file. + func_show_eval '(cd $output_objdir && $LTCC$symtab_cflags -c$no_builtin_flag$pic_flag_for_symtable "$my_dlsyms")' 'exit $?' + + # Clean up the generated files. + func_show_eval '$RM "$output_objdir/$my_dlsyms" "$nlist" "${nlist}S" "${nlist}T" "${nlist}I"' + + # Transform the symbol file into the correct name. + symfileobj=$output_objdir/${my_outputname}S.$objext + case $host in + *cygwin* | *mingw* | *cegcc* ) + if test -f "$output_objdir/$my_outputname.def"; then + compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"` + finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"` + else + compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"` + finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"` + fi + ;; + *) + compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"` + finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"` + ;; + esac + ;; + *) + func_fatal_error "unknown suffix for '$my_dlsyms'" + ;; + esac + else + # We keep going just in case the user didn't refer to + # lt_preloaded_symbols. The linker will fail if global_symbol_pipe + # really was required. + + # Nullify the symbol file. + compile_command=`$ECHO "$compile_command" | $SED "s% @SYMFILE@%%"` + finalize_command=`$ECHO "$finalize_command" | $SED "s% @SYMFILE@%%"` + fi +} + +# func_cygming_gnu_implib_p ARG +# This predicate returns with zero status (TRUE) if +# ARG is a GNU/binutils-style import library. Returns +# with nonzero status (FALSE) otherwise. +func_cygming_gnu_implib_p () +{ + $debug_cmd + + func_to_tool_file "$1" func_convert_file_msys_to_w32 + func_cygming_gnu_implib_tmp=`$NM "$func_to_tool_file_result" | eval "$global_symbol_pipe" | $EGREP ' (_head_[A-Za-z0-9_]+_[ad]l*|[A-Za-z0-9_]+_[ad]l*_iname)$'` + test -n "$func_cygming_gnu_implib_tmp" +} + +# func_cygming_ms_implib_p ARG +# This predicate returns with zero status (TRUE) if +# ARG is an MS-style import library. Returns +# with nonzero status (FALSE) otherwise. +func_cygming_ms_implib_p () +{ + $debug_cmd + + func_to_tool_file "$1" func_convert_file_msys_to_w32 + func_cygming_ms_implib_tmp=`$NM "$func_to_tool_file_result" | eval "$global_symbol_pipe" | $GREP '_NULL_IMPORT_DESCRIPTOR'` + test -n "$func_cygming_ms_implib_tmp" +} + +# func_win32_libid arg +# return the library type of file 'arg' +# +# Need a lot of goo to handle *both* DLLs and import libs +# Has to be a shell function in order to 'eat' the argument +# that is supplied when $file_magic_command is called. +# Despite the name, also deal with 64 bit binaries. +func_win32_libid () +{ + $debug_cmd + + win32_libid_type=unknown + win32_fileres=`file -L $1 2>/dev/null` + case $win32_fileres in + *ar\ archive\ import\ library*) # definitely import + win32_libid_type="x86 archive import" + ;; + *ar\ archive*) # could be an import, or static + # Keep the egrep pattern in sync with the one in _LT_CHECK_MAGIC_METHOD. + if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null | + $EGREP 'file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64)' >/dev/null; then + case $nm_interface in + "MS dumpbin") + if func_cygming_ms_implib_p "$1" || + func_cygming_gnu_implib_p "$1" + then + win32_nmres=import + else + win32_nmres= + fi + ;; + *) + func_to_tool_file "$1" func_convert_file_msys_to_w32 + win32_nmres=`eval $NM -f posix -A \"$func_to_tool_file_result\" | + $SED -n -e ' + 1,100{ + / I /{ + s|.*|import| + p + q + } + }'` + ;; + esac + case $win32_nmres in + import*) win32_libid_type="x86 archive import";; + *) win32_libid_type="x86 archive static";; + esac + fi + ;; + *DLL*) + win32_libid_type="x86 DLL" + ;; + *executable*) # but shell scripts are "executable" too... + case $win32_fileres in + *MS\ Windows\ PE\ Intel*) + win32_libid_type="x86 DLL" + ;; + esac + ;; + esac + $ECHO "$win32_libid_type" +} + +# func_cygming_dll_for_implib ARG +# +# Platform-specific function to extract the +# name of the DLL associated with the specified +# import library ARG. +# Invoked by eval'ing the libtool variable +# $sharedlib_from_linklib_cmd +# Result is available in the variable +# $sharedlib_from_linklib_result +func_cygming_dll_for_implib () +{ + $debug_cmd + + sharedlib_from_linklib_result=`$DLLTOOL --identify-strict --identify "$1"` +} + +# func_cygming_dll_for_implib_fallback_core SECTION_NAME LIBNAMEs +# +# The is the core of a fallback implementation of a +# platform-specific function to extract the name of the +# DLL associated with the specified import library LIBNAME. +# +# SECTION_NAME is either .idata$6 or .idata$7, depending +# on the platform and compiler that created the implib. +# +# Echos the name of the DLL associated with the +# specified import library. +func_cygming_dll_for_implib_fallback_core () +{ + $debug_cmd + + match_literal=`$ECHO "$1" | $SED "$sed_make_literal_regex"` + $OBJDUMP -s --section "$1" "$2" 2>/dev/null | + $SED '/^Contents of section '"$match_literal"':/{ + # Place marker at beginning of archive member dllname section + s/.*/====MARK====/ + p + d + } + # These lines can sometimes be longer than 43 characters, but + # are always uninteresting + /:[ ]*file format pe[i]\{,1\}-/d + /^In archive [^:]*:/d + # Ensure marker is printed + /^====MARK====/p + # Remove all lines with less than 43 characters + /^.\{43\}/!d + # From remaining lines, remove first 43 characters + s/^.\{43\}//' | + $SED -n ' + # Join marker and all lines until next marker into a single line + /^====MARK====/ b para + H + $ b para + b + :para + x + s/\n//g + # Remove the marker + s/^====MARK====// + # Remove trailing dots and whitespace + s/[\. \t]*$// + # Print + /./p' | + # we now have a list, one entry per line, of the stringified + # contents of the appropriate section of all members of the + # archive that possess that section. Heuristic: eliminate + # all those that have a first or second character that is + # a '.' (that is, objdump's representation of an unprintable + # character.) This should work for all archives with less than + # 0x302f exports -- but will fail for DLLs whose name actually + # begins with a literal '.' or a single character followed by + # a '.'. + # + # Of those that remain, print the first one. + $SED -e '/^\./d;/^.\./d;q' +} + +# func_cygming_dll_for_implib_fallback ARG +# Platform-specific function to extract the +# name of the DLL associated with the specified +# import library ARG. +# +# This fallback implementation is for use when $DLLTOOL +# does not support the --identify-strict option. +# Invoked by eval'ing the libtool variable +# $sharedlib_from_linklib_cmd +# Result is available in the variable +# $sharedlib_from_linklib_result +func_cygming_dll_for_implib_fallback () +{ + $debug_cmd + + if func_cygming_gnu_implib_p "$1"; then + # binutils import library + sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$7' "$1"` + elif func_cygming_ms_implib_p "$1"; then + # ms-generated import library + sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$6' "$1"` + else + # unknown + sharedlib_from_linklib_result= + fi +} + + +# func_extract_an_archive dir oldlib +func_extract_an_archive () +{ + $debug_cmd + + f_ex_an_ar_dir=$1; shift + f_ex_an_ar_oldlib=$1 + if test yes = "$lock_old_archive_extraction"; then + lockfile=$f_ex_an_ar_oldlib.lock + until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do + func_echo "Waiting for $lockfile to be removed" + sleep 2 + done + fi + func_show_eval "(cd \$f_ex_an_ar_dir && $AR x \"\$f_ex_an_ar_oldlib\")" \ + 'stat=$?; rm -f "$lockfile"; exit $stat' + if test yes = "$lock_old_archive_extraction"; then + $opt_dry_run || rm -f "$lockfile" + fi + if ($AR t "$f_ex_an_ar_oldlib" | sort | sort -uc >/dev/null 2>&1); then + : + else + func_fatal_error "object name conflicts in archive: $f_ex_an_ar_dir/$f_ex_an_ar_oldlib" + fi +} + + +# func_extract_archives gentop oldlib ... +func_extract_archives () +{ + $debug_cmd + + my_gentop=$1; shift + my_oldlibs=${1+"$@"} + my_oldobjs= + my_xlib= + my_xabs= + my_xdir= + + for my_xlib in $my_oldlibs; do + # Extract the objects. + case $my_xlib in + [\\/]* | [A-Za-z]:[\\/]*) my_xabs=$my_xlib ;; + *) my_xabs=`pwd`"/$my_xlib" ;; + esac + func_basename "$my_xlib" + my_xlib=$func_basename_result + my_xlib_u=$my_xlib + while :; do + case " $extracted_archives " in + *" $my_xlib_u "*) + func_arith $extracted_serial + 1 + extracted_serial=$func_arith_result + my_xlib_u=lt$extracted_serial-$my_xlib ;; + *) break ;; + esac + done + extracted_archives="$extracted_archives $my_xlib_u" + my_xdir=$my_gentop/$my_xlib_u + + func_mkdir_p "$my_xdir" + + case $host in + *-darwin*) + func_verbose "Extracting $my_xabs" + # Do not bother doing anything if just a dry run + $opt_dry_run || { + darwin_orig_dir=`pwd` + cd $my_xdir || exit $? + darwin_archive=$my_xabs + darwin_curdir=`pwd` + func_basename "$darwin_archive" + darwin_base_archive=$func_basename_result + darwin_arches=`$LIPO -info "$darwin_archive" 2>/dev/null | $GREP Architectures 2>/dev/null || true` + if test -n "$darwin_arches"; then + darwin_arches=`$ECHO "$darwin_arches" | $SED -e 's/.*are://'` + darwin_arch= + func_verbose "$darwin_base_archive has multiple architectures $darwin_arches" + for darwin_arch in $darwin_arches; do + func_mkdir_p "unfat-$$/$darwin_base_archive-$darwin_arch" + $LIPO -thin $darwin_arch -output "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive" "$darwin_archive" + cd "unfat-$$/$darwin_base_archive-$darwin_arch" + func_extract_an_archive "`pwd`" "$darwin_base_archive" + cd "$darwin_curdir" + $RM "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive" + done # $darwin_arches + ## Okay now we've a bunch of thin objects, gotta fatten them up :) + darwin_filelist=`find unfat-$$ -type f -name \*.o -print -o -name \*.lo -print | $SED -e "$sed_basename" | sort -u` + darwin_file= + darwin_files= + for darwin_file in $darwin_filelist; do + darwin_files=`find unfat-$$ -name $darwin_file -print | sort | $NL2SP` + $LIPO -create -output "$darwin_file" $darwin_files + done # $darwin_filelist + $RM -rf unfat-$$ + cd "$darwin_orig_dir" + else + cd $darwin_orig_dir + func_extract_an_archive "$my_xdir" "$my_xabs" + fi # $darwin_arches + } # !$opt_dry_run + ;; + *) + func_extract_an_archive "$my_xdir" "$my_xabs" + ;; + esac + my_oldobjs="$my_oldobjs "`find $my_xdir -name \*.$objext -print -o -name \*.lo -print | sort | $NL2SP` + done + + func_extract_archives_result=$my_oldobjs +} + + +# func_emit_wrapper [arg=no] +# +# Emit a libtool wrapper script on stdout. +# Don't directly open a file because we may want to +# incorporate the script contents within a cygwin/mingw +# wrapper executable. Must ONLY be called from within +# func_mode_link because it depends on a number of variables +# set therein. +# +# ARG is the value that the WRAPPER_SCRIPT_BELONGS_IN_OBJDIR +# variable will take. If 'yes', then the emitted script +# will assume that the directory where it is stored is +# the $objdir directory. This is a cygwin/mingw-specific +# behavior. +func_emit_wrapper () +{ + func_emit_wrapper_arg1=${1-no} + + $ECHO "\ +#! $SHELL + +# $output - temporary wrapper script for $objdir/$outputname +# Generated by $PROGRAM (GNU $PACKAGE) $VERSION +# +# The $output program cannot be directly executed until all the libtool +# libraries that it depends on are installed. +# +# This wrapper script should never be moved out of the build directory. +# If it is, it will not operate correctly. + +# Sed substitution that helps us do robust quoting. It backslashifies +# metacharacters that are still active within double-quoted strings. +sed_quote_subst='$sed_quote_subst' + +# Be Bourne compatible +if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then + emulate sh + NULLCMD=: + # Zsh 3.x and 4.x performs word splitting on \${1+\"\$@\"}, which + # is contrary to our usage. Disable this feature. + alias -g '\${1+\"\$@\"}'='\"\$@\"' + setopt NO_GLOB_SUBST +else + case \`(set -o) 2>/dev/null\` in *posix*) set -o posix;; esac +fi +BIN_SH=xpg4; export BIN_SH # for Tru64 +DUALCASE=1; export DUALCASE # for MKS sh + +# The HP-UX ksh and POSIX shell print the target directory to stdout +# if CDPATH is set. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + +relink_command=\"$relink_command\" + +# This environment variable determines our operation mode. +if test \"\$libtool_install_magic\" = \"$magic\"; then + # install mode needs the following variables: + generated_by_libtool_version='$macro_version' + notinst_deplibs='$notinst_deplibs' +else + # When we are sourced in execute mode, \$file and \$ECHO are already set. + if test \"\$libtool_execute_magic\" != \"$magic\"; then + file=\"\$0\"" + + qECHO=`$ECHO "$ECHO" | $SED "$sed_quote_subst"` + $ECHO "\ + +# A function that is used when there is no print builtin or printf. +func_fallback_echo () +{ + eval 'cat <<_LTECHO_EOF +\$1 +_LTECHO_EOF' +} + ECHO=\"$qECHO\" + fi + +# Very basic option parsing. These options are (a) specific to +# the libtool wrapper, (b) are identical between the wrapper +# /script/ and the wrapper /executable/ that is used only on +# windows platforms, and (c) all begin with the string "--lt-" +# (application programs are unlikely to have options that match +# this pattern). +# +# There are only two supported options: --lt-debug and +# --lt-dump-script. There is, deliberately, no --lt-help. +# +# The first argument to this parsing function should be the +# script's $0 value, followed by "$@". +lt_option_debug= +func_parse_lt_options () +{ + lt_script_arg0=\$0 + shift + for lt_opt + do + case \"\$lt_opt\" in + --lt-debug) lt_option_debug=1 ;; + --lt-dump-script) + lt_dump_D=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%/[^/]*$%%'\` + test \"X\$lt_dump_D\" = \"X\$lt_script_arg0\" && lt_dump_D=. + lt_dump_F=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%^.*/%%'\` + cat \"\$lt_dump_D/\$lt_dump_F\" + exit 0 + ;; + --lt-*) + \$ECHO \"Unrecognized --lt- option: '\$lt_opt'\" 1>&2 + exit 1 + ;; + esac + done + + # Print the debug banner immediately: + if test -n \"\$lt_option_debug\"; then + echo \"$outputname:$output:\$LINENO: libtool wrapper (GNU $PACKAGE) $VERSION\" 1>&2 + fi +} + +# Used when --lt-debug. Prints its arguments to stdout +# (redirection is the responsibility of the caller) +func_lt_dump_args () +{ + lt_dump_args_N=1; + for lt_arg + do + \$ECHO \"$outputname:$output:\$LINENO: newargv[\$lt_dump_args_N]: \$lt_arg\" + lt_dump_args_N=\`expr \$lt_dump_args_N + 1\` + done +} + +# Core function for launching the target application +func_exec_program_core () +{ +" + case $host in + # Backslashes separate directories on plain windows + *-*-mingw | *-*-os2* | *-cegcc*) + $ECHO "\ + if test -n \"\$lt_option_debug\"; then + \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir\\\\\$program\" 1>&2 + func_lt_dump_args \${1+\"\$@\"} 1>&2 + fi + exec \"\$progdir\\\\\$program\" \${1+\"\$@\"} +" + ;; + + *) + $ECHO "\ + if test -n \"\$lt_option_debug\"; then + \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir/\$program\" 1>&2 + func_lt_dump_args \${1+\"\$@\"} 1>&2 + fi + exec \"\$progdir/\$program\" \${1+\"\$@\"} +" + ;; + esac + $ECHO "\ + \$ECHO \"\$0: cannot exec \$program \$*\" 1>&2 + exit 1 +} + +# A function to encapsulate launching the target application +# Strips options in the --lt-* namespace from \$@ and +# launches target application with the remaining arguments. +func_exec_program () +{ + case \" \$* \" in + *\\ --lt-*) + for lt_wr_arg + do + case \$lt_wr_arg in + --lt-*) ;; + *) set x \"\$@\" \"\$lt_wr_arg\"; shift;; + esac + shift + done ;; + esac + func_exec_program_core \${1+\"\$@\"} +} + + # Parse options + func_parse_lt_options \"\$0\" \${1+\"\$@\"} + + # Find the directory that this script lives in. + thisdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*$%%'\` + test \"x\$thisdir\" = \"x\$file\" && thisdir=. + + # Follow symbolic links until we get to the real thisdir. + file=\`ls -ld \"\$file\" | $SED -n 's/.*-> //p'\` + while test -n \"\$file\"; do + destdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*\$%%'\` + + # If there was a directory component, then change thisdir. + if test \"x\$destdir\" != \"x\$file\"; then + case \"\$destdir\" in + [\\\\/]* | [A-Za-z]:[\\\\/]*) thisdir=\"\$destdir\" ;; + *) thisdir=\"\$thisdir/\$destdir\" ;; + esac + fi + + file=\`\$ECHO \"\$file\" | $SED 's%^.*/%%'\` + file=\`ls -ld \"\$thisdir/\$file\" | $SED -n 's/.*-> //p'\` + done + + # Usually 'no', except on cygwin/mingw when embedded into + # the cwrapper. + WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=$func_emit_wrapper_arg1 + if test \"\$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR\" = \"yes\"; then + # special case for '.' + if test \"\$thisdir\" = \".\"; then + thisdir=\`pwd\` + fi + # remove .libs from thisdir + case \"\$thisdir\" in + *[\\\\/]$objdir ) thisdir=\`\$ECHO \"\$thisdir\" | $SED 's%[\\\\/][^\\\\/]*$%%'\` ;; + $objdir ) thisdir=. ;; + esac + fi + + # Try to get the absolute directory name. + absdir=\`cd \"\$thisdir\" && pwd\` + test -n \"\$absdir\" && thisdir=\"\$absdir\" +" + + if test yes = "$fast_install"; then + $ECHO "\ + program=lt-'$outputname'$exeext + progdir=\"\$thisdir/$objdir\" + + if test ! -f \"\$progdir/\$program\" || + { file=\`ls -1dt \"\$progdir/\$program\" \"\$progdir/../\$program\" 2>/dev/null | $SED 1q\`; \\ + test \"X\$file\" != \"X\$progdir/\$program\"; }; then + + file=\"\$\$-\$program\" + + if test ! -d \"\$progdir\"; then + $MKDIR \"\$progdir\" + else + $RM \"\$progdir/\$file\" + fi" + + $ECHO "\ + + # relink executable if necessary + if test -n \"\$relink_command\"; then + if relink_command_output=\`eval \$relink_command 2>&1\`; then : + else + \$ECHO \"\$relink_command_output\" >&2 + $RM \"\$progdir/\$file\" + exit 1 + fi + fi + + $MV \"\$progdir/\$file\" \"\$progdir/\$program\" 2>/dev/null || + { $RM \"\$progdir/\$program\"; + $MV \"\$progdir/\$file\" \"\$progdir/\$program\"; } + $RM \"\$progdir/\$file\" + fi" + else + $ECHO "\ + program='$outputname' + progdir=\"\$thisdir/$objdir\" +" + fi + + $ECHO "\ + + if test -f \"\$progdir/\$program\"; then" + + # fixup the dll searchpath if we need to. + # + # Fix the DLL searchpath if we need to. Do this before prepending + # to shlibpath, because on Windows, both are PATH and uninstalled + # libraries must come first. + if test -n "$dllsearchpath"; then + $ECHO "\ + # Add the dll search path components to the executable PATH + PATH=$dllsearchpath:\$PATH +" + fi + + # Export our shlibpath_var if we have one. + if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then + $ECHO "\ + # Add our own library path to $shlibpath_var + $shlibpath_var=\"$temp_rpath\$$shlibpath_var\" + + # Some systems cannot cope with colon-terminated $shlibpath_var + # The second colon is a workaround for a bug in BeOS R4 sed + $shlibpath_var=\`\$ECHO \"\$$shlibpath_var\" | $SED 's/::*\$//'\` + + export $shlibpath_var +" + fi + + $ECHO "\ + if test \"\$libtool_execute_magic\" != \"$magic\"; then + # Run the actual program with our arguments. + func_exec_program \${1+\"\$@\"} + fi + else + # The program doesn't exist. + \$ECHO \"\$0: error: '\$progdir/\$program' does not exist\" 1>&2 + \$ECHO \"This script is just a wrapper for \$program.\" 1>&2 + \$ECHO \"See the $PACKAGE documentation for more information.\" 1>&2 + exit 1 + fi +fi\ +" +} + + +# func_emit_cwrapperexe_src +# emit the source code for a wrapper executable on stdout +# Must ONLY be called from within func_mode_link because +# it depends on a number of variable set therein. +func_emit_cwrapperexe_src () +{ + cat < +#include +#ifdef _MSC_VER +# include +# include +# include +#else +# include +# include +# ifdef __CYGWIN__ +# include +# endif +#endif +#include +#include +#include +#include +#include +#include +#include +#include + +#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0) + +/* declarations of non-ANSI functions */ +#if defined __MINGW32__ +# ifdef __STRICT_ANSI__ +int _putenv (const char *); +# endif +#elif defined __CYGWIN__ +# ifdef __STRICT_ANSI__ +char *realpath (const char *, char *); +int putenv (char *); +int setenv (const char *, const char *, int); +# endif +/* #elif defined other_platform || defined ... */ +#endif + +/* portability defines, excluding path handling macros */ +#if defined _MSC_VER +# define setmode _setmode +# define stat _stat +# define chmod _chmod +# define getcwd _getcwd +# define putenv _putenv +# define S_IXUSR _S_IEXEC +#elif defined __MINGW32__ +# define setmode _setmode +# define stat _stat +# define chmod _chmod +# define getcwd _getcwd +# define putenv _putenv +#elif defined __CYGWIN__ +# define HAVE_SETENV +# define FOPEN_WB "wb" +/* #elif defined other platforms ... */ +#endif + +#if defined PATH_MAX +# define LT_PATHMAX PATH_MAX +#elif defined MAXPATHLEN +# define LT_PATHMAX MAXPATHLEN +#else +# define LT_PATHMAX 1024 +#endif + +#ifndef S_IXOTH +# define S_IXOTH 0 +#endif +#ifndef S_IXGRP +# define S_IXGRP 0 +#endif + +/* path handling portability macros */ +#ifndef DIR_SEPARATOR +# define DIR_SEPARATOR '/' +# define PATH_SEPARATOR ':' +#endif + +#if defined _WIN32 || defined __MSDOS__ || defined __DJGPP__ || \ + defined __OS2__ +# define HAVE_DOS_BASED_FILE_SYSTEM +# define FOPEN_WB "wb" +# ifndef DIR_SEPARATOR_2 +# define DIR_SEPARATOR_2 '\\' +# endif +# ifndef PATH_SEPARATOR_2 +# define PATH_SEPARATOR_2 ';' +# endif +#endif + +#ifndef DIR_SEPARATOR_2 +# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR) +#else /* DIR_SEPARATOR_2 */ +# define IS_DIR_SEPARATOR(ch) \ + (((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2)) +#endif /* DIR_SEPARATOR_2 */ + +#ifndef PATH_SEPARATOR_2 +# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR) +#else /* PATH_SEPARATOR_2 */ +# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR_2) +#endif /* PATH_SEPARATOR_2 */ + +#ifndef FOPEN_WB +# define FOPEN_WB "w" +#endif +#ifndef _O_BINARY +# define _O_BINARY 0 +#endif + +#define XMALLOC(type, num) ((type *) xmalloc ((num) * sizeof(type))) +#define XFREE(stale) do { \ + if (stale) { free (stale); stale = 0; } \ +} while (0) + +#if defined LT_DEBUGWRAPPER +static int lt_debug = 1; +#else +static int lt_debug = 0; +#endif + +const char *program_name = "libtool-wrapper"; /* in case xstrdup fails */ + +void *xmalloc (size_t num); +char *xstrdup (const char *string); +const char *base_name (const char *name); +char *find_executable (const char *wrapper); +char *chase_symlinks (const char *pathspec); +int make_executable (const char *path); +int check_executable (const char *path); +char *strendzap (char *str, const char *pat); +void lt_debugprintf (const char *file, int line, const char *fmt, ...); +void lt_fatal (const char *file, int line, const char *message, ...); +static const char *nonnull (const char *s); +static const char *nonempty (const char *s); +void lt_setenv (const char *name, const char *value); +char *lt_extend_str (const char *orig_value, const char *add, int to_end); +void lt_update_exe_path (const char *name, const char *value); +void lt_update_lib_path (const char *name, const char *value); +char **prepare_spawn (char **argv); +void lt_dump_script (FILE *f); +EOF + + cat <= 0) + && (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH))) + return 1; + else + return 0; +} + +int +make_executable (const char *path) +{ + int rval = 0; + struct stat st; + + lt_debugprintf (__FILE__, __LINE__, "(make_executable): %s\n", + nonempty (path)); + if ((!path) || (!*path)) + return 0; + + if (stat (path, &st) >= 0) + { + rval = chmod (path, st.st_mode | S_IXOTH | S_IXGRP | S_IXUSR); + } + return rval; +} + +/* Searches for the full path of the wrapper. Returns + newly allocated full path name if found, NULL otherwise + Does not chase symlinks, even on platforms that support them. +*/ +char * +find_executable (const char *wrapper) +{ + int has_slash = 0; + const char *p; + const char *p_next; + /* static buffer for getcwd */ + char tmp[LT_PATHMAX + 1]; + size_t tmp_len; + char *concat_name; + + lt_debugprintf (__FILE__, __LINE__, "(find_executable): %s\n", + nonempty (wrapper)); + + if ((wrapper == NULL) || (*wrapper == '\0')) + return NULL; + + /* Absolute path? */ +#if defined HAVE_DOS_BASED_FILE_SYSTEM + if (isalpha ((unsigned char) wrapper[0]) && wrapper[1] == ':') + { + concat_name = xstrdup (wrapper); + if (check_executable (concat_name)) + return concat_name; + XFREE (concat_name); + } + else + { +#endif + if (IS_DIR_SEPARATOR (wrapper[0])) + { + concat_name = xstrdup (wrapper); + if (check_executable (concat_name)) + return concat_name; + XFREE (concat_name); + } +#if defined HAVE_DOS_BASED_FILE_SYSTEM + } +#endif + + for (p = wrapper; *p; p++) + if (*p == '/') + { + has_slash = 1; + break; + } + if (!has_slash) + { + /* no slashes; search PATH */ + const char *path = getenv ("PATH"); + if (path != NULL) + { + for (p = path; *p; p = p_next) + { + const char *q; + size_t p_len; + for (q = p; *q; q++) + if (IS_PATH_SEPARATOR (*q)) + break; + p_len = (size_t) (q - p); + p_next = (*q == '\0' ? q : q + 1); + if (p_len == 0) + { + /* empty path: current directory */ + if (getcwd (tmp, LT_PATHMAX) == NULL) + lt_fatal (__FILE__, __LINE__, "getcwd failed: %s", + nonnull (strerror (errno))); + tmp_len = strlen (tmp); + concat_name = + XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1); + memcpy (concat_name, tmp, tmp_len); + concat_name[tmp_len] = '/'; + strcpy (concat_name + tmp_len + 1, wrapper); + } + else + { + concat_name = + XMALLOC (char, p_len + 1 + strlen (wrapper) + 1); + memcpy (concat_name, p, p_len); + concat_name[p_len] = '/'; + strcpy (concat_name + p_len + 1, wrapper); + } + if (check_executable (concat_name)) + return concat_name; + XFREE (concat_name); + } + } + /* not found in PATH; assume curdir */ + } + /* Relative path | not found in path: prepend cwd */ + if (getcwd (tmp, LT_PATHMAX) == NULL) + lt_fatal (__FILE__, __LINE__, "getcwd failed: %s", + nonnull (strerror (errno))); + tmp_len = strlen (tmp); + concat_name = XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1); + memcpy (concat_name, tmp, tmp_len); + concat_name[tmp_len] = '/'; + strcpy (concat_name + tmp_len + 1, wrapper); + + if (check_executable (concat_name)) + return concat_name; + XFREE (concat_name); + return NULL; +} + +char * +chase_symlinks (const char *pathspec) +{ +#ifndef S_ISLNK + return xstrdup (pathspec); +#else + char buf[LT_PATHMAX]; + struct stat s; + char *tmp_pathspec = xstrdup (pathspec); + char *p; + int has_symlinks = 0; + while (strlen (tmp_pathspec) && !has_symlinks) + { + lt_debugprintf (__FILE__, __LINE__, + "checking path component for symlinks: %s\n", + tmp_pathspec); + if (lstat (tmp_pathspec, &s) == 0) + { + if (S_ISLNK (s.st_mode) != 0) + { + has_symlinks = 1; + break; + } + + /* search backwards for last DIR_SEPARATOR */ + p = tmp_pathspec + strlen (tmp_pathspec) - 1; + while ((p > tmp_pathspec) && (!IS_DIR_SEPARATOR (*p))) + p--; + if ((p == tmp_pathspec) && (!IS_DIR_SEPARATOR (*p))) + { + /* no more DIR_SEPARATORS left */ + break; + } + *p = '\0'; + } + else + { + lt_fatal (__FILE__, __LINE__, + "error accessing file \"%s\": %s", + tmp_pathspec, nonnull (strerror (errno))); + } + } + XFREE (tmp_pathspec); + + if (!has_symlinks) + { + return xstrdup (pathspec); + } + + tmp_pathspec = realpath (pathspec, buf); + if (tmp_pathspec == 0) + { + lt_fatal (__FILE__, __LINE__, + "could not follow symlinks for %s", pathspec); + } + return xstrdup (tmp_pathspec); +#endif +} + +char * +strendzap (char *str, const char *pat) +{ + size_t len, patlen; + + assert (str != NULL); + assert (pat != NULL); + + len = strlen (str); + patlen = strlen (pat); + + if (patlen <= len) + { + str += len - patlen; + if (STREQ (str, pat)) + *str = '\0'; + } + return str; +} + +void +lt_debugprintf (const char *file, int line, const char *fmt, ...) +{ + va_list args; + if (lt_debug) + { + (void) fprintf (stderr, "%s:%s:%d: ", program_name, file, line); + va_start (args, fmt); + (void) vfprintf (stderr, fmt, args); + va_end (args); + } +} + +static void +lt_error_core (int exit_status, const char *file, + int line, const char *mode, + const char *message, va_list ap) +{ + fprintf (stderr, "%s:%s:%d: %s: ", program_name, file, line, mode); + vfprintf (stderr, message, ap); + fprintf (stderr, ".\n"); + + if (exit_status >= 0) + exit (exit_status); +} + +void +lt_fatal (const char *file, int line, const char *message, ...) +{ + va_list ap; + va_start (ap, message); + lt_error_core (EXIT_FAILURE, file, line, "FATAL", message, ap); + va_end (ap); +} + +static const char * +nonnull (const char *s) +{ + return s ? s : "(null)"; +} + +static const char * +nonempty (const char *s) +{ + return (s && !*s) ? "(empty)" : nonnull (s); +} + +void +lt_setenv (const char *name, const char *value) +{ + lt_debugprintf (__FILE__, __LINE__, + "(lt_setenv) setting '%s' to '%s'\n", + nonnull (name), nonnull (value)); + { +#ifdef HAVE_SETENV + /* always make a copy, for consistency with !HAVE_SETENV */ + char *str = xstrdup (value); + setenv (name, str, 1); +#else + size_t len = strlen (name) + 1 + strlen (value) + 1; + char *str = XMALLOC (char, len); + sprintf (str, "%s=%s", name, value); + if (putenv (str) != EXIT_SUCCESS) + { + XFREE (str); + } +#endif + } +} + +char * +lt_extend_str (const char *orig_value, const char *add, int to_end) +{ + char *new_value; + if (orig_value && *orig_value) + { + size_t orig_value_len = strlen (orig_value); + size_t add_len = strlen (add); + new_value = XMALLOC (char, add_len + orig_value_len + 1); + if (to_end) + { + strcpy (new_value, orig_value); + strcpy (new_value + orig_value_len, add); + } + else + { + strcpy (new_value, add); + strcpy (new_value + add_len, orig_value); + } + } + else + { + new_value = xstrdup (add); + } + return new_value; +} + +void +lt_update_exe_path (const char *name, const char *value) +{ + lt_debugprintf (__FILE__, __LINE__, + "(lt_update_exe_path) modifying '%s' by prepending '%s'\n", + nonnull (name), nonnull (value)); + + if (name && *name && value && *value) + { + char *new_value = lt_extend_str (getenv (name), value, 0); + /* some systems can't cope with a ':'-terminated path #' */ + size_t len = strlen (new_value); + while ((len > 0) && IS_PATH_SEPARATOR (new_value[len-1])) + { + new_value[--len] = '\0'; + } + lt_setenv (name, new_value); + XFREE (new_value); + } +} + +void +lt_update_lib_path (const char *name, const char *value) +{ + lt_debugprintf (__FILE__, __LINE__, + "(lt_update_lib_path) modifying '%s' by prepending '%s'\n", + nonnull (name), nonnull (value)); + + if (name && *name && value && *value) + { + char *new_value = lt_extend_str (getenv (name), value, 0); + lt_setenv (name, new_value); + XFREE (new_value); + } +} + +EOF + case $host_os in + mingw*) + cat <<"EOF" + +/* Prepares an argument vector before calling spawn(). + Note that spawn() does not by itself call the command interpreter + (getenv ("COMSPEC") != NULL ? getenv ("COMSPEC") : + ({ OSVERSIONINFO v; v.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); + GetVersionEx(&v); + v.dwPlatformId == VER_PLATFORM_WIN32_NT; + }) ? "cmd.exe" : "command.com"). + Instead it simply concatenates the arguments, separated by ' ', and calls + CreateProcess(). We must quote the arguments since Win32 CreateProcess() + interprets characters like ' ', '\t', '\\', '"' (but not '<' and '>') in a + special way: + - Space and tab are interpreted as delimiters. They are not treated as + delimiters if they are surrounded by double quotes: "...". + - Unescaped double quotes are removed from the input. Their only effect is + that within double quotes, space and tab are treated like normal + characters. + - Backslashes not followed by double quotes are not special. + - But 2*n+1 backslashes followed by a double quote become + n backslashes followed by a double quote (n >= 0): + \" -> " + \\\" -> \" + \\\\\" -> \\" + */ +#define SHELL_SPECIAL_CHARS "\"\\ \001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037" +#define SHELL_SPACE_CHARS " \001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037" +char ** +prepare_spawn (char **argv) +{ + size_t argc; + char **new_argv; + size_t i; + + /* Count number of arguments. */ + for (argc = 0; argv[argc] != NULL; argc++) + ; + + /* Allocate new argument vector. */ + new_argv = XMALLOC (char *, argc + 1); + + /* Put quoted arguments into the new argument vector. */ + for (i = 0; i < argc; i++) + { + const char *string = argv[i]; + + if (string[0] == '\0') + new_argv[i] = xstrdup ("\"\""); + else if (strpbrk (string, SHELL_SPECIAL_CHARS) != NULL) + { + int quote_around = (strpbrk (string, SHELL_SPACE_CHARS) != NULL); + size_t length; + unsigned int backslashes; + const char *s; + char *quoted_string; + char *p; + + length = 0; + backslashes = 0; + if (quote_around) + length++; + for (s = string; *s != '\0'; s++) + { + char c = *s; + if (c == '"') + length += backslashes + 1; + length++; + if (c == '\\') + backslashes++; + else + backslashes = 0; + } + if (quote_around) + length += backslashes + 1; + + quoted_string = XMALLOC (char, length + 1); + + p = quoted_string; + backslashes = 0; + if (quote_around) + *p++ = '"'; + for (s = string; *s != '\0'; s++) + { + char c = *s; + if (c == '"') + { + unsigned int j; + for (j = backslashes + 1; j > 0; j--) + *p++ = '\\'; + } + *p++ = c; + if (c == '\\') + backslashes++; + else + backslashes = 0; + } + if (quote_around) + { + unsigned int j; + for (j = backslashes; j > 0; j--) + *p++ = '\\'; + *p++ = '"'; + } + *p = '\0'; + + new_argv[i] = quoted_string; + } + else + new_argv[i] = (char *) string; + } + new_argv[argc] = NULL; + + return new_argv; +} +EOF + ;; + esac + + cat <<"EOF" +void lt_dump_script (FILE* f) +{ +EOF + func_emit_wrapper yes | + $SED -n -e ' +s/^\(.\{79\}\)\(..*\)/\1\ +\2/ +h +s/\([\\"]\)/\\\1/g +s/$/\\n/ +s/\([^\n]*\).*/ fputs ("\1", f);/p +g +D' + cat <<"EOF" +} +EOF +} +# end: func_emit_cwrapperexe_src + +# func_win32_import_lib_p ARG +# True if ARG is an import lib, as indicated by $file_magic_cmd +func_win32_import_lib_p () +{ + $debug_cmd + + case `eval $file_magic_cmd \"\$1\" 2>/dev/null | $SED -e 10q` in + *import*) : ;; + *) false ;; + esac +} + +# func_suncc_cstd_abi +# !!ONLY CALL THIS FOR SUN CC AFTER $compile_command IS FULLY EXPANDED!! +# Several compiler flags select an ABI that is incompatible with the +# Cstd library. Avoid specifying it if any are in CXXFLAGS. +func_suncc_cstd_abi () +{ + $debug_cmd + + case " $compile_command " in + *" -compat=g "*|*\ -std=c++[0-9][0-9]\ *|*" -library=stdcxx4 "*|*" -library=stlport4 "*) + suncc_use_cstd_abi=no + ;; + *) + suncc_use_cstd_abi=yes + ;; + esac +} + +# func_mode_link arg... +func_mode_link () +{ + $debug_cmd + + case $host in + *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*) + # It is impossible to link a dll without this setting, and + # we shouldn't force the makefile maintainer to figure out + # what system we are compiling for in order to pass an extra + # flag for every libtool invocation. + # allow_undefined=no + + # FIXME: Unfortunately, there are problems with the above when trying + # to make a dll that has undefined symbols, in which case not + # even a static library is built. For now, we need to specify + # -no-undefined on the libtool link line when we can be certain + # that all symbols are satisfied, otherwise we get a static library. + allow_undefined=yes + ;; + *) + allow_undefined=yes + ;; + esac + libtool_args=$nonopt + base_compile="$nonopt $@" + compile_command=$nonopt + finalize_command=$nonopt + + compile_rpath= + finalize_rpath= + compile_shlibpath= + finalize_shlibpath= + convenience= + old_convenience= + deplibs= + old_deplibs= + compiler_flags= + linker_flags= + dllsearchpath= + lib_search_path=`pwd` + inst_prefix_dir= + new_inherited_linker_flags= + + avoid_version=no + bindir= + dlfiles= + dlprefiles= + dlself=no + export_dynamic=no + export_symbols= + export_symbols_regex= + generated= + libobjs= + ltlibs= + module=no + no_install=no + objs= + os2dllname= + non_pic_objects= + precious_files_regex= + prefer_static_libs=no + preload=false + prev= + prevarg= + release= + rpath= + xrpath= + perm_rpath= + temp_rpath= + thread_safe=no + vinfo= + vinfo_number=no + weak_libs= + single_module=$wl-single_module + func_infer_tag $base_compile + + # We need to know -static, to get the right output filenames. + for arg + do + case $arg in + -shared) + test yes != "$build_libtool_libs" \ + && func_fatal_configuration "cannot build a shared library" + build_old_libs=no + break + ;; + -all-static | -static | -static-libtool-libs) + case $arg in + -all-static) + if test yes = "$build_libtool_libs" && test -z "$link_static_flag"; then + func_warning "complete static linking is impossible in this configuration" + fi + if test -n "$link_static_flag"; then + dlopen_self=$dlopen_self_static + fi + prefer_static_libs=yes + ;; + -static) + if test -z "$pic_flag" && test -n "$link_static_flag"; then + dlopen_self=$dlopen_self_static + fi + prefer_static_libs=built + ;; + -static-libtool-libs) + if test -z "$pic_flag" && test -n "$link_static_flag"; then + dlopen_self=$dlopen_self_static + fi + prefer_static_libs=yes + ;; + esac + build_libtool_libs=no + build_old_libs=yes + break + ;; + esac + done + + # See if our shared archives depend on static archives. + test -n "$old_archive_from_new_cmds" && build_old_libs=yes + + # Go through the arguments, transforming them on the way. + while test "$#" -gt 0; do + arg=$1 + shift + func_quote_for_eval "$arg" + qarg=$func_quote_for_eval_unquoted_result + func_append libtool_args " $func_quote_for_eval_result" + + # If the previous option needs an argument, assign it. + if test -n "$prev"; then + case $prev in + output) + func_append compile_command " @OUTPUT@" + func_append finalize_command " @OUTPUT@" + ;; + esac + + case $prev in + bindir) + bindir=$arg + prev= + continue + ;; + dlfiles|dlprefiles) + $preload || { + # Add the symbol object into the linking commands. + func_append compile_command " @SYMFILE@" + func_append finalize_command " @SYMFILE@" + preload=: + } + case $arg in + *.la | *.lo) ;; # We handle these cases below. + force) + if test no = "$dlself"; then + dlself=needless + export_dynamic=yes + fi + prev= + continue + ;; + self) + if test dlprefiles = "$prev"; then + dlself=yes + elif test dlfiles = "$prev" && test yes != "$dlopen_self"; then + dlself=yes + else + dlself=needless + export_dynamic=yes + fi + prev= + continue + ;; + *) + if test dlfiles = "$prev"; then + func_append dlfiles " $arg" + else + func_append dlprefiles " $arg" + fi + prev= + continue + ;; + esac + ;; + expsyms) + export_symbols=$arg + test -f "$arg" \ + || func_fatal_error "symbol file '$arg' does not exist" + prev= + continue + ;; + expsyms_regex) + export_symbols_regex=$arg + prev= + continue + ;; + framework) + case $host in + *-*-darwin*) + case "$deplibs " in + *" $qarg.ltframework "*) ;; + *) func_append deplibs " $qarg.ltframework" # this is fixed later + ;; + esac + ;; + esac + prev= + continue + ;; + inst_prefix) + inst_prefix_dir=$arg + prev= + continue + ;; + mllvm) + # Clang does not use LLVM to link, so we can simply discard any + # '-mllvm $arg' options when doing the link step. + prev= + continue + ;; + objectlist) + if test -f "$arg"; then + save_arg=$arg + moreargs= + for fil in `cat "$save_arg"` + do +# func_append moreargs " $fil" + arg=$fil + # A libtool-controlled object. + + # Check to see that this really is a libtool object. + if func_lalib_unsafe_p "$arg"; then + pic_object= + non_pic_object= + + # Read the .lo file + func_source "$arg" + + if test -z "$pic_object" || + test -z "$non_pic_object" || + test none = "$pic_object" && + test none = "$non_pic_object"; then + func_fatal_error "cannot find name of object for '$arg'" + fi + + # Extract subdirectory from the argument. + func_dirname "$arg" "/" "" + xdir=$func_dirname_result + + if test none != "$pic_object"; then + # Prepend the subdirectory the object is found in. + pic_object=$xdir$pic_object + + if test dlfiles = "$prev"; then + if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then + func_append dlfiles " $pic_object" + prev= + continue + else + # If libtool objects are unsupported, then we need to preload. + prev=dlprefiles + fi + fi + + # CHECK ME: I think I busted this. -Ossama + if test dlprefiles = "$prev"; then + # Preload the old-style object. + func_append dlprefiles " $pic_object" + prev= + fi + + # A PIC object. + func_append libobjs " $pic_object" + arg=$pic_object + fi + + # Non-PIC object. + if test none != "$non_pic_object"; then + # Prepend the subdirectory the object is found in. + non_pic_object=$xdir$non_pic_object + + # A standard non-PIC object + func_append non_pic_objects " $non_pic_object" + if test -z "$pic_object" || test none = "$pic_object"; then + arg=$non_pic_object + fi + else + # If the PIC object exists, use it instead. + # $xdir was prepended to $pic_object above. + non_pic_object=$pic_object + func_append non_pic_objects " $non_pic_object" + fi + else + # Only an error if not doing a dry-run. + if $opt_dry_run; then + # Extract subdirectory from the argument. + func_dirname "$arg" "/" "" + xdir=$func_dirname_result + + func_lo2o "$arg" + pic_object=$xdir$objdir/$func_lo2o_result + non_pic_object=$xdir$func_lo2o_result + func_append libobjs " $pic_object" + func_append non_pic_objects " $non_pic_object" + else + func_fatal_error "'$arg' is not a valid libtool object" + fi + fi + done + else + func_fatal_error "link input file '$arg' does not exist" + fi + arg=$save_arg + prev= + continue + ;; + os2dllname) + os2dllname=$arg + prev= + continue + ;; + precious_regex) + precious_files_regex=$arg + prev= + continue + ;; + release) + release=-$arg + prev= + continue + ;; + rpath | xrpath) + # We need an absolute path. + case $arg in + [\\/]* | [A-Za-z]:[\\/]*) ;; + *) + func_fatal_error "only absolute run-paths are allowed" + ;; + esac + if test rpath = "$prev"; then + case "$rpath " in + *" $arg "*) ;; + *) func_append rpath " $arg" ;; + esac + else + case "$xrpath " in + *" $arg "*) ;; + *) func_append xrpath " $arg" ;; + esac + fi + prev= + continue + ;; + shrext) + shrext_cmds=$arg + prev= + continue + ;; + weak) + func_append weak_libs " $arg" + prev= + continue + ;; + xcclinker) + func_append linker_flags " $qarg" + func_append compiler_flags " $qarg" + prev= + func_append compile_command " $qarg" + func_append finalize_command " $qarg" + continue + ;; + xcompiler) + func_append compiler_flags " $qarg" + prev= + func_append compile_command " $qarg" + func_append finalize_command " $qarg" + continue + ;; + xlinker) + func_append linker_flags " $qarg" + func_append compiler_flags " $wl$qarg" + prev= + func_append compile_command " $wl$qarg" + func_append finalize_command " $wl$qarg" + continue + ;; + *) + eval "$prev=\"\$arg\"" + prev= + continue + ;; + esac + fi # test -n "$prev" + + prevarg=$arg + + case $arg in + -all-static) + if test -n "$link_static_flag"; then + # See comment for -static flag below, for more details. + func_append compile_command " $link_static_flag" + func_append finalize_command " $link_static_flag" + fi + continue + ;; + + -allow-undefined) + # FIXME: remove this flag sometime in the future. + func_fatal_error "'-allow-undefined' must not be used because it is the default" + ;; + + -avoid-version) + avoid_version=yes + continue + ;; + + -bindir) + prev=bindir + continue + ;; + + -dlopen) + prev=dlfiles + continue + ;; + + -dlpreopen) + prev=dlprefiles + continue + ;; + + -export-dynamic) + export_dynamic=yes + continue + ;; + + -export-symbols | -export-symbols-regex) + if test -n "$export_symbols" || test -n "$export_symbols_regex"; then + func_fatal_error "more than one -exported-symbols argument is not allowed" + fi + if test X-export-symbols = "X$arg"; then + prev=expsyms + else + prev=expsyms_regex + fi + continue + ;; + + -framework) + prev=framework + continue + ;; + + -inst-prefix-dir) + prev=inst_prefix + continue + ;; + + # The native IRIX linker understands -LANG:*, -LIST:* and -LNO:* + # so, if we see these flags be careful not to treat them like -L + -L[A-Z][A-Z]*:*) + case $with_gcc/$host in + no/*-*-irix* | /*-*-irix*) + func_append compile_command " $arg" + func_append finalize_command " $arg" + ;; + esac + continue + ;; + + -L*) + func_stripname "-L" '' "$arg" + if test -z "$func_stripname_result"; then + if test "$#" -gt 0; then + func_fatal_error "require no space between '-L' and '$1'" + else + func_fatal_error "need path for '-L' option" + fi + fi + func_resolve_sysroot "$func_stripname_result" + dir=$func_resolve_sysroot_result + # We need an absolute path. + case $dir in + [\\/]* | [A-Za-z]:[\\/]*) ;; + *) + absdir=`cd "$dir" && pwd` + test -z "$absdir" && \ + func_fatal_error "cannot determine absolute directory name of '$dir'" + dir=$absdir + ;; + esac + case "$deplibs " in + *" -L$dir "* | *" $arg "*) + # Will only happen for absolute or sysroot arguments + ;; + *) + # Preserve sysroot, but never include relative directories + case $dir in + [\\/]* | [A-Za-z]:[\\/]* | =*) func_append deplibs " $arg" ;; + *) func_append deplibs " -L$dir" ;; + esac + func_append lib_search_path " $dir" + ;; + esac + case $host in + *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*) + testbindir=`$ECHO "$dir" | $SED 's*/lib$*/bin*'` + case :$dllsearchpath: in + *":$dir:"*) ;; + ::) dllsearchpath=$dir;; + *) func_append dllsearchpath ":$dir";; + esac + case :$dllsearchpath: in + *":$testbindir:"*) ;; + ::) dllsearchpath=$testbindir;; + *) func_append dllsearchpath ":$testbindir";; + esac + ;; + esac + continue + ;; + + -l*) + if test X-lc = "X$arg" || test X-lm = "X$arg"; then + case $host in + *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-beos* | *-cegcc* | *-*-haiku*) + # These systems don't actually have a C or math library (as such) + continue + ;; + *-*-os2*) + # These systems don't actually have a C library (as such) + test X-lc = "X$arg" && continue + ;; + *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig*) + # Do not include libc due to us having libc/libc_r. + test X-lc = "X$arg" && continue + ;; + *-*-rhapsody* | *-*-darwin1.[012]) + # Rhapsody C and math libraries are in the System framework + func_append deplibs " System.ltframework" + continue + ;; + *-*-sco3.2v5* | *-*-sco5v6*) + # Causes problems with __ctype + test X-lc = "X$arg" && continue + ;; + *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*) + # Compiler inserts libc in the correct place for threads to work + test X-lc = "X$arg" && continue + ;; + esac + elif test X-lc_r = "X$arg"; then + case $host in + *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig*) + # Do not include libc_r directly, use -pthread flag. + continue + ;; + esac + fi + func_append deplibs " $arg" + continue + ;; + + -mllvm) + prev=mllvm + continue + ;; + + -module) + module=yes + continue + ;; + + # Tru64 UNIX uses -model [arg] to determine the layout of C++ + # classes, name mangling, and exception handling. + # Darwin uses the -arch flag to determine output architecture. + -model|-arch|-isysroot|--sysroot) + func_append compiler_flags " $arg" + func_append compile_command " $arg" + func_append finalize_command " $arg" + prev=xcompiler + continue + ;; + + -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \ + |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*) + func_append compiler_flags " $arg" + func_append compile_command " $arg" + func_append finalize_command " $arg" + case "$new_inherited_linker_flags " in + *" $arg "*) ;; + * ) func_append new_inherited_linker_flags " $arg" ;; + esac + continue + ;; + + -multi_module) + single_module=$wl-multi_module + continue + ;; + + -no-fast-install) + fast_install=no + continue + ;; + + -no-install) + case $host in + *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*) + # The PATH hackery in wrapper scripts is required on Windows + # and Darwin in order for the loader to find any dlls it needs. + func_warning "'-no-install' is ignored for $host" + func_warning "assuming '-no-fast-install' instead" + fast_install=no + ;; + *) no_install=yes ;; + esac + continue + ;; + + -no-undefined) + allow_undefined=no + continue + ;; + + -objectlist) + prev=objectlist + continue + ;; + + -os2dllname) + prev=os2dllname + continue + ;; + + -o) prev=output ;; + + -precious-files-regex) + prev=precious_regex + continue + ;; + + -release) + prev=release + continue + ;; + + -rpath) + prev=rpath + continue + ;; + + -R) + prev=xrpath + continue + ;; + + -R*) + func_stripname '-R' '' "$arg" + dir=$func_stripname_result + # We need an absolute path. + case $dir in + [\\/]* | [A-Za-z]:[\\/]*) ;; + =*) + func_stripname '=' '' "$dir" + dir=$lt_sysroot$func_stripname_result + ;; + *) + func_fatal_error "only absolute run-paths are allowed" + ;; + esac + case "$xrpath " in + *" $dir "*) ;; + *) func_append xrpath " $dir" ;; + esac + continue + ;; + + -shared) + # The effects of -shared are defined in a previous loop. + continue + ;; + + -shrext) + prev=shrext + continue + ;; + + -static | -static-libtool-libs) + # The effects of -static are defined in a previous loop. + # We used to do the same as -all-static on platforms that + # didn't have a PIC flag, but the assumption that the effects + # would be equivalent was wrong. It would break on at least + # Digital Unix and AIX. + continue + ;; + + -thread-safe) + thread_safe=yes + continue + ;; + + -version-info) + prev=vinfo + continue + ;; + + -version-number) + prev=vinfo + vinfo_number=yes + continue + ;; + + -weak) + prev=weak + continue + ;; + + -Wc,*) + func_stripname '-Wc,' '' "$arg" + args=$func_stripname_result + arg= + save_ifs=$IFS; IFS=, + for flag in $args; do + IFS=$save_ifs + func_quote_for_eval "$flag" + func_append arg " $func_quote_for_eval_result" + func_append compiler_flags " $func_quote_for_eval_result" + done + IFS=$save_ifs + func_stripname ' ' '' "$arg" + arg=$func_stripname_result + ;; + + -Wl,*) + func_stripname '-Wl,' '' "$arg" + args=$func_stripname_result + arg= + save_ifs=$IFS; IFS=, + for flag in $args; do + IFS=$save_ifs + func_quote_for_eval "$flag" + func_append arg " $wl$func_quote_for_eval_result" + func_append compiler_flags " $wl$func_quote_for_eval_result" + func_append linker_flags " $func_quote_for_eval_result" + done + IFS=$save_ifs + func_stripname ' ' '' "$arg" + arg=$func_stripname_result + ;; + + -Xcompiler) + prev=xcompiler + continue + ;; + + -Xlinker) + prev=xlinker + continue + ;; + + -XCClinker) + prev=xcclinker + continue + ;; + + # -msg_* for osf cc + -msg_*) + func_quote_for_eval "$arg" + arg=$func_quote_for_eval_result + ;; + + # Flags to be passed through unchanged, with rationale: + # -64, -mips[0-9] enable 64-bit mode for the SGI compiler + # -r[0-9][0-9]* specify processor for the SGI compiler + # -xarch=*, -xtarget=* enable 64-bit mode for the Sun compiler + # +DA*, +DD* enable 64-bit mode for the HP compiler + # -q* compiler args for the IBM compiler + # -m*, -t[45]*, -txscale* architecture-specific flags for GCC + # -F/path path to uninstalled frameworks, gcc on darwin + # -p, -pg, --coverage, -fprofile-* profiling flags for GCC + # -fstack-protector* stack protector flags for GCC + # @file GCC response files + # -tp=* Portland pgcc target processor selection + # --sysroot=* for sysroot support + # -O*, -g*, -flto*, -fwhopr*, -fuse-linker-plugin GCC link-time optimization + # -specs=* GCC specs files + # -stdlib=* select c++ std lib with clang + # -fsanitize=* Clang/GCC memory and address sanitizer + # -fuse-ld=* Linker select flags for GCC + # -static-* direct GCC to link specific libraries statically + # -fcilkplus Cilk Plus language extension features for C/C++ + -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \ + -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \ + -O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-stdlib=*| \ + -specs=*|-fsanitize=*|-fuse-ld=*|-static-*|-fcilkplus) + func_quote_for_eval "$arg" + arg=$func_quote_for_eval_result + func_append compile_command " $arg" + func_append finalize_command " $arg" + func_append compiler_flags " $arg" + continue + ;; + + -Z*) + if test os2 = "`expr $host : '.*\(os2\)'`"; then + # OS/2 uses -Zxxx to specify OS/2-specific options + compiler_flags="$compiler_flags $arg" + func_append compile_command " $arg" + func_append finalize_command " $arg" + case $arg in + -Zlinker | -Zstack) + prev=xcompiler + ;; + esac + continue + else + # Otherwise treat like 'Some other compiler flag' below + func_quote_for_eval "$arg" + arg=$func_quote_for_eval_result + fi + ;; + + # Some other compiler flag. + -* | +*) + func_quote_for_eval "$arg" + arg=$func_quote_for_eval_result + ;; + + *.$objext) + # A standard object. + func_append objs " $arg" + ;; + + *.lo) + # A libtool-controlled object. + + # Check to see that this really is a libtool object. + if func_lalib_unsafe_p "$arg"; then + pic_object= + non_pic_object= + + # Read the .lo file + func_source "$arg" + + if test -z "$pic_object" || + test -z "$non_pic_object" || + test none = "$pic_object" && + test none = "$non_pic_object"; then + func_fatal_error "cannot find name of object for '$arg'" + fi + + # Extract subdirectory from the argument. + func_dirname "$arg" "/" "" + xdir=$func_dirname_result + + test none = "$pic_object" || { + # Prepend the subdirectory the object is found in. + pic_object=$xdir$pic_object + + if test dlfiles = "$prev"; then + if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then + func_append dlfiles " $pic_object" + prev= + continue + else + # If libtool objects are unsupported, then we need to preload. + prev=dlprefiles + fi + fi + + # CHECK ME: I think I busted this. -Ossama + if test dlprefiles = "$prev"; then + # Preload the old-style object. + func_append dlprefiles " $pic_object" + prev= + fi + + # A PIC object. + func_append libobjs " $pic_object" + arg=$pic_object + } + + # Non-PIC object. + if test none != "$non_pic_object"; then + # Prepend the subdirectory the object is found in. + non_pic_object=$xdir$non_pic_object + + # A standard non-PIC object + func_append non_pic_objects " $non_pic_object" + if test -z "$pic_object" || test none = "$pic_object"; then + arg=$non_pic_object + fi + else + # If the PIC object exists, use it instead. + # $xdir was prepended to $pic_object above. + non_pic_object=$pic_object + func_append non_pic_objects " $non_pic_object" + fi + else + # Only an error if not doing a dry-run. + if $opt_dry_run; then + # Extract subdirectory from the argument. + func_dirname "$arg" "/" "" + xdir=$func_dirname_result + + func_lo2o "$arg" + pic_object=$xdir$objdir/$func_lo2o_result + non_pic_object=$xdir$func_lo2o_result + func_append libobjs " $pic_object" + func_append non_pic_objects " $non_pic_object" + else + func_fatal_error "'$arg' is not a valid libtool object" + fi + fi + ;; + + *.$libext) + # An archive. + func_append deplibs " $arg" + func_append old_deplibs " $arg" + continue + ;; + + *.la) + # A libtool-controlled library. + + func_resolve_sysroot "$arg" + if test dlfiles = "$prev"; then + # This library was specified with -dlopen. + func_append dlfiles " $func_resolve_sysroot_result" + prev= + elif test dlprefiles = "$prev"; then + # The library was specified with -dlpreopen. + func_append dlprefiles " $func_resolve_sysroot_result" + prev= + else + func_append deplibs " $func_resolve_sysroot_result" + fi + continue + ;; + + # Some other compiler argument. + *) + # Unknown arguments in both finalize_command and compile_command need + # to be aesthetically quoted because they are evaled later. + func_quote_for_eval "$arg" + arg=$func_quote_for_eval_result + ;; + esac # arg + + # Now actually substitute the argument into the commands. + if test -n "$arg"; then + func_append compile_command " $arg" + func_append finalize_command " $arg" + fi + done # argument parsing loop + + test -n "$prev" && \ + func_fatal_help "the '$prevarg' option requires an argument" + + if test yes = "$export_dynamic" && test -n "$export_dynamic_flag_spec"; then + eval arg=\"$export_dynamic_flag_spec\" + func_append compile_command " $arg" + func_append finalize_command " $arg" + fi + + oldlibs= + # calculate the name of the file, without its directory + func_basename "$output" + outputname=$func_basename_result + libobjs_save=$libobjs + + if test -n "$shlibpath_var"; then + # get the directories listed in $shlibpath_var + eval shlib_search_path=\`\$ECHO \"\$$shlibpath_var\" \| \$SED \'s/:/ /g\'\` + else + shlib_search_path= + fi + eval sys_lib_search_path=\"$sys_lib_search_path_spec\" + eval sys_lib_dlsearch_path=\"$sys_lib_dlsearch_path_spec\" + + # Definition is injected by LT_CONFIG during libtool generation. + func_munge_path_list sys_lib_dlsearch_path "$LT_SYS_LIBRARY_PATH" + + func_dirname "$output" "/" "" + output_objdir=$func_dirname_result$objdir + func_to_tool_file "$output_objdir/" + tool_output_objdir=$func_to_tool_file_result + # Create the object directory. + func_mkdir_p "$output_objdir" + + # Determine the type of output + case $output in + "") + func_fatal_help "you must specify an output file" + ;; + *.$libext) linkmode=oldlib ;; + *.lo | *.$objext) linkmode=obj ;; + *.la) linkmode=lib ;; + *) linkmode=prog ;; # Anything else should be a program. + esac + + specialdeplibs= + + libs= + # Find all interdependent deplibs by searching for libraries + # that are linked more than once (e.g. -la -lb -la) + for deplib in $deplibs; do + if $opt_preserve_dup_deps; then + case "$libs " in + *" $deplib "*) func_append specialdeplibs " $deplib" ;; + esac + fi + func_append libs " $deplib" + done + + if test lib = "$linkmode"; then + libs="$predeps $libs $compiler_lib_search_path $postdeps" + + # Compute libraries that are listed more than once in $predeps + # $postdeps and mark them as special (i.e., whose duplicates are + # not to be eliminated). + pre_post_deps= + if $opt_duplicate_compiler_generated_deps; then + for pre_post_dep in $predeps $postdeps; do + case "$pre_post_deps " in + *" $pre_post_dep "*) func_append specialdeplibs " $pre_post_deps" ;; + esac + func_append pre_post_deps " $pre_post_dep" + done + fi + pre_post_deps= + fi + + deplibs= + newdependency_libs= + newlib_search_path= + need_relink=no # whether we're linking any uninstalled libtool libraries + notinst_deplibs= # not-installed libtool libraries + notinst_path= # paths that contain not-installed libtool libraries + + case $linkmode in + lib) + passes="conv dlpreopen link" + for file in $dlfiles $dlprefiles; do + case $file in + *.la) ;; + *) + func_fatal_help "libraries can '-dlopen' only libtool libraries: $file" + ;; + esac + done + ;; + prog) + compile_deplibs= + finalize_deplibs= + alldeplibs=false + newdlfiles= + newdlprefiles= + passes="conv scan dlopen dlpreopen link" + ;; + *) passes="conv" + ;; + esac + + for pass in $passes; do + # The preopen pass in lib mode reverses $deplibs; put it back here + # so that -L comes before libs that need it for instance... + if test lib,link = "$linkmode,$pass"; then + ## FIXME: Find the place where the list is rebuilt in the wrong + ## order, and fix it there properly + tmp_deplibs= + for deplib in $deplibs; do + tmp_deplibs="$deplib $tmp_deplibs" + done + deplibs=$tmp_deplibs + fi + + if test lib,link = "$linkmode,$pass" || + test prog,scan = "$linkmode,$pass"; then + libs=$deplibs + deplibs= + fi + if test prog = "$linkmode"; then + case $pass in + dlopen) libs=$dlfiles ;; + dlpreopen) libs=$dlprefiles ;; + link) + libs="$deplibs %DEPLIBS%" + test "X$link_all_deplibs" != Xno && libs="$libs $dependency_libs" + ;; + esac + fi + if test lib,dlpreopen = "$linkmode,$pass"; then + # Collect and forward deplibs of preopened libtool libs + for lib in $dlprefiles; do + # Ignore non-libtool-libs + dependency_libs= + func_resolve_sysroot "$lib" + case $lib in + *.la) func_source "$func_resolve_sysroot_result" ;; + esac + + # Collect preopened libtool deplibs, except any this library + # has declared as weak libs + for deplib in $dependency_libs; do + func_basename "$deplib" + deplib_base=$func_basename_result + case " $weak_libs " in + *" $deplib_base "*) ;; + *) func_append deplibs " $deplib" ;; + esac + done + done + libs=$dlprefiles + fi + if test dlopen = "$pass"; then + # Collect dlpreopened libraries + save_deplibs=$deplibs + deplibs= + fi + + for deplib in $libs; do + lib= + found=false + case $deplib in + -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \ + |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*) + if test prog,link = "$linkmode,$pass"; then + compile_deplibs="$deplib $compile_deplibs" + finalize_deplibs="$deplib $finalize_deplibs" + else + func_append compiler_flags " $deplib" + if test lib = "$linkmode"; then + case "$new_inherited_linker_flags " in + *" $deplib "*) ;; + * ) func_append new_inherited_linker_flags " $deplib" ;; + esac + fi + fi + continue + ;; + -l*) + if test lib != "$linkmode" && test prog != "$linkmode"; then + func_warning "'-l' is ignored for archives/objects" + continue + fi + func_stripname '-l' '' "$deplib" + name=$func_stripname_result + if test lib = "$linkmode"; then + searchdirs="$newlib_search_path $lib_search_path $compiler_lib_search_dirs $sys_lib_search_path $shlib_search_path" + else + searchdirs="$newlib_search_path $lib_search_path $sys_lib_search_path $shlib_search_path" + fi + for searchdir in $searchdirs; do + for search_ext in .la $std_shrext .so .a; do + # Search the libtool library + lib=$searchdir/lib$name$search_ext + if test -f "$lib"; then + if test .la = "$search_ext"; then + found=: + else + found=false + fi + break 2 + fi + done + done + if $found; then + # deplib is a libtool library + # If $allow_libtool_libs_with_static_runtimes && $deplib is a stdlib, + # We need to do some special things here, and not later. + if test yes = "$allow_libtool_libs_with_static_runtimes"; then + case " $predeps $postdeps " in + *" $deplib "*) + if func_lalib_p "$lib"; then + library_names= + old_library= + func_source "$lib" + for l in $old_library $library_names; do + ll=$l + done + if test "X$ll" = "X$old_library"; then # only static version available + found=false + func_dirname "$lib" "" "." + ladir=$func_dirname_result + lib=$ladir/$old_library + if test prog,link = "$linkmode,$pass"; then + compile_deplibs="$deplib $compile_deplibs" + finalize_deplibs="$deplib $finalize_deplibs" + else + deplibs="$deplib $deplibs" + test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs" + fi + continue + fi + fi + ;; + *) ;; + esac + fi + else + # deplib doesn't seem to be a libtool library + if test prog,link = "$linkmode,$pass"; then + compile_deplibs="$deplib $compile_deplibs" + finalize_deplibs="$deplib $finalize_deplibs" + else + deplibs="$deplib $deplibs" + test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs" + fi + continue + fi + ;; # -l + *.ltframework) + if test prog,link = "$linkmode,$pass"; then + compile_deplibs="$deplib $compile_deplibs" + finalize_deplibs="$deplib $finalize_deplibs" + else + deplibs="$deplib $deplibs" + if test lib = "$linkmode"; then + case "$new_inherited_linker_flags " in + *" $deplib "*) ;; + * ) func_append new_inherited_linker_flags " $deplib" ;; + esac + fi + fi + continue + ;; + -L*) + case $linkmode in + lib) + deplibs="$deplib $deplibs" + test conv = "$pass" && continue + newdependency_libs="$deplib $newdependency_libs" + func_stripname '-L' '' "$deplib" + func_resolve_sysroot "$func_stripname_result" + func_append newlib_search_path " $func_resolve_sysroot_result" + ;; + prog) + if test conv = "$pass"; then + deplibs="$deplib $deplibs" + continue + fi + if test scan = "$pass"; then + deplibs="$deplib $deplibs" + else + compile_deplibs="$deplib $compile_deplibs" + finalize_deplibs="$deplib $finalize_deplibs" + fi + func_stripname '-L' '' "$deplib" + func_resolve_sysroot "$func_stripname_result" + func_append newlib_search_path " $func_resolve_sysroot_result" + ;; + *) + func_warning "'-L' is ignored for archives/objects" + ;; + esac # linkmode + continue + ;; # -L + -R*) + if test link = "$pass"; then + func_stripname '-R' '' "$deplib" + func_resolve_sysroot "$func_stripname_result" + dir=$func_resolve_sysroot_result + # Make sure the xrpath contains only unique directories. + case "$xrpath " in + *" $dir "*) ;; + *) func_append xrpath " $dir" ;; + esac + fi + deplibs="$deplib $deplibs" + continue + ;; + *.la) + func_resolve_sysroot "$deplib" + lib=$func_resolve_sysroot_result + ;; + *.$libext) + if test conv = "$pass"; then + deplibs="$deplib $deplibs" + continue + fi + case $linkmode in + lib) + # Linking convenience modules into shared libraries is allowed, + # but linking other static libraries is non-portable. + case " $dlpreconveniencelibs " in + *" $deplib "*) ;; + *) + valid_a_lib=false + case $deplibs_check_method in + match_pattern*) + set dummy $deplibs_check_method; shift + match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"` + if eval "\$ECHO \"$deplib\"" 2>/dev/null | $SED 10q \ + | $EGREP "$match_pattern_regex" > /dev/null; then + valid_a_lib=: + fi + ;; + pass_all) + valid_a_lib=: + ;; + esac + if $valid_a_lib; then + echo + $ECHO "*** Warning: Linking the shared library $output against the" + $ECHO "*** static library $deplib is not portable!" + deplibs="$deplib $deplibs" + else + echo + $ECHO "*** Warning: Trying to link with static lib archive $deplib." + echo "*** I have the capability to make that library automatically link in when" + echo "*** you link to this library. But I can only do this if you have a" + echo "*** shared version of the library, which you do not appear to have" + echo "*** because the file extensions .$libext of this argument makes me believe" + echo "*** that it is just a static archive that I should not use here." + fi + ;; + esac + continue + ;; + prog) + if test link != "$pass"; then + deplibs="$deplib $deplibs" + else + compile_deplibs="$deplib $compile_deplibs" + finalize_deplibs="$deplib $finalize_deplibs" + fi + continue + ;; + esac # linkmode + ;; # *.$libext + *.lo | *.$objext) + if test conv = "$pass"; then + deplibs="$deplib $deplibs" + elif test prog = "$linkmode"; then + if test dlpreopen = "$pass" || test yes != "$dlopen_support" || test no = "$build_libtool_libs"; then + # If there is no dlopen support or we're linking statically, + # we need to preload. + func_append newdlprefiles " $deplib" + compile_deplibs="$deplib $compile_deplibs" + finalize_deplibs="$deplib $finalize_deplibs" + else + func_append newdlfiles " $deplib" + fi + fi + continue + ;; + %DEPLIBS%) + alldeplibs=: + continue + ;; + esac # case $deplib + + $found || test -f "$lib" \ + || func_fatal_error "cannot find the library '$lib' or unhandled argument '$deplib'" + + # Check to see that this really is a libtool archive. + func_lalib_unsafe_p "$lib" \ + || func_fatal_error "'$lib' is not a valid libtool archive" + + func_dirname "$lib" "" "." + ladir=$func_dirname_result + + dlname= + dlopen= + dlpreopen= + libdir= + library_names= + old_library= + inherited_linker_flags= + # If the library was installed with an old release of libtool, + # it will not redefine variables installed, or shouldnotlink + installed=yes + shouldnotlink=no + avoidtemprpath= + + + # Read the .la file + func_source "$lib" + + # Convert "-framework foo" to "foo.ltframework" + if test -n "$inherited_linker_flags"; then + tmp_inherited_linker_flags=`$ECHO "$inherited_linker_flags" | $SED 's/-framework \([^ $]*\)/\1.ltframework/g'` + for tmp_inherited_linker_flag in $tmp_inherited_linker_flags; do + case " $new_inherited_linker_flags " in + *" $tmp_inherited_linker_flag "*) ;; + *) func_append new_inherited_linker_flags " $tmp_inherited_linker_flag";; + esac + done + fi + dependency_libs=`$ECHO " $dependency_libs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'` + if test lib,link = "$linkmode,$pass" || + test prog,scan = "$linkmode,$pass" || + { test prog != "$linkmode" && test lib != "$linkmode"; }; then + test -n "$dlopen" && func_append dlfiles " $dlopen" + test -n "$dlpreopen" && func_append dlprefiles " $dlpreopen" + fi + + if test conv = "$pass"; then + # Only check for convenience libraries + deplibs="$lib $deplibs" + if test -z "$libdir"; then + if test -z "$old_library"; then + func_fatal_error "cannot find name of link library for '$lib'" + fi + # It is a libtool convenience library, so add in its objects. + func_append convenience " $ladir/$objdir/$old_library" + func_append old_convenience " $ladir/$objdir/$old_library" + tmp_libs= + for deplib in $dependency_libs; do + deplibs="$deplib $deplibs" + if $opt_preserve_dup_deps; then + case "$tmp_libs " in + *" $deplib "*) func_append specialdeplibs " $deplib" ;; + esac + fi + func_append tmp_libs " $deplib" + done + elif test prog != "$linkmode" && test lib != "$linkmode"; then + func_fatal_error "'$lib' is not a convenience library" + fi + continue + fi # $pass = conv + + + # Get the name of the library we link against. + linklib= + if test -n "$old_library" && + { test yes = "$prefer_static_libs" || + test built,no = "$prefer_static_libs,$installed"; }; then + linklib=$old_library + else + for l in $old_library $library_names; do + linklib=$l + done + fi + if test -z "$linklib"; then + func_fatal_error "cannot find name of link library for '$lib'" + fi + + # This library was specified with -dlopen. + if test dlopen = "$pass"; then + test -z "$libdir" \ + && func_fatal_error "cannot -dlopen a convenience library: '$lib'" + if test -z "$dlname" || + test yes != "$dlopen_support" || + test no = "$build_libtool_libs" + then + # If there is no dlname, no dlopen support or we're linking + # statically, we need to preload. We also need to preload any + # dependent libraries so libltdl's deplib preloader doesn't + # bomb out in the load deplibs phase. + func_append dlprefiles " $lib $dependency_libs" + else + func_append newdlfiles " $lib" + fi + continue + fi # $pass = dlopen + + # We need an absolute path. + case $ladir in + [\\/]* | [A-Za-z]:[\\/]*) abs_ladir=$ladir ;; + *) + abs_ladir=`cd "$ladir" && pwd` + if test -z "$abs_ladir"; then + func_warning "cannot determine absolute directory name of '$ladir'" + func_warning "passing it literally to the linker, although it might fail" + abs_ladir=$ladir + fi + ;; + esac + func_basename "$lib" + laname=$func_basename_result + + # Find the relevant object directory and library name. + if test yes = "$installed"; then + if test ! -f "$lt_sysroot$libdir/$linklib" && test -f "$abs_ladir/$linklib"; then + func_warning "library '$lib' was moved." + dir=$ladir + absdir=$abs_ladir + libdir=$abs_ladir + else + dir=$lt_sysroot$libdir + absdir=$lt_sysroot$libdir + fi + test yes = "$hardcode_automatic" && avoidtemprpath=yes + else + if test ! -f "$ladir/$objdir/$linklib" && test -f "$abs_ladir/$linklib"; then + dir=$ladir + absdir=$abs_ladir + # Remove this search path later + func_append notinst_path " $abs_ladir" + else + dir=$ladir/$objdir + absdir=$abs_ladir/$objdir + # Remove this search path later + func_append notinst_path " $abs_ladir" + fi + fi # $installed = yes + func_stripname 'lib' '.la' "$laname" + name=$func_stripname_result + + # This library was specified with -dlpreopen. + if test dlpreopen = "$pass"; then + if test -z "$libdir" && test prog = "$linkmode"; then + func_fatal_error "only libraries may -dlpreopen a convenience library: '$lib'" + fi + case $host in + # special handling for platforms with PE-DLLs. + *cygwin* | *mingw* | *cegcc* ) + # Linker will automatically link against shared library if both + # static and shared are present. Therefore, ensure we extract + # symbols from the import library if a shared library is present + # (otherwise, the dlopen module name will be incorrect). We do + # this by putting the import library name into $newdlprefiles. + # We recover the dlopen module name by 'saving' the la file + # name in a special purpose variable, and (later) extracting the + # dlname from the la file. + if test -n "$dlname"; then + func_tr_sh "$dir/$linklib" + eval "libfile_$func_tr_sh_result=\$abs_ladir/\$laname" + func_append newdlprefiles " $dir/$linklib" + else + func_append newdlprefiles " $dir/$old_library" + # Keep a list of preopened convenience libraries to check + # that they are being used correctly in the link pass. + test -z "$libdir" && \ + func_append dlpreconveniencelibs " $dir/$old_library" + fi + ;; + * ) + # Prefer using a static library (so that no silly _DYNAMIC symbols + # are required to link). + if test -n "$old_library"; then + func_append newdlprefiles " $dir/$old_library" + # Keep a list of preopened convenience libraries to check + # that they are being used correctly in the link pass. + test -z "$libdir" && \ + func_append dlpreconveniencelibs " $dir/$old_library" + # Otherwise, use the dlname, so that lt_dlopen finds it. + elif test -n "$dlname"; then + func_append newdlprefiles " $dir/$dlname" + else + func_append newdlprefiles " $dir/$linklib" + fi + ;; + esac + fi # $pass = dlpreopen + + if test -z "$libdir"; then + # Link the convenience library + if test lib = "$linkmode"; then + deplibs="$dir/$old_library $deplibs" + elif test prog,link = "$linkmode,$pass"; then + compile_deplibs="$dir/$old_library $compile_deplibs" + finalize_deplibs="$dir/$old_library $finalize_deplibs" + else + deplibs="$lib $deplibs" # used for prog,scan pass + fi + continue + fi + + + if test prog = "$linkmode" && test link != "$pass"; then + func_append newlib_search_path " $ladir" + deplibs="$lib $deplibs" + + linkalldeplibs=false + if test no != "$link_all_deplibs" || test -z "$library_names" || + test no = "$build_libtool_libs"; then + linkalldeplibs=: + fi + + tmp_libs= + for deplib in $dependency_libs; do + case $deplib in + -L*) func_stripname '-L' '' "$deplib" + func_resolve_sysroot "$func_stripname_result" + func_append newlib_search_path " $func_resolve_sysroot_result" + ;; + esac + # Need to link against all dependency_libs? + if $linkalldeplibs; then + deplibs="$deplib $deplibs" + else + # Need to hardcode shared library paths + # or/and link against static libraries + newdependency_libs="$deplib $newdependency_libs" + fi + if $opt_preserve_dup_deps; then + case "$tmp_libs " in + *" $deplib "*) func_append specialdeplibs " $deplib" ;; + esac + fi + func_append tmp_libs " $deplib" + done # for deplib + continue + fi # $linkmode = prog... + + if test prog,link = "$linkmode,$pass"; then + if test -n "$library_names" && + { { test no = "$prefer_static_libs" || + test built,yes = "$prefer_static_libs,$installed"; } || + test -z "$old_library"; }; then + # We need to hardcode the library path + if test -n "$shlibpath_var" && test -z "$avoidtemprpath"; then + # Make sure the rpath contains only unique directories. + case $temp_rpath: in + *"$absdir:"*) ;; + *) func_append temp_rpath "$absdir:" ;; + esac + fi + + # Hardcode the library path. + # Skip directories that are in the system default run-time + # search path. + case " $sys_lib_dlsearch_path " in + *" $absdir "*) ;; + *) + case "$compile_rpath " in + *" $absdir "*) ;; + *) func_append compile_rpath " $absdir" ;; + esac + ;; + esac + case " $sys_lib_dlsearch_path " in + *" $libdir "*) ;; + *) + case "$finalize_rpath " in + *" $libdir "*) ;; + *) func_append finalize_rpath " $libdir" ;; + esac + ;; + esac + fi # $linkmode,$pass = prog,link... + + if $alldeplibs && + { test pass_all = "$deplibs_check_method" || + { test yes = "$build_libtool_libs" && + test -n "$library_names"; }; }; then + # We only need to search for static libraries + continue + fi + fi + + link_static=no # Whether the deplib will be linked statically + use_static_libs=$prefer_static_libs + if test built = "$use_static_libs" && test yes = "$installed"; then + use_static_libs=no + fi + if test -n "$library_names" && + { test no = "$use_static_libs" || test -z "$old_library"; }; then + case $host in + *cygwin* | *mingw* | *cegcc* | *os2*) + # No point in relinking DLLs because paths are not encoded + func_append notinst_deplibs " $lib" + need_relink=no + ;; + *) + if test no = "$installed"; then + func_append notinst_deplibs " $lib" + need_relink=yes + fi + ;; + esac + # This is a shared library + + # Warn about portability, can't link against -module's on some + # systems (darwin). Don't bleat about dlopened modules though! + dlopenmodule= + for dlpremoduletest in $dlprefiles; do + if test "X$dlpremoduletest" = "X$lib"; then + dlopenmodule=$dlpremoduletest + break + fi + done + if test -z "$dlopenmodule" && test yes = "$shouldnotlink" && test link = "$pass"; then + echo + if test prog = "$linkmode"; then + $ECHO "*** Warning: Linking the executable $output against the loadable module" + else + $ECHO "*** Warning: Linking the shared library $output against the loadable module" + fi + $ECHO "*** $linklib is not portable!" + fi + if test lib = "$linkmode" && + test yes = "$hardcode_into_libs"; then + # Hardcode the library path. + # Skip directories that are in the system default run-time + # search path. + case " $sys_lib_dlsearch_path " in + *" $absdir "*) ;; + *) + case "$compile_rpath " in + *" $absdir "*) ;; + *) func_append compile_rpath " $absdir" ;; + esac + ;; + esac + case " $sys_lib_dlsearch_path " in + *" $libdir "*) ;; + *) + case "$finalize_rpath " in + *" $libdir "*) ;; + *) func_append finalize_rpath " $libdir" ;; + esac + ;; + esac + fi + + if test -n "$old_archive_from_expsyms_cmds"; then + # figure out the soname + set dummy $library_names + shift + realname=$1 + shift + libname=`eval "\\$ECHO \"$libname_spec\""` + # use dlname if we got it. it's perfectly good, no? + if test -n "$dlname"; then + soname=$dlname + elif test -n "$soname_spec"; then + # bleh windows + case $host in + *cygwin* | mingw* | *cegcc* | *os2*) + func_arith $current - $age + major=$func_arith_result + versuffix=-$major + ;; + esac + eval soname=\"$soname_spec\" + else + soname=$realname + fi + + # Make a new name for the extract_expsyms_cmds to use + soroot=$soname + func_basename "$soroot" + soname=$func_basename_result + func_stripname 'lib' '.dll' "$soname" + newlib=libimp-$func_stripname_result.a + + # If the library has no export list, then create one now + if test -f "$output_objdir/$soname-def"; then : + else + func_verbose "extracting exported symbol list from '$soname'" + func_execute_cmds "$extract_expsyms_cmds" 'exit $?' + fi + + # Create $newlib + if test -f "$output_objdir/$newlib"; then :; else + func_verbose "generating import library for '$soname'" + func_execute_cmds "$old_archive_from_expsyms_cmds" 'exit $?' + fi + # make sure the library variables are pointing to the new library + dir=$output_objdir + linklib=$newlib + fi # test -n "$old_archive_from_expsyms_cmds" + + if test prog = "$linkmode" || test relink != "$opt_mode"; then + add_shlibpath= + add_dir= + add= + lib_linked=yes + case $hardcode_action in + immediate | unsupported) + if test no = "$hardcode_direct"; then + add=$dir/$linklib + case $host in + *-*-sco3.2v5.0.[024]*) add_dir=-L$dir ;; + *-*-sysv4*uw2*) add_dir=-L$dir ;; + *-*-sysv5OpenUNIX* | *-*-sysv5UnixWare7.[01].[10]* | \ + *-*-unixware7*) add_dir=-L$dir ;; + *-*-darwin* ) + # if the lib is a (non-dlopened) module then we cannot + # link against it, someone is ignoring the earlier warnings + if /usr/bin/file -L $add 2> /dev/null | + $GREP ": [^:]* bundle" >/dev/null; then + if test "X$dlopenmodule" != "X$lib"; then + $ECHO "*** Warning: lib $linklib is a module, not a shared library" + if test -z "$old_library"; then + echo + echo "*** And there doesn't seem to be a static archive available" + echo "*** The link will probably fail, sorry" + else + add=$dir/$old_library + fi + elif test -n "$old_library"; then + add=$dir/$old_library + fi + fi + esac + elif test no = "$hardcode_minus_L"; then + case $host in + *-*-sunos*) add_shlibpath=$dir ;; + esac + add_dir=-L$dir + add=-l$name + elif test no = "$hardcode_shlibpath_var"; then + add_shlibpath=$dir + add=-l$name + else + lib_linked=no + fi + ;; + relink) + if test yes = "$hardcode_direct" && + test no = "$hardcode_direct_absolute"; then + add=$dir/$linklib + elif test yes = "$hardcode_minus_L"; then + add_dir=-L$absdir + # Try looking first in the location we're being installed to. + if test -n "$inst_prefix_dir"; then + case $libdir in + [\\/]*) + func_append add_dir " -L$inst_prefix_dir$libdir" + ;; + esac + fi + add=-l$name + elif test yes = "$hardcode_shlibpath_var"; then + add_shlibpath=$dir + add=-l$name + else + lib_linked=no + fi + ;; + *) lib_linked=no ;; + esac + + if test yes != "$lib_linked"; then + func_fatal_configuration "unsupported hardcode properties" + fi + + if test -n "$add_shlibpath"; then + case :$compile_shlibpath: in + *":$add_shlibpath:"*) ;; + *) func_append compile_shlibpath "$add_shlibpath:" ;; + esac + fi + if test prog = "$linkmode"; then + test -n "$add_dir" && compile_deplibs="$add_dir $compile_deplibs" + test -n "$add" && compile_deplibs="$add $compile_deplibs" + else + test -n "$add_dir" && deplibs="$add_dir $deplibs" + test -n "$add" && deplibs="$add $deplibs" + if test yes != "$hardcode_direct" && + test yes != "$hardcode_minus_L" && + test yes = "$hardcode_shlibpath_var"; then + case :$finalize_shlibpath: in + *":$libdir:"*) ;; + *) func_append finalize_shlibpath "$libdir:" ;; + esac + fi + fi + fi + + if test prog = "$linkmode" || test relink = "$opt_mode"; then + add_shlibpath= + add_dir= + add= + # Finalize command for both is simple: just hardcode it. + if test yes = "$hardcode_direct" && + test no = "$hardcode_direct_absolute"; then + add=$libdir/$linklib + elif test yes = "$hardcode_minus_L"; then + add_dir=-L$libdir + add=-l$name + elif test yes = "$hardcode_shlibpath_var"; then + case :$finalize_shlibpath: in + *":$libdir:"*) ;; + *) func_append finalize_shlibpath "$libdir:" ;; + esac + add=-l$name + elif test yes = "$hardcode_automatic"; then + if test -n "$inst_prefix_dir" && + test -f "$inst_prefix_dir$libdir/$linklib"; then + add=$inst_prefix_dir$libdir/$linklib + else + add=$libdir/$linklib + fi + else + # We cannot seem to hardcode it, guess we'll fake it. + add_dir=-L$libdir + # Try looking first in the location we're being installed to. + if test -n "$inst_prefix_dir"; then + case $libdir in + [\\/]*) + func_append add_dir " -L$inst_prefix_dir$libdir" + ;; + esac + fi + add=-l$name + fi + + if test prog = "$linkmode"; then + test -n "$add_dir" && finalize_deplibs="$add_dir $finalize_deplibs" + test -n "$add" && finalize_deplibs="$add $finalize_deplibs" + else + test -n "$add_dir" && deplibs="$add_dir $deplibs" + test -n "$add" && deplibs="$add $deplibs" + fi + fi + elif test prog = "$linkmode"; then + # Here we assume that one of hardcode_direct or hardcode_minus_L + # is not unsupported. This is valid on all known static and + # shared platforms. + if test unsupported != "$hardcode_direct"; then + test -n "$old_library" && linklib=$old_library + compile_deplibs="$dir/$linklib $compile_deplibs" + finalize_deplibs="$dir/$linklib $finalize_deplibs" + else + compile_deplibs="-l$name -L$dir $compile_deplibs" + finalize_deplibs="-l$name -L$dir $finalize_deplibs" + fi + elif test yes = "$build_libtool_libs"; then + # Not a shared library + if test pass_all != "$deplibs_check_method"; then + # We're trying link a shared library against a static one + # but the system doesn't support it. + + # Just print a warning and add the library to dependency_libs so + # that the program can be linked against the static library. + echo + $ECHO "*** Warning: This system cannot link to static lib archive $lib." + echo "*** I have the capability to make that library automatically link in when" + echo "*** you link to this library. But I can only do this if you have a" + echo "*** shared version of the library, which you do not appear to have." + if test yes = "$module"; then + echo "*** But as you try to build a module library, libtool will still create " + echo "*** a static module, that should work as long as the dlopening application" + echo "*** is linked with the -dlopen flag to resolve symbols at runtime." + if test -z "$global_symbol_pipe"; then + echo + echo "*** However, this would only work if libtool was able to extract symbol" + echo "*** lists from a program, using 'nm' or equivalent, but libtool could" + echo "*** not find such a program. So, this module is probably useless." + echo "*** 'nm' from GNU binutils and a full rebuild may help." + fi + if test no = "$build_old_libs"; then + build_libtool_libs=module + build_old_libs=yes + else + build_libtool_libs=no + fi + fi + else + deplibs="$dir/$old_library $deplibs" + link_static=yes + fi + fi # link shared/static library? + + if test lib = "$linkmode"; then + if test -n "$dependency_libs" && + { test yes != "$hardcode_into_libs" || + test yes = "$build_old_libs" || + test yes = "$link_static"; }; then + # Extract -R from dependency_libs + temp_deplibs= + for libdir in $dependency_libs; do + case $libdir in + -R*) func_stripname '-R' '' "$libdir" + temp_xrpath=$func_stripname_result + case " $xrpath " in + *" $temp_xrpath "*) ;; + *) func_append xrpath " $temp_xrpath";; + esac;; + *) func_append temp_deplibs " $libdir";; + esac + done + dependency_libs=$temp_deplibs + fi + + func_append newlib_search_path " $absdir" + # Link against this library + test no = "$link_static" && newdependency_libs="$abs_ladir/$laname $newdependency_libs" + # ... and its dependency_libs + tmp_libs= + for deplib in $dependency_libs; do + newdependency_libs="$deplib $newdependency_libs" + case $deplib in + -L*) func_stripname '-L' '' "$deplib" + func_resolve_sysroot "$func_stripname_result";; + *) func_resolve_sysroot "$deplib" ;; + esac + if $opt_preserve_dup_deps; then + case "$tmp_libs " in + *" $func_resolve_sysroot_result "*) + func_append specialdeplibs " $func_resolve_sysroot_result" ;; + esac + fi + func_append tmp_libs " $func_resolve_sysroot_result" + done + + if test no != "$link_all_deplibs"; then + # Add the search paths of all dependency libraries + for deplib in $dependency_libs; do + path= + case $deplib in + -L*) path=$deplib ;; + *.la) + func_resolve_sysroot "$deplib" + deplib=$func_resolve_sysroot_result + func_dirname "$deplib" "" "." + dir=$func_dirname_result + # We need an absolute path. + case $dir in + [\\/]* | [A-Za-z]:[\\/]*) absdir=$dir ;; + *) + absdir=`cd "$dir" && pwd` + if test -z "$absdir"; then + func_warning "cannot determine absolute directory name of '$dir'" + absdir=$dir + fi + ;; + esac + if $GREP "^installed=no" $deplib > /dev/null; then + case $host in + *-*-darwin*) + depdepl= + eval deplibrary_names=`$SED -n -e 's/^library_names=\(.*\)$/\1/p' $deplib` + if test -n "$deplibrary_names"; then + for tmp in $deplibrary_names; do + depdepl=$tmp + done + if test -f "$absdir/$objdir/$depdepl"; then + depdepl=$absdir/$objdir/$depdepl + darwin_install_name=`$OTOOL -L $depdepl | awk '{if (NR == 2) {print $1;exit}}'` + if test -z "$darwin_install_name"; then + darwin_install_name=`$OTOOL64 -L $depdepl | awk '{if (NR == 2) {print $1;exit}}'` + fi + func_append compiler_flags " $wl-dylib_file $wl$darwin_install_name:$depdepl" + func_append linker_flags " -dylib_file $darwin_install_name:$depdepl" + path= + fi + fi + ;; + *) + path=-L$absdir/$objdir + ;; + esac + else + eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $deplib` + test -z "$libdir" && \ + func_fatal_error "'$deplib' is not a valid libtool archive" + test "$absdir" != "$libdir" && \ + func_warning "'$deplib' seems to be moved" + + path=-L$absdir + fi + ;; + esac + case " $deplibs " in + *" $path "*) ;; + *) deplibs="$path $deplibs" ;; + esac + done + fi # link_all_deplibs != no + fi # linkmode = lib + done # for deplib in $libs + if test link = "$pass"; then + if test prog = "$linkmode"; then + compile_deplibs="$new_inherited_linker_flags $compile_deplibs" + finalize_deplibs="$new_inherited_linker_flags $finalize_deplibs" + else + compiler_flags="$compiler_flags "`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'` + fi + fi + dependency_libs=$newdependency_libs + if test dlpreopen = "$pass"; then + # Link the dlpreopened libraries before other libraries + for deplib in $save_deplibs; do + deplibs="$deplib $deplibs" + done + fi + if test dlopen != "$pass"; then + test conv = "$pass" || { + # Make sure lib_search_path contains only unique directories. + lib_search_path= + for dir in $newlib_search_path; do + case "$lib_search_path " in + *" $dir "*) ;; + *) func_append lib_search_path " $dir" ;; + esac + done + newlib_search_path= + } + + if test prog,link = "$linkmode,$pass"; then + vars="compile_deplibs finalize_deplibs" + else + vars=deplibs + fi + for var in $vars dependency_libs; do + # Add libraries to $var in reverse order + eval tmp_libs=\"\$$var\" + new_libs= + for deplib in $tmp_libs; do + # FIXME: Pedantically, this is the right thing to do, so + # that some nasty dependency loop isn't accidentally + # broken: + #new_libs="$deplib $new_libs" + # Pragmatically, this seems to cause very few problems in + # practice: + case $deplib in + -L*) new_libs="$deplib $new_libs" ;; + -R*) ;; + *) + # And here is the reason: when a library appears more + # than once as an explicit dependence of a library, or + # is implicitly linked in more than once by the + # compiler, it is considered special, and multiple + # occurrences thereof are not removed. Compare this + # with having the same library being listed as a + # dependency of multiple other libraries: in this case, + # we know (pedantically, we assume) the library does not + # need to be listed more than once, so we keep only the + # last copy. This is not always right, but it is rare + # enough that we require users that really mean to play + # such unportable linking tricks to link the library + # using -Wl,-lname, so that libtool does not consider it + # for duplicate removal. + case " $specialdeplibs " in + *" $deplib "*) new_libs="$deplib $new_libs" ;; + *) + case " $new_libs " in + *" $deplib "*) ;; + *) new_libs="$deplib $new_libs" ;; + esac + ;; + esac + ;; + esac + done + tmp_libs= + for deplib in $new_libs; do + case $deplib in + -L*) + case " $tmp_libs " in + *" $deplib "*) ;; + *) func_append tmp_libs " $deplib" ;; + esac + ;; + *) func_append tmp_libs " $deplib" ;; + esac + done + eval $var=\"$tmp_libs\" + done # for var + fi + + # Add Sun CC postdeps if required: + test CXX = "$tagname" && { + case $host_os in + linux*) + case `$CC -V 2>&1 | sed 5q` in + *Sun\ C*) # Sun C++ 5.9 + func_suncc_cstd_abi + + if test no != "$suncc_use_cstd_abi"; then + func_append postdeps ' -library=Cstd -library=Crun' + fi + ;; + esac + ;; + + solaris*) + func_cc_basename "$CC" + case $func_cc_basename_result in + CC* | sunCC*) + func_suncc_cstd_abi + + if test no != "$suncc_use_cstd_abi"; then + func_append postdeps ' -library=Cstd -library=Crun' + fi + ;; + esac + ;; + esac + } + + # Last step: remove runtime libs from dependency_libs + # (they stay in deplibs) + tmp_libs= + for i in $dependency_libs; do + case " $predeps $postdeps $compiler_lib_search_path " in + *" $i "*) + i= + ;; + esac + if test -n "$i"; then + func_append tmp_libs " $i" + fi + done + dependency_libs=$tmp_libs + done # for pass + if test prog = "$linkmode"; then + dlfiles=$newdlfiles + fi + if test prog = "$linkmode" || test lib = "$linkmode"; then + dlprefiles=$newdlprefiles + fi + + case $linkmode in + oldlib) + if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then + func_warning "'-dlopen' is ignored for archives" + fi + + case " $deplibs" in + *\ -l* | *\ -L*) + func_warning "'-l' and '-L' are ignored for archives" ;; + esac + + test -n "$rpath" && \ + func_warning "'-rpath' is ignored for archives" + + test -n "$xrpath" && \ + func_warning "'-R' is ignored for archives" + + test -n "$vinfo" && \ + func_warning "'-version-info/-version-number' is ignored for archives" + + test -n "$release" && \ + func_warning "'-release' is ignored for archives" + + test -n "$export_symbols$export_symbols_regex" && \ + func_warning "'-export-symbols' is ignored for archives" + + # Now set the variables for building old libraries. + build_libtool_libs=no + oldlibs=$output + func_append objs "$old_deplibs" + ;; + + lib) + # Make sure we only generate libraries of the form 'libNAME.la'. + case $outputname in + lib*) + func_stripname 'lib' '.la' "$outputname" + name=$func_stripname_result + eval shared_ext=\"$shrext_cmds\" + eval libname=\"$libname_spec\" + ;; + *) + test no = "$module" \ + && func_fatal_help "libtool library '$output' must begin with 'lib'" + + if test no != "$need_lib_prefix"; then + # Add the "lib" prefix for modules if required + func_stripname '' '.la' "$outputname" + name=$func_stripname_result + eval shared_ext=\"$shrext_cmds\" + eval libname=\"$libname_spec\" + else + func_stripname '' '.la' "$outputname" + libname=$func_stripname_result + fi + ;; + esac + + if test -n "$objs"; then + if test pass_all != "$deplibs_check_method"; then + func_fatal_error "cannot build libtool library '$output' from non-libtool objects on this host:$objs" + else + echo + $ECHO "*** Warning: Linking the shared library $output against the non-libtool" + $ECHO "*** objects $objs is not portable!" + func_append libobjs " $objs" + fi + fi + + test no = "$dlself" \ + || func_warning "'-dlopen self' is ignored for libtool libraries" + + set dummy $rpath + shift + test 1 -lt "$#" \ + && func_warning "ignoring multiple '-rpath's for a libtool library" + + install_libdir=$1 + + oldlibs= + if test -z "$rpath"; then + if test yes = "$build_libtool_libs"; then + # Building a libtool convenience library. + # Some compilers have problems with a '.al' extension so + # convenience libraries should have the same extension an + # archive normally would. + oldlibs="$output_objdir/$libname.$libext $oldlibs" + build_libtool_libs=convenience + build_old_libs=yes + fi + + test -n "$vinfo" && \ + func_warning "'-version-info/-version-number' is ignored for convenience libraries" + + test -n "$release" && \ + func_warning "'-release' is ignored for convenience libraries" + else + + # Parse the version information argument. + save_ifs=$IFS; IFS=: + set dummy $vinfo 0 0 0 + shift + IFS=$save_ifs + + test -n "$7" && \ + func_fatal_help "too many parameters to '-version-info'" + + # convert absolute version numbers to libtool ages + # this retains compatibility with .la files and attempts + # to make the code below a bit more comprehensible + + case $vinfo_number in + yes) + number_major=$1 + number_minor=$2 + number_revision=$3 + # + # There are really only two kinds -- those that + # use the current revision as the major version + # and those that subtract age and use age as + # a minor version. But, then there is irix + # that has an extra 1 added just for fun + # + case $version_type in + # correct linux to gnu/linux during the next big refactor + darwin|freebsd-elf|linux|osf|windows|none) + func_arith $number_major + $number_minor + current=$func_arith_result + age=$number_minor + revision=$number_revision + ;; + freebsd-aout|qnx|sunos) + current=$number_major + revision=$number_minor + age=0 + ;; + irix|nonstopux) + func_arith $number_major + $number_minor + current=$func_arith_result + age=$number_minor + revision=$number_minor + lt_irix_increment=no + ;; + *) + func_fatal_configuration "$modename: unknown library version type '$version_type'" + ;; + esac + ;; + no) + current=$1 + revision=$2 + age=$3 + ;; + esac + + # Check that each of the things are valid numbers. + case $current in + 0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;; + *) + func_error "CURRENT '$current' must be a nonnegative integer" + func_fatal_error "'$vinfo' is not valid version information" + ;; + esac + + case $revision in + 0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;; + *) + func_error "REVISION '$revision' must be a nonnegative integer" + func_fatal_error "'$vinfo' is not valid version information" + ;; + esac + + case $age in + 0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;; + *) + func_error "AGE '$age' must be a nonnegative integer" + func_fatal_error "'$vinfo' is not valid version information" + ;; + esac + + if test "$age" -gt "$current"; then + func_error "AGE '$age' is greater than the current interface number '$current'" + func_fatal_error "'$vinfo' is not valid version information" + fi + + # Calculate the version variables. + major= + versuffix= + verstring= + case $version_type in + none) ;; + + darwin) + # Like Linux, but with the current version available in + # verstring for coding it into the library header + func_arith $current - $age + major=.$func_arith_result + versuffix=$major.$age.$revision + # Darwin ld doesn't like 0 for these options... + func_arith $current + 1 + minor_current=$func_arith_result + xlcverstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision" + verstring="-compatibility_version $minor_current -current_version $minor_current.$revision" + # On Darwin other compilers + case $CC in + nagfor*) + verstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision" + ;; + *) + verstring="-compatibility_version $minor_current -current_version $minor_current.$revision" + ;; + esac + ;; + + freebsd-aout) + major=.$current + versuffix=.$current.$revision + ;; + + freebsd-elf) + func_arith $current - $age + major=.$func_arith_result + versuffix=$major.$age.$revision + ;; + + irix | nonstopux) + if test no = "$lt_irix_increment"; then + func_arith $current - $age + else + func_arith $current - $age + 1 + fi + major=$func_arith_result + + case $version_type in + nonstopux) verstring_prefix=nonstopux ;; + *) verstring_prefix=sgi ;; + esac + verstring=$verstring_prefix$major.$revision + + # Add in all the interfaces that we are compatible with. + loop=$revision + while test 0 -ne "$loop"; do + func_arith $revision - $loop + iface=$func_arith_result + func_arith $loop - 1 + loop=$func_arith_result + verstring=$verstring_prefix$major.$iface:$verstring + done + + # Before this point, $major must not contain '.'. + major=.$major + versuffix=$major.$revision + ;; + + linux) # correct to gnu/linux during the next big refactor + func_arith $current - $age + major=.$func_arith_result + versuffix=$major.$age.$revision + ;; + + osf) + func_arith $current - $age + major=.$func_arith_result + versuffix=.$current.$age.$revision + verstring=$current.$age.$revision + + # Add in all the interfaces that we are compatible with. + loop=$age + while test 0 -ne "$loop"; do + func_arith $current - $loop + iface=$func_arith_result + func_arith $loop - 1 + loop=$func_arith_result + verstring=$verstring:$iface.0 + done + + # Make executables depend on our current version. + func_append verstring ":$current.0" + ;; + + qnx) + major=.$current + versuffix=.$current + ;; + + sco) + major=.$current + versuffix=.$current + ;; + + sunos) + major=.$current + versuffix=.$current.$revision + ;; + + windows) + # Use '-' rather than '.', since we only want one + # extension on DOS 8.3 file systems. + func_arith $current - $age + major=$func_arith_result + versuffix=-$major + ;; + + *) + func_fatal_configuration "unknown library version type '$version_type'" + ;; + esac + + # Clear the version info if we defaulted, and they specified a release. + if test -z "$vinfo" && test -n "$release"; then + major= + case $version_type in + darwin) + # we can't check for "0.0" in archive_cmds due to quoting + # problems, so we reset it completely + verstring= + ;; + *) + verstring=0.0 + ;; + esac + if test no = "$need_version"; then + versuffix= + else + versuffix=.0.0 + fi + fi + + # Remove version info from name if versioning should be avoided + if test yes,no = "$avoid_version,$need_version"; then + major= + versuffix= + verstring= + fi + + # Check to see if the archive will have undefined symbols. + if test yes = "$allow_undefined"; then + if test unsupported = "$allow_undefined_flag"; then + if test yes = "$build_old_libs"; then + func_warning "undefined symbols not allowed in $host shared libraries; building static only" + build_libtool_libs=no + else + func_fatal_error "can't build $host shared library unless -no-undefined is specified" + fi + fi + else + # Don't allow undefined symbols. + allow_undefined_flag=$no_undefined_flag + fi + + fi + + func_generate_dlsyms "$libname" "$libname" : + func_append libobjs " $symfileobj" + test " " = "$libobjs" && libobjs= + + if test relink != "$opt_mode"; then + # Remove our outputs, but don't remove object files since they + # may have been created when compiling PIC objects. + removelist= + tempremovelist=`$ECHO "$output_objdir/*"` + for p in $tempremovelist; do + case $p in + *.$objext | *.gcno) + ;; + $output_objdir/$outputname | $output_objdir/$libname.* | $output_objdir/$libname$release.*) + if test -n "$precious_files_regex"; then + if $ECHO "$p" | $EGREP -e "$precious_files_regex" >/dev/null 2>&1 + then + continue + fi + fi + func_append removelist " $p" + ;; + *) ;; + esac + done + test -n "$removelist" && \ + func_show_eval "${RM}r \$removelist" + fi + + # Now set the variables for building old libraries. + if test yes = "$build_old_libs" && test convenience != "$build_libtool_libs"; then + func_append oldlibs " $output_objdir/$libname.$libext" + + # Transform .lo files to .o files. + oldobjs="$objs "`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; $lo2o" | $NL2SP` + fi + + # Eliminate all temporary directories. + #for path in $notinst_path; do + # lib_search_path=`$ECHO "$lib_search_path " | $SED "s% $path % %g"` + # deplibs=`$ECHO "$deplibs " | $SED "s% -L$path % %g"` + # dependency_libs=`$ECHO "$dependency_libs " | $SED "s% -L$path % %g"` + #done + + if test -n "$xrpath"; then + # If the user specified any rpath flags, then add them. + temp_xrpath= + for libdir in $xrpath; do + func_replace_sysroot "$libdir" + func_append temp_xrpath " -R$func_replace_sysroot_result" + case "$finalize_rpath " in + *" $libdir "*) ;; + *) func_append finalize_rpath " $libdir" ;; + esac + done + if test yes != "$hardcode_into_libs" || test yes = "$build_old_libs"; then + dependency_libs="$temp_xrpath $dependency_libs" + fi + fi + + # Make sure dlfiles contains only unique files that won't be dlpreopened + old_dlfiles=$dlfiles + dlfiles= + for lib in $old_dlfiles; do + case " $dlprefiles $dlfiles " in + *" $lib "*) ;; + *) func_append dlfiles " $lib" ;; + esac + done + + # Make sure dlprefiles contains only unique files + old_dlprefiles=$dlprefiles + dlprefiles= + for lib in $old_dlprefiles; do + case "$dlprefiles " in + *" $lib "*) ;; + *) func_append dlprefiles " $lib" ;; + esac + done + + if test yes = "$build_libtool_libs"; then + if test -n "$rpath"; then + case $host in + *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-beos* | *-cegcc* | *-*-haiku*) + # these systems don't actually have a c library (as such)! + ;; + *-*-rhapsody* | *-*-darwin1.[012]) + # Rhapsody C library is in the System framework + func_append deplibs " System.ltframework" + ;; + *-*-netbsd*) + # Don't link with libc until the a.out ld.so is fixed. + ;; + *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*) + # Do not include libc due to us having libc/libc_r. + ;; + *-*-sco3.2v5* | *-*-sco5v6*) + # Causes problems with __ctype + ;; + *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*) + # Compiler inserts libc in the correct place for threads to work + ;; + *) + # Add libc to deplibs on all other systems if necessary. + if test yes = "$build_libtool_need_lc"; then + func_append deplibs " -lc" + fi + ;; + esac + fi + + # Transform deplibs into only deplibs that can be linked in shared. + name_save=$name + libname_save=$libname + release_save=$release + versuffix_save=$versuffix + major_save=$major + # I'm not sure if I'm treating the release correctly. I think + # release should show up in the -l (ie -lgmp5) so we don't want to + # add it in twice. Is that correct? + release= + versuffix= + major= + newdeplibs= + droppeddeps=no + case $deplibs_check_method in + pass_all) + # Don't check for shared/static. Everything works. + # This might be a little naive. We might want to check + # whether the library exists or not. But this is on + # osf3 & osf4 and I'm not really sure... Just + # implementing what was already the behavior. + newdeplibs=$deplibs + ;; + test_compile) + # This code stresses the "libraries are programs" paradigm to its + # limits. Maybe even breaks it. We compile a program, linking it + # against the deplibs as a proxy for the library. Then we can check + # whether they linked in statically or dynamically with ldd. + $opt_dry_run || $RM conftest.c + cat > conftest.c </dev/null` + $nocaseglob + else + potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null` + fi + for potent_lib in $potential_libs; do + # Follow soft links. + if ls -lLd "$potent_lib" 2>/dev/null | + $GREP " -> " >/dev/null; then + continue + fi + # The statement above tries to avoid entering an + # endless loop below, in case of cyclic links. + # We might still enter an endless loop, since a link + # loop can be closed while we follow links, + # but so what? + potlib=$potent_lib + while test -h "$potlib" 2>/dev/null; do + potliblink=`ls -ld $potlib | $SED 's/.* -> //'` + case $potliblink in + [\\/]* | [A-Za-z]:[\\/]*) potlib=$potliblink;; + *) potlib=`$ECHO "$potlib" | $SED 's|[^/]*$||'`"$potliblink";; + esac + done + if eval $file_magic_cmd \"\$potlib\" 2>/dev/null | + $SED -e 10q | + $EGREP "$file_magic_regex" > /dev/null; then + func_append newdeplibs " $a_deplib" + a_deplib= + break 2 + fi + done + done + fi + if test -n "$a_deplib"; then + droppeddeps=yes + echo + $ECHO "*** Warning: linker path does not have real file for library $a_deplib." + echo "*** I have the capability to make that library automatically link in when" + echo "*** you link to this library. But I can only do this if you have a" + echo "*** shared version of the library, which you do not appear to have" + echo "*** because I did check the linker path looking for a file starting" + if test -z "$potlib"; then + $ECHO "*** with $libname but no candidates were found. (...for file magic test)" + else + $ECHO "*** with $libname and none of the candidates passed a file format test" + $ECHO "*** using a file magic. Last file checked: $potlib" + fi + fi + ;; + *) + # Add a -L argument. + func_append newdeplibs " $a_deplib" + ;; + esac + done # Gone through all deplibs. + ;; + match_pattern*) + set dummy $deplibs_check_method; shift + match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"` + for a_deplib in $deplibs; do + case $a_deplib in + -l*) + func_stripname -l '' "$a_deplib" + name=$func_stripname_result + if test yes = "$allow_libtool_libs_with_static_runtimes"; then + case " $predeps $postdeps " in + *" $a_deplib "*) + func_append newdeplibs " $a_deplib" + a_deplib= + ;; + esac + fi + if test -n "$a_deplib"; then + libname=`eval "\\$ECHO \"$libname_spec\""` + for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do + potential_libs=`ls $i/$libname[.-]* 2>/dev/null` + for potent_lib in $potential_libs; do + potlib=$potent_lib # see symlink-check above in file_magic test + if eval "\$ECHO \"$potent_lib\"" 2>/dev/null | $SED 10q | \ + $EGREP "$match_pattern_regex" > /dev/null; then + func_append newdeplibs " $a_deplib" + a_deplib= + break 2 + fi + done + done + fi + if test -n "$a_deplib"; then + droppeddeps=yes + echo + $ECHO "*** Warning: linker path does not have real file for library $a_deplib." + echo "*** I have the capability to make that library automatically link in when" + echo "*** you link to this library. But I can only do this if you have a" + echo "*** shared version of the library, which you do not appear to have" + echo "*** because I did check the linker path looking for a file starting" + if test -z "$potlib"; then + $ECHO "*** with $libname but no candidates were found. (...for regex pattern test)" + else + $ECHO "*** with $libname and none of the candidates passed a file format test" + $ECHO "*** using a regex pattern. Last file checked: $potlib" + fi + fi + ;; + *) + # Add a -L argument. + func_append newdeplibs " $a_deplib" + ;; + esac + done # Gone through all deplibs. + ;; + none | unknown | *) + newdeplibs= + tmp_deplibs=`$ECHO " $deplibs" | $SED 's/ -lc$//; s/ -[LR][^ ]*//g'` + if test yes = "$allow_libtool_libs_with_static_runtimes"; then + for i in $predeps $postdeps; do + # can't use Xsed below, because $i might contain '/' + tmp_deplibs=`$ECHO " $tmp_deplibs" | $SED "s|$i||"` + done + fi + case $tmp_deplibs in + *[!\ \ ]*) + echo + if test none = "$deplibs_check_method"; then + echo "*** Warning: inter-library dependencies are not supported in this platform." + else + echo "*** Warning: inter-library dependencies are not known to be supported." + fi + echo "*** All declared inter-library dependencies are being dropped." + droppeddeps=yes + ;; + esac + ;; + esac + versuffix=$versuffix_save + major=$major_save + release=$release_save + libname=$libname_save + name=$name_save + + case $host in + *-*-rhapsody* | *-*-darwin1.[012]) + # On Rhapsody replace the C library with the System framework + newdeplibs=`$ECHO " $newdeplibs" | $SED 's/ -lc / System.ltframework /'` + ;; + esac + + if test yes = "$droppeddeps"; then + if test yes = "$module"; then + echo + echo "*** Warning: libtool could not satisfy all declared inter-library" + $ECHO "*** dependencies of module $libname. Therefore, libtool will create" + echo "*** a static module, that should work as long as the dlopening" + echo "*** application is linked with the -dlopen flag." + if test -z "$global_symbol_pipe"; then + echo + echo "*** However, this would only work if libtool was able to extract symbol" + echo "*** lists from a program, using 'nm' or equivalent, but libtool could" + echo "*** not find such a program. So, this module is probably useless." + echo "*** 'nm' from GNU binutils and a full rebuild may help." + fi + if test no = "$build_old_libs"; then + oldlibs=$output_objdir/$libname.$libext + build_libtool_libs=module + build_old_libs=yes + else + build_libtool_libs=no + fi + else + echo "*** The inter-library dependencies that have been dropped here will be" + echo "*** automatically added whenever a program is linked with this library" + echo "*** or is declared to -dlopen it." + + if test no = "$allow_undefined"; then + echo + echo "*** Since this library must not contain undefined symbols," + echo "*** because either the platform does not support them or" + echo "*** it was explicitly requested with -no-undefined," + echo "*** libtool will only create a static version of it." + if test no = "$build_old_libs"; then + oldlibs=$output_objdir/$libname.$libext + build_libtool_libs=module + build_old_libs=yes + else + build_libtool_libs=no + fi + fi + fi + fi + # Done checking deplibs! + deplibs=$newdeplibs + fi + # Time to change all our "foo.ltframework" stuff back to "-framework foo" + case $host in + *-*-darwin*) + newdeplibs=`$ECHO " $newdeplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'` + new_inherited_linker_flags=`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'` + deplibs=`$ECHO " $deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'` + ;; + esac + + # move library search paths that coincide with paths to not yet + # installed libraries to the beginning of the library search list + new_libs= + for path in $notinst_path; do + case " $new_libs " in + *" -L$path/$objdir "*) ;; + *) + case " $deplibs " in + *" -L$path/$objdir "*) + func_append new_libs " -L$path/$objdir" ;; + esac + ;; + esac + done + for deplib in $deplibs; do + case $deplib in + -L*) + case " $new_libs " in + *" $deplib "*) ;; + *) func_append new_libs " $deplib" ;; + esac + ;; + *) func_append new_libs " $deplib" ;; + esac + done + deplibs=$new_libs + + # All the library-specific variables (install_libdir is set above). + library_names= + old_library= + dlname= + + # Test again, we may have decided not to build it any more + if test yes = "$build_libtool_libs"; then + # Remove $wl instances when linking with ld. + # FIXME: should test the right _cmds variable. + case $archive_cmds in + *\$LD\ *) wl= ;; + esac + if test yes = "$hardcode_into_libs"; then + # Hardcode the library paths + hardcode_libdirs= + dep_rpath= + rpath=$finalize_rpath + test relink = "$opt_mode" || rpath=$compile_rpath$rpath + for libdir in $rpath; do + if test -n "$hardcode_libdir_flag_spec"; then + if test -n "$hardcode_libdir_separator"; then + func_replace_sysroot "$libdir" + libdir=$func_replace_sysroot_result + if test -z "$hardcode_libdirs"; then + hardcode_libdirs=$libdir + else + # Just accumulate the unique libdirs. + case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in + *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*) + ;; + *) + func_append hardcode_libdirs "$hardcode_libdir_separator$libdir" + ;; + esac + fi + else + eval flag=\"$hardcode_libdir_flag_spec\" + func_append dep_rpath " $flag" + fi + elif test -n "$runpath_var"; then + case "$perm_rpath " in + *" $libdir "*) ;; + *) func_append perm_rpath " $libdir" ;; + esac + fi + done + # Substitute the hardcoded libdirs into the rpath. + if test -n "$hardcode_libdir_separator" && + test -n "$hardcode_libdirs"; then + libdir=$hardcode_libdirs + eval "dep_rpath=\"$hardcode_libdir_flag_spec\"" + fi + if test -n "$runpath_var" && test -n "$perm_rpath"; then + # We should set the runpath_var. + rpath= + for dir in $perm_rpath; do + func_append rpath "$dir:" + done + eval "$runpath_var='$rpath\$$runpath_var'; export $runpath_var" + fi + test -n "$dep_rpath" && deplibs="$dep_rpath $deplibs" + fi + + shlibpath=$finalize_shlibpath + test relink = "$opt_mode" || shlibpath=$compile_shlibpath$shlibpath + if test -n "$shlibpath"; then + eval "$shlibpath_var='$shlibpath\$$shlibpath_var'; export $shlibpath_var" + fi + + # Get the real and link names of the library. + eval shared_ext=\"$shrext_cmds\" + eval library_names=\"$library_names_spec\" + set dummy $library_names + shift + realname=$1 + shift + + if test -n "$soname_spec"; then + eval soname=\"$soname_spec\" + else + soname=$realname + fi + if test -z "$dlname"; then + dlname=$soname + fi + + lib=$output_objdir/$realname + linknames= + for link + do + func_append linknames " $link" + done + + # Use standard objects if they are pic + test -z "$pic_flag" && libobjs=`$ECHO "$libobjs" | $SP2NL | $SED "$lo2o" | $NL2SP` + test "X$libobjs" = "X " && libobjs= + + delfiles= + if test -n "$export_symbols" && test -n "$include_expsyms"; then + $opt_dry_run || cp "$export_symbols" "$output_objdir/$libname.uexp" + export_symbols=$output_objdir/$libname.uexp + func_append delfiles " $export_symbols" + fi + + orig_export_symbols= + case $host_os in + cygwin* | mingw* | cegcc*) + if test -n "$export_symbols" && test -z "$export_symbols_regex"; then + # exporting using user supplied symfile + func_dll_def_p "$export_symbols" || { + # and it's NOT already a .def file. Must figure out + # which of the given symbols are data symbols and tag + # them as such. So, trigger use of export_symbols_cmds. + # export_symbols gets reassigned inside the "prepare + # the list of exported symbols" if statement, so the + # include_expsyms logic still works. + orig_export_symbols=$export_symbols + export_symbols= + always_export_symbols=yes + } + fi + ;; + esac + + # Prepare the list of exported symbols + if test -z "$export_symbols"; then + if test yes = "$always_export_symbols" || test -n "$export_symbols_regex"; then + func_verbose "generating symbol list for '$libname.la'" + export_symbols=$output_objdir/$libname.exp + $opt_dry_run || $RM $export_symbols + cmds=$export_symbols_cmds + save_ifs=$IFS; IFS='~' + for cmd1 in $cmds; do + IFS=$save_ifs + # Take the normal branch if the nm_file_list_spec branch + # doesn't work or if tool conversion is not needed. + case $nm_file_list_spec~$to_tool_file_cmd in + *~func_convert_file_noop | *~func_convert_file_msys_to_w32 | ~*) + try_normal_branch=yes + eval cmd=\"$cmd1\" + func_len " $cmd" + len=$func_len_result + ;; + *) + try_normal_branch=no + ;; + esac + if test yes = "$try_normal_branch" \ + && { test "$len" -lt "$max_cmd_len" \ + || test "$max_cmd_len" -le -1; } + then + func_show_eval "$cmd" 'exit $?' + skipped_export=false + elif test -n "$nm_file_list_spec"; then + func_basename "$output" + output_la=$func_basename_result + save_libobjs=$libobjs + save_output=$output + output=$output_objdir/$output_la.nm + func_to_tool_file "$output" + libobjs=$nm_file_list_spec$func_to_tool_file_result + func_append delfiles " $output" + func_verbose "creating $NM input file list: $output" + for obj in $save_libobjs; do + func_to_tool_file "$obj" + $ECHO "$func_to_tool_file_result" + done > "$output" + eval cmd=\"$cmd1\" + func_show_eval "$cmd" 'exit $?' + output=$save_output + libobjs=$save_libobjs + skipped_export=false + else + # The command line is too long to execute in one step. + func_verbose "using reloadable object file for export list..." + skipped_export=: + # Break out early, otherwise skipped_export may be + # set to false by a later but shorter cmd. + break + fi + done + IFS=$save_ifs + if test -n "$export_symbols_regex" && test : != "$skipped_export"; then + func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"' + func_show_eval '$MV "${export_symbols}T" "$export_symbols"' + fi + fi + fi + + if test -n "$export_symbols" && test -n "$include_expsyms"; then + tmp_export_symbols=$export_symbols + test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols + $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"' + fi + + if test : != "$skipped_export" && test -n "$orig_export_symbols"; then + # The given exports_symbols file has to be filtered, so filter it. + func_verbose "filter symbol list for '$libname.la' to tag DATA exports" + # FIXME: $output_objdir/$libname.filter potentially contains lots of + # 's' commands, which not all seds can handle. GNU sed should be fine + # though. Also, the filter scales superlinearly with the number of + # global variables. join(1) would be nice here, but unfortunately + # isn't a blessed tool. + $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter + func_append delfiles " $export_symbols $output_objdir/$libname.filter" + export_symbols=$output_objdir/$libname.def + $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols + fi + + tmp_deplibs= + for test_deplib in $deplibs; do + case " $convenience " in + *" $test_deplib "*) ;; + *) + func_append tmp_deplibs " $test_deplib" + ;; + esac + done + deplibs=$tmp_deplibs + + if test -n "$convenience"; then + if test -n "$whole_archive_flag_spec" && + test yes = "$compiler_needs_object" && + test -z "$libobjs"; then + # extract the archives, so we have objects to list. + # TODO: could optimize this to just extract one archive. + whole_archive_flag_spec= + fi + if test -n "$whole_archive_flag_spec"; then + save_libobjs=$libobjs + eval libobjs=\"\$libobjs $whole_archive_flag_spec\" + test "X$libobjs" = "X " && libobjs= + else + gentop=$output_objdir/${outputname}x + func_append generated " $gentop" + + func_extract_archives $gentop $convenience + func_append libobjs " $func_extract_archives_result" + test "X$libobjs" = "X " && libobjs= + fi + fi + + if test yes = "$thread_safe" && test -n "$thread_safe_flag_spec"; then + eval flag=\"$thread_safe_flag_spec\" + func_append linker_flags " $flag" + fi + + # Make a backup of the uninstalled library when relinking + if test relink = "$opt_mode"; then + $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}U && $MV $realname ${realname}U)' || exit $? + fi + + # Do each of the archive commands. + if test yes = "$module" && test -n "$module_cmds"; then + if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then + eval test_cmds=\"$module_expsym_cmds\" + cmds=$module_expsym_cmds + else + eval test_cmds=\"$module_cmds\" + cmds=$module_cmds + fi + else + if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then + eval test_cmds=\"$archive_expsym_cmds\" + cmds=$archive_expsym_cmds + else + eval test_cmds=\"$archive_cmds\" + cmds=$archive_cmds + fi + fi + + if test : != "$skipped_export" && + func_len " $test_cmds" && + len=$func_len_result && + test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then + : + else + # The command line is too long to link in one step, link piecewise + # or, if using GNU ld and skipped_export is not :, use a linker + # script. + + # Save the value of $output and $libobjs because we want to + # use them later. If we have whole_archive_flag_spec, we + # want to use save_libobjs as it was before + # whole_archive_flag_spec was expanded, because we can't + # assume the linker understands whole_archive_flag_spec. + # This may have to be revisited, in case too many + # convenience libraries get linked in and end up exceeding + # the spec. + if test -z "$convenience" || test -z "$whole_archive_flag_spec"; then + save_libobjs=$libobjs + fi + save_output=$output + func_basename "$output" + output_la=$func_basename_result + + # Clear the reloadable object creation command queue and + # initialize k to one. + test_cmds= + concat_cmds= + objlist= + last_robj= + k=1 + + if test -n "$save_libobjs" && test : != "$skipped_export" && test yes = "$with_gnu_ld"; then + output=$output_objdir/$output_la.lnkscript + func_verbose "creating GNU ld script: $output" + echo 'INPUT (' > $output + for obj in $save_libobjs + do + func_to_tool_file "$obj" + $ECHO "$func_to_tool_file_result" >> $output + done + echo ')' >> $output + func_append delfiles " $output" + func_to_tool_file "$output" + output=$func_to_tool_file_result + elif test -n "$save_libobjs" && test : != "$skipped_export" && test -n "$file_list_spec"; then + output=$output_objdir/$output_la.lnk + func_verbose "creating linker input file list: $output" + : > $output + set x $save_libobjs + shift + firstobj= + if test yes = "$compiler_needs_object"; then + firstobj="$1 " + shift + fi + for obj + do + func_to_tool_file "$obj" + $ECHO "$func_to_tool_file_result" >> $output + done + func_append delfiles " $output" + func_to_tool_file "$output" + output=$firstobj\"$file_list_spec$func_to_tool_file_result\" + else + if test -n "$save_libobjs"; then + func_verbose "creating reloadable object files..." + output=$output_objdir/$output_la-$k.$objext + eval test_cmds=\"$reload_cmds\" + func_len " $test_cmds" + len0=$func_len_result + len=$len0 + + # Loop over the list of objects to be linked. + for obj in $save_libobjs + do + func_len " $obj" + func_arith $len + $func_len_result + len=$func_arith_result + if test -z "$objlist" || + test "$len" -lt "$max_cmd_len"; then + func_append objlist " $obj" + else + # The command $test_cmds is almost too long, add a + # command to the queue. + if test 1 -eq "$k"; then + # The first file doesn't have a previous command to add. + reload_objs=$objlist + eval concat_cmds=\"$reload_cmds\" + else + # All subsequent reloadable object files will link in + # the last one created. + reload_objs="$objlist $last_robj" + eval concat_cmds=\"\$concat_cmds~$reload_cmds~\$RM $last_robj\" + fi + last_robj=$output_objdir/$output_la-$k.$objext + func_arith $k + 1 + k=$func_arith_result + output=$output_objdir/$output_la-$k.$objext + objlist=" $obj" + func_len " $last_robj" + func_arith $len0 + $func_len_result + len=$func_arith_result + fi + done + # Handle the remaining objects by creating one last + # reloadable object file. All subsequent reloadable object + # files will link in the last one created. + test -z "$concat_cmds" || concat_cmds=$concat_cmds~ + reload_objs="$objlist $last_robj" + eval concat_cmds=\"\$concat_cmds$reload_cmds\" + if test -n "$last_robj"; then + eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\" + fi + func_append delfiles " $output" + + else + output= + fi + + ${skipped_export-false} && { + func_verbose "generating symbol list for '$libname.la'" + export_symbols=$output_objdir/$libname.exp + $opt_dry_run || $RM $export_symbols + libobjs=$output + # Append the command to create the export file. + test -z "$concat_cmds" || concat_cmds=$concat_cmds~ + eval concat_cmds=\"\$concat_cmds$export_symbols_cmds\" + if test -n "$last_robj"; then + eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\" + fi + } + + test -n "$save_libobjs" && + func_verbose "creating a temporary reloadable object file: $output" + + # Loop through the commands generated above and execute them. + save_ifs=$IFS; IFS='~' + for cmd in $concat_cmds; do + IFS=$save_ifs + $opt_quiet || { + func_quote_for_expand "$cmd" + eval "func_echo $func_quote_for_expand_result" + } + $opt_dry_run || eval "$cmd" || { + lt_exit=$? + + # Restore the uninstalled library and exit + if test relink = "$opt_mode"; then + ( cd "$output_objdir" && \ + $RM "${realname}T" && \ + $MV "${realname}U" "$realname" ) + fi + + exit $lt_exit + } + done + IFS=$save_ifs + + if test -n "$export_symbols_regex" && ${skipped_export-false}; then + func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"' + func_show_eval '$MV "${export_symbols}T" "$export_symbols"' + fi + fi + + ${skipped_export-false} && { + if test -n "$export_symbols" && test -n "$include_expsyms"; then + tmp_export_symbols=$export_symbols + test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols + $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"' + fi + + if test -n "$orig_export_symbols"; then + # The given exports_symbols file has to be filtered, so filter it. + func_verbose "filter symbol list for '$libname.la' to tag DATA exports" + # FIXME: $output_objdir/$libname.filter potentially contains lots of + # 's' commands, which not all seds can handle. GNU sed should be fine + # though. Also, the filter scales superlinearly with the number of + # global variables. join(1) would be nice here, but unfortunately + # isn't a blessed tool. + $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter + func_append delfiles " $export_symbols $output_objdir/$libname.filter" + export_symbols=$output_objdir/$libname.def + $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols + fi + } + + libobjs=$output + # Restore the value of output. + output=$save_output + + if test -n "$convenience" && test -n "$whole_archive_flag_spec"; then + eval libobjs=\"\$libobjs $whole_archive_flag_spec\" + test "X$libobjs" = "X " && libobjs= + fi + # Expand the library linking commands again to reset the + # value of $libobjs for piecewise linking. + + # Do each of the archive commands. + if test yes = "$module" && test -n "$module_cmds"; then + if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then + cmds=$module_expsym_cmds + else + cmds=$module_cmds + fi + else + if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then + cmds=$archive_expsym_cmds + else + cmds=$archive_cmds + fi + fi + fi + + if test -n "$delfiles"; then + # Append the command to remove temporary files to $cmds. + eval cmds=\"\$cmds~\$RM $delfiles\" + fi + + # Add any objects from preloaded convenience libraries + if test -n "$dlprefiles"; then + gentop=$output_objdir/${outputname}x + func_append generated " $gentop" + + func_extract_archives $gentop $dlprefiles + func_append libobjs " $func_extract_archives_result" + test "X$libobjs" = "X " && libobjs= + fi + + save_ifs=$IFS; IFS='~' + for cmd in $cmds; do + IFS=$sp$nl + eval cmd=\"$cmd\" + IFS=$save_ifs + $opt_quiet || { + func_quote_for_expand "$cmd" + eval "func_echo $func_quote_for_expand_result" + } + $opt_dry_run || eval "$cmd" || { + lt_exit=$? + + # Restore the uninstalled library and exit + if test relink = "$opt_mode"; then + ( cd "$output_objdir" && \ + $RM "${realname}T" && \ + $MV "${realname}U" "$realname" ) + fi + + exit $lt_exit + } + done + IFS=$save_ifs + + # Restore the uninstalled library and exit + if test relink = "$opt_mode"; then + $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}T && $MV $realname ${realname}T && $MV ${realname}U $realname)' || exit $? + + if test -n "$convenience"; then + if test -z "$whole_archive_flag_spec"; then + func_show_eval '${RM}r "$gentop"' + fi + fi + + exit $EXIT_SUCCESS + fi + + # Create links to the real library. + for linkname in $linknames; do + if test "$realname" != "$linkname"; then + func_show_eval '(cd "$output_objdir" && $RM "$linkname" && $LN_S "$realname" "$linkname")' 'exit $?' + fi + done + + # If -module or -export-dynamic was specified, set the dlname. + if test yes = "$module" || test yes = "$export_dynamic"; then + # On all known operating systems, these are identical. + dlname=$soname + fi + fi + ;; + + obj) + if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then + func_warning "'-dlopen' is ignored for objects" + fi + + case " $deplibs" in + *\ -l* | *\ -L*) + func_warning "'-l' and '-L' are ignored for objects" ;; + esac + + test -n "$rpath" && \ + func_warning "'-rpath' is ignored for objects" + + test -n "$xrpath" && \ + func_warning "'-R' is ignored for objects" + + test -n "$vinfo" && \ + func_warning "'-version-info' is ignored for objects" + + test -n "$release" && \ + func_warning "'-release' is ignored for objects" + + case $output in + *.lo) + test -n "$objs$old_deplibs" && \ + func_fatal_error "cannot build library object '$output' from non-libtool objects" + + libobj=$output + func_lo2o "$libobj" + obj=$func_lo2o_result + ;; + *) + libobj= + obj=$output + ;; + esac + + # Delete the old objects. + $opt_dry_run || $RM $obj $libobj + + # Objects from convenience libraries. This assumes + # single-version convenience libraries. Whenever we create + # different ones for PIC/non-PIC, this we'll have to duplicate + # the extraction. + reload_conv_objs= + gentop= + # if reload_cmds runs $LD directly, get rid of -Wl from + # whole_archive_flag_spec and hope we can get by with turning comma + # into space. + case $reload_cmds in + *\$LD[\ \$]*) wl= ;; + esac + if test -n "$convenience"; then + if test -n "$whole_archive_flag_spec"; then + eval tmp_whole_archive_flags=\"$whole_archive_flag_spec\" + test -n "$wl" || tmp_whole_archive_flags=`$ECHO "$tmp_whole_archive_flags" | $SED 's|,| |g'` + reload_conv_objs=$reload_objs\ $tmp_whole_archive_flags + else + gentop=$output_objdir/${obj}x + func_append generated " $gentop" + + func_extract_archives $gentop $convenience + reload_conv_objs="$reload_objs $func_extract_archives_result" + fi + fi + + # If we're not building shared, we need to use non_pic_objs + test yes = "$build_libtool_libs" || libobjs=$non_pic_objects + + # Create the old-style object. + reload_objs=$objs$old_deplibs' '`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; /\.lib$/d; $lo2o" | $NL2SP`' '$reload_conv_objs + + output=$obj + func_execute_cmds "$reload_cmds" 'exit $?' + + # Exit if we aren't doing a library object file. + if test -z "$libobj"; then + if test -n "$gentop"; then + func_show_eval '${RM}r "$gentop"' + fi + + exit $EXIT_SUCCESS + fi + + test yes = "$build_libtool_libs" || { + if test -n "$gentop"; then + func_show_eval '${RM}r "$gentop"' + fi + + # Create an invalid libtool object if no PIC, so that we don't + # accidentally link it into a program. + # $show "echo timestamp > $libobj" + # $opt_dry_run || eval "echo timestamp > $libobj" || exit $? + exit $EXIT_SUCCESS + } + + if test -n "$pic_flag" || test default != "$pic_mode"; then + # Only do commands if we really have different PIC objects. + reload_objs="$libobjs $reload_conv_objs" + output=$libobj + func_execute_cmds "$reload_cmds" 'exit $?' + fi + + if test -n "$gentop"; then + func_show_eval '${RM}r "$gentop"' + fi + + exit $EXIT_SUCCESS + ;; + + prog) + case $host in + *cygwin*) func_stripname '' '.exe' "$output" + output=$func_stripname_result.exe;; + esac + test -n "$vinfo" && \ + func_warning "'-version-info' is ignored for programs" + + test -n "$release" && \ + func_warning "'-release' is ignored for programs" + + $preload \ + && test unknown,unknown,unknown = "$dlopen_support,$dlopen_self,$dlopen_self_static" \ + && func_warning "'LT_INIT([dlopen])' not used. Assuming no dlopen support." + + case $host in + *-*-rhapsody* | *-*-darwin1.[012]) + # On Rhapsody replace the C library is the System framework + compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's/ -lc / System.ltframework /'` + finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's/ -lc / System.ltframework /'` + ;; + esac + + case $host in + *-*-darwin*) + # Don't allow lazy linking, it breaks C++ global constructors + # But is supposedly fixed on 10.4 or later (yay!). + if test CXX = "$tagname"; then + case ${MACOSX_DEPLOYMENT_TARGET-10.0} in + 10.[0123]) + func_append compile_command " $wl-bind_at_load" + func_append finalize_command " $wl-bind_at_load" + ;; + esac + fi + # Time to change all our "foo.ltframework" stuff back to "-framework foo" + compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'` + finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'` + ;; + esac + + + # move library search paths that coincide with paths to not yet + # installed libraries to the beginning of the library search list + new_libs= + for path in $notinst_path; do + case " $new_libs " in + *" -L$path/$objdir "*) ;; + *) + case " $compile_deplibs " in + *" -L$path/$objdir "*) + func_append new_libs " -L$path/$objdir" ;; + esac + ;; + esac + done + for deplib in $compile_deplibs; do + case $deplib in + -L*) + case " $new_libs " in + *" $deplib "*) ;; + *) func_append new_libs " $deplib" ;; + esac + ;; + *) func_append new_libs " $deplib" ;; + esac + done + compile_deplibs=$new_libs + + + func_append compile_command " $compile_deplibs" + func_append finalize_command " $finalize_deplibs" + + if test -n "$rpath$xrpath"; then + # If the user specified any rpath flags, then add them. + for libdir in $rpath $xrpath; do + # This is the magic to use -rpath. + case "$finalize_rpath " in + *" $libdir "*) ;; + *) func_append finalize_rpath " $libdir" ;; + esac + done + fi + + # Now hardcode the library paths + rpath= + hardcode_libdirs= + for libdir in $compile_rpath $finalize_rpath; do + if test -n "$hardcode_libdir_flag_spec"; then + if test -n "$hardcode_libdir_separator"; then + if test -z "$hardcode_libdirs"; then + hardcode_libdirs=$libdir + else + # Just accumulate the unique libdirs. + case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in + *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*) + ;; + *) + func_append hardcode_libdirs "$hardcode_libdir_separator$libdir" + ;; + esac + fi + else + eval flag=\"$hardcode_libdir_flag_spec\" + func_append rpath " $flag" + fi + elif test -n "$runpath_var"; then + case "$perm_rpath " in + *" $libdir "*) ;; + *) func_append perm_rpath " $libdir" ;; + esac + fi + case $host in + *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*) + testbindir=`$ECHO "$libdir" | $SED -e 's*/lib$*/bin*'` + case :$dllsearchpath: in + *":$libdir:"*) ;; + ::) dllsearchpath=$libdir;; + *) func_append dllsearchpath ":$libdir";; + esac + case :$dllsearchpath: in + *":$testbindir:"*) ;; + ::) dllsearchpath=$testbindir;; + *) func_append dllsearchpath ":$testbindir";; + esac + ;; + esac + done + # Substitute the hardcoded libdirs into the rpath. + if test -n "$hardcode_libdir_separator" && + test -n "$hardcode_libdirs"; then + libdir=$hardcode_libdirs + eval rpath=\" $hardcode_libdir_flag_spec\" + fi + compile_rpath=$rpath + + rpath= + hardcode_libdirs= + for libdir in $finalize_rpath; do + if test -n "$hardcode_libdir_flag_spec"; then + if test -n "$hardcode_libdir_separator"; then + if test -z "$hardcode_libdirs"; then + hardcode_libdirs=$libdir + else + # Just accumulate the unique libdirs. + case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in + *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*) + ;; + *) + func_append hardcode_libdirs "$hardcode_libdir_separator$libdir" + ;; + esac + fi + else + eval flag=\"$hardcode_libdir_flag_spec\" + func_append rpath " $flag" + fi + elif test -n "$runpath_var"; then + case "$finalize_perm_rpath " in + *" $libdir "*) ;; + *) func_append finalize_perm_rpath " $libdir" ;; + esac + fi + done + # Substitute the hardcoded libdirs into the rpath. + if test -n "$hardcode_libdir_separator" && + test -n "$hardcode_libdirs"; then + libdir=$hardcode_libdirs + eval rpath=\" $hardcode_libdir_flag_spec\" + fi + finalize_rpath=$rpath + + if test -n "$libobjs" && test yes = "$build_old_libs"; then + # Transform all the library objects into standard objects. + compile_command=`$ECHO "$compile_command" | $SP2NL | $SED "$lo2o" | $NL2SP` + finalize_command=`$ECHO "$finalize_command" | $SP2NL | $SED "$lo2o" | $NL2SP` + fi + + func_generate_dlsyms "$outputname" "@PROGRAM@" false + + # template prelinking step + if test -n "$prelink_cmds"; then + func_execute_cmds "$prelink_cmds" 'exit $?' + fi + + wrappers_required=: + case $host in + *cegcc* | *mingw32ce*) + # Disable wrappers for cegcc and mingw32ce hosts, we are cross compiling anyway. + wrappers_required=false + ;; + *cygwin* | *mingw* ) + test yes = "$build_libtool_libs" || wrappers_required=false + ;; + *) + if test no = "$need_relink" || test yes != "$build_libtool_libs"; then + wrappers_required=false + fi + ;; + esac + $wrappers_required || { + # Replace the output file specification. + compile_command=`$ECHO "$compile_command" | $SED 's%@OUTPUT@%'"$output"'%g'` + link_command=$compile_command$compile_rpath + + # We have no uninstalled library dependencies, so finalize right now. + exit_status=0 + func_show_eval "$link_command" 'exit_status=$?' + + if test -n "$postlink_cmds"; then + func_to_tool_file "$output" + postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'` + func_execute_cmds "$postlink_cmds" 'exit $?' + fi + + # Delete the generated files. + if test -f "$output_objdir/${outputname}S.$objext"; then + func_show_eval '$RM "$output_objdir/${outputname}S.$objext"' + fi + + exit $exit_status + } + + if test -n "$compile_shlibpath$finalize_shlibpath"; then + compile_command="$shlibpath_var=\"$compile_shlibpath$finalize_shlibpath\$$shlibpath_var\" $compile_command" + fi + if test -n "$finalize_shlibpath"; then + finalize_command="$shlibpath_var=\"$finalize_shlibpath\$$shlibpath_var\" $finalize_command" + fi + + compile_var= + finalize_var= + if test -n "$runpath_var"; then + if test -n "$perm_rpath"; then + # We should set the runpath_var. + rpath= + for dir in $perm_rpath; do + func_append rpath "$dir:" + done + compile_var="$runpath_var=\"$rpath\$$runpath_var\" " + fi + if test -n "$finalize_perm_rpath"; then + # We should set the runpath_var. + rpath= + for dir in $finalize_perm_rpath; do + func_append rpath "$dir:" + done + finalize_var="$runpath_var=\"$rpath\$$runpath_var\" " + fi + fi + + if test yes = "$no_install"; then + # We don't need to create a wrapper script. + link_command=$compile_var$compile_command$compile_rpath + # Replace the output file specification. + link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output"'%g'` + # Delete the old output file. + $opt_dry_run || $RM $output + # Link the executable and exit + func_show_eval "$link_command" 'exit $?' + + if test -n "$postlink_cmds"; then + func_to_tool_file "$output" + postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'` + func_execute_cmds "$postlink_cmds" 'exit $?' + fi + + exit $EXIT_SUCCESS + fi + + case $hardcode_action,$fast_install in + relink,*) + # Fast installation is not supported + link_command=$compile_var$compile_command$compile_rpath + relink_command=$finalize_var$finalize_command$finalize_rpath + + func_warning "this platform does not like uninstalled shared libraries" + func_warning "'$output' will be relinked during installation" + ;; + *,yes) + link_command=$finalize_var$compile_command$finalize_rpath + relink_command=`$ECHO "$compile_var$compile_command$compile_rpath" | $SED 's%@OUTPUT@%\$progdir/\$file%g'` + ;; + *,no) + link_command=$compile_var$compile_command$compile_rpath + relink_command=$finalize_var$finalize_command$finalize_rpath + ;; + *,needless) + link_command=$finalize_var$compile_command$finalize_rpath + relink_command= + ;; + esac + + # Replace the output file specification. + link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output_objdir/$outputname"'%g'` + + # Delete the old output files. + $opt_dry_run || $RM $output $output_objdir/$outputname $output_objdir/lt-$outputname + + func_show_eval "$link_command" 'exit $?' + + if test -n "$postlink_cmds"; then + func_to_tool_file "$output_objdir/$outputname" + postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output_objdir/$outputname"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'` + func_execute_cmds "$postlink_cmds" 'exit $?' + fi + + # Now create the wrapper script. + func_verbose "creating $output" + + # Quote the relink command for shipping. + if test -n "$relink_command"; then + # Preserve any variables that may affect compiler behavior + for var in $variables_saved_for_relink; do + if eval test -z \"\${$var+set}\"; then + relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command" + elif eval var_value=\$$var; test -z "$var_value"; then + relink_command="$var=; export $var; $relink_command" + else + func_quote_for_eval "$var_value" + relink_command="$var=$func_quote_for_eval_result; export $var; $relink_command" + fi + done + relink_command="(cd `pwd`; $relink_command)" + relink_command=`$ECHO "$relink_command" | $SED "$sed_quote_subst"` + fi + + # Only actually do things if not in dry run mode. + $opt_dry_run || { + # win32 will think the script is a binary if it has + # a .exe suffix, so we strip it off here. + case $output in + *.exe) func_stripname '' '.exe' "$output" + output=$func_stripname_result ;; + esac + # test for cygwin because mv fails w/o .exe extensions + case $host in + *cygwin*) + exeext=.exe + func_stripname '' '.exe' "$outputname" + outputname=$func_stripname_result ;; + *) exeext= ;; + esac + case $host in + *cygwin* | *mingw* ) + func_dirname_and_basename "$output" "" "." + output_name=$func_basename_result + output_path=$func_dirname_result + cwrappersource=$output_path/$objdir/lt-$output_name.c + cwrapper=$output_path/$output_name.exe + $RM $cwrappersource $cwrapper + trap "$RM $cwrappersource $cwrapper; exit $EXIT_FAILURE" 1 2 15 + + func_emit_cwrapperexe_src > $cwrappersource + + # The wrapper executable is built using the $host compiler, + # because it contains $host paths and files. If cross- + # compiling, it, like the target executable, must be + # executed on the $host or under an emulation environment. + $opt_dry_run || { + $LTCC $LTCFLAGS -o $cwrapper $cwrappersource + $STRIP $cwrapper + } + + # Now, create the wrapper script for func_source use: + func_ltwrapper_scriptname $cwrapper + $RM $func_ltwrapper_scriptname_result + trap "$RM $func_ltwrapper_scriptname_result; exit $EXIT_FAILURE" 1 2 15 + $opt_dry_run || { + # note: this script will not be executed, so do not chmod. + if test "x$build" = "x$host"; then + $cwrapper --lt-dump-script > $func_ltwrapper_scriptname_result + else + func_emit_wrapper no > $func_ltwrapper_scriptname_result + fi + } + ;; + * ) + $RM $output + trap "$RM $output; exit $EXIT_FAILURE" 1 2 15 + + func_emit_wrapper no > $output + chmod +x $output + ;; + esac + } + exit $EXIT_SUCCESS + ;; + esac + + # See if we need to build an old-fashioned archive. + for oldlib in $oldlibs; do + + case $build_libtool_libs in + convenience) + oldobjs="$libobjs_save $symfileobj" + addlibs=$convenience + build_libtool_libs=no + ;; + module) + oldobjs=$libobjs_save + addlibs=$old_convenience + build_libtool_libs=no + ;; + *) + oldobjs="$old_deplibs $non_pic_objects" + $preload && test -f "$symfileobj" \ + && func_append oldobjs " $symfileobj" + addlibs=$old_convenience + ;; + esac + + if test -n "$addlibs"; then + gentop=$output_objdir/${outputname}x + func_append generated " $gentop" + + func_extract_archives $gentop $addlibs + func_append oldobjs " $func_extract_archives_result" + fi + + # Do each command in the archive commands. + if test -n "$old_archive_from_new_cmds" && test yes = "$build_libtool_libs"; then + cmds=$old_archive_from_new_cmds + else + + # Add any objects from preloaded convenience libraries + if test -n "$dlprefiles"; then + gentop=$output_objdir/${outputname}x + func_append generated " $gentop" + + func_extract_archives $gentop $dlprefiles + func_append oldobjs " $func_extract_archives_result" + fi + + # POSIX demands no paths to be encoded in archives. We have + # to avoid creating archives with duplicate basenames if we + # might have to extract them afterwards, e.g., when creating a + # static archive out of a convenience library, or when linking + # the entirety of a libtool archive into another (currently + # not supported by libtool). + if (for obj in $oldobjs + do + func_basename "$obj" + $ECHO "$func_basename_result" + done | sort | sort -uc >/dev/null 2>&1); then + : + else + echo "copying selected object files to avoid basename conflicts..." + gentop=$output_objdir/${outputname}x + func_append generated " $gentop" + func_mkdir_p "$gentop" + save_oldobjs=$oldobjs + oldobjs= + counter=1 + for obj in $save_oldobjs + do + func_basename "$obj" + objbase=$func_basename_result + case " $oldobjs " in + " ") oldobjs=$obj ;; + *[\ /]"$objbase "*) + while :; do + # Make sure we don't pick an alternate name that also + # overlaps. + newobj=lt$counter-$objbase + func_arith $counter + 1 + counter=$func_arith_result + case " $oldobjs " in + *[\ /]"$newobj "*) ;; + *) if test ! -f "$gentop/$newobj"; then break; fi ;; + esac + done + func_show_eval "ln $obj $gentop/$newobj || cp $obj $gentop/$newobj" + func_append oldobjs " $gentop/$newobj" + ;; + *) func_append oldobjs " $obj" ;; + esac + done + fi + func_to_tool_file "$oldlib" func_convert_file_msys_to_w32 + tool_oldlib=$func_to_tool_file_result + eval cmds=\"$old_archive_cmds\" + + func_len " $cmds" + len=$func_len_result + if test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then + cmds=$old_archive_cmds + elif test -n "$archiver_list_spec"; then + func_verbose "using command file archive linking..." + for obj in $oldobjs + do + func_to_tool_file "$obj" + $ECHO "$func_to_tool_file_result" + done > $output_objdir/$libname.libcmd + func_to_tool_file "$output_objdir/$libname.libcmd" + oldobjs=" $archiver_list_spec$func_to_tool_file_result" + cmds=$old_archive_cmds + else + # the command line is too long to link in one step, link in parts + func_verbose "using piecewise archive linking..." + save_RANLIB=$RANLIB + RANLIB=: + objlist= + concat_cmds= + save_oldobjs=$oldobjs + oldobjs= + # Is there a better way of finding the last object in the list? + for obj in $save_oldobjs + do + last_oldobj=$obj + done + eval test_cmds=\"$old_archive_cmds\" + func_len " $test_cmds" + len0=$func_len_result + len=$len0 + for obj in $save_oldobjs + do + func_len " $obj" + func_arith $len + $func_len_result + len=$func_arith_result + func_append objlist " $obj" + if test "$len" -lt "$max_cmd_len"; then + : + else + # the above command should be used before it gets too long + oldobjs=$objlist + if test "$obj" = "$last_oldobj"; then + RANLIB=$save_RANLIB + fi + test -z "$concat_cmds" || concat_cmds=$concat_cmds~ + eval concat_cmds=\"\$concat_cmds$old_archive_cmds\" + objlist= + len=$len0 + fi + done + RANLIB=$save_RANLIB + oldobjs=$objlist + if test -z "$oldobjs"; then + eval cmds=\"\$concat_cmds\" + else + eval cmds=\"\$concat_cmds~\$old_archive_cmds\" + fi + fi + fi + func_execute_cmds "$cmds" 'exit $?' + done + + test -n "$generated" && \ + func_show_eval "${RM}r$generated" + + # Now create the libtool archive. + case $output in + *.la) + old_library= + test yes = "$build_old_libs" && old_library=$libname.$libext + func_verbose "creating $output" + + # Preserve any variables that may affect compiler behavior + for var in $variables_saved_for_relink; do + if eval test -z \"\${$var+set}\"; then + relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command" + elif eval var_value=\$$var; test -z "$var_value"; then + relink_command="$var=; export $var; $relink_command" + else + func_quote_for_eval "$var_value" + relink_command="$var=$func_quote_for_eval_result; export $var; $relink_command" + fi + done + # Quote the link command for shipping. + relink_command="(cd `pwd`; $SHELL \"$progpath\" $preserve_args --mode=relink $libtool_args @inst_prefix_dir@)" + relink_command=`$ECHO "$relink_command" | $SED "$sed_quote_subst"` + if test yes = "$hardcode_automatic"; then + relink_command= + fi + + # Only create the output if not a dry run. + $opt_dry_run || { + for installed in no yes; do + if test yes = "$installed"; then + if test -z "$install_libdir"; then + break + fi + output=$output_objdir/${outputname}i + # Replace all uninstalled libtool libraries with the installed ones + newdependency_libs= + for deplib in $dependency_libs; do + case $deplib in + *.la) + func_basename "$deplib" + name=$func_basename_result + func_resolve_sysroot "$deplib" + eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $func_resolve_sysroot_result` + test -z "$libdir" && \ + func_fatal_error "'$deplib' is not a valid libtool archive" + func_append newdependency_libs " ${lt_sysroot:+=}$libdir/$name" + ;; + -L*) + func_stripname -L '' "$deplib" + func_replace_sysroot "$func_stripname_result" + func_append newdependency_libs " -L$func_replace_sysroot_result" + ;; + -R*) + func_stripname -R '' "$deplib" + func_replace_sysroot "$func_stripname_result" + func_append newdependency_libs " -R$func_replace_sysroot_result" + ;; + *) func_append newdependency_libs " $deplib" ;; + esac + done + dependency_libs=$newdependency_libs + newdlfiles= + + for lib in $dlfiles; do + case $lib in + *.la) + func_basename "$lib" + name=$func_basename_result + eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib` + test -z "$libdir" && \ + func_fatal_error "'$lib' is not a valid libtool archive" + func_append newdlfiles " ${lt_sysroot:+=}$libdir/$name" + ;; + *) func_append newdlfiles " $lib" ;; + esac + done + dlfiles=$newdlfiles + newdlprefiles= + for lib in $dlprefiles; do + case $lib in + *.la) + # Only pass preopened files to the pseudo-archive (for + # eventual linking with the app. that links it) if we + # didn't already link the preopened objects directly into + # the library: + func_basename "$lib" + name=$func_basename_result + eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib` + test -z "$libdir" && \ + func_fatal_error "'$lib' is not a valid libtool archive" + func_append newdlprefiles " ${lt_sysroot:+=}$libdir/$name" + ;; + esac + done + dlprefiles=$newdlprefiles + else + newdlfiles= + for lib in $dlfiles; do + case $lib in + [\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;; + *) abs=`pwd`"/$lib" ;; + esac + func_append newdlfiles " $abs" + done + dlfiles=$newdlfiles + newdlprefiles= + for lib in $dlprefiles; do + case $lib in + [\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;; + *) abs=`pwd`"/$lib" ;; + esac + func_append newdlprefiles " $abs" + done + dlprefiles=$newdlprefiles + fi + $RM $output + # place dlname in correct position for cygwin + # In fact, it would be nice if we could use this code for all target + # systems that can't hard-code library paths into their executables + # and that have no shared library path variable independent of PATH, + # but it turns out we can't easily determine that from inspecting + # libtool variables, so we have to hard-code the OSs to which it + # applies here; at the moment, that means platforms that use the PE + # object format with DLL files. See the long comment at the top of + # tests/bindir.at for full details. + tdlname=$dlname + case $host,$output,$installed,$module,$dlname in + *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll | *cegcc*,*lai,yes,no,*.dll) + # If a -bindir argument was supplied, place the dll there. + if test -n "$bindir"; then + func_relative_path "$install_libdir" "$bindir" + tdlname=$func_relative_path_result/$dlname + else + # Otherwise fall back on heuristic. + tdlname=../bin/$dlname + fi + ;; + esac + $ECHO > $output "\ +# $outputname - a libtool library file +# Generated by $PROGRAM (GNU $PACKAGE) $VERSION +# +# Please DO NOT delete this file! +# It is necessary for linking the library. + +# The name that we can dlopen(3). +dlname='$tdlname' + +# Names of this library. +library_names='$library_names' + +# The name of the static archive. +old_library='$old_library' + +# Linker flags that cannot go in dependency_libs. +inherited_linker_flags='$new_inherited_linker_flags' + +# Libraries that this one depends upon. +dependency_libs='$dependency_libs' + +# Names of additional weak libraries provided by this library +weak_library_names='$weak_libs' + +# Version information for $libname. +current=$current +age=$age +revision=$revision + +# Is this an already installed library? +installed=$installed + +# Should we warn about portability when linking against -modules? +shouldnotlink=$module + +# Files to dlopen/dlpreopen +dlopen='$dlfiles' +dlpreopen='$dlprefiles' + +# Directory that this library needs to be installed in: +libdir='$install_libdir'" + if test no,yes = "$installed,$need_relink"; then + $ECHO >> $output "\ +relink_command=\"$relink_command\"" + fi + done + } + + # Do a symbolic link so that the libtool archive can be found in + # LD_LIBRARY_PATH before the program is installed. + func_show_eval '( cd "$output_objdir" && $RM "$outputname" && $LN_S "../$outputname" "$outputname" )' 'exit $?' + ;; + esac + exit $EXIT_SUCCESS +} + +if test link = "$opt_mode" || test relink = "$opt_mode"; then + func_mode_link ${1+"$@"} +fi + + +# func_mode_uninstall arg... +func_mode_uninstall () +{ + $debug_cmd + + RM=$nonopt + files= + rmforce=false + exit_status=0 + + # This variable tells wrapper scripts just to set variables rather + # than running their programs. + libtool_install_magic=$magic + + for arg + do + case $arg in + -f) func_append RM " $arg"; rmforce=: ;; + -*) func_append RM " $arg" ;; + *) func_append files " $arg" ;; + esac + done + + test -z "$RM" && \ + func_fatal_help "you must specify an RM program" + + rmdirs= + + for file in $files; do + func_dirname "$file" "" "." + dir=$func_dirname_result + if test . = "$dir"; then + odir=$objdir + else + odir=$dir/$objdir + fi + func_basename "$file" + name=$func_basename_result + test uninstall = "$opt_mode" && odir=$dir + + # Remember odir for removal later, being careful to avoid duplicates + if test clean = "$opt_mode"; then + case " $rmdirs " in + *" $odir "*) ;; + *) func_append rmdirs " $odir" ;; + esac + fi + + # Don't error if the file doesn't exist and rm -f was used. + if { test -L "$file"; } >/dev/null 2>&1 || + { test -h "$file"; } >/dev/null 2>&1 || + test -f "$file"; then + : + elif test -d "$file"; then + exit_status=1 + continue + elif $rmforce; then + continue + fi + + rmfiles=$file + + case $name in + *.la) + # Possibly a libtool archive, so verify it. + if func_lalib_p "$file"; then + func_source $dir/$name + + # Delete the libtool libraries and symlinks. + for n in $library_names; do + func_append rmfiles " $odir/$n" + done + test -n "$old_library" && func_append rmfiles " $odir/$old_library" + + case $opt_mode in + clean) + case " $library_names " in + *" $dlname "*) ;; + *) test -n "$dlname" && func_append rmfiles " $odir/$dlname" ;; + esac + test -n "$libdir" && func_append rmfiles " $odir/$name $odir/${name}i" + ;; + uninstall) + if test -n "$library_names"; then + # Do each command in the postuninstall commands. + func_execute_cmds "$postuninstall_cmds" '$rmforce || exit_status=1' + fi + + if test -n "$old_library"; then + # Do each command in the old_postuninstall commands. + func_execute_cmds "$old_postuninstall_cmds" '$rmforce || exit_status=1' + fi + # FIXME: should reinstall the best remaining shared library. + ;; + esac + fi + ;; + + *.lo) + # Possibly a libtool object, so verify it. + if func_lalib_p "$file"; then + + # Read the .lo file + func_source $dir/$name + + # Add PIC object to the list of files to remove. + if test -n "$pic_object" && test none != "$pic_object"; then + func_append rmfiles " $dir/$pic_object" + fi + + # Add non-PIC object to the list of files to remove. + if test -n "$non_pic_object" && test none != "$non_pic_object"; then + func_append rmfiles " $dir/$non_pic_object" + fi + fi + ;; + + *) + if test clean = "$opt_mode"; then + noexename=$name + case $file in + *.exe) + func_stripname '' '.exe' "$file" + file=$func_stripname_result + func_stripname '' '.exe' "$name" + noexename=$func_stripname_result + # $file with .exe has already been added to rmfiles, + # add $file without .exe + func_append rmfiles " $file" + ;; + esac + # Do a test to see if this is a libtool program. + if func_ltwrapper_p "$file"; then + if func_ltwrapper_executable_p "$file"; then + func_ltwrapper_scriptname "$file" + relink_command= + func_source $func_ltwrapper_scriptname_result + func_append rmfiles " $func_ltwrapper_scriptname_result" + else + relink_command= + func_source $dir/$noexename + fi + + # note $name still contains .exe if it was in $file originally + # as does the version of $file that was added into $rmfiles + func_append rmfiles " $odir/$name $odir/${name}S.$objext" + if test yes = "$fast_install" && test -n "$relink_command"; then + func_append rmfiles " $odir/lt-$name" + fi + if test "X$noexename" != "X$name"; then + func_append rmfiles " $odir/lt-$noexename.c" + fi + fi + fi + ;; + esac + func_show_eval "$RM $rmfiles" 'exit_status=1' + done + + # Try to remove the $objdir's in the directories where we deleted files + for dir in $rmdirs; do + if test -d "$dir"; then + func_show_eval "rmdir $dir >/dev/null 2>&1" + fi + done + + exit $exit_status +} + +if test uninstall = "$opt_mode" || test clean = "$opt_mode"; then + func_mode_uninstall ${1+"$@"} +fi + +test -z "$opt_mode" && { + help=$generic_help + func_fatal_help "you must specify a MODE" +} + +test -z "$exec_cmd" && \ + func_fatal_help "invalid operation mode '$opt_mode'" + +if test -n "$exec_cmd"; then + eval exec "$exec_cmd" + exit $EXIT_FAILURE +fi + +exit $exit_status + + +# The TAGs below are defined such that we never get into a situation +# where we disable both kinds of libraries. Given conflicting +# choices, we go for a static library, that is the most portable, +# since we can't tell whether shared libraries were disabled because +# the user asked for that or because the platform doesn't support +# them. This is particularly important on AIX, because we don't +# support having both static and shared libraries enabled at the same +# time on that platform, so we default to a shared-only configuration. +# If a disable-shared tag is given, we'll fallback to a static-only +# configuration. But we'll never go from static-only to shared-only. + +# ### BEGIN LIBTOOL TAG CONFIG: disable-shared +build_libtool_libs=no +build_old_libs=yes +# ### END LIBTOOL TAG CONFIG: disable-shared + +# ### BEGIN LIBTOOL TAG CONFIG: disable-static +build_old_libs=`case $build_libtool_libs in yes) echo no;; *) echo yes;; esac` +# ### END LIBTOOL TAG CONFIG: disable-static + +# Local Variables: +# mode:shell-script +# sh-indentation:2 +# End: diff --git a/third_party/json-c/math_compat.h b/third_party/json-c/math_compat.h index d530537b9..2382fe15b 100644 --- a/third_party/json-c/math_compat.h +++ b/third_party/json-c/math_compat.h @@ -9,17 +9,24 @@ /* Define isnan, isinf, infinity and nan on Windows/MSVC */ #ifndef HAVE_DECL_ISNAN -# ifdef HAVE_DECL__ISNAN +#ifdef HAVE_DECL__ISNAN #include #define isnan(x) _isnan(x) -# endif +#else +/* On platforms like AIX and "IBM i" we need to provide our own isnan */ +#define isnan(x) ((x) != (x)) +#endif #endif #ifndef HAVE_DECL_ISINF -# ifdef HAVE_DECL__FINITE +#ifdef HAVE_DECL__FINITE #include #define isinf(x) (!_finite(x)) -# endif +#else +#include +/* On platforms like AIX and "IBM i" we need to provide our own isinf */ +#define isinf(x) ((x) < -DBL_MAX || (x) > DBL_MAX) +#endif #endif #ifndef HAVE_DECL_INFINITY diff --git a/third_party/json-c/meson.build b/third_party/json-c/meson.build new file mode 100644 index 000000000..4196818e9 --- /dev/null +++ b/third_party/json-c/meson.build @@ -0,0 +1,93 @@ +# +# Copyright (c) 2022-2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. +# +# This software product is a proprietary product of NVIDIA CORPORATION & +# AFFILIATES (the "Company") and all right, title, and interest in and to the +# software product, including all associated intellectual property rights, are +# and shall remain exclusively with the Company. +# +# This software product is governed by the End User License Agreement +# provided with the software product. +# + +subdir('config') +third_party_include += include_directories('config') +third_party_include += include_directories('.') + +json_config = configuration_data() +if conf.has('HAVE_INTTYPES_H') + json_config.set10('JSON_C_HAVE_INTTYPES_H', true) +endif +json_config_h = configure_file( + configuration: json_config, + output: 'json_config.h', +) + +public_headers = [ + json_config_h, + 'arraylist.h', + 'debug.h', + 'json.h', + 'json_c_version.h', + 'json_inttypes.h', + 'json_object.h', + 'json_object_iterator.h', + 'json_pointer.h', + 'json_tokener.h', + 'json_types.h', + 'json_util.h', + 'json_visit.h', + 'linkhash.h', + 'printbuf.h', +] + +third_party_sources = files([ + 'arraylist.c', + 'debug.c', + 'json_c_version.c', + 'json_object.c', + 'json_object_iterator.c', + 'json_pointer.c', + 'json_tokener.c', + 'json_util.c', + 'json_visit.c', + 'linkhash.c', + 'printbuf.c', + 'random_seed.c', + 'strerror_override.c', +]) + +if is_compiler_msvc + third_party_c_args += [ + # mark that this is windows OS + '/DWIN32', + # ignore conversion from 'type1' to 'type2', possible loss of data + '/wd4244', + # ignore conversion from 'size_t' to 'type', possible loss of data + '/wd4267', + # ignore use of deprecated functions + '/wd4996', + ] +else + third_party_dependencies += [ + dependency_mlib, + dependency_threads, + ] + + third_party_c_args += [ + '-Wno-double-promotion', + '-Wno-format', + '-Wno-format-security', + '-Wno-null-dereference', + '-Wno-format-nonliteral', + '-Wno-missing-declarations', + '-Wno-missing-prototypes', + '-Wno-old-style-definition', + '-Wno-strict-prototypes', + '-Wno-suggest-attribute=format', + ] + + if is_compiler_clang + third_party_c_args += ['-Wno-missing-variable-declarations'] + endif +endif diff --git a/third_party/json-c/missing b/third_party/json-c/missing new file mode 100755 index 000000000..1fe1611f1 --- /dev/null +++ b/third_party/json-c/missing @@ -0,0 +1,215 @@ +#! /bin/sh +# Common wrapper for a few potentially missing GNU programs. + +scriptversion=2018-03-07.03; # UTC + +# Copyright (C) 1996-2021 Free Software Foundation, Inc. +# Originally written by Fran,cois Pinard , 1996. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + +if test $# -eq 0; then + echo 1>&2 "Try '$0 --help' for more information" + exit 1 +fi + +case $1 in + + --is-lightweight) + # Used by our autoconf macros to check whether the available missing + # script is modern enough. + exit 0 + ;; + + --run) + # Back-compat with the calling convention used by older automake. + shift + ;; + + -h|--h|--he|--hel|--help) + echo "\ +$0 [OPTION]... PROGRAM [ARGUMENT]... + +Run 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due +to PROGRAM being missing or too old. + +Options: + -h, --help display this help and exit + -v, --version output version information and exit + +Supported PROGRAM values: + aclocal autoconf autoheader autom4te automake makeinfo + bison yacc flex lex help2man + +Version suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and +'g' are ignored when checking the name. + +Send bug reports to ." + exit $? + ;; + + -v|--v|--ve|--ver|--vers|--versi|--versio|--version) + echo "missing $scriptversion (GNU Automake)" + exit $? + ;; + + -*) + echo 1>&2 "$0: unknown '$1' option" + echo 1>&2 "Try '$0 --help' for more information" + exit 1 + ;; + +esac + +# Run the given program, remember its exit status. +"$@"; st=$? + +# If it succeeded, we are done. +test $st -eq 0 && exit 0 + +# Also exit now if we it failed (or wasn't found), and '--version' was +# passed; such an option is passed most likely to detect whether the +# program is present and works. +case $2 in --version|--help) exit $st;; esac + +# Exit code 63 means version mismatch. This often happens when the user +# tries to use an ancient version of a tool on a file that requires a +# minimum version. +if test $st -eq 63; then + msg="probably too old" +elif test $st -eq 127; then + # Program was missing. + msg="missing on your system" +else + # Program was found and executed, but failed. Give up. + exit $st +fi + +perl_URL=https://www.perl.org/ +flex_URL=https://github.com/westes/flex +gnu_software_URL=https://www.gnu.org/software + +program_details () +{ + case $1 in + aclocal|automake) + echo "The '$1' program is part of the GNU Automake package:" + echo "<$gnu_software_URL/automake>" + echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:" + echo "<$gnu_software_URL/autoconf>" + echo "<$gnu_software_URL/m4/>" + echo "<$perl_URL>" + ;; + autoconf|autom4te|autoheader) + echo "The '$1' program is part of the GNU Autoconf package:" + echo "<$gnu_software_URL/autoconf/>" + echo "It also requires GNU m4 and Perl in order to run:" + echo "<$gnu_software_URL/m4/>" + echo "<$perl_URL>" + ;; + esac +} + +give_advice () +{ + # Normalize program name to check for. + normalized_program=`echo "$1" | sed ' + s/^gnu-//; t + s/^gnu//; t + s/^g//; t'` + + printf '%s\n' "'$1' is $msg." + + configure_deps="'configure.ac' or m4 files included by 'configure.ac'" + case $normalized_program in + autoconf*) + echo "You should only need it if you modified 'configure.ac'," + echo "or m4 files included by it." + program_details 'autoconf' + ;; + autoheader*) + echo "You should only need it if you modified 'acconfig.h' or" + echo "$configure_deps." + program_details 'autoheader' + ;; + automake*) + echo "You should only need it if you modified 'Makefile.am' or" + echo "$configure_deps." + program_details 'automake' + ;; + aclocal*) + echo "You should only need it if you modified 'acinclude.m4' or" + echo "$configure_deps." + program_details 'aclocal' + ;; + autom4te*) + echo "You might have modified some maintainer files that require" + echo "the 'autom4te' program to be rebuilt." + program_details 'autom4te' + ;; + bison*|yacc*) + echo "You should only need it if you modified a '.y' file." + echo "You may want to install the GNU Bison package:" + echo "<$gnu_software_URL/bison/>" + ;; + lex*|flex*) + echo "You should only need it if you modified a '.l' file." + echo "You may want to install the Fast Lexical Analyzer package:" + echo "<$flex_URL>" + ;; + help2man*) + echo "You should only need it if you modified a dependency" \ + "of a man page." + echo "You may want to install the GNU Help2man package:" + echo "<$gnu_software_URL/help2man/>" + ;; + makeinfo*) + echo "You should only need it if you modified a '.texi' file, or" + echo "any other file indirectly affecting the aspect of the manual." + echo "You might want to install the Texinfo package:" + echo "<$gnu_software_URL/texinfo/>" + echo "The spurious makeinfo call might also be the consequence of" + echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might" + echo "want to install GNU make:" + echo "<$gnu_software_URL/make/>" + ;; + *) + echo "You might have modified some files without having the proper" + echo "tools for further handling them. Check the 'README' file, it" + echo "often tells you about the needed prerequisites for installing" + echo "this package. You may also peek at any GNU archive site, in" + echo "case some other package contains this missing '$1' program." + ;; + esac +} + +give_advice "$1" | sed -e '1s/^/WARNING: /' \ + -e '2,$s/^/ /' >&2 + +# Propagate the correct exit status (expected to be 127 for a program +# not found, 63 for a program that failed due to version mismatch). +exit $st + +# Local variables: +# eval: (add-hook 'before-save-hook 'time-stamp) +# time-stamp-start: "scriptversion=" +# time-stamp-format: "%:y-%02m-%02d.%02H" +# time-stamp-time-zone: "UTC0" +# time-stamp-end: "; # UTC" +# End: diff --git a/third_party/json-c/printbuf.c b/third_party/json-c/printbuf.c index 6c77b5def..72d459f94 100644 --- a/third_party/json-c/printbuf.c +++ b/third_party/json-c/printbuf.c @@ -1,4 +1,6 @@ /* + * Original work: + * * $Id: printbuf.c,v 1.5 2006/01/26 02:16:28 mclark Exp $ * * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd. @@ -10,19 +12,34 @@ * * Copyright (c) 2008-2009 Yahoo! Inc. All rights reserved. * The copyrights to the contents of this file are licensed under the MIT License - * (http://www.opensource.org/licenses/mit-license.php) + * (https://www.opensource.org/licenses/mit-license.php) + * + * Modified Work: + * + * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. + * + * This software product is a proprietary product of NVIDIA CORPORATION & + * AFFILIATES (the "Company") and all right, title, and interest in and to the + * software product, including all associated intellectual property rights, are + * and shall remain exclusively with the Company. + * + * This software product is governed by the End User License Agreement + * provided with the software product. + * */ #include "config.h" +#include +#include #include #include #include #ifdef HAVE_STDARG_H -# include +#include #else /* !HAVE_STDARG_H */ -# error Not enough var arg support! +#error Not enough var arg support! #endif /* HAVE_STDARG_H */ #include "debug.h" @@ -32,28 +49,31 @@ static int printbuf_extend(struct printbuf *p, int min_size); -struct printbuf* printbuf_new(void) +struct printbuf *doca_third_party_printbuf_new(void) { - struct printbuf *p; - - p = (struct printbuf*)calloc(1, sizeof(struct printbuf)); - if(!p) return NULL; - p->size = 32; - p->bpos = 0; - if(!(p->buf = (char*)malloc(p->size))) { - free(p); - return NULL; - } - p->buf[0]= '\0'; - return p; + struct printbuf *p; + + p = (struct printbuf *)calloc(1, sizeof(struct printbuf)); + if (!p) + return NULL; + p->size = 32; + p->bpos = 0; + if (!(p->buf = (char *)malloc(p->size))) + { + free(p); + return NULL; + } + p->buf[0] = '\0'; + return p; } - /** * Extend the buffer p so it has a size of at least min_size. * * If the current size is large enough, nothing is changed. * + * If extension failed, errno is set to indicate the error. + * * Note: this does not check the available space! The caller * is responsible for performing those calculations. */ @@ -64,40 +84,62 @@ static int printbuf_extend(struct printbuf *p, int min_size) if (p->size >= min_size) return 0; - - new_size = p->size * 2; - if (new_size < min_size + 8) - new_size = min_size + 8; + /* Prevent signed integer overflows with large buffers. */ + if (min_size > INT_MAX - 8) + { + errno = EFBIG; + return -1; + } + if (p->size > INT_MAX / 2) + new_size = min_size + 8; + else { + new_size = p->size * 2; + if (new_size < min_size + 8) + new_size = min_size + 8; + } #ifdef PRINTBUF_DEBUG - MC_DEBUG("printbuf_memappend: realloc " - "bpos=%d min_size=%d old_size=%d new_size=%d\n", - p->bpos, min_size, p->size, new_size); + MC_DEBUG("printbuf_extend: realloc " + "bpos=%d min_size=%d old_size=%d new_size=%d\n", + p->bpos, min_size, p->size, new_size); #endif /* PRINTBUF_DEBUG */ - if(!(t = (char*)realloc(p->buf, new_size))) + if (!(t = (char *)realloc(p->buf, new_size))) return -1; p->size = new_size; p->buf = t; return 0; } -int printbuf_memappend(struct printbuf *p, const char *buf, int size) +int doca_third_party_printbuf_memappend(struct printbuf *p, const char *buf, int size) { - if (p->size <= p->bpos + size + 1) { - if (printbuf_extend(p, p->bpos + size + 1) < 0) - return -1; - } - memcpy(p->buf + p->bpos, buf, size); - p->bpos += size; - p->buf[p->bpos]= '\0'; - return size; + /* Prevent signed integer overflows with large buffers. */ + if (size < 0 || size > INT_MAX - p->bpos - 1) + { + errno = EFBIG; + return -1; + } + if (p->size <= p->bpos + size + 1) + { + if (printbuf_extend(p, p->bpos + size + 1) < 0) + return -1; + } + memcpy(p->buf + p->bpos, buf, size); + p->bpos += size; + p->buf[p->bpos] = '\0'; + return size; } -int printbuf_memset(struct printbuf *pb, int offset, int charvalue, int len) +int doca_third_party_printbuf_memset(struct printbuf *pb, int offset, int charvalue, int len) { int size_needed; if (offset == -1) offset = pb->bpos; + /* Prevent signed integer overflows with large buffers. */ + if (len < 0 || offset < -1 || len > INT_MAX - offset) + { + errno = EFBIG; + return -1; + } size_needed = offset + len; if (pb->size < size_needed) { @@ -105,6 +147,8 @@ int printbuf_memset(struct printbuf *pb, int offset, int charvalue, int len) return -1; } + if (pb->bpos < offset) + memset(pb->buf + pb->bpos, '\0', offset - pb->bpos); memset(pb->buf + offset, charvalue, len); if (pb->bpos < size_needed) pb->bpos = size_needed; @@ -112,44 +156,52 @@ int printbuf_memset(struct printbuf *pb, int offset, int charvalue, int len) return 0; } -int sprintbuf(struct printbuf *p, const char *msg, ...) +int doca_third_party_sprintbuf(struct printbuf *p, const char *msg, ...) { - va_list ap; - char *t; - int size; - char buf[128]; - - /* user stack buffer first */ - va_start(ap, msg); - size = vsnprintf(buf, 128, msg, ap); - va_end(ap); - /* if string is greater than stack buffer, then use dynamic string - with vasprintf. Note: some implementation of vsnprintf return -1 - if output is truncated whereas some return the number of bytes that - would have been written - this code handles both cases. */ - if(size == -1 || size > 127) { - va_start(ap, msg); - if((size = vasprintf(&t, msg, ap)) < 0) { va_end(ap); return -1; } - va_end(ap); - printbuf_memappend(p, t, size); - free(t); - return size; - } else { - printbuf_memappend(p, buf, size); - return size; - } + va_list ap; + char *t; + int size; + char buf[128]; + + /* use stack buffer first */ + va_start(ap, msg); + size = vsnprintf(buf, 128, msg, ap); + va_end(ap); + /* if string is greater than stack buffer, then use dynamic string + * with vasprintf. Note: some implementations of vsnprintf return -1 + * if output is truncated whereas some return the number of bytes that + * would have been written - this code handles both cases. + */ + if (size < 0 || size > 127) + { + va_start(ap, msg); + if ((size = vasprintf(&t, msg, ap)) < 0) + { + va_end(ap); + return -1; + } + va_end(ap); + size = doca_third_party_printbuf_memappend(p, t, size); + free(t); + } + else + { + size = doca_third_party_printbuf_memappend(p, buf, size); + } + return size; } -void printbuf_reset(struct printbuf *p) +void doca_third_party_printbuf_reset(struct printbuf *p) { - p->buf[0] = '\0'; - p->bpos = 0; + p->buf[0] = '\0'; + p->bpos = 0; } -void printbuf_free(struct printbuf *p) +void doca_third_party_printbuf_free(struct printbuf *p) { - if(p) { - free(p->buf); - free(p); - } + if (p) + { + free(p->buf); + free(p); + } } diff --git a/third_party/json-c/printbuf.h b/third_party/json-c/printbuf.h index 567a6a08b..dd1ed2e49 100644 --- a/third_party/json-c/printbuf.h +++ b/third_party/json-c/printbuf.h @@ -1,4 +1,6 @@ /* + * Original work: + * * $Id: printbuf.h,v 1.4 2006/01/26 02:16:28 mclark Exp $ * * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd. @@ -10,32 +12,53 @@ * * Copyright (c) 2008-2009 Yahoo! Inc. All rights reserved. * The copyrights to the contents of this file are licensed under the MIT License - * (http://www.opensource.org/licenses/mit-license.php) + * (https://www.opensource.org/licenses/mit-license.php) + * + * Modified Work: + * + * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. + * + * This software product is a proprietary product of NVIDIA CORPORATION & + * AFFILIATES (the "Company") and all right, title, and interest in and to the + * software product, including all associated intellectual property rights, are + * and shall remain exclusively with the Company. + * + * This software product is governed by the End User License Agreement + * provided with the software product. + * */ /** * @file - * @brief Internal string buffer handing. Unless you're writing a + * @brief Internal string buffer handling. Unless you're writing a * json_object_to_json_string_fn implementation for use with * json_object_set_serializer() direct use of this is not * recommended. */ -#ifndef _printbuf_h_ -#define _printbuf_h_ +#ifndef _json_c_printbuf_h_ +#define _json_c_printbuf_h_ + +#ifndef JSON_EXPORT +#if defined(_MSC_VER) && defined(JSON_C_DLL) +#define JSON_EXPORT __declspec(dllexport) +#else +#define JSON_EXPORT extern +#endif +#endif #ifdef __cplusplus extern "C" { #endif -struct printbuf { - char *buf; - int bpos; - int size; +struct printbuf +{ + char *buf; + int bpos; + int size; }; typedef struct printbuf printbuf; -extern struct printbuf* -printbuf_new(void); +JSON_EXPORT struct printbuf *doca_third_party_printbuf_new(void); /* As an optimization, printbuf_memappend_fast() is defined as a macro * that handles copying data if the buffer is large enough; otherwise @@ -45,17 +68,22 @@ printbuf_new(void); * Your code should not use printbuf_memappend() directly unless it * checks the return code. Use printbuf_memappend_fast() instead. */ -extern int -printbuf_memappend(struct printbuf *p, const char *buf, int size); - -#define printbuf_memappend_fast(p, bufptr, bufsize) \ -do { \ - if ((p->size - p->bpos) > bufsize) { \ - memcpy(p->buf + p->bpos, (bufptr), bufsize); \ - p->bpos += bufsize; \ - p->buf[p->bpos]= '\0'; \ - } else { printbuf_memappend(p, (bufptr), bufsize); } \ -} while (0) +JSON_EXPORT int doca_third_party_printbuf_memappend(struct printbuf *p, const char *buf, int size); + +#define printbuf_memappend_fast(p, bufptr, bufsize) \ + do \ + { \ + if ((p->size - p->bpos) > bufsize) \ + { \ + memcpy(p->buf + p->bpos, (bufptr), bufsize); \ + p->bpos += bufsize; \ + p->buf[p->bpos] = '\0'; \ + } \ + else \ + { \ + doca_third_party_printbuf_memappend(p, (bufptr), bufsize); \ + } \ + } while (0) #define printbuf_length(p) ((p)->bpos) @@ -79,7 +107,7 @@ do { \ * sprintbuf() */ #define printbuf_strappend(pb, str) \ - printbuf_memappend ((pb), _printbuf_check_literal(str), sizeof(str) - 1) + doca_third_party_printbuf_memappend((pb), _printbuf_check_literal(str), sizeof(str) - 1) /** * Set len bytes of the buffer to charvalue, starting at offset offset. @@ -89,8 +117,7 @@ do { \ * * If offset is -1, this starts at the end of the current data in the buffer. */ -extern int -printbuf_memset(struct printbuf *pb, int offset, int charvalue, int len); +JSON_EXPORT int doca_third_party_printbuf_memset(struct printbuf *pb, int offset, int charvalue, int len); /** * Formatted print to printbuf. @@ -106,14 +133,11 @@ printbuf_memset(struct printbuf *pb, int offset, int charvalue, int len); * printbuf_memappend() * printbuf_strappend() */ -extern int -sprintbuf(struct printbuf *p, const char *msg, ...); +JSON_EXPORT int doca_third_party_sprintbuf(struct printbuf *p, const char *msg, ...); -extern void -printbuf_reset(struct printbuf *p); +JSON_EXPORT void doca_third_party_printbuf_reset(struct printbuf *p); -extern void -printbuf_free(struct printbuf *p); +JSON_EXPORT void doca_third_party_printbuf_free(struct printbuf *p); #ifdef __cplusplus } diff --git a/third_party/json-c/random_seed.c b/third_party/json-c/random_seed.c index 32327774a..ff355e863 100644 --- a/third_party/json-c/random_seed.c +++ b/third_party/json-c/random_seed.c @@ -1,4 +1,6 @@ /* + * Original work: + * * random_seed.c * * Copyright (c) 2013 Metaparadigm Pte. Ltd. @@ -7,15 +9,40 @@ * This library is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See COPYING for details. * + * Modified Work: + * + * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. + * + * This software product is a proprietary product of NVIDIA CORPORATION & + * AFFILIATES (the "Company") and all right, title, and interest in and to the + * software product, including all associated intellectual property rights, are + * and shall remain exclusively with the Company. + * + * This software product is governed by the End User License Agreement + * provided with the software product. + * */ +#include "random_seed.h" +#include "config.h" #include "strerror_override.h" #include -#include "config.h" -#include "random_seed.h" +#include +#ifdef HAVE_BSD_STDLIB_H +#include +#endif #define DEBUG_SEED(s) +#if defined(__APPLE__) || defined(__unix__) || defined(__linux__) +#define HAVE_DEV_RANDOM 1 +#endif + +#ifdef HAVE_ARC4RANDOM +#undef HAVE_GETRANDOM +#undef HAVE_DEV_RANDOM +#undef HAVE_CRYPTGENRANDOM +#endif #if defined ENABLE_RDRAND @@ -26,20 +53,11 @@ static void do_cpuid(int regs[], int h) { - __asm__ __volatile__( -#if defined __x86_64__ - "pushq %%rbx;\n" -#else - "pushl %%ebx;\n" -#endif - "cpuid;\n" -#if defined __x86_64__ - "popq %%rbx;\n" -#else - "popl %%ebx;\n" -#endif - : "=a"(regs[0]), [ebx] "=r"(regs[1]), "=c"(regs[2]), "=d"(regs[3]) + /* clang-format off */ + __asm__ __volatile__("cpuid" + : "=a"(regs[0]), "=b"(regs[1]), "=c"(regs[2]), "=d"(regs[3]) : "a"(h)); + /* clang-format on */ } #elif defined _MSC_VER @@ -53,12 +71,51 @@ static void do_cpuid(int regs[], int h) #if HAS_X86_CPUID -static int has_rdrand() +static int get_rdrand_seed(void); + +/* Valid values are -1 (haven't tested), 0 (no), and 1 (yes). */ +static int _has_rdrand = -1; + +static int has_rdrand(void) { - // CPUID.01H:ECX.RDRAND[bit 30] == 1 - int regs[4]; - do_cpuid(regs, 1); - return (regs[2] & (1 << 30)) != 0; + if (_has_rdrand != -1) + { + return _has_rdrand; + } + + /* CPUID.01H:ECX.RDRAND[bit 30] == 1 */ + int regs[4]; + do_cpuid(regs, 1); + if (!(regs[2] & (1 << 30))) + { + _has_rdrand = 0; + return 0; + } + + /* + * Some CPUs advertise RDRAND in CPUID, but return 0xFFFFFFFF + * unconditionally. To avoid locking up later, test RDRAND here. If over + * 3 trials RDRAND has returned the same value, declare it broken. + * Example CPUs are AMD Ryzen 3000 series + * and much older AMD APUs, such as the E1-1500 + * https://github.com/systemd/systemd/issues/11810 + * https://linuxreviews.org/RDRAND_stops_returning_random_values_on_older_AMD_CPUs_after_suspend + */ + _has_rdrand = 0; + int prev = get_rdrand_seed(); + for (int i = 0; i < 3; i++) + { + int temp = get_rdrand_seed(); + if (temp != prev) + { + _has_rdrand = 1; + break; + } + + prev = temp; + } + + return _has_rdrand; } #endif @@ -69,17 +126,19 @@ static int has_rdrand() #define HAVE_RDRAND 1 -static int get_rdrand_seed() +static int get_rdrand_seed(void) { - DEBUG_SEED("get_rdrand_seed"); - int _eax; - // rdrand eax - __asm__ __volatile__("1: .byte 0x0F\n" - " .byte 0xC7\n" - " .byte 0xF0\n" - " jnc 1b;\n" - : "=a" (_eax)); - return _eax; + DEBUG_SEED("get_rdrand_seed"); + int _eax; + /* rdrand eax */ + /* clang-format off */ + __asm__ __volatile__("1: .byte 0x0F\n" + " .byte 0xC7\n" + " .byte 0xF0\n" + " jnc 1b;\n" + : "=a" (_eax)); + /* clang-format on */ + return _eax; } #endif @@ -91,12 +150,13 @@ static int get_rdrand_seed() /* get_rdrand_seed - Visual Studio 2012 and above */ -static int get_rdrand_seed() +static int get_rdrand_seed(void) { - DEBUG_SEED("get_rdrand_seed"); - int r; - while (_rdrand32_step(&r) == 0); - return r; + DEBUG_SEED("get_rdrand_seed"); + int r; + while (_rdrand32_step(&r) == 0) + ; + return r; } #elif defined _M_IX86 @@ -104,135 +164,207 @@ static int get_rdrand_seed() /* get_rdrand_seed - Visual Studio 2010 and below - x86 only */ -static int get_rdrand_seed() +/* clang-format off */ +static int get_rdrand_seed(void) { DEBUG_SEED("get_rdrand_seed"); int _eax; retry: - // rdrand eax + /* rdrand eax */ __asm _emit 0x0F __asm _emit 0xC7 __asm _emit 0xF0 __asm jnc retry __asm mov _eax, eax return _eax; } +/* clang-format on */ #endif #endif #endif /* defined ENABLE_RDRAND */ +#ifdef HAVE_GETRANDOM -/* has_dev_urandom */ +#include +#ifdef HAVE_SYS_RANDOM_H +#include +#endif -#if defined (__APPLE__) || defined(__unix__) || defined(__linux__) +static int get_getrandom_seed(int *seed) +{ + DEBUG_SEED("get_getrandom_seed"); + + ssize_t ret; + + do + { + ret = getrandom(seed, sizeof(*seed), GRND_NONBLOCK); + } while ((ret == -1) && (errno == EINTR)); + + if (ret == -1) + { + if (errno == ENOSYS) /* syscall not available in kernel */ + return -1; + if (errno == EAGAIN) /* entropy not yet initialized */ + return -1; + + fprintf(stderr, "error from getrandom(): %s", strerror(errno)); + return -1; + } + + if (ret != sizeof(*seed)) + return -1; + + return 0; +} +#endif /* defined HAVE_GETRANDOM */ + +/* get_dev_random_seed */ + +#ifdef HAVE_DEV_RANDOM -#include #include +#include +#if HAVE_UNISTD_H #include +#endif /* HAVE_UNISTD_H */ #include #include -#define HAVE_DEV_RANDOM 1 - static const char *dev_random_file = "/dev/urandom"; -static int has_dev_urandom() +static int get_dev_random_seed(int *seed) { - struct stat buf; - if (stat(dev_random_file, &buf)) { - return 0; - } - return ((buf.st_mode & S_IFCHR) != 0); -} + DEBUG_SEED("get_dev_random_seed"); + struct stat buf; + if (stat(dev_random_file, &buf)) + return -1; + if ((buf.st_mode & S_IFCHR) == 0) + return -1; -/* get_dev_random_seed */ + int fd = open(dev_random_file, O_RDONLY); + if (fd < 0) + { + fprintf(stderr, "error opening %s: %s", dev_random_file, strerror(errno)); + return -1; + } -static int get_dev_random_seed() -{ - DEBUG_SEED("get_dev_random_seed"); - - int fd = open(dev_random_file, O_RDONLY); - if (fd < 0) { - fprintf(stderr, "error opening %s: %s", dev_random_file, strerror(errno)); - exit(1); - } - - int r; - ssize_t nread = read(fd, &r, sizeof(r)); - if (nread != sizeof(r)) { - fprintf(stderr, "error short read %s: %s", dev_random_file, strerror(errno)); - exit(1); - } - - close(fd); - return r; + ssize_t nread = read(fd, seed, sizeof(*seed)); + + close(fd); + + if (nread != sizeof(*seed)) + { + fprintf(stderr, "error short read %s: %s", dev_random_file, strerror(errno)); + return -1; + } + + return 0; } #endif - /* get_cryptgenrandom_seed */ #ifdef WIN32 #define HAVE_CRYPTGENRANDOM 1 +/* clang-format off */ #include + +/* Caution: these blank lines must remain so clang-format doesn't reorder + includes to put windows.h after wincrypt.h */ + #include +/* clang-format on */ #ifndef __GNUC__ #pragma comment(lib, "advapi32.lib") #endif -static int get_cryptgenrandom_seed() +static int get_cryptgenrandom_seed(int *seed) { - HCRYPTPROV hProvider = 0; - int r; - - DEBUG_SEED("get_cryptgenrandom_seed"); - - if (!CryptAcquireContextW(&hProvider, 0, 0, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT | CRYPT_SILENT)) { - fprintf(stderr, "error CryptAcquireContextW"); - exit(1); - } - - if (!CryptGenRandom(hProvider, sizeof(r), (BYTE*)&r)) { - fprintf(stderr, "error CryptGenRandom"); - exit(1); - } - - CryptReleaseContext(hProvider, 0); - - return r; + HCRYPTPROV hProvider = 0; + DWORD dwFlags = CRYPT_VERIFYCONTEXT; + + DEBUG_SEED("get_cryptgenrandom_seed"); + + /* WinNT 4 and Win98 do no support CRYPT_SILENT */ + if (LOBYTE(LOWORD(GetVersion())) > 4) + dwFlags |= CRYPT_SILENT; + + if (!CryptAcquireContextA(&hProvider, 0, 0, PROV_RSA_FULL, dwFlags)) + { + fprintf(stderr, "error CryptAcquireContextA 0x%08lx", GetLastError()); + return -1; + } + else + { + BOOL ret = CryptGenRandom(hProvider, sizeof(*seed), (BYTE *)seed); + CryptReleaseContext(hProvider, 0); + if (!ret) + { + fprintf(stderr, "error CryptGenRandom 0x%08lx", GetLastError()); + return -1; + } + } + + return 0; } #endif - /* get_time_seed */ +#ifndef HAVE_ARC4RANDOM #include -static int get_time_seed() +static int get_time_seed(void) { - DEBUG_SEED("get_time_seed"); + DEBUG_SEED("get_time_seed"); - return (int)time(NULL) * 433494437; + /* coverity[store_truncates_time_t] */ + return (unsigned)time(NULL) * 433494437; } - +#endif /* json_c_get_random_seed */ -int json_c_get_random_seed() +int doca_third_party_json_c_get_random_seed(void) { -#if HAVE_RDRAND - if (has_rdrand()) return get_rdrand_seed(); +#ifdef OVERRIDE_GET_RANDOM_SEED + OVERRIDE_GET_RANDOM_SEED; +#endif +#if defined HAVE_RDRAND && HAVE_RDRAND + if (has_rdrand()) + return get_rdrand_seed(); +#endif +#ifdef HAVE_ARC4RANDOM + /* arc4random never fails, so use it if it's available */ + return arc4random(); +#else +#ifdef HAVE_GETRANDOM + { + int seed = 0; + if (get_getrandom_seed(&seed) == 0) + return seed; + } #endif -#if HAVE_DEV_RANDOM - if (has_dev_urandom()) return get_dev_random_seed(); +#if defined HAVE_DEV_RANDOM && HAVE_DEV_RANDOM + { + int seed = 0; + if (get_dev_random_seed(&seed) == 0) + return seed; + } #endif -#if HAVE_CRYPTGENRANDOM - return get_cryptgenrandom_seed(); +#if defined HAVE_CRYPTGENRANDOM && HAVE_CRYPTGENRANDOM + { + int seed = 0; + if (get_cryptgenrandom_seed(&seed) == 0) + return seed; + } #endif - return get_time_seed(); + return get_time_seed(); +#endif /* !HAVE_ARC4RANDOM */ } diff --git a/third_party/json-c/random_seed.h b/third_party/json-c/random_seed.h index 2f43dad1f..b1e615568 100644 --- a/third_party/json-c/random_seed.h +++ b/third_party/json-c/random_seed.h @@ -1,4 +1,6 @@ /* + * Original work: + * * random_seed.h * * Copyright (c) 2013 Metaparadigm Pte. Ltd. @@ -7,6 +9,18 @@ * This library is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See COPYING for details. * + * Modified Work: + * + * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. + * + * This software product is a proprietary product of NVIDIA CORPORATION & + * AFFILIATES (the "Company") and all right, title, and interest in and to the + * software product, including all associated intellectual property rights, are + * and shall remain exclusively with the Company. + * + * This software product is governed by the End User License Agreement + * provided with the software product. + * */ /** @@ -20,7 +34,7 @@ extern "C" { #endif -extern int json_c_get_random_seed(); +extern int doca_third_party_json_c_get_random_seed(void); #ifdef __cplusplus } diff --git a/third_party/json-c/snprintf_compat.h b/third_party/json-c/snprintf_compat.h index 8ca9b31c6..51fcb24af 100644 --- a/third_party/json-c/snprintf_compat.h +++ b/third_party/json-c/snprintf_compat.h @@ -13,7 +13,7 @@ #include -#if !defined(HAVE_SNPRINTF) && defined(_MSC_VER) +#if !defined(HAVE_SNPRINTF) && (defined(_MSC_VER) || defined(__MINGW32__)) static int json_c_vsnprintf(char *str, size_t size, const char *format, va_list ap) { int ret; @@ -35,7 +35,7 @@ static int json_c_snprintf(char *str, size_t size, const char *format, ...) #define snprintf json_c_snprintf #elif !defined(HAVE_SNPRINTF) /* !HAVE_SNPRINTF */ -# error Need vsnprintf! +#error snprintf is required but was not found #endif /* !HAVE_SNPRINTF && defined(WIN32) */ #endif /* __snprintf_compat_h */ diff --git a/third_party/json-c/stamp-h2 b/third_party/json-c/stamp-h2 new file mode 100644 index 000000000..4ecdef5f9 --- /dev/null +++ b/third_party/json-c/stamp-h2 @@ -0,0 +1 @@ +timestamp for json_config.h diff --git a/third_party/json-c/strdup_compat.h b/third_party/json-c/strdup_compat.h index 9c523596e..2f2df65a0 100644 --- a/third_party/json-c/strdup_compat.h +++ b/third_party/json-c/strdup_compat.h @@ -7,10 +7,10 @@ */ #if !defined(HAVE_STRDUP) && defined(_MSC_VER) - /* MSC has the version as _strdup */ -# define strdup _strdup +/* MSC has the version as _strdup */ +#define strdup _strdup #elif !defined(HAVE_STRDUP) -# error You do not have strdup on your system. +#error You do not have strdup on your system. #endif /* HAVE_STRDUP */ #endif diff --git a/third_party/json-c/strerror_override.c b/third_party/json-c/strerror_override.c index 90a15814c..1039e052b 100644 --- a/third_party/json-c/strerror_override.c +++ b/third_party/json-c/strerror_override.c @@ -1,3 +1,22 @@ +/* + * Original work: + * + * json-c (copyright was originally missing from this file) + * + * Modified Work: + * + * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. + * + * This software product is a proprietary product of NVIDIA CORPORATION & + * AFFILIATES (the "Company") and all right, title, and interest in and to the + * software product, including all associated intellectual property rights, are + * and shall remain exclusively with the Company. + * + * This software product is governed by the End User License Agreement + * provided with the software product. + * + */ + #define STRERROR_OVERRIDE_IMPL 1 #include "strerror_override.h" @@ -5,10 +24,12 @@ * Override strerror() to get consistent output across platforms. */ -static struct { +static struct +{ int errno_value; const char *errno_str; } errno_list[] = { +/* clang-format off */ #define STRINGIFY(x) #x #define ENTRY(x) {x, &STRINGIFY(undef_ ## x)[6]} ENTRY(EPERM), @@ -18,7 +39,9 @@ static struct { ENTRY(EIO), ENTRY(ENXIO), ENTRY(E2BIG), +#ifdef ENOEXEC ENTRY(ENOEXEC), +#endif ENTRY(EBADF), ENTRY(ECHILD), ENTRY(EDEADLK), @@ -52,19 +75,23 @@ static struct { ENTRY(EAGAIN), { 0, (char *)0 } }; +/* clang-format on */ // Enabled during tests -int _json_c_strerror_enable = 0; +static int _json_c_strerror_enable = 0; +extern char *getenv(const char *name); // Avoid including stdlib.h #define PREFIX "ERRNO=" static char errno_buf[128] = PREFIX; -char *_json_c_strerror(int errno_in) +char *doca_third_party__json_c_strerror(int errno_in) { int start_idx; char digbuf[20]; int ii, jj; if (!_json_c_strerror_enable) + _json_c_strerror_enable = (getenv("_JSON_C_STRERROR_ENABLE") == NULL) ? -1 : 1; + if (_json_c_strerror_enable == -1) return strerror(errno_in); // Avoid standard functions, so we don't need to include any @@ -76,7 +103,8 @@ char *_json_c_strerror(int errno_in) if (errno_list[ii].errno_value != errno_in) continue; - for (start_idx = sizeof(PREFIX) - 1, jj = 0; errno_str[jj] != '\0'; jj++, start_idx++) + for (start_idx = sizeof(PREFIX) - 1, jj = 0; errno_str[jj] != '\0'; + jj++, start_idx++) { errno_buf[start_idx] = errno_str[jj]; } @@ -85,17 +113,17 @@ char *_json_c_strerror(int errno_in) } // It's not one of the known errno values, return the numeric value. - for (ii = 0; errno_in > 10; errno_in /= 10, ii++) + for (ii = 0; errno_in >= 10; errno_in /= 10, ii++) { digbuf[ii] = "0123456789"[(errno_in % 10)]; } digbuf[ii] = "0123456789"[(errno_in % 10)]; // Reverse the digits - for (start_idx = sizeof(PREFIX) - 1 ; ii >= 0; ii--, start_idx++) + for (start_idx = sizeof(PREFIX) - 1; ii >= 0; ii--, start_idx++) { errno_buf[start_idx] = digbuf[ii]; } + errno_buf[start_idx] = '\0'; return errno_buf; } - diff --git a/third_party/json-c/strerror_override.h b/third_party/json-c/strerror_override.h index 567438180..dd6df0161 100644 --- a/third_party/json-c/strerror_override.h +++ b/third_party/json-c/strerror_override.h @@ -1,3 +1,22 @@ +/* + * Original work: + * + * json-c (copyright was originally missing from this file) + * + * Modified Work: + * + * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. + * + * This software product is a proprietary product of NVIDIA CORPORATION & + * AFFILIATES (the "Company") and all right, title, and interest in and to the + * software product, including all associated intellectual property rights, are + * and shall remain exclusively with the Company. + * + * This software product is governed by the End User License Agreement + * provided with the software product. + * + */ + #ifndef _json_strerror_override_h_ #define _json_strerror_override_h_ @@ -17,14 +36,14 @@ extern "C" { #include -JSON_EXPORT char *_json_c_strerror(int errno_in); +JSON_EXPORT char *doca_third_party__json_c_strerror(int errno_in); #ifndef STRERROR_OVERRIDE_IMPL -#define strerror _json_c_strerror +#define strerror doca_third_party__json_c_strerror #endif #ifdef __cplusplus } #endif -#endif /* _json_strerror_override_h_ */ +#endif /* _json_strerror_override_h_ */ diff --git a/third_party/json-c/strerror_override_private.h b/third_party/json-c/strerror_override_private.h deleted file mode 100644 index 5180b4f30..000000000 --- a/third_party/json-c/strerror_override_private.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef __json_strerror_override_private_h__ -#define __json_strerror_override_private_h__ - -/** - * @file - * @brief Do not use, json-c internal, may be changed or removed at any time. - */ - -/* Used by tests to get consistent output */ -extern int _json_c_strerror_enable; - -#endif diff --git a/third_party/json-c/tests/CMakeLists.txt b/third_party/json-c/tests/CMakeLists.txt new file mode 100644 index 000000000..f54840d59 --- /dev/null +++ b/third_party/json-c/tests/CMakeLists.txt @@ -0,0 +1,64 @@ +cmake_minimum_required(VERSION 3.1) +add_executable(test1Formatted test1.c parse_flags.c parse_flags.h) +target_compile_definitions(test1Formatted PRIVATE TEST_FORMATTED=1) +target_link_libraries(test1Formatted PRIVATE ${PROJECT_NAME}) + +add_executable(test2Formatted test2.c parse_flags.c parse_flags.h) +target_compile_definitions(test2Formatted PRIVATE TEST_FORMATTED=1) +target_link_libraries(test2Formatted PRIVATE ${PROJECT_NAME}) + +# https://cmake.org/cmake/help/v3.0/command/add_test.html +# https://pabloariasal.github.io/2018/02/19/its-time-to-do-cmake-right/ + +include_directories(PUBLIC ${CMAKE_SOURCE_DIR}) + +set(ALL_TEST_NAMES + test1 + test2 + test4 + testReplaceExisting + test_cast + test_charcase + test_compare + test_deep_copy + test_double_serializer + test_float + test_int_add + test_int_get + test_locale + test_null + test_parse + test_parse_int64 + test_printbuf + test_set_serializer + test_set_value + test_strerror + test_util_file + test_visit + test_object_iterator) + +if (NOT DISABLE_JSON_POINTER) + set(ALL_TEST_NAMES ${ALL_TEST_NAMES} test_json_pointer) + if (NOT DISABLE_JSON_PATCH) + set(ALL_TEST_NAMES ${ALL_TEST_NAMES} test_json_patch) + endif() +endif() + +foreach(TESTNAME ${ALL_TEST_NAMES}) + +add_executable(${TESTNAME} ${TESTNAME}.c) +add_test(NAME ${TESTNAME} COMMAND ${PROJECT_SOURCE_DIR}/tests/${TESTNAME}.test) + +# XXX using the non-target_ versions of these doesn't work :( +target_include_directories( + ${TESTNAME} + PUBLIC + ${CMAKE_CURRENT_LIST_DIR} + ) +target_link_libraries( + ${TESTNAME} + PRIVATE + ${PROJECT_NAME} + ) + +endforeach(TESTNAME) diff --git a/third_party/json-c/tests/Makefile.am b/third_party/json-c/tests/Makefile.am deleted file mode 100644 index ea57bdab6..000000000 --- a/third_party/json-c/tests/Makefile.am +++ /dev/null @@ -1,64 +0,0 @@ - -AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/tests - -LDADD= $(LIBJSON_LA) - -LIBJSON_LA=$(top_builddir)/libjson-c.la - -TESTS= -TESTS+= test_util_file.test -TESTS+= test_float.test -TESTS+= test1.test -TESTS+= test2.test -TESTS+= test4.test -TESTS+= testReplaceExisting.test -TESTS+= test_parse_int64.test -TESTS+= test_deep_copy.test -TESTS+= test_null.test -TESTS+= test_cast.test -TESTS+= test_double_serializer.test -TESTS+= test_parse.test -TESTS+= test_locale.test -TESTS+= test_charcase.test -TESTS+= test_printbuf.test -TESTS+= test_set_serializer.test -TESTS+= test_compare.test -TESTS+= test_set_value.test -TESTS+= test_visit.test -TESTS+= test_json_pointer.test -TESTS+= test_int_add.test - -check_PROGRAMS= -check_PROGRAMS += $(TESTS:.test=) - -EXTRA_DIST= -EXTRA_DIST += $(TESTS) -EXTRA_DIST += $(TESTS:.test=.expected) -EXTRA_DIST += test-defs.sh -EXTRA_DIST += valid.json - - -# Note: handled by test1.test -check_PROGRAMS += test1Formatted -test1Formatted_SOURCES = test1.c parse_flags.c parse_flags.h -test1Formatted_CPPFLAGS = $(AM_CPPFLAGS) -DTEST_FORMATTED -EXTRA_DIST+= test1Formatted_plain.expected -EXTRA_DIST+= test1Formatted_pretty.expected -EXTRA_DIST+= test1Formatted_spaced.expected - -# Note: handled by test2.test -check_PROGRAMS += test2Formatted -test2Formatted_SOURCES = test2.c parse_flags.c parse_flags.h -test2Formatted_CPPFLAGS = $(AM_CPPFLAGS) -DTEST_FORMATTED -EXTRA_DIST+= test2Formatted_plain.expected -EXTRA_DIST+= test2Formatted_pretty.expected -EXTRA_DIST+= test2Formatted_spaced.expected - -test_util_file_SOURCES = test_util_file.c - -testsubdir=testSubDir -TESTS_ENVIRONMENT = top_builddir=$(top_builddir) - -distclean-local: - -rm -rf $(testsubdir) - -rm -f *.vg.out diff --git a/third_party/json-c/tests/json_patch_spec_tests.json b/third_party/json-c/tests/json_patch_spec_tests.json new file mode 100644 index 000000000..d7d407d3f --- /dev/null +++ b/third_party/json-c/tests/json_patch_spec_tests.json @@ -0,0 +1,233 @@ +[ + { + "comment": "4.1. add with missing object", + "doc": { "q": { "bar": 2 } }, + "patch": [ {"op": "add", "path": "/a/b", "value": 1} ], + "error": + "path /a does not exist -- missing objects are not created recursively" + }, + + { + "comment": "A.1. Adding an Object Member", + "doc": { + "foo": "bar" +}, + "patch": [ + { "op": "add", "path": "/baz", "value": "qux" } +], + "expected": { + "baz": "qux", + "foo": "bar" +} + }, + + { + "comment": "A.2. Adding an Array Element", + "doc": { + "foo": [ "bar", "baz" ] +}, + "patch": [ + { "op": "add", "path": "/foo/1", "value": "qux" } +], + "expected": { + "foo": [ "bar", "qux", "baz" ] +} + }, + + { + "comment": "A.3. Removing an Object Member", + "doc": { + "baz": "qux", + "foo": "bar" +}, + "patch": [ + { "op": "remove", "path": "/baz" } +], + "expected": { + "foo": "bar" +} + }, + + { + "comment": "A.4. Removing an Array Element", + "doc": { + "foo": [ "bar", "qux", "baz" ] +}, + "patch": [ + { "op": "remove", "path": "/foo/1" } +], + "expected": { + "foo": [ "bar", "baz" ] +} + }, + + { + "comment": "A.5. Replacing a Value", + "doc": { + "baz": "qux", + "foo": "bar" +}, + "patch": [ + { "op": "replace", "path": "/baz", "value": "boo" } +], + "expected": { + "baz": "boo", + "foo": "bar" +} + }, + + { + "comment": "A.6. Moving a Value", + "doc": { + "foo": { + "bar": "baz", + "waldo": "fred" + }, + "qux": { + "corge": "grault" + } +}, + "patch": [ + { "op": "move", "from": "/foo/waldo", "path": "/qux/thud" } +], + "expected": { + "foo": { + "bar": "baz" + }, + "qux": { + "corge": "grault", + "thud": "fred" + } +} + }, + + { + "comment": "A.7. Moving an Array Element", + "doc": { + "foo": [ "all", "grass", "cows", "eat" ] +}, + "patch": [ + { "op": "move", "from": "/foo/1", "path": "/foo/3" } +], + "expected": { + "foo": [ "all", "cows", "eat", "grass" ] +} + + }, + + { + "comment": "A.8. Testing a Value: Success", + "doc": { + "baz": "qux", + "foo": [ "a", 2, "c" ] +}, + "patch": [ + { "op": "test", "path": "/baz", "value": "qux" }, + { "op": "test", "path": "/foo/1", "value": 2 } +], + "expected": { + "baz": "qux", + "foo": [ "a", 2, "c" ] + } + }, + + { + "comment": "A.9. Testing a Value: Error", + "doc": { + "baz": "qux" +}, + "patch": [ + { "op": "test", "path": "/baz", "value": "bar" } +], + "error": "string not equivalent" + }, + + { + "comment": "A.10. Adding a nested Member Object", + "doc": { + "foo": "bar" +}, + "patch": [ + { "op": "add", "path": "/child", "value": { "grandchild": { } } } +], + "expected": { + "foo": "bar", + "child": { + "grandchild": { + } + } +} + }, + + { + "comment": "A.11. Ignoring Unrecognized Elements", + "doc": { + "foo":"bar" +}, + "patch": [ + { "op": "add", "path": "/baz", "value": "qux", "xyz": 123 } +], + "expected": { + "foo":"bar", + "baz":"qux" +} + }, + + { + "comment": "A.12. Adding to a Non-existent Target", + "doc": { + "foo": "bar" +}, + "patch": [ + { "op": "add", "path": "/baz/bat", "value": "qux" } +], + "error": "add to a non-existent target" + }, + + { + "comment": "A.13 Invalid JSON Patch Document", + "doc": { + "foo": "bar" + }, + "patch": [ + { "op": "add", "path": "/baz", "value": "qux", "op": "remove" } +], + "error_wont_happen_in_jsonc": "operation has two 'op' members", + "error": "Did not find element referenced by path field" + }, + + { + "comment": "A.14. ~ Escape Ordering", + "doc": { + "/": 9, + "~1": 10 + }, + "patch": [{"op": "test", "path": "/~01", "value": 10}], + "expected": { + "/": 9, + "~1": 10 + } + }, + + { + "comment": "A.15. Comparing Strings and Numbers", + "doc": { + "/": 9, + "~1": 10 + }, + "patch": [{"op": "test", "path": "/~01", "value": "10"}], + "error": "number is not equal to string" + }, + + { + "comment": "A.16. Adding an Array Value", + "doc": { + "foo": ["bar"] + }, + "patch": [{ "op": "add", "path": "/foo/-", "value": ["abc", "def"] }], + "expected": { + "foo": ["bar", ["abc", "def"]] + } + } + +] diff --git a/third_party/json-c/tests/json_patch_tests.json b/third_party/json-c/tests/json_patch_tests.json new file mode 100644 index 000000000..8cafb93c9 --- /dev/null +++ b/third_party/json-c/tests/json_patch_tests.json @@ -0,0 +1,540 @@ +[ + { "comment": "empty list, empty docs", + "doc": {}, + "patch": [], + "expected": {} }, + + { "comment": "empty patch list", + "doc": {"foo": 1}, + "patch": [], + "expected": {"foo": 1} }, + + { "comment": "rearrangements OK?", + "doc": {"foo": 1, "bar": 2}, + "patch": [], + "expected": {"bar":2, "foo": 1} }, + + { "comment": "rearrangements OK? How about one level down ... array", + "doc": [{"foo": 1, "bar": 2}], + "patch": [], + "expected": [{"bar":2, "foo": 1}] }, + + { "comment": "rearrangements OK? How about one level down...", + "doc": {"foo":{"foo": 1, "bar": 2}}, + "patch": [], + "expected": {"foo":{"bar":2, "foo": 1}} }, + + { "comment": "add replaces any existing field", + "doc": {"foo": null}, + "patch": [{"op": "add", "path": "/foo", "value":1}], + "expected": {"foo": 1} }, + + { "comment": "toplevel array", + "doc": [], + "patch": [{"op": "add", "path": "/0", "value": "foo"}], + "expected": ["foo"] }, + + { "comment": "toplevel array, no change", + "doc": ["foo"], + "patch": [], + "expected": ["foo"] }, + + { "comment": "toplevel object, numeric string", + "doc": {}, + "patch": [{"op": "add", "path": "/foo", "value": "1"}], + "expected": {"foo":"1"} }, + + { "comment": "toplevel object, integer", + "doc": {}, + "patch": [{"op": "add", "path": "/foo", "value": 1}], + "expected": {"foo":1} }, + + { "comment": "Toplevel scalar values OK?", + "doc": "foo", + "patch": [{"op": "replace", "path": "", "value": "bar"}], + "expected": "bar" + }, + + { "comment": "replace object document with array document?", + "doc": {}, + "patch": [{"op": "add", "path": "", "value": []}], + "expected": [] }, + + { "comment": "replace array document with object document?", + "doc": [], + "patch": [{"op": "add", "path": "", "value": {}}], + "expected": {} }, + + { "comment": "append to root array document?", + "doc": [], + "patch": [{"op": "add", "path": "/-", "value": "hi"}], + "expected": ["hi"] }, + + { "comment": "Add, / target", + "doc": {}, + "patch": [ {"op": "add", "path": "/", "value":1 } ], + "expected": {"":1} }, + + { "comment": "Add, /foo/ deep target (trailing slash)", + "doc": {"foo": {}}, + "patch": [ {"op": "add", "path": "/foo/", "value":1 } ], + "expected": {"foo":{"": 1}} }, + + { "comment": "Add composite value at top level", + "doc": {"foo": 1}, + "patch": [{"op": "add", "path": "/bar", "value": [1, 2]}], + "expected": {"foo": 1, "bar": [1, 2]} }, + + { "comment": "Add into composite value", + "doc": {"foo": 1, "baz": [{"qux": "hello"}]}, + "patch": [{"op": "add", "path": "/baz/0/foo", "value": "world"}], + "expected": {"foo": 1, "baz": [{"qux": "hello", "foo": "world"}]} }, + + { "doc": {"bar": [1, 2]}, + "patch": [{"op": "add", "path": "/bar/8", "value": "5"}], + "error": "Out of bounds (upper)" }, + + { "doc": {"bar": [1, 2]}, + "patch": [{"op": "add", "path": "/bar/-1", "value": "5"}], + "error": "Out of bounds (lower)" }, + + { "doc": {"foo": 1}, + "patch": [{"op": "add", "path": "/bar", "value": true}], + "expected": {"foo": 1, "bar": true} }, + + { "doc": {"foo": 1}, + "patch": [{"op": "add", "path": "/bar", "value": false}], + "expected": {"foo": 1, "bar": false} }, + + { "doc": {"foo": 1}, + "patch": [{"op": "add", "path": "/bar", "value": null}], + "expected": {"foo": 1, "bar": null} }, + + { "comment": "0 can be an array index or object element name", + "doc": {"foo": 1}, + "patch": [{"op": "add", "path": "/0", "value": "bar"}], + "expected": {"foo": 1, "0": "bar" } }, + + { "doc": ["foo"], + "patch": [{"op": "add", "path": "/1", "value": "bar"}], + "expected": ["foo", "bar"] }, + + { "doc": ["foo", "sil"], + "patch": [{"op": "add", "path": "/1", "value": "bar"}], + "expected": ["foo", "bar", "sil"] }, + + { "doc": ["foo", "sil"], + "patch": [{"op": "add", "path": "/0", "value": "bar"}], + "expected": ["bar", "foo", "sil"] }, + + { "comment": "push item to array via last index + 1", + "doc": ["foo", "sil"], + "patch": [{"op":"add", "path": "/2", "value": "bar"}], + "expected": ["foo", "sil", "bar"] }, + + { "comment": "add item to array at index > length should fail", + "doc": ["foo", "sil"], + "patch": [{"op":"add", "path": "/3", "value": "bar"}], + "error": "index is greater than number of items in array" }, + + { "comment": "test against implementation-specific numeric parsing", + "doc": {"1e0": "foo"}, + "patch": [{"op": "test", "path": "/1e0", "value": "foo"}], + "expected": {"1e0": "foo"} }, + + { "comment": "test with bad number should fail", + "doc": ["foo", "bar"], + "patch": [{"op": "test", "path": "/1e0", "value": "bar"}], + "error": "test op shouldn't get array element 1" }, + + { "doc": ["foo", "sil"], + "patch": [{"op": "add", "path": "/bar", "value": 42}], + "error": "Object operation on array target" }, + + { "doc": ["foo", "sil"], + "patch": [{"op": "add", "path": "/1", "value": ["bar", "baz"]}], + "expected": ["foo", ["bar", "baz"], "sil"], + "comment": "value in array add not flattened" }, + + { "doc": {"foo": 1, "bar": [1, 2, 3, 4]}, + "patch": [{"op": "remove", "path": "/bar"}], + "expected": {"foo": 1} }, + + { "doc": {"foo": 1, "baz": [{"qux": "hello"}]}, + "patch": [{"op": "remove", "path": "/baz/0/qux"}], + "expected": {"foo": 1, "baz": [{}]} }, + + { "doc": {"foo": 1, "baz": [{"qux": "hello"}]}, + "patch": [{"op": "replace", "path": "/foo", "value": [1, 2, 3, 4]}], + "expected": {"foo": [1, 2, 3, 4], "baz": [{"qux": "hello"}]} }, + + { "doc": {"foo": [1, 2, 3, 4], "baz": [{"qux": "hello"}]}, + "patch": [{"op": "replace", "path": "/baz/0/qux", "value": "world"}], + "expected": {"foo": [1, 2, 3, 4], "baz": [{"qux": "world"}]} }, + + { "doc": ["foo"], + "patch": [{"op": "replace", "path": "/0", "value": "bar"}], + "expected": ["bar"] }, + + { "doc": [""], + "patch": [{"op": "replace", "path": "/0", "value": 0}], + "expected": [0] }, + + { "doc": [""], + "patch": [{"op": "replace", "path": "/0", "value": true}], + "expected": [true] }, + + { "doc": [""], + "patch": [{"op": "replace", "path": "/0", "value": false}], + "expected": [false] }, + + { "doc": [""], + "patch": [{"op": "replace", "path": "/0", "value": null}], + "expected": [null] }, + + { "doc": ["foo", "sil"], + "patch": [{"op": "replace", "path": "/1", "value": ["bar", "baz"]}], + "expected": ["foo", ["bar", "baz"]], + "comment": "value in array replace not flattened" }, + + { "comment": "replace whole document", + "doc": {"foo": "bar"}, + "patch": [{"op": "replace", "path": "", "value": {"baz": "qux"}}], + "expected": {"baz": "qux"} }, + + { "comment": "add whole document, null", + "doc": {}, + "Note1": "We can't pass null in to json_patch_apply, so start with _something_ and remove it", + "patch": [ + {"op": "remove", "path": ""}, + {"op": "add", "path": "", "value": {"baz": "qux"}} + ], + "expected": {"baz": "qux"} }, + + { "comment": "replace whole document, null", + "doc": {}, + "Note1": "We can't pass null in to json_patch_apply, so start with _something_ and remove it", + "patch": [ + {"op": "remove", "path": ""}, + {"op": "replace", "path": "", "value": {"baz": "qux"}} + ], + "error": "The spec says the target location must exist, so replacing a null document fails" + }, + + { "comment": "remove whole document", + "doc": {"foo": "bar"}, + "patch": [{"op": "remove", "path": ""}], + "expected": null }, + + { "comment": "remove whole document", + "doc": {"foo": "bar"}, + "patch": [{"op": "remove", "path": ""}], + "expected": null }, + + { "comment": "remove whole document, array", + "doc": ["foo", "bar"], + "patch": [{"op": "remove", "path": ""}], + "expected": null }, + + { "comment": "remove whole document, string", + "doc": "foo", + "patch": [{"op": "remove", "path": ""}], + "expected": null }, + + { "comment": "remove whole document, null", + "doc": {}, + "Note1": "We can't pass null in to json_patch_apply, so start with _something_ and remove it", + "patch": [ + {"op": "remove", "path": ""}, + {"op": "remove", "path": ""}, + ], + "error": "The spec says the target location must exist, so removing a null document fails" + }, + + { "comment": "test replace with missing parent key should fail", + "doc": {"bar": "baz"}, + "patch": [{"op": "replace", "path": "/foo/bar", "value": false}], + "error": "replace op should fail with missing parent key" }, + + { "comment": "spurious patch properties", + "doc": {"foo": 1}, + "patch": [{"op": "test", "path": "/foo", "value": 1, "spurious": 1}], + "expected": {"foo": 1} }, + + { "doc": {"foo": null}, + "patch": [{"op": "test", "path": "/foo", "value": null}], + "expected": {"foo": null}, + "comment": "null value should be valid obj property" }, + + { "doc": {"foo": null}, + "patch": [{"op": "replace", "path": "/foo", "value": "truthy"}], + "expected": {"foo": "truthy"}, + "comment": "null value should be valid obj property to be replaced with something truthy" }, + + { "doc": {"foo": null}, + "patch": [{"op": "move", "from": "/foo", "path": "/bar"}], + "expected": {"bar": null}, + "comment": "null value should be valid obj property to be moved" }, + + { "doc": {"foo": null}, + "patch": [{"op": "copy", "from": "/foo", "path": "/bar"}], + "expected": {"foo": null, "bar": null}, + "comment": "null value should be valid obj property to be copied" }, + + { "doc": {"foo": null}, + "patch": [{"op": "remove", "path": "/foo"}], + "expected": {}, + "comment": "null value should be valid obj property to be removed" }, + + { "doc": {"foo": "bar"}, + "patch": [{"op": "replace", "path": "/foo", "value": null}], + "expected": {"foo": null}, + "comment": "null value should still be valid obj property replace other value" }, + + { "doc": {"foo": {"foo": 1, "bar": 2}}, + "patch": [{"op": "test", "path": "/foo", "value": {"bar": 2, "foo": 1}}], + "expected": {"foo": {"foo": 1, "bar": 2}}, + "comment": "test should pass despite rearrangement" }, + + { "doc": {"foo": [{"foo": 1, "bar": 2}]}, + "patch": [{"op": "test", "path": "/foo", "value": [{"bar": 2, "foo": 1}]}], + "expected": {"foo": [{"foo": 1, "bar": 2}]}, + "comment": "test should pass despite (nested) rearrangement" }, + + { "doc": {"foo": {"bar": [1, 2, 5, 4]}}, + "patch": [{"op": "test", "path": "/foo", "value": {"bar": [1, 2, 5, 4]}}], + "expected": {"foo": {"bar": [1, 2, 5, 4]}}, + "comment": "test should pass - no error" }, + + { "doc": {"foo": {"bar": [1, 2, 5, 4]}}, + "patch": [{"op": "test", "path": "/foo", "value": [1, 2]}], + "error": "test op should fail" }, + + { "comment": "Test the whole document", + "doc": { "foo": 1 }, + "patch": [{"op": "test", "path": "", "value": {"foo": 1}}], + "expected": { "foo": 1 } }, + + { "comment": "Test the whole document, no match", + "doc": { "foo": 1 }, + "patch": [{"op": "test", "path": "", "value": {"foo": 2}}], + "expected": { "foo": 1 }, + "error": "Tested value does not match original doc" }, + + { "comment": "Empty-string element", + "doc": { "": 1 }, + "patch": [{"op": "test", "path": "/", "value": 1}], + "expected": { "": 1 } }, + + { "doc": { + "foo": ["bar", "baz"], + "": 0, + "a/b": 1, + "c%d": 2, + "e^f": 3, + "g|h": 4, + "i\\j": 5, + "k\"l": 6, + " ": 7, + "m~n": 8 + }, + "patch": [{"op": "test", "path": "/foo", "value": ["bar", "baz"]}, + {"op": "test", "path": "/foo/0", "value": "bar"}, + {"op": "test", "path": "/", "value": 0}, + {"op": "test", "path": "/a~1b", "value": 1}, + {"op": "test", "path": "/c%d", "value": 2}, + {"op": "test", "path": "/e^f", "value": 3}, + {"op": "test", "path": "/g|h", "value": 4}, + {"op": "test", "path": "/i\\j", "value": 5}, + {"op": "test", "path": "/k\"l", "value": 6}, + {"op": "test", "path": "/ ", "value": 7}, + {"op": "test", "path": "/m~0n", "value": 8}], + "expected": { + "": 0, + " ": 7, + "a/b": 1, + "c%d": 2, + "e^f": 3, + "foo": [ + "bar", + "baz" + ], + "g|h": 4, + "i\\j": 5, + "k\"l": 6, + "m~n": 8 + } + }, + { "comment": "Move to same location has no effect", + "doc": {"foo": 1}, + "patch": [{"op": "move", "from": "/foo", "path": "/foo"}], + "expected": {"foo": 1} }, + + { "doc": {"foo": 1, "baz": [{"qux": "hello"}]}, + "patch": [{"op": "move", "from": "/foo", "path": "/bar"}], + "expected": {"baz": [{"qux": "hello"}], "bar": 1} }, + + { "doc": {"baz": [{"qux": "hello"}], "bar": 1}, + "patch": [{"op": "move", "from": "/baz/0/qux", "path": "/baz/1"}], + "expected": {"baz": [{}, "hello"], "bar": 1} }, + + { "doc": {"baz": [{"qux": "hello"}], "bar": 1}, + "patch": [{"op": "copy", "from": "/baz/0", "path": "/boo"}], + "expected": {"baz":[{"qux":"hello"}],"bar":1,"boo":{"qux":"hello"}} }, + + { "comment": "replacing the root of the document is possible with add", + "doc": {"foo": "bar"}, + "patch": [{"op": "add", "path": "", "value": {"baz": "qux"}}], + "expected": {"baz":"qux"}}, + + { "comment": "Adding to \"/-\" adds to the end of the array", + "doc": [ 1, 2 ], + "patch": [ { "op": "add", "path": "/-", "value": { "foo": [ "bar", "baz" ] } } ], + "expected": [ 1, 2, { "foo": [ "bar", "baz" ] } ]}, + + { "comment": "Adding to \"/-\" adds to the end of the array, even n levels down", + "doc": [ 1, 2, [ 3, [ 4, 5 ] ] ], + "patch": [ { "op": "add", "path": "/2/1/-", "value": { "foo": [ "bar", "baz" ] } } ], + "expected": [ 1, 2, [ 3, [ 4, 5, { "foo": [ "bar", "baz" ] } ] ] ]}, + + { "comment": "test remove with bad number should fail", + "doc": {"foo": 1, "baz": [{"qux": "hello"}]}, + "patch": [{"op": "remove", "path": "/baz/1e0/qux"}], + "error": "remove op shouldn't remove from array with bad number" }, + + { "comment": "test remove on array", + "doc": [1, 2, 3, 4], + "patch": [{"op": "remove", "path": "/0"}], + "expected": [2, 3, 4] }, + + { "comment": "test repeated removes", + "doc": [1, 2, 3, 4], + "patch": [{ "op": "remove", "path": "/1" }, + { "op": "remove", "path": "/2" }], + "expected": [1, 3] }, + + { "comment": "test remove with bad index should fail", + "doc": [1, 2, 3, 4], + "patch": [{"op": "remove", "path": "/1e0"}], + "error": "remove op shouldn't remove from array with bad number" }, + + { "comment": "test replace with bad number should fail", + "doc": [""], + "patch": [{"op": "replace", "path": "/1e0", "value": false}], + "error": "replace op shouldn't replace in array with bad number" }, + + { "comment": "test copy with bad number should fail", + "doc": {"baz": [1,2,3], "bar": 1}, + "patch": [{"op": "copy", "from": "/baz/1e0", "path": "/boo"}], + "error": "copy op shouldn't work with bad number" }, + + { "comment": "test move with bad number should fail", + "doc": {"foo": 1, "baz": [1,2,3,4]}, + "patch": [{"op": "move", "from": "/baz/1e0", "path": "/foo"}], + "error": "move op shouldn't work with bad number" }, + + { "comment": "test add with bad number should fail", + "doc": ["foo", "sil"], + "patch": [{"op": "add", "path": "/1e0", "value": "bar"}], + "error": "add op shouldn't add to array with bad number" }, + + { "comment": "missing 'path' parameter", + "doc": {}, + "patch": [ { "op": "add", "value": "bar" } ], + "error": "missing 'path' parameter" }, + + { "comment": "'path' parameter with null value", + "doc": {}, + "patch": [ { "op": "add", "path": null, "value": "bar" } ], + "error": "null is not valid value for 'path'" }, + + { "comment": "invalid JSON Pointer token", + "doc": {}, + "patch": [ { "op": "add", "path": "foo", "value": "bar" } ], + "error": "JSON Pointer should start with a slash" }, + + { "comment": "missing 'value' parameter to add", + "doc": [ 1 ], + "patch": [ { "op": "add", "path": "/-" } ], + "error": "missing 'value' parameter" }, + + { "comment": "missing 'value' parameter to replace", + "doc": [ 1 ], + "patch": [ { "op": "replace", "path": "/0" } ], + "error": "missing 'value' parameter" }, + + { "comment": "missing 'value' parameter to test", + "doc": [ null ], + "patch": [ { "op": "test", "path": "/0" } ], + "error": "missing 'value' parameter" }, + + { "comment": "missing value parameter to test - where undef is falsy", + "doc": [ false ], + "patch": [ { "op": "test", "path": "/0" } ], + "error": "missing 'value' parameter" }, + + { "comment": "missing from parameter to copy", + "doc": [ 1 ], + "patch": [ { "op": "copy", "path": "/-" } ], + "error": "missing 'from' parameter" }, + + { "comment": "missing from location to copy", + "doc": { "foo": 1 }, + "patch": [ { "op": "copy", "from": "/bar", "path": "/foo" } ], + "error": "missing 'from' location" }, + + { "comment": "missing from parameter to move", + "doc": { "foo": 1 }, + "patch": [ { "op": "move", "path": "" } ], + "error": "missing 'from' parameter" }, + + { "comment": "missing from location to move", + "doc": { "foo": 1 }, + "patch": [ { "op": "move", "from": "/bar", "path": "/foo" } ], + "error": "missing 'from' location" }, + + { "comment": "duplicate ops, json-c parses this as op:move", + "doc": { "foo": "bar" }, + "patch": [ { "op": "add", "path": "/baz", "value": "qux", + "op": "move", "from":"/foo" } ], + "error_wont_happen_in_jsonc": "patch has two 'op' members", + "expected": { "baz": "bar" } + }, + + { "comment": "unrecognized op should fail", + "doc": {"foo": 1}, + "patch": [{"op": "spam", "path": "/foo", "value": 1}], + "error": "Unrecognized op 'spam'" }, + + { "comment": "test with bad array number that has leading zeros", + "doc": ["foo", "bar"], + "patch": [{"op": "test", "path": "/00", "value": "foo"}], + "error": "test op should reject the array value, it has leading zeros" }, + + { "comment": "test with bad array number that has leading zeros", + "doc": ["foo", "bar"], + "patch": [{"op": "test", "path": "/01", "value": "bar"}], + "error": "test op should reject the array value, it has leading zeros" }, + + { "comment": "Removing nonexistent field", + "doc": {"foo" : "bar"}, + "patch": [{"op": "remove", "path": "/baz"}], + "error": "removing a nonexistent field should fail" }, + + { "comment": "Removing deep nonexistent path", + "doc": {"foo" : "bar"}, + "patch": [{"op": "remove", "path": "/missing1/missing2"}], + "error": "removing a nonexistent field should fail" }, + + { "comment": "Removing nonexistent index", + "doc": ["foo", "bar"], + "patch": [{"op": "remove", "path": "/2"}], + "error": "removing a nonexistent index should fail" }, + + { "comment": "Patch with different capitalisation than doc", + "doc": {"foo":"bar"}, + "patch": [{"op": "add", "path": "/FOO", "value": "BAR"}], + "expected": {"foo": "bar", "FOO": "BAR"} + } + +] diff --git a/third_party/json-c/tests/parse_flags.c b/third_party/json-c/tests/parse_flags.c index b1f8337f7..6224ca316 100644 --- a/third_party/json-c/tests/parse_flags.c +++ b/third_party/json-c/tests/parse_flags.c @@ -1,3 +1,6 @@ +#ifdef NDEBUG +#undef NDEBUG +#endif #include "config.h" #include @@ -7,18 +10,20 @@ #include "parse_flags.h" #if !defined(HAVE_STRCASECMP) && defined(_MSC_VER) -# define strcasecmp _stricmp +#define strcasecmp _stricmp #elif !defined(HAVE_STRCASECMP) -# error You do not have strcasecmp on your system. +#error You do not have strcasecmp on your system. #endif /* HAVE_STRNCASECMP */ -static struct { +static struct +{ const char *arg; int flag; } format_args[] = { - { "plain", JSON_C_TO_STRING_PLAIN }, - { "spaced", JSON_C_TO_STRING_SPACED }, - { "pretty", JSON_C_TO_STRING_PRETTY }, + {"plain", JSON_C_TO_STRING_PLAIN}, + {"spaced", JSON_C_TO_STRING_SPACED}, + {"pretty", JSON_C_TO_STRING_PRETTY}, + {"pretty_tab", JSON_C_TO_STRING_PRETTY_TAB}, }; #ifndef NELEM @@ -29,7 +34,7 @@ int parse_flags(int argc, char **argv) { int arg_idx; int sflags = 0; - for (arg_idx = 1; arg_idx < argc ; arg_idx++) + for (arg_idx = 1; arg_idx < argc; arg_idx++) { int jj; for (jj = 0; jj < (int)NELEM(format_args); jj++) diff --git a/third_party/json-c/tests/test-defs.sh b/third_party/json-c/tests/test-defs.sh index 7e1739b41..8c5b521f0 100755 --- a/third_party/json-c/tests/test-defs.sh +++ b/third_party/json-c/tests/test-defs.sh @@ -1,5 +1,10 @@ #!/bin/sh +if [ ! -z "$JSONC_TEST_TRACE" ] ; then + VERBOSE=1 + set -x + set -v +fi # Make sure srcdir is an absolute path. Supply the variable # if it does not exist. We want to be able to run the tests # stand-alone!! @@ -85,7 +90,7 @@ run_output_test() fi TEST_COMMAND="$1" shift - if [ -z "${TEST_OUTPUT}" ] ; then + if [ -z "${TEST_OUTPUT}" ] ; then TEST_OUTPUT=${TEST_COMMAND} fi diff --git a/third_party/json-c/tests/test1.c b/third_party/json-c/tests/test1.c index 3ddaf7203..63d4d656b 100644 --- a/third_party/json-c/tests/test1.c +++ b/third_party/json-c/tests/test1.c @@ -1,19 +1,44 @@ +/* + * Original work: + * + * json-c (copyright was originally missing from this file) + * + * Modified Work: + * + * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. + * + * This software product is a proprietary product of NVIDIA CORPORATION & + * AFFILIATES (the "Company") and all right, title, and interest in and to the + * software product, including all associated intellectual property rights, are + * and shall remain exclusively with the Company. + * + * This software product is governed by the End User License Agreement + * provided with the software product. + * + */ + +#ifdef NDEBUG +#undef NDEBUG +#endif +#include +#include +#include #include #include -#include #include -#include + +#include "config.h" #include "json.h" #include "parse_flags.h" -static int sort_fn (const void *j1, const void *j2) +static int sort_fn(const void *j1, const void *j2) { - json_object * const *jso1, * const *jso2; + json_object *const *jso1, *const *jso2; int i1, i2; - jso1 = (json_object* const*)j1; - jso2 = (json_object* const*)j2; + jso1 = (json_object *const *)j1; + jso2 = (json_object *const *)j2; if (!*jso1 && !*jso2) return 0; if (!*jso1) @@ -21,8 +46,8 @@ static int sort_fn (const void *j1, const void *j2) if (!*jso2) return 1; - i1 = json_object_get_int(*jso1); - i2 = json_object_get_int(*jso2); + i1 = doca_third_party_json_object_get_int(*jso1); + i2 = doca_third_party_json_object_get_int(*jso2); return i1 - i2; } @@ -34,12 +59,13 @@ static const char *to_json_string(json_object *obj, int flags) char *copy; const char *result; - result = json_object_to_json_string_length(obj, flags, &length); + result = doca_third_party_json_object_to_json_string_length(obj, flags, &length); copy = strdup(result); if (copy == NULL) printf("to_json_string: Allocation failed!\n"); - else { - result = json_object_to_json_string_ext(obj, flags); + else + { + result = doca_third_party_json_object_to_json_string_ext(obj, flags); if (length != strlen(result)) printf("to_json_string: Length mismatch!\n"); if (strcmp(copy, result) != 0) @@ -48,29 +74,29 @@ static const char *to_json_string(json_object *obj, int flags) } return result; } -#define json_object_to_json_string(obj) to_json_string(obj,sflags) +#define doca_third_party_json_object_to_json_string(obj) to_json_string(obj, sflags) #else /* no special define */ #endif json_object *make_array(void); -json_object *make_array() +json_object *make_array(void) { json_object *my_array; - my_array = json_object_new_array(); - json_object_array_add(my_array, json_object_new_int(1)); - json_object_array_add(my_array, json_object_new_int(2)); - json_object_array_add(my_array, json_object_new_int(3)); - json_object_array_put_idx(my_array, 4, json_object_new_int(5)); - json_object_array_put_idx(my_array, 3, json_object_new_int(4)); - json_object_array_put_idx(my_array, 6, json_object_new_int(7)); + my_array = doca_third_party_json_object_new_array(); + doca_third_party_json_object_array_add(my_array, doca_third_party_json_object_new_int(1)); + doca_third_party_json_object_array_add(my_array, doca_third_party_json_object_new_int(2)); + doca_third_party_json_object_array_add(my_array, doca_third_party_json_object_new_int(3)); + doca_third_party_json_object_array_put_idx(my_array, 4, doca_third_party_json_object_new_int(5)); + doca_third_party_json_object_array_put_idx(my_array, 3, doca_third_party_json_object_new_int(4)); + doca_third_party_json_object_array_put_idx(my_array, 6, doca_third_party_json_object_new_int(7)); return my_array; } void test_array_del_idx(void); -void test_array_del_idx() +void test_array_del_idx(void) { int rc; size_t ii; @@ -81,63 +107,146 @@ void test_array_del_idx() #endif my_array = make_array(); - orig_array_len = json_object_array_length(my_array); + orig_array_len = doca_third_party_json_object_array_length(my_array); printf("my_array=\n"); - for(ii = 0; ii < json_object_array_length(my_array); ii++) + for (ii = 0; ii < doca_third_party_json_object_array_length(my_array); ii++) { - json_object *obj = json_object_array_get_idx(my_array, ii); - printf("\t[%d]=%s\n", (int)ii, json_object_to_json_string(obj)); + json_object *obj = doca_third_party_json_object_array_get_idx(my_array, ii); + printf("\t[%d]=%s\n", (int)ii, doca_third_party_json_object_to_json_string(obj)); } - printf("my_array.to_string()=%s\n", json_object_to_json_string(my_array)); + printf("my_array.to_string()=%s\n", doca_third_party_json_object_to_json_string(my_array)); for (ii = 0; ii < orig_array_len; ii++) { - rc = json_object_array_del_idx(my_array, 0, 1); - printf("after del_idx(0,1)=%d, my_array.to_string()=%s\n", - rc, json_object_to_json_string(my_array)); + rc = doca_third_party_json_object_array_del_idx(my_array, 0, 1); + printf("after del_idx(0,1)=%d, my_array.to_string()=%s\n", rc, + doca_third_party_json_object_to_json_string(my_array)); } /* One more time, with the empty array: */ - rc = json_object_array_del_idx(my_array, 0, 1); - printf("after del_idx(0,1)=%d, my_array.to_string()=%s\n", - rc, json_object_to_json_string(my_array)); + rc = doca_third_party_json_object_array_del_idx(my_array, 0, 1); + printf("after del_idx(0,1)=%d, my_array.to_string()=%s\n", rc, + doca_third_party_json_object_to_json_string(my_array)); - json_object_put(my_array); + doca_third_party_json_object_put(my_array); /* Delete all array indexes at once */ my_array = make_array(); - rc = json_object_array_del_idx(my_array, 0, orig_array_len); - printf("after del_idx(0,%d)=%d, my_array.to_string()=%s\n", - (int)orig_array_len, rc, json_object_to_json_string(my_array)); + rc = doca_third_party_json_object_array_del_idx(my_array, 0, orig_array_len); + printf("after del_idx(0,%d)=%d, my_array.to_string()=%s\n", (int)orig_array_len, rc, + doca_third_party_json_object_to_json_string(my_array)); - json_object_put(my_array); + doca_third_party_json_object_put(my_array); /* Delete *more* than all array indexes at once */ my_array = make_array(); - rc = json_object_array_del_idx(my_array, 0, orig_array_len + 1); - printf("after del_idx(0,%d)=%d, my_array.to_string()=%s\n", - (int)(orig_array_len + 1), rc, json_object_to_json_string(my_array)); + rc = doca_third_party_json_object_array_del_idx(my_array, 0, orig_array_len + 1); + printf("after del_idx(0,%d)=%d, my_array.to_string()=%s\n", (int)(orig_array_len + 1), rc, + doca_third_party_json_object_to_json_string(my_array)); + + doca_third_party_json_object_put(my_array); - json_object_put(my_array); - /* Delete some array indexes, then add more */ my_array = make_array(); - rc = json_object_array_del_idx(my_array, 0, orig_array_len - 1); - printf("after del_idx(0,%d)=%d, my_array.to_string()=%s\n", - (int)(orig_array_len - 1), rc, json_object_to_json_string(my_array)); - json_object_array_add(my_array, json_object_new_string("s1")); - json_object_array_add(my_array, json_object_new_string("s2")); - json_object_array_add(my_array, json_object_new_string("s3")); + rc = doca_third_party_json_object_array_del_idx(my_array, 0, orig_array_len - 1); + printf("after del_idx(0,%d)=%d, my_array.to_string()=%s\n", (int)(orig_array_len - 1), rc, + doca_third_party_json_object_to_json_string(my_array)); + doca_third_party_json_object_array_add(my_array, doca_third_party_json_object_new_string("s1")); + doca_third_party_json_object_array_add(my_array, doca_third_party_json_object_new_string("s2")); + doca_third_party_json_object_array_add(my_array, doca_third_party_json_object_new_string("s3")); printf("after adding more entries, my_array.to_string()=%s\n", - json_object_to_json_string(my_array)); - json_object_put(my_array); + doca_third_party_json_object_to_json_string(my_array)); + doca_third_party_json_object_put(my_array); +} + +void test_array_list_expand_internal(void); +void test_array_list_expand_internal(void) +{ + int rc; + size_t ii; + size_t idx; + json_object *my_array; +#ifdef TEST_FORMATTED + int sflags = 0; +#endif + + my_array = make_array(); + printf("my_array=\n"); + for (ii = 0; ii < doca_third_party_json_object_array_length(my_array); ii++) + { + json_object *obj = doca_third_party_json_object_array_get_idx(my_array, ii); + printf("\t[%d]=%s\n", (int)ii, doca_third_party_json_object_to_json_string(obj)); + } + printf("my_array.to_string()=%s\n", doca_third_party_json_object_to_json_string(my_array)); + + /* Put iNdex < array->size, no expand. */ + rc = doca_third_party_json_object_array_put_idx(my_array, 5, doca_third_party_json_object_new_int(6)); + printf("put_idx(5,6)=%d\n", rc); + + /* array->size < Put Index < array->size * 2 <= SIZE_T_MAX, the size = array->size * 2. */ + idx = ARRAY_LIST_DEFAULT_SIZE * 2 - 1; + rc = doca_third_party_json_object_array_put_idx(my_array, idx, doca_third_party_json_object_new_int(0)); + printf("put_idx(%d,0)=%d\n", (int)(idx), rc); + + /* array->size * 2 < Put Index, the size = Put Index. */ + idx = ARRAY_LIST_DEFAULT_SIZE * 2 * 2 + 1; + rc = doca_third_party_json_object_array_put_idx(my_array, idx, doca_third_party_json_object_new_int(0)); + printf("put_idx(%d,0)=%d\n", (int)(idx), rc); + + /* SIZE_T_MAX <= Put Index, it will fail and the size will no change. */ + idx = SIZE_MAX; // SIZE_MAX = SIZE_T_MAX + json_object *tmp = doca_third_party_json_object_new_int(10); + rc = doca_third_party_json_object_array_put_idx(my_array, idx, tmp); + printf("put_idx(SIZE_T_MAX,0)=%d\n", rc); + if (rc == -1) + { + doca_third_party_json_object_put(tmp); + } + + doca_third_party_json_object_put(my_array); +} + +void test_array_insert_idx(void); +void test_array_insert_idx(void) +{ + json_object *my_array; + struct json_object *jo1; + + my_array = doca_third_party_json_object_new_array(); + doca_third_party_json_object_array_add(my_array, doca_third_party_json_object_new_int(1)); + doca_third_party_json_object_array_add(my_array, doca_third_party_json_object_new_int(2)); + doca_third_party_json_object_array_add(my_array, doca_third_party_json_object_new_int(5)); + + doca_third_party_json_object_array_insert_idx(my_array, 2, doca_third_party_json_object_new_int(4)); + jo1 = doca_third_party_json_tokener_parse("[1, 2, 4, 5]"); + assert(1 == doca_third_party_json_object_equal(my_array, jo1)); + doca_third_party_json_object_put(jo1); + + doca_third_party_json_object_array_insert_idx(my_array, 2, doca_third_party_json_object_new_int(3)); + + jo1 = doca_third_party_json_tokener_parse("[1, 2, 3, 4, 5]"); + assert(1 == doca_third_party_json_object_equal(my_array, jo1)); + doca_third_party_json_object_put(jo1); + + doca_third_party_json_object_array_insert_idx(my_array, 5, doca_third_party_json_object_new_int(6)); + + jo1 = doca_third_party_json_tokener_parse("[1, 2, 3, 4, 5, 6]"); + assert(1 == doca_third_party_json_object_equal(my_array, jo1)); + doca_third_party_json_object_put(jo1); + + doca_third_party_json_object_array_insert_idx(my_array, 7, doca_third_party_json_object_new_int(8)); + jo1 = doca_third_party_json_tokener_parse("[1, 2, 3, 4, 5, 6, null, 8]"); + assert(1 == doca_third_party_json_object_equal(my_array, jo1)); + doca_third_party_json_object_put(jo1); + + doca_third_party_json_object_put(my_array); } int main(int argc, char **argv) { - json_object *my_string, *my_int, *my_object, *my_array; + json_object *my_string, *my_int, *my_null, *my_object, *my_array; size_t i; #ifdef TEST_FORMATTED int sflags = 0; @@ -149,108 +258,149 @@ int main(int argc, char **argv) sflags = parse_flags(argc, argv); #endif - my_string = json_object_new_string("\t"); - printf("my_string=%s\n", json_object_get_string(my_string)); - printf("my_string.to_string()=%s\n", json_object_to_json_string(my_string)); - json_object_put(my_string); - - my_string = json_object_new_string("\\"); - printf("my_string=%s\n", json_object_get_string(my_string)); - printf("my_string.to_string()=%s\n", json_object_to_json_string(my_string)); - json_object_put(my_string); - - my_string = json_object_new_string("/"); - printf("my_string=%s\n", json_object_get_string(my_string)); - printf("my_string.to_string()=%s\n", json_object_to_json_string(my_string)); - printf("my_string.to_string(NOSLASHESCAPE)=%s\n", json_object_to_json_string_ext(my_string, JSON_C_TO_STRING_NOSLASHESCAPE)); - json_object_put(my_string); - - my_string = json_object_new_string("/foo/bar/baz"); - printf("my_string=%s\n", json_object_get_string(my_string)); - printf("my_string.to_string()=%s\n", json_object_to_json_string(my_string)); - printf("my_string.to_string(NOSLASHESCAPE)=%s\n", json_object_to_json_string_ext(my_string, JSON_C_TO_STRING_NOSLASHESCAPE)); - json_object_put(my_string); - - my_string = json_object_new_string("foo"); - printf("my_string=%s\n", json_object_get_string(my_string)); - printf("my_string.to_string()=%s\n", json_object_to_json_string(my_string)); - - my_int = json_object_new_int(9); - printf("my_int=%d\n", json_object_get_int(my_int)); - printf("my_int.to_string()=%s\n", json_object_to_json_string(my_int)); - - my_array = json_object_new_array(); - json_object_array_add(my_array, json_object_new_int(1)); - json_object_array_add(my_array, json_object_new_int(2)); - json_object_array_add(my_array, json_object_new_int(3)); - json_object_array_put_idx(my_array, 4, json_object_new_int(5)); + my_string = doca_third_party_json_object_new_string("\t"); + printf("my_string=%s\n", doca_third_party_json_object_get_string(my_string)); + printf("my_string.to_string()=%s\n", doca_third_party_json_object_to_json_string(my_string)); + doca_third_party_json_object_put(my_string); + + my_string = doca_third_party_json_object_new_string("\\"); + printf("my_string=%s\n", doca_third_party_json_object_get_string(my_string)); + printf("my_string.to_string()=%s\n", doca_third_party_json_object_to_json_string(my_string)); + doca_third_party_json_object_put(my_string); + + my_string = doca_third_party_json_object_new_string("/"); + printf("my_string=%s\n", doca_third_party_json_object_get_string(my_string)); + printf("my_string.to_string()=%s\n", doca_third_party_json_object_to_json_string(my_string)); + printf("my_string.to_string(NOSLASHESCAPE)=%s\n", + doca_third_party_json_object_to_json_string_ext(my_string, JSON_C_TO_STRING_NOSLASHESCAPE)); + doca_third_party_json_object_put(my_string); + + my_string = doca_third_party_json_object_new_string("/foo/bar/baz"); + printf("my_string=%s\n", doca_third_party_json_object_get_string(my_string)); + printf("my_string.to_string()=%s\n", doca_third_party_json_object_to_json_string(my_string)); + printf("my_string.to_string(NOSLASHESCAPE)=%s\n", + doca_third_party_json_object_to_json_string_ext(my_string, JSON_C_TO_STRING_NOSLASHESCAPE)); + doca_third_party_json_object_put(my_string); + + my_string = doca_third_party_json_object_new_string("foo"); + printf("my_string=%s\n", doca_third_party_json_object_get_string(my_string)); + printf("my_string.to_string()=%s\n", doca_third_party_json_object_to_json_string(my_string)); + + my_int = doca_third_party_json_object_new_int(9); + printf("my_int=%d\n", doca_third_party_json_object_get_int(my_int)); + printf("my_int.to_string()=%s\n", doca_third_party_json_object_to_json_string(my_int)); + + my_null = doca_third_party_json_object_new_null(); + printf("my_null.to_string()=%s\n", doca_third_party_json_object_to_json_string(my_null)); + + my_array = doca_third_party_json_object_new_array(); + doca_third_party_json_object_array_add(my_array, doca_third_party_json_object_new_int(1)); + doca_third_party_json_object_array_add(my_array, doca_third_party_json_object_new_int(2)); + doca_third_party_json_object_array_add(my_array, doca_third_party_json_object_new_int(3)); + doca_third_party_json_object_array_put_idx(my_array, 4, doca_third_party_json_object_new_int(5)); printf("my_array=\n"); - for(i=0; i < json_object_array_length(my_array); i++) + for (i = 0; i < doca_third_party_json_object_array_length(my_array); i++) { - json_object *obj = json_object_array_get_idx(my_array, i); - printf("\t[%d]=%s\n", (int)i, json_object_to_json_string(obj)); + json_object *obj = doca_third_party_json_object_array_get_idx(my_array, i); + printf("\t[%d]=%s\n", (int)i, doca_third_party_json_object_to_json_string(obj)); } - printf("my_array.to_string()=%s\n", json_object_to_json_string(my_array)); + printf("my_array.to_string()=%s\n", doca_third_party_json_object_to_json_string(my_array)); - json_object_put(my_array); + doca_third_party_json_object_put(my_array); + + test_array_insert_idx(); test_array_del_idx(); + test_array_list_expand_internal(); - my_array = json_object_new_array(); - json_object_array_add(my_array, json_object_new_int(3)); - json_object_array_add(my_array, json_object_new_int(1)); - json_object_array_add(my_array, json_object_new_int(2)); - json_object_array_put_idx(my_array, 4, json_object_new_int(0)); + my_array = doca_third_party_json_object_new_array_ext(5); + doca_third_party_json_object_array_add(my_array, doca_third_party_json_object_new_int(3)); + doca_third_party_json_object_array_add(my_array, doca_third_party_json_object_new_int(1)); + doca_third_party_json_object_array_add(my_array, doca_third_party_json_object_new_int(2)); + doca_third_party_json_object_array_put_idx(my_array, 4, doca_third_party_json_object_new_int(0)); printf("my_array=\n"); - for(i=0; i < json_object_array_length(my_array); i++) + for (i = 0; i < doca_third_party_json_object_array_length(my_array); i++) { - json_object *obj = json_object_array_get_idx(my_array, i); - printf("\t[%d]=%s\n", (int)i, json_object_to_json_string(obj)); + json_object *obj = doca_third_party_json_object_array_get_idx(my_array, i); + printf("\t[%d]=%s\n", (int)i, doca_third_party_json_object_to_json_string(obj)); } - printf("my_array.to_string()=%s\n", json_object_to_json_string(my_array)); - json_object_array_sort(my_array, sort_fn); + printf("my_array.to_string()=%s\n", doca_third_party_json_object_to_json_string(my_array)); + doca_third_party_json_object_array_sort(my_array, sort_fn); printf("my_array=\n"); - for(i=0; i < json_object_array_length(my_array); i++) + for (i = 0; i < doca_third_party_json_object_array_length(my_array); i++) { - json_object *obj = json_object_array_get_idx(my_array, i); - printf("\t[%d]=%s\n", (int)i, json_object_to_json_string(obj)); + json_object *obj = doca_third_party_json_object_array_get_idx(my_array, i); + printf("\t[%d]=%s\n", (int)i, doca_third_party_json_object_to_json_string(obj)); } - printf("my_array.to_string()=%s\n", json_object_to_json_string(my_array)); + printf("my_array.to_string()=%s\n", doca_third_party_json_object_to_json_string(my_array)); + + json_object *one = doca_third_party_json_object_new_int(1); + json_object *result = doca_third_party_json_object_array_bsearch(one, my_array, sort_fn); + printf("find json_object(1) in my_array successfully: %s\n", + doca_third_party_json_object_to_json_string(result)); + doca_third_party_json_object_put(one); - my_object = json_object_new_object(); - int rc = json_object_object_add(my_object, "abc", my_object); + my_object = doca_third_party_json_object_new_object(); + int rc = doca_third_party_json_object_object_add(my_object, "abc", my_object); if (rc != -1) { printf("ERROR: able to successfully add object to itself!\n"); fflush(stdout); } - json_object_object_add(my_object, "abc", json_object_new_int(12)); - json_object_object_add(my_object, "foo", json_object_new_string("bar")); - json_object_object_add(my_object, "bool0", json_object_new_boolean(0)); - json_object_object_add(my_object, "bool1", json_object_new_boolean(1)); - json_object_object_add(my_object, "baz", json_object_new_string("bang")); + doca_third_party_json_object_object_add(my_object, "abc", doca_third_party_json_object_new_int(12)); + doca_third_party_json_object_object_add(my_object, "foo", doca_third_party_json_object_new_string("bar")); + doca_third_party_json_object_object_add(my_object, "bool0", doca_third_party_json_object_new_boolean(0)); + doca_third_party_json_object_object_add(my_object, "bool1", doca_third_party_json_object_new_boolean(1)); + doca_third_party_json_object_object_add(my_object, "baz", doca_third_party_json_object_new_string("bang")); - json_object *baz_obj = json_object_new_string("fark"); - json_object_get(baz_obj); - json_object_object_add(my_object, "baz", baz_obj); - json_object_object_del(my_object, "baz"); + json_object *baz_obj = doca_third_party_json_object_new_string("fark"); + doca_third_party_json_object_get(baz_obj); + doca_third_party_json_object_object_add(my_object, "baz", baz_obj); + doca_third_party_json_object_object_del(my_object, "baz"); /* baz_obj should still be valid */ - printf("baz_obj.to_string()=%s\n", json_object_to_json_string(baz_obj)); - json_object_put(baz_obj); + printf("baz_obj.to_string()=%s\n", doca_third_party_json_object_to_json_string(baz_obj)); + doca_third_party_json_object_put(baz_obj); /*json_object_object_add(my_object, "arr", my_array);*/ printf("my_object=\n"); - json_object_object_foreach(my_object, key, val) + doca_third_party_json_object_object_foreach(my_object, key, val) + { + printf("\t%s: %s\n", key, doca_third_party_json_object_to_json_string(val)); + } + + json_object *empty_array = doca_third_party_json_object_new_array(); + json_object *empty_obj = doca_third_party_json_object_new_object(); + doca_third_party_json_object_object_add(my_object, "empty_array", empty_array); + doca_third_party_json_object_object_add(my_object, "empty_obj", empty_obj); + printf("my_object.to_string()=%s\n", doca_third_party_json_object_to_json_string(my_object)); + + doca_third_party_json_object_put(my_array); + my_array = doca_third_party_json_object_new_array_ext(INT_MIN + 1); + if (my_array != NULL) { - printf("\t%s: %s\n", key, json_object_to_json_string(val)); + printf("ERROR: able to allocate an array of negative size!\n"); + fflush(stdout); + doca_third_party_json_object_put(my_array); + my_array = NULL; + } + +#if SIZEOF_SIZE_T == SIZEOF_INT + my_array = doca_third_party_json_object_new_array_ext(INT_MAX / 2 + 2); + if (my_array != NULL) + { + printf("ERROR: able to allocate an array of insufficient size!\n"); + fflush(stdout); + doca_third_party_json_object_put(my_array); + my_array = NULL; } - printf("my_object.to_string()=%s\n", json_object_to_json_string(my_object)); +#endif - json_object_put(my_string); - json_object_put(my_int); - json_object_put(my_object); - json_object_put(my_array); + doca_third_party_json_object_put(my_string); + doca_third_party_json_object_put(my_int); + doca_third_party_json_object_put(my_null); + doca_third_party_json_object_put(my_object); + doca_third_party_json_object_put(my_array); return EXIT_SUCCESS; } diff --git a/third_party/json-c/tests/test1.expected b/third_party/json-c/tests/test1.expected index e36d37261..b473a8b4d 100644 --- a/third_party/json-c/tests/test1.expected +++ b/third_party/json-c/tests/test1.expected @@ -12,6 +12,7 @@ my_string=foo my_string.to_string()="foo" my_int=9 my_int.to_string()=9 +my_null.to_string()=null my_array= [0]=1 [1]=2 @@ -40,6 +41,19 @@ after del_idx(0,7)=0, my_array.to_string()=[ ] after del_idx(0,8)=-1, my_array.to_string()=[ 1, 2, 3, 4, 5, null, 7 ] after del_idx(0,6)=0, my_array.to_string()=[ 7 ] after adding more entries, my_array.to_string()=[ 7, "s1", "s2", "s3" ] +my_array= + [0]=1 + [1]=2 + [2]=3 + [3]=4 + [4]=5 + [5]=null + [6]=7 +my_array.to_string()=[ 1, 2, 3, 4, 5, null, 7 ] +put_idx(5,6)=0 +put_idx(63,0)=0 +put_idx(129,0)=0 +put_idx(SIZE_T_MAX,0)=-1 my_array= [0]=3 [1]=1 @@ -54,10 +68,11 @@ my_array= [3]=2 [4]=3 my_array.to_string()=[ null, 0, 1, 2, 3 ] +find json_object(1) in my_array successfully: 1 baz_obj.to_string()="fark" my_object= abc: 12 foo: "bar" bool0: false bool1: true -my_object.to_string()={ "abc": 12, "foo": "bar", "bool0": false, "bool1": true } +my_object.to_string()={ "abc": 12, "foo": "bar", "bool0": false, "bool1": true, "empty_array": [ ], "empty_obj": { } } diff --git a/third_party/json-c/tests/test1.test b/third_party/json-c/tests/test1.test index 79d2e09a8..0331f9815 100755 --- a/third_party/json-c/tests/test1.test +++ b/third_party/json-c/tests/test1.test @@ -19,4 +19,20 @@ for flag in plain spaced pretty ; do fi done +# Spaced and pretty JSON string +run_output_test -o test1Formatted_spaced_pretty \ + test1Formatted spaced pretty +_err2=$? +if [ $_err -eq 0 ] ; then + _err=$_err2 +fi + +# Spaced and pretty JSON string using tabs +run_output_test -o test1Formatted_spaced_pretty_pretty_tab \ + test1Formatted spaced pretty pretty_tab +_err2=$? +if [ $_err -eq 0 ] ; then + _err=$_err2 +fi + exit $_err diff --git a/third_party/json-c/tests/test1Formatted_plain.expected b/third_party/json-c/tests/test1Formatted_plain.expected index 8a05723f2..ad12d9917 100644 --- a/third_party/json-c/tests/test1Formatted_plain.expected +++ b/third_party/json-c/tests/test1Formatted_plain.expected @@ -12,6 +12,7 @@ my_string=foo my_string.to_string()="foo" my_int=9 my_int.to_string()=9 +my_null.to_string()=null my_array= [0]=1 [1]=2 @@ -40,6 +41,19 @@ after del_idx(0,7)=0, my_array.to_string()=[] after del_idx(0,8)=-1, my_array.to_string()=[1,2,3,4,5,null,7] after del_idx(0,6)=0, my_array.to_string()=[7] after adding more entries, my_array.to_string()=[7,"s1","s2","s3"] +my_array= + [0]=1 + [1]=2 + [2]=3 + [3]=4 + [4]=5 + [5]=null + [6]=7 +my_array.to_string()=[1,2,3,4,5,null,7] +put_idx(5,6)=0 +put_idx(63,0)=0 +put_idx(129,0)=0 +put_idx(SIZE_T_MAX,0)=-1 my_array= [0]=3 [1]=1 @@ -54,10 +68,11 @@ my_array= [3]=2 [4]=3 my_array.to_string()=[null,0,1,2,3] +find json_object(1) in my_array successfully: 1 baz_obj.to_string()="fark" my_object= abc: 12 foo: "bar" bool0: false bool1: true -my_object.to_string()={"abc":12,"foo":"bar","bool0":false,"bool1":true} +my_object.to_string()={"abc":12,"foo":"bar","bool0":false,"bool1":true,"empty_array":[],"empty_obj":{}} diff --git a/third_party/json-c/tests/test1Formatted_pretty.expected b/third_party/json-c/tests/test1Formatted_pretty.expected index 809dfbec5..ab2cc7840 100644 --- a/third_party/json-c/tests/test1Formatted_pretty.expected +++ b/third_party/json-c/tests/test1Formatted_pretty.expected @@ -12,6 +12,7 @@ my_string=foo my_string.to_string()="foo" my_int=9 my_int.to_string()=9 +my_null.to_string()=null my_array= [0]=1 [1]=2 @@ -46,6 +47,19 @@ after del_idx(0,7)=0, my_array.to_string()=[] after del_idx(0,8)=-1, my_array.to_string()=[1,2,3,4,5,null,7] after del_idx(0,6)=0, my_array.to_string()=[7] after adding more entries, my_array.to_string()=[7,"s1","s2","s3"] +my_array= + [0]=1 + [1]=2 + [2]=3 + [3]=4 + [4]=5 + [5]=null + [6]=7 +my_array.to_string()=[1,2,3,4,5,null,7] +put_idx(5,6)=0 +put_idx(63,0)=0 +put_idx(129,0)=0 +put_idx(SIZE_T_MAX,0)=-1 my_array= [0]=3 [1]=1 @@ -72,6 +86,7 @@ my_array.to_string()=[ 2, 3 ] +find json_object(1) in my_array successfully: 1 baz_obj.to_string()="fark" my_object= abc: 12 @@ -82,5 +97,7 @@ my_object.to_string()={ "abc":12, "foo":"bar", "bool0":false, - "bool1":true + "bool1":true, + "empty_array":[], + "empty_obj":{} } diff --git a/third_party/json-c/tests/test1Formatted_spaced.expected b/third_party/json-c/tests/test1Formatted_spaced.expected index 6afb39f00..f57bd05c0 100644 --- a/third_party/json-c/tests/test1Formatted_spaced.expected +++ b/third_party/json-c/tests/test1Formatted_spaced.expected @@ -12,6 +12,7 @@ my_string=foo my_string.to_string()="foo" my_int=9 my_int.to_string()=9 +my_null.to_string()=null my_array= [0]=1 [1]=2 @@ -40,6 +41,19 @@ after del_idx(0,7)=0, my_array.to_string()=[] after del_idx(0,8)=-1, my_array.to_string()=[1,2,3,4,5,null,7] after del_idx(0,6)=0, my_array.to_string()=[7] after adding more entries, my_array.to_string()=[7,"s1","s2","s3"] +my_array= + [0]=1 + [1]=2 + [2]=3 + [3]=4 + [4]=5 + [5]=null + [6]=7 +my_array.to_string()=[1,2,3,4,5,null,7] +put_idx(5,6)=0 +put_idx(63,0)=0 +put_idx(129,0)=0 +put_idx(SIZE_T_MAX,0)=-1 my_array= [0]=3 [1]=1 @@ -54,10 +68,11 @@ my_array= [3]=2 [4]=3 my_array.to_string()=[ null, 0, 1, 2, 3 ] +find json_object(1) in my_array successfully: 1 baz_obj.to_string()="fark" my_object= abc: 12 foo: "bar" bool0: false bool1: true -my_object.to_string()={ "abc": 12, "foo": "bar", "bool0": false, "bool1": true } +my_object.to_string()={ "abc": 12, "foo": "bar", "bool0": false, "bool1": true, "empty_array": [ ], "empty_obj": { } } diff --git a/third_party/json-c/tests/test1Formatted_spaced_pretty.expected b/third_party/json-c/tests/test1Formatted_spaced_pretty.expected new file mode 100644 index 000000000..c88729fab --- /dev/null +++ b/third_party/json-c/tests/test1Formatted_spaced_pretty.expected @@ -0,0 +1,103 @@ +my_string= +my_string.to_string()="\t" +my_string=\ +my_string.to_string()="\\" +my_string=/ +my_string.to_string()="\/" +my_string.to_string(NOSLASHESCAPE)="/" +my_string=/foo/bar/baz +my_string.to_string()="\/foo\/bar\/baz" +my_string.to_string(NOSLASHESCAPE)="/foo/bar/baz" +my_string=foo +my_string.to_string()="foo" +my_int=9 +my_int.to_string()=9 +my_null.to_string()=null +my_array= + [0]=1 + [1]=2 + [2]=3 + [3]=null + [4]=5 +my_array.to_string()=[ + 1, + 2, + 3, + null, + 5 +] +my_array= + [0]=1 + [1]=2 + [2]=3 + [3]=4 + [4]=5 + [5]=null + [6]=7 +my_array.to_string()=[1,2,3,4,5,null,7] +after del_idx(0,1)=0, my_array.to_string()=[2,3,4,5,null,7] +after del_idx(0,1)=0, my_array.to_string()=[3,4,5,null,7] +after del_idx(0,1)=0, my_array.to_string()=[4,5,null,7] +after del_idx(0,1)=0, my_array.to_string()=[5,null,7] +after del_idx(0,1)=0, my_array.to_string()=[null,7] +after del_idx(0,1)=0, my_array.to_string()=[7] +after del_idx(0,1)=0, my_array.to_string()=[] +after del_idx(0,1)=-1, my_array.to_string()=[] +after del_idx(0,7)=0, my_array.to_string()=[] +after del_idx(0,8)=-1, my_array.to_string()=[1,2,3,4,5,null,7] +after del_idx(0,6)=0, my_array.to_string()=[7] +after adding more entries, my_array.to_string()=[7,"s1","s2","s3"] +my_array= + [0]=1 + [1]=2 + [2]=3 + [3]=4 + [4]=5 + [5]=null + [6]=7 +my_array.to_string()=[1,2,3,4,5,null,7] +put_idx(5,6)=0 +put_idx(63,0)=0 +put_idx(129,0)=0 +put_idx(SIZE_T_MAX,0)=-1 +my_array= + [0]=3 + [1]=1 + [2]=2 + [3]=null + [4]=0 +my_array.to_string()=[ + 3, + 1, + 2, + null, + 0 +] +my_array= + [0]=null + [1]=0 + [2]=1 + [3]=2 + [4]=3 +my_array.to_string()=[ + null, + 0, + 1, + 2, + 3 +] +find json_object(1) in my_array successfully: 1 +baz_obj.to_string()="fark" +my_object= + abc: 12 + foo: "bar" + bool0: false + bool1: true +my_object.to_string()={ + "abc": 12, + "foo": "bar", + "bool0": false, + "bool1": true, + "empty_array": [], + "empty_obj": {} +} diff --git a/third_party/json-c/tests/test1Formatted_spaced_pretty_pretty_tab.expected b/third_party/json-c/tests/test1Formatted_spaced_pretty_pretty_tab.expected new file mode 100644 index 000000000..bab239ff8 --- /dev/null +++ b/third_party/json-c/tests/test1Formatted_spaced_pretty_pretty_tab.expected @@ -0,0 +1,103 @@ +my_string= +my_string.to_string()="\t" +my_string=\ +my_string.to_string()="\\" +my_string=/ +my_string.to_string()="\/" +my_string.to_string(NOSLASHESCAPE)="/" +my_string=/foo/bar/baz +my_string.to_string()="\/foo\/bar\/baz" +my_string.to_string(NOSLASHESCAPE)="/foo/bar/baz" +my_string=foo +my_string.to_string()="foo" +my_int=9 +my_int.to_string()=9 +my_null.to_string()=null +my_array= + [0]=1 + [1]=2 + [2]=3 + [3]=null + [4]=5 +my_array.to_string()=[ + 1, + 2, + 3, + null, + 5 +] +my_array= + [0]=1 + [1]=2 + [2]=3 + [3]=4 + [4]=5 + [5]=null + [6]=7 +my_array.to_string()=[1,2,3,4,5,null,7] +after del_idx(0,1)=0, my_array.to_string()=[2,3,4,5,null,7] +after del_idx(0,1)=0, my_array.to_string()=[3,4,5,null,7] +after del_idx(0,1)=0, my_array.to_string()=[4,5,null,7] +after del_idx(0,1)=0, my_array.to_string()=[5,null,7] +after del_idx(0,1)=0, my_array.to_string()=[null,7] +after del_idx(0,1)=0, my_array.to_string()=[7] +after del_idx(0,1)=0, my_array.to_string()=[] +after del_idx(0,1)=-1, my_array.to_string()=[] +after del_idx(0,7)=0, my_array.to_string()=[] +after del_idx(0,8)=-1, my_array.to_string()=[1,2,3,4,5,null,7] +after del_idx(0,6)=0, my_array.to_string()=[7] +after adding more entries, my_array.to_string()=[7,"s1","s2","s3"] +my_array= + [0]=1 + [1]=2 + [2]=3 + [3]=4 + [4]=5 + [5]=null + [6]=7 +my_array.to_string()=[1,2,3,4,5,null,7] +put_idx(5,6)=0 +put_idx(63,0)=0 +put_idx(129,0)=0 +put_idx(SIZE_T_MAX,0)=-1 +my_array= + [0]=3 + [1]=1 + [2]=2 + [3]=null + [4]=0 +my_array.to_string()=[ + 3, + 1, + 2, + null, + 0 +] +my_array= + [0]=null + [1]=0 + [2]=1 + [3]=2 + [4]=3 +my_array.to_string()=[ + null, + 0, + 1, + 2, + 3 +] +find json_object(1) in my_array successfully: 1 +baz_obj.to_string()="fark" +my_object= + abc: 12 + foo: "bar" + bool0: false + bool1: true +my_object.to_string()={ + "abc": 12, + "foo": "bar", + "bool0": false, + "bool1": true, + "empty_array": [], + "empty_obj": {} +} diff --git a/third_party/json-c/tests/test2.c b/third_party/json-c/tests/test2.c index 06a453e50..b94874224 100644 --- a/third_party/json-c/tests/test2.c +++ b/third_party/json-c/tests/test2.c @@ -1,18 +1,39 @@ +/* + * Original work: + * + * json-c (copyright was originally missing from this file) + * + * Modified Work: + * + * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. + * + * This software product is a proprietary product of NVIDIA CORPORATION & + * AFFILIATES (the "Company") and all right, title, and interest in and to the + * software product, including all associated intellectual property rights, are + * and shall remain exclusively with the Company. + * + * This software product is governed by the End User License Agreement + * provided with the software product. + * + */ + +#ifdef NDEBUG +#undef NDEBUG +#endif +#include #include #include -#include #include #include "json.h" #include "parse_flags.h" #ifdef TEST_FORMATTED -#define json_object_to_json_string(obj) json_object_to_json_string_ext(obj,sflags) +#define doca_third_party_json_object_to_json_string(obj) doca_third_party_json_object_to_json_string_ext(obj, sflags) #else /* no special define */ #endif - int main(int argc, char **argv) { json_object *new_obj; @@ -26,10 +47,15 @@ int main(int argc, char **argv) sflags = parse_flags(argc, argv); #endif - new_obj = json_tokener_parse("/* more difficult test case */" - "{ \"glossary\": { \"title\": \"example glossary\", \"GlossDiv\": { \"title\": \"S\", \"GlossList\": [ { \"ID\": \"SGML\", \"SortAs\": \"SGML\", \"GlossTerm\": \"Standard Generalized Markup Language\", \"Acronym\": \"SGML\", \"Abbrev\": \"ISO 8879:1986\", \"GlossDef\": \"A meta-markup language, used to create markup languages such as DocBook.\", \"GlossSeeAlso\": [\"GML\", \"XML\", \"markup\"] } ] } } }"); - printf("new_obj.to_string()=%s\n", json_object_to_json_string(new_obj)); - json_object_put(new_obj); + new_obj = doca_third_party_json_tokener_parse( + "/* more difficult test case */" + "{ \"glossary\": { \"title\": \"example glossary\", \"GlossDiv\": { \"title\": \"S\", " + "\"GlossList\": [ { \"ID\": \"SGML\", \"SortAs\": \"SGML\", \"GlossTerm\": \"Standard " + "Generalized Markup Language\", \"Acronym\": \"SGML\", \"Abbrev\": \"ISO 8879:1986\", " + "\"GlossDef\": \"A meta-markup language, used to create markup languages such as " + "DocBook.\", \"GlossSeeAlso\": [\"GML\", \"XML\", \"markup\"] } ] } } }"); + printf("new_obj.to_string()=%s\n", doca_third_party_json_object_to_json_string(new_obj)); + doca_third_party_json_object_put(new_obj); return EXIT_SUCCESS; } diff --git a/third_party/json-c/tests/test2.test b/third_party/json-c/tests/test2.test index d4a4e792b..b5330fe26 100755 --- a/third_party/json-c/tests/test2.test +++ b/third_party/json-c/tests/test2.test @@ -19,4 +19,20 @@ for flag in plain spaced pretty ; do fi done +# Spaced and pretty JSON string +run_output_test -o test2Formatted_spaced_pretty \ + test2Formatted spaced pretty +_err2=$? +if [ $_err -eq 0 ] ; then + _err=$_err2 +fi + +# Spaced and pretty JSON string using tabs +run_output_test -o test2Formatted_spaced_pretty_pretty_tab \ + test2Formatted spaced pretty pretty_tab +_err2=$? +if [ $_err -eq 0 ] ; then + _err=$_err2 +fi + exit $_err diff --git a/third_party/json-c/tests/test2Formatted_spaced_pretty.expected b/third_party/json-c/tests/test2Formatted_spaced_pretty.expected new file mode 100644 index 000000000..49f9ef281 --- /dev/null +++ b/third_party/json-c/tests/test2Formatted_spaced_pretty.expected @@ -0,0 +1,23 @@ +new_obj.to_string()={ + "glossary": { + "title": "example glossary", + "GlossDiv": { + "title": "S", + "GlossList": [ + { + "ID": "SGML", + "SortAs": "SGML", + "GlossTerm": "Standard Generalized Markup Language", + "Acronym": "SGML", + "Abbrev": "ISO 8879:1986", + "GlossDef": "A meta-markup language, used to create markup languages such as DocBook.", + "GlossSeeAlso": [ + "GML", + "XML", + "markup" + ] + } + ] + } + } +} diff --git a/third_party/json-c/tests/test2Formatted_spaced_pretty_pretty_tab.expected b/third_party/json-c/tests/test2Formatted_spaced_pretty_pretty_tab.expected new file mode 100644 index 000000000..0296b9cb0 --- /dev/null +++ b/third_party/json-c/tests/test2Formatted_spaced_pretty_pretty_tab.expected @@ -0,0 +1,23 @@ +new_obj.to_string()={ + "glossary": { + "title": "example glossary", + "GlossDiv": { + "title": "S", + "GlossList": [ + { + "ID": "SGML", + "SortAs": "SGML", + "GlossTerm": "Standard Generalized Markup Language", + "Acronym": "SGML", + "Abbrev": "ISO 8879:1986", + "GlossDef": "A meta-markup language, used to create markup languages such as DocBook.", + "GlossSeeAlso": [ + "GML", + "XML", + "markup" + ] + } + ] + } + } +} diff --git a/third_party/json-c/tests/test4.c b/third_party/json-c/tests/test4.c index fc8b79dbf..17c69dd1e 100644 --- a/third_party/json-c/tests/test4.c +++ b/third_party/json-c/tests/test4.c @@ -1,45 +1,96 @@ +/* + * Original work: + * + * json-c (copyright was originally missing from this file) + * + * Modified Work: + * + * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. + * + * This software product is a proprietary product of NVIDIA CORPORATION & + * AFFILIATES (the "Company") and all right, title, and interest in and to the + * software product, including all associated intellectual property rights, are + * and shall remain exclusively with the Company. + * + * This software product is governed by the End User License Agreement + * provided with the software product. + * + */ + /* * gcc -o utf8 utf8.c -I/home/y/include -L./.libs -ljson */ +#ifdef NDEBUG +#undef NDEBUG +#endif +#include "config.h" +#include #include +#include #include -#include "config.h" #include "json_inttypes.h" #include "json_object.h" #include "json_tokener.h" +#include "snprintf_compat.h" -void print_hex(const char* s) +void print_hex(const char *s) { const char *iter = s; unsigned char ch; while ((ch = *iter++) != 0) { - if( ',' != ch) + if (',' != ch) printf("%x ", ch); else - printf( ","); + printf(","); } putchar('\n'); } +static void test_lot_of_adds(void); +static void test_lot_of_adds(void) +{ + int ii; + char key[50]; + json_object *jobj = doca_third_party_json_object_new_object(); + assert(jobj != NULL); + for (ii = 0; ii < 500; ii++) + { + snprintf(key, sizeof(key), "k%d", ii); + json_object *iobj = doca_third_party_json_object_new_int(ii); + assert(iobj != NULL); + if (doca_third_party_json_object_object_add(jobj, key, iobj)) + { + fprintf(stderr, "FAILED to add object #%d\n", ii); + abort(); + } + } + printf("%s\n", doca_third_party_json_object_to_json_string(jobj)); + assert(doca_third_party_json_object_object_length(jobj) == 500); + doca_third_party_json_object_put(jobj); +} + int main(void) { const char *input = "\"\\ud840\\udd26,\\ud840\\udd27,\\ud800\\udd26,\\ud800\\udd27\""; - const char *expected = "\xF0\xA0\x84\xA6,\xF0\xA0\x84\xA7,\xF0\x90\x84\xA6,\xF0\x90\x84\xA7"; - struct json_object *parse_result = json_tokener_parse(input); - const char *unjson = json_object_get_string(parse_result); + const char *expected = + "\xF0\xA0\x84\xA6,\xF0\xA0\x84\xA7,\xF0\x90\x84\xA6,\xF0\x90\x84\xA7"; + struct json_object *parse_result = doca_third_party_json_tokener_parse(input); + const char *unjson = doca_third_party_json_object_get_string(parse_result); printf("input: %s\n", input); - int strings_match = !strcmp( expected, unjson); + int strings_match = !strcmp(expected, unjson); int retval = 0; if (strings_match) { printf("JSON parse result is correct: %s\n", unjson); puts("PASS"); - } else { + } + else + { printf("JSON parse result doesn't match expected string\n"); printf("expected string bytes: "); print_hex(expected); @@ -48,6 +99,9 @@ int main(void) puts("FAIL"); retval = 1; } - json_object_put(parse_result); + doca_third_party_json_object_put(parse_result); + + test_lot_of_adds(); + return retval; } diff --git a/third_party/json-c/tests/test4.expected b/third_party/json-c/tests/test4.expected index 68d4336d9..cb2744012 100644 --- a/third_party/json-c/tests/test4.expected +++ b/third_party/json-c/tests/test4.expected @@ -1,3 +1,4 @@ input: "\ud840\udd26,\ud840\udd27,\ud800\udd26,\ud800\udd27" JSON parse result is correct: 𠄦,𠄧,𐄦,𐄧 PASS +{ "k0": 0, "k1": 1, "k2": 2, "k3": 3, "k4": 4, "k5": 5, "k6": 6, "k7": 7, "k8": 8, "k9": 9, "k10": 10, "k11": 11, "k12": 12, "k13": 13, "k14": 14, "k15": 15, "k16": 16, "k17": 17, "k18": 18, "k19": 19, "k20": 20, "k21": 21, "k22": 22, "k23": 23, "k24": 24, "k25": 25, "k26": 26, "k27": 27, "k28": 28, "k29": 29, "k30": 30, "k31": 31, "k32": 32, "k33": 33, "k34": 34, "k35": 35, "k36": 36, "k37": 37, "k38": 38, "k39": 39, "k40": 40, "k41": 41, "k42": 42, "k43": 43, "k44": 44, "k45": 45, "k46": 46, "k47": 47, "k48": 48, "k49": 49, "k50": 50, "k51": 51, "k52": 52, "k53": 53, "k54": 54, "k55": 55, "k56": 56, "k57": 57, "k58": 58, "k59": 59, "k60": 60, "k61": 61, "k62": 62, "k63": 63, "k64": 64, "k65": 65, "k66": 66, "k67": 67, "k68": 68, "k69": 69, "k70": 70, "k71": 71, "k72": 72, "k73": 73, "k74": 74, "k75": 75, "k76": 76, "k77": 77, "k78": 78, "k79": 79, "k80": 80, "k81": 81, "k82": 82, "k83": 83, "k84": 84, "k85": 85, "k86": 86, "k87": 87, "k88": 88, "k89": 89, "k90": 90, "k91": 91, "k92": 92, "k93": 93, "k94": 94, "k95": 95, "k96": 96, "k97": 97, "k98": 98, "k99": 99, "k100": 100, "k101": 101, "k102": 102, "k103": 103, "k104": 104, "k105": 105, "k106": 106, "k107": 107, "k108": 108, "k109": 109, "k110": 110, "k111": 111, "k112": 112, "k113": 113, "k114": 114, "k115": 115, "k116": 116, "k117": 117, "k118": 118, "k119": 119, "k120": 120, "k121": 121, "k122": 122, "k123": 123, "k124": 124, "k125": 125, "k126": 126, "k127": 127, "k128": 128, "k129": 129, "k130": 130, "k131": 131, "k132": 132, "k133": 133, "k134": 134, "k135": 135, "k136": 136, "k137": 137, "k138": 138, "k139": 139, "k140": 140, "k141": 141, "k142": 142, "k143": 143, "k144": 144, "k145": 145, "k146": 146, "k147": 147, "k148": 148, "k149": 149, "k150": 150, "k151": 151, "k152": 152, "k153": 153, "k154": 154, "k155": 155, "k156": 156, "k157": 157, "k158": 158, "k159": 159, "k160": 160, "k161": 161, "k162": 162, "k163": 163, "k164": 164, "k165": 165, "k166": 166, "k167": 167, "k168": 168, "k169": 169, "k170": 170, "k171": 171, "k172": 172, "k173": 173, "k174": 174, "k175": 175, "k176": 176, "k177": 177, "k178": 178, "k179": 179, "k180": 180, "k181": 181, "k182": 182, "k183": 183, "k184": 184, "k185": 185, "k186": 186, "k187": 187, "k188": 188, "k189": 189, "k190": 190, "k191": 191, "k192": 192, "k193": 193, "k194": 194, "k195": 195, "k196": 196, "k197": 197, "k198": 198, "k199": 199, "k200": 200, "k201": 201, "k202": 202, "k203": 203, "k204": 204, "k205": 205, "k206": 206, "k207": 207, "k208": 208, "k209": 209, "k210": 210, "k211": 211, "k212": 212, "k213": 213, "k214": 214, "k215": 215, "k216": 216, "k217": 217, "k218": 218, "k219": 219, "k220": 220, "k221": 221, "k222": 222, "k223": 223, "k224": 224, "k225": 225, "k226": 226, "k227": 227, "k228": 228, "k229": 229, "k230": 230, "k231": 231, "k232": 232, "k233": 233, "k234": 234, "k235": 235, "k236": 236, "k237": 237, "k238": 238, "k239": 239, "k240": 240, "k241": 241, "k242": 242, "k243": 243, "k244": 244, "k245": 245, "k246": 246, "k247": 247, "k248": 248, "k249": 249, "k250": 250, "k251": 251, "k252": 252, "k253": 253, "k254": 254, "k255": 255, "k256": 256, "k257": 257, "k258": 258, "k259": 259, "k260": 260, "k261": 261, "k262": 262, "k263": 263, "k264": 264, "k265": 265, "k266": 266, "k267": 267, "k268": 268, "k269": 269, "k270": 270, "k271": 271, "k272": 272, "k273": 273, "k274": 274, "k275": 275, "k276": 276, "k277": 277, "k278": 278, "k279": 279, "k280": 280, "k281": 281, "k282": 282, "k283": 283, "k284": 284, "k285": 285, "k286": 286, "k287": 287, "k288": 288, "k289": 289, "k290": 290, "k291": 291, "k292": 292, "k293": 293, "k294": 294, "k295": 295, "k296": 296, "k297": 297, "k298": 298, "k299": 299, "k300": 300, "k301": 301, "k302": 302, "k303": 303, "k304": 304, "k305": 305, "k306": 306, "k307": 307, "k308": 308, "k309": 309, "k310": 310, "k311": 311, "k312": 312, "k313": 313, "k314": 314, "k315": 315, "k316": 316, "k317": 317, "k318": 318, "k319": 319, "k320": 320, "k321": 321, "k322": 322, "k323": 323, "k324": 324, "k325": 325, "k326": 326, "k327": 327, "k328": 328, "k329": 329, "k330": 330, "k331": 331, "k332": 332, "k333": 333, "k334": 334, "k335": 335, "k336": 336, "k337": 337, "k338": 338, "k339": 339, "k340": 340, "k341": 341, "k342": 342, "k343": 343, "k344": 344, "k345": 345, "k346": 346, "k347": 347, "k348": 348, "k349": 349, "k350": 350, "k351": 351, "k352": 352, "k353": 353, "k354": 354, "k355": 355, "k356": 356, "k357": 357, "k358": 358, "k359": 359, "k360": 360, "k361": 361, "k362": 362, "k363": 363, "k364": 364, "k365": 365, "k366": 366, "k367": 367, "k368": 368, "k369": 369, "k370": 370, "k371": 371, "k372": 372, "k373": 373, "k374": 374, "k375": 375, "k376": 376, "k377": 377, "k378": 378, "k379": 379, "k380": 380, "k381": 381, "k382": 382, "k383": 383, "k384": 384, "k385": 385, "k386": 386, "k387": 387, "k388": 388, "k389": 389, "k390": 390, "k391": 391, "k392": 392, "k393": 393, "k394": 394, "k395": 395, "k396": 396, "k397": 397, "k398": 398, "k399": 399, "k400": 400, "k401": 401, "k402": 402, "k403": 403, "k404": 404, "k405": 405, "k406": 406, "k407": 407, "k408": 408, "k409": 409, "k410": 410, "k411": 411, "k412": 412, "k413": 413, "k414": 414, "k415": 415, "k416": 416, "k417": 417, "k418": 418, "k419": 419, "k420": 420, "k421": 421, "k422": 422, "k423": 423, "k424": 424, "k425": 425, "k426": 426, "k427": 427, "k428": 428, "k429": 429, "k430": 430, "k431": 431, "k432": 432, "k433": 433, "k434": 434, "k435": 435, "k436": 436, "k437": 437, "k438": 438, "k439": 439, "k440": 440, "k441": 441, "k442": 442, "k443": 443, "k444": 444, "k445": 445, "k446": 446, "k447": 447, "k448": 448, "k449": 449, "k450": 450, "k451": 451, "k452": 452, "k453": 453, "k454": 454, "k455": 455, "k456": 456, "k457": 457, "k458": 458, "k459": 459, "k460": 460, "k461": 461, "k462": 462, "k463": 463, "k464": 464, "k465": 465, "k466": 466, "k467": 467, "k468": 468, "k469": 469, "k470": 470, "k471": 471, "k472": 472, "k473": 473, "k474": 474, "k475": 475, "k476": 476, "k477": 477, "k478": 478, "k479": 479, "k480": 480, "k481": 481, "k482": 482, "k483": 483, "k484": 484, "k485": 485, "k486": 486, "k487": 487, "k488": 488, "k489": 489, "k490": 490, "k491": 491, "k492": 492, "k493": 493, "k494": 494, "k495": 495, "k496": 496, "k497": 497, "k498": 498, "k499": 499 } diff --git a/third_party/json-c/tests/testReplaceExisting.c b/third_party/json-c/tests/testReplaceExisting.c index 79f37c521..bd6c585c0 100644 --- a/third_party/json-c/tests/testReplaceExisting.c +++ b/third_party/json-c/tests/testReplaceExisting.c @@ -1,6 +1,28 @@ +/* + * Original work: + * + * json-c (copyright was originally missing from this file) + * + * Modified Work: + * + * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. + * + * This software product is a proprietary product of NVIDIA CORPORATION & + * AFFILIATES (the "Company") and all right, title, and interest in and to the + * software product, including all associated intellectual property rights, are + * and shall remain exclusively with the Company. + * + * This software product is governed by the End User License Agreement + * provided with the software product. + * + */ + +#ifdef NDEBUG +#undef NDEBUG +#endif +#include #include #include -#include #include #include "json.h" @@ -13,21 +35,21 @@ int main(int argc, char **argv) * Check that replacing an existing object keeps the key valid, * and that it keeps the order the same. */ - json_object *my_object = json_object_new_object(); - json_object_object_add(my_object, "foo1", json_object_new_string("bar1")); - json_object_object_add(my_object, "foo2", json_object_new_string("bar2")); - json_object_object_add(my_object, "deleteme", json_object_new_string("bar2")); - json_object_object_add(my_object, "foo3", json_object_new_string("bar3")); + json_object *my_object = doca_third_party_json_object_new_object(); + doca_third_party_json_object_object_add(my_object, "foo1", doca_third_party_json_object_new_string("bar1")); + doca_third_party_json_object_object_add(my_object, "foo2", doca_third_party_json_object_new_string("bar2")); + doca_third_party_json_object_object_add(my_object, "deleteme", doca_third_party_json_object_new_string("bar2")); + doca_third_party_json_object_object_add(my_object, "foo3", doca_third_party_json_object_new_string("bar3")); printf("==== delete-in-loop test starting ====\n"); int orig_count = 0; - json_object_object_foreach(my_object, key0, val0) + doca_third_party_json_object_object_foreach(my_object, key0, val0) { printf("Key at index %d is [%s] %d", orig_count, key0, (val0 == NULL)); if (strcmp(key0, "deleteme") == 0) { - json_object_object_del(my_object, key0); + doca_third_party_json_object_object_del(my_object, key0); printf(" (deleted)\n"); } else @@ -39,7 +61,7 @@ int main(int argc, char **argv) const char *original_key = NULL; orig_count = 0; - json_object_object_foreach(my_object, key, val) + doca_third_party_json_object_object_foreach(my_object, key, val) { printf("Key at index %d is [%s] %d\n", orig_count, key, (val == NULL)); orig_count++; @@ -47,14 +69,14 @@ int main(int argc, char **argv) continue; printf("replacing value for key [%s]\n", key); original_key = key; - json_object_object_add(my_object, key, json_object_new_string("zzz")); + doca_third_party_json_object_object_add(my_object, key, doca_third_party_json_object_new_string("zzz")); } printf("==== second loop starting ====\n"); int new_count = 0; int retval = 0; - json_object_object_foreach(my_object, key2, val2) + doca_third_party_json_object_object_foreach(my_object, key2, val2) { printf("Key at index %d is [%s] %d\n", new_count, key2, (val2 == NULL)); new_count++; @@ -67,12 +89,12 @@ int main(int argc, char **argv) } if (new_count != orig_count) { - printf("mismatch between original count (%d) and new count (%d)\n", - orig_count, new_count); + printf("mismatch between original count (%d) and new count (%d)\n", orig_count, + new_count); retval = 1; } - json_object_put( my_object ); + doca_third_party_json_object_put(my_object); return retval; } diff --git a/third_party/json-c/tests/test_basic.test b/third_party/json-c/tests/test_basic.test index 154e036d5..474e7a827 100755 --- a/third_party/json-c/tests/test_basic.test +++ b/third_party/json-c/tests/test_basic.test @@ -1,5 +1,7 @@ #!/bin/sh +export _JSON_C_STRERROR_ENABLE=1 + # Common definitions if test -z "$srcdir"; then srcdir="${0%/*}" diff --git a/third_party/json-c/tests/test_cast.c b/third_party/json-c/tests/test_cast.c index 7e2bcd5e1..ad9ad73af 100644 --- a/third_party/json-c/tests/test_cast.c +++ b/third_party/json-c/tests/test_cast.c @@ -1,12 +1,34 @@ +/* + * Original work: + * + * json-c (copyright was originally missing from this file) + * + * Modified Work: + * + * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. + * + * This software product is a proprietary product of NVIDIA CORPORATION & + * AFFILIATES (the "Company") and all right, title, and interest in and to the + * software product, including all associated intellectual property rights, are + * and shall remain exclusively with the Company. + * + * This software product is governed by the End User License Agreement + * provided with the software product. + * + */ + /* * Tests if casting within the json_object_get_* functions work correctly. * Also checks the json_object_get_type and json_object_is_type functions. */ +#ifdef NDEBUG +#undef NDEBUG +#endif +#include "config.h" #include -#include #include -#include "config.h" +#include #include "json_inttypes.h" #include "json_object.h" @@ -25,14 +47,22 @@ int main(int argc, char **argv) \"decimal_number\": 99.55,\n\ \"boolean_true\": true,\n\ \"boolean_false\": false,\n\ - \"big_number\": 2147483649,\n\ + \"int64_number\": 2147483649,\n\ + \"negative_number\": -321321321,\n\ \"a_null\": null,\n\ + \"empty_array\": [],\n\ + \"nonempty_array\": [ 123 ],\n\ + \"array_with_zero\": [ 0 ],\n\ + \"empty_object\": {},\n\ + \"nonempty_object\": { \"a\": 123 },\n\ }"; /* Note: 2147483649 = INT_MAX + 2 */ + /* Note: 9223372036854775809 = INT64_MAX + 2 */ + /* Note: 18446744073709551617 = UINT64_MAX + 2 */ struct json_object *new_obj; - new_obj = json_tokener_parse(input); + new_obj = doca_third_party_json_tokener_parse(input); printf("Parsed input: %s\n", input); printf("Result is %s\n", (new_obj == NULL) ? "NULL (error!)" : "not NULL"); if (!new_obj) @@ -43,8 +73,14 @@ int main(int argc, char **argv) getit(new_obj, "decimal_number"); getit(new_obj, "boolean_true"); getit(new_obj, "boolean_false"); - getit(new_obj, "big_number"); + getit(new_obj, "int64_number"); + getit(new_obj, "negative_number"); getit(new_obj, "a_null"); + getit(new_obj, "empty_array"); + getit(new_obj, "nonempty_array"); + getit(new_obj, "array_with_zero"); + getit(new_obj, "empty_object"); + getit(new_obj, "nonempty_object"); // Now check the behaviour of the json_object_is_type() function. printf("\n================================\n"); @@ -55,10 +91,11 @@ int main(int argc, char **argv) checktype(new_obj, "decimal_number"); checktype(new_obj, "boolean_true"); checktype(new_obj, "boolean_false"); - checktype(new_obj, "big_number"); + checktype(new_obj, "int64_number"); + checktype(new_obj, "negative_number"); checktype(new_obj, "a_null"); - json_object_put(new_obj); + doca_third_party_json_object_put(new_obj); return 0; } @@ -66,46 +103,35 @@ int main(int argc, char **argv) static void getit(struct json_object *new_obj, const char *field) { struct json_object *o = NULL; - if (!json_object_object_get_ex(new_obj, field, &o)) + if (!doca_third_party_json_object_object_get_ex(new_obj, field, &o)) printf("Field %s does not exist\n", field); - enum json_type o_type = json_object_get_type(o); - printf("new_obj.%s json_object_get_type()=%s\n", field, - json_type_to_name(o_type)); - printf("new_obj.%s json_object_get_int()=%d\n", field, - json_object_get_int(o)); - printf("new_obj.%s json_object_get_int64()=%" PRId64 "\n", field, - json_object_get_int64(o)); - printf("new_obj.%s json_object_get_boolean()=%d\n", field, - json_object_get_boolean(o)); - printf("new_obj.%s json_object_get_double()=%f\n", field, - json_object_get_double(o)); + enum json_type o_type = doca_third_party_json_object_get_type(o); + printf("new_obj.%s json_object_get_type()=%s\n", field, doca_third_party_json_type_to_name(o_type)); + printf("new_obj.%s json_object_get_int()=%d\n", field, doca_third_party_json_object_get_int(o)); + printf("new_obj.%s json_object_get_int64()=%" PRId64 "\n", field, doca_third_party_json_object_get_int64(o)); + printf("new_obj.%s json_object_get_uint64()=%" PRIu64 "\n", field, + doca_third_party_json_object_get_uint64(o)); + printf("new_obj.%s json_object_get_boolean()=%d\n", field, doca_third_party_json_object_get_boolean(o)); + printf("new_obj.%s json_object_get_double()=%f\n", field, doca_third_party_json_object_get_double(o)); } -static void checktype_header() +static void checktype_header(void) { - printf("json_object_is_type: %s,%s,%s,%s,%s,%s,%s\n", - json_type_to_name(json_type_null), - json_type_to_name(json_type_boolean), - json_type_to_name(json_type_double), - json_type_to_name(json_type_int), - json_type_to_name(json_type_object), - json_type_to_name(json_type_array), - json_type_to_name(json_type_string)); + printf("json_object_is_type: %s,%s,%s,%s,%s,%s,%s\n", doca_third_party_json_type_to_name(json_type_null), + doca_third_party_json_type_to_name(json_type_boolean), doca_third_party_json_type_to_name(json_type_double), + doca_third_party_json_type_to_name(json_type_int), doca_third_party_json_type_to_name(json_type_object), + doca_third_party_json_type_to_name(json_type_array), doca_third_party_json_type_to_name(json_type_string)); } static void checktype(struct json_object *new_obj, const char *field) { struct json_object *o = new_obj; - if (field && !json_object_object_get_ex(new_obj, field, &o)) + if (field && !doca_third_party_json_object_object_get_ex(new_obj, field, &o)) printf("Field %s does not exist\n", field); - - printf("new_obj%s%-18s: %d,%d,%d,%d,%d,%d,%d\n", - field ? "." : " ", field ? field : "", - json_object_is_type(o, json_type_null), - json_object_is_type(o, json_type_boolean), - json_object_is_type(o, json_type_double), - json_object_is_type(o, json_type_int), - json_object_is_type(o, json_type_object), - json_object_is_type(o, json_type_array), - json_object_is_type(o, json_type_string)); + + printf("new_obj%s%-18s: %d,%d,%d,%d,%d,%d,%d\n", field ? "." : " ", field ? field : "", + doca_third_party_json_object_is_type(o, json_type_null), doca_third_party_json_object_is_type(o, json_type_boolean), + doca_third_party_json_object_is_type(o, json_type_double), doca_third_party_json_object_is_type(o, json_type_int), + doca_third_party_json_object_is_type(o, json_type_object), doca_third_party_json_object_is_type(o, json_type_array), + doca_third_party_json_object_is_type(o, json_type_string)); } diff --git a/third_party/json-c/tests/test_cast.expected b/third_party/json-c/tests/test_cast.expected index 76ff8231a..6a19de9a8 100644 --- a/third_party/json-c/tests/test_cast.expected +++ b/third_party/json-c/tests/test_cast.expected @@ -4,45 +4,94 @@ Parsed input: { "decimal_number": 99.55, "boolean_true": true, "boolean_false": false, - "big_number": 2147483649, + "int64_number": 2147483649, + "negative_number": -321321321, "a_null": null, + "empty_array": [], + "nonempty_array": [ 123 ], + "array_with_zero": [ 0 ], + "empty_object": {}, + "nonempty_object": { "a": 123 }, } Result is not NULL new_obj.string_of_digits json_object_get_type()=string new_obj.string_of_digits json_object_get_int()=123 new_obj.string_of_digits json_object_get_int64()=123 +new_obj.string_of_digits json_object_get_uint64()=123 new_obj.string_of_digits json_object_get_boolean()=1 new_obj.string_of_digits json_object_get_double()=123.000000 new_obj.regular_number json_object_get_type()=int new_obj.regular_number json_object_get_int()=222 new_obj.regular_number json_object_get_int64()=222 +new_obj.regular_number json_object_get_uint64()=222 new_obj.regular_number json_object_get_boolean()=1 new_obj.regular_number json_object_get_double()=222.000000 new_obj.decimal_number json_object_get_type()=double new_obj.decimal_number json_object_get_int()=99 new_obj.decimal_number json_object_get_int64()=99 +new_obj.decimal_number json_object_get_uint64()=99 new_obj.decimal_number json_object_get_boolean()=1 new_obj.decimal_number json_object_get_double()=99.550000 new_obj.boolean_true json_object_get_type()=boolean new_obj.boolean_true json_object_get_int()=1 new_obj.boolean_true json_object_get_int64()=1 +new_obj.boolean_true json_object_get_uint64()=1 new_obj.boolean_true json_object_get_boolean()=1 new_obj.boolean_true json_object_get_double()=1.000000 new_obj.boolean_false json_object_get_type()=boolean new_obj.boolean_false json_object_get_int()=0 new_obj.boolean_false json_object_get_int64()=0 +new_obj.boolean_false json_object_get_uint64()=0 new_obj.boolean_false json_object_get_boolean()=0 new_obj.boolean_false json_object_get_double()=0.000000 -new_obj.big_number json_object_get_type()=int -new_obj.big_number json_object_get_int()=2147483647 -new_obj.big_number json_object_get_int64()=2147483649 -new_obj.big_number json_object_get_boolean()=1 -new_obj.big_number json_object_get_double()=2147483649.000000 +new_obj.int64_number json_object_get_type()=int +new_obj.int64_number json_object_get_int()=2147483647 +new_obj.int64_number json_object_get_int64()=2147483649 +new_obj.int64_number json_object_get_uint64()=2147483649 +new_obj.int64_number json_object_get_boolean()=1 +new_obj.int64_number json_object_get_double()=2147483649.000000 +new_obj.negative_number json_object_get_type()=int +new_obj.negative_number json_object_get_int()=-321321321 +new_obj.negative_number json_object_get_int64()=-321321321 +new_obj.negative_number json_object_get_uint64()=0 +new_obj.negative_number json_object_get_boolean()=1 +new_obj.negative_number json_object_get_double()=-321321321.000000 new_obj.a_null json_object_get_type()=null new_obj.a_null json_object_get_int()=0 new_obj.a_null json_object_get_int64()=0 +new_obj.a_null json_object_get_uint64()=0 new_obj.a_null json_object_get_boolean()=0 new_obj.a_null json_object_get_double()=0.000000 +new_obj.empty_array json_object_get_type()=array +new_obj.empty_array json_object_get_int()=0 +new_obj.empty_array json_object_get_int64()=0 +new_obj.empty_array json_object_get_uint64()=0 +new_obj.empty_array json_object_get_boolean()=0 +new_obj.empty_array json_object_get_double()=0.000000 +new_obj.nonempty_array json_object_get_type()=array +new_obj.nonempty_array json_object_get_int()=0 +new_obj.nonempty_array json_object_get_int64()=0 +new_obj.nonempty_array json_object_get_uint64()=0 +new_obj.nonempty_array json_object_get_boolean()=0 +new_obj.nonempty_array json_object_get_double()=0.000000 +new_obj.array_with_zero json_object_get_type()=array +new_obj.array_with_zero json_object_get_int()=0 +new_obj.array_with_zero json_object_get_int64()=0 +new_obj.array_with_zero json_object_get_uint64()=0 +new_obj.array_with_zero json_object_get_boolean()=0 +new_obj.array_with_zero json_object_get_double()=0.000000 +new_obj.empty_object json_object_get_type()=object +new_obj.empty_object json_object_get_int()=0 +new_obj.empty_object json_object_get_int64()=0 +new_obj.empty_object json_object_get_uint64()=0 +new_obj.empty_object json_object_get_boolean()=0 +new_obj.empty_object json_object_get_double()=0.000000 +new_obj.nonempty_object json_object_get_type()=object +new_obj.nonempty_object json_object_get_int()=0 +new_obj.nonempty_object json_object_get_int64()=0 +new_obj.nonempty_object json_object_get_uint64()=0 +new_obj.nonempty_object json_object_get_boolean()=0 +new_obj.nonempty_object json_object_get_double()=0.000000 ================================ json_object_is_type: null,boolean,double,int,object,array,string @@ -52,5 +101,6 @@ new_obj.regular_number : 0,0,0,1,0,0,0 new_obj.decimal_number : 0,0,1,0,0,0,0 new_obj.boolean_true : 0,1,0,0,0,0,0 new_obj.boolean_false : 0,1,0,0,0,0,0 -new_obj.big_number : 0,0,0,1,0,0,0 +new_obj.int64_number : 0,0,0,1,0,0,0 +new_obj.negative_number : 0,0,0,1,0,0,0 new_obj.a_null : 1,0,0,0,0,0,0 diff --git a/third_party/json-c/tests/test_charcase.c b/third_party/json-c/tests/test_charcase.c index cb2456b1c..427e114bf 100644 --- a/third_party/json-c/tests/test_charcase.c +++ b/third_party/json-c/tests/test_charcase.c @@ -1,8 +1,30 @@ +/* + * Original work: + * + * json-c (copyright was originally missing from this file) + * + * Modified Work: + * + * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. + * + * This software product is a proprietary product of NVIDIA CORPORATION & + * AFFILIATES (the "Company") and all right, title, and interest in and to the + * software product, including all associated intellectual property rights, are + * and shall remain exclusively with the Company. + * + * This software product is governed by the End User License Agreement + * provided with the software product. + * + */ + +#ifdef NDEBUG +#undef NDEBUG +#endif +#include +#include #include #include -#include #include -#include #include "json.h" #include "json_tokener.h" @@ -14,27 +36,29 @@ int main(int argc, char **argv) MC_SET_DEBUG(1); test_case_parse(); + + return 0; } /* make sure only lowercase forms are parsed in strict mode */ -static void test_case_parse() +static void test_case_parse(void) { struct json_tokener *tok; json_object *new_obj; - tok = json_tokener_new(); - json_tokener_set_flags(tok, JSON_TOKENER_STRICT); + tok = doca_third_party_json_tokener_new(); + doca_third_party_json_tokener_set_flags(tok, JSON_TOKENER_STRICT); - new_obj = json_tokener_parse_ex(tok, "True", 4); - assert (new_obj == NULL); + new_obj = doca_third_party_json_tokener_parse_ex(tok, "True", 4); + assert(new_obj == NULL); - new_obj = json_tokener_parse_ex(tok, "False", 5); - assert (new_obj == NULL); + new_obj = doca_third_party_json_tokener_parse_ex(tok, "False", 5); + assert(new_obj == NULL); - new_obj = json_tokener_parse_ex(tok, "Null", 4); - assert (new_obj == NULL); + new_obj = doca_third_party_json_tokener_parse_ex(tok, "Null", 4); + assert(new_obj == NULL); printf("OK\n"); - json_tokener_free(tok); + doca_third_party_json_tokener_free(tok); } diff --git a/third_party/json-c/tests/test_compare.c b/third_party/json-c/tests/test_compare.c index c7e44f6ea..6220af190 100644 --- a/third_party/json-c/tests/test_compare.c +++ b/third_party/json-c/tests/test_compare.c @@ -1,151 +1,279 @@ +/* + * Original work: + * + * json-c (copyright was originally missing from this file) + * + * Modified Work: + * + * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. + * + * This software product is a proprietary product of NVIDIA CORPORATION & + * AFFILIATES (the "Company") and all right, title, and interest in and to the + * software product, including all associated intellectual property rights, are + * and shall remain exclusively with the Company. + * + * This software product is governed by the End User License Agreement + * provided with the software product. + * + */ + /* * Tests if json_object_equal behaves correct. */ +#ifdef NDEBUG +#undef NDEBUG +#endif +#include "config.h" #include #include -#include "config.h" #include "json_inttypes.h" #include "json_object.h" -#include "json_tokener.h" -int main() +int main(int argc, char **argv) { /* integer tests */ - struct json_object *int1 = json_object_new_int(0); - struct json_object *int2 = json_object_new_int(1); - struct json_object *int3 = json_object_new_int(1); + struct json_object *int1 = doca_third_party_json_object_new_int(0); + struct json_object *int2 = doca_third_party_json_object_new_int(1); + struct json_object *int3 = doca_third_party_json_object_new_int(1); + struct json_object *int4 = doca_third_party_json_object_new_int(-1); + struct json_object *uint1 = doca_third_party_json_object_new_uint64(0); + struct json_object *uint2 = doca_third_party_json_object_new_uint64(1); + struct json_object *uint3 = doca_third_party_json_object_new_uint64(1); + struct json_object *uint4 = doca_third_party_json_object_new_uint64((uint64_t)INT64_MAX + 100); + + if (!doca_third_party_json_object_equal(int1, int2)) + printf("JSON integer comparison is correct\n"); + else + printf("JSON integer comparison failed\n"); + + if (doca_third_party_json_object_equal(int1, int1)) + printf("JSON same object comparison is correct\n"); + else + printf("JSON same object comparison failed\n"); + + if (doca_third_party_json_object_equal(int2, int3)) + printf("JSON same integer comparison is correct\n"); + else + printf("JSON same integer comparison failed\n"); + + if (!doca_third_party_json_object_equal(uint1, uint2)) + printf("JSON usigned integer comparison is correct\n"); + else + printf("JSON usigned integer comparison failed\n"); - if (!json_object_equal(int1, int2)) - printf("JSON integer comparision is correct\n"); + if (doca_third_party_json_object_equal(uint1, uint1)) + printf("JSON same usigned object comparison is correct\n"); else - printf("JSON integer comparision failed\n"); + printf("JSON same usigned object comparison failed\n"); - if (json_object_equal(int1, int1)) - printf("JSON same object comparision is correct\n"); + if (doca_third_party_json_object_equal(uint2, uint3)) + printf("JSON same usigned integer comparison is correct\n"); else - printf("JSON same object comparision failed\n"); + printf("JSON same usigned integer comparison failed\n"); - if (json_object_equal(int2, int3)) - printf("JSON same integer comparision is correct\n"); + if (doca_third_party_json_object_equal(int2, uint2)) + printf("JSON integer & usigned integer comparison is correct\n"); else - printf("JSON same integer comparision failed\n"); + printf("JSON integer & usigned integer comparison failed\n"); - json_object_put(int1); - json_object_put(int2); - json_object_put(int3); + if (!doca_third_party_json_object_equal(int2, uint4)) + printf("JSON integer & usigned integer comparison is correct\n"); + else + printf("JSON integer & usigned integer comparison failed\n"); + + if (!doca_third_party_json_object_equal(int4, uint2)) + printf("JSON integer & usigned integer comparison is correct\n"); + else + printf("JSON integer & usigned integer comparison failed\n"); + + if (!doca_third_party_json_object_equal(int4, uint4)) + printf("JSON integer & usigned integer comparison is correct\n"); + else + printf("JSON integer & usigned integer comparison failed\n"); + + if (doca_third_party_json_object_equal(uint2, int2)) + printf("JSON usigned integer & integer comparison is correct\n"); + else + printf("JSON usigned integer & integer comparison failed\n"); + + if (!doca_third_party_json_object_equal(uint2, int4)) + printf("JSON usigned integer & integer comparison is correct\n"); + else + printf("JSON usigned integer & integer comparison failed\n"); + + if (!doca_third_party_json_object_equal(uint4, int2)) + printf("JSON usigned integer & integer comparison is correct\n"); + else + printf("JSON usigned integer & integer comparison failed\n"); + + if (!doca_third_party_json_object_equal(uint4, int4)) + printf("JSON usigned integer & integer comparison is correct\n"); + else + printf("JSON usigned integer & integer comparison failed\n"); + + doca_third_party_json_object_put(int1); + doca_third_party_json_object_put(int2); + doca_third_party_json_object_put(int3); + doca_third_party_json_object_put(int4); + doca_third_party_json_object_put(uint1); + doca_third_party_json_object_put(uint2); + doca_third_party_json_object_put(uint3); + doca_third_party_json_object_put(uint4); /* string tests */ - struct json_object *str1 = json_object_new_string("TESTSTRING"); - struct json_object *str2 = json_object_new_string("TESTSTRING"); - struct json_object *str3 = json_object_new_string("DIFFERENT"); + struct json_object *str1 = doca_third_party_json_object_new_string("TESTSTRING"); + struct json_object *str2 = doca_third_party_json_object_new_string("TESTSTRING"); + struct json_object *str3 = doca_third_party_json_object_new_string("DIFFERENT"); - if (json_object_equal(str1, str2)) + if (doca_third_party_json_object_equal(str1, str2)) printf("Comparing equal strings is correct\n"); else printf("Comparing equal strings failed\n"); - if (!json_object_equal(str1, str3)) + if (!doca_third_party_json_object_equal(str1, str3)) printf("Comparing different strings is correct\n"); else printf("Comparing different strings failed\n"); - json_object_put(str1); - json_object_put(str2); - json_object_put(str3); + doca_third_party_json_object_put(str1); + doca_third_party_json_object_put(str2); + doca_third_party_json_object_put(str3); /* double tests */ - struct json_object *dbl1 = json_object_new_double(3.14159); - struct json_object *dbl2 = json_object_new_double(3.14159); - struct json_object *dbl3 = json_object_new_double(3.0); + struct json_object *dbl1 = doca_third_party_json_object_new_double(3.14159); + struct json_object *dbl2 = doca_third_party_json_object_new_double(3.14159); + struct json_object *dbl3 = doca_third_party_json_object_new_double(3.0); - if (json_object_equal(dbl1, dbl2)) + if (doca_third_party_json_object_equal(dbl1, dbl2)) printf("Comparing equal doubles is correct\n"); else printf("Comparing equal doubles failed\n"); - if (!json_object_equal(dbl1, dbl3)) + if (!doca_third_party_json_object_equal(dbl1, dbl3)) printf("Comparing different doubles is correct\n"); else printf("Comparing different doubles failed\n"); - json_object_put(dbl1); - json_object_put(dbl2); - json_object_put(dbl3); + doca_third_party_json_object_put(dbl1); + doca_third_party_json_object_put(dbl2); + doca_third_party_json_object_put(dbl3); /* array tests */ - struct json_object *ar1 = json_object_new_array(); - struct json_object *ar2 = json_object_new_array(); - struct json_object *ar3 = json_object_new_array(); - struct json_object *ar4 = json_object_new_array(); + struct json_object *ar1 = doca_third_party_json_object_new_array(); + struct json_object *ar2 = doca_third_party_json_object_new_array(); + struct json_object *ar3 = doca_third_party_json_object_new_array(); + struct json_object *ar4 = doca_third_party_json_object_new_array(); - json_object_array_add(ar1, json_object_new_int(1)); - json_object_array_add(ar1, json_object_new_int(2)); + doca_third_party_json_object_array_add(ar1, doca_third_party_json_object_new_int(1)); + doca_third_party_json_object_array_add(ar1, doca_third_party_json_object_new_int(2)); - json_object_array_add(ar2, json_object_new_int(1)); - json_object_array_add(ar2, json_object_new_int(2)); + doca_third_party_json_object_array_add(ar2, doca_third_party_json_object_new_int(1)); + doca_third_party_json_object_array_add(ar2, doca_third_party_json_object_new_int(2)); - json_object_array_add(ar3, json_object_new_int(1)); - json_object_array_add(ar3, json_object_new_int(1)); + doca_third_party_json_object_array_add(ar3, doca_third_party_json_object_new_int(1)); + doca_third_party_json_object_array_add(ar3, doca_third_party_json_object_new_int(1)); - if (json_object_equal(ar1, ar2)) + if (doca_third_party_json_object_equal(ar1, ar2)) printf("Comparing equal arrays is correct\n"); else printf("Comparing equal arrays failed\n"); - json_object_array_add(ar2, json_object_new_int(1)); - if (!json_object_equal(ar1, ar2)) + doca_third_party_json_object_array_add(ar2, doca_third_party_json_object_new_int(1)); + if (!doca_third_party_json_object_equal(ar1, ar2)) printf("Comparing arrays of different len is correct\n"); else printf("Comparing arrays of different len failed\n"); - if (!json_object_equal(ar1, ar3)) + if (!doca_third_party_json_object_equal(ar1, ar3)) printf("Comparing different arrays is correct\n"); else printf("Comparing different arrays failed\n"); - if (!json_object_equal(ar1, ar4)) + if (!doca_third_party_json_object_equal(ar1, ar4)) printf("Comparing different arrays (one empty) is correct\n"); else printf("Comparing different arrays (one empty) failed\n"); - json_object_put(ar1); - json_object_put(ar2); - json_object_put(ar3); - json_object_put(ar4); + doca_third_party_json_object_put(ar1); + doca_third_party_json_object_put(ar2); + doca_third_party_json_object_put(ar3); + doca_third_party_json_object_put(ar4); /* object tests */ - struct json_object *obj1 = json_object_new_object(); - struct json_object *obj2 = json_object_new_object(); + struct json_object *obj1 = doca_third_party_json_object_new_object(); + struct json_object *obj2 = doca_third_party_json_object_new_object(); - json_object_object_add(obj1, "test1", json_object_new_int(123)); - json_object_object_add(obj1, "test2", json_object_new_int(321)); - json_object_object_add(obj1, "test3", json_object_new_int(320)); - json_object_object_add(obj1, "test4", json_object_new_int(319)); - json_object_object_add(obj1, "test5", json_object_new_int(318)); + doca_third_party_json_object_object_add(obj1, "test1", doca_third_party_json_object_new_int(123)); + doca_third_party_json_object_object_add(obj1, "test2", doca_third_party_json_object_new_int(321)); + doca_third_party_json_object_object_add(obj1, "test3", doca_third_party_json_object_new_int(320)); + doca_third_party_json_object_object_add(obj1, "test4", doca_third_party_json_object_new_int(319)); + doca_third_party_json_object_object_add(obj1, "test5", doca_third_party_json_object_new_int(318)); - json_object_object_add(obj2, "test5", json_object_new_int(318)); - json_object_object_add(obj2, "test4", json_object_new_int(319)); - json_object_object_add(obj2, "test3", json_object_new_int(320)); - json_object_object_add(obj2, "test2", json_object_new_int(321)); - json_object_object_add(obj2, "test1", json_object_new_int(123)); + doca_third_party_json_object_object_add(obj2, "test5", doca_third_party_json_object_new_int(318)); + doca_third_party_json_object_object_add(obj2, "test4", doca_third_party_json_object_new_int(319)); + doca_third_party_json_object_object_add(obj2, "test3", doca_third_party_json_object_new_int(320)); + doca_third_party_json_object_object_add(obj2, "test2", doca_third_party_json_object_new_int(321)); + doca_third_party_json_object_object_add(obj2, "test1", doca_third_party_json_object_new_int(123)); /* key-order is different between obj1 and obj2, should still be equal */ - if (json_object_equal(obj1, obj2)) + if (doca_third_party_json_object_equal(obj1, obj2)) printf("Comparing JSON object with different key order is correct\n"); else printf("Comparing JSON object with different key order is incorrect\n"); /* make obj2 look different to obj1 */ - json_object_object_add(obj2, "test3", json_object_new_int(234)); - if (!json_object_equal(obj1, obj2)) + doca_third_party_json_object_object_add(obj2, "test3", doca_third_party_json_object_new_int(234)); + if (!doca_third_party_json_object_equal(obj1, obj2)) + printf("Comparing different objects is correct\n"); + else + printf("Comparing different objects is incorrect\n"); + + /* iterate over jso2 keys to see if any exist that are not in jso1 */ + doca_third_party_json_object_object_add(obj2, "test3", doca_third_party_json_object_new_int(320)); + doca_third_party_json_object_object_add(obj2, "test6", doca_third_party_json_object_new_int(321)); + if (!doca_third_party_json_object_equal(obj1, obj2)) + printf("Comparing different objects is correct\n"); + else + printf("Comparing different objects is incorrect\n"); + + /* iterate over jso1 keys and see if they exist in jso1 */ + doca_third_party_json_object_object_add(obj1, "test6", doca_third_party_json_object_new_int(321)); + if (doca_third_party_json_object_equal(obj1, obj2)) printf("Comparing different objects is correct\n"); else printf("Comparing different objects is incorrect\n"); + doca_third_party_json_object_object_add(obj1, "test7", doca_third_party_json_object_new_int(322)); + if (!doca_third_party_json_object_equal(obj1, obj2)) + printf("Comparing different objects is correct\n"); + else + printf("Comparing different objects is incorrect\n"); + + doca_third_party_json_object_put(obj1); + doca_third_party_json_object_put(obj2); + + /* different types tests */ + struct json_object *int5 = doca_third_party_json_object_new_int(0); + struct json_object *dbl5 = doca_third_party_json_object_new_double(3.14159); + + if (!doca_third_party_json_object_equal(int5, NULL)) + printf("JSON integer and NULL comparison is correct\n"); + else + printf("JSON integer and NULL comparison failed\n"); + + if (!doca_third_party_json_object_equal(NULL, dbl5)) + printf("JSON NULL and double comparison is correct\n"); + else + printf("JSON NULL and double comparison failed\n"); + + if (!doca_third_party_json_object_equal(int5, dbl5)) + printf("JSON integer and double comparison is correct\n"); + else + printf("JSON integer and double comparison failed\n"); - json_object_put(obj1); - json_object_put(obj2); + doca_third_party_json_object_put(int5); + doca_third_party_json_object_put(dbl5); return 0; } diff --git a/third_party/json-c/tests/test_compare.expected b/third_party/json-c/tests/test_compare.expected index 46f03c410..51366d9c8 100644 --- a/third_party/json-c/tests/test_compare.expected +++ b/third_party/json-c/tests/test_compare.expected @@ -1,6 +1,17 @@ -JSON integer comparision is correct -JSON same object comparision is correct -JSON same integer comparision is correct +JSON integer comparison is correct +JSON same object comparison is correct +JSON same integer comparison is correct +JSON usigned integer comparison is correct +JSON same usigned object comparison is correct +JSON same usigned integer comparison is correct +JSON integer & usigned integer comparison is correct +JSON integer & usigned integer comparison is correct +JSON integer & usigned integer comparison is correct +JSON integer & usigned integer comparison is correct +JSON usigned integer & integer comparison is correct +JSON usigned integer & integer comparison is correct +JSON usigned integer & integer comparison is correct +JSON usigned integer & integer comparison is correct Comparing equal strings is correct Comparing different strings is correct Comparing equal doubles is correct @@ -11,3 +22,9 @@ Comparing different arrays is correct Comparing different arrays (one empty) is correct Comparing JSON object with different key order is correct Comparing different objects is correct +Comparing different objects is correct +Comparing different objects is correct +Comparing different objects is correct +JSON integer and NULL comparison is correct +JSON NULL and double comparison is correct +JSON integer and double comparison is correct diff --git a/third_party/json-c/tests/test_deep_copy.c b/third_party/json-c/tests/test_deep_copy.c index 7a6e63f81..0781aff0e 100644 --- a/third_party/json-c/tests/test_deep_copy.c +++ b/third_party/json-c/tests/test_deep_copy.c @@ -1,7 +1,29 @@ +/* + * Original work: + * + * json-c (copyright was originally missing from this file) + * + * Modified Work: + * + * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. + * + * This software product is a proprietary product of NVIDIA CORPORATION & + * AFFILIATES (the "Company") and all right, title, and interest in and to the + * software product, including all associated intellectual property rights, are + * and shall remain exclusively with the Company. + * + * This software product is governed by the End User License Agreement + * provided with the software product. + * + */ + +#include #include #include -#include #include +#ifdef NDEBUG +#undef NDEBUG +#endif #include #include #include @@ -11,98 +33,102 @@ static void do_benchmark(json_object *src1); -static const char *json_str1 = -"{" -" \"glossary\": {" -" \"title\": \"example glossary\"," -" \"GlossDiv\": {" -" \"title\": \"S\"," -" \"null_obj\": null, " -" \"GlossList\": {" -" \"GlossEntry\": {" -" \"ID\": \"SGML\"," -" \"SortAs\": \"SGML\"," -" \"GlossTerm\": \"Standard Generalized Markup Language\"," -" \"Acronym\": \"SGML\"," -" \"Abbrev\": \"ISO 8879:1986\"," -" \"GlossDef\": {" -" \"para\": \"A meta-markup language, used to create markup languages such as DocBook.\"," -" \"GlossSeeAlso\": [\"GML\", \"XML\"]" -" }," -" \"GlossSee\": \"markup\"" -" }" -" }" -" }" -" }" -"}"; +static const char *json_str1 = + "{" + " \"glossary\": {" + " \"title\": \"example glossary\"," + " \"GlossDiv\": {" + " \"number\": 16446744073709551615," + " \"title\": \"S\"," + " \"null_obj\": null, " + " \"exist\": false," + " \"quantity\":20," + " \"univalent\":19.8," + " \"GlossList\": {" + " \"GlossEntry\": {" + " \"ID\": \"SGML\"," + " \"SortAs\": \"SGML\"," + " \"GlossTerm\": \"Standard Generalized Markup Language\"," + " \"Acronym\": \"SGML\"," + " \"Abbrev\": \"ISO 8879:1986\"," + " \"GlossDef\": {" + " \"para\": \"A meta-markup language, used to create markup languages " + "such as DocBook.\"," + " \"GlossSeeAlso\": [\"GML\", \"XML\"]" + " }," + " \"GlossSee\": \"markup\"" + " }" + " }" + " }" + " }" + "}"; static const char *json_str2 = -"{\"menu\": {" -" \"header\": \"SVG Viewer\"," -" \"items\": [" -" {\"id\": \"Open\"}," -" {\"id\": \"OpenNew\", \"label\": \"Open New\"}," -" null," -" {\"id\": \"ZoomIn\", \"label\": \"Zoom In\"}," -" {\"id\": \"ZoomOut\", \"label\": \"Zoom Out\"}," -" {\"id\": \"OriginalView\", \"label\": \"Original View\"}," -" null," -" {\"id\": \"Quality\", \"another_null\": null}," -" {\"id\": \"Pause\"}," -" {\"id\": \"Mute\"}," -" null," -" {\"id\": \"Find\", \"label\": \"Find...\"}," -" {\"id\": \"FindAgain\", \"label\": \"Find Again\"}," -" {\"id\": \"Copy\"}," -" {\"id\": \"CopyAgain\", \"label\": \"Copy Again\"}," -" {\"id\": \"CopySVG\", \"label\": \"Copy SVG\"}," -" {\"id\": \"ViewSVG\", \"label\": \"View SVG\"}," -" {\"id\": \"ViewSource\", \"label\": \"View Source\"}," -" {\"id\": \"SaveAs\", \"label\": \"Save As\"}," -" null," -" {\"id\": \"Help\"}," -" {\"id\": \"About\", \"label\": \"About Adobe CVG Viewer...\"}" -" ]" -"}}"; - -static const char *json_str3 = -"{\"menu\": {" -" \"id\": \"file\"," -" \"value\": \"File\"," -" \"popup\": {" -" \"menuitem\": [" -" {\"value\": \"New\", \"onclick\": \"CreateNewDoc()\"}," -" {\"value\": \"Open\", \"onclick\": \"OpenDoc()\"}," -" {\"value\": \"Close\", \"onclick\": \"CloseDoc()\"}" -" ]" -" }" -"}}"; + "{\"menu\": {" + " \"header\": \"SVG Viewer\"," + " \"items\": [" + " {\"id\": \"Open\"}," + " {\"id\": \"OpenNew\", \"label\": \"Open New\"}," + " null," + " {\"id\": \"ZoomIn\", \"label\": \"Zoom In\"}," + " {\"id\": \"ZoomOut\", \"label\": \"Zoom Out\"}," + " {\"id\": \"OriginalView\", \"label\": \"Original View\"}," + " null," + " {\"id\": \"Quality\", \"another_null\": null}," + " {\"id\": \"Pause\"}," + " {\"id\": \"Mute\"}," + " null," + " {\"id\": \"Find\", \"label\": \"Find...\"}," + " {\"id\": \"FindAgain\", \"label\": \"Find Again\"}," + " {\"id\": \"Copy\"}," + " {\"id\": \"CopyAgain\", \"label\": \"Copy Again\"}," + " {\"id\": \"CopySVG\", \"label\": \"Copy SVG\"}," + " {\"id\": \"ViewSVG\", \"label\": \"View SVG\"}," + " {\"id\": \"ViewSource\", \"label\": \"View Source\"}," + " {\"id\": \"SaveAs\", \"label\": \"Save As\"}," + " null," + " {\"id\": \"Help\"}," + " {\"id\": \"About\", \"label\": \"About Adobe CVG Viewer...\"}" + " ]" + "}}"; + +static const char *json_str3 = "{\"menu\": {" + " \"id\": \"file\"," + " \"value\": \"File\"," + " \"popup\": {" + " \"menuitem\": [" + " {\"value\": \"New\", \"onclick\": \"CreateNewDoc()\"}," + " {\"value\": \"Open\", \"onclick\": \"OpenDoc()\"}," + " {\"value\": \"Close\", \"onclick\": \"CloseDoc()\"}" + " ]" + " }" + "}}"; json_object_to_json_string_fn my_custom_serializer; int my_custom_serializer(struct json_object *jso, struct printbuf *pb, int level, int flags) { - sprintbuf(pb, "OTHER"); + doca_third_party_sprintbuf(pb, "OTHER"); return 0; } json_c_shallow_copy_fn my_shallow_copy; -int my_shallow_copy(json_object *src, json_object *parent, const char *key, size_t index, json_object **dst) +int my_shallow_copy(json_object *src, json_object *parent, const char *key, size_t index, + json_object **dst) { int rc; - rc = json_c_shallow_copy_default(src, parent, key, index, dst); + rc = doca_third_party_json_c_shallow_copy_default(src, parent, key, index, dst); if (rc < 0) return rc; if (key != NULL && strcmp(key, "with_serializer") == 0) { printf("CALLED: my_shallow_copy on with_serializer object\n"); - void *userdata = json_object_get_userdata(src); - json_object_set_serializer(*dst, my_custom_serializer, userdata, NULL); + void *userdata = doca_third_party_json_object_get_userdata(src); + doca_third_party_json_object_set_serializer(*dst, my_custom_serializer, userdata, NULL); return 2; } return rc; } - int main(int argc, char **argv) { struct json_object *src1, *src2, *src3; @@ -114,103 +140,104 @@ int main(int argc, char **argv) benchmark = 1; } - src1 = json_tokener_parse(json_str1); - src2 = json_tokener_parse(json_str2); - src3 = json_tokener_parse(json_str3); + src1 = doca_third_party_json_tokener_parse(json_str1); + src2 = doca_third_party_json_tokener_parse(json_str2); + src3 = doca_third_party_json_tokener_parse(json_str3); assert(src1 != NULL); - assert(src1 != NULL); + assert(src2 != NULL); assert(src3 != NULL); printf("PASSED - loaded input data\n"); /* do this 3 times to make sure overwriting it works */ - assert(0 == json_object_deep_copy(src1, &dst1, NULL)); - assert(0 == json_object_deep_copy(src2, &dst2, NULL)); - assert(0 == json_object_deep_copy(src3, &dst3, NULL)); + assert(0 == doca_third_party_json_object_deep_copy(src1, &dst1, NULL)); + assert(0 == doca_third_party_json_object_deep_copy(src2, &dst2, NULL)); + assert(0 == doca_third_party_json_object_deep_copy(src3, &dst3, NULL)); - printf("PASSED - all json_object_deep_copy() returned succesful\n"); + printf("PASSED - all json_object_deep_copy() returned successful\n"); - assert(-1 == json_object_deep_copy(src1, &dst1, NULL)); + assert(-1 == doca_third_party_json_object_deep_copy(src1, &dst1, NULL)); assert(errno == EINVAL); - assert(-1 == json_object_deep_copy(src2, &dst2, NULL)); + assert(-1 == doca_third_party_json_object_deep_copy(src2, &dst2, NULL)); assert(errno == EINVAL); - assert(-1 == json_object_deep_copy(src3, &dst3, NULL)); + assert(-1 == doca_third_party_json_object_deep_copy(src3, &dst3, NULL)); assert(errno == EINVAL); printf("PASSED - all json_object_deep_copy() returned EINVAL for non-null pointer\n"); - assert(1 == json_object_equal(src1, dst1)); - assert(1 == json_object_equal(src2, dst2)); - assert(1 == json_object_equal(src3, dst3)); + assert(1 == doca_third_party_json_object_equal(src1, dst1)); + assert(1 == doca_third_party_json_object_equal(src2, dst2)); + assert(1 == doca_third_party_json_object_equal(src3, dst3)); - printf("PASSED - all json_object_equal() tests returned succesful\n"); + printf("PASSED - all json_object_equal() tests returned successful\n"); - assert(0 == strcmp(json_object_to_json_string_ext(src1, JSON_C_TO_STRING_PRETTY), - json_object_to_json_string_ext(dst1, JSON_C_TO_STRING_PRETTY))); - assert(0 == strcmp(json_object_to_json_string_ext(src2, JSON_C_TO_STRING_PRETTY), - json_object_to_json_string_ext(dst2, JSON_C_TO_STRING_PRETTY))); - assert(0 == strcmp(json_object_to_json_string_ext(src3, JSON_C_TO_STRING_PRETTY), - json_object_to_json_string_ext(dst3, JSON_C_TO_STRING_PRETTY))); + assert(0 == strcmp(doca_third_party_json_object_to_json_string_ext(src1, JSON_C_TO_STRING_PRETTY), + doca_third_party_json_object_to_json_string_ext(dst1, JSON_C_TO_STRING_PRETTY))); + assert(0 == strcmp(doca_third_party_json_object_to_json_string_ext(src2, JSON_C_TO_STRING_PRETTY), + doca_third_party_json_object_to_json_string_ext(dst2, JSON_C_TO_STRING_PRETTY))); + assert(0 == strcmp(doca_third_party_json_object_to_json_string_ext(src3, JSON_C_TO_STRING_PRETTY), + doca_third_party_json_object_to_json_string_ext(dst3, JSON_C_TO_STRING_PRETTY))); printf("PASSED - comparison of string output\n"); - json_object_get(dst1); - assert(-1 == json_object_deep_copy(src1, &dst1, NULL)); + doca_third_party_json_object_get(dst1); + assert(-1 == doca_third_party_json_object_deep_copy(src1, &dst1, NULL)); assert(errno == EINVAL); - json_object_put(dst1); + doca_third_party_json_object_put(dst1); printf("PASSED - trying to overrwrite an object that has refcount > 1"); printf("\nPrinting JSON objects for visual inspection\n"); printf("------------------------------------------------\n"); printf(" JSON1\n"); - printf("%s\n", json_object_to_json_string_ext(dst1, JSON_C_TO_STRING_PRETTY)); + printf("%s\n", doca_third_party_json_object_to_json_string_ext(dst1, JSON_C_TO_STRING_PRETTY)); printf("------------------------------------------------\n"); printf("------------------------------------------------\n"); printf(" JSON2\n"); - printf("%s\n", json_object_to_json_string_ext(dst2, JSON_C_TO_STRING_PRETTY)); + printf("%s\n", doca_third_party_json_object_to_json_string_ext(dst2, JSON_C_TO_STRING_PRETTY)); printf("------------------------------------------------\n"); printf("------------------------------------------------\n"); printf(" JSON3\n"); printf("------------------------------------------------\n"); - printf("%s\n", json_object_to_json_string_ext(dst3, JSON_C_TO_STRING_PRETTY)); + printf("%s\n", doca_third_party_json_object_to_json_string_ext(dst3, JSON_C_TO_STRING_PRETTY)); printf("------------------------------------------------\n"); - json_object_put(dst1); - json_object_put(dst2); - json_object_put(dst3); + doca_third_party_json_object_put(dst1); + doca_third_party_json_object_put(dst2); + doca_third_party_json_object_put(dst3); printf("\nTesting deep_copy with a custom serializer set\n"); - json_object *with_serializer = json_object_new_string("notemitted"); + json_object *with_serializer = doca_third_party_json_object_new_string("notemitted"); - json_object_set_serializer(with_serializer, my_custom_serializer, "dummy userdata", NULL); - json_object_object_add(src1, "with_serializer", with_serializer); + char udata[] = "dummy userdata"; + doca_third_party_json_object_set_serializer(with_serializer, my_custom_serializer, udata, NULL); + doca_third_party_json_object_object_add(src1, "with_serializer", with_serializer); dst1 = NULL; /* With a custom serializer in use, a custom shallow_copy function must also be used */ - assert(-1 == json_object_deep_copy(src1, &dst1, NULL)); - assert(0 == json_object_deep_copy(src1, &dst1, my_shallow_copy)); + assert(-1 == doca_third_party_json_object_deep_copy(src1, &dst1, NULL)); + assert(0 == doca_third_party_json_object_deep_copy(src1, &dst1, my_shallow_copy)); - json_object *dest_with_serializer = json_object_object_get(dst1, "with_serializer"); + json_object *dest_with_serializer = doca_third_party_json_object_object_get(dst1, "with_serializer"); assert(dest_with_serializer != NULL); - char *dst_userdata = json_object_get_userdata(dest_with_serializer); + char *dst_userdata = doca_third_party_json_object_get_userdata(dest_with_serializer); assert(strcmp(dst_userdata, "dummy userdata") == 0); - const char *special_output = json_object_to_json_string(dest_with_serializer); + const char *special_output = doca_third_party_json_object_to_json_string(dest_with_serializer); assert(strcmp(special_output, "OTHER") == 0); printf("\ndeep_copy with custom serializer worked OK.\n"); - json_object_put(dst1); + doca_third_party_json_object_put(dst1); if (benchmark) { do_benchmark(src2); } - json_object_put(src1); - json_object_put(src2); - json_object_put(src3); + doca_third_party_json_object_put(src1); + doca_third_party_json_object_put(src2); + doca_third_party_json_object_put(src3); return 0; } @@ -230,19 +257,24 @@ static void do_benchmark(json_object *src2) time_t start = time(NULL); start = time(NULL); - for (ii = 0; ii < iterations; ii++) { - dst2 = json_tokener_parse(json_object_get_string(src2)); - json_object_put(dst2); + for (ii = 0; ii < iterations; ii++) + { + dst2 = doca_third_party_json_tokener_parse(doca_third_party_json_object_get_string(src2)); + doca_third_party_json_object_put(dst2); } - printf("BENCHMARK - %d iterations of 'dst2 = json_tokener_parse(json_object_get_string(src2))' took %d seconds\n", iterations, (int)(time(NULL) - start)); + printf("BENCHMARK - %d iterations of 'dst2 = " + "json_tokener_parse(json_object_get_string(src2))' took %d seconds\n", + iterations, (int)(time(NULL) - start)); start = time(NULL); dst2 = NULL; - for (ii = 0; ii < iterations; ii++) { - json_object_deep_copy(src2, &dst2, NULL); - json_object_put(dst2); + for (ii = 0; ii < iterations; ii++) + { + doca_third_party_json_object_deep_copy(src2, &dst2, NULL); + doca_third_party_json_object_put(dst2); dst2 = NULL; } - printf("BENCHMARK - %d iterations of 'json_object_deep_copy(src2, &dst2, NULL)' took %d seconds\n", iterations, (int)(time(NULL) - start)); + printf("BENCHMARK - %d iterations of 'json_object_deep_copy(src2, &dst2, NULL)' took %d " + "seconds\n", + iterations, (int)(time(NULL) - start)); } - diff --git a/third_party/json-c/tests/test_deep_copy.expected b/third_party/json-c/tests/test_deep_copy.expected index d009e948b..3bd44629d 100644 --- a/third_party/json-c/tests/test_deep_copy.expected +++ b/third_party/json-c/tests/test_deep_copy.expected @@ -1,7 +1,7 @@ PASSED - loaded input data -PASSED - all json_object_deep_copy() returned succesful +PASSED - all json_object_deep_copy() returned successful PASSED - all json_object_deep_copy() returned EINVAL for non-null pointer -PASSED - all json_object_equal() tests returned succesful +PASSED - all json_object_equal() tests returned successful PASSED - comparison of string output PASSED - trying to overrwrite an object that has refcount > 1 Printing JSON objects for visual inspection @@ -11,8 +11,12 @@ Printing JSON objects for visual inspection "glossary":{ "title":"example glossary", "GlossDiv":{ + "number":16446744073709551615, "title":"S", "null_obj":null, + "exist":false, + "quantity":20, + "univalent":19.8, "GlossList":{ "GlossEntry":{ "ID":"SGML", diff --git a/third_party/json-c/tests/test_double_serializer.c b/third_party/json-c/tests/test_double_serializer.c index 0f7a60ea7..8499c35b6 100644 --- a/third_party/json-c/tests/test_double_serializer.c +++ b/third_party/json-c/tests/test_double_serializer.c @@ -1,77 +1,132 @@ +/* + * Original work: + * + * json-c (copyright was originally missing from this file) + * + * Modified Work: + * + * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. + * + * This software product is a proprietary product of NVIDIA CORPORATION & + * AFFILIATES (the "Company") and all right, title, and interest in and to the + * software product, including all associated intellectual property rights, are + * and shall remain exclusively with the Company. + * + * This software product is governed by the End User License Agreement + * provided with the software product. + * + */ + /* * Tests if the format string for double serialization is handled correctly */ -#include +#ifdef NDEBUG +#undef NDEBUG +#endif #include "config.h" +#include #include "json_object.h" #include "json_object_private.h" -int main() +/* Avoid compiler warnings about diving by constant zero */ +double zero_dot_zero = 0.0; + +int main(int argc, char **argv) { - struct json_object *obj = json_object_new_double(0.5); + struct json_object *obj = doca_third_party_json_object_new_double(0.5); + char udata[] = "test"; printf("Test default serializer:\n"); - printf("obj.to_string(standard)=%s\n", json_object_to_json_string(obj)); + printf("obj.to_string(standard)=%s\n", doca_third_party_json_object_to_json_string(obj)); printf("Test default serializer with custom userdata:\n"); - obj->_userdata = "test"; - printf("obj.to_string(userdata)=%s\n", json_object_to_json_string(obj)); + obj->_userdata = udata; + printf("obj.to_string(userdata)=%s\n", doca_third_party_json_object_to_json_string(obj)); printf("Test explicit serializer with custom userdata:\n"); - json_object_set_serializer(obj, json_object_double_to_json_string, "test", NULL); - printf("obj.to_string(custom)=%s\n", json_object_to_json_string(obj)); + doca_third_party_json_object_set_serializer(obj, doca_third_party_json_object_double_to_json_string, udata, NULL); + printf("obj.to_string(custom)=%s\n", doca_third_party_json_object_to_json_string(obj)); printf("Test reset serializer:\n"); - json_object_set_serializer(obj, NULL, NULL, NULL); - printf("obj.to_string(reset)=%s\n", json_object_to_json_string(obj)); + doca_third_party_json_object_set_serializer(obj, NULL, NULL, NULL); + printf("obj.to_string(reset)=%s\n", doca_third_party_json_object_to_json_string(obj)); - json_object_put(obj); - obj = json_object_new_double(0.52381); + doca_third_party_json_object_put(obj); + printf("Test no zero reset serializer:\n"); + obj = doca_third_party_json_object_new_double(3.1415000); + char data[] = "%.17g"; + doca_third_party_json_object_set_serializer(obj, doca_third_party_json_object_double_to_json_string, data, NULL); + printf("obj.to_string(reset)=%s\n", doca_third_party_json_object_to_json_string_ext(obj, 4)); - printf("obj.to_string(default format)=%s\n", json_object_to_json_string(obj)); - if (json_c_set_serialization_double_format("x%0.3fy", JSON_C_OPTION_GLOBAL) < 0) + doca_third_party_json_object_put(obj); + obj = doca_third_party_json_object_new_double(0.52381); + + printf("obj.to_string(default format)=%s\n", doca_third_party_json_object_to_json_string(obj)); + if (doca_third_party_json_c_set_serialization_double_format("x%0.3fy", JSON_C_OPTION_GLOBAL) < 0) printf("ERROR: json_c_set_serialization_double_format() failed"); - printf("obj.to_string(with global format)=%s\n", json_object_to_json_string(obj)); + printf("obj.to_string(with global format)=%s\n", doca_third_party_json_object_to_json_string(obj)); #ifdef HAVE___THREAD - if (json_c_set_serialization_double_format("T%0.2fX", JSON_C_OPTION_THREAD) < 0) + if (doca_third_party_json_c_set_serialization_double_format("T%0.2fX", JSON_C_OPTION_THREAD) < 0) printf("ERROR: json_c_set_serialization_double_format() failed"); - printf("obj.to_string(with thread format)=%s\n", json_object_to_json_string(obj)); - if (json_c_set_serialization_double_format("Ttttttttttttt%0.2fxxxxxxxxxxxxxxxxxxX", JSON_C_OPTION_THREAD) < 0) + printf("obj.to_string(with thread format)=%s\n", doca_third_party_json_object_to_json_string(obj)); + if (doca_third_party_json_c_set_serialization_double_format("Ttttttttttttt%0.2fxxxxxxxxxxxxxxxxxxX", + JSON_C_OPTION_THREAD) < 0) printf("ERROR: json_c_set_serialization_double_format() failed"); - printf("obj.to_string(long thread format)=%s\n", json_object_to_json_string(obj)); - if (json_c_set_serialization_double_format(NULL, JSON_C_OPTION_THREAD) < 0) + printf("obj.to_string(long thread format)=%s\n", doca_third_party_json_object_to_json_string(obj)); + if (doca_third_party_json_c_set_serialization_double_format(NULL, JSON_C_OPTION_THREAD) < 0) printf("ERROR: json_c_set_serialization_double_format() failed"); - printf("obj.to_string(back to global format)=%s\n", json_object_to_json_string(obj)); + printf("obj.to_string(back to global format)=%s\n", doca_third_party_json_object_to_json_string(obj)); #else // Just fake it up, so the output matches. printf("obj.to_string(with thread format)=%s\n", "T0.52X"); + printf("obj.to_string(long thread format)=%s\n", "Ttttttttttttt0.52xxxxxxxxxxxxxxxxxxX"); printf("obj.to_string(back to global format)=%s\n", "x0.524y"); #endif - if (json_c_set_serialization_double_format(NULL, JSON_C_OPTION_GLOBAL) < 0) + if (doca_third_party_json_c_set_serialization_double_format(NULL, JSON_C_OPTION_GLOBAL) < 0) printf("ERROR: json_c_set_serialization_double_format() failed"); - printf("obj.to_string(back to default format)=%s\n", json_object_to_json_string(obj)); + printf("obj.to_string(back to default format)=%s\n", doca_third_party_json_object_to_json_string(obj)); - json_object_put(obj); + doca_third_party_json_object_put(obj); - obj = json_object_new_double(12.0); - printf("obj(12.0).to_string(default format)=%s\n", json_object_to_json_string(obj)); - if (json_c_set_serialization_double_format("%.0f", JSON_C_OPTION_GLOBAL) < 0) + obj = doca_third_party_json_object_new_double(12.0); + printf("obj(12.0).to_string(default format)=%s\n", doca_third_party_json_object_to_json_string(obj)); + if (doca_third_party_json_c_set_serialization_double_format("%.0f", JSON_C_OPTION_GLOBAL) < 0) printf("ERROR: json_c_set_serialization_double_format() failed"); - printf("obj(12.0).to_string(%%.0f)=%s\n", json_object_to_json_string(obj)); + printf("obj(12.0).to_string(%%.0f)=%s\n", doca_third_party_json_object_to_json_string(obj)); - if (json_c_set_serialization_double_format("%.0g", JSON_C_OPTION_GLOBAL) < 0) + if (doca_third_party_json_c_set_serialization_double_format("%.0g", JSON_C_OPTION_GLOBAL) < 0) printf("ERROR: json_c_set_serialization_double_format() failed"); - printf("obj(12.0).to_string(%%.0g)=%s\n", json_object_to_json_string(obj)); + printf("obj(12.0).to_string(%%.0g)=%s\n", doca_third_party_json_object_to_json_string(obj)); - if (json_c_set_serialization_double_format("%.2g", JSON_C_OPTION_GLOBAL) < 0) + if (doca_third_party_json_c_set_serialization_double_format("%.2g", JSON_C_OPTION_GLOBAL) < 0) printf("ERROR: json_c_set_serialization_double_format() failed"); - printf("obj(12.0).to_string(%%.1g)=%s\n", json_object_to_json_string(obj)); + printf("obj(12.0).to_string(%%.1g)=%s\n", doca_third_party_json_object_to_json_string(obj)); // Reset to default to free memory - if (json_c_set_serialization_double_format(NULL, JSON_C_OPTION_GLOBAL) < 0) + if (doca_third_party_json_c_set_serialization_double_format(NULL, JSON_C_OPTION_GLOBAL) < 0) printf("ERROR: json_c_set_serialization_double_format() failed"); - json_object_put(obj); + doca_third_party_json_object_put(obj); + + obj = doca_third_party_json_object_new_double(-12.0); + printf("obj(-12.0).to_string(default format)=%s\n", doca_third_party_json_object_to_json_string(obj)); + doca_third_party_json_object_put(obj); + + /* Test NaN handling */ + obj = doca_third_party_json_object_new_double(zero_dot_zero / zero_dot_zero); + printf("obj(0.0/0.0)=%s\n", doca_third_party_json_object_to_json_string(obj)); + doca_third_party_json_object_put(obj); + + /* Test Infinity and -Infinity handling */ + obj = doca_third_party_json_object_new_double(1.0 / zero_dot_zero); + printf("obj(1.0/0.0)=%s\n", doca_third_party_json_object_to_json_string(obj)); + doca_third_party_json_object_put(obj); + + obj = doca_third_party_json_object_new_double(-1.0 / zero_dot_zero); + printf("obj(-1.0/0.0)=%s\n", doca_third_party_json_object_to_json_string(obj)); + doca_third_party_json_object_put(obj); + + return 0; } diff --git a/third_party/json-c/tests/test_double_serializer.expected b/third_party/json-c/tests/test_double_serializer.expected index 98eea1e13..8e3b7e427 100644 --- a/third_party/json-c/tests/test_double_serializer.expected +++ b/third_party/json-c/tests/test_double_serializer.expected @@ -6,6 +6,8 @@ Test explicit serializer with custom userdata: obj.to_string(custom)=test Test reset serializer: obj.to_string(reset)=0.5 +Test no zero reset serializer: +obj.to_string(reset)=3.1415000000000002 obj.to_string(default format)=0.52381 obj.to_string(with global format)=x0.524y obj.to_string(with thread format)=T0.52X @@ -16,3 +18,7 @@ obj(12.0).to_string(default format)=12.0 obj(12.0).to_string(%.0f)=12 obj(12.0).to_string(%.0g)=1e+01 obj(12.0).to_string(%.1g)=12.0 +obj(-12.0).to_string(default format)=-12.0 +obj(0.0/0.0)=NaN +obj(1.0/0.0)=Infinity +obj(-1.0/0.0)=-Infinity diff --git a/third_party/json-c/tests/test_float.c b/third_party/json-c/tests/test_float.c index a790cd48c..f105ebc18 100644 --- a/third_party/json-c/tests/test_float.c +++ b/third_party/json-c/tests/test_float.c @@ -1,24 +1,48 @@ -/* Copyright (C) 2016 by Rainer Gerhards - * Released under ASL 2.0 */ +/* + * Original work: + * + * Copyright (C) 2016 by Rainer Gerhards + * Released under ASL 2.0 * + * + * Modified Work: + * + * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. + * + * This software product is a proprietary product of NVIDIA CORPORATION & + * AFFILIATES (the "Company") and all right, title, and interest in and to the + * software product, including all associated intellectual property rights, are + * and shall remain exclusively with the Company. + * + * This software product is governed by the End User License Agreement + * provided with the software product. + * + */ +#ifdef NDEBUG +#undef NDEBUG +#endif #include "config.h" +#include "json_object.h" +#include "json_tokener.h" #include -#include "../json_object.h" -#include "../json_tokener.h" int main(void) { - json_object *json; + json_object *json; - json = json_object_new_double(1.0); - printf("json = %s\n", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY)); - json_object_put(json); - json = json_object_new_double(1.23); - printf("json = %s\n", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY)); - json_object_put(json); - json = json_object_new_double(123456789.0); - printf("json = %s\n", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY)); - json_object_put(json); - json = json_object_new_double(123456789.123); - printf("json = %s\n", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY)); - json_object_put(json); - return 0; + json = doca_third_party_json_object_new_double(1.0); + printf("json = %s\n", doca_third_party_json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY)); + doca_third_party_json_object_put(json); + + json = doca_third_party_json_object_new_double(-1.0); + printf("json = %s\n", doca_third_party_json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY)); + doca_third_party_json_object_put(json); + json = doca_third_party_json_object_new_double(1.23); + printf("json = %s\n", doca_third_party_json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY)); + doca_third_party_json_object_put(json); + json = doca_third_party_json_object_new_double(123456789.0); + printf("json = %s\n", doca_third_party_json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY)); + doca_third_party_json_object_put(json); + json = doca_third_party_json_object_new_double(123456789.123); + printf("json = %s\n", doca_third_party_json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY)); + doca_third_party_json_object_put(json); + return 0; } diff --git a/third_party/json-c/tests/test_float.expected b/third_party/json-c/tests/test_float.expected index 970c6543e..7ca5916b0 100644 --- a/third_party/json-c/tests/test_float.expected +++ b/third_party/json-c/tests/test_float.expected @@ -1,4 +1,5 @@ json = 1.0 +json = -1.0 json = 1.23 json = 123456789.0 json = 123456789.123 diff --git a/third_party/json-c/tests/test_int_add.c b/third_party/json-c/tests/test_int_add.c index 08a880220..1751c8587 100644 --- a/third_party/json-c/tests/test_int_add.c +++ b/third_party/json-c/tests/test_int_add.c @@ -1,3 +1,25 @@ +/* + * Original work: + * + * json-c (copyright was originally missing from this file) + * + * Modified Work: + * + * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. + * + * This software product is a proprietary product of NVIDIA CORPORATION & + * AFFILIATES (the "Company") and all right, title, and interest in and to the + * software product, including all associated intellectual property rights, are + * and shall remain exclusively with the Company. + * + * This software product is governed by the End User License Agreement + * provided with the software product. + * + */ + +#ifdef NDEBUG +#undef NDEBUG +#endif #include #include @@ -5,42 +27,66 @@ int main(int argc, char **argv) { - json_object *tmp = json_object_new_int(123); - json_object_int_inc(tmp, 123); - assert(json_object_get_int(tmp) == 246); - json_object_put(tmp); + json_object *tmp = doca_third_party_json_object_new_int(123); + doca_third_party_json_object_int_inc(tmp, 123); + assert(doca_third_party_json_object_get_int(tmp) == 246); + doca_third_party_json_object_put(tmp); printf("INT ADD PASSED\n"); - tmp = json_object_new_int(INT32_MAX); - json_object_int_inc(tmp, 100); - assert(json_object_get_int(tmp) == INT32_MAX); - assert(json_object_get_int64(tmp) == (int64_t)INT32_MAX + 100L); - json_object_put(tmp); + tmp = doca_third_party_json_object_new_int(INT32_MAX); + doca_third_party_json_object_int_inc(tmp, 100); + assert(doca_third_party_json_object_get_int(tmp) == INT32_MAX); + assert(doca_third_party_json_object_get_int64(tmp) == (int64_t)INT32_MAX + 100L); + doca_third_party_json_object_put(tmp); printf("INT ADD OVERFLOW PASSED\n"); - tmp = json_object_new_int(INT32_MIN); - json_object_int_inc(tmp, -100); - assert(json_object_get_int(tmp) == INT32_MIN); - assert(json_object_get_int64(tmp) == (int64_t)INT32_MIN - 100L); - json_object_put(tmp); + tmp = doca_third_party_json_object_new_int(INT32_MIN); + doca_third_party_json_object_int_inc(tmp, -100); + assert(doca_third_party_json_object_get_int(tmp) == INT32_MIN); + assert(doca_third_party_json_object_get_int64(tmp) == (int64_t)INT32_MIN - 100L); + doca_third_party_json_object_put(tmp); printf("INT ADD UNDERFLOW PASSED\n"); - tmp = json_object_new_int64(321321321); - json_object_int_inc(tmp, 321321321); - assert(json_object_get_int(tmp) == 642642642); - json_object_put(tmp); + tmp = doca_third_party_json_object_new_int64(321321321); + doca_third_party_json_object_int_inc(tmp, 321321321); + assert(doca_third_party_json_object_get_int(tmp) == 642642642); + doca_third_party_json_object_put(tmp); printf("INT64 ADD PASSED\n"); - tmp = json_object_new_int64(INT64_MAX); - json_object_int_inc(tmp, 100); - assert(json_object_get_int64(tmp) == INT64_MAX); - json_object_int_inc(tmp, -100); - assert(json_object_get_int64(tmp) != INT64_MAX); - json_object_put(tmp); + tmp = doca_third_party_json_object_new_int64(INT64_MAX); + doca_third_party_json_object_int_inc(tmp, 100); + assert(doca_third_party_json_object_get_int64(tmp) == INT64_MAX); + assert(doca_third_party_json_object_get_uint64(tmp) == (uint64_t)INT64_MAX + 100U); + doca_third_party_json_object_int_inc(tmp, -100); + assert(doca_third_party_json_object_get_int64(tmp) == INT64_MAX); + assert(doca_third_party_json_object_get_uint64(tmp) == (uint64_t)INT64_MAX); + doca_third_party_json_object_put(tmp); printf("INT64 ADD OVERFLOW PASSED\n"); - tmp = json_object_new_int64(INT64_MIN); - json_object_int_inc(tmp, -100); - assert(json_object_get_int64(tmp) == INT64_MIN); - json_object_int_inc(tmp, 100); - assert(json_object_get_int64(tmp) != INT64_MIN); - json_object_put(tmp); + tmp = doca_third_party_json_object_new_int64(INT64_MIN); + doca_third_party_json_object_int_inc(tmp, -100); + assert(doca_third_party_json_object_get_int64(tmp) == INT64_MIN); + doca_third_party_json_object_int_inc(tmp, 100); + assert(doca_third_party_json_object_get_int64(tmp) != INT64_MIN); + doca_third_party_json_object_put(tmp); printf("INT64 ADD UNDERFLOW PASSED\n"); + // uint64 + negative int64--> negative int64 + tmp = doca_third_party_json_object_new_uint64(400); + doca_third_party_json_object_int_inc(tmp, -200); + assert(doca_third_party_json_object_get_int64(tmp) == 200); + assert(doca_third_party_json_object_get_uint64(tmp) == 200); + doca_third_party_json_object_int_inc(tmp, 200); + assert(doca_third_party_json_object_get_int64(tmp) == 400); + assert(doca_third_party_json_object_get_uint64(tmp) == 400); + doca_third_party_json_object_put(tmp); + printf("UINT64 ADD PASSED\n"); + tmp = doca_third_party_json_object_new_uint64(UINT64_MAX-50); + doca_third_party_json_object_int_inc(tmp, 100); + assert(doca_third_party_json_object_get_int64(tmp) == INT64_MAX); + assert(doca_third_party_json_object_get_uint64(tmp) == UINT64_MAX); + doca_third_party_json_object_put(tmp); + printf("UINT64 ADD OVERFLOW PASSED\n"); + tmp = doca_third_party_json_object_new_uint64(100); + doca_third_party_json_object_int_inc(tmp, -200); + assert(doca_third_party_json_object_get_int64(tmp) == -100); + assert(doca_third_party_json_object_get_uint64(tmp) == 0); + doca_third_party_json_object_put(tmp); + printf("UINT64 ADD UNDERFLOW PASSED\n"); printf("PASSED\n"); return 0; diff --git a/third_party/json-c/tests/test_int_add.expected b/third_party/json-c/tests/test_int_add.expected index 61c205c37..f9348d4b0 100644 --- a/third_party/json-c/tests/test_int_add.expected +++ b/third_party/json-c/tests/test_int_add.expected @@ -4,4 +4,7 @@ INT ADD UNDERFLOW PASSED INT64 ADD PASSED INT64 ADD OVERFLOW PASSED INT64 ADD UNDERFLOW PASSED +UINT64 ADD PASSED +UINT64 ADD OVERFLOW PASSED +UINT64 ADD UNDERFLOW PASSED PASSED diff --git a/third_party/json-c/tests/test_int_get.c b/third_party/json-c/tests/test_int_get.c new file mode 100644 index 000000000..1702ceafd --- /dev/null +++ b/third_party/json-c/tests/test_int_get.c @@ -0,0 +1,84 @@ +/* + * Original work: + * + * json-c (copyright was originally missing from this file) + * + * Modified Work: + * + * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. + * + * This software product is a proprietary product of NVIDIA CORPORATION & + * AFFILIATES (the "Company") and all right, title, and interest in and to the + * software product, including all associated intellectual property rights, are + * and shall remain exclusively with the Company. + * + * This software product is governed by the End User License Agreement + * provided with the software product. + * + */ + +#ifdef NDEBUG +#undef NDEBUG +#endif +#include +#include +#include + +#include "json.h" + +#define I64_MAX_S "9223372036854775807" +#define I64_OVER "9223372036854775808" +#define I64_MIN_S "-9223372036854775808" +#define I64_UNDER "-9223372036854775809" +#define U64_MAX_S "18446744073709551615" +#define U64_OUT_S "18446744073709551616" + +#define CHECK_GET(GET_F, J, EXPECTED) { struct json_object *jtmp = J; errno = 0; assert(GET_F(jtmp) == EXPECTED); doca_third_party_json_object_put(jtmp); } +#define CHECK_GET_INT(J, EXPECTED) CHECK_GET( doca_third_party_json_object_get_int, J, EXPECTED) +#define CHECK_GET_INT64(J, EXPECTED) CHECK_GET( doca_third_party_json_object_get_int64, J, EXPECTED) +#define CHECK_GET_UINT64(J, EXPECTED) CHECK_GET( doca_third_party_json_object_get_uint64, J, EXPECTED) + +#define CHECK_BASE(J, EXPECTED) CHECK_GET_INT(J, EXPECTED); CHECK_GET_INT64(J, EXPECTED); CHECK_GET_UINT64(J, EXPECTED) + +#define N_INT doca_third_party_json_object_new_int +#define N_I64 doca_third_party_json_object_new_int64 +#define N_U64 doca_third_party_json_object_new_uint64 +#define N_STR doca_third_party_json_object_new_string + +int main(int argc, char **argv) +{ + CHECK_BASE(N_INT(5), 5); + CHECK_BASE(N_INT(0), 0); + CHECK_BASE(N_STR("0"), 0); + CHECK_BASE(N_STR("00000"), 0); + CHECK_BASE(N_STR("000004568789"), 4568789); + CHECK_BASE(N_STR("0xFF"), 0 && errno == 0); // Hex-string values being parsed as 0 is the intended behavior + CHECK_BASE(N_STR("333this_seems_a_valid_string"), 333); + CHECK_BASE(N_STR("this_is_not_a_number"), 0 && errno == EINVAL); + CHECK_BASE(N_STR("B0"), 0 && errno == EINVAL); + printf("BASE CHECK PASSED\n"); + + CHECK_GET_INT(N_I64(INT32_MAX), INT32_MAX && errno == 0); + CHECK_GET_INT(N_I64(INT32_MIN), INT32_MIN && errno == 0); + CHECK_GET_INT(N_I64(INT64_MAX), INT32_MAX && errno == 0); + CHECK_GET_INT(N_I64(INT64_MIN), INT32_MIN && errno == 0); + CHECK_GET_INT(N_STR(I64_MAX_S), INT32_MAX && errno == 0); + CHECK_GET_INT(N_STR(I64_MIN_S), INT32_MIN && errno == 0); + printf("INT GET PASSED\n"); + + CHECK_GET_INT64(N_I64(INT64_MAX), INT64_MAX && errno == 0); + CHECK_GET_INT64(N_I64(INT64_MIN), INT64_MIN && errno == 0); + CHECK_GET_INT64(N_STR(I64_MAX_S), INT64_MAX && errno == 0); + CHECK_GET_INT64(N_STR(I64_MIN_S), INT64_MIN && errno == 0); + CHECK_GET_INT64(N_STR(I64_OVER), INT64_MAX && errno == ERANGE); + CHECK_GET_INT64(N_STR(I64_UNDER), INT64_MIN && errno == ERANGE); + printf("INT64 GET PASSED\n"); + + CHECK_GET_UINT64(N_U64(UINT64_MAX), UINT64_MAX && errno == 0); + CHECK_GET_UINT64(N_U64(-1), UINT64_MAX && errno == 0); + CHECK_GET_UINT64(N_STR(U64_OUT_S), UINT64_MAX && errno == ERANGE); + printf("UINT64 GET PASSED\n"); + + printf("PASSED\n"); + return 0; +} diff --git a/third_party/json-c/tests/test_int_get.expected b/third_party/json-c/tests/test_int_get.expected new file mode 100644 index 000000000..a9d78bf0b --- /dev/null +++ b/third_party/json-c/tests/test_int_get.expected @@ -0,0 +1,5 @@ +BASE CHECK PASSED +INT GET PASSED +INT64 GET PASSED +UINT64 GET PASSED +PASSED diff --git a/third_party/json-c/tests/test_int_get.test b/third_party/json-c/tests/test_int_get.test new file mode 120000 index 000000000..58a13f4f3 --- /dev/null +++ b/third_party/json-c/tests/test_int_get.test @@ -0,0 +1 @@ +test_basic.test \ No newline at end of file diff --git a/third_party/json-c/tests/test_json_patch.c b/third_party/json-c/tests/test_json_patch.c new file mode 100644 index 000000000..16327ab15 --- /dev/null +++ b/third_party/json-c/tests/test_json_patch.c @@ -0,0 +1,158 @@ +/* + * Original work: + * + * json-c (copyright was originally missing from this file) + * + * Modified Work: + * + * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. + * + * This software product is a proprietary product of NVIDIA CORPORATION & + * AFFILIATES (the "Company") and all right, title, and interest in and to the + * software product, including all associated intellectual property rights, are + * and shall remain exclusively with the Company. + * + * This software product is governed by the End User License Agreement + * provided with the software product. + * + */ + +#ifdef NDEBUG +#undef NDEBUG +#endif +#include "strerror_override.h" +#include +#include +#include +#include +#include + +#include "config.h" +#include "json.h" +#include "snprintf_compat.h" + +#ifndef PATH_MAX +#define PATH_MAX 256 +#endif + +void test_json_patch_op(struct json_object *jo) +{ + const char *comment = doca_third_party_json_object_get_string( + doca_third_party_json_object_object_get(jo, "comment")); + struct json_object *doc = doca_third_party_json_object_object_get(jo, "doc"); + struct json_object *patch = doca_third_party_json_object_object_get(jo, "patch"); + struct json_object *expected = NULL; + json_bool have_expected = + doca_third_party_json_object_object_get_ex(jo, "expected", &expected); + struct json_object *error = doca_third_party_json_object_object_get(jo, "error"); + const char *error_s = doca_third_party_json_object_get_string(error); + struct json_object *res = NULL; + int ret; + + printf("Testing '%s', doc '%s' patch '%s' : ", comment ? comment : error_s, + doca_third_party_json_object_get_string(doc), + doca_third_party_json_object_get_string(patch)); + if (!error && !have_expected) + { + printf("BAD TEST - no expected or error conditions in test: %s\n", + doca_third_party_json_object_to_json_string(jo)); + assert(0); + } + fflush(stdout); + struct json_patch_error jperr; + if (error) + { + assert(-1 == doca_third_party_json_patch_apply(doc, patch, &res, &jperr)); + assert(jperr.errno_code != 0); + printf("OK\n"); + printf(" => json_patch_apply failed as expected: %s at patch idx %zu: %s\n", + strerror(jperr.errno_code), jperr.patch_failure_idx, jperr.errmsg); + doca_third_party_json_object_put(res); + } + else + { + ret = doca_third_party_json_patch_apply(doc, patch, &res, &jperr); + if (ret) + { + fprintf(stderr, "json_patch_apply() returned '%d'\n", ret); + fprintf(stderr, "Expected: %s\n", + doca_third_party_json_object_get_string(expected)); + fprintf(stderr, "Got: %s\n", + res ? doca_third_party_json_object_get_string(res) : "(null)"); + fprintf(stderr, "json_patch_apply failed: %s at patch idx %zu: %s\n", + strerror(jperr.errno_code), jperr.patch_failure_idx, jperr.errmsg); + fflush(stderr); + assert(0); + } + // Note: res might be NULL if the whole document was removed + assert(jperr.errno_code == 0); + ret = doca_third_party_json_object_equal(expected, res); + if (ret == 0) + { + fprintf(stderr, "json_object_equal() returned '%d'\n", ret); + fprintf(stderr, "Expected: %s\n", + doca_third_party_json_object_get_string(expected)); + fprintf(stderr, "Got: %s\n", doca_third_party_json_object_get_string(res)); + fflush(stderr); + assert(0); + } + doca_third_party_json_object_put(res); + res = NULL; + printf("OK\n"); + } +} + +void test_json_patch_using_file(const char *testdir, const char *filename) +{ + char full_filename[PATH_MAX]; + (void)snprintf(full_filename, sizeof(full_filename), "%s/%s", testdir, filename); + size_t ii; + + printf("Testing using file %s\n", filename); + json_object *jo = doca_third_party_json_object_from_file(full_filename); + if (!jo) + { + fprintf(stderr, "FAIL: unable to open %s: %s\n", full_filename, strerror(errno)); + exit(EXIT_FAILURE); + } + + for (ii = 0; ii < doca_third_party_json_object_array_length(jo); ii++) + { + struct json_object *jo1 = doca_third_party_json_object_array_get_idx(jo, ii); + test_json_patch_op(jo1); + } + + doca_third_party_json_object_put(jo); +} + +int main(int argc, char **argv) +{ + const char *testdir; + if (argc < 2) + { + fprintf(stderr, + "Usage: %s \n" + " is the location of input files\n", + argv[0]); + return EXIT_FAILURE; + } + testdir = argv[1]; + + // Test json_c_version.c + if (strncmp(doca_third_party_json_c_version(), JSON_C_VERSION, sizeof(JSON_C_VERSION))) + { + printf("FAIL: Output from json_c_version(): %s does not match %s", + doca_third_party_json_c_version(), JSON_C_VERSION); + return EXIT_FAILURE; + } + if (doca_third_party_json_c_version_num() != JSON_C_VERSION_NUM) + { + printf("FAIL: Output from json_c_version_num(): %d does not match %d", + doca_third_party_json_c_version_num(), JSON_C_VERSION_NUM); + return EXIT_FAILURE; + } + + test_json_patch_using_file(testdir, "json_patch_spec_tests.json"); + test_json_patch_using_file(testdir, "json_patch_tests.json"); + return 0; +} diff --git a/third_party/json-c/tests/test_json_patch.expected b/third_party/json-c/tests/test_json_patch.expected new file mode 100644 index 000000000..523d276b2 --- /dev/null +++ b/third_party/json-c/tests/test_json_patch.expected @@ -0,0 +1,158 @@ +Testing using file json_patch_spec_tests.json +Testing '4.1. add with missing object', doc '{ "q": { "bar": 2 } }' patch '[ { "op": "add", "path": "\/a\/b", "value": 1 } ]' : OK + => json_patch_apply failed as expected: ERRNO=ENOENT at patch idx 0: Failed to set value at path referenced by 'path' field +Testing 'A.1. Adding an Object Member', doc '{ "foo": "bar" }' patch '[ { "op": "add", "path": "\/baz", "value": "qux" } ]' : OK +Testing 'A.2. Adding an Array Element', doc '{ "foo": [ "bar", "baz" ] }' patch '[ { "op": "add", "path": "\/foo\/1", "value": "qux" } ]' : OK +Testing 'A.3. Removing an Object Member', doc '{ "baz": "qux", "foo": "bar" }' patch '[ { "op": "remove", "path": "\/baz" } ]' : OK +Testing 'A.4. Removing an Array Element', doc '{ "foo": [ "bar", "qux", "baz" ] }' patch '[ { "op": "remove", "path": "\/foo\/1" } ]' : OK +Testing 'A.5. Replacing a Value', doc '{ "baz": "qux", "foo": "bar" }' patch '[ { "op": "replace", "path": "\/baz", "value": "boo" } ]' : OK +Testing 'A.6. Moving a Value', doc '{ "foo": { "bar": "baz", "waldo": "fred" }, "qux": { "corge": "grault" } }' patch '[ { "op": "move", "from": "\/foo\/waldo", "path": "\/qux\/thud" } ]' : OK +Testing 'A.7. Moving an Array Element', doc '{ "foo": [ "all", "grass", "cows", "eat" ] }' patch '[ { "op": "move", "from": "\/foo\/1", "path": "\/foo\/3" } ]' : OK +Testing 'A.8. Testing a Value: Success', doc '{ "baz": "qux", "foo": [ "a", 2, "c" ] }' patch '[ { "op": "test", "path": "\/baz", "value": "qux" }, { "op": "test", "path": "\/foo\/1", "value": 2 } ]' : OK +Testing 'A.9. Testing a Value: Error', doc '{ "baz": "qux" }' patch '[ { "op": "test", "path": "\/baz", "value": "bar" } ]' : OK + => json_patch_apply failed as expected: ERRNO=ENOENT at patch idx 0: Value of element referenced by 'path' field did not match 'value' field +Testing 'A.10. Adding a nested Member Object', doc '{ "foo": "bar" }' patch '[ { "op": "add", "path": "\/child", "value": { "grandchild": { } } } ]' : OK +Testing 'A.11. Ignoring Unrecognized Elements', doc '{ "foo": "bar" }' patch '[ { "op": "add", "path": "\/baz", "value": "qux", "xyz": 123 } ]' : OK +Testing 'A.12. Adding to a Non-existent Target', doc '{ "foo": "bar" }' patch '[ { "op": "add", "path": "\/baz\/bat", "value": "qux" } ]' : OK + => json_patch_apply failed as expected: ERRNO=ENOENT at patch idx 0: Failed to set value at path referenced by 'path' field +Testing 'A.13 Invalid JSON Patch Document', doc '{ "foo": "bar" }' patch '[ { "op": "remove", "path": "\/baz", "value": "qux" } ]' : OK + => json_patch_apply failed as expected: ERRNO=ENOENT at patch idx 0: Did not find element referenced by path field +Testing 'A.14. ~ Escape Ordering', doc '{ "\/": 9, "~1": 10 }' patch '[ { "op": "test", "path": "\/~01", "value": 10 } ]' : OK +Testing 'A.15. Comparing Strings and Numbers', doc '{ "\/": 9, "~1": 10 }' patch '[ { "op": "test", "path": "\/~01", "value": "10" } ]' : OK + => json_patch_apply failed as expected: ERRNO=ENOENT at patch idx 0: Value of element referenced by 'path' field did not match 'value' field +Testing 'A.16. Adding an Array Value', doc '{ "foo": [ "bar" ] }' patch '[ { "op": "add", "path": "\/foo\/-", "value": [ "abc", "def" ] } ]' : OK +Testing using file json_patch_tests.json +Testing 'empty list, empty docs', doc '{ }' patch '[ ]' : OK +Testing 'empty patch list', doc '{ "foo": 1 }' patch '[ ]' : OK +Testing 'rearrangements OK?', doc '{ "foo": 1, "bar": 2 }' patch '[ ]' : OK +Testing 'rearrangements OK? How about one level down ... array', doc '[ { "foo": 1, "bar": 2 } ]' patch '[ ]' : OK +Testing 'rearrangements OK? How about one level down...', doc '{ "foo": { "foo": 1, "bar": 2 } }' patch '[ ]' : OK +Testing 'add replaces any existing field', doc '{ "foo": null }' patch '[ { "op": "add", "path": "\/foo", "value": 1 } ]' : OK +Testing 'toplevel array', doc '[ ]' patch '[ { "op": "add", "path": "\/0", "value": "foo" } ]' : OK +Testing 'toplevel array, no change', doc '[ "foo" ]' patch '[ ]' : OK +Testing 'toplevel object, numeric string', doc '{ }' patch '[ { "op": "add", "path": "\/foo", "value": "1" } ]' : OK +Testing 'toplevel object, integer', doc '{ }' patch '[ { "op": "add", "path": "\/foo", "value": 1 } ]' : OK +Testing 'Toplevel scalar values OK?', doc 'foo' patch '[ { "op": "replace", "path": "", "value": "bar" } ]' : OK +Testing 'replace object document with array document?', doc '{ }' patch '[ { "op": "add", "path": "", "value": [ ] } ]' : OK +Testing 'replace array document with object document?', doc '[ ]' patch '[ { "op": "add", "path": "", "value": { } } ]' : OK +Testing 'append to root array document?', doc '[ ]' patch '[ { "op": "add", "path": "\/-", "value": "hi" } ]' : OK +Testing 'Add, / target', doc '{ }' patch '[ { "op": "add", "path": "\/", "value": 1 } ]' : OK +Testing 'Add, /foo/ deep target (trailing slash)', doc '{ "foo": { } }' patch '[ { "op": "add", "path": "\/foo\/", "value": 1 } ]' : OK +Testing 'Add composite value at top level', doc '{ "foo": 1 }' patch '[ { "op": "add", "path": "\/bar", "value": [ 1, 2 ] } ]' : OK +Testing 'Add into composite value', doc '{ "foo": 1, "baz": [ { "qux": "hello" } ] }' patch '[ { "op": "add", "path": "\/baz\/0\/foo", "value": "world" } ]' : OK +Testing 'Out of bounds (upper)', doc '{ "bar": [ 1, 2 ] }' patch '[ { "op": "add", "path": "\/bar\/8", "value": "5" } ]' : OK + => json_patch_apply failed as expected: ERRNO=EINVAL at patch idx 0: Failed to set value at path referenced by 'path' field +Testing 'Out of bounds (lower)', doc '{ "bar": [ 1, 2 ] }' patch '[ { "op": "add", "path": "\/bar\/-1", "value": "5" } ]' : OK + => json_patch_apply failed as expected: ERRNO=EINVAL at patch idx 0: Failed to set value at path referenced by 'path' field +Testing '(null)', doc '{ "foo": 1 }' patch '[ { "op": "add", "path": "\/bar", "value": true } ]' : OK +Testing '(null)', doc '{ "foo": 1 }' patch '[ { "op": "add", "path": "\/bar", "value": false } ]' : OK +Testing '(null)', doc '{ "foo": 1 }' patch '[ { "op": "add", "path": "\/bar", "value": null } ]' : OK +Testing '0 can be an array index or object element name', doc '{ "foo": 1 }' patch '[ { "op": "add", "path": "\/0", "value": "bar" } ]' : OK +Testing '(null)', doc '[ "foo" ]' patch '[ { "op": "add", "path": "\/1", "value": "bar" } ]' : OK +Testing '(null)', doc '[ "foo", "sil" ]' patch '[ { "op": "add", "path": "\/1", "value": "bar" } ]' : OK +Testing '(null)', doc '[ "foo", "sil" ]' patch '[ { "op": "add", "path": "\/0", "value": "bar" } ]' : OK +Testing 'push item to array via last index + 1', doc '[ "foo", "sil" ]' patch '[ { "op": "add", "path": "\/2", "value": "bar" } ]' : OK +Testing 'add item to array at index > length should fail', doc '[ "foo", "sil" ]' patch '[ { "op": "add", "path": "\/3", "value": "bar" } ]' : OK + => json_patch_apply failed as expected: ERRNO=EINVAL at patch idx 0: Failed to set value at path referenced by 'path' field +Testing 'test against implementation-specific numeric parsing', doc '{ "1e0": "foo" }' patch '[ { "op": "test", "path": "\/1e0", "value": "foo" } ]' : OK +Testing 'test with bad number should fail', doc '[ "foo", "bar" ]' patch '[ { "op": "test", "path": "\/1e0", "value": "bar" } ]' : OK + => json_patch_apply failed as expected: ERRNO=EINVAL at patch idx 0: Invalid path field +Testing 'Object operation on array target', doc '[ "foo", "sil" ]' patch '[ { "op": "add", "path": "\/bar", "value": 42 } ]' : OK + => json_patch_apply failed as expected: ERRNO=EINVAL at patch idx 0: Failed to set value at path referenced by 'path' field +Testing 'value in array add not flattened', doc '[ "foo", "sil" ]' patch '[ { "op": "add", "path": "\/1", "value": [ "bar", "baz" ] } ]' : OK +Testing '(null)', doc '{ "foo": 1, "bar": [ 1, 2, 3, 4 ] }' patch '[ { "op": "remove", "path": "\/bar" } ]' : OK +Testing '(null)', doc '{ "foo": 1, "baz": [ { "qux": "hello" } ] }' patch '[ { "op": "remove", "path": "\/baz\/0\/qux" } ]' : OK +Testing '(null)', doc '{ "foo": 1, "baz": [ { "qux": "hello" } ] }' patch '[ { "op": "replace", "path": "\/foo", "value": [ 1, 2, 3, 4 ] } ]' : OK +Testing '(null)', doc '{ "foo": [ 1, 2, 3, 4 ], "baz": [ { "qux": "hello" } ] }' patch '[ { "op": "replace", "path": "\/baz\/0\/qux", "value": "world" } ]' : OK +Testing '(null)', doc '[ "foo" ]' patch '[ { "op": "replace", "path": "\/0", "value": "bar" } ]' : OK +Testing '(null)', doc '[ "" ]' patch '[ { "op": "replace", "path": "\/0", "value": 0 } ]' : OK +Testing '(null)', doc '[ "" ]' patch '[ { "op": "replace", "path": "\/0", "value": true } ]' : OK +Testing '(null)', doc '[ "" ]' patch '[ { "op": "replace", "path": "\/0", "value": false } ]' : OK +Testing '(null)', doc '[ "" ]' patch '[ { "op": "replace", "path": "\/0", "value": null } ]' : OK +Testing 'value in array replace not flattened', doc '[ "foo", "sil" ]' patch '[ { "op": "replace", "path": "\/1", "value": [ "bar", "baz" ] } ]' : OK +Testing 'replace whole document', doc '{ "foo": "bar" }' patch '[ { "op": "replace", "path": "", "value": { "baz": "qux" } } ]' : OK +Testing 'add whole document, null', doc '{ }' patch '[ { "op": "remove", "path": "" }, { "op": "add", "path": "", "value": { "baz": "qux" } } ]' : OK +Testing 'replace whole document, null', doc '{ }' patch '[ { "op": "remove", "path": "" }, { "op": "replace", "path": "", "value": { "baz": "qux" } } ]' : OK + => json_patch_apply failed as expected: ERRNO=EINVAL at patch idx 1: Invalid path field +Testing 'remove whole document', doc '{ "foo": "bar" }' patch '[ { "op": "remove", "path": "" } ]' : OK +Testing 'remove whole document', doc '{ "foo": "bar" }' patch '[ { "op": "remove", "path": "" } ]' : OK +Testing 'remove whole document, array', doc '[ "foo", "bar" ]' patch '[ { "op": "remove", "path": "" } ]' : OK +Testing 'remove whole document, string', doc 'foo' patch '[ { "op": "remove", "path": "" } ]' : OK +Testing 'remove whole document, null', doc '{ }' patch '[ { "op": "remove", "path": "" }, { "op": "remove", "path": "" } ]' : OK + => json_patch_apply failed as expected: ERRNO=EINVAL at patch idx 1: Invalid path field +Testing 'test replace with missing parent key should fail', doc '{ "bar": "baz" }' patch '[ { "op": "replace", "path": "\/foo\/bar", "value": false } ]' : OK + => json_patch_apply failed as expected: ERRNO=ENOENT at patch idx 0: Did not find element referenced by path field +Testing 'spurious patch properties', doc '{ "foo": 1 }' patch '[ { "op": "test", "path": "\/foo", "value": 1, "spurious": 1 } ]' : OK +Testing 'null value should be valid obj property', doc '{ "foo": null }' patch '[ { "op": "test", "path": "\/foo", "value": null } ]' : OK +Testing 'null value should be valid obj property to be replaced with something truthy', doc '{ "foo": null }' patch '[ { "op": "replace", "path": "\/foo", "value": "truthy" } ]' : OK +Testing 'null value should be valid obj property to be moved', doc '{ "foo": null }' patch '[ { "op": "move", "from": "\/foo", "path": "\/bar" } ]' : OK +Testing 'null value should be valid obj property to be copied', doc '{ "foo": null }' patch '[ { "op": "copy", "from": "\/foo", "path": "\/bar" } ]' : OK +Testing 'null value should be valid obj property to be removed', doc '{ "foo": null }' patch '[ { "op": "remove", "path": "\/foo" } ]' : OK +Testing 'null value should still be valid obj property replace other value', doc '{ "foo": "bar" }' patch '[ { "op": "replace", "path": "\/foo", "value": null } ]' : OK +Testing 'test should pass despite rearrangement', doc '{ "foo": { "foo": 1, "bar": 2 } }' patch '[ { "op": "test", "path": "\/foo", "value": { "bar": 2, "foo": 1 } } ]' : OK +Testing 'test should pass despite (nested) rearrangement', doc '{ "foo": [ { "foo": 1, "bar": 2 } ] }' patch '[ { "op": "test", "path": "\/foo", "value": [ { "bar": 2, "foo": 1 } ] } ]' : OK +Testing 'test should pass - no error', doc '{ "foo": { "bar": [ 1, 2, 5, 4 ] } }' patch '[ { "op": "test", "path": "\/foo", "value": { "bar": [ 1, 2, 5, 4 ] } } ]' : OK +Testing 'test op should fail', doc '{ "foo": { "bar": [ 1, 2, 5, 4 ] } }' patch '[ { "op": "test", "path": "\/foo", "value": [ 1, 2 ] } ]' : OK + => json_patch_apply failed as expected: ERRNO=ENOENT at patch idx 0: Value of element referenced by 'path' field did not match 'value' field +Testing 'Test the whole document', doc '{ "foo": 1 }' patch '[ { "op": "test", "path": "", "value": { "foo": 1 } } ]' : OK +Testing 'Test the whole document, no match', doc '{ "foo": 1 }' patch '[ { "op": "test", "path": "", "value": { "foo": 2 } } ]' : OK + => json_patch_apply failed as expected: ERRNO=ENOENT at patch idx 0: Value of element referenced by 'path' field did not match 'value' field +Testing 'Empty-string element', doc '{ "": 1 }' patch '[ { "op": "test", "path": "\/", "value": 1 } ]' : OK +Testing '(null)', doc '{ "foo": [ "bar", "baz" ], "": 0, "a\/b": 1, "c%d": 2, "e^f": 3, "g|h": 4, "i\\j": 5, "k\"l": 6, " ": 7, "m~n": 8 }' patch '[ { "op": "test", "path": "\/foo", "value": [ "bar", "baz" ] }, { "op": "test", "path": "\/foo\/0", "value": "bar" }, { "op": "test", "path": "\/", "value": 0 }, { "op": "test", "path": "\/a~1b", "value": 1 }, { "op": "test", "path": "\/c%d", "value": 2 }, { "op": "test", "path": "\/e^f", "value": 3 }, { "op": "test", "path": "\/g|h", "value": 4 }, { "op": "test", "path": "\/i\\j", "value": 5 }, { "op": "test", "path": "\/k\"l", "value": 6 }, { "op": "test", "path": "\/ ", "value": 7 }, { "op": "test", "path": "\/m~0n", "value": 8 } ]' : OK +Testing 'Move to same location has no effect', doc '{ "foo": 1 }' patch '[ { "op": "move", "from": "\/foo", "path": "\/foo" } ]' : OK +Testing '(null)', doc '{ "foo": 1, "baz": [ { "qux": "hello" } ] }' patch '[ { "op": "move", "from": "\/foo", "path": "\/bar" } ]' : OK +Testing '(null)', doc '{ "baz": [ { "qux": "hello" } ], "bar": 1 }' patch '[ { "op": "move", "from": "\/baz\/0\/qux", "path": "\/baz\/1" } ]' : OK +Testing '(null)', doc '{ "baz": [ { "qux": "hello" } ], "bar": 1 }' patch '[ { "op": "copy", "from": "\/baz\/0", "path": "\/boo" } ]' : OK +Testing 'replacing the root of the document is possible with add', doc '{ "foo": "bar" }' patch '[ { "op": "add", "path": "", "value": { "baz": "qux" } } ]' : OK +Testing 'Adding to "/-" adds to the end of the array', doc '[ 1, 2 ]' patch '[ { "op": "add", "path": "\/-", "value": { "foo": [ "bar", "baz" ] } } ]' : OK +Testing 'Adding to "/-" adds to the end of the array, even n levels down', doc '[ 1, 2, [ 3, [ 4, 5 ] ] ]' patch '[ { "op": "add", "path": "\/2\/1\/-", "value": { "foo": [ "bar", "baz" ] } } ]' : OK +Testing 'test remove with bad number should fail', doc '{ "foo": 1, "baz": [ { "qux": "hello" } ] }' patch '[ { "op": "remove", "path": "\/baz\/1e0\/qux" } ]' : OK + => json_patch_apply failed as expected: ERRNO=EINVAL at patch idx 0: Invalid path field +Testing 'test remove on array', doc '[ 1, 2, 3, 4 ]' patch '[ { "op": "remove", "path": "\/0" } ]' : OK +Testing 'test repeated removes', doc '[ 1, 2, 3, 4 ]' patch '[ { "op": "remove", "path": "\/1" }, { "op": "remove", "path": "\/2" } ]' : OK +Testing 'test remove with bad index should fail', doc '[ 1, 2, 3, 4 ]' patch '[ { "op": "remove", "path": "\/1e0" } ]' : OK + => json_patch_apply failed as expected: ERRNO=EINVAL at patch idx 0: Invalid path field +Testing 'test replace with bad number should fail', doc '[ "" ]' patch '[ { "op": "replace", "path": "\/1e0", "value": false } ]' : OK + => json_patch_apply failed as expected: ERRNO=EINVAL at patch idx 0: Invalid path field +Testing 'test copy with bad number should fail', doc '{ "baz": [ 1, 2, 3 ], "bar": 1 }' patch '[ { "op": "copy", "from": "\/baz\/1e0", "path": "\/boo" } ]' : OK + => json_patch_apply failed as expected: ERRNO=EINVAL at patch idx 0: Invalid from field +Testing 'test move with bad number should fail', doc '{ "foo": 1, "baz": [ 1, 2, 3, 4 ] }' patch '[ { "op": "move", "from": "\/baz\/1e0", "path": "\/foo" } ]' : OK + => json_patch_apply failed as expected: ERRNO=EINVAL at patch idx 0: Invalid from field +Testing 'test add with bad number should fail', doc '[ "foo", "sil" ]' patch '[ { "op": "add", "path": "\/1e0", "value": "bar" } ]' : OK + => json_patch_apply failed as expected: ERRNO=EINVAL at patch idx 0: Failed to set value at path referenced by 'path' field +Testing 'missing 'path' parameter', doc '{ }' patch '[ { "op": "add", "value": "bar" } ]' : OK + => json_patch_apply failed as expected: ERRNO=EINVAL at patch idx 0: Patch object does not contain 'path' field +Testing ''path' parameter with null value', doc '{ }' patch '[ { "op": "add", "path": null, "value": "bar" } ]' : OK + => json_patch_apply failed as expected: ERRNO=EINVAL at patch idx 0: Failed to set value at path referenced by 'path' field +Testing 'invalid JSON Pointer token', doc '{ }' patch '[ { "op": "add", "path": "foo", "value": "bar" } ]' : OK + => json_patch_apply failed as expected: ERRNO=EINVAL at patch idx 0: Failed to set value at path referenced by 'path' field +Testing 'missing 'value' parameter to add', doc '[ 1 ]' patch '[ { "op": "add", "path": "\/-" } ]' : OK + => json_patch_apply failed as expected: ERRNO=EINVAL at patch idx 0: Patch object does not contain a 'value' field +Testing 'missing 'value' parameter to replace', doc '[ 1 ]' patch '[ { "op": "replace", "path": "\/0" } ]' : OK + => json_patch_apply failed as expected: ERRNO=EINVAL at patch idx 0: Patch object does not contain a 'value' field +Testing 'missing 'value' parameter to test', doc '[ null ]' patch '[ { "op": "test", "path": "\/0" } ]' : OK + => json_patch_apply failed as expected: ERRNO=EINVAL at patch idx 0: Patch object does not contain a 'value' field +Testing 'missing value parameter to test - where undef is falsy', doc '[ false ]' patch '[ { "op": "test", "path": "\/0" } ]' : OK + => json_patch_apply failed as expected: ERRNO=EINVAL at patch idx 0: Patch object does not contain a 'value' field +Testing 'missing from parameter to copy', doc '[ 1 ]' patch '[ { "op": "copy", "path": "\/-" } ]' : OK + => json_patch_apply failed as expected: ERRNO=EINVAL at patch idx 0: Patch does not contain a 'from' field +Testing 'missing from location to copy', doc '{ "foo": 1 }' patch '[ { "op": "copy", "from": "\/bar", "path": "\/foo" } ]' : OK + => json_patch_apply failed as expected: ERRNO=ENOENT at patch idx 0: Did not find element referenced by from field +Testing 'missing from parameter to move', doc '{ "foo": 1 }' patch '[ { "op": "move", "path": "" } ]' : OK + => json_patch_apply failed as expected: ERRNO=EINVAL at patch idx 0: Patch does not contain a 'from' field +Testing 'missing from location to move', doc '{ "foo": 1 }' patch '[ { "op": "move", "from": "\/bar", "path": "\/foo" } ]' : OK + => json_patch_apply failed as expected: ERRNO=ENOENT at patch idx 0: Did not find element referenced by from field +Testing 'duplicate ops, json-c parses this as op:move', doc '{ "foo": "bar" }' patch '[ { "op": "move", "path": "\/baz", "value": "qux", "from": "\/foo" } ]' : OK +Testing 'unrecognized op should fail', doc '{ "foo": 1 }' patch '[ { "op": "spam", "path": "\/foo", "value": 1 } ]' : OK + => json_patch_apply failed as expected: ERRNO=EINVAL at patch idx 0: Patch object has invalid 'op' field +Testing 'test with bad array number that has leading zeros', doc '[ "foo", "bar" ]' patch '[ { "op": "test", "path": "\/00", "value": "foo" } ]' : OK + => json_patch_apply failed as expected: ERRNO=EINVAL at patch idx 0: Invalid path field +Testing 'test with bad array number that has leading zeros', doc '[ "foo", "bar" ]' patch '[ { "op": "test", "path": "\/01", "value": "bar" } ]' : OK + => json_patch_apply failed as expected: ERRNO=EINVAL at patch idx 0: Invalid path field +Testing 'Removing nonexistent field', doc '{ "foo": "bar" }' patch '[ { "op": "remove", "path": "\/baz" } ]' : OK + => json_patch_apply failed as expected: ERRNO=ENOENT at patch idx 0: Did not find element referenced by path field +Testing 'Removing deep nonexistent path', doc '{ "foo": "bar" }' patch '[ { "op": "remove", "path": "\/missing1\/missing2" } ]' : OK + => json_patch_apply failed as expected: ERRNO=ENOENT at patch idx 0: Did not find element referenced by path field +Testing 'Removing nonexistent index', doc '[ "foo", "bar" ]' patch '[ { "op": "remove", "path": "\/2" } ]' : OK + => json_patch_apply failed as expected: ERRNO=ENOENT at patch idx 0: Did not find element referenced by path field +Testing 'Patch with different capitalisation than doc', doc '{ "foo": "bar" }' patch '[ { "op": "add", "path": "\/FOO", "value": "BAR" } ]' : OK diff --git a/third_party/json-c/tests/test_json_patch.test b/third_party/json-c/tests/test_json_patch.test new file mode 100755 index 000000000..0dc5aff80 --- /dev/null +++ b/third_party/json-c/tests/test_json_patch.test @@ -0,0 +1,17 @@ +#!/bin/sh + +export _JSON_C_STRERROR_ENABLE=1 + +# Common definitions +if test -z "$srcdir"; then + srcdir="${0%/*}" + test "$srcdir" = "$0" && srcdir=. + test -z "$srcdir" && srcdir=. +fi +. "$srcdir/test-defs.sh" + +filename=$(basename "$0") +filename="${filename%.*}" + +run_output_test $filename "$srcdir" +exit $? diff --git a/third_party/json-c/tests/test_json_pointer.c b/third_party/json-c/tests/test_json_pointer.c index 97566e263..790b746f9 100644 --- a/third_party/json-c/tests/test_json_pointer.c +++ b/third_party/json-c/tests/test_json_pointer.c @@ -1,6 +1,27 @@ -#include "strerror_override.h" -#include "strerror_override_private.h" +/* + * Original work: + * + * json-c (copyright was originally missing from this file) + * + * Modified Work: + * + * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. + * + * This software product is a proprietary product of NVIDIA CORPORATION & + * AFFILIATES (the "Company") and all right, title, and interest in and to the + * software product, including all associated intellectual property rights, are + * and shall remain exclusively with the Company. + * + * This software product is governed by the End User License Agreement + * provided with the software product. + * + */ + +#ifdef NDEBUG +#undef NDEBUG +#endif #include +#include #include #include @@ -9,61 +30,65 @@ static void test_example_int(struct json_object *jo1, const char *json_pointer, int expected_int) { struct json_object *jo2 = NULL; - assert(0 == json_pointer_get(jo1, json_pointer, NULL)); - assert(0 == json_pointer_get(jo1, json_pointer, &jo2)); - assert(json_object_is_type(jo2, json_type_int)); - assert(expected_int == json_object_get_int(jo2)); + assert(0 == doca_third_party_json_pointer_get(jo1, json_pointer, NULL)); + assert(0 == doca_third_party_json_pointer_get(jo1, json_pointer, &jo2)); + assert(doca_third_party_json_object_is_type(jo2, json_type_int)); + assert(expected_int == doca_third_party_json_object_get_int(jo2)); printf("PASSED - GET - %s == %d\n", json_pointer, expected_int); } static const char *input_json_str = "{ " - "'foo': ['bar', 'baz'], " - "'': 0, " - "'a/b': 1, " - "'c\%d': 2, " - "'e^f': 3, " - "'g|h': 4, " - "'i\\\\j': 5, " - "'k\\\"l': 6, " - "' ': 7, " - "'m~n': 8 " -"}"; - - -static const char *rec_input_json_str = "{" - "'arr' : [" - "{" - "'obj': [" - "{},{}," - "{" - "'obj1': 0," - "'obj2': \"1\"" - "}" - "]" - "}" - "]," - "'obj' : {" - "'obj': {" - "'obj': [" - "{" - "'obj1': 0," - "'obj2': \"1\"" - "}" - "]" - "}" - "}" -"}"; + "'foo': ['bar', 'baz'], " + "'': 0, " + "'a/b': 1, " + "'c%d': 2, " + "'e^f': 3, " + "'g|h': 4, " + "'i\\\\j': 5, " + "'k\\\"l': 6, " + "' ': 7, " + "'m~n': 8 " + "}"; + +/* clang-format off */ +static const char *rec_input_json_str = + "{" + "'arr' : [" + "{" + "'obj': [" + "{},{}," + "{" + "'obj1': 0," + "'obj2': \"1\"" + "}" + "]" + "}" + "]," + "'obj' : {" + "'obj': {" + "'obj': [" + "{" + "'obj1': 0," + "'obj2': \"1\"" + "}" + "]" + "}" + "}" + "}"; +/* clang-format on */ /* Example from RFC */ -static void test_example_get() +static void test_example_get(void) { int i; struct json_object *jo1, *jo2, *jo3; - struct json_pointer_map_s_i { + struct json_pointer_map_s_i + { const char *s; int i; }; /* Create a map to iterate over for the ints */ + /* clang-format off */ struct json_pointer_map_s_i json_pointers[] = { { "/", 0 }, { "/a~1b", 1 }, @@ -76,213 +101,259 @@ static void test_example_get() { "/m~0n", 8 }, { NULL, 0} }; + /* clang-format on */ - jo1 = json_tokener_parse(input_json_str); + jo1 = doca_third_party_json_tokener_parse(input_json_str); assert(NULL != jo1); printf("PASSED - GET - LOADED TEST JSON\n"); - printf("%s\n", json_object_get_string(jo1)); + printf("%s\n", doca_third_party_json_object_get_string(jo1)); /* Test empty string returns entire object */ jo2 = NULL; /* For each test, we're trying to see that NULL **value works (does no segfault) */ - assert(0 == json_pointer_get(jo1, "", NULL)); - assert(0 == json_pointer_get(jo1, "", &jo2)); - assert(json_object_equal(jo2, jo1)); + assert(0 == doca_third_party_json_pointer_get(jo1, "", NULL)); + assert(0 == doca_third_party_json_pointer_get(jo1, "", &jo2)); + assert(doca_third_party_json_object_equal(jo2, jo1)); printf("PASSED - GET - ENTIRE OBJECT WORKED\n"); /* Test /foo == ['bar', 'baz'] */ - jo3 = json_object_new_array(); - json_object_array_add(jo3, json_object_new_string("bar")); - json_object_array_add(jo3, json_object_new_string("baz")); + jo3 = doca_third_party_json_object_new_array(); + doca_third_party_json_object_array_add(jo3, doca_third_party_json_object_new_string("bar")); + doca_third_party_json_object_array_add(jo3, doca_third_party_json_object_new_string("baz")); jo2 = NULL; - assert(0 == json_pointer_get(jo1, "/foo", NULL)); - assert(0 == json_pointer_get(jo1, "/foo", &jo2)); + assert(0 == doca_third_party_json_pointer_get(jo1, "/foo", NULL)); + assert(0 == doca_third_party_json_pointer_get(jo1, "/foo", &jo2)); assert(NULL != jo2); - assert(json_object_equal(jo2, jo3)); - json_object_put(jo3); + assert(doca_third_party_json_object_equal(jo2, jo3)); + doca_third_party_json_object_put(jo3); printf("PASSED - GET - /foo == ['bar', 'baz']\n"); /* Test /foo/0 == 'bar' */ jo2 = NULL; - assert(0 == json_pointer_get(jo1, "/foo/0", NULL)); - assert(0 == json_pointer_get(jo1, "/foo/0", &jo2)); + assert(0 == doca_third_party_json_pointer_get(jo1, "/foo/0", NULL)); + assert(0 == doca_third_party_json_pointer_get(jo1, "/foo/0", &jo2)); assert(NULL != jo2); - assert(0 == strcmp("bar", json_object_get_string(jo2))); + assert(0 == strcmp("bar", doca_third_party_json_object_get_string(jo2))); printf("PASSED - GET - /foo/0 == 'bar'\n"); - for (i = 0 ; json_pointers[i].s; i++) + for (i = 0; json_pointers[i].s; i++) test_example_int(jo1, json_pointers[i].s, json_pointers[i].i); - json_object_put(jo1); + doca_third_party_json_object_put(jo1); } -/* I'm not too happy with the RFC example to test the recusion of the json_pointer_get() function */ -static void test_recursion_get() +/* I'm not too happy with the RFC example to test the recursion of the json_pointer_get() function */ +static void test_recursion_get(void) { - struct json_object *jo2, *jo1 = json_tokener_parse(rec_input_json_str); + struct json_object *jo2, *jo1 = doca_third_party_json_tokener_parse(rec_input_json_str); jo2 = NULL; assert(jo1 != NULL); - printf("%s\n", json_object_get_string(jo1)); - assert(0 == json_pointer_get(jo1, "/arr/0/obj/2/obj1", &jo2)); - assert(json_object_is_type(jo2, json_type_int)); - assert(0 == json_object_get_int(jo2)); + printf("%s\n", doca_third_party_json_object_get_string(jo1)); + assert(0 == doca_third_party_json_pointer_get(jo1, "/arr/0/obj/2/obj1", &jo2)); + assert(doca_third_party_json_object_is_type(jo2, json_type_int)); + assert(0 == doca_third_party_json_object_get_int(jo2)); - assert(0 == json_pointer_get(jo1, "/arr/0/obj/2/obj2", &jo2)); - assert(json_object_is_type(jo2, json_type_string)); - assert(0 == strcmp("1", json_object_get_string(jo2))); + assert(0 == doca_third_party_json_pointer_get(jo1, "/arr/0/obj/2/obj2", &jo2)); + assert(doca_third_party_json_object_is_type(jo2, json_type_string)); + assert(0 == strcmp("1", doca_third_party_json_object_get_string(jo2))); - assert(0 == json_pointer_getf(jo1, &jo2, "/%s/%d/%s/%d/%s", "arr", 0, "obj", 2, "obj2")); - assert(json_object_is_type(jo2, json_type_string)); - assert(0 == strcmp("1", json_object_get_string(jo2))); + assert(0 == doca_third_party_json_pointer_getf(jo1, &jo2, "/%s/%d/%s/%d/%s", "arr", 0, "obj", 2, "obj2")); + assert(doca_third_party_json_object_is_type(jo2, json_type_string)); + assert(0 == strcmp("1", doca_third_party_json_object_get_string(jo2))); assert(jo1 != NULL); - assert(0 == json_pointer_get(jo1, "/obj/obj/obj/0/obj1", &jo2)); - assert(json_object_is_type(jo2, json_type_int)); - assert(0 == json_object_get_int(jo2)); + assert(0 == doca_third_party_json_pointer_get(jo1, "/obj/obj/obj/0/obj1", &jo2)); + assert(doca_third_party_json_object_is_type(jo2, json_type_int)); + assert(0 == doca_third_party_json_object_get_int(jo2)); - assert(0 == json_pointer_get(jo1, "/obj/obj/obj/0/obj2", &jo2)); - assert(json_object_is_type(jo2, json_type_string)); - assert(0 == strcmp("1", json_object_get_string(jo2))); + assert(0 == doca_third_party_json_pointer_get(jo1, "/obj/obj/obj/0/obj2", &jo2)); + assert(doca_third_party_json_object_is_type(jo2, json_type_string)); + assert(0 == strcmp("1", doca_third_party_json_object_get_string(jo2))); + + assert(0 == doca_third_party_json_pointer_getf(jo1, &jo2, "%s", "\0")); printf("PASSED - GET - RECURSION TEST\n"); - json_object_put(jo1); + doca_third_party_json_object_put(jo1); } -static void test_wrong_inputs_get() +static void test_wrong_inputs_get(void) { - struct json_object *jo2, *jo1 = json_tokener_parse(input_json_str); + struct json_object *jo2, *jo1 = doca_third_party_json_tokener_parse(input_json_str); assert(NULL != jo1); printf("PASSED - GET - LOADED TEST JSON\n"); - printf("%s\n", json_object_get_string(jo1)); + printf("%s\n", doca_third_party_json_object_get_string(jo1)); /* Test leading '/' missing */ jo2 = NULL; errno = 0; - assert(0 != json_pointer_get(jo1, "foo/bar", NULL)); - assert(0 != json_pointer_get(jo1, "foo/bar", &jo2)); + assert(0 != doca_third_party_json_pointer_get(jo1, "foo/bar", NULL)); + assert(0 != doca_third_party_json_pointer_get(jo1, "foo/bar", &jo2)); assert(errno == EINVAL); assert(jo2 == NULL); printf("PASSED - GET - MISSING /\n"); /* Test combinations of NULL params for input json & path */ errno = 0; - assert(0 != json_pointer_get(NULL, "foo/bar", NULL)); + assert(0 != doca_third_party_json_pointer_get(NULL, "foo/bar", NULL)); + assert(errno == EINVAL); + errno = 0; + assert(0 != doca_third_party_json_pointer_get(NULL, NULL, NULL)); + assert(errno == EINVAL); + errno = 0; + assert(0 != doca_third_party_json_pointer_getf(NULL, NULL, NULL)); assert(errno == EINVAL); errno = 0; - assert(0 != json_pointer_get(NULL, NULL, NULL)); + assert(0 != doca_third_party_json_pointer_get(jo1, NULL, NULL)); assert(errno == EINVAL); errno = 0; - assert(0 != json_pointer_get(jo1, NULL, NULL)); + assert(0 != doca_third_party_json_pointer_getf(jo1, NULL, NULL)); assert(errno == EINVAL); printf("PASSED - GET - NULL INPUTS\n"); /* Test invalid indexes for array */ errno = 0; - assert(0 != json_pointer_get(jo1, "/foo/a", NULL)); + assert(0 != doca_third_party_json_pointer_get(jo1, "/foo/a", NULL)); assert(errno == EINVAL); errno = 0; - assert(0 != json_pointer_getf(jo1, NULL, "/%s/a", "foo")); + assert(0 != doca_third_party_json_pointer_get(jo1, "/foo/01", NULL)); assert(errno == EINVAL); errno = 0; - assert(0 != json_pointer_get(jo1, "/foo/-", NULL)); + assert(0 != doca_third_party_json_pointer_getf(jo1, NULL, "/%s/a", "foo")); + assert(errno == EINVAL); + errno = 0; + assert(0 != doca_third_party_json_pointer_get(jo1, "/foo/-", NULL)); assert(errno == EINVAL); errno = 0; /* Test optimized array path */ - assert(0 != json_pointer_get(jo1, "/foo/4", NULL)); + assert(0 != doca_third_party_json_pointer_get(jo1, "/foo/4", NULL)); assert(errno == ENOENT); errno = 0; /* Test non-optimized array path */ - assert(0 != json_pointer_getf(jo1, NULL, "%s", "/foo/22")); + assert(0 != doca_third_party_json_pointer_getf(jo1, NULL, "%s", "/foo/22")); assert(errno == ENOENT); errno = 0; - assert(0 != json_pointer_getf(jo1, NULL, "/%s/%d", "foo", 22)); + assert(0 != doca_third_party_json_pointer_getf(jo1, NULL, "/%s/%d", "foo", 22)); assert(errno == ENOENT); errno = 0; - assert(0 != json_pointer_get(jo1, "/foo/-1", NULL)); + assert(0 != doca_third_party_json_pointer_get(jo1, "/foo/-1", NULL)); assert(errno == EINVAL); errno = 0; - assert(0 != json_pointer_get(jo1, "/foo/10", NULL)); + assert(0 != doca_third_party_json_pointer_get(jo1, "/foo/10", NULL)); assert(errno == ENOENT); printf("PASSED - GET - INVALID INDEXES\n"); - json_object_put(jo1); + doca_third_party_json_object_put(jo1); } -static void test_example_set() +static void test_example_set(void) { - struct json_object *jo2, *jo1 = json_tokener_parse(input_json_str); + struct json_object *jo2, *jo1 = doca_third_party_json_tokener_parse(input_json_str); assert(jo1 != NULL); printf("PASSED - SET - LOADED TEST JSON\n"); - printf("%s\n", json_object_get_string(jo1)); + printf("%s\n", doca_third_party_json_object_get_string(jo1)); - assert(0 == json_pointer_set(&jo1, "/foo/1", json_object_new_string("cod"))); - assert(0 == strcmp("cod", json_object_get_string(json_object_array_get_idx(json_object_object_get(jo1, "foo"), 1)))); + assert(0 == doca_third_party_json_pointer_set(&jo1, "/foo/1", doca_third_party_json_object_new_string("cod"))); + assert(0 == strcmp("cod", doca_third_party_json_object_get_string(doca_third_party_json_object_array_get_idx( + doca_third_party_json_object_object_get(jo1, "foo"), 1)))); printf("PASSED - SET - 'cod' in /foo/1\n"); - assert(0 != json_pointer_set(&jo1, "/fud/gaw", (jo2 = json_tokener_parse("[1,2,3]")))); + assert(0 != doca_third_party_json_pointer_set(&jo1, "/fud/gaw", (jo2 = doca_third_party_json_tokener_parse("[1,2,3]")))); assert(errno == ENOENT); printf("PASSED - SET - non-existing /fud/gaw\n"); - assert(0 == json_pointer_set(&jo1, "/fud", json_object_new_object())); + assert(0 == doca_third_party_json_pointer_set(&jo1, "/fud", doca_third_party_json_object_new_object())); printf("PASSED - SET - /fud == {}\n"); - assert(0 == json_pointer_set(&jo1, "/fud/gaw", jo2)); /* re-using jo2 from above */ + assert(0 == doca_third_party_json_pointer_set(&jo1, "/fud/gaw", jo2)); /* re-using jo2 from above */ printf("PASSED - SET - /fug/gaw == [1,2,3]\n"); - assert(0 == json_pointer_set(&jo1, "/fud/gaw/0", json_object_new_int(0))); - assert(0 == json_pointer_setf(&jo1, json_object_new_int(0), "%s%s/%d", "/fud", "/gaw", 0)); + assert(0 == doca_third_party_json_pointer_set(&jo1, "/fud/gaw/0", doca_third_party_json_object_new_int(0))); + assert(0 == doca_third_party_json_pointer_setf(&jo1, doca_third_party_json_object_new_int(0), "%s%s/%d", "/fud", "/gaw", 0)); printf("PASSED - SET - /fug/gaw == [0,2,3]\n"); - assert(0 == json_pointer_set(&jo1, "/fud/gaw/-", json_object_new_int(4))); + assert(0 == doca_third_party_json_pointer_set(&jo1, "/fud/gaw/-", doca_third_party_json_object_new_int(4))); printf("PASSED - SET - /fug/gaw == [0,2,3,4]\n"); - assert(0 == json_pointer_set(&jo1, "/", json_object_new_int(9))); + assert(0 == doca_third_party_json_pointer_set(&jo1, "/", doca_third_party_json_object_new_int(9))); printf("PASSED - SET - / == 9\n"); - jo2 = json_tokener_parse("{ 'foo': [ 'bar', 'cod' ], '': 9, 'a/b': 1, 'c\%d': 2, 'e^f': 3, 'g|h': 4, 'i\\\\j': 5, 'k\\\"l': 6, ' ': 7, 'm~n': 8, 'fud': { 'gaw': [ 0, 2, 3, 4 ] } }"); - assert(json_object_equal(jo2, jo1)); - printf("PASSED - SET - Final JSON is: %s\n", json_object_get_string(jo1)); - json_object_put(jo2); + jo2 = doca_third_party_json_tokener_parse( + "{ 'foo': [ 'bar', 'cod' ], '': 9, 'a/b': 1, 'c%d': 2, 'e^f': 3, 'g|h': 4, 'i\\\\j': " + "5, 'k\\\"l': 6, ' ': 7, 'm~n': 8, 'fud': { 'gaw': [ 0, 2, 3, 4 ] } }"); + assert(doca_third_party_json_object_equal(jo2, jo1)); + printf("PASSED - SET - Final JSON is: %s\n", doca_third_party_json_object_get_string(jo1)); + doca_third_party_json_object_put(jo2); + + assert(0 == doca_third_party_json_pointer_set(&jo1, "", doca_third_party_json_object_new_int(10))); + assert(10 == doca_third_party_json_object_get_int(jo1)); + printf("%s\n", doca_third_party_json_object_get_string(jo1)); + + doca_third_party_json_object_put(jo1); + + jo1 = doca_third_party_json_tokener_parse("[0, 1, 2, 3]"); + jo2 = doca_third_party_json_tokener_parse("[0, 1, 2, 3, null, null, null, 7]"); - assert(0 == json_pointer_set(&jo1, "", json_object_new_int(10))); - assert(10 == json_object_get_int(jo1)); - printf("%s\n", json_object_get_string(jo1)); + assert(0 == doca_third_party_json_pointer_set(&jo1, "/7", doca_third_party_json_object_new_int(7))); + assert(1 == doca_third_party_json_object_equal(jo1, jo2)); - json_object_put(jo1); + doca_third_party_json_object_put(jo1); + + jo1 = doca_third_party_json_tokener_parse("[0, 1, 2, 3]"); + + assert(0 == doca_third_party_json_pointer_setf(&jo1, doca_third_party_json_object_new_int(7), "/%u", 7)); + assert(1 == doca_third_party_json_object_equal(jo1, jo2)); + + doca_third_party_json_object_put(jo1); + doca_third_party_json_object_put(jo2); } -static void test_wrong_inputs_set() +static void test_wrong_inputs_set(void) { - struct json_object *jo2, *jo1 = json_tokener_parse(input_json_str); + struct json_object *jo2, *jo1 = doca_third_party_json_tokener_parse(input_json_str); assert(jo1 != NULL); printf("PASSED - SET - LOADED TEST JSON\n"); - printf("%s\n", json_object_get_string(jo1)); + printf("%s\n", doca_third_party_json_object_get_string(jo1)); - assert(0 != json_pointer_set(&jo1, "foo/bar", (jo2 = json_object_new_string("cod")))); + assert(0 != doca_third_party_json_pointer_set(NULL, NULL, NULL)); + assert(0 != doca_third_party_json_pointer_setf(NULL, NULL, NULL)); + assert(0 != doca_third_party_json_pointer_set(&jo1, NULL, NULL)); + assert(0 != doca_third_party_json_pointer_setf(&jo1, NULL, NULL)); + printf("PASSED - SET - failed with NULL params for input json & path\n"); + + assert(0 != doca_third_party_json_pointer_set(&jo1, "foo/bar", (jo2 = doca_third_party_json_object_new_string("cod")))); printf("PASSED - SET - failed 'cod' with path 'foo/bar'\n"); - json_object_put(jo2); + doca_third_party_json_object_put(jo2); - jo2 = json_object_new_string("whatever"); - assert(0 != json_pointer_set(&jo1, "/fud/gaw", jo2)); - assert(0 == json_pointer_set(&jo1, "/fud", json_object_new_object())); - assert(0 == json_pointer_set(&jo1, "/fud/gaw", jo2)); /* re-using jo2 from above */ + assert(0 != + doca_third_party_json_pointer_setf(&jo1, (jo2 = doca_third_party_json_object_new_string("cod")), "%s", "foo/bar")); + printf("PASSED - SET - failed 'cod' with path 'foo/bar'\n"); + doca_third_party_json_object_put(jo2); + + assert(0 != doca_third_party_json_pointer_set(&jo1, "0", (jo2 = doca_third_party_json_object_new_string("cod")))); + printf("PASSED - SET - failed with invalid array index'\n"); + doca_third_party_json_object_put(jo2); + + jo2 = doca_third_party_json_object_new_string("whatever"); + assert(0 != doca_third_party_json_pointer_set(&jo1, "/fud/gaw", jo2)); + assert(0 == doca_third_party_json_pointer_set(&jo1, "/fud", doca_third_party_json_object_new_object())); + assert(0 == doca_third_party_json_pointer_set(&jo1, "/fud/gaw", jo2)); /* re-using jo2 from above */ // ownership of jo2 transferred into jo1 - jo2 = json_object_new_int(0); - assert(0 != json_pointer_set(&jo1, "/fud/gaw/0", jo2)); - json_object_put(jo2); - jo2 = json_object_new_int(0); - assert(0 != json_pointer_set(&jo1, "/fud/gaw/", jo2)); - json_object_put(jo2); + jo2 = doca_third_party_json_object_new_int(0); + assert(0 != doca_third_party_json_pointer_set(&jo1, "/fud/gaw/0", jo2)); + doca_third_party_json_object_put(jo2); + jo2 = doca_third_party_json_object_new_int(0); + assert(0 != doca_third_party_json_pointer_set(&jo1, "/fud/gaw/", jo2)); + doca_third_party_json_object_put(jo2); printf("PASSED - SET - failed to set index to non-array\n"); - json_object_put(jo1); + assert(0 == doca_third_party_json_pointer_setf(&jo1, doca_third_party_json_object_new_string("cod"), "%s", "\0")); + + doca_third_party_json_object_put(jo1); } int main(int argc, char **argv) { - _json_c_strerror_enable = 1; - test_example_get(); test_recursion_get(); test_wrong_inputs_get(); diff --git a/third_party/json-c/tests/test_json_pointer.expected b/third_party/json-c/tests/test_json_pointer.expected index e77e542cc..7cb158edf 100644 --- a/third_party/json-c/tests/test_json_pointer.expected +++ b/third_party/json-c/tests/test_json_pointer.expected @@ -32,5 +32,8 @@ PASSED - SET - Final JSON is: { "foo": [ "bar", "cod" ], "": 9, "a\/b": 1, "c%d" 10 PASSED - SET - LOADED TEST JSON { "foo": [ "bar", "baz" ], "": 0, "a\/b": 1, "c%d": 2, "e^f": 3, "g|h": 4, "i\\j": 5, "k\"l": 6, " ": 7, "m~n": 8 } +PASSED - SET - failed with NULL params for input json & path PASSED - SET - failed 'cod' with path 'foo/bar' +PASSED - SET - failed 'cod' with path 'foo/bar' +PASSED - SET - failed with invalid array index' PASSED - SET - failed to set index to non-array diff --git a/third_party/json-c/tests/test_locale.c b/third_party/json-c/tests/test_locale.c index 7d6541ae9..5684b5883 100644 --- a/third_party/json-c/tests/test_locale.c +++ b/third_party/json-c/tests/test_locale.c @@ -1,8 +1,30 @@ +/* + * Original work: + * + * json-c (copyright was originally missing from this file) + * + * Modified Work: + * + * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. + * + * This software product is a proprietary product of NVIDIA CORPORATION & + * AFFILIATES (the "Company") and all right, title, and interest in and to the + * software product, including all associated intellectual property rights, are + * and shall remain exclusively with the Company. + * + * This software product is governed by the End User License Agreement + * provided with the software product. + * + */ + +#ifdef NDEBUG +#undef NDEBUG +#endif +#include +#include #include #include -#include #include -#include #include "config.h" #include "json.h" @@ -21,8 +43,6 @@ int main(int argc, char **argv) json_object *new_obj; #ifdef HAVE_SETLOCALE setlocale(LC_NUMERIC, "de_DE"); -#else - printf("No locale\n"); #endif char buf1[10], buf2[10]; @@ -33,12 +53,11 @@ int main(int argc, char **argv) MC_SET_DEBUG(1); - new_obj = json_tokener_parse("[1.2,3.4,123456.78,5.0,2.3e10]"); + new_obj = doca_third_party_json_tokener_parse("[1.2,3.4,123456.78,5.0,2.3e10]"); (void)snprintf(buf2, sizeof(buf2), "%f", 0.1); if (strcmp(buf1, buf2) != 0) - printf("ERROR: Original locale not restored \"%s\" != \"%s\"", - buf1, buf2); + printf("ERROR: Original locale not restored \"%s\" != \"%s\"", buf1, buf2); #ifdef HAVE_SETLOCALE setlocale(LC_NUMERIC, "C"); @@ -49,14 +68,16 @@ int main(int argc, char **argv) // string that was parsed. (see json_object_new_double_s()) printf("new_obj.to_string()=["); unsigned int ii; - for (ii = 0 ; ii < json_object_array_length(new_obj); ii++) + for (ii = 0; ii < doca_third_party_json_object_array_length(new_obj); ii++) { - json_object *val = json_object_array_get_idx(new_obj, ii); - printf("%s%.2lf", (ii > 0) ? "," : "", json_object_get_double(val)); + json_object *val = doca_third_party_json_object_array_get_idx(new_obj, ii); + printf("%s%.2lf", (ii > 0) ? "," : "", doca_third_party_json_object_get_double(val)); } printf("]\n"); - printf("new_obj.to_string()=%s\n", json_object_to_json_string_ext(new_obj,JSON_C_TO_STRING_NOZERO)); - json_object_put(new_obj); -} + printf("new_obj.to_string()=%s\n", + doca_third_party_json_object_to_json_string_ext(new_obj, JSON_C_TO_STRING_NOZERO)); + doca_third_party_json_object_put(new_obj); + return 0; +} diff --git a/third_party/json-c/tests/test_null.c b/third_party/json-c/tests/test_null.c index 6ef0a967e..f5793d718 100644 --- a/third_party/json-c/tests/test_null.c +++ b/third_party/json-c/tests/test_null.c @@ -1,10 +1,32 @@ +/* + * Original work: + * + * json-c (copyright was originally missing from this file) + * + * Modified Work: + * + * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. + * + * This software product is a proprietary product of NVIDIA CORPORATION & + * AFFILIATES (the "Company") and all right, title, and interest in and to the + * software product, including all associated intellectual property rights, are + * and shall remain exclusively with the Company. + * + * This software product is governed by the End User License Agreement + * provided with the software product. + * + */ + /* * Tests if binary strings are supported. */ +#ifdef NDEBUG +#undef NDEBUG +#endif +#include "config.h" #include #include -#include "config.h" #include "json_inttypes.h" #include "json_object.h" @@ -15,39 +37,41 @@ int main(void) /* this test has a space after the null character. check that it's still included */ const char *input = " \0 "; const char *expected = "\" \\u0000 \""; - struct json_object *string = json_object_new_string_len(input, 3); - const char *json = json_object_to_json_string(string); + struct json_object *string = doca_third_party_json_object_new_string_len(input, 3); + const char *json = doca_third_party_json_object_to_json_string(string); - int strings_match = !strcmp( expected, json); + int strings_match = !strcmp(expected, json); int retval = 0; if (strings_match) { printf("JSON write result is correct: %s\n", json); puts("PASS"); - } else { + } + else + { puts("JSON write result doesn't match expected string"); printf("expected string: "); puts(expected); printf("parsed string: "); puts(json); puts("FAIL"); - retval=1; + retval = 1; } - json_object_put(string); + doca_third_party_json_object_put(string); - struct json_object *parsed_str = json_tokener_parse(expected); + struct json_object *parsed_str = doca_third_party_json_tokener_parse(expected); if (parsed_str) { - int parsed_len = json_object_get_string_len(parsed_str); - const char *parsed_cstr = json_object_get_string(parsed_str); + int parsed_len = doca_third_party_json_object_get_string_len(parsed_str); + const char *parsed_cstr = doca_third_party_json_object_get_string(parsed_str); int ii; printf("Re-parsed object string len=%d, chars=[", parsed_len); - for (ii = 0; ii < parsed_len ; ii++) + for (ii = 0; ii < parsed_len; ii++) { printf("%s%d", (ii ? ", " : ""), (int)parsed_cstr[ii]); } puts("]"); - json_object_put(parsed_str); + doca_third_party_json_object_put(parsed_str); } else { diff --git a/third_party/json-c/tests/test_object_iterator.c b/third_party/json-c/tests/test_object_iterator.c new file mode 100644 index 000000000..39a23b434 --- /dev/null +++ b/third_party/json-c/tests/test_object_iterator.c @@ -0,0 +1,63 @@ +/* + * Original work: + * + * json-c (copyright was originally missing from this file) + * + * Modified Work: + * + * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. + * + * This software product is a proprietary product of NVIDIA CORPORATION & + * AFFILIATES (the "Company") and all right, title, and interest in and to the + * software product, including all associated intellectual property rights, are + * and shall remain exclusively with the Company. + * + * This software product is governed by the End User License Agreement + * provided with the software product. + * + */ + +#ifdef NDEBUG +#undef NDEBUG +#endif +#include "config.h" +#include +#include +#include + +#include "json_object.h" +#include "json_object_iterator.h" +#include "json_tokener.h" + +int main(int atgc, char **argv) +{ + const char *input = "{\n\ + \"string_of_digits\": \"123\",\n\ + \"regular_number\": 222,\n\ + \"decimal_number\": 99.55,\n\ + \"boolean_true\": true,\n\ + \"boolean_false\": false,\n\ + \"big_number\": 2147483649,\n\ + \"a_null\": null,\n\ + }"; + + struct json_object *new_obj; + struct json_object_iterator it; + struct json_object_iterator itEnd; + + it = doca_third_party_json_object_iter_init_default(); + new_obj = doca_third_party_json_tokener_parse(input); + it = doca_third_party_json_object_iter_begin(new_obj); + itEnd = doca_third_party_json_object_iter_end(new_obj); + + while (!doca_third_party_json_object_iter_equal(&it, &itEnd)) + { + printf("%s\n", doca_third_party_json_object_iter_peek_name(&it)); + printf("%s\n", doca_third_party_json_object_to_json_string(doca_third_party_json_object_iter_peek_value(&it))); + doca_third_party_json_object_iter_next(&it); + } + + doca_third_party_json_object_put(new_obj); + + return 0; +} diff --git a/third_party/json-c/tests/test_object_iterator.expected b/third_party/json-c/tests/test_object_iterator.expected new file mode 100644 index 000000000..e56e288b0 --- /dev/null +++ b/third_party/json-c/tests/test_object_iterator.expected @@ -0,0 +1,14 @@ +string_of_digits +"123" +regular_number +222 +decimal_number +99.55 +boolean_true +true +boolean_false +false +big_number +2147483649 +a_null +null diff --git a/third_party/json-c/tests/test_object_iterator.test b/third_party/json-c/tests/test_object_iterator.test new file mode 120000 index 000000000..58a13f4f3 --- /dev/null +++ b/third_party/json-c/tests/test_object_iterator.test @@ -0,0 +1 @@ +test_basic.test \ No newline at end of file diff --git a/third_party/json-c/tests/test_parse.c b/third_party/json-c/tests/test_parse.c index ee1f8387b..f56dcd01a 100644 --- a/third_party/json-c/tests/test_parse.c +++ b/third_party/json-c/tests/test_parse.c @@ -1,14 +1,37 @@ +/* + * Original work: + * + * json-c (copyright was originally missing from this file) + * + * Modified Work: + * + * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. + * + * This software product is a proprietary product of NVIDIA CORPORATION & + * AFFILIATES (the "Company") and all right, title, and interest in and to the + * software product, including all associated intellectual property rights, are + * and shall remain exclusively with the Company. + * + * This software product is governed by the End User License Agreement + * provided with the software product. + * + */ + +#ifdef NDEBUG +#undef NDEBUG +#endif +#include +#include #include #include -#include #include -#include #include "json.h" #include "json_tokener.h" #include "json_visit.h" static void test_basic_parse(void); +static void test_utf8_parse(void); static void test_verbose_parse(void); static void test_incremental_parse(void); @@ -19,32 +42,94 @@ int main(void) static const char separator[] = "=================================="; test_basic_parse(); puts(separator); + test_utf8_parse(); + puts(separator); test_verbose_parse(); puts(separator); test_incremental_parse(); puts(separator); + + return 0; } static json_c_visit_userfunc clear_serializer; static void do_clear_serializer(json_object *jso); +static void single_incremental_parse(const char *test_string, int clear_serializer) +{ + size_t ii; + int chunksize = atoi(getenv("TEST_PARSE_CHUNKSIZE")); + struct json_tokener *tok; + enum json_tokener_error jerr; + json_object *all_at_once_obj, *new_obj; + const char *all_at_once_str, *new_str; + + new_obj = NULL; + assert(chunksize > 0); + all_at_once_obj = doca_third_party_json_tokener_parse(test_string); + if (clear_serializer) + do_clear_serializer(all_at_once_obj); + all_at_once_str = doca_third_party_json_object_to_json_string(all_at_once_obj); + + tok = doca_third_party_json_tokener_new(); + size_t test_string_len = strlen(test_string) + 1; // Including '\0' ! + for (ii = 0; ii < test_string_len; ii += chunksize) + { + int len_to_parse = chunksize; + if (ii + chunksize > test_string_len) + len_to_parse = test_string_len - ii; + + if (getenv("TEST_PARSE_DEBUG") != NULL) + printf(" chunk: %.*s\n", len_to_parse, &test_string[ii]); + new_obj = doca_third_party_json_tokener_parse_ex(tok, &test_string[ii], len_to_parse); + jerr = doca_third_party_json_tokener_get_error(tok); + if (jerr != json_tokener_continue || new_obj) + break; + } + if (clear_serializer && new_obj) + do_clear_serializer(new_obj); + new_str = doca_third_party_json_object_to_json_string(new_obj); + + if (strcmp(all_at_once_str, new_str) != 0) + { + printf("ERROR: failed to parse (%s) in %d byte chunks: %s != %s\n", test_string, + chunksize, all_at_once_str, new_str); + } + doca_third_party_json_tokener_free(tok); + if (all_at_once_obj) + doca_third_party_json_object_put(all_at_once_obj); + if (new_obj) + doca_third_party_json_object_put(new_obj); +} + static void single_basic_parse(const char *test_string, int clear_serializer) { json_object *new_obj; - new_obj = json_tokener_parse(test_string); + new_obj = doca_third_party_json_tokener_parse(test_string); if (clear_serializer) do_clear_serializer(new_obj); - printf("new_obj.to_string(%s)=%s\n", test_string, json_object_to_json_string(new_obj)); - json_object_put(new_obj); + printf("new_obj.to_string(%s)=%s\n", test_string, doca_third_party_json_object_to_json_string(new_obj)); + doca_third_party_json_object_put(new_obj); + + if (getenv("TEST_PARSE_CHUNKSIZE") != NULL) + single_incremental_parse(test_string, clear_serializer); } -static void test_basic_parse() +static void test_basic_parse(void) { single_basic_parse("\"\003\"", 0); single_basic_parse("/* hello */\"foo\"", 0); single_basic_parse("// hello\n\"foo\"", 0); single_basic_parse("\"foo\"blue", 0); + single_basic_parse("\'foo\'", 0); single_basic_parse("\"\\u0041\\u0042\\u0043\"", 0); + single_basic_parse("\"\\u4e16\\u754c\\u00df\"", 0); + single_basic_parse("\"\\u4E16\"", 0); + single_basic_parse("\"\\u4e1\"", 0); + single_basic_parse("\"\\u4e1@\"", 0); + single_basic_parse("\"\\ud840\\u4e16\"", 0); + single_basic_parse("\"\\ud840\"", 0); + single_basic_parse("\"\\udd27\"", 0); // Test with a "short" high surrogate single_basic_parse("[9,'\\uDAD", 0); single_basic_parse("null", 0); @@ -72,21 +157,31 @@ static void test_basic_parse() single_basic_parse("True", 0); single_basic_parse("False", 0); + /* not case sensitive */ + single_basic_parse("tRue", 0); + single_basic_parse("fAlse", 0); + single_basic_parse("nAn", 0); + single_basic_parse("iNfinity", 0); + single_basic_parse("12", 0); single_basic_parse("12.3", 0); - single_basic_parse("12.3.4", 0); /* non-sensical, returns null */ - /* was returning (int)2015 before patch, should return null */ - single_basic_parse("2015-01-15", 0); - /* ...but this works. It's rather inconsistent, and a future major release - * should change the behavior so it either always returns null when extra - * bytes are present (preferred), or always return object created from as much - * as was able to be parsed. + /* Even though, when using json_tokener_parse() there's no way to + * know when there is more data after the parsed object, + * an object is successfully returned anyway (in some cases) */ + + single_basic_parse("12.3.4", 0); + single_basic_parse("2015-01-15", 0); single_basic_parse("12.3xxx", 0); + single_basic_parse("12.3{\"a\":123}", 0); + single_basic_parse("12.3\n", 0); + single_basic_parse("12.3 ", 0); single_basic_parse("{\"FoO\" : -12.3E512}", 0); - single_basic_parse("{\"FoO\" : -12.3E51.2}", 0); /* non-sensical, returns null */ + single_basic_parse("{\"FoO\" : -12.3e512}", 0); + single_basic_parse("{\"FoO\" : -12.3E51.2}", 0); /* non-sensical, returns null */ + single_basic_parse("{\"FoO\" : -12.3E512E12}", 0); /* non-sensical, returns null */ single_basic_parse("[\"\\n\"]", 0); single_basic_parse("[\"\\nabc\\n\"]", 0); single_basic_parse("[null]", 0); @@ -95,204 +190,434 @@ static void test_basic_parse() single_basic_parse("[\"abc\",null,\"def\",12]", 0); single_basic_parse("{}", 0); single_basic_parse("{ \"foo\": \"bar\" }", 0); + single_basic_parse("{ \'foo\': \'bar\' }", 0); single_basic_parse("{ \"foo\": \"bar\", \"baz\": null, \"bool0\": true }", 0); single_basic_parse("{ \"foo\": [null, \"foo\"] }", 0); - single_basic_parse("{ \"abc\": 12, \"foo\": \"bar\", \"bool0\": false, \"bool1\": true, \"arr\": [ 1, 2, 3, null, 5 ] }", 0); + single_basic_parse("{ \"abc\": 12, \"foo\": \"bar\", \"bool0\": false, \"bool1\": true, " + "\"arr\": [ 1, 2, 3, null, 5 ] }", + 0); single_basic_parse("{ \"abc\": \"blue\nred\\ngreen\" }", 0); // Clear serializer for these tests so we see the actual parsed value. + single_basic_parse("null", 1); + single_basic_parse("false", 1); single_basic_parse("[0e]", 1); single_basic_parse("[0e+]", 1); single_basic_parse("[0e+-1]", 1); + single_basic_parse("\"hello world!\"", 1); + + // uint64/int64 range test + single_basic_parse("[9223372036854775806]", 1); + single_basic_parse("[9223372036854775807]", 1); + single_basic_parse("[9223372036854775808]", 1); + single_basic_parse("[-9223372036854775807]", 1); + single_basic_parse("[-9223372036854775808]", 1); + single_basic_parse("[-9223372036854775809]", 1); + single_basic_parse("[18446744073709551614]", 1); + single_basic_parse("[18446744073709551615]", 1); single_basic_parse("[18446744073709551616]", 1); } +static void test_utf8_parse(void) +{ + // json_tokener_parse doesn't support checking for byte order marks. + // It's the responsibility of the caller to detect and skip a BOM. + // Both of these checks return null. + const char *utf8_bom = "\xEF\xBB\xBF"; + const char *utf8_bom_and_chars = "\xEF\xBB\xBF{}"; + single_basic_parse(utf8_bom, 0); + single_basic_parse(utf8_bom_and_chars, 0); +} + // Clear the re-serialization information that the tokener // saves to ensure that the output reflects the actual // values we parsed, rather than just the original input. static void do_clear_serializer(json_object *jso) { - json_c_visit(jso, 0, clear_serializer, NULL); + doca_third_party_json_c_visit(jso, 0, clear_serializer, NULL); } -static int clear_serializer(json_object *jso, int flags, - json_object *parent_jso, - const char *jso_key, - size_t *jso_index, void *userarg) +static int clear_serializer(json_object *jso, int flags, json_object *parent_jso, + const char *jso_key, size_t *jso_index, void *userarg) { if (jso) - json_object_set_serializer(jso, NULL, NULL, NULL); + doca_third_party_json_object_set_serializer(jso, NULL, NULL, NULL); return JSON_C_VISIT_RETURN_CONTINUE; } -static void test_verbose_parse() +static void test_verbose_parse(void) { json_object *new_obj; enum json_tokener_error error = json_tokener_success; - new_obj = json_tokener_parse_verbose("{ foo }", &error); - assert (error == json_tokener_error_parse_object_key_name); - assert (new_obj == NULL); + new_obj = doca_third_party_json_tokener_parse_verbose("{ foo }", &error); + assert(error == json_tokener_error_parse_object_key_name); + assert(new_obj == NULL); - new_obj = json_tokener_parse("{ foo }"); - assert (new_obj == NULL); + new_obj = doca_third_party_json_tokener_parse("{ foo }"); + assert(new_obj == NULL); - new_obj = json_tokener_parse("foo"); - assert (new_obj == NULL); - new_obj = json_tokener_parse_verbose("foo", &error); - assert (new_obj == NULL); + new_obj = doca_third_party_json_tokener_parse("foo"); + assert(new_obj == NULL); + new_obj = doca_third_party_json_tokener_parse_verbose("foo", &error); + assert(new_obj == NULL); /* b/c the string starts with 'f' parsing return a boolean error */ - assert (error == json_tokener_error_parse_boolean); + assert(error == json_tokener_error_parse_boolean); - puts("json_tokener_parse_versbose() OK"); + puts("json_tokener_parse_verbose() OK"); } -struct incremental_step { +struct incremental_step +{ const char *string_to_parse; int length; int char_offset; enum json_tokener_error expected_error; - int reset_tokener; + int reset_tokener; /* Set to 1 to call json_tokener_reset() after parsing */ + int tok_flags; /* JSON_TOKENER_* flags to pass to json_tokener_set_flags() */ } incremental_steps[] = { - /* Check that full json messages can be parsed, both w/ and w/o a reset */ - { "{ \"foo\": 123 }", -1, -1, json_tokener_success, 0 }, - { "{ \"foo\": 456 }", -1, -1, json_tokener_success, 1 }, - { "{ \"foo\": 789 }", -1, -1, json_tokener_success, 1 }, - - /* Check a basic incremental parse */ - { "{ \"foo", -1, -1, json_tokener_continue, 0 }, - { "\": {\"bar", -1, -1, json_tokener_continue, 0 }, - { "\":13}}", -1, -1, json_tokener_success, 1 }, - - /* Check that json_tokener_reset actually resets */ - { "{ \"foo", -1, -1, json_tokener_continue, 1 }, - { ": \"bar\"}", -1, 0, json_tokener_error_parse_unexpected, 1 }, - - /* Check incremental parsing with trailing characters */ - { "{ \"foo", -1, -1, json_tokener_continue, 0 }, - { "\": {\"bar", -1, -1, json_tokener_continue, 0 }, - { "\":13}}XXXX", 10, 6, json_tokener_success, 0 }, - { "XXXX", 4, 0, json_tokener_error_parse_unexpected, 1 }, - - /* Check that trailing characters can change w/o a reset */ - { "{\"x\": 123 }\"X\"", -1, 11, json_tokener_success, 0 }, - { "\"Y\"", -1, -1, json_tokener_success, 1 }, - - /* To stop parsing a number we need to reach a non-digit, e.g. a \0 */ - { "1", 1, 1, json_tokener_continue, 0 }, - /* This should parse as the number 12, since it continues the "1" */ - { "2", 2, 1, json_tokener_success, 0 }, - { "12{", 3, 2, json_tokener_success, 1 }, - - /* Similar tests for other kinds of objects: */ - /* These could all return success immediately, since regardless of + /* Check that full json messages can be parsed, both w/ and w/o a reset */ + {"{ \"foo\": 123 }", -1, -1, json_tokener_success, 0, 0}, + {"{ \"foo\": 456 }", -1, -1, json_tokener_success, 1, 0}, + {"{ \"foo\": 789 }", -1, -1, json_tokener_success, 1, 0}, + + /* Check the comment parse*/ + {"/* hello */{ \"foo\"", -1, -1, json_tokener_continue, 0, 0}, + {"/* hello */:/* hello */", -1, -1, json_tokener_continue, 0, 0}, + {"\"bar\"/* hello */", -1, -1, json_tokener_continue, 0, 0}, + {"}/* hello */", -1, -1, json_tokener_success, 1, 0}, + {"/ hello ", -1, 1, json_tokener_error_parse_comment, 1, 0}, + {"/* hello\"foo\"", -1, -1, json_tokener_continue, 1, 0}, + {"/* hello*\"foo\"", -1, -1, json_tokener_continue, 1, 0}, + {"// hello\"foo\"", -1, -1, json_tokener_continue, 1, 0}, + + /* Check a basic incremental parse */ + {"{ \"foo", -1, -1, json_tokener_continue, 0, 0}, + {"\": {\"bar", -1, -1, json_tokener_continue, 0, 0}, + {"\":13}}", -1, -1, json_tokener_success, 1, 0}, + + /* Check the UTF-16 surrogate pair handling in various ways. + * Note: \ud843\udd1e is u+1D11E, Musical Symbol G Clef + * Your terminal may not display these correctly, in particular + * PuTTY doesn't currently show this character. + */ + /* parse one char at every time */ + {"\"\\", -1, -1, json_tokener_continue, 0, 0}, + {"u", -1, -1, json_tokener_continue, 0, 0}, + {"d", -1, -1, json_tokener_continue, 0, 0}, + {"8", -1, -1, json_tokener_continue, 0, 0}, + {"3", -1, -1, json_tokener_continue, 0, 0}, + {"4", -1, -1, json_tokener_continue, 0, 0}, + {"\\", -1, -1, json_tokener_continue, 0, 0}, + {"u", -1, -1, json_tokener_continue, 0, 0}, + {"d", -1, -1, json_tokener_continue, 0, 0}, + {"d", -1, -1, json_tokener_continue, 0, 0}, + {"1", -1, -1, json_tokener_continue, 0, 0}, + {"e\"", -1, -1, json_tokener_success, 1, 0}, + /* parse two char at every time */ + {"\"\\u", -1, -1, json_tokener_continue, 0, 0}, + {"d8", -1, -1, json_tokener_continue, 0, 0}, + {"34", -1, -1, json_tokener_continue, 0, 0}, + {"\\u", -1, -1, json_tokener_continue, 0, 0}, + {"dd", -1, -1, json_tokener_continue, 0, 0}, + {"1e\"", -1, -1, json_tokener_success, 1, 0}, + /* check the low surrogate pair */ + {"\"\\ud834", -1, -1, json_tokener_continue, 0, 0}, + {"\\udd1e\"", -1, -1, json_tokener_success, 1, 0}, + {"\"\\ud834\\", -1, -1, json_tokener_continue, 0, 0}, + {"udd1e\"", -1, -1, json_tokener_success, 1, 0}, + {"\"\\ud834\\u", -1, -1, json_tokener_continue, 0, 0}, + {"dd1e\"", -1, -1, json_tokener_success, 1, 0}, + {"\"fff \\ud834\\ud", -1, -1, json_tokener_continue, 0, 0}, + {"d1e bar\"", -1, -1, json_tokener_success, 1, 0}, + {"\"fff \\ud834\\udd", -1, -1, json_tokener_continue, 0, 0}, + {"1e bar\"", -1, -1, json_tokener_success, 1, 0}, + + /* \ud83d\ude00 is U+1F600, Grinning Face + * Displays fine in PuTTY, though you may need "less -r" + */ + {"\"fff \\ud83d\\ude", -1, -1, json_tokener_continue, 0, 0}, + {"00 bar\"", -1, -1, json_tokener_success, 1, 0}, + + /* Check that json_tokener_reset actually resets */ + {"{ \"foo", -1, -1, json_tokener_continue, 1, 0}, + {": \"bar\"}", -1, 0, json_tokener_error_parse_unexpected, 1, 0}, + + /* Check incremental parsing with trailing characters */ + {"{ \"foo", -1, -1, json_tokener_continue, 0, 0}, + {"\": {\"bar", -1, -1, json_tokener_continue, 0, 0}, + {"\":13}}XXXX", 10, 6, json_tokener_success, 0, 0}, + {"XXXX", 4, 0, json_tokener_error_parse_unexpected, 1, 0}, + + /* Check that trailing characters can change w/o a reset */ + {"{\"x\": 123 }\"X\"", -1, 11, json_tokener_success, 0, 0}, + {"\"Y\"", -1, -1, json_tokener_success, 1, 0}, + + /* Trailing characters should cause a failure in strict mode */ + {"{\"foo\":9}{\"bar\":8}", -1, 9, json_tokener_error_parse_unexpected, 1, JSON_TOKENER_STRICT}, + + /* ... unless explicitly allowed. */ + {"{\"foo\":9}{\"bar\":8}", -1, 9, json_tokener_success, 0, + JSON_TOKENER_STRICT | JSON_TOKENER_ALLOW_TRAILING_CHARS}, + {"{\"b\":8}ignored garbage", -1, 7, json_tokener_success, 1, + JSON_TOKENER_STRICT | JSON_TOKENER_ALLOW_TRAILING_CHARS}, + + /* To stop parsing a number we need to reach a non-digit, e.g. a \0 */ + {"1", 1, 1, json_tokener_continue, 0, 0}, + /* This should parse as the number 12, since it continues the "1" */ + {"2", 2, 1, json_tokener_success, 0, 0}, + {"12{", 3, 2, json_tokener_success, 1, 0}, + /* Parse number in strict mode */ + {"[02]", -1, 3, json_tokener_error_parse_number, 1, JSON_TOKENER_STRICT}, + + {"0e+0", 5, 4, json_tokener_success, 1, 0}, + {"[0e+0]", -1, -1, json_tokener_success, 1, 0}, + + /* The behavior when missing the exponent varies slightly */ + {"0e", 2, 2, json_tokener_continue, 1, 0}, + {"0e", 3, 2, json_tokener_success, 1, 0}, + {"0e", 3, 2, json_tokener_error_parse_eof, 1, JSON_TOKENER_STRICT}, + {"[0e]", -1, -1, json_tokener_success, 1, 0}, + {"[0e]", -1, 3, json_tokener_error_parse_number, 1, JSON_TOKENER_STRICT}, + + {"0e+", 3, 3, json_tokener_continue, 1, 0}, + {"0e+", 4, 3, json_tokener_success, 1, 0}, + {"0e+", 4, 3, json_tokener_error_parse_eof, 1, JSON_TOKENER_STRICT}, + {"[0e+]", -1, -1, json_tokener_success, 1, 0}, + {"[0e+]", -1, 4, json_tokener_error_parse_number, 1, JSON_TOKENER_STRICT}, + + {"0e-", 3, 3, json_tokener_continue, 1, 0}, + {"0e-", 4, 3, json_tokener_success, 1, 0}, + {"0e-", 4, 3, json_tokener_error_parse_eof, 1, JSON_TOKENER_STRICT}, + {"[0e-]", -1, -1, json_tokener_success, 1, 0}, + {"[0e-]", -1, 4, json_tokener_error_parse_number, 1, JSON_TOKENER_STRICT}, + + /* You might expect this to fail, but it won't because + it's a valid partial parse; note the char_offset: */ + {"0e+-", 5, 3, json_tokener_success, 1, 0}, + {"0e+-", 5, 3, json_tokener_error_parse_number, 1, JSON_TOKENER_STRICT}, + {"[0e+-]", -1, 4, json_tokener_error_parse_number, 1, 0}, + + /* Similar tests for other kinds of objects: */ + /* These could all return success immediately, since regardless of what follows the false/true/null token we *will* return a json object, but it currently doesn't work that way. hmm... */ - { "false", 5, 5, json_tokener_continue, 1 }, - { "false", 6, 5, json_tokener_success, 1 }, - { "true", 4, 4, json_tokener_continue, 1 }, - { "true", 5, 4, json_tokener_success, 1 }, - { "null", 4, 4, json_tokener_continue, 1 }, - { "null", 5, 4, json_tokener_success, 1 }, - - { "Infinity", 9, 8, json_tokener_success, 1 }, - { "infinity", 9, 8, json_tokener_success, 1 }, - { "-infinity", 10, 9, json_tokener_success, 1 }, - { "infinity", 9, 0, json_tokener_error_parse_unexpected, 3 }, - { "-infinity", 10, 1, json_tokener_error_parse_unexpected, 3 }, - - { "inf", 3, 3, json_tokener_continue, 0 }, - { "inity", 6, 5, json_tokener_success, 1 }, - { "-inf", 4, 4, json_tokener_continue, 0 }, - { "inity", 6, 5, json_tokener_success, 1 }, - - { "i", 1, 1, json_tokener_continue, 0 }, - { "n", 1, 1, json_tokener_continue, 0 }, - { "f", 1, 1, json_tokener_continue, 0 }, - { "i", 1, 1, json_tokener_continue, 0 }, - { "n", 1, 1, json_tokener_continue, 0 }, - { "i", 1, 1, json_tokener_continue, 0 }, - { "t", 1, 1, json_tokener_continue, 0 }, - { "y", 1, 1, json_tokener_continue, 0 }, - { "", 1, 0, json_tokener_success, 1 }, - - { "-", 1, 1, json_tokener_continue, 0 }, - { "inf", 3, 3, json_tokener_continue, 0 }, - { "ini", 3, 3, json_tokener_continue, 0 }, - { "ty", 3, 2, json_tokener_success, 1 }, - - { "-", 1, 1, json_tokener_continue, 0 }, - { "i", 1, 1, json_tokener_continue, 0 }, - { "nfini", 5, 5, json_tokener_continue, 0 }, - { "ty", 3, 2, json_tokener_success, 1 }, - - { "-i", 2, 2, json_tokener_continue, 0 }, - { "nfinity", 8, 7, json_tokener_success, 1 }, - - { "InfinityX", 10, 8, json_tokener_success, 0 }, - { "X", 1, 0, json_tokener_error_parse_unexpected, 1 }, - - { "Infinity1234", 13, 8, json_tokener_success, 0 }, - { "1234", 5, 4, json_tokener_success, 1 }, - - { "Infinity9999", 8, 8, json_tokener_continue, 0 }, - /* returns the Infinity loaded up by the previous call: */ - { "1234", 5, 0, json_tokener_success, 0 }, - { "1234", 5, 4, json_tokener_success, 1 }, - - /* offset=1 because "n" is the start of "null". hmm... */ - { "noodle", 7, 1, json_tokener_error_parse_null, 1 }, - /* offset=2 because "na" is the start of "nan". hmm... */ - { "naodle", 7, 2, json_tokener_error_parse_null, 1 }, - /* offset=2 because "tr" is the start of "true". hmm... */ - { "track", 6, 2, json_tokener_error_parse_boolean, 1 }, - - /* Although they may initially look like they should fail, - the next few tests check that parsing multiple sequential - json objects in the input works as expected */ - { "null123", 9, 4, json_tokener_success, 0 }, - { "null123" + 4, 4, 3, json_tokener_success, 1 }, - { "nullx", 5, 4, json_tokener_success, 0 }, - { "nullx" + 4, 2, 0, json_tokener_error_parse_unexpected, 1 }, - { "{\"a\":1}{\"b\":2}",15, 7, json_tokener_success, 0 }, - { "{\"a\":1}{\"b\":2}" + 7, - 8, 7, json_tokener_success, 1 }, - - /* Some bad formatting. Check we get the correct error status */ - { "2015-01-15", 10, 4, json_tokener_error_parse_number, 1 }, - - /* Strings have a well defined end point, so we can stop at the quote */ - { "\"blue\"", -1, -1, json_tokener_success, 0 }, - - /* Check each of the escape sequences defined by the spec */ - { "\"\\\"\"", -1, -1, json_tokener_success, 0 }, - { "\"\\\\\"", -1, -1, json_tokener_success, 0 }, - { "\"\\b\"", -1, -1, json_tokener_success, 0 }, - { "\"\\f\"", -1, -1, json_tokener_success, 0 }, - { "\"\\n\"", -1, -1, json_tokener_success, 0 }, - { "\"\\r\"", -1, -1, json_tokener_success, 0 }, - { "\"\\t\"", -1, -1, json_tokener_success, 0 }, - { "\"\\/\"", -1, -1, json_tokener_success, 0 }, - // Escaping a forward slash is optional - { "\"/\"", -1, -1, json_tokener_success, 0 }, - - { "[1,2,3]", -1, -1, json_tokener_success, 0 }, - - /* This behaviour doesn't entirely follow the json spec, but until we have - a way to specify how strict to be we follow Postel's Law and be liberal - in what we accept (up to a point). */ - { "[1,2,3,]", -1, -1, json_tokener_success, 0 }, - { "[1,2,,3,]", -1, 5, json_tokener_error_parse_unexpected, 0 }, - - { "[1,2,3,]", -1, 7, json_tokener_error_parse_unexpected, 3 }, - { "{\"a\":1,}", -1, 7, json_tokener_error_parse_unexpected, 3 }, - - { NULL, -1, -1, json_tokener_success, 0 }, + {"false", 5, 5, json_tokener_continue, 1, 0}, + {"false", 6, 5, json_tokener_success, 1, 0}, + {"true", 4, 4, json_tokener_continue, 1, 0}, + {"true", 5, 4, json_tokener_success, 1, 0}, + {"null", 4, 4, json_tokener_continue, 1, 0}, + {"null", 5, 4, json_tokener_success, 1, 0}, + + {"Infinity", 9, 8, json_tokener_success, 1, 0}, + {"infinity", 9, 8, json_tokener_success, 1, 0}, + {"-infinity", 10, 9, json_tokener_success, 1, 0}, + {"infinity", 9, 0, json_tokener_error_parse_unexpected, 1, JSON_TOKENER_STRICT}, + {"-infinity", 10, 1, json_tokener_error_parse_unexpected, 1, JSON_TOKENER_STRICT}, + + {"inf", 3, 3, json_tokener_continue, 0, 0}, + {"inity", 6, 5, json_tokener_success, 1, 0}, + {"-inf", 4, 4, json_tokener_continue, 0, 0}, + {"inity", 6, 5, json_tokener_success, 1, 0}, + + {"i", 1, 1, json_tokener_continue, 0, 0}, + {"n", 1, 1, json_tokener_continue, 0, 0}, + {"f", 1, 1, json_tokener_continue, 0, 0}, + {"i", 1, 1, json_tokener_continue, 0, 0}, + {"n", 1, 1, json_tokener_continue, 0, 0}, + {"i", 1, 1, json_tokener_continue, 0, 0}, + {"t", 1, 1, json_tokener_continue, 0, 0}, + {"y", 1, 1, json_tokener_continue, 0, 0}, + {"", 1, 0, json_tokener_success, 1, 0}, + + {"-", 1, 1, json_tokener_continue, 0, 0}, + {"inf", 3, 3, json_tokener_continue, 0, 0}, + {"ini", 3, 3, json_tokener_continue, 0, 0}, + {"ty", 3, 2, json_tokener_success, 1, 0}, + + {"-", 1, 1, json_tokener_continue, 0, 0}, + {"i", 1, 1, json_tokener_continue, 0, 0}, + {"nfini", 5, 5, json_tokener_continue, 0, 0}, + {"ty", 3, 2, json_tokener_success, 1, 0}, + + {"-i", 2, 2, json_tokener_continue, 0, 0}, + {"nfinity", 8, 7, json_tokener_success, 1, 0}, + + {"InfinityX", 10, 8, json_tokener_success, 0, 0}, + {"X", 1, 0, json_tokener_error_parse_unexpected, 1, 0}, + + {"Infinity1234", 13, 8, json_tokener_success, 0, 0}, + {"1234", 5, 4, json_tokener_success, 1, 0}, + + {"Infinity9999", 8, 8, json_tokener_continue, 0, 0}, + + /* returns the Infinity loaded up by the previous call: */ + {"1234", 5, 0, json_tokener_success, 0, 0}, + {"1234", 5, 4, json_tokener_success, 1, 0}, + + /* INT64_MAX */ + {"[9223372036854775807]", 22, 21, json_tokener_success, 1, 0}, + /* INT64_MAX+1 => parsed as uint64 */ + {"[9223372036854775808]", 22, 21, json_tokener_success, 1, 0}, + + /* INT64_MIN */ + {"[-9223372036854775808]", 23, 22, json_tokener_success, 1, 0}, + + /* INT64_MIN-1 => success, but value ends up capped */ + {"[-9223372036854775809]", 23, 22, json_tokener_success, 1, 0}, + + /* INT64_MIN-1 => failure due to underflow detected */ + {"[-9223372036854775809]", 23, 21, json_tokener_error_parse_number, 1, JSON_TOKENER_STRICT}, + + /* UINT64_MAX */ + {"[18446744073709551615]", 23, 22, json_tokener_success, 1, 0}, + + /* UINT64_MAX+1 => success, but value ends up capped */ + {"[18446744073709551616]", 23, 22, json_tokener_success, 1, 0}, + + /* UINT64_MAX+1 => failure due to overflow detected */ + {"[18446744073709551616]", 23, 21, json_tokener_error_parse_number, 1, JSON_TOKENER_STRICT}, + + /* XXX this seems like a bug, should fail with _error_parse_number instead */ + {"18446744073709551616", 21, 20, json_tokener_error_parse_eof, 1, JSON_TOKENER_STRICT}, + + /* Exceeding integer limits as double parse OK */ + {"[9223372036854775808.0]", 24, 23, json_tokener_success, 1, 0}, + {"[-9223372036854775809.0]", 25, 24, json_tokener_success, 1, JSON_TOKENER_STRICT}, + {"[18446744073709551615.0]", 25, 24, json_tokener_success, 1, 0}, + {"[18446744073709551616.0]", 25, 24, json_tokener_success, 1, JSON_TOKENER_STRICT}, + + /* offset=1 because "n" is the start of "null". hmm... */ + {"noodle", 7, 1, json_tokener_error_parse_null, 1, 0}, + /* offset=2 because "na" is the start of "nan". hmm... */ + {"naodle", 7, 2, json_tokener_error_parse_null, 1, 0}, + /* offset=2 because "tr" is the start of "true". hmm... */ + {"track", 6, 2, json_tokener_error_parse_boolean, 1, 0}, + {"fail", 5, 2, json_tokener_error_parse_boolean, 1, 0}, + + /* Although they may initially look like they should fail, + * the next few tests check that parsing multiple sequential + * json objects in the input works as expected + */ + {"null123", 8, 4, json_tokener_success, 0, 0}, + {&"null123"[4], 4, 3, json_tokener_success, 1, 0}, + {"nullx", 6, 4, json_tokener_success, 0, 0}, + {&"nullx"[4], 2, 0, json_tokener_error_parse_unexpected, 1, 0}, + {"{\"a\":1}{\"b\":2}", 15, 7, json_tokener_success, 0, 0}, + {&"{\"a\":1}{\"b\":2}"[7], 8, 7, json_tokener_success, 1, 0}, + + /* + * Though this may seem invalid at first glance, it + * parses as three separate numbers, 2015, -1 and -15 + * Of course, simply pasting together a stream of arbitrary + * positive numbers won't work, since there'll be no way to + * tell where in e.g. "2015015" the next number stats, so + * a reliably parsable stream must not include json_type_int + * or json_type_double objects without some other delimiter. + * e.g. whitespace + */ + {&"2015-01-15"[0], 11, 4, json_tokener_success, 1, 0}, + {&"2015-01-15"[4], 7, 3, json_tokener_success, 1, 0}, + {&"2015-01-15"[7], 4, 3, json_tokener_success, 1, 0}, + {&"2015 01 15"[0], 11, 5, json_tokener_success, 1, 0}, + {&"2015 01 15"[4], 7, 4, json_tokener_success, 1, 0}, + {&"2015 01 15"[7], 4, 3, json_tokener_success, 1, 0}, + + /* Strings have a well defined end point, so we can stop at the quote */ + {"\"blue\"", -1, -1, json_tokener_success, 0, 0}, + + /* Check each of the escape sequences defined by the spec */ + {"\"\\\"\"", -1, -1, json_tokener_success, 0, 0}, + {"\"\\\\\"", -1, -1, json_tokener_success, 0, 0}, + {"\"\\b\"", -1, -1, json_tokener_success, 0, 0}, + {"\"\\f\"", -1, -1, json_tokener_success, 0, 0}, + {"\"\\n\"", -1, -1, json_tokener_success, 0, 0}, + {"\"\\r\"", -1, -1, json_tokener_success, 0, 0}, + {"\"\\t\"", -1, -1, json_tokener_success, 0, 0}, + {"\"\\/\"", -1, -1, json_tokener_success, 0, 0}, + // Escaping a forward slash is optional + {"\"/\"", -1, -1, json_tokener_success, 0, 0}, + /* Check wrong escape sequences */ + {"\"\\a\"", -1, 2, json_tokener_error_parse_string, 1, 0}, + + /* Check '\'' in strict model */ + {"\'foo\'", -1, 0, json_tokener_error_parse_unexpected, 1, JSON_TOKENER_STRICT}, + + /* Parse array/object */ + {"[1,2,3]", -1, -1, json_tokener_success, 0, 0}, + {"[1,2,3}", -1, 6, json_tokener_error_parse_array, 1, 0}, + {"{\"a\"}", -1, 4, json_tokener_error_parse_object_key_sep, 1, 0}, + {"{\"a\":1]", -1, 6, json_tokener_error_parse_object_value_sep, 1, 0}, + {"{\"a\"::1}", -1, 5, json_tokener_error_parse_unexpected, 1, 0}, + {"{\"a\":}", -1, 5, json_tokener_error_parse_unexpected, 1, 0}, + {"{\"a\":1,\"a\":2}", -1, -1, json_tokener_success, 1, 0}, + {"\"a\":1}", -1, 3, json_tokener_success, 1, 0}, + {"{\"a\":1", -1, -1, json_tokener_continue, 1, 0}, + {"[,]", -1, 1, json_tokener_error_parse_unexpected, 1, 0}, + {"[,1]", -1, 1, json_tokener_error_parse_unexpected, 1, 0}, + + /* This behaviour doesn't entirely follow the json spec, but until we have + * a way to specify how strict to be we follow Postel's Law and be liberal + * in what we accept (up to a point). + */ + {"[1,2,3,]", -1, -1, json_tokener_success, 0, 0}, + {"[1,2,,3,]", -1, 5, json_tokener_error_parse_unexpected, 0, 0}, + + {"[1,2,3,]", -1, 7, json_tokener_error_parse_unexpected, 1, JSON_TOKENER_STRICT}, + {"{\"a\":1,}", -1, 7, json_tokener_error_parse_unexpected, 1, JSON_TOKENER_STRICT}, + + // utf-8 test + // acsll encoding + {"\x22\x31\x32\x33\x61\x73\x63\x24\x25\x26\x22", -1, -1, json_tokener_success, 1, + JSON_TOKENER_VALIDATE_UTF8}, + {"\x22\x31\x32\x33\x61\x73\x63\x24\x25\x26\x22", -1, -1, json_tokener_success, 1, 0}, + // utf-8 encoding + {"\x22\xe4\xb8\x96\xe7\x95\x8c\x22", -1, -1, json_tokener_success, 1, + JSON_TOKENER_VALIDATE_UTF8}, + {"\x22\xe4\xb8", -1, 3, json_tokener_error_parse_utf8_string, 0, JSON_TOKENER_VALIDATE_UTF8}, + {"\x96\xe7\x95\x8c\x22", -1, 0, json_tokener_error_parse_utf8_string, 1, + JSON_TOKENER_VALIDATE_UTF8}, + {"\x22\xe4\xb8\x96\xe7\x95\x8c\x22", -1, -1, json_tokener_success, 1, 0}, + {"\x22\xcf\x80\xcf\x86\x22", -1, -1, json_tokener_success, 1, JSON_TOKENER_VALIDATE_UTF8}, + {"\x22\xf0\xa5\x91\x95\x22", -1, -1, json_tokener_success, 1, JSON_TOKENER_VALIDATE_UTF8}, + // wrong utf-8 encoding + {"\x22\xe6\x9d\x4e\x22", -1, 3, json_tokener_error_parse_utf8_string, 1, + JSON_TOKENER_VALIDATE_UTF8}, + {"\x22\xe6\x9d\x4e\x22", -1, 5, json_tokener_success, 1, 0}, + // GBK encoding + {"\x22\xc0\xee\xc5\xf4\x22", -1, 2, json_tokener_error_parse_utf8_string, 1, + JSON_TOKENER_VALIDATE_UTF8}, + {"\x22\xc0\xee\xc5\xf4\x22", -1, 6, json_tokener_success, 1, 0}, + // char after space + {"\x20\x20\x22\xe4\xb8\x96\x22", -1, -1, json_tokener_success, 1, JSON_TOKENER_VALIDATE_UTF8}, + {"\x20\x20\x81\x22\xe4\xb8\x96\x22", -1, 2, json_tokener_error_parse_utf8_string, 1, + JSON_TOKENER_VALIDATE_UTF8}, + {"\x5b\x20\x81\x31\x5d", -1, 2, json_tokener_error_parse_utf8_string, 1, + JSON_TOKENER_VALIDATE_UTF8}, + // char in state inf + {"\x49\x6e\x66\x69\x6e\x69\x74\x79", 9, 8, json_tokener_success, 1, 0}, + {"\x49\x6e\x66\x81\x6e\x69\x74\x79", -1, 3, json_tokener_error_parse_utf8_string, 1, + JSON_TOKENER_VALIDATE_UTF8}, + // char in escape unicode + {"\x22\x5c\x75\x64\x38\x35\x35\x5c\x75\x64\x63\x35\x35\x22", 15, 14, json_tokener_success, 1, + JSON_TOKENER_VALIDATE_UTF8}, + {"\x22\x5c\x75\x64\x38\x35\x35\xc0\x75\x64\x63\x35\x35\x22", -1, 8, + json_tokener_error_parse_utf8_string, 1, JSON_TOKENER_VALIDATE_UTF8}, + {"\x22\x5c\x75\x64\x30\x30\x33\x31\xc0\x22", -1, 9, json_tokener_error_parse_utf8_string, 1, + JSON_TOKENER_VALIDATE_UTF8}, + // char in number + {"\x31\x31\x81\x31\x31", -1, 2, json_tokener_error_parse_utf8_string, 1, + JSON_TOKENER_VALIDATE_UTF8}, + // char in object + {"\x7b\x22\x31\x81\x22\x3a\x31\x7d", -1, 3, json_tokener_error_parse_utf8_string, 1, + JSON_TOKENER_VALIDATE_UTF8}, + + {NULL, -1, -1, json_tokener_success, 0, 0}, }; -static void test_incremental_parse() +static void test_incremental_parse(void) { json_object *new_obj; enum json_tokener_error jerr; @@ -310,77 +635,74 @@ static void test_incremental_parse() string_to_parse = "{ \"foo"; /* } */ printf("json_tokener_parse(%s) ... ", string_to_parse); - new_obj = json_tokener_parse(string_to_parse); - if (new_obj == NULL) puts("got error as expected"); + new_obj = doca_third_party_json_tokener_parse(string_to_parse); + if (new_obj == NULL) + puts("got error as expected"); /* test incremental parsing in various forms */ - tok = json_tokener_new(); + tok = doca_third_party_json_tokener_new(); for (ii = 0; incremental_steps[ii].string_to_parse != NULL; ii++) { int this_step_ok = 0; struct incremental_step *step = &incremental_steps[ii]; int length = step->length; - int expected_char_offset = step->char_offset; + size_t expected_char_offset; - if (step->reset_tokener & 2) - json_tokener_set_flags(tok, JSON_TOKENER_STRICT); - else - json_tokener_set_flags(tok, 0); + doca_third_party_json_tokener_set_flags(tok, step->tok_flags); if (length == -1) - length = strlen(step->string_to_parse); - if (expected_char_offset == -1) + length = (int)strlen(step->string_to_parse); + if (step->char_offset == -1) expected_char_offset = length; + else + expected_char_offset = step->char_offset; - printf("json_tokener_parse_ex(tok, %-12s, %3d) ... ", - step->string_to_parse, length); - new_obj = json_tokener_parse_ex(tok, step->string_to_parse, length); + printf("json_tokener_parse_ex(tok, %-12s, %3d) ... ", step->string_to_parse, + length); + new_obj = doca_third_party_json_tokener_parse_ex(tok, step->string_to_parse, length); - jerr = json_tokener_get_error(tok); + jerr = doca_third_party_json_tokener_get_error(tok); if (step->expected_error != json_tokener_success) { if (new_obj != NULL) printf("ERROR: invalid object returned: %s\n", - json_object_to_json_string(new_obj)); + doca_third_party_json_object_to_json_string(new_obj)); else if (jerr != step->expected_error) printf("ERROR: got wrong error: %s\n", - json_tokener_error_desc(jerr)); - else if (tok->char_offset != expected_char_offset) - printf("ERROR: wrong char_offset %d != expected %d\n", - tok->char_offset, - expected_char_offset); + doca_third_party_json_tokener_error_desc(jerr)); + else if (doca_third_party_json_tokener_get_parse_end(tok) != expected_char_offset) + printf("ERROR: wrong char_offset %zu != expected %zu\n", + doca_third_party_json_tokener_get_parse_end(tok), expected_char_offset); else { printf("OK: got correct error: %s\n", - json_tokener_error_desc(jerr)); + doca_third_party_json_tokener_error_desc(jerr)); this_step_ok = 1; } } else { if (new_obj == NULL && - !(step->length >= 4 && - strncmp(step->string_to_parse, "null", 4) == 0)) + !(step->length >= 4 && strncmp(step->string_to_parse, "null", 4) == 0)) printf("ERROR: expected valid object, instead: %s\n", - json_tokener_error_desc(jerr)); - else if (tok->char_offset != expected_char_offset) - printf("ERROR: wrong char_offset %d != expected %d\n", - tok->char_offset, - expected_char_offset); + doca_third_party_json_tokener_error_desc(jerr)); + else if (doca_third_party_json_tokener_get_parse_end(tok) != expected_char_offset) + printf("ERROR: wrong char_offset %zu != expected %zu\n", + doca_third_party_json_tokener_get_parse_end(tok), expected_char_offset); else { printf("OK: got object of type [%s]: %s\n", - json_type_to_name(json_object_get_type(new_obj)), - json_object_to_json_string(new_obj)); + doca_third_party_json_type_to_name(doca_third_party_json_object_get_type(new_obj)), + doca_third_party_json_object_to_json_string(new_obj)); this_step_ok = 1; } } if (new_obj) - json_object_put(new_obj); + doca_third_party_json_object_put(new_obj); if (step->reset_tokener & 1) - json_tokener_reset(tok); + doca_third_party_json_tokener_reset(tok); if (this_step_ok) num_ok++; @@ -388,7 +710,7 @@ static void test_incremental_parse() num_error++; } - json_tokener_free(tok); + doca_third_party_json_tokener_free(tok); printf("End Incremental Tests OK=%d ERROR=%d\n", num_ok, num_error); } diff --git a/third_party/json-c/tests/test_parse.expected b/third_party/json-c/tests/test_parse.expected index ada61411f..50fb6d8c5 100644 --- a/third_party/json-c/tests/test_parse.expected +++ b/third_party/json-c/tests/test_parse.expected @@ -3,7 +3,15 @@ new_obj.to_string(/* hello */"foo")="foo" new_obj.to_string(// hello "foo")="foo" new_obj.to_string("foo"blue)="foo" +new_obj.to_string('foo')="foo" new_obj.to_string("\u0041\u0042\u0043")="ABC" +new_obj.to_string("\u4e16\u754c\u00df")="世界ß" +new_obj.to_string("\u4E16")="世" +new_obj.to_string("\u4e1")=null +new_obj.to_string("\u4e1@")=null +new_obj.to_string("\ud840\u4e16")="�世" +new_obj.to_string("\ud840")="�" +new_obj.to_string("\udd27")="�" new_obj.to_string([9,'\uDAD)=null new_obj.to_string(null)=null new_obj.to_string(NaN)=NaN @@ -26,13 +34,23 @@ new_obj.to_string(-Infinoodle)=null new_obj.to_string(-InfinAAA)=null new_obj.to_string(True)=true new_obj.to_string(False)=false +new_obj.to_string(tRue)=true +new_obj.to_string(fAlse)=false +new_obj.to_string(nAn)=NaN +new_obj.to_string(iNfinity)=Infinity new_obj.to_string(12)=12 new_obj.to_string(12.3)=12.3 -new_obj.to_string(12.3.4)=null -new_obj.to_string(2015-01-15)=null +new_obj.to_string(12.3.4)=12.3 +new_obj.to_string(2015-01-15)=2015 new_obj.to_string(12.3xxx)=12.3 +new_obj.to_string(12.3{"a":123})=12.3 +new_obj.to_string(12.3 +)=12.3 +new_obj.to_string(12.3 )=12.3 new_obj.to_string({"FoO" : -12.3E512})={ "FoO": -12.3E512 } +new_obj.to_string({"FoO" : -12.3e512})={ "FoO": -12.3e512 } new_obj.to_string({"FoO" : -12.3E51.2})=null +new_obj.to_string({"FoO" : -12.3E512E12})=null new_obj.to_string(["\n"])=[ "\n" ] new_obj.to_string(["\nabc\n"])=[ "\nabc\n" ] new_obj.to_string([null])=[ null ] @@ -41,17 +59,32 @@ new_obj.to_string([false])=[ false ] new_obj.to_string(["abc",null,"def",12])=[ "abc", null, "def", 12 ] new_obj.to_string({})={ } new_obj.to_string({ "foo": "bar" })={ "foo": "bar" } +new_obj.to_string({ 'foo': 'bar' })={ "foo": "bar" } new_obj.to_string({ "foo": "bar", "baz": null, "bool0": true })={ "foo": "bar", "baz": null, "bool0": true } new_obj.to_string({ "foo": [null, "foo"] })={ "foo": [ null, "foo" ] } new_obj.to_string({ "abc": 12, "foo": "bar", "bool0": false, "bool1": true, "arr": [ 1, 2, 3, null, 5 ] })={ "abc": 12, "foo": "bar", "bool0": false, "bool1": true, "arr": [ 1, 2, 3, null, 5 ] } new_obj.to_string({ "abc": "blue red\ngreen" })={ "abc": "blue\nred\ngreen" } +new_obj.to_string(null)=null +new_obj.to_string(false)=false new_obj.to_string([0e])=[ 0.0 ] new_obj.to_string([0e+])=[ 0.0 ] new_obj.to_string([0e+-1])=null -new_obj.to_string([18446744073709551616])=[ 9223372036854775807 ] +new_obj.to_string("hello world!")="hello world!" +new_obj.to_string([9223372036854775806])=[ 9223372036854775806 ] +new_obj.to_string([9223372036854775807])=[ 9223372036854775807 ] +new_obj.to_string([9223372036854775808])=[ 9223372036854775808 ] +new_obj.to_string([-9223372036854775807])=[ -9223372036854775807 ] +new_obj.to_string([-9223372036854775808])=[ -9223372036854775808 ] +new_obj.to_string([-9223372036854775809])=[ -9223372036854775808 ] +new_obj.to_string([18446744073709551614])=[ 18446744073709551614 ] +new_obj.to_string([18446744073709551615])=[ 18446744073709551615 ] +new_obj.to_string([18446744073709551616])=[ 18446744073709551615 ] +================================== +new_obj.to_string()=null +new_obj.to_string({})=null ================================== -json_tokener_parse_versbose() OK +json_tokener_parse_verbose() OK ================================== Starting incremental tests. Note: quotes and backslashes seen in the output here are literal values passed @@ -60,9 +93,47 @@ json_tokener_parse({ "foo) ... got error as expected json_tokener_parse_ex(tok, { "foo": 123 }, 14) ... OK: got object of type [object]: { "foo": 123 } json_tokener_parse_ex(tok, { "foo": 456 }, 14) ... OK: got object of type [object]: { "foo": 456 } json_tokener_parse_ex(tok, { "foo": 789 }, 14) ... OK: got object of type [object]: { "foo": 789 } +json_tokener_parse_ex(tok, /* hello */{ "foo", 18) ... OK: got correct error: continue +json_tokener_parse_ex(tok, /* hello */:/* hello */, 23) ... OK: got correct error: continue +json_tokener_parse_ex(tok, "bar"/* hello */, 16) ... OK: got correct error: continue +json_tokener_parse_ex(tok, }/* hello */, 12) ... OK: got object of type [object]: { "foo": "bar" } +json_tokener_parse_ex(tok, / hello , 8) ... OK: got correct error: expected comment +json_tokener_parse_ex(tok, /* hello"foo", 13) ... OK: got correct error: continue +json_tokener_parse_ex(tok, /* hello*"foo", 14) ... OK: got correct error: continue +json_tokener_parse_ex(tok, // hello"foo", 13) ... OK: got correct error: continue json_tokener_parse_ex(tok, { "foo , 6) ... OK: got correct error: continue json_tokener_parse_ex(tok, ": {"bar , 8) ... OK: got correct error: continue json_tokener_parse_ex(tok, ":13}} , 6) ... OK: got object of type [object]: { "foo": { "bar": 13 } } +json_tokener_parse_ex(tok, "\ , 2) ... OK: got correct error: continue +json_tokener_parse_ex(tok, u , 1) ... OK: got correct error: continue +json_tokener_parse_ex(tok, d , 1) ... OK: got correct error: continue +json_tokener_parse_ex(tok, 8 , 1) ... OK: got correct error: continue +json_tokener_parse_ex(tok, 3 , 1) ... OK: got correct error: continue +json_tokener_parse_ex(tok, 4 , 1) ... OK: got correct error: continue +json_tokener_parse_ex(tok, \ , 1) ... OK: got correct error: continue +json_tokener_parse_ex(tok, u , 1) ... OK: got correct error: continue +json_tokener_parse_ex(tok, d , 1) ... OK: got correct error: continue +json_tokener_parse_ex(tok, d , 1) ... OK: got correct error: continue +json_tokener_parse_ex(tok, 1 , 1) ... OK: got correct error: continue +json_tokener_parse_ex(tok, e" , 2) ... OK: got object of type [string]: "𝄞" +json_tokener_parse_ex(tok, "\u , 3) ... OK: got correct error: continue +json_tokener_parse_ex(tok, d8 , 2) ... OK: got correct error: continue +json_tokener_parse_ex(tok, 34 , 2) ... OK: got correct error: continue +json_tokener_parse_ex(tok, \u , 2) ... OK: got correct error: continue +json_tokener_parse_ex(tok, dd , 2) ... OK: got correct error: continue +json_tokener_parse_ex(tok, 1e" , 3) ... OK: got object of type [string]: "𝄞" +json_tokener_parse_ex(tok, "\ud834 , 7) ... OK: got correct error: continue +json_tokener_parse_ex(tok, \udd1e" , 7) ... OK: got object of type [string]: "𝄞" +json_tokener_parse_ex(tok, "\ud834\ , 8) ... OK: got correct error: continue +json_tokener_parse_ex(tok, udd1e" , 6) ... OK: got object of type [string]: "𝄞" +json_tokener_parse_ex(tok, "\ud834\u , 9) ... OK: got correct error: continue +json_tokener_parse_ex(tok, dd1e" , 5) ... OK: got object of type [string]: "𝄞" +json_tokener_parse_ex(tok, "fff \ud834\ud, 14) ... OK: got correct error: continue +json_tokener_parse_ex(tok, d1e bar" , 8) ... OK: got object of type [string]: "fff 𝄞 bar" +json_tokener_parse_ex(tok, "fff \ud834\udd, 15) ... OK: got correct error: continue +json_tokener_parse_ex(tok, 1e bar" , 7) ... OK: got object of type [string]: "fff 𝄞 bar" +json_tokener_parse_ex(tok, "fff \ud83d\ude, 15) ... OK: got correct error: continue +json_tokener_parse_ex(tok, 00 bar" , 7) ... OK: got object of type [string]: "fff 😀 bar" json_tokener_parse_ex(tok, { "foo , 6) ... OK: got correct error: continue json_tokener_parse_ex(tok, : "bar"} , 8) ... OK: got correct error: unexpected character json_tokener_parse_ex(tok, { "foo , 6) ... OK: got correct error: continue @@ -71,9 +142,33 @@ json_tokener_parse_ex(tok, ":13}}XXXX , 10) ... OK: got object of type [object json_tokener_parse_ex(tok, XXXX , 4) ... OK: got correct error: unexpected character json_tokener_parse_ex(tok, {"x": 123 }"X", 14) ... OK: got object of type [object]: { "x": 123 } json_tokener_parse_ex(tok, "Y" , 3) ... OK: got object of type [string]: "Y" +json_tokener_parse_ex(tok, {"foo":9}{"bar":8}, 18) ... OK: got correct error: unexpected character +json_tokener_parse_ex(tok, {"foo":9}{"bar":8}, 18) ... OK: got object of type [object]: { "foo": 9 } +json_tokener_parse_ex(tok, {"b":8}ignored garbage, 22) ... OK: got object of type [object]: { "b": 8 } json_tokener_parse_ex(tok, 1 , 1) ... OK: got correct error: continue json_tokener_parse_ex(tok, 2 , 2) ... OK: got object of type [int]: 12 json_tokener_parse_ex(tok, 12{ , 3) ... OK: got object of type [int]: 12 +json_tokener_parse_ex(tok, [02] , 4) ... OK: got correct error: number expected +json_tokener_parse_ex(tok, 0e+0 , 5) ... OK: got object of type [double]: 0e+0 +json_tokener_parse_ex(tok, [0e+0] , 6) ... OK: got object of type [array]: [ 0e+0 ] +json_tokener_parse_ex(tok, 0e , 2) ... OK: got correct error: continue +json_tokener_parse_ex(tok, 0e , 3) ... OK: got object of type [double]: 0 +json_tokener_parse_ex(tok, 0e , 3) ... OK: got correct error: unexpected end of data +json_tokener_parse_ex(tok, [0e] , 4) ... OK: got object of type [array]: [ 0 ] +json_tokener_parse_ex(tok, [0e] , 4) ... OK: got correct error: number expected +json_tokener_parse_ex(tok, 0e+ , 3) ... OK: got correct error: continue +json_tokener_parse_ex(tok, 0e+ , 4) ... OK: got object of type [double]: 0 +json_tokener_parse_ex(tok, 0e+ , 4) ... OK: got correct error: unexpected end of data +json_tokener_parse_ex(tok, [0e+] , 5) ... OK: got object of type [array]: [ 0 ] +json_tokener_parse_ex(tok, [0e+] , 5) ... OK: got correct error: number expected +json_tokener_parse_ex(tok, 0e- , 3) ... OK: got correct error: continue +json_tokener_parse_ex(tok, 0e- , 4) ... OK: got object of type [double]: 0 +json_tokener_parse_ex(tok, 0e- , 4) ... OK: got correct error: unexpected end of data +json_tokener_parse_ex(tok, [0e-] , 5) ... OK: got object of type [array]: [ 0 ] +json_tokener_parse_ex(tok, [0e-] , 5) ... OK: got correct error: number expected +json_tokener_parse_ex(tok, 0e+- , 5) ... OK: got object of type [double]: 0 +json_tokener_parse_ex(tok, 0e+- , 5) ... OK: got correct error: number expected +json_tokener_parse_ex(tok, [0e+-] , 6) ... OK: got correct error: number expected json_tokener_parse_ex(tok, false , 5) ... OK: got correct error: continue json_tokener_parse_ex(tok, false , 6) ... OK: got object of type [boolean]: false json_tokener_parse_ex(tok, true , 4) ... OK: got correct error: continue @@ -115,16 +210,35 @@ json_tokener_parse_ex(tok, 1234 , 5) ... OK: got object of type [int]: json_tokener_parse_ex(tok, Infinity9999, 8) ... OK: got correct error: continue json_tokener_parse_ex(tok, 1234 , 5) ... OK: got object of type [double]: Infinity json_tokener_parse_ex(tok, 1234 , 5) ... OK: got object of type [int]: 1234 +json_tokener_parse_ex(tok, [9223372036854775807], 22) ... OK: got object of type [array]: [ 9223372036854775807 ] +json_tokener_parse_ex(tok, [9223372036854775808], 22) ... OK: got object of type [array]: [ 9223372036854775808 ] +json_tokener_parse_ex(tok, [-9223372036854775808], 23) ... OK: got object of type [array]: [ -9223372036854775808 ] +json_tokener_parse_ex(tok, [-9223372036854775809], 23) ... OK: got object of type [array]: [ -9223372036854775808 ] +json_tokener_parse_ex(tok, [-9223372036854775809], 23) ... OK: got correct error: number expected +json_tokener_parse_ex(tok, [18446744073709551615], 23) ... OK: got object of type [array]: [ 18446744073709551615 ] +json_tokener_parse_ex(tok, [18446744073709551616], 23) ... OK: got object of type [array]: [ 18446744073709551615 ] +json_tokener_parse_ex(tok, [18446744073709551616], 23) ... OK: got correct error: number expected +json_tokener_parse_ex(tok, 18446744073709551616, 21) ... OK: got correct error: unexpected end of data +json_tokener_parse_ex(tok, [9223372036854775808.0], 24) ... OK: got object of type [array]: [ 9223372036854775808.0 ] +json_tokener_parse_ex(tok, [-9223372036854775809.0], 25) ... OK: got object of type [array]: [ -9223372036854775809.0 ] +json_tokener_parse_ex(tok, [18446744073709551615.0], 25) ... OK: got object of type [array]: [ 18446744073709551615.0 ] +json_tokener_parse_ex(tok, [18446744073709551616.0], 25) ... OK: got object of type [array]: [ 18446744073709551616.0 ] json_tokener_parse_ex(tok, noodle , 7) ... OK: got correct error: null expected json_tokener_parse_ex(tok, naodle , 7) ... OK: got correct error: null expected json_tokener_parse_ex(tok, track , 6) ... OK: got correct error: boolean expected -json_tokener_parse_ex(tok, null123 , 9) ... OK: got object of type [null]: null +json_tokener_parse_ex(tok, fail , 5) ... OK: got correct error: boolean expected +json_tokener_parse_ex(tok, null123 , 8) ... OK: got object of type [null]: null json_tokener_parse_ex(tok, 123 , 4) ... OK: got object of type [int]: 123 -json_tokener_parse_ex(tok, nullx , 5) ... OK: got object of type [null]: null +json_tokener_parse_ex(tok, nullx , 6) ... OK: got object of type [null]: null json_tokener_parse_ex(tok, x , 2) ... OK: got correct error: unexpected character json_tokener_parse_ex(tok, {"a":1}{"b":2}, 15) ... OK: got object of type [object]: { "a": 1 } json_tokener_parse_ex(tok, {"b":2} , 8) ... OK: got object of type [object]: { "b": 2 } -json_tokener_parse_ex(tok, 2015-01-15 , 10) ... OK: got correct error: number expected +json_tokener_parse_ex(tok, 2015-01-15 , 11) ... OK: got object of type [int]: 2015 +json_tokener_parse_ex(tok, -01-15 , 7) ... OK: got object of type [int]: -1 +json_tokener_parse_ex(tok, -15 , 4) ... OK: got object of type [int]: -15 +json_tokener_parse_ex(tok, 2015 01 15 , 11) ... OK: got object of type [int]: 2015 +json_tokener_parse_ex(tok, 01 15 , 7) ... OK: got object of type [int]: 1 +json_tokener_parse_ex(tok, 15 , 4) ... OK: got object of type [int]: 15 json_tokener_parse_ex(tok, "blue" , 6) ... OK: got object of type [string]: "blue" json_tokener_parse_ex(tok, "\"" , 4) ... OK: got object of type [string]: "\"" json_tokener_parse_ex(tok, "\\" , 4) ... OK: got object of type [string]: "\\" @@ -135,10 +249,44 @@ json_tokener_parse_ex(tok, "\r" , 4) ... OK: got object of type [string json_tokener_parse_ex(tok, "\t" , 4) ... OK: got object of type [string]: "\t" json_tokener_parse_ex(tok, "\/" , 4) ... OK: got object of type [string]: "\/" json_tokener_parse_ex(tok, "/" , 3) ... OK: got object of type [string]: "\/" +json_tokener_parse_ex(tok, "\a" , 4) ... OK: got correct error: invalid string sequence +json_tokener_parse_ex(tok, 'foo' , 5) ... OK: got correct error: unexpected character json_tokener_parse_ex(tok, [1,2,3] , 7) ... OK: got object of type [array]: [ 1, 2, 3 ] +json_tokener_parse_ex(tok, [1,2,3} , 7) ... OK: got correct error: array value separator ',' expected +json_tokener_parse_ex(tok, {"a"} , 5) ... OK: got correct error: object property name separator ':' expected +json_tokener_parse_ex(tok, {"a":1] , 7) ... OK: got correct error: object value separator ',' expected +json_tokener_parse_ex(tok, {"a"::1} , 8) ... OK: got correct error: unexpected character +json_tokener_parse_ex(tok, {"a":} , 6) ... OK: got correct error: unexpected character +json_tokener_parse_ex(tok, {"a":1,"a":2}, 13) ... OK: got object of type [object]: { "a": 2 } +json_tokener_parse_ex(tok, "a":1} , 6) ... OK: got object of type [string]: "a" +json_tokener_parse_ex(tok, {"a":1 , 6) ... OK: got correct error: continue +json_tokener_parse_ex(tok, [,] , 3) ... OK: got correct error: unexpected character +json_tokener_parse_ex(tok, [,1] , 4) ... OK: got correct error: unexpected character json_tokener_parse_ex(tok, [1,2,3,] , 8) ... OK: got object of type [array]: [ 1, 2, 3 ] json_tokener_parse_ex(tok, [1,2,,3,] , 9) ... OK: got correct error: unexpected character json_tokener_parse_ex(tok, [1,2,3,] , 8) ... OK: got correct error: unexpected character json_tokener_parse_ex(tok, {"a":1,} , 8) ... OK: got correct error: unexpected character -End Incremental Tests OK=83 ERROR=0 +json_tokener_parse_ex(tok, "123asc$%&" , 11) ... OK: got object of type [string]: "123asc$%&" +json_tokener_parse_ex(tok, "123asc$%&" , 11) ... OK: got object of type [string]: "123asc$%&" +json_tokener_parse_ex(tok, "世界" , 8) ... OK: got object of type [string]: "世界" +json_tokener_parse_ex(tok, " , 3) ... OK: got correct error: invalid utf-8 string +json_tokener_parse_ex(tok, 界" , 5) ... OK: got correct error: invalid utf-8 string +json_tokener_parse_ex(tok, "世界" , 8) ... OK: got object of type [string]: "世界" +json_tokener_parse_ex(tok, "πφ" , 6) ... OK: got object of type [string]: "πφ" +json_tokener_parse_ex(tok, "𥑕" , 6) ... OK: got object of type [string]: "𥑕" +json_tokener_parse_ex(tok, "N" , 5) ... OK: got correct error: invalid utf-8 string +json_tokener_parse_ex(tok, "N" , 5) ... OK: got object of type [string]: "N" +json_tokener_parse_ex(tok, "" , 6) ... OK: got correct error: invalid utf-8 string +json_tokener_parse_ex(tok, "" , 6) ... OK: got object of type [string]: "" +json_tokener_parse_ex(tok, "世" , 7) ... OK: got object of type [string]: "世" +json_tokener_parse_ex(tok, "世" , 8) ... OK: got correct error: invalid utf-8 string +json_tokener_parse_ex(tok, [ 1] , 5) ... OK: got correct error: invalid utf-8 string +json_tokener_parse_ex(tok, Infinity , 9) ... OK: got object of type [double]: Infinity +json_tokener_parse_ex(tok, Infnity , 8) ... OK: got correct error: invalid utf-8 string +json_tokener_parse_ex(tok, "\ud855\udc55", 15) ... OK: got object of type [string]: "𥑕" +json_tokener_parse_ex(tok, "\ud855udc55", 14) ... OK: got correct error: invalid utf-8 string +json_tokener_parse_ex(tok, "\ud0031" , 10) ... OK: got correct error: invalid utf-8 string +json_tokener_parse_ex(tok, 1111 , 5) ... OK: got correct error: invalid utf-8 string +json_tokener_parse_ex(tok, {"1":1} , 8) ... OK: got correct error: invalid utf-8 string +End Incremental Tests OK=198 ERROR=0 ================================== diff --git a/third_party/json-c/tests/test_parse_int64.c b/third_party/json-c/tests/test_parse_int64.c index c251e0134..6eb12af02 100644 --- a/third_party/json-c/tests/test_parse_int64.c +++ b/third_party/json-c/tests/test_parse_int64.c @@ -1,4 +1,25 @@ +/* + * Original work: + * + * json-c (copyright was originally missing from this file) + * + * Modified Work: + * + * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. + * + * This software product is a proprietary product of NVIDIA CORPORATION & + * AFFILIATES (the "Company") and all right, title, and interest in and to the + * software product, including all associated intellectual property rights, are + * and shall remain exclusively with the Company. + * + * This software product is governed by the End User License Agreement + * provided with the software product. + * + */ +#ifdef NDEBUG +#undef NDEBUG +#endif #include #include @@ -11,22 +32,31 @@ void checkit(const char *buf) { int64_t cint64 = -666; - int retval = json_parse_int64(buf, &cint64); + int retval = doca_third_party_json_parse_int64(buf, &cint64); printf("buf=%s parseit=%d, value=%" PRId64 " \n", buf, retval, cint64); } +void checkit_uint(const char *buf) +{ + uint64_t cuint64 = 666; + + int retval = doca_third_party_json_parse_uint64(buf, &cuint64); + printf("buf=%s parseit=%d, value=%" PRIu64 " \n", buf, retval, cuint64); +} + /** - * This test calls json_parse_int64 with a variety of different strings. - * It's purpose is to ensure that the results are consistent across all - * different environments that it might be executed in. + * This test calls json_parse_int64 and json_parse_int64 with a variety + * of different strings. It's purpose is to ensure that the results are + * consistent across all different environments that it might be executed in. * * This always exits with a 0 exit value. The output should be compared * against previously saved expected output. */ -int main() +int main(int argc, char **argv) { char buf[100]; + printf("==========json_parse_int64() test===========\n"); checkit("x"); checkit("0"); @@ -59,8 +89,10 @@ int main() checkit(buf); strcpy(buf, "4294967295"); // aka UINT32_MAX + checkit(buf); - sprintf(buf, "4294967296"); // aka UINT32_MAX + 1 + strcpy(buf, "4294967296"); // aka UINT32_MAX + 1 + checkit(buf); strcpy(buf, "21474836470"); // INT32_MAX * 10 checkit(buf); @@ -111,5 +143,68 @@ int main() strcpy(buf, "123"); checkit(buf); + printf("\n==========json_parse_uint64() test===========\n"); + checkit_uint("x"); + + checkit_uint("0"); + checkit_uint("-0"); + + checkit_uint("00000000"); + checkit_uint("-00000000"); + + checkit_uint("1"); + + strcpy(buf, "2147483647"); // aka INT32_MAX + checkit_uint(buf); + + strcpy(buf, "-1"); + checkit_uint(buf); + + strcpy(buf, "-9223372036854775808"); + checkit_uint(buf); + + strcpy(buf, " 1"); + checkit_uint(buf); + + strcpy(buf, "00001234"); + checkit_uint(buf); + + strcpy(buf, "0001234x"); + checkit_uint(buf); + + strcpy(buf, "4294967295"); // aka UINT32_MAX + checkit_uint(buf); + + strcpy(buf, "4294967296"); // aka UINT32_MAX + 1 + checkit_uint(buf); + + strcpy(buf, "21474836470"); // INT32_MAX * 10 + checkit_uint(buf); + + strcpy(buf, "31474836470"); // INT32_MAX * 10 + a bunch + checkit_uint(buf); + + strcpy(buf, "9223372036854775806"); // INT64_MAX - 1 + checkit_uint(buf); + + strcpy(buf, "9223372036854775807"); // INT64_MAX + checkit_uint(buf); + + strcpy(buf, "9223372036854775808"); // INT64_MAX + 1 + checkit_uint(buf); + + strcpy(buf, "18446744073709551614"); // UINT64_MAX - 1 + checkit_uint(buf); + + strcpy(buf, "18446744073709551615"); // UINT64_MAX + checkit_uint(buf); + + strcpy(buf, "18446744073709551616"); // UINT64_MAX + 1 + checkit_uint(buf); + + // Ensure we can still parse valid numbers after parsing out of range ones. + strcpy(buf, "123"); + checkit_uint(buf); + return 0; } diff --git a/third_party/json-c/tests/test_parse_int64.expected b/third_party/json-c/tests/test_parse_int64.expected index d9cdf5ace..6dca94b47 100644 --- a/third_party/json-c/tests/test_parse_int64.expected +++ b/third_party/json-c/tests/test_parse_int64.expected @@ -1,3 +1,4 @@ +==========json_parse_int64() test=========== buf=x parseit=1, value=-666 buf=0 parseit=0, value=0 buf=-0 parseit=0, value=0 @@ -11,6 +12,8 @@ buf=00001234 parseit=0, value=1234 buf=0001234x parseit=0, value=1234 buf=-00001234 parseit=0, value=-1234 buf=-00001234x parseit=0, value=-1234 +buf=4294967295 parseit=0, value=4294967295 +buf=4294967296 parseit=0, value=4294967296 buf=21474836470 parseit=0, value=21474836470 buf=31474836470 parseit=0, value=31474836470 buf=-2147483647 parseit=0, value=-2147483647 @@ -27,3 +30,28 @@ buf=18446744073709551615 parseit=0, value=9223372036854775807 buf=18446744073709551616 parseit=0, value=9223372036854775807 buf=-18446744073709551616 parseit=0, value=-9223372036854775808 buf=123 parseit=0, value=123 + +==========json_parse_uint64() test=========== +buf=x parseit=1, value=666 +buf=0 parseit=0, value=0 +buf=-0 parseit=1, value=666 +buf=00000000 parseit=0, value=0 +buf=-00000000 parseit=1, value=666 +buf=1 parseit=0, value=1 +buf=2147483647 parseit=0, value=2147483647 +buf=-1 parseit=1, value=666 +buf=-9223372036854775808 parseit=1, value=666 +buf= 1 parseit=0, value=1 +buf=00001234 parseit=0, value=1234 +buf=0001234x parseit=0, value=1234 +buf=4294967295 parseit=0, value=4294967295 +buf=4294967296 parseit=0, value=4294967296 +buf=21474836470 parseit=0, value=21474836470 +buf=31474836470 parseit=0, value=31474836470 +buf=9223372036854775806 parseit=0, value=9223372036854775806 +buf=9223372036854775807 parseit=0, value=9223372036854775807 +buf=9223372036854775808 parseit=0, value=9223372036854775808 +buf=18446744073709551614 parseit=0, value=18446744073709551614 +buf=18446744073709551615 parseit=0, value=18446744073709551615 +buf=18446744073709551616 parseit=0, value=18446744073709551615 +buf=123 parseit=0, value=123 diff --git a/third_party/json-c/tests/test_printbuf.c b/third_party/json-c/tests/test_printbuf.c index 0dd2dc9f8..232d6d1f2 100644 --- a/third_party/json-c/tests/test_printbuf.c +++ b/third_party/json-c/tests/test_printbuf.c @@ -1,9 +1,31 @@ +/* + * Original work: + * + * json-c (copyright was originally missing from this file) + * + * Modified Work: + * + * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. + * + * This software product is a proprietary product of NVIDIA CORPORATION & + * AFFILIATES (the "Company") and all right, title, and interest in and to the + * software product, including all associated intellectual property rights, are + * and shall remain exclusively with the Company. + * + * This software product is governed by the End User License Agreement + * provided with the software product. + * + */ + +#ifdef NDEBUG +#undef NDEBUG +#endif #include +#include #include #include #include #include -#include #include "debug.h" #include "printbuf.h" @@ -11,53 +33,58 @@ static void test_basic_printbuf_memset(void); static void test_printbuf_memset_length(void); -static void test_basic_printbuf_memset() +#ifndef __func__ +/* VC++ compat */ +#define __func__ __FUNCTION__ +#endif + +static void test_basic_printbuf_memset(void) { struct printbuf *pb; printf("%s: starting test\n", __func__); - pb = printbuf_new(); - sprintbuf(pb, "blue:%d", 1); - printbuf_memset(pb, -1, 'x', 52); + pb = doca_third_party_printbuf_new(); + doca_third_party_sprintbuf(pb, "blue:%d", 1); + doca_third_party_printbuf_memset(pb, -1, 'x', 52); printf("Buffer contents:%.*s\n", printbuf_length(pb), pb->buf); - printbuf_free(pb); + doca_third_party_printbuf_free(pb); printf("%s: end test\n", __func__); } -static void test_printbuf_memset_length() +static void test_printbuf_memset_length(void) { struct printbuf *pb; printf("%s: starting test\n", __func__); - pb = printbuf_new(); - printbuf_memset(pb, -1, ' ', 0); - printbuf_memset(pb, -1, ' ', 0); - printbuf_memset(pb, -1, ' ', 0); - printbuf_memset(pb, -1, ' ', 0); - printbuf_memset(pb, -1, ' ', 0); + pb = doca_third_party_printbuf_new(); + doca_third_party_printbuf_memset(pb, -1, ' ', 0); + doca_third_party_printbuf_memset(pb, -1, ' ', 0); + doca_third_party_printbuf_memset(pb, -1, ' ', 0); + doca_third_party_printbuf_memset(pb, -1, ' ', 0); + doca_third_party_printbuf_memset(pb, -1, ' ', 0); printf("Buffer length: %d\n", printbuf_length(pb)); - printbuf_memset(pb, -1, ' ', 2); - printbuf_memset(pb, -1, ' ', 4); - printbuf_memset(pb, -1, ' ', 6); + doca_third_party_printbuf_memset(pb, -1, ' ', 2); + doca_third_party_printbuf_memset(pb, -1, ' ', 4); + doca_third_party_printbuf_memset(pb, -1, ' ', 6); printf("Buffer length: %d\n", printbuf_length(pb)); - printbuf_memset(pb, -1, ' ', 6); + doca_third_party_printbuf_memset(pb, -1, ' ', 6); printf("Buffer length: %d\n", printbuf_length(pb)); - printbuf_memset(pb, -1, ' ', 8); - printbuf_memset(pb, -1, ' ', 10); - printbuf_memset(pb, -1, ' ', 10); - printbuf_memset(pb, -1, ' ', 10); - printbuf_memset(pb, -1, ' ', 20); + doca_third_party_printbuf_memset(pb, -1, ' ', 8); + doca_third_party_printbuf_memset(pb, -1, ' ', 10); + doca_third_party_printbuf_memset(pb, -1, ' ', 10); + doca_third_party_printbuf_memset(pb, -1, ' ', 10); + doca_third_party_printbuf_memset(pb, -1, ' ', 20); printf("Buffer length: %d\n", printbuf_length(pb)); // No length change should occur - printbuf_memset(pb, 0, 'x', 30); + doca_third_party_printbuf_memset(pb, 0, 'x', 30); printf("Buffer length: %d\n", printbuf_length(pb)); // This should extend it by one. - printbuf_memset(pb, 0, 'x', printbuf_length(pb) + 1); + doca_third_party_printbuf_memset(pb, 0, 'x', printbuf_length(pb) + 1); printf("Buffer length: %d\n", printbuf_length(pb)); - printbuf_free(pb); + doca_third_party_printbuf_free(pb); printf("%s: end test\n", __func__); } @@ -68,52 +95,52 @@ static void test_printbuf_memappend(int *before_resize) int initial_size; printf("%s: starting test\n", __func__); - pb = printbuf_new(); + pb = doca_third_party_printbuf_new(); printf("Buffer length: %d\n", printbuf_length(pb)); initial_size = pb->size; - while(pb->size == initial_size) + while (pb->size == initial_size) { printbuf_memappend_fast(pb, "x", 1); } *before_resize = printbuf_length(pb) - 1; printf("Appended %d bytes for resize: [%s]\n", *before_resize + 1, pb->buf); - printbuf_reset(pb); + doca_third_party_printbuf_reset(pb); printbuf_memappend_fast(pb, "bluexyz123", 3); printf("Partial append: %d, [%s]\n", printbuf_length(pb), pb->buf); - char with_nulls[] = { 'a', 'b', '\0', 'c' }; - printbuf_reset(pb); + char with_nulls[] = {'a', 'b', '\0', 'c'}; + doca_third_party_printbuf_reset(pb); printbuf_memappend_fast(pb, with_nulls, (int)sizeof(with_nulls)); printf("With embedded \\0 character: %d, [%s]\n", printbuf_length(pb), pb->buf); - printbuf_free(pb); - pb = printbuf_new(); + doca_third_party_printbuf_free(pb); + pb = doca_third_party_printbuf_new(); char *data = malloc(*before_resize); memset(data, 'X', *before_resize); printbuf_memappend_fast(pb, data, *before_resize); printf("Append to just before resize: %d, [%s]\n", printbuf_length(pb), pb->buf); free(data); - printbuf_free(pb); + doca_third_party_printbuf_free(pb); - pb = printbuf_new(); + pb = doca_third_party_printbuf_new(); data = malloc(*before_resize + 1); memset(data, 'X', *before_resize + 1); printbuf_memappend_fast(pb, data, *before_resize + 1); printf("Append to just after resize: %d, [%s]\n", printbuf_length(pb), pb->buf); free(data); - printbuf_free(pb); + doca_third_party_printbuf_free(pb); #define SA_TEST_STR "XXXXXXXXXXXXXXXX" - pb = printbuf_new(); + pb = doca_third_party_printbuf_new(); printbuf_strappend(pb, SA_TEST_STR); printf("Buffer size after printbuf_strappend(): %d, [%s]\n", printbuf_length(pb), pb->buf); - printbuf_free(pb); -#undef SA_TEST_STR + doca_third_party_printbuf_free(pb); +#undef SA_TEST_STR printf("%s: end test\n", __func__); } @@ -122,35 +149,43 @@ static void test_sprintbuf(int before_resize); static void test_sprintbuf(int before_resize) { struct printbuf *pb; + const char *max_char = + "if string is greater than stack buffer, then use dynamic string" + " with vasprintf. Note: some implementation of vsnprintf return -1 " + " if output is truncated whereas some return the number of bytes that " + " would have been written - this code handles both cases."; printf("%s: starting test\n", __func__); - pb = printbuf_new(); + pb = doca_third_party_printbuf_new(); printf("Buffer length: %d\n", printbuf_length(pb)); char *data = malloc(before_resize + 1 + 1); memset(data, 'X', before_resize + 1 + 1); data[before_resize + 1] = '\0'; - sprintbuf(pb, "%s", data); + doca_third_party_sprintbuf(pb, "%s", data); free(data); - printf("sprintbuf to just after resize(%d+1): %d, [%s], strlen(buf)=%d\n", before_resize, printbuf_length(pb), pb->buf, (int)strlen(pb->buf)); + printf("sprintbuf to just after resize(%d+1): %d, [%s], strlen(buf)=%d\n", before_resize, + printbuf_length(pb), pb->buf, (int)strlen(pb->buf)); - printbuf_reset(pb); - sprintbuf(pb, "plain"); + doca_third_party_printbuf_reset(pb); + doca_third_party_sprintbuf(pb, "plain"); printf("%d, [%s]\n", printbuf_length(pb), pb->buf); - sprintbuf(pb, "%d", 1); + doca_third_party_sprintbuf(pb, "%d", 1); printf("%d, [%s]\n", printbuf_length(pb), pb->buf); - sprintbuf(pb, "%d", INT_MAX); + doca_third_party_sprintbuf(pb, "%d", INT_MAX); printf("%d, [%s]\n", printbuf_length(pb), pb->buf); - sprintbuf(pb, "%d", INT_MIN); + doca_third_party_sprintbuf(pb, "%d", INT_MIN); printf("%d, [%s]\n", printbuf_length(pb), pb->buf); - sprintbuf(pb, "%s", "%s"); + doca_third_party_sprintbuf(pb, "%s", "%s"); printf("%d, [%s]\n", printbuf_length(pb), pb->buf); - printbuf_free(pb); + doca_third_party_sprintbuf(pb, max_char); + printf("%d, [%s]\n", printbuf_length(pb), pb->buf); + doca_third_party_printbuf_free(pb); printf("%s: end test\n", __func__); } @@ -158,7 +193,7 @@ int main(int argc, char **argv) { int before_resize = 0; - mc_set_debug(1); + MC_SET_DEBUG(1); test_basic_printbuf_memset(); printf("========================================\n"); diff --git a/third_party/json-c/tests/test_printbuf.expected b/third_party/json-c/tests/test_printbuf.expected index 64644125b..a4ebc2a62 100644 --- a/third_party/json-c/tests/test_printbuf.expected +++ b/third_party/json-c/tests/test_printbuf.expected @@ -29,5 +29,6 @@ sprintbuf to just after resize(31+1): 32, [XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX], st 16, [plain12147483647] 27, [plain12147483647-2147483648] 29, [plain12147483647-2147483648%s] +284, [plain12147483647-2147483648%sif string is greater than stack buffer, then use dynamic string with vasprintf. Note: some implementation of vsnprintf return -1 if output is truncated whereas some return the number of bytes that would have been written - this code handles both cases.] test_sprintbuf: end test ======================================== diff --git a/third_party/json-c/tests/test_set_serializer.c b/third_party/json-c/tests/test_set_serializer.c index 0f122af23..fe5d2afa9 100644 --- a/third_party/json-c/tests/test_set_serializer.c +++ b/third_party/json-c/tests/test_set_serializer.c @@ -1,3 +1,25 @@ +/* + * Original work: + * + * json-c (copyright was originally missing from this file) + * + * Modified Work: + * + * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. + * + * This software product is a proprietary product of NVIDIA CORPORATION & + * AFFILIATES (the "Company") and all right, title, and interest in and to the + * software product, including all associated intellectual property rights, are + * and shall remain exclusively with the Company. + * + * This software product is governed by the End User License Agreement + * provided with the software product. + * + */ + +#ifdef NDEBUG +#undef NDEBUG +#endif #include #include #include @@ -5,7 +27,8 @@ #include "json.h" #include "printbuf.h" -struct myinfo { +struct myinfo +{ int value; }; @@ -17,55 +40,67 @@ static void freeit(json_object *jso, void *userdata) // Don't actually free anything here, the userdata is stack allocated. freeit_was_called = 1; } -static int custom_serializer(struct json_object *o, - struct printbuf *pb, - int level, - int flags) +static int custom_serializer(struct json_object *o, struct printbuf *pb, int level, int flags) { - sprintbuf(pb, "Custom Output"); + doca_third_party_sprintbuf(pb, "Custom Output"); return 0; } int main(int argc, char **argv) { - json_object *my_object; + json_object *my_object, *my_sub_object; MC_SET_DEBUG(1); printf("Test setting, then resetting a custom serializer:\n"); - my_object = json_object_new_object(); - json_object_object_add(my_object, "abc", json_object_new_int(12)); - json_object_object_add(my_object, "foo", json_object_new_string("bar")); + my_object = doca_third_party_json_object_new_object(); + doca_third_party_json_object_object_add(my_object, "abc", doca_third_party_json_object_new_int(12)); + doca_third_party_json_object_object_add(my_object, "foo", doca_third_party_json_object_new_string("bar")); - printf("my_object.to_string(standard)=%s\n", json_object_to_json_string(my_object)); + printf("my_object.to_string(standard)=%s\n", doca_third_party_json_object_to_json_string(my_object)); - struct myinfo userdata = { .value = 123 }; - json_object_set_serializer(my_object, custom_serializer, &userdata, freeit); + struct myinfo userdata = {.value = 123}; + doca_third_party_json_object_set_serializer(my_object, custom_serializer, &userdata, freeit); - printf("my_object.to_string(custom serializer)=%s\n", json_object_to_json_string(my_object)); + printf("my_object.to_string(custom serializer)=%s\n", + doca_third_party_json_object_to_json_string(my_object)); printf("Next line of output should be from the custom freeit function:\n"); freeit_was_called = 0; - json_object_set_serializer(my_object, NULL, NULL, NULL); + doca_third_party_json_object_set_serializer(my_object, NULL, NULL, NULL); assert(freeit_was_called); - printf("my_object.to_string(standard)=%s\n", json_object_to_json_string(my_object)); + printf("my_object.to_string(standard)=%s\n", doca_third_party_json_object_to_json_string(my_object)); - json_object_put(my_object); + doca_third_party_json_object_put(my_object); // ============================================ - my_object = json_object_new_object(); + my_object = doca_third_party_json_object_new_object(); printf("Check that the custom serializer isn't free'd until the last json_object_put:\n"); - json_object_set_serializer(my_object, custom_serializer, &userdata, freeit); - json_object_get(my_object); - json_object_put(my_object); - printf("my_object.to_string(custom serializer)=%s\n", json_object_to_json_string(my_object)); + doca_third_party_json_object_set_serializer(my_object, custom_serializer, &userdata, freeit); + doca_third_party_json_object_get(my_object); + doca_third_party_json_object_put(my_object); + printf("my_object.to_string(custom serializer)=%s\n", + doca_third_party_json_object_to_json_string(my_object)); printf("Next line of output should be from the custom freeit function:\n"); freeit_was_called = 0; - json_object_put(my_object); + doca_third_party_json_object_put(my_object); assert(freeit_was_called); + // ============================================ + + my_object = doca_third_party_json_object_new_object(); + my_sub_object = doca_third_party_json_object_new_double(1.0); + doca_third_party_json_object_object_add(my_object, "double", my_sub_object); + printf("Check that the custom serializer does not include nul byte:\n"); +#define UNCONST(a) ((void *)(uintptr_t)(const void *)(a)) + doca_third_party_json_object_set_serializer(my_sub_object, doca_third_party_json_object_double_to_json_string, UNCONST("%125.0f"), NULL); + printf("my_object.to_string(custom serializer)=%s\n", + doca_third_party_json_object_to_json_string_ext(my_object, JSON_C_TO_STRING_NOZERO)); + + doca_third_party_json_object_put(my_object); + return 0; } diff --git a/third_party/json-c/tests/test_set_serializer.expected b/third_party/json-c/tests/test_set_serializer.expected index ad44a9053..9a1351282 100644 --- a/third_party/json-c/tests/test_set_serializer.expected +++ b/third_party/json-c/tests/test_set_serializer.expected @@ -8,3 +8,5 @@ Check that the custom serializer isn't free'd until the last json_object_put: my_object.to_string(custom serializer)=Custom Output Next line of output should be from the custom freeit function: freeit, value=123 +Check that the custom serializer does not include nul byte: +my_object.to_string(custom serializer)={"double": 1} diff --git a/third_party/json-c/tests/test_set_value.c b/third_party/json-c/tests/test_set_value.c index 4c0a54a9b..c89074943 100644 --- a/third_party/json-c/tests/test_set_value.c +++ b/third_party/json-c/tests/test_set_value.c @@ -1,3 +1,25 @@ +/* + * Original work: + * + * json-c (copyright was originally missing from this file) + * + * Modified Work: + * + * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. + * + * This software product is a proprietary product of NVIDIA CORPORATION & + * AFFILIATES (the "Company") and all right, title, and interest in and to the + * software product, including all associated intellectual property rights, are + * and shall remain exclusively with the Company. + * + * This software product is governed by the End User License Agreement + * provided with the software product. + * + */ + +#ifdef NDEBUG +#undef NDEBUG +#endif #include #include #include @@ -6,47 +28,108 @@ int main(int argc, char **argv) { - json_object *tmp=json_object_new_int(123); - assert (json_object_get_int(tmp)==123); - json_object_set_int(tmp,321); - assert (json_object_get_int(tmp)==321); + json_object *tmp = doca_third_party_json_object_new_int(123); + assert(doca_third_party_json_object_get_int(tmp) == 123); + doca_third_party_json_object_set_int(tmp, 321); + assert(doca_third_party_json_object_get_int(tmp) == 321); printf("INT PASSED\n"); - json_object_set_int64(tmp,(int64_t)321321321); - assert (json_object_get_int64(tmp)==321321321); - json_object_put(tmp); + doca_third_party_json_object_set_int64(tmp, (int64_t)321321321); + assert(doca_third_party_json_object_get_int64(tmp) == 321321321); + doca_third_party_json_object_put(tmp); printf("INT64 PASSED\n"); - tmp=json_object_new_boolean(TRUE); - assert (json_object_get_boolean(tmp)==TRUE); - json_object_set_boolean(tmp,FALSE); - assert (json_object_get_boolean(tmp)==FALSE); - json_object_set_boolean(tmp,TRUE); - assert (json_object_get_boolean(tmp)==TRUE); - json_object_put(tmp); + tmp = doca_third_party_json_object_new_uint64(123); + assert(doca_third_party_json_object_get_boolean(tmp) == 1); + assert(doca_third_party_json_object_get_int(tmp) == 123); + assert(doca_third_party_json_object_get_int64(tmp) == 123); + assert(doca_third_party_json_object_get_uint64(tmp) == 123); + assert(doca_third_party_json_object_get_double(tmp) == 123.000000); + doca_third_party_json_object_set_uint64(tmp, (uint64_t)321321321); + assert(doca_third_party_json_object_get_uint64(tmp) == 321321321); + doca_third_party_json_object_set_uint64(tmp, 9223372036854775808U); + assert(doca_third_party_json_object_get_int(tmp) == INT32_MAX); + assert(doca_third_party_json_object_get_uint64(tmp) == 9223372036854775808U); + doca_third_party_json_object_put(tmp); + printf("UINT64 PASSED\n"); + tmp = doca_third_party_json_object_new_boolean(1); + assert(doca_third_party_json_object_get_boolean(tmp) == 1); + doca_third_party_json_object_set_boolean(tmp, 0); + assert(doca_third_party_json_object_get_boolean(tmp) == 0); + doca_third_party_json_object_set_boolean(tmp, 1); + assert(doca_third_party_json_object_get_boolean(tmp) == 1); + doca_third_party_json_object_put(tmp); printf("BOOL PASSED\n"); - tmp=json_object_new_double(12.34); - assert (json_object_get_double(tmp)==12.34); - json_object_set_double(tmp,34.56); - assert (json_object_get_double(tmp)==34.56); - json_object_set_double(tmp,6435.34); - assert (json_object_get_double(tmp)==6435.34); - json_object_put(tmp); + tmp = doca_third_party_json_object_new_double(12.34); + assert(doca_third_party_json_object_get_double(tmp) == 12.34); + doca_third_party_json_object_set_double(tmp, 34.56); + assert(doca_third_party_json_object_get_double(tmp) == 34.56); + doca_third_party_json_object_set_double(tmp, 6435.34); + assert(doca_third_party_json_object_get_double(tmp) == 6435.34); + doca_third_party_json_object_set_double(tmp, 2e21); + assert(doca_third_party_json_object_get_int(tmp) == INT32_MAX); + assert(doca_third_party_json_object_get_int64(tmp) == INT64_MAX); + assert(doca_third_party_json_object_get_uint64(tmp) == UINT64_MAX); + doca_third_party_json_object_set_double(tmp, -2e21); + assert(doca_third_party_json_object_get_int(tmp) == INT32_MIN); + assert(doca_third_party_json_object_get_int64(tmp) == INT64_MIN); + assert(doca_third_party_json_object_get_uint64(tmp) == 0); + doca_third_party_json_object_put(tmp); printf("DOUBLE PASSED\n"); - #define SHORT "SHORT" - #define MID "A MID STRING" - // 12345678901234567890123456789012.... - #define HUGE "A string longer than 32 chars as to check non local buf codepath" - tmp=json_object_new_string(SHORT); - assert (strcmp(json_object_get_string(tmp),SHORT)==0); - json_object_set_string(tmp,MID); - assert (strcmp(json_object_get_string(tmp),MID)==0); - json_object_set_string(tmp,HUGE); - assert (strcmp(json_object_get_string(tmp),HUGE)==0); - json_object_set_string(tmp,SHORT); - assert (strcmp(json_object_get_string(tmp),SHORT)==0); - json_object_put(tmp); +#define SHORT "SHORT" +#define MID "A MID STRING" +// 12345678901234567890123456789012.... +#define HUGE "A string longer than 32 chars as to check non local buf codepath" + tmp = doca_third_party_json_object_new_string(MID); + assert(strcmp(doca_third_party_json_object_get_string(tmp), MID) == 0); + assert(strcmp(doca_third_party_json_object_to_json_string(tmp), "\"" MID "\"") == 0); + doca_third_party_json_object_set_string(tmp, SHORT); + assert(strcmp(doca_third_party_json_object_get_string(tmp), SHORT) == 0); + assert(strcmp(doca_third_party_json_object_to_json_string(tmp), "\"" SHORT "\"") == 0); + doca_third_party_json_object_set_string(tmp, HUGE); + assert(strcmp(doca_third_party_json_object_get_string(tmp), HUGE) == 0); + assert(strcmp(doca_third_party_json_object_to_json_string(tmp), "\"" HUGE "\"") == 0); + doca_third_party_json_object_set_string(tmp, SHORT); + assert(strcmp(doca_third_party_json_object_get_string(tmp), SHORT) == 0); + assert(strcmp(doca_third_party_json_object_to_json_string(tmp), "\"" SHORT "\"") == 0); + + // Set an empty string a couple times to try to trigger + // a case that used to leak memory. + doca_third_party_json_object_set_string(tmp, ""); + doca_third_party_json_object_set_string(tmp, HUGE); + doca_third_party_json_object_set_string(tmp, ""); + doca_third_party_json_object_set_string(tmp, HUGE); + + doca_third_party_json_object_put(tmp); printf("STRING PASSED\n"); - - + +#define STR "STR" +#define DOUBLE "123.123" +#define DOUBLE_E "12E+3" +#define DOUBLE_STR "123.123STR" +#define DOUBLE_OVER "1.8E+308" +#define DOUBLE_OVER_NEGATIVE "-1.8E+308" + tmp = doca_third_party_json_object_new_string(STR); + assert(doca_third_party_json_object_get_double(tmp) == 0.0); + doca_third_party_json_object_set_string(tmp, DOUBLE); + assert(doca_third_party_json_object_get_double(tmp) == 123.123000); + doca_third_party_json_object_set_string(tmp, DOUBLE_E); + assert(doca_third_party_json_object_get_double(tmp) == 12000.000000); + doca_third_party_json_object_set_string(tmp, DOUBLE_STR); + assert(doca_third_party_json_object_get_double(tmp) == 0.0); + doca_third_party_json_object_set_string(tmp, DOUBLE_OVER); + assert(doca_third_party_json_object_get_double(tmp) == 0.0); + doca_third_party_json_object_set_string(tmp, DOUBLE_OVER_NEGATIVE); + assert(doca_third_party_json_object_get_double(tmp) == 0.0); + doca_third_party_json_object_put(tmp); + printf("STRINGTODOUBLE PASSED\n"); + + tmp = doca_third_party_json_tokener_parse("1.234"); + doca_third_party_json_object_set_double(tmp, 12.3); + const char *serialized = doca_third_party_json_object_to_json_string(tmp); + fprintf(stderr, "%s\n", serialized); + assert(strncmp(serialized, "12.3", 4) == 0); + doca_third_party_json_object_put(tmp); + printf("PARSE AND SET PASSED\n"); + printf("PASSED\n"); return 0; } diff --git a/third_party/json-c/tests/test_set_value.expected b/third_party/json-c/tests/test_set_value.expected index 6a900f9a6..7b43eec49 100644 --- a/third_party/json-c/tests/test_set_value.expected +++ b/third_party/json-c/tests/test_set_value.expected @@ -1,6 +1,9 @@ INT PASSED INT64 PASSED +UINT64 PASSED BOOL PASSED DOUBLE PASSED STRING PASSED +STRINGTODOUBLE PASSED +PARSE AND SET PASSED PASSED diff --git a/third_party/json-c/tests/test_strerror.c b/third_party/json-c/tests/test_strerror.c new file mode 100644 index 000000000..773b1aa10 --- /dev/null +++ b/third_party/json-c/tests/test_strerror.c @@ -0,0 +1,13 @@ +#ifdef NDEBUG +#undef NDEBUG +#endif +#include "strerror_override.h" + +#include + +int main(int argc, char **argv) +{ + puts(strerror(10000)); + puts(strerror(999)); + return 0; +} diff --git a/third_party/json-c/tests/test_strerror.expected b/third_party/json-c/tests/test_strerror.expected new file mode 100644 index 000000000..b6b3bb655 --- /dev/null +++ b/third_party/json-c/tests/test_strerror.expected @@ -0,0 +1,2 @@ +ERRNO=10000 +ERRNO=999 diff --git a/third_party/json-c/tests/test_strerror.test b/third_party/json-c/tests/test_strerror.test new file mode 120000 index 000000000..58a13f4f3 --- /dev/null +++ b/third_party/json-c/tests/test_strerror.test @@ -0,0 +1 @@ +test_basic.test \ No newline at end of file diff --git a/third_party/json-c/tests/test_util_file.c b/third_party/json-c/tests/test_util_file.c index 5a8a8a086..0d6406dc8 100644 --- a/third_party/json-c/tests/test_util_file.c +++ b/third_party/json-c/tests/test_util_file.c @@ -1,96 +1,130 @@ +/* + * Original work: + * + * json-c (copyright was originally missing from this file) + * + * Modified Work: + * + * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. + * + * This software product is a proprietary product of NVIDIA CORPORATION & + * AFFILIATES (the "Company") and all right, title, and interest in and to the + * software product, including all associated intellectual property rights, are + * and shall remain exclusively with the Company. + * + * This software product is governed by the End User License Agreement + * provided with the software product. + * + */ + +#ifdef NDEBUG +#undef NDEBUG +#endif #include "strerror_override.h" -#include "strerror_override_private.h" +#ifdef WIN32 +#define WIN32_LEAN_AND_MEAN +#include +#include +#endif /* defined(WIN32) */ +#include +#include +#include #include #include -#include #include -#include +#if HAVE_UNISTD_H #include -#include +#endif /* HAVE_UNISTD_H */ +#include #include +#include #include "json.h" #include "json_util.h" +#include "snprintf_compat.h" static void test_read_valid_with_fd(const char *testdir); -static void test_read_nonexistant(); +static void test_read_valid_nested_with_fd(const char *testdir); +static void test_read_nonexistant(void); static void test_read_closed(void); -static void test_write_to_file(); +static void test_write_to_file(void); static void stat_and_cat(const char *file); +static void test_read_fd_equal(const char *testdir); -static void test_write_to_file() +#ifndef PATH_MAX +#define PATH_MAX 256 +#endif + +static void test_write_to_file(void) { json_object *jso; - jso = json_tokener_parse("{" - "\"foo\":1234," - "\"foo1\":\"abcdefghijklmnopqrstuvwxyz\"," - "\"foo2\":\"abcdefghijklmnopqrstuvwxyz\"," - "\"foo3\":\"abcdefghijklmnopqrstuvwxyz\"," - "\"foo4\":\"abcdefghijklmnopqrstuvwxyz\"," - "\"foo5\":\"abcdefghijklmnopqrstuvwxyz\"," - "\"foo6\":\"abcdefghijklmnopqrstuvwxyz\"," - "\"foo7\":\"abcdefghijklmnopqrstuvwxyz\"," - "\"foo8\":\"abcdefghijklmnopqrstuvwxyz\"," - "\"foo9\":\"abcdefghijklmnopqrstuvwxyz\"" - "}"); + jso = doca_third_party_json_tokener_parse("{" + "\"foo\":1234," + "\"foo1\":\"abcdefghijklmnopqrstuvwxyz\"," + "\"foo2\":\"abcdefghijklmnopqrstuvwxyz\"," + "\"foo3\":\"abcdefghijklmnopqrstuvwxyz\"," + "\"foo4\":\"abcdefghijklmnopqrstuvwxyz\"," + "\"foo5\":\"abcdefghijklmnopqrstuvwxyz\"," + "\"foo6\":\"abcdefghijklmnopqrstuvwxyz\"," + "\"foo7\":\"abcdefghijklmnopqrstuvwxyz\"," + "\"foo8\":\"abcdefghijklmnopqrstuvwxyz\"," + "\"foo9\":\"abcdefghijklmnopqrstuvwxyz\"" + "}"); const char *outfile = "json.out"; - int rv = json_object_to_file(outfile, jso); - printf("%s: json_object_to_file(%s, jso)=%d\n", - (rv == 0) ? "OK" : "FAIL", outfile, rv); + int rv = doca_third_party_json_object_to_file(outfile, jso); + printf("%s: json_object_to_file(%s, jso)=%d\n", (rv == 0) ? "OK" : "FAIL", outfile, rv); if (rv == 0) stat_and_cat(outfile); putchar('\n'); const char *outfile2 = "json2.out"; - rv = json_object_to_file_ext(outfile2, jso, JSON_C_TO_STRING_PRETTY); + rv = doca_third_party_json_object_to_file_ext(outfile2, jso, JSON_C_TO_STRING_PRETTY); printf("%s: json_object_to_file_ext(%s, jso, JSON_C_TO_STRING_PRETTY)=%d\n", (rv == 0) ? "OK" : "FAIL", outfile2, rv); if (rv == 0) stat_and_cat(outfile2); const char *outfile3 = "json3.out"; - int d = open(outfile3, O_WRONLY|O_CREAT, 0600); + int d = open(outfile3, O_WRONLY | O_CREAT, 0600); if (d < 0) { printf("FAIL: unable to open %s %s\n", outfile3, strerror(errno)); return; } - rv = json_object_to_fd(d, jso, JSON_C_TO_STRING_PRETTY); + rv = doca_third_party_json_object_to_fd(d, jso, JSON_C_TO_STRING_PRETTY); printf("%s: json_object_to_fd(%s, jso, JSON_C_TO_STRING_PRETTY)=%d\n", (rv == 0) ? "OK" : "FAIL", outfile3, rv); // Write the same object twice - rv = json_object_to_fd(d, jso, JSON_C_TO_STRING_PLAIN); + rv = doca_third_party_json_object_to_fd(d, jso, JSON_C_TO_STRING_PLAIN); printf("%s: json_object_to_fd(%s, jso, JSON_C_TO_STRING_PLAIN)=%d\n", (rv == 0) ? "OK" : "FAIL", outfile3, rv); close(d); if (rv == 0) stat_and_cat(outfile3); - json_object_put(jso); + doca_third_party_json_object_put(jso); } static void stat_and_cat(const char *file) { struct stat sb; - int d = open(file, O_RDONLY, 0600); + int d = open(file, O_RDONLY); if (d < 0) { - printf("FAIL: unable to open %s: %s\n", - file, strerror(errno)); + printf("FAIL: unable to open %s: %s\n", file, strerror(errno)); return; } if (fstat(d, &sb) < 0) { - printf("FAIL: unable to stat %s: %s\n", - file, strerror(errno)); + printf("FAIL: unable to stat %s: %s\n", file, strerror(errno)); close(d); return; } char *buf = malloc(sb.st_size + 1); - if(!buf) + if (!buf) { printf("FAIL: unable to allocate memory\n"); close(d); @@ -98,8 +132,7 @@ static void stat_and_cat(const char *file) } if (read(d, buf, sb.st_size) < sb.st_size) { - printf("FAIL: unable to read all of %s: %s\n", - file, strerror(errno)); + printf("FAIL: unable to read all of %s: %s\n", file, strerror(errno)); free(buf); close(d); return; @@ -112,80 +145,137 @@ static void stat_and_cat(const char *file) int main(int argc, char **argv) { -// json_object_to_file(file, obj); -// json_object_to_file_ext(file, obj, flags); - - _json_c_strerror_enable = 1; + // json_object_to_file(file, obj); + // json_object_to_file_ext(file, obj, flags); const char *testdir; if (argc < 2) { fprintf(stderr, - "Usage: %s \n" - " is the location of input files\n", - argv[0]); + "Usage: %s \n" + " is the location of input files\n", + argv[0]); return EXIT_FAILURE; } testdir = argv[1]; + // Test json_c_version.c + if (strncmp(doca_third_party_json_c_version(), JSON_C_VERSION, sizeof(JSON_C_VERSION))) + { + printf("FAIL: Output from json_c_version(): %s " + "does not match %s", + doca_third_party_json_c_version(), JSON_C_VERSION); + return EXIT_FAILURE; + } + if (doca_third_party_json_c_version_num() != JSON_C_VERSION_NUM) + { + printf("FAIL: Output from json_c_version_num(): %d " + "does not match %d", + doca_third_party_json_c_version_num(), JSON_C_VERSION_NUM); + return EXIT_FAILURE; + } + test_read_valid_with_fd(testdir); + test_read_valid_nested_with_fd(testdir); test_read_nonexistant(); test_read_closed(); test_write_to_file(); + test_read_fd_equal(testdir); return EXIT_SUCCESS; } static void test_read_valid_with_fd(const char *testdir) { - const char *filename = "./valid.json"; + char filename[PATH_MAX]; + (void)snprintf(filename, sizeof(filename), "%s/valid.json", testdir); - int d = open(filename, O_RDONLY, 0); + int d = open(filename, O_RDONLY); if (d < 0) { - fprintf(stderr, - "FAIL: unable to open %s: %s\n", - filename, strerror(errno)); + fprintf(stderr, "FAIL: unable to open %s: %s\n", filename, strerror(errno)); exit(EXIT_FAILURE); } - json_object *jso = json_object_from_fd(d); + json_object *jso = doca_third_party_json_object_from_fd(d); if (jso != NULL) { - printf("OK: json_object_from_fd(%s)=%s\n", - filename, json_object_to_json_string(jso)); - json_object_put(jso); + printf("OK: json_object_from_fd(valid.json)=%s\n", + doca_third_party_json_object_to_json_string(jso)); + doca_third_party_json_object_put(jso); } else { - fprintf(stderr, - "FAIL: unable to parse contents of %s: %s\n", - filename, json_util_get_last_err()); + fprintf(stderr, "FAIL: unable to parse contents of %s: %s\n", filename, + doca_third_party_json_util_get_last_err()); } close(d); } -static void test_read_nonexistant() +static void test_read_valid_nested_with_fd(const char *testdir) +{ + char filename[PATH_MAX]; + (void)snprintf(filename, sizeof(filename), "%s/valid_nested.json", testdir); + + int d = open(filename, O_RDONLY); + if (d < 0) + { + fprintf(stderr, "FAIL: unable to open %s: %s\n", filename, strerror(errno)); + exit(EXIT_FAILURE); + } + assert(NULL == doca_third_party_json_object_from_fd_ex(d, -2)); + json_object *jso = doca_third_party_json_object_from_fd_ex(d, 20); + if (jso != NULL) + { + printf("OK: json_object_from_fd_ex(valid_nested.json, 20)=%s\n", + doca_third_party_json_object_to_json_string(jso)); + doca_third_party_json_object_put(jso); + } + else + { + fprintf(stderr, "FAIL: unable to parse contents of %s: %s\n", filename, + doca_third_party_json_util_get_last_err()); + } + + (void)lseek(d, SEEK_SET, 0); + + jso = doca_third_party_json_object_from_fd_ex(d, 3); + if (jso != NULL) + { + printf("FAIL: json_object_from_fd_ex(%s, 3)=%s\n", filename, + doca_third_party_json_object_to_json_string(jso)); + doca_third_party_json_object_put(jso); + } + else + { + printf("OK: correctly unable to parse contents of valid_nested.json with low max " + "depth: %s\n", + doca_third_party_json_util_get_last_err()); + } + close(d); +} + +static void test_read_nonexistant(void) { const char *filename = "./not_present.json"; - json_object *jso = json_object_from_file(filename); + json_object *jso = doca_third_party_json_object_from_file(filename); if (jso != NULL) { - printf("FAIL: json_object_from_file(%s) returned %p when NULL expected\n", - filename, (void *)jso); - json_object_put(jso); + printf("FAIL: json_object_from_file(%s) returned %p when NULL expected\n", filename, + (void *)jso); + doca_third_party_json_object_put(jso); } else { - printf("OK: json_object_from_file(%s) correctly returned NULL: %s\n", - filename, json_util_get_last_err()); + printf("OK: json_object_from_file(%s) correctly returned NULL: %s\n", filename, + doca_third_party_json_util_get_last_err()); } } -static void test_read_closed() +static void test_read_closed(void) { // Test reading from a closed fd - int d = open("/dev/null", O_RDONLY, 0); - if(d < 0) + int d = open("/dev/null", O_RDONLY); + if (d < 0) { puts("FAIL: unable to open"); } @@ -198,17 +288,40 @@ static void test_read_closed() close(d); close(fixed_d); - json_object *jso = json_object_from_fd(fixed_d); + json_object *jso = doca_third_party_json_object_from_fd(fixed_d); if (jso != NULL) { - printf("FAIL: read from closed fd returning non-NULL: %p\n", - (void *)jso); + printf("FAIL: read from closed fd returning non-NULL: %p\n", (void *)jso); fflush(stdout); - printf(" jso=%s\n", json_object_to_json_string(jso)); - json_object_put(jso); + printf(" jso=%s\n", doca_third_party_json_object_to_json_string(jso)); + doca_third_party_json_object_put(jso); return; } printf("OK: json_object_from_fd(closed_fd), " "expecting NULL, EBADF, got:NULL, %s\n", - json_util_get_last_err()); + doca_third_party_json_util_get_last_err()); +} + +static void test_read_fd_equal(const char *testdir) +{ + char filename[PATH_MAX]; + (void)snprintf(filename, sizeof(filename), "%s/valid_nested.json", testdir); + + json_object *jso = doca_third_party_json_object_from_file(filename); + + int d = open(filename, O_RDONLY); + if (d < 0) + { + fprintf(stderr, "FAIL: unable to open %s: %s\n", filename, strerror(errno)); + exit(EXIT_FAILURE); + } + json_object *new_jso = doca_third_party_json_object_from_fd(d); + close(d); + + printf("OK: json_object_from_file(valid.json)=%s\n", + doca_third_party_json_object_to_json_string(jso)); + printf("OK: json_object_from_fd(valid.json)=%s\n", + doca_third_party_json_object_to_json_string(new_jso)); + doca_third_party_json_object_put(jso); + doca_third_party_json_object_put(new_jso); } diff --git a/third_party/json-c/tests/test_util_file.expected b/third_party/json-c/tests/test_util_file.expected index f64a5a500..4a8aea55f 100644 --- a/third_party/json-c/tests/test_util_file.expected +++ b/third_party/json-c/tests/test_util_file.expected @@ -1,7 +1,10 @@ -OK: json_object_from_fd(./valid.json)={ "foo": 123 } +OK: json_object_from_fd(valid.json)={ "foo": 123 } +OK: json_object_from_fd_ex(valid_nested.json, 20)={ "foo": 123, "obj2": { "obj3": { "obj4": { "foo": 999 } } } } +OK: correctly unable to parse contents of valid_nested.json with low max depth: json_tokener_parse_ex failed: nesting too deep + OK: json_object_from_file(./not_present.json) correctly returned NULL: json_object_from_file: error opening file ./not_present.json: ERRNO=ENOENT -OK: json_object_from_fd(closed_fd), expecting NULL, EBADF, got:NULL, json_object_from_fd: error reading fd 10: ERRNO=EBADF +OK: json_object_from_fd(closed_fd), expecting NULL, EBADF, got:NULL, json_object_from_fd_ex: error reading fd 10: ERRNO=EBADF OK: json_object_to_file(json.out, jso)=0 file[json.out], size=336, contents={"foo":1234,"foo1":"abcdefghijklmnopqrstuvwxyz","foo2":"abcdefghijklmnopqrstuvwxyz","foo3":"abcdefghijklmnopqrstuvwxyz","foo4":"abcdefghijklmnopqrstuvwxyz","foo5":"abcdefghijklmnopqrstuvwxyz","foo6":"abcdefghijklmnopqrstuvwxyz","foo7":"abcdefghijklmnopqrstuvwxyz","foo8":"abcdefghijklmnopqrstuvwxyz","foo9":"abcdefghijklmnopqrstuvwxyz"} @@ -33,3 +36,5 @@ file[json3.out], size=703, contents={ "foo8":"abcdefghijklmnopqrstuvwxyz", "foo9":"abcdefghijklmnopqrstuvwxyz" }{"foo":1234,"foo1":"abcdefghijklmnopqrstuvwxyz","foo2":"abcdefghijklmnopqrstuvwxyz","foo3":"abcdefghijklmnopqrstuvwxyz","foo4":"abcdefghijklmnopqrstuvwxyz","foo5":"abcdefghijklmnopqrstuvwxyz","foo6":"abcdefghijklmnopqrstuvwxyz","foo7":"abcdefghijklmnopqrstuvwxyz","foo8":"abcdefghijklmnopqrstuvwxyz","foo9":"abcdefghijklmnopqrstuvwxyz"} +OK: json_object_from_file(valid.json)={ "foo": 123, "obj2": { "obj3": { "obj4": { "foo": 999 } } } } +OK: json_object_from_fd(valid.json)={ "foo": 123, "obj2": { "obj3": { "obj4": { "foo": 999 } } } } diff --git a/third_party/json-c/tests/test_visit.c b/third_party/json-c/tests/test_visit.c index f2ffe8c09..26768bfec 100644 --- a/third_party/json-c/tests/test_visit.c +++ b/third_party/json-c/tests/test_visit.c @@ -1,8 +1,30 @@ +/* + * Original work: + * + * json-c (copyright was originally missing from this file) + * + * Modified Work: + * + * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED. + * + * This software product is a proprietary product of NVIDIA CORPORATION & + * AFFILIATES (the "Company") and all right, title, and interest in and to the + * software product, including all associated intellectual property rights, are + * and shall remain exclusively with the Company. + * + * This software product is governed by the End User License Agreement + * provided with the software product. + * + */ + +#ifdef NDEBUG +#undef NDEBUG +#endif +#include +#include #include #include -#include #include -#include #include "json.h" #include "json_tokener.h" @@ -12,6 +34,9 @@ static json_c_visit_userfunc emit_object; static json_c_visit_userfunc skip_arrays; static json_c_visit_userfunc pop_and_stop; static json_c_visit_userfunc err_on_subobj2; +static json_c_visit_userfunc pop_array; +static json_c_visit_userfunc stop_array; +static json_c_visit_userfunc err_return; int main(void) { @@ -28,58 +53,63 @@ int main(void) \"obj4\": [ true, false, null ]\ }"; - json_object *jso = json_tokener_parse(input); - printf("jso.to_string()=%s\n", json_object_to_json_string(jso)); + json_object *jso = doca_third_party_json_tokener_parse(input); + printf("jso.to_string()=%s\n", doca_third_party_json_object_to_json_string(jso)); int rv; - rv = json_c_visit(jso, 0, emit_object, NULL); + rv = doca_third_party_json_c_visit(jso, 0, emit_object, NULL); printf("json_c_visit(emit_object)=%d\n", rv); printf("================================\n\n"); - rv = json_c_visit(jso, 0, skip_arrays, NULL); + rv = doca_third_party_json_c_visit(jso, 0, skip_arrays, NULL); printf("json_c_visit(skip_arrays)=%d\n", rv); printf("================================\n\n"); - rv = json_c_visit(jso, 0, pop_and_stop, NULL); + rv = doca_third_party_json_c_visit(jso, 0, pop_and_stop, NULL); printf("json_c_visit(pop_and_stop)=%d\n", rv); printf("================================\n\n"); - rv = json_c_visit(jso, 0, err_on_subobj2, NULL); + rv = doca_third_party_json_c_visit(jso, 0, err_on_subobj2, NULL); printf("json_c_visit(err_on_subobj2)=%d\n", rv); printf("================================\n\n"); - json_object_put(jso); -} + rv = doca_third_party_json_c_visit(jso, 0, pop_array, NULL); + printf("json_c_visit(pop_array)=%d\n", rv); + printf("================================\n\n"); + rv = doca_third_party_json_c_visit(jso, 0, stop_array, NULL); + printf("json_c_visit(stop_array)=%d\n", rv); + printf("================================\n\n"); -static int emit_object(json_object *jso, int flags, - json_object *parent_jso, - const char *jso_key, - size_t *jso_index, void *userarg) + rv = doca_third_party_json_c_visit(jso, 0, err_return, NULL); + printf("json_c_visit(err_return)=%d\n", rv); + printf("================================\n\n"); + + doca_third_party_json_object_put(jso); + + return 0; +} + +static int emit_object(json_object *jso, int flags, json_object *parent_jso, const char *jso_key, + size_t *jso_index, void *userarg) { - printf("flags: 0x%x, key: %s, index: %ld, value: %s\n", - flags, - (jso_key ? jso_key : "(null)"), - (jso_index ? (long)*jso_index : -1L), - json_object_to_json_string(jso)); + printf("flags: 0x%x, key: %s, index: %ld, value: %s\n", flags, + (jso_key ? jso_key : "(null)"), (jso_index ? (long)*jso_index : -1L), + doca_third_party_json_object_to_json_string(jso)); return JSON_C_VISIT_RETURN_CONTINUE; } -static int skip_arrays(json_object *jso, int flags, - json_object *parent_jso, - const char *jso_key, - size_t *jso_index, void *userarg) +static int skip_arrays(json_object *jso, int flags, json_object *parent_jso, const char *jso_key, + size_t *jso_index, void *userarg) { (void)emit_object(jso, flags, parent_jso, jso_key, jso_index, userarg); - if (json_object_get_type(jso) == json_type_array) + if (doca_third_party_json_object_get_type(jso) == json_type_array) return JSON_C_VISIT_RETURN_SKIP; return JSON_C_VISIT_RETURN_CONTINUE; } -static int pop_and_stop(json_object *jso, int flags, - json_object *parent_jso, - const char *jso_key, - size_t *jso_index, void *userarg) +static int pop_and_stop(json_object *jso, int flags, json_object *parent_jso, const char *jso_key, + size_t *jso_index, void *userarg) { (void)emit_object(jso, flags, parent_jso, jso_key, jso_index, userarg); if (jso_key != NULL && strcmp(jso_key, "subobj1") == 0) @@ -95,10 +125,8 @@ static int pop_and_stop(json_object *jso, int flags, return JSON_C_VISIT_RETURN_CONTINUE; } -static int err_on_subobj2(json_object *jso, int flags, - json_object *parent_jso, - const char *jso_key, - size_t *jso_index, void *userarg) +static int err_on_subobj2(json_object *jso, int flags, json_object *parent_jso, const char *jso_key, + size_t *jso_index, void *userarg) { (void)emit_object(jso, flags, parent_jso, jso_key, jso_index, userarg); if (jso_key != NULL && strcmp(jso_key, "subobj2") == 0) @@ -109,3 +137,35 @@ static int err_on_subobj2(json_object *jso, int flags, return JSON_C_VISIT_RETURN_CONTINUE; } +static int pop_array(json_object *jso, int flags, json_object *parent_jso, const char *jso_key, + size_t *jso_index, void *userarg) +{ + (void)emit_object(jso, flags, parent_jso, jso_key, jso_index, userarg); + if (jso_index != NULL && (*jso_index == 0)) + { + printf("POP after handling array[0]\n"); + return JSON_C_VISIT_RETURN_POP; + } + return JSON_C_VISIT_RETURN_CONTINUE; +} + +static int stop_array(json_object *jso, int flags, json_object *parent_jso, const char *jso_key, + size_t *jso_index, void *userarg) +{ + (void)emit_object(jso, flags, parent_jso, jso_key, jso_index, userarg); + if (jso_index != NULL && (*jso_index == 0)) + { + printf("STOP after handling array[1]\n"); + return JSON_C_VISIT_RETURN_STOP; + } + return JSON_C_VISIT_RETURN_CONTINUE; +} + +static int err_return(json_object *jso, int flags, json_object *parent_jso, const char *jso_key, + size_t *jso_index, void *userarg) +{ + printf("flags: 0x%x, key: %s, index: %ld, value: %s\n", flags, + (jso_key ? jso_key : "(null)"), (jso_index ? (long)*jso_index : -1L), + doca_third_party_json_object_to_json_string(jso)); + return 100; +} diff --git a/third_party/json-c/tests/test_visit.expected b/third_party/json-c/tests/test_visit.expected index 2f05622b9..5f323174b 100644 --- a/third_party/json-c/tests/test_visit.expected +++ b/third_party/json-c/tests/test_visit.expected @@ -53,3 +53,37 @@ ERROR after handling subobj1 json_c_visit(err_on_subobj2)=-1 ================================ +flags: 0x0, key: (null), index: -1, value: { "obj1": 123, "obj2": { "subobj1": "aaa", "subobj2": "bbb", "subobj3": [ "elem1", "elem2", true ] }, "obj3": 1.234, "obj4": [ true, false, null ] } +flags: 0x0, key: obj1, index: -1, value: 123 +flags: 0x0, key: obj2, index: -1, value: { "subobj1": "aaa", "subobj2": "bbb", "subobj3": [ "elem1", "elem2", true ] } +flags: 0x0, key: subobj1, index: -1, value: "aaa" +flags: 0x0, key: subobj2, index: -1, value: "bbb" +flags: 0x0, key: subobj3, index: -1, value: [ "elem1", "elem2", true ] +flags: 0x0, key: (null), index: 0, value: "elem1" +POP after handling array[0] +flags: 0x2, key: subobj3, index: -1, value: [ "elem1", "elem2", true ] +flags: 0x2, key: obj2, index: -1, value: { "subobj1": "aaa", "subobj2": "bbb", "subobj3": [ "elem1", "elem2", true ] } +flags: 0x0, key: obj3, index: -1, value: 1.234 +flags: 0x0, key: obj4, index: -1, value: [ true, false, null ] +flags: 0x0, key: (null), index: 0, value: true +POP after handling array[0] +flags: 0x2, key: obj4, index: -1, value: [ true, false, null ] +flags: 0x2, key: (null), index: -1, value: { "obj1": 123, "obj2": { "subobj1": "aaa", "subobj2": "bbb", "subobj3": [ "elem1", "elem2", true ] }, "obj3": 1.234, "obj4": [ true, false, null ] } +json_c_visit(pop_array)=0 +================================ + +flags: 0x0, key: (null), index: -1, value: { "obj1": 123, "obj2": { "subobj1": "aaa", "subobj2": "bbb", "subobj3": [ "elem1", "elem2", true ] }, "obj3": 1.234, "obj4": [ true, false, null ] } +flags: 0x0, key: obj1, index: -1, value: 123 +flags: 0x0, key: obj2, index: -1, value: { "subobj1": "aaa", "subobj2": "bbb", "subobj3": [ "elem1", "elem2", true ] } +flags: 0x0, key: subobj1, index: -1, value: "aaa" +flags: 0x0, key: subobj2, index: -1, value: "bbb" +flags: 0x0, key: subobj3, index: -1, value: [ "elem1", "elem2", true ] +flags: 0x0, key: (null), index: 0, value: "elem1" +STOP after handling array[1] +json_c_visit(stop_array)=0 +================================ + +flags: 0x0, key: (null), index: -1, value: { "obj1": 123, "obj2": { "subobj1": "aaa", "subobj2": "bbb", "subobj3": [ "elem1", "elem2", true ] }, "obj3": 1.234, "obj4": [ true, false, null ] } +json_c_visit(err_return)=-1 +================================ + diff --git a/third_party/json-c/tests/valid_nested.json b/third_party/json-c/tests/valid_nested.json new file mode 100644 index 000000000..3e1a0cffc --- /dev/null +++ b/third_party/json-c/tests/valid_nested.json @@ -0,0 +1 @@ +{"foo":123, "obj2": { "obj3": { "obj4": { "foo": 999 } } } } diff --git a/third_party/json-c/vasprintf_compat.h b/third_party/json-c/vasprintf_compat.h index 43dbf8939..59b2e9607 100644 --- a/third_party/json-c/vasprintf_compat.h +++ b/third_party/json-c/vasprintf_compat.h @@ -8,34 +8,55 @@ #include "snprintf_compat.h" +#ifndef WIN32 +#include +#endif /* !defined(WIN32) */ +#include +#include + #if !defined(HAVE_VASPRINTF) /* CAW: compliant version of vasprintf */ static int vasprintf(char **buf, const char *fmt, va_list ap) { #ifndef WIN32 static char _T_emptybuffer = '\0'; + va_list ap2; #endif /* !defined(WIN32) */ int chars; char *b; - if(!buf) { return -1; } + if (!buf) + { + return -1; + } #ifdef WIN32 - chars = _vscprintf(fmt, ap)+1; -#else /* !defined(WIN32) */ + chars = _vscprintf(fmt, ap); +#else /* !defined(WIN32) */ /* CAW: RAWR! We have to hope to god here that vsnprintf doesn't overwrite - our buffer like on some 64bit sun systems.... but hey, its time to move on */ - chars = vsnprintf(&_T_emptybuffer, 0, fmt, ap)+1; - if(chars < 0) { chars *= -1; } /* CAW: old glibc versions have this problem */ + * our buffer like on some 64bit sun systems... but hey, it's time to move on + */ + va_copy(ap2, ap); + chars = vsnprintf(&_T_emptybuffer, 0, fmt, ap2); + va_end(ap2); #endif /* defined(WIN32) */ + if (chars < 0 || (size_t)chars + 1 > SIZE_MAX / sizeof(char)) + { + return -1; + } - b = (char*)malloc(sizeof(char)*chars); - if(!b) { return -1; } + b = (char *)malloc(sizeof(char) * ((size_t)chars + 1)); + if (!b) + { + return -1; + } - if((chars = vsprintf(b, fmt, ap)) < 0) + if ((chars = vsprintf(b, fmt, ap)) < 0) { free(b); - } else { + } + else + { *buf = b; }