Skip to content

Commit

Permalink
Merge branch 'main' into cbmc-6.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
graebm authored Nov 26, 2024
2 parents d84df07 + 4f3c2ee commit 42b14e2
Show file tree
Hide file tree
Showing 11 changed files with 312 additions and 72 deletions.
202 changes: 144 additions & 58 deletions .github/workflows/ci.yml

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion cmake/AwsCFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@ function(aws_set_common_properties target)
# We do this so that backtraces are more likely to show function names.
# We mostly use backtraces to diagnose memory leaks.
if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
set_target_properties(${target} PROPERTIES C_VISIBILITY_PRESET hidden CXX_VISIBILITY_PRESET hidden VISIBILITY_INLINES_HIDDEN ON)
# And dont hide symbols on anything pre GCC 5.0 (Visibility support was not great on older compilers and some libraries didnt annotate visibility -
# looking at you jni, which does not annotate on gcc less than 4.2. Mixing no annotation and hidden symbols leads to unexpected failures.).
if (NOT (CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_LESS "5.0"))
set_target_properties(${target} PROPERTIES C_VISIBILITY_PRESET hidden CXX_VISIBILITY_PRESET hidden VISIBILITY_INLINES_HIDDEN ON)
endif ()
endif ()
endfunction()
80 changes: 77 additions & 3 deletions cmake/AwsPrebuildDependency.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ function(aws_prebuild_dependency)
set(multiValueArgs CMAKE_ARGUMENTS)
cmake_parse_arguments(AWS_PREBUILD "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

if(NOT AWS_PREBUILD_DEPENDENCY_NAME)
if (NOT AWS_PREBUILD_DEPENDENCY_NAME)
message(FATAL_ERROR "Missing DEPENDENCY_NAME argument in prebuild_dependency function")
endif()

if(NOT AWS_PREBUILD_SOURCE_DIR)
if (NOT AWS_PREBUILD_SOURCE_DIR)
message(FATAL_ERROR "Missing SOURCE_DIR argument in prebuild_dependency function")
endif()

Expand All @@ -29,18 +29,31 @@ function(aws_prebuild_dependency)
string(REPLACE ";" "\\\\;" ESCAPED_PREFIX_PATH "${CMAKE_PREFIX_PATH}")
# For execute_process to accept a dynamically constructed command, it should be passed in a list format.
set(cmakeCommand "${CMAKE_COMMAND}")

# Get the list of optional and platform-specific variables that may affect build process.
set(cmakeOptionalVariables "")
aws_get_variables_for_prebuild_dependency(cmakeOptionalVariables)
list(APPEND cmakeCommand ${cmakeOptionalVariables})

# The following variables should always be used.
list(APPEND cmakeCommand ${AWS_PREBUILD_SOURCE_DIR})
list(APPEND cmakeCommand -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE})
list(APPEND cmakeCommand -DCMAKE_PREFIX_PATH=${ESCAPED_PREFIX_PATH})
list(APPEND cmakeCommand -DCMAKE_INSTALL_PREFIX=${depInstallDir})
list(APPEND cmakeCommand -DCMAKE_INSTALL_RPATH=${CMAKE_INSTALL_RPATH})
list(APPEND cmakeCommand -DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS})
# In case a custom generator was provided via -G option. If we don't propagate it, the default value might
# conflict with other cmake options (e.g. CMAKE_MAKE_PROGRAM) or no make program could be found at all.
if (CMAKE_GENERATOR)
list(APPEND cmakeCommand -G${CMAKE_GENERATOR})
endif()

# Append provided arguments to CMake command.
if(AWS_PREBUILD_CMAKE_ARGUMENTS)
if (AWS_PREBUILD_CMAKE_ARGUMENTS)
list(APPEND cmakeCommand ${AWS_PREBUILD_CMAKE_ARGUMENTS})
endif()

message(STATUS "cmake command for dependency ${AWS_PREBUILD_DEPENDENCY_NAME}: ${cmakeCommand}")
# Configure dependency project.
execute_process(
COMMAND ${cmakeCommand}
Expand All @@ -65,6 +78,10 @@ function(aws_prebuild_dependency)
# Make the installation visible for others.
list(INSERT CMAKE_PREFIX_PATH 0 ${depInstallDir}/)
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} PARENT_SCOPE)
if (CMAKE_CROSSCOMPILING)
list(INSERT CMAKE_FIND_ROOT_PATH 0 ${depInstallDir})
set(CMAKE_FIND_ROOT_PATH ${CMAKE_FIND_ROOT_PATH} PARENT_SCOPE)
endif()

set(${AWS_PREBUILD_DEPENDENCY_NAME}_PREBUILT TRUE CACHE INTERNAL "Indicate that dependency is built and can be used")

Expand All @@ -75,3 +92,60 @@ function(aws_prebuild_dependency)
DESTINATION ${CMAKE_INSTALL_PREFIX}
)
endfunction()

# Get list of optional or platform-specific variables that may affect build process.
function(aws_get_variables_for_prebuild_dependency AWS_CMAKE_PREBUILD_ARGS)
set(variables "")

# The CMake variables below were chosen for Linux, BSD, and Android platforms. If you want to use the prebuild logic
# on other platforms, the chances are you have to handle additional variables (like CMAKE_OSX_SYSROOT). Refer to
# https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html to update the list of handled variables, and
# then you can enable a new platform here.
if ((NOT UNIX) OR APPLE)
message(FATAL_ERROR "aws_get_variables_for_prebuild_dependency is called for unsupported platform")
endif()

get_cmake_property(vars CACHE_VARIABLES)
foreach(var ${vars})
# Variables in this block make sense only in cross-compiling mode. The variable list is created from the CMake
# documentation on toolchains: https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html
# NOTE: Some variables are missed here (e.g. CMAKE_SYSROOT) because they can be set via toolchain file only.
if (CMAKE_CROSSCOMPILING AND (
var STREQUAL "CMAKE_TOOLCHAIN_FILE"
OR var STREQUAL "CMAKE_SYSTEM_NAME"
OR var STREQUAL "CMAKE_SYSTEM_VERSION"
OR var STREQUAL "CMAKE_SYSTEM_PROCESSOR"
# Android-specific variables.
OR var MATCHES "^(CMAKE_)?ANDROID_"))
# To store a list within another list, it needs to be escaped first.
string(REPLACE ";" "\\\\;" escapedVar "${${var}}")
if (escapedVar)
list(APPEND variables "-D${var}=${escapedVar}")
endif()
endif()

# Other optional variables applicable both in cross-compiling and non-cross-compiling modes.
# Refer to https://cmake.org/cmake/help/latest/manual/cmake-variables.7.html for each variable description.
if (var STREQUAL "CMAKE_C_COMPILER"
OR var MATCHES "^CMAKE_C_FLAGS(_DEBUG|_RELEASE|_RELWITHDEBINFO|_MINSIZEREL)?"
OR var STREQUAL "CMAKE_CXX_COMPILER"
OR var MATCHES "^CMAKE_CXX_FLAGS(_DEBUG|_RELEASE|_RELWITHDEBINFO|_MINSIZEREL)?"
OR var STREQUAL "CMAKE_LINKER_TYPE"
OR var MATCHES "^CMAKE_EXE_LINKER_FLAGS(_DEBUG|_RELEASE|_RELWITHDEBINFO|_MINSIZEREL)?"
OR var MATCHES "^CMAKE_MODULE_LINKER_FLAGS(_DEBUG|_RELEASE|_RELWITHDEBINFO|_MINSIZEREL)?"
OR var MATCHES "^CMAKE_STATIC_LINKER_FLAGS(_DEBUG|_RELEASE|_RELWITHDEBINFO|_MINSIZEREL)?"
OR var MATCHES "^CMAKE_SHARED_LINKER_FLAGS(_DEBUG|_RELEASE|_RELWITHDEBINFO|_MINSIZEREL)?"
OR var STREQUAL "CMAKE_MAKE_PROGRAM"
OR var MATCHES "^CMAKE_RUNTIME_OUTPUT_DIRECTORY"
OR var MATCHES "^CMAKE_ARCHIVE_OUTPUT_DIRECTORY"
OR var MATCHES "^CMAKE_LIBRARY_OUTPUT_DIRECTORY")
# To store a list within another list, it needs to be escaped first.
string(REPLACE ";" "\\\\;" escapedVar "${${var}}")
if (escapedVar)
list(APPEND variables "-D${var}=${escapedVar}")
endif()
endif()
endforeach()

set(${AWS_CMAKE_PREBUILD_ARGS} ${variables} PARENT_SCOPE)
endfunction()
4 changes: 2 additions & 2 deletions include/aws/common/cbor.h
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ int aws_cbor_decoder_peek_type(struct aws_cbor_decoder *decoder, enum aws_cbor_t
* @brief Consume the next data item, includes all the content within the data item.
*
* As an example for the following cbor, this function will consume all the data
* as it's only one cbor data item, an indefinite map with 2 key, value pair:
* as it's only one cbor data item, an indefinite map with 2 <key, value> pair:
* 0xbf6346756ef563416d7421ff
* BF -- Start indefinite-length map
* 63 -- First key, UTF-8 string length 3
Expand Down Expand Up @@ -374,7 +374,7 @@ int aws_cbor_decoder_consume_next_single_element(struct aws_cbor_decoder *decode
* Specifically:
* AWS_CBOR_TYPE_UINT - aws_cbor_decoder_pop_next_unsigned_int_val
* AWS_CBOR_TYPE_NEGINT - aws_cbor_decoder_pop_next_negative_int_val, it represents (-1 - *out)
* AWS_CBOR_TYPE_FLOAT - aws_cbor_decoder_pop_next_double_val
* AWS_CBOR_TYPE_FLOAT - aws_cbor_decoder_pop_next_float_val
* AWS_CBOR_TYPE_BYTES - aws_cbor_decoder_pop_next_bytes_val
* AWS_CBOR_TYPE_TEXT - aws_cbor_decoder_pop_next_text_val
*
Expand Down
1 change: 1 addition & 0 deletions include/aws/common/private/xml_parser_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ struct aws_xml_node {
struct aws_array_list attributes;
struct aws_byte_cursor doc_at_body;
bool processed;
bool is_empty;
};

struct aws_xml_parser {
Expand Down
8 changes: 1 addition & 7 deletions include/aws/common/ref_count.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
#include <aws/common/common.h>

#include <aws/common/atomics.h>
#include <aws/common/shutdown_types.h>

AWS_PUSH_SANE_WARNING_LEVEL

typedef void(aws_simple_completion_callback)(void *);

/*
* A utility type for making ref-counted types, reminiscent of std::shared_ptr in C++
*/
Expand All @@ -22,11 +21,6 @@ struct aws_ref_count {
aws_simple_completion_callback *on_zero_fn;
};

struct aws_shutdown_callback_options {
aws_simple_completion_callback *shutdown_callback_fn;
void *shutdown_callback_user_data;
};

AWS_EXTERN_C_BEGIN

/**
Expand Down
34 changes: 34 additions & 0 deletions include/aws/common/shutdown_types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#ifndef AWS_COMMON_SHUTDOWN_TYPES_H
#define AWS_COMMON_SHUTDOWN_TYPES_H

/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/

#include <aws/common/common.h>

AWS_PUSH_SANE_WARNING_LEVEL

typedef void(aws_simple_completion_callback)(void *);

/**
* Configuration for a callback to invoke when something has been completely
* cleaned up. Primarily used in async cleanup control flows.
*/
struct aws_shutdown_callback_options {

/**
* Function to invoke when the associated object is fully destroyed.
*/
aws_simple_completion_callback *shutdown_callback_fn;

/**
* User data to invoke the shutdown callback with.
*/
void *shutdown_callback_user_data;
};

AWS_POP_SANE_WARNING_LEVEL

#endif /* AWS_COMMON_SHUTDOWN_TYPES_H */
10 changes: 10 additions & 0 deletions source/xml_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ static int s_load_node_decl(
AWS_PRECONDITION(decl_body);
AWS_PRECONDITION(node);

node->is_empty = decl_body->ptr[decl_body->len - 1] == '/';

struct aws_array_list splits;
AWS_ZERO_STRUCT(splits);

Expand Down Expand Up @@ -158,6 +160,14 @@ int s_advance_to_closing_tag(
AWS_PRECONDITION(parser);
AWS_PRECONDITION(node);

if (node->is_empty) {
if (out_body) {
out_body->ptr = NULL;
out_body->len = 0;
}
return AWS_OP_SUCCESS;
}

/* currently the max node name is 256 characters. This is arbitrary, but should be enough
* for our uses. If we ever generalize this, we'll have to come back and rethink this. */
uint8_t name_close[MAX_NAME_LEN + NODE_CLOSE_OVERHEAD] = {0};
Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ add_test_case(xml_parser_nested_node_same_name_test)
add_test_case(xml_parser_nested_node_deep_recursion_test)
add_test_case(xml_parser_too_many_attributes_test)
add_test_case(xml_parser_name_too_long_test)
add_test_case(xml_parser_child_empty_tag)

add_test_case(test_thread_scheduler_ordering)
add_test_case(test_thread_scheduler_happy_path_cancellation)
Expand Down
2 changes: 1 addition & 1 deletion tests/hash_table_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1084,7 +1084,7 @@ static int s_test_hash_churn_fn(struct aws_allocator *allocator, void *ctx) {
int was_present;
err_code = aws_hash_table_remove(&hash_table, e->key, NULL, &was_present);
ASSERT_SUCCESS(err_code, "Unexpected failure removing element");
if (i == 0 && entries[i - 1].key == e->key && entries[i - 1].is_removed) {
if (i != 0 && entries[i - 1].key == e->key && entries[i - 1].is_removed) {
ASSERT_INT_EQUALS(0, was_present, "Expected item to be missing");
} else {
ASSERT_INT_EQUALS(1, was_present, "Expected item to be present");
Expand Down
36 changes: 36 additions & 0 deletions tests/xml_parser_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,42 @@ static int s_xml_parser_siblings_with_text_test(struct aws_allocator *allocator,

AWS_TEST_CASE(xml_parser_siblings_with_text, s_xml_parser_siblings_with_text_test)

const char *siblings_with_empty_tag = "<?xml version=\"1.0\" "
"encoding=\"UTF-8\"?><rootNode><child1 /><child2>TestBody2</child2></rootNode>";

static int s_xml_parser_child_empty_tag(struct aws_allocator *allocator, void *ctx) {
(void)ctx;
struct sibling_text_capture capture;
AWS_ZERO_STRUCT(capture);

capture.capture1 = aws_byte_cursor_from_c_str("random values");

struct aws_xml_parser_options options = {
.doc = aws_byte_cursor_from_c_str(siblings_with_empty_tag),
.on_root_encountered = s_root_with_child_siblings,
.user_data = &capture,
};
ASSERT_SUCCESS(aws_xml_parse(allocator, &options));

const char expected_name1[] = "child1";

const char expected_name2[] = "child2";
const char expected_value2[] = "TestBody2";

ASSERT_BIN_ARRAYS_EQUALS(
expected_name1, sizeof(expected_name1) - 1, capture.node_name1.ptr, capture.node_name1.len);
ASSERT_PTR_EQUALS(capture.capture1.ptr, NULL);
ASSERT_UINT_EQUALS(capture.capture1.len, 0);

ASSERT_BIN_ARRAYS_EQUALS(
expected_name2, sizeof(expected_name2) - 1, capture.node_name2.ptr, capture.node_name2.len);
ASSERT_BIN_ARRAYS_EQUALS(expected_value2, sizeof(expected_value2) - 1, capture.capture2.ptr, capture.capture2.len);

return AWS_OP_SUCCESS;
}

AWS_TEST_CASE(xml_parser_child_empty_tag, s_xml_parser_child_empty_tag)

const char *preamble_and_attributes =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<!DOCTYPE html \n"
Expand Down

0 comments on commit 42b14e2

Please sign in to comment.