Skip to content

Commit

Permalink
Merge branch 'main' into add-cmake-cmd-args
Browse files Browse the repository at this point in the history
  • Loading branch information
sfodagain committed Nov 13, 2024
2 parents cdb20c2 + c4b032d commit 31095b8
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 8 deletions.
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_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_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()
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
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 31095b8

Please sign in to comment.