diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 909862917..90ba83090 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,7 +6,7 @@ on: - 'main' env: - BUILDER_VERSION: v0.9.40 + BUILDER_VERSION: v0.9.43 BUILDER_HOST: https://d19elf31gohf1l.cloudfront.net BUILDER_SOURCE: releases PACKAGE_NAME: aws-c-common @@ -125,7 +125,7 @@ jobs: python builder.pyz build -p ${{ env.PACKAGE_NAME }} --target windows-${{ matrix.arch }} --compiler msvc-16 windows-vc15: - runs-on: windows-2019 # windows-2019 is last env with Visual Studio 2017 (v15.0) + runs-on: windows-2022 # latest strategy: matrix: arch: [x86, x64] diff --git a/CMakeLists.txt b/CMakeLists.txt index 5d7f1d9e0..6d484d7f9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -178,7 +178,7 @@ aws_set_common_properties(${PROJECT_NAME} NO_WEXTRA) aws_prepare_symbol_visibility_args(${PROJECT_NAME} "AWS_COMMON") target_compile_options(${PROJECT_NAME} PUBLIC ${PLATFORM_CFLAGS}) -aws_check_headers(${PROJECT_NAME} ${AWS_COMMON_HEADERS} ${AWS_TEST_HEADERS} ${AWS_COMMON_OS_HEADERS}) +aws_check_headers(${PROJECT_NAME} ${AWS_COMMON_HEADERS}) #apple source already includes the definitions we want, and setting this posix source #version causes it to revert to an older version. So don't turn it on there, we don't need it. diff --git a/cmake/AwsCheckHeaders.cmake b/cmake/AwsCheckHeaders.cmake index b75314e8c..795664396 100644 --- a/cmake/AwsCheckHeaders.cmake +++ b/cmake/AwsCheckHeaders.cmake @@ -20,14 +20,14 @@ function(aws_check_headers target) set(HEADER_CHECKER_ROOT "${CMAKE_CURRENT_BINARY_DIR}/header-checker") # Write stub main file - set(HEADER_CHECKER_MAIN "${HEADER_CHECKER_ROOT}/stub.c") + set(HEADER_CHECKER_MAIN "${HEADER_CHECKER_ROOT}/headerchecker_main.c") file(WRITE ${HEADER_CHECKER_MAIN} " int main(int argc, char **argv) { (void)argc; (void)argv; return 0; - }") + }\n") set(HEADER_CHECKER_LIB ${target}-header-check) add_executable(${HEADER_CHECKER_LIB} ${HEADER_CHECKER_MAIN}) @@ -40,20 +40,31 @@ function(aws_check_headers target) LINKER_LANGUAGE CXX CXX_STANDARD 11 CXX_STANDARD_REQUIRED 0 - C_STANDARD 90 + C_STANDARD 99 ) + # Ensure our headers can be included by an application with its warnings set very high + if(MSVC) + target_compile_options(${HEADER_CHECKER_LIB} PRIVATE /Wall /WX) + else() + target_compile_options(${HEADER_CHECKER_LIB} PRIVATE -Wall -Wextra -Wpedantic -Werror) + endif() + foreach(header IN LISTS ARGN) if (NOT ${header} MATCHES "\\.inl$") - file(RELATIVE_PATH rel_header ${CMAKE_HOME_DIRECTORY} ${header}) - file(RELATIVE_PATH include_path "${CMAKE_HOME_DIRECTORY}/include" ${header}) - set(stub_dir "${HEADER_CHECKER_ROOT}/${rel_header}") - file(MAKE_DIRECTORY "${stub_dir}") + # create unique token for this file, e.g.: + # "${CMAKE_CURRENT_SOURCE_DIR}/include/aws/common/byte_buf.h" -> "aws_common_byte_buf_h" + file(RELATIVE_PATH include_path "${CMAKE_CURRENT_SOURCE_DIR}/include" ${header}) + # replace non-alphanumeric characters with underscores + string(REGEX REPLACE "[^a-zA-Z0-9]" "_" unique_token ${include_path}) + set(c_file "${HEADER_CHECKER_ROOT}/headerchecker_${unique_token}.c") + set(cpp_file "${HEADER_CHECKER_ROOT}/headerchecker_${unique_token}.cpp") # include header twice to check for include-guards - file(WRITE "${stub_dir}/check.c" "#include <${include_path}>\n#include <${include_path}>\n") - file(WRITE "${stub_dir}/checkcpp.cpp" "#include <${include_path}>\n#include <${include_path}>\n") + # define a unique int or compiler complains that there's nothing in the file + file(WRITE "${c_file}" "#include <${include_path}>\n#include <${include_path}>\nint ${unique_token}_c;\n") + file(WRITE "${cpp_file}" "#include <${include_path}>\n#include <${include_path}>\nint ${unique_token}_cpp;") - target_sources(${HEADER_CHECKER_LIB} PUBLIC "${stub_dir}/check.c" "${stub_dir}/checkcpp.cpp") + target_sources(${HEADER_CHECKER_LIB} PUBLIC "${c_file}" "${cpp_file}") endif() endforeach(header) endif() # PERFORM_HEADER_CHECK diff --git a/include/aws/common/allocator.h b/include/aws/common/allocator.h index ab081e763..a9ba14fdc 100644 --- a/include/aws/common/allocator.h +++ b/include/aws/common/allocator.h @@ -9,6 +9,7 @@ #include #include +AWS_PUSH_SANE_WARNING_LEVEL AWS_EXTERN_C_BEGIN /* Allocator structure. An instance of this will be passed around for anything needing memory allocation */ @@ -205,5 +206,6 @@ AWS_COMMON_API size_t aws_small_block_allocator_page_size_available(struct aws_allocator *sba_allocator); AWS_EXTERN_C_END +AWS_POP_SANE_WARNING_LEVEL #endif /* AWS_COMMON_ALLOCATOR_H */ diff --git a/include/aws/common/array_list.h b/include/aws/common/array_list.h index bbd50ead3..ad7be100b 100644 --- a/include/aws/common/array_list.h +++ b/include/aws/common/array_list.h @@ -10,6 +10,8 @@ #include +AWS_PUSH_SANE_WARNING_LEVEL + #define AWS_ARRAY_LIST_DEBUG_FILL 0xDD struct aws_array_list { @@ -211,7 +213,7 @@ void aws_array_list_swap(struct aws_array_list *AWS_RESTRICT list, size_t a, siz /** * Sort elements in the list in-place according to the comparator function. */ -AWS_STATIC_IMPL +AWS_COMMON_API void aws_array_list_sort(struct aws_array_list *AWS_RESTRICT list, aws_array_list_comparator_fn *compare_fn); #ifndef AWS_NO_STATIC_IMPL @@ -219,5 +221,6 @@ void aws_array_list_sort(struct aws_array_list *AWS_RESTRICT list, aws_array_lis #endif /* AWS_NO_STATIC_IMPL */ AWS_EXTERN_C_END +AWS_POP_SANE_WARNING_LEVEL #endif /* AWS_COMMON_ARRAY_LIST_H */ diff --git a/include/aws/common/array_list.inl b/include/aws/common/array_list.inl index d61425d8d..9d3ceb458 100644 --- a/include/aws/common/array_list.inl +++ b/include/aws/common/array_list.inl @@ -96,18 +96,6 @@ bool aws_array_list_is_valid(const struct aws_array_list *AWS_RESTRICT list) { return required_size_is_valid && current_size_is_valid && data_is_valid && item_size_is_valid; } -AWS_STATIC_IMPL -void aws_array_list_debug_print(const struct aws_array_list *list) { - printf( - "arraylist %p. Alloc %p. current_size %zu. length %zu. item_size %zu. data %p\n", - (void *)list, - (void *)list->alloc, - list->current_size, - list->length, - list->item_size, - (void *)list->data); -} - AWS_STATIC_IMPL void aws_array_list_clean_up(struct aws_array_list *AWS_RESTRICT list) { AWS_PRECONDITION(AWS_IS_ZEROED(*list) || aws_array_list_is_valid(list)); @@ -404,15 +392,6 @@ int aws_array_list_set_at(struct aws_array_list *AWS_RESTRICT list, const void * return AWS_OP_SUCCESS; } -AWS_STATIC_IMPL -void aws_array_list_sort(struct aws_array_list *AWS_RESTRICT list, aws_array_list_comparator_fn *compare_fn) { - AWS_PRECONDITION(aws_array_list_is_valid(list)); - if (list->data) { - qsort(list->data, aws_array_list_length(list), list->item_size, compare_fn); - } - AWS_POSTCONDITION(aws_array_list_is_valid(list)); -} - AWS_EXTERN_C_END #endif /* AWS_COMMON_ARRAY_LIST_INL */ diff --git a/include/aws/common/assert.h b/include/aws/common/assert.h index 9bd614c7b..ed5a4eca2 100644 --- a/include/aws/common/assert.h +++ b/include/aws/common/assert.h @@ -10,6 +10,7 @@ #include #include +AWS_PUSH_SANE_WARNING_LEVEL AWS_EXTERN_C_BEGIN AWS_COMMON_API @@ -59,7 +60,7 @@ AWS_EXTERN_C_END #if defined(CBMC) # include # define AWS_ASSERT(cond) assert(cond) -#elif defined(DEBUG_BUILD) || __clang_analyzer__ +#elif defined(DEBUG_BUILD) || defined(__clang_analyzer__) # define AWS_ASSERT(cond) AWS_FATAL_ASSERT(cond) #else # define AWS_ASSERT(cond) @@ -67,7 +68,7 @@ AWS_EXTERN_C_END #if defined(CBMC) # define AWS_FATAL_ASSERT(cond) AWS_ASSERT(cond) -#elif __clang_analyzer__ +#elif defined(__clang_analyzer__) # define AWS_FATAL_ASSERT(cond) \ if (!(cond)) { \ abort(); \ @@ -187,4 +188,6 @@ AWS_EXTERN_C_END #define AWS_OBJECT_PTR_IS_READABLE(ptr) AWS_MEM_IS_READABLE((ptr), sizeof(*(ptr))) #define AWS_OBJECT_PTR_IS_WRITABLE(ptr) AWS_MEM_IS_WRITABLE((ptr), sizeof(*(ptr))) +AWS_POP_SANE_WARNING_LEVEL + #endif /* AWS_COMMON_ASSERT_H */ diff --git a/include/aws/common/atomics.h b/include/aws/common/atomics.h index e2ee8df95..ef64f985a 100644 --- a/include/aws/common/atomics.h +++ b/include/aws/common/atomics.h @@ -8,6 +8,8 @@ * SPDX-License-Identifier: Apache-2.0. */ +AWS_PUSH_SANE_WARNING_LEVEL + /** * struct aws_atomic_var represents an atomic variable - a value which can hold an integer or pointer * that can be manipulated atomically. struct aws_atomic_vars should normally only be manipulated @@ -323,5 +325,6 @@ void aws_atomic_thread_fence(enum aws_memory_order order); #endif /* AWS_NO_STATIC_IMPL */ AWS_EXTERN_C_END +AWS_POP_SANE_WARNING_LEVEL #endif diff --git a/include/aws/common/atomics_msvc.inl b/include/aws/common/atomics_msvc.inl index fa74a75eb..516385f27 100644 --- a/include/aws/common/atomics_msvc.inl +++ b/include/aws/common/atomics_msvc.inl @@ -10,7 +10,11 @@ #include #include +/* This file generates level 4 compiler warnings in Visual Studio 2017 and older */ +#pragma warning(push, 3) #include +#pragma warning(pop) + #include #include @@ -140,7 +144,7 @@ static inline void aws_atomic_priv_barrier_after(enum aws_memory_order order, en */ AWS_STATIC_IMPL void aws_atomic_init_int(volatile struct aws_atomic_var *var, size_t n) { - AWS_ATOMIC_VAR_INTVAL(var) = n; + AWS_ATOMIC_VAR_INTVAL(var) = (aws_atomic_impl_int_t)n; } /** @@ -158,7 +162,7 @@ void aws_atomic_init_ptr(volatile struct aws_atomic_var *var, void *p) { AWS_STATIC_IMPL size_t aws_atomic_load_int_explicit(volatile const struct aws_atomic_var *var, enum aws_memory_order memory_order) { aws_atomic_priv_barrier_before(memory_order, aws_atomic_priv_load); - size_t result = AWS_ATOMIC_VAR_INTVAL(var); + size_t result = (size_t)AWS_ATOMIC_VAR_INTVAL(var); aws_atomic_priv_barrier_after(memory_order, aws_atomic_priv_load); return result; } @@ -181,10 +185,10 @@ AWS_STATIC_IMPL void aws_atomic_store_int_explicit(volatile struct aws_atomic_var *var, size_t n, enum aws_memory_order memory_order) { if (memory_order != aws_memory_order_seq_cst) { aws_atomic_priv_barrier_before(memory_order, aws_atomic_priv_store); - AWS_ATOMIC_VAR_INTVAL(var) = n; + AWS_ATOMIC_VAR_INTVAL(var) = (aws_atomic_impl_int_t)n; aws_atomic_priv_barrier_after(memory_order, aws_atomic_priv_store); } else { - AWS_INTERLOCKED_INT(Exchange)(&AWS_ATOMIC_VAR_INTVAL(var), n); + AWS_INTERLOCKED_INT(Exchange)(&AWS_ATOMIC_VAR_INTVAL(var), (aws_atomic_impl_int_t)n); } } @@ -213,7 +217,7 @@ size_t aws_atomic_exchange_int_explicit( size_t n, enum aws_memory_order memory_order) { aws_atomic_priv_check_order(memory_order); - return AWS_INTERLOCKED_INT(Exchange)(&AWS_ATOMIC_VAR_INTVAL(var), n); + return (size_t)AWS_INTERLOCKED_INT(Exchange)(&AWS_ATOMIC_VAR_INTVAL(var), (aws_atomic_impl_int_t)n); } /** @@ -244,7 +248,8 @@ bool aws_atomic_compare_exchange_int_explicit( aws_atomic_priv_check_order(order_success); aws_atomic_priv_check_order(order_failure); - size_t oldval = AWS_INTERLOCKED_INT(CompareExchange)(&AWS_ATOMIC_VAR_INTVAL(var), desired, *expected); + size_t oldval = (size_t)AWS_INTERLOCKED_INT(CompareExchange)( + &AWS_ATOMIC_VAR_INTVAL(var), (aws_atomic_impl_int_t)desired, (aws_atomic_impl_int_t)*expected); bool successful = oldval == *expected; *expected = oldval; @@ -280,7 +285,7 @@ AWS_STATIC_IMPL size_t aws_atomic_fetch_add_explicit(volatile struct aws_atomic_var *var, size_t n, enum aws_memory_order order) { aws_atomic_priv_check_order(order); - return AWS_INTERLOCKED_INT(ExchangeAdd)(&AWS_ATOMIC_VAR_INTVAL(var), n); + return (size_t)AWS_INTERLOCKED_INT(ExchangeAdd)(&AWS_ATOMIC_VAR_INTVAL(var), (aws_atomic_impl_int_t)n); } /** @@ -290,7 +295,7 @@ AWS_STATIC_IMPL size_t aws_atomic_fetch_sub_explicit(volatile struct aws_atomic_var *var, size_t n, enum aws_memory_order order) { aws_atomic_priv_check_order(order); - return AWS_INTERLOCKED_INT(ExchangeAdd)(&AWS_ATOMIC_VAR_INTVAL(var), -(aws_atomic_impl_int_t)n); + return (size_t)AWS_INTERLOCKED_INT(ExchangeAdd)(&AWS_ATOMIC_VAR_INTVAL(var), -(aws_atomic_impl_int_t)n); } /** @@ -300,7 +305,7 @@ AWS_STATIC_IMPL size_t aws_atomic_fetch_or_explicit(volatile struct aws_atomic_var *var, size_t n, enum aws_memory_order order) { aws_atomic_priv_check_order(order); - return AWS_INTERLOCKED_INT(Or)(&AWS_ATOMIC_VAR_INTVAL(var), n); + return (size_t)AWS_INTERLOCKED_INT(Or)(&AWS_ATOMIC_VAR_INTVAL(var), (aws_atomic_impl_int_t)n); } /** @@ -310,7 +315,7 @@ AWS_STATIC_IMPL size_t aws_atomic_fetch_and_explicit(volatile struct aws_atomic_var *var, size_t n, enum aws_memory_order order) { aws_atomic_priv_check_order(order); - return AWS_INTERLOCKED_INT(And)(&AWS_ATOMIC_VAR_INTVAL(var), n); + return (size_t)AWS_INTERLOCKED_INT(And)(&AWS_ATOMIC_VAR_INTVAL(var), (aws_atomic_impl_int_t)n); } /** @@ -320,7 +325,7 @@ AWS_STATIC_IMPL size_t aws_atomic_fetch_xor_explicit(volatile struct aws_atomic_var *var, size_t n, enum aws_memory_order order) { aws_atomic_priv_check_order(order); - return AWS_INTERLOCKED_INT(Xor)(&AWS_ATOMIC_VAR_INTVAL(var), n); + return (size_t)AWS_INTERLOCKED_INT(Xor)(&AWS_ATOMIC_VAR_INTVAL(var), (aws_atomic_impl_int_t)n); } /** diff --git a/include/aws/common/byte_buf.h b/include/aws/common/byte_buf.h index 7df579ec4..17b0ae59b 100644 --- a/include/aws/common/byte_buf.h +++ b/include/aws/common/byte_buf.h @@ -11,6 +11,8 @@ #include +AWS_PUSH_SANE_WARNING_LEVEL + /** * Represents a length-delimited binary string or buffer. If byte buffer points * to constant memory or memory that should otherwise not be freed by this @@ -948,5 +950,6 @@ AWS_COMMON_API int aws_byte_cursor_utf8_parse_u64_hex(struct aws_byte_cursor cursor, uint64_t *dst); AWS_EXTERN_C_END +AWS_POP_SANE_WARNING_LEVEL #endif /* AWS_COMMON_BYTE_BUF_H */ diff --git a/include/aws/common/byte_order.h b/include/aws/common/byte_order.h index efd59d60b..b42f7a666 100644 --- a/include/aws/common/byte_order.h +++ b/include/aws/common/byte_order.h @@ -8,6 +8,7 @@ #include +AWS_PUSH_SANE_WARNING_LEVEL AWS_EXTERN_C_BEGIN /** @@ -70,5 +71,6 @@ AWS_STATIC_IMPL uint16_t aws_ntoh16(uint16_t x); #endif /* AWS_NO_STATIC_IMPL */ AWS_EXTERN_C_END +AWS_POP_SANE_WARNING_LEVEL #endif /* AWS_COMMON_BYTE_ORDER_H */ diff --git a/include/aws/common/cache.h b/include/aws/common/cache.h index f41e6d694..dfac0de6d 100644 --- a/include/aws/common/cache.h +++ b/include/aws/common/cache.h @@ -7,6 +7,8 @@ #include +AWS_PUSH_SANE_WARNING_LEVEL + struct aws_cache; struct aws_cache_vtable { @@ -80,5 +82,6 @@ AWS_COMMON_API size_t aws_cache_get_element_count(const struct aws_cache *cache); AWS_EXTERN_C_END +AWS_POP_SANE_WARNING_LEVEL #endif /* AWS_COMMON_CACHE_H */ diff --git a/include/aws/common/clock.h b/include/aws/common/clock.h index 68b202f1b..f1ca14877 100644 --- a/include/aws/common/clock.h +++ b/include/aws/common/clock.h @@ -9,6 +9,8 @@ #include #include +AWS_PUSH_SANE_WARNING_LEVEL + enum aws_timestamp_unit { AWS_TIMESTAMP_SECS = 1, AWS_TIMESTAMP_MILLIS = 1000, @@ -57,5 +59,6 @@ int aws_sys_clock_get_ticks(uint64_t *timestamp); #endif /* AWS_NO_STATIC_IMPL */ AWS_EXTERN_C_END +AWS_POP_SANE_WARNING_LEVEL #endif /* AWS_COMMON_CLOCK_H */ diff --git a/include/aws/common/command_line_parser.h b/include/aws/common/command_line_parser.h index 4e7454057..0f7523c8a 100644 --- a/include/aws/common/command_line_parser.h +++ b/include/aws/common/command_line_parser.h @@ -6,6 +6,8 @@ */ #include +AWS_PUSH_SANE_WARNING_LEVEL + enum aws_cli_options_has_arg { AWS_CLI_OPTIONS_NO_ARGUMENT = 0, AWS_CLI_OPTIONS_REQUIRED_ARGUMENT = 1, @@ -101,5 +103,6 @@ AWS_COMMON_API int aws_cli_dispatch_on_subcommand( int table_length, void *user_data); AWS_EXTERN_C_END +AWS_POP_SANE_WARNING_LEVEL #endif /* AWS_COMMON_COMMAND_LINE_PARSER_H */ diff --git a/include/aws/common/common.h b/include/aws/common/common.h index ce09ef226..b378a4f90 100644 --- a/include/aws/common/common.h +++ b/include/aws/common/common.h @@ -23,6 +23,7 @@ #include /* for abort() */ #include +AWS_PUSH_SANE_WARNING_LEVEL AWS_EXTERN_C_BEGIN /** @@ -42,5 +43,6 @@ AWS_COMMON_API void aws_common_fatal_assert_library_initialized(void); AWS_EXTERN_C_END +AWS_POP_SANE_WARNING_LEVEL #endif /* AWS_COMMON_COMMON_H */ diff --git a/include/aws/common/condition_variable.h b/include/aws/common/condition_variable.h index e78ceea16..317dedb9c 100644 --- a/include/aws/common/condition_variable.h +++ b/include/aws/common/condition_variable.h @@ -11,6 +11,8 @@ # include #endif +AWS_PUSH_SANE_WARNING_LEVEL + struct aws_mutex; struct aws_condition_variable; @@ -108,4 +110,6 @@ int aws_condition_variable_wait_for_pred( void *pred_ctx); AWS_EXTERN_C_END +AWS_POP_SANE_WARNING_LEVEL + #endif /* AWS_COMMON_CONDITION_VARIABLE_H */ diff --git a/include/aws/common/cpuid.h b/include/aws/common/cpuid.h index 8b3ec883b..6f9540d05 100644 --- a/include/aws/common/cpuid.h +++ b/include/aws/common/cpuid.h @@ -7,6 +7,8 @@ #include +AWS_PUSH_SANE_WARNING_LEVEL + enum aws_cpu_feature_name { AWS_CPU_FEATURE_CLMUL, AWS_CPU_FEATURE_SSE_4_1, @@ -25,5 +27,6 @@ AWS_EXTERN_C_BEGIN AWS_COMMON_API bool aws_cpu_has_feature(enum aws_cpu_feature_name feature_name); AWS_EXTERN_C_END +AWS_POP_SANE_WARNING_LEVEL #endif /* AWS_COMMON_CPUID_H */ diff --git a/include/aws/common/date_time.h b/include/aws/common/date_time.h index 40d83f864..1e38fa7d5 100644 --- a/include/aws/common/date_time.h +++ b/include/aws/common/date_time.h @@ -8,6 +8,8 @@ #include +AWS_PUSH_SANE_WARNING_LEVEL + #define AWS_DATE_TIME_STR_MAX_LEN 100 #define AWS_DATE_TIME_STR_MAX_BASIC_LEN 20 @@ -155,5 +157,6 @@ AWS_COMMON_API bool aws_date_time_dst(const struct aws_date_time *dt, bool local AWS_COMMON_API time_t aws_date_time_diff(const struct aws_date_time *a, const struct aws_date_time *b); AWS_EXTERN_C_END +AWS_POP_SANE_WARNING_LEVEL #endif /* AWS_COMMON_DATE_TIME_H */ diff --git a/include/aws/common/device_random.h b/include/aws/common/device_random.h index 5c25d9f84..6336f635d 100644 --- a/include/aws/common/device_random.h +++ b/include/aws/common/device_random.h @@ -6,6 +6,8 @@ */ #include +AWS_PUSH_SANE_WARNING_LEVEL + struct aws_byte_buf; AWS_EXTERN_C_BEGIN @@ -43,5 +45,6 @@ AWS_COMMON_API int aws_device_random_buffer(struct aws_byte_buf *output); AWS_COMMON_API int aws_device_random_buffer_append(struct aws_byte_buf *output, size_t n); AWS_EXTERN_C_END +AWS_POP_SANE_WARNING_LEVEL #endif /* AWS_COMMON_DEVICE_RANDOM_H */ diff --git a/include/aws/common/encoding.h b/include/aws/common/encoding.h index b707c70be..b5f4d88e3 100644 --- a/include/aws/common/encoding.h +++ b/include/aws/common/encoding.h @@ -12,6 +12,7 @@ #include +AWS_PUSH_SANE_WARNING_LEVEL AWS_EXTERN_C_BEGIN /* @@ -228,5 +229,6 @@ AWS_COMMON_API int aws_utf8_decoder_finalize(struct aws_utf8_decoder *decoder); #endif /* AWS_NO_STATIC_IMPL */ AWS_EXTERN_C_END +AWS_POP_SANE_WARNING_LEVEL #endif /* AWS_COMMON_ENCODING_H */ diff --git a/include/aws/common/environment.h b/include/aws/common/environment.h index c11bac3ad..ae712548e 100644 --- a/include/aws/common/environment.h +++ b/include/aws/common/environment.h @@ -8,6 +8,8 @@ #include +AWS_PUSH_SANE_WARNING_LEVEL + struct aws_string; /* @@ -42,5 +44,6 @@ AWS_COMMON_API int aws_unset_environment_value(const struct aws_string *variable_name); AWS_EXTERN_C_END +AWS_POP_SANE_WARNING_LEVEL #endif /* AWS_COMMON_ENVIRONMENT_H */ diff --git a/include/aws/common/error.h b/include/aws/common/error.h index 00aa5f8bc..8fd0b4360 100644 --- a/include/aws/common/error.h +++ b/include/aws/common/error.h @@ -12,6 +12,8 @@ #include #include +AWS_PUSH_SANE_WARNING_LEVEL + #define AWS_OP_SUCCESS (0) #define AWS_OP_ERR (-1) @@ -202,4 +204,6 @@ enum aws_common_error { AWS_ERROR_END_COMMON_RANGE = AWS_ERROR_ENUM_END_RANGE(AWS_C_COMMON_PACKAGE_ID) }; +AWS_POP_SANE_WARNING_LEVEL + #endif /* AWS_COMMON_ERROR_H */ diff --git a/include/aws/common/fifo_cache.h b/include/aws/common/fifo_cache.h index d81a21595..44127aa65 100644 --- a/include/aws/common/fifo_cache.h +++ b/include/aws/common/fifo_cache.h @@ -7,6 +7,7 @@ #include +AWS_PUSH_SANE_WARNING_LEVEL AWS_EXTERN_C_BEGIN /** @@ -25,5 +26,6 @@ struct aws_cache *aws_cache_new_fifo( size_t max_items); AWS_EXTERN_C_END +AWS_POP_SANE_WARNING_LEVEL #endif /* AWS_COMMON_FIFO_CACHE_H */ diff --git a/include/aws/common/file.h b/include/aws/common/file.h index 37f474faf..842b777d8 100644 --- a/include/aws/common/file.h +++ b/include/aws/common/file.h @@ -9,6 +9,8 @@ #include #include +AWS_PUSH_SANE_WARNING_LEVEL + #ifdef AWS_OS_WINDOWS # define AWS_PATH_DELIM '\\' # define AWS_PATH_DELIM_STR "\\" @@ -204,5 +206,6 @@ AWS_COMMON_API int aws_file_get_length(FILE *file, int64_t *length); AWS_EXTERN_C_END +AWS_POP_SANE_WARNING_LEVEL #endif /* AWS_COMMON_FILE_H */ diff --git a/include/aws/common/hash_table.h b/include/aws/common/hash_table.h index 8135a1549..370b1c38d 100644 --- a/include/aws/common/hash_table.h +++ b/include/aws/common/hash_table.h @@ -10,6 +10,8 @@ #include +AWS_PUSH_SANE_WARNING_LEVEL + #define AWS_COMMON_HASH_TABLE_ITER_CONTINUE (1 << 0) #define AWS_COMMON_HASH_TABLE_ITER_DELETE (1 << 1) #define AWS_COMMON_HASH_TABLE_ITER_ERROR (1 << 2) @@ -429,5 +431,6 @@ AWS_COMMON_API bool aws_hash_iter_is_valid(const struct aws_hash_iter *iter); AWS_EXTERN_C_END +AWS_POP_SANE_WARNING_LEVEL #endif /* AWS_COMMON_HASH_TABLE_H */ diff --git a/include/aws/common/json.h b/include/aws/common/json.h index e8a5f476d..b614387c0 100644 --- a/include/aws/common/json.h +++ b/include/aws/common/json.h @@ -9,6 +9,8 @@ #include #include +AWS_PUSH_SANE_WARNING_LEVEL + struct aws_json_value; AWS_EXTERN_C_BEGIN @@ -415,5 +417,6 @@ struct aws_json_value *aws_json_value_new_from_string(struct aws_allocator *allo // ==================== AWS_EXTERN_C_END +AWS_POP_SANE_WARNING_LEVEL #endif // AWS_COMMON_JSON_H diff --git a/include/aws/common/lifo_cache.h b/include/aws/common/lifo_cache.h index 04911cfee..cd547fed7 100644 --- a/include/aws/common/lifo_cache.h +++ b/include/aws/common/lifo_cache.h @@ -7,6 +7,7 @@ #include +AWS_PUSH_SANE_WARNING_LEVEL AWS_EXTERN_C_BEGIN /** @@ -25,5 +26,6 @@ struct aws_cache *aws_cache_new_lifo( size_t max_items); AWS_EXTERN_C_END +AWS_POP_SANE_WARNING_LEVEL #endif /* AWS_COMMON_LIFO_CACHE_H */ diff --git a/include/aws/common/linked_hash_table.h b/include/aws/common/linked_hash_table.h index ba17c9799..d7fd3c88b 100644 --- a/include/aws/common/linked_hash_table.h +++ b/include/aws/common/linked_hash_table.h @@ -7,6 +7,8 @@ #include #include +AWS_PUSH_SANE_WARNING_LEVEL + /** * Simple linked hash table. Preserves insertion order, and can be iterated in insertion order. * @@ -118,5 +120,6 @@ AWS_COMMON_API const struct aws_linked_list *aws_linked_hash_table_get_iteration_list(const struct aws_linked_hash_table *table); AWS_EXTERN_C_END +AWS_POP_SANE_WARNING_LEVEL #endif /* AWS_COMMON_LINKED_HASH_TABLE_H */ diff --git a/include/aws/common/linked_list.h b/include/aws/common/linked_list.h index e4c3be963..3f550c6fe 100644 --- a/include/aws/common/linked_list.h +++ b/include/aws/common/linked_list.h @@ -10,6 +10,8 @@ #include +AWS_PUSH_SANE_WARNING_LEVEL + struct aws_linked_list_node { struct aws_linked_list_node *next; struct aws_linked_list_node *prev; @@ -184,5 +186,6 @@ AWS_STATIC_IMPL void aws_linked_list_move_all_front( # include #endif /* AWS_NO_STATIC_IMPL */ AWS_EXTERN_C_END +AWS_POP_SANE_WARNING_LEVEL #endif /* AWS_COMMON_LINKED_LIST_H */ diff --git a/include/aws/common/linked_list.inl b/include/aws/common/linked_list.inl index 5a3547570..99604834a 100644 --- a/include/aws/common/linked_list.inl +++ b/include/aws/common/linked_list.inl @@ -39,7 +39,7 @@ AWS_STATIC_IMPL bool aws_linked_list_empty(const struct aws_linked_list *list) { */ AWS_STATIC_IMPL bool aws_linked_list_is_valid(const struct aws_linked_list *list) { if (list && list->head.next && list->head.prev == NULL && list->tail.prev && list->tail.next == NULL) { -#if (AWS_DEEP_CHECKS == 1) +#if defined(AWS_DEEP_CHECKS) && (AWS_DEEP_CHECKS == 1) return aws_linked_list_is_valid_deep(list); #else return true; diff --git a/include/aws/common/log_channel.h b/include/aws/common/log_channel.h index c50f3264b..b6e1f0fc3 100644 --- a/include/aws/common/log_channel.h +++ b/include/aws/common/log_channel.h @@ -11,6 +11,8 @@ #include +AWS_PUSH_SANE_WARNING_LEVEL + struct aws_string; struct aws_log_writer; @@ -68,5 +70,6 @@ AWS_COMMON_API void aws_log_channel_clean_up(struct aws_log_channel *channel); AWS_EXTERN_C_END +AWS_POP_SANE_WARNING_LEVEL #endif /* AWS_COMMON_LOG_CHANNEL_H */ diff --git a/include/aws/common/log_formatter.h b/include/aws/common/log_formatter.h index 995fd7e0e..f76045562 100644 --- a/include/aws/common/log_formatter.h +++ b/include/aws/common/log_formatter.h @@ -15,6 +15,8 @@ #include #include +AWS_PUSH_SANE_WARNING_LEVEL + struct aws_allocator; struct aws_string; @@ -91,5 +93,6 @@ AWS_COMMON_API int aws_format_standard_log_line(struct aws_logging_standard_formatting_data *formatting_data, va_list args); AWS_EXTERN_C_END +AWS_POP_SANE_WARNING_LEVEL #endif /* AWS_COMMON_LOG_FORMATTER_H */ diff --git a/include/aws/common/log_writer.h b/include/aws/common/log_writer.h index da016a2b6..54fb98358 100644 --- a/include/aws/common/log_writer.h +++ b/include/aws/common/log_writer.h @@ -9,6 +9,8 @@ #include +AWS_PUSH_SANE_WARNING_LEVEL + struct aws_allocator; struct aws_string; @@ -69,5 +71,6 @@ AWS_COMMON_API void aws_log_writer_clean_up(struct aws_log_writer *writer); AWS_EXTERN_C_END +AWS_POP_SANE_WARNING_LEVEL #endif /* AWS_COMMON_LOG_WRITER_H */ diff --git a/include/aws/common/logging.h b/include/aws/common/logging.h index e5fbe8858..87b956811 100644 --- a/include/aws/common/logging.h +++ b/include/aws/common/logging.h @@ -10,6 +10,8 @@ #include #include +AWS_PUSH_SANE_WARNING_LEVEL + #define AWS_LOG_LEVEL_NONE 0 #define AWS_LOG_LEVEL_FATAL 1 #define AWS_LOG_LEVEL_ERROR 2 @@ -94,6 +96,13 @@ struct aws_log_formatter; struct aws_log_channel; struct aws_log_writer; +#ifdef _MSC_VER +# pragma warning(push) +# pragma warning(disable : 4623) /* default constructor was implicitly defined as deleted */ +# pragma warning(disable : 4626) /* assignment operator was implicitly defined as deleted */ +# pragma warning(disable : 5027) /* move assignment operator was implicitly defined as deleted */ +#endif + /** * We separate the log level function from the log call itself so that we can do the filter check in the macros (see * below) @@ -117,6 +126,10 @@ struct aws_logger_vtable { int (*set_log_level)(struct aws_logger *logger, enum aws_log_level); }; +#ifdef _MSC_VER +# pragma warning(pop) +#endif + struct aws_logger { struct aws_logger_vtable *vtable; struct aws_allocator *allocator; @@ -339,5 +352,6 @@ int aws_logger_init_noalloc( struct aws_logger_standard_options *options); AWS_EXTERN_C_END +AWS_POP_SANE_WARNING_LEVEL #endif /* AWS_COMMON_LOGGING_H */ diff --git a/include/aws/common/lru_cache.h b/include/aws/common/lru_cache.h index 37eff525f..b99551a79 100644 --- a/include/aws/common/lru_cache.h +++ b/include/aws/common/lru_cache.h @@ -7,6 +7,7 @@ #include +AWS_PUSH_SANE_WARNING_LEVEL AWS_EXTERN_C_BEGIN /** @@ -38,5 +39,6 @@ AWS_COMMON_API void *aws_lru_cache_get_mru_element(const struct aws_cache *cache); AWS_EXTERN_C_END +AWS_POP_SANE_WARNING_LEVEL #endif /* AWS_COMMON_LRU_CACHE_H */ diff --git a/include/aws/common/macros.h b/include/aws/common/macros.h index f0758354f..0b0b8b667 100644 --- a/include/aws/common/macros.h +++ b/include/aws/common/macros.h @@ -5,6 +5,27 @@ * SPDX-License-Identifier: Apache-2.0. */ +/* clang-format off */ + +/* Use these macros in public header files to suppress unreasonable compiler + * warnings. Public header files are included by external applications, + * which may set their warning levels pedantically high. + * + * Developers of AWS libraries should hesitate before adding more warnings to this macro. + * Prefer disabling the warning within a .c file, or in the library's CFLAGS, + * or push/pop the warning around a single problematic declaration. */ +#if defined(_MSC_VER) +# define AWS_PUSH_SANE_WARNING_LEVEL \ + __pragma(warning(push)) \ + __pragma(warning(disable : 4820)) /* padding added to struct */ \ + __pragma(warning(disable : 4514)) /* unreferenced inline function has been removed */ +# define AWS_POP_SANE_WARNING_LEVEL __pragma(warning(pop)) +#else +# define AWS_PUSH_SANE_WARNING_LEVEL +# define AWS_POP_SANE_WARNING_LEVEL +#endif +/* clang-format on */ + #ifdef __cplusplus # define AWS_EXTERN_C_BEGIN extern "C" { # define AWS_EXTERN_C_END } diff --git a/include/aws/common/math.h b/include/aws/common/math.h index 2473dcf5e..7d0f97b61 100644 --- a/include/aws/common/math.h +++ b/include/aws/common/math.h @@ -12,6 +12,8 @@ #include #include +AWS_PUSH_SANE_WARNING_LEVEL + /* The number of bits in a size_t variable */ #if SIZE_MAX == UINT32_MAX # define SIZE_BITS 32 @@ -203,5 +205,6 @@ AWS_STATIC_IMPL double aws_max_double(double a, double b); #endif /* AWS_NO_STATIC_IMPL */ AWS_EXTERN_C_END +AWS_POP_SANE_WARNING_LEVEL #endif /* AWS_COMMON_MATH_H */ diff --git a/include/aws/common/math.msvc.inl b/include/aws/common/math.msvc.inl index 0aad29e8e..c41fac562 100644 --- a/include/aws/common/math.msvc.inl +++ b/include/aws/common/math.msvc.inl @@ -14,8 +14,10 @@ #include #include -#include +/* This file generates level 4 compiler warnings in Visual Studio 2017 and older */ +#pragma warning(push, 3) #include +#pragma warning(pop) AWS_EXTERN_C_BEGIN /** @@ -194,7 +196,7 @@ AWS_STATIC_IMPL size_t aws_clz_u32(uint32_t n) { AWS_STATIC_IMPL size_t aws_clz_i32(int32_t n) { unsigned long idx = 0; - if (_BitScanReverse(&idx, n)) { + if (_BitScanReverse(&idx, (unsigned long)n)) { return 31 - idx; } return 32; @@ -210,7 +212,7 @@ AWS_STATIC_IMPL size_t aws_clz_u64(uint64_t n) { AWS_STATIC_IMPL size_t aws_clz_i64(int64_t n) { unsigned long idx = 0; - if (_BitScanReverse64(&idx, n)) { + if (_BitScanReverse64(&idx, (uint64_t)n)) { return 63 - idx; } return 64; @@ -237,7 +239,7 @@ AWS_STATIC_IMPL size_t aws_ctz_u32(uint32_t n) { AWS_STATIC_IMPL size_t aws_ctz_i32(int32_t n) { unsigned long idx = 0; - if (_BitScanForward(&idx, n)) { + if (_BitScanForward(&idx, (uint32_t)n)) { return idx; } return 32; @@ -253,7 +255,7 @@ AWS_STATIC_IMPL size_t aws_ctz_u64(uint64_t n) { AWS_STATIC_IMPL size_t aws_ctz_i64(int64_t n) { unsigned long idx = 0; - if (_BitScanForward64(&idx, n)) { + if (_BitScanForward64(&idx, (uint64_t)n)) { return idx; } return 64; diff --git a/include/aws/common/mutex.h b/include/aws/common/mutex.h index edb91864a..b64e5e32f 100644 --- a/include/aws/common/mutex.h +++ b/include/aws/common/mutex.h @@ -14,6 +14,8 @@ # include #endif +AWS_PUSH_SANE_WARNING_LEVEL + struct aws_mutex { #ifdef _WIN32 void *mutex_handle; @@ -69,5 +71,6 @@ AWS_COMMON_API int aws_mutex_unlock(struct aws_mutex *mutex); AWS_EXTERN_C_END +AWS_POP_SANE_WARNING_LEVEL #endif /* AWS_COMMON_MUTEX_H */ diff --git a/include/aws/common/predicates.h b/include/aws/common/predicates.h index e085c48f9..ca05692c0 100644 --- a/include/aws/common/predicates.h +++ b/include/aws/common/predicates.h @@ -8,7 +8,7 @@ /** * Returns whether all bytes of the two byte arrays match. */ -#if (AWS_DEEP_CHECKS == 1) +#if defined(AWS_DEEP_CHECKS) && (AWS_DEEP_CHECKS == 1) # ifdef CBMC /* clang-format off */ # define AWS_BYTES_EQ(arr1, arr2, len) \ diff --git a/include/aws/common/priority_queue.h b/include/aws/common/priority_queue.h index a4df8c506..4478b95d0 100644 --- a/include/aws/common/priority_queue.h +++ b/include/aws/common/priority_queue.h @@ -8,6 +8,8 @@ #include #include +AWS_PUSH_SANE_WARNING_LEVEL + /* The comparator should return a positive value if the second argument has a * higher priority than the first; Otherwise, it should return a negative value * or zero. NOTE: priority_queue pops its highest priority element first. For @@ -174,5 +176,6 @@ AWS_COMMON_API size_t aws_priority_queue_capacity(const struct aws_priority_queue *queue); AWS_EXTERN_C_END +AWS_POP_SANE_WARNING_LEVEL #endif /* AWS_COMMON_PRIORITY_QUEUE_H */ diff --git a/include/aws/common/process.h b/include/aws/common/process.h index 385d95362..df9188eec 100644 --- a/include/aws/common/process.h +++ b/include/aws/common/process.h @@ -7,6 +7,8 @@ #include +AWS_PUSH_SANE_WARNING_LEVEL + struct aws_run_command_result { /* return code from running the command. */ int ret_code; @@ -77,5 +79,6 @@ AWS_COMMON_API int aws_run_command( struct aws_run_command_result *result); AWS_EXTERN_C_END +AWS_POP_SANE_WARNING_LEVEL #endif /* AWS_COMMON_PROCESS_H */ diff --git a/include/aws/common/promise.h b/include/aws/common/promise.h index e19d858c7..37f930ee1 100644 --- a/include/aws/common/promise.h +++ b/include/aws/common/promise.h @@ -8,12 +8,17 @@ #include +AWS_PUSH_SANE_WARNING_LEVEL + /* * Standard promise interface. Promise can be waited on by multiple threads, and as long as it is * ref-counted correctly, will provide the resultant value/error code to all waiters. * All promise API calls are internally thread-safe. */ struct aws_promise; + +AWS_EXTERN_C_BEGIN + /* * Creates a new promise */ @@ -92,4 +97,7 @@ void *aws_promise_value(struct aws_promise *promise); AWS_COMMON_API void *aws_promise_take_value(struct aws_promise *promise); +AWS_EXTERN_C_END +AWS_POP_SANE_WARNING_LEVEL + #endif // AWS_COMMON_PROMISE_H diff --git a/include/aws/common/ref_count.h b/include/aws/common/ref_count.h index 596ec2c49..5166eb3f3 100644 --- a/include/aws/common/ref_count.h +++ b/include/aws/common/ref_count.h @@ -9,6 +9,8 @@ #include +AWS_PUSH_SANE_WARNING_LEVEL + typedef void(aws_simple_completion_callback)(void *); /* @@ -55,5 +57,6 @@ AWS_COMMON_API void *aws_ref_count_acquire(struct aws_ref_count *ref_count); AWS_COMMON_API size_t aws_ref_count_release(struct aws_ref_count *ref_count); AWS_EXTERN_C_END +AWS_POP_SANE_WARNING_LEVEL #endif /* AWS_COMMON_REF_COUNT_H */ diff --git a/include/aws/common/ring_buffer.h b/include/aws/common/ring_buffer.h index d2921dbff..24cddd09f 100644 --- a/include/aws/common/ring_buffer.h +++ b/include/aws/common/ring_buffer.h @@ -7,6 +7,8 @@ #include +AWS_PUSH_SANE_WARNING_LEVEL + /** * Lockless ring buffer implementation that is thread safe assuming a single thread acquires and a single thread * releases. For any other use case (other than the single-threaded use-case), you must manage thread-safety manually. @@ -96,5 +98,6 @@ AWS_COMMON_API bool aws_ring_buffer_buf_belongs_to_pool( #endif /* AWS_NO_STATIC_IMPL */ AWS_EXTERN_C_END +AWS_POP_SANE_WARNING_LEVEL #endif /* AWS_COMMON_RING_BUFFER_H */ diff --git a/include/aws/common/rw_lock.h b/include/aws/common/rw_lock.h index 01c257dfb..f8d86ae2a 100644 --- a/include/aws/common/rw_lock.h +++ b/include/aws/common/rw_lock.h @@ -14,6 +14,8 @@ # include #endif +AWS_PUSH_SANE_WARNING_LEVEL + struct aws_rw_lock { #ifdef _WIN32 void *lock_handle; @@ -66,5 +68,6 @@ AWS_COMMON_API int aws_rw_lock_runlock(struct aws_rw_lock *lock); AWS_COMMON_API int aws_rw_lock_wunlock(struct aws_rw_lock *lock); AWS_EXTERN_C_END +AWS_POP_SANE_WARNING_LEVEL #endif /* AWS_COMMON_RW_LOCK_H */ diff --git a/include/aws/common/statistics.h b/include/aws/common/statistics.h index 712eebe68..3ad06a429 100644 --- a/include/aws/common/statistics.h +++ b/include/aws/common/statistics.h @@ -11,6 +11,8 @@ #include +AWS_PUSH_SANE_WARNING_LEVEL + struct aws_array_list; typedef uint32_t aws_crt_statistics_category_t; @@ -136,5 +138,6 @@ AWS_COMMON_API void aws_crt_statistics_handler_destroy(struct aws_crt_statistics_handler *handler); AWS_EXTERN_C_END +AWS_POP_SANE_WARNING_LEVEL #endif /* AWS_COMMON_STATISTICS_H */ diff --git a/include/aws/common/string.h b/include/aws/common/string.h index fbc513911..da4482abf 100644 --- a/include/aws/common/string.h +++ b/include/aws/common/string.h @@ -7,6 +7,8 @@ #include #include +AWS_PUSH_SANE_WARNING_LEVEL + /** * Represents an immutable string holding either text or binary data. If the * string is in constant memory or memory that should otherwise not be freed by @@ -36,7 +38,9 @@ */ #ifdef _MSC_VER # pragma warning(push) -# pragma warning(disable : 4200) +# pragma warning(disable : 4623) /* default constructor was implicitly defined as deleted */ +# pragma warning(disable : 4626) /* assignment operator was implicitly defined as deleted */ +# pragma warning(disable : 5027) /* move assignment operator was implicitly defined as deleted */ #endif struct aws_string { struct aws_allocator *const allocator; @@ -374,5 +378,6 @@ bool aws_char_is_space(uint8_t c); #endif /* AWS_NO_STATIC_IMPL */ AWS_EXTERN_C_END +AWS_POP_SANE_WARNING_LEVEL #endif /* AWS_COMMON_STRING_H */ diff --git a/include/aws/common/system_info.h b/include/aws/common/system_info.h index 5b6600e93..fe7604120 100644 --- a/include/aws/common/system_info.h +++ b/include/aws/common/system_info.h @@ -8,6 +8,8 @@ #include +AWS_PUSH_SANE_WARNING_LEVEL + enum aws_platform_os { AWS_PLATFORM_OS_WINDOWS, AWS_PLATFORM_OS_MAC, @@ -101,5 +103,6 @@ AWS_COMMON_API void aws_backtrace_log(int log_level); AWS_EXTERN_C_END +AWS_POP_SANE_WARNING_LEVEL #endif /* AWS_COMMON_SYSTEM_INFO_H */ diff --git a/include/aws/common/task_scheduler.h b/include/aws/common/task_scheduler.h index 24a5cc60d..a51d6e41e 100644 --- a/include/aws/common/task_scheduler.h +++ b/include/aws/common/task_scheduler.h @@ -10,6 +10,8 @@ #include #include +AWS_PUSH_SANE_WARNING_LEVEL + struct aws_task; typedef enum aws_task_status { @@ -125,5 +127,6 @@ AWS_COMMON_API const char *aws_task_status_to_c_str(enum aws_task_status status); AWS_EXTERN_C_END +AWS_POP_SANE_WARNING_LEVEL #endif /* AWS_COMMON_TASK_SCHEDULER_H */ diff --git a/include/aws/common/thread.h b/include/aws/common/thread.h index 5b3014288..90f0bc363 100644 --- a/include/aws/common/thread.h +++ b/include/aws/common/thread.h @@ -12,6 +12,8 @@ # include #endif +AWS_PUSH_SANE_WARNING_LEVEL + enum aws_thread_detach_state { AWS_THREAD_NOT_CREATED = 1, AWS_THREAD_JOINABLE, @@ -264,5 +266,6 @@ AWS_COMMON_API int aws_thread_name( struct aws_string **out_name); AWS_EXTERN_C_END +AWS_POP_SANE_WARNING_LEVEL #endif /* AWS_COMMON_THREAD_H */ diff --git a/include/aws/common/thread_scheduler.h b/include/aws/common/thread_scheduler.h index 5457aa2d7..039773d20 100644 --- a/include/aws/common/thread_scheduler.h +++ b/include/aws/common/thread_scheduler.h @@ -7,6 +7,8 @@ #include +AWS_PUSH_SANE_WARNING_LEVEL + struct aws_thread_scheduler; struct aws_thread_options; struct aws_task; @@ -56,5 +58,6 @@ AWS_COMMON_API void aws_thread_scheduler_schedule_now(struct aws_thread_schedule AWS_COMMON_API void aws_thread_scheduler_cancel_task(struct aws_thread_scheduler *scheduler, struct aws_task *task); AWS_EXTERN_C_END +AWS_POP_SANE_WARNING_LEVEL #endif /* AWS_COMMON_THREAD_SCHEDULER_H */ diff --git a/include/aws/common/time.h b/include/aws/common/time.h index 6ea6c9c75..f5cfe31ad 100644 --- a/include/aws/common/time.h +++ b/include/aws/common/time.h @@ -8,6 +8,7 @@ #include +AWS_PUSH_SANE_WARNING_LEVEL AWS_EXTERN_C_BEGIN /** @@ -26,5 +27,6 @@ AWS_COMMON_API void aws_localtime(time_t time, struct tm *t); AWS_COMMON_API void aws_gmtime(time_t time, struct tm *t); AWS_EXTERN_C_END +AWS_POP_SANE_WARNING_LEVEL #endif /* AWS_COMMON_TIME_H */ diff --git a/include/aws/common/uri.h b/include/aws/common/uri.h index 9677276b8..0ac1fd9b3 100644 --- a/include/aws/common/uri.h +++ b/include/aws/common/uri.h @@ -7,6 +7,8 @@ #include +AWS_PUSH_SANE_WARNING_LEVEL + /** * Data representing a URI. uri_str is always allocated and filled in. * The other portions are merely storing offsets into uri_str. @@ -158,5 +160,6 @@ AWS_COMMON_API int aws_byte_buf_append_encoding_uri_param( AWS_COMMON_API int aws_byte_buf_append_decoding_uri(struct aws_byte_buf *buffer, const struct aws_byte_cursor *cursor); AWS_EXTERN_C_END +AWS_POP_SANE_WARNING_LEVEL #endif /* AWS_COMMON_URI_H */ diff --git a/include/aws/common/uuid.h b/include/aws/common/uuid.h index a8677c581..4bd92c832 100644 --- a/include/aws/common/uuid.h +++ b/include/aws/common/uuid.h @@ -7,6 +7,8 @@ */ #include +AWS_PUSH_SANE_WARNING_LEVEL + struct aws_byte_cursor; struct aws_byte_buf; @@ -25,5 +27,6 @@ AWS_COMMON_API int aws_uuid_to_str(const struct aws_uuid *uuid, struct aws_byte_ AWS_COMMON_API bool aws_uuid_equals(const struct aws_uuid *a, const struct aws_uuid *b); AWS_EXTERN_C_END +AWS_POP_SANE_WARNING_LEVEL #endif /* AWS_COMMON_UUID_H */ diff --git a/include/aws/common/xml_parser.h b/include/aws/common/xml_parser.h index 4e089ca2c..542a72bec 100644 --- a/include/aws/common/xml_parser.h +++ b/include/aws/common/xml_parser.h @@ -11,6 +11,8 @@ #include +AWS_PUSH_SANE_WARNING_LEVEL + struct aws_xml_parser; struct aws_xml_node; @@ -104,5 +106,6 @@ int aws_xml_node_get_attribute( struct aws_xml_attribute *out_attribute); AWS_EXTERN_C_END +AWS_POP_SANE_WARNING_LEVEL #endif /* AWS_COMMON_XML_PARSER_H */ diff --git a/include/aws/common/zero.h b/include/aws/common/zero.h index 5c5be2d6d..e83cf454b 100644 --- a/include/aws/common/zero.h +++ b/include/aws/common/zero.h @@ -11,6 +11,7 @@ #include +AWS_PUSH_SANE_WARNING_LEVEL AWS_EXTERN_C_BEGIN /** @@ -60,5 +61,6 @@ void aws_secure_zero(void *pBuf, size_t bufsize); #endif /* AWS_NO_STATIC_IMPL */ AWS_EXTERN_C_END +AWS_POP_SANE_WARNING_LEVEL #endif /* AWS_COMMON_ZERO_H */ diff --git a/include/aws/testing/aws_test_harness.h b/include/aws/testing/aws_test_harness.h index 295e02be2..bcb3d26c6 100644 --- a/include/aws/testing/aws_test_harness.h +++ b/include/aws/testing/aws_test_harness.h @@ -36,6 +36,10 @@ the AWS_UNSTABLE_TESTING_API compiler flag # pragma warning(disable : 4204) /* non-constant aggregate initializer */ #endif +#if defined(__clang__) +# pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments" +#endif + /** Prints a message to AWS_TESTING_REPORT_FD using printf format that appends the function, file and line number. * If format is null, returns 0 without printing anything; otherwise returns 1. */ @@ -94,11 +98,11 @@ static int total_skip; printf("\n"); \ return SUCCESS; \ } while (0) -#define PRINT_FAIL_INTERNAL(...) \ - CUNIT_FAILURE_MESSAGE(__FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__, (const char *)NULL) + +#define PRINT_FAIL_INTERNAL(...) CUNIT_FAILURE_MESSAGE(__func__, __FILE__, __LINE__, ##__VA_ARGS__, (const char *)NULL) #define PRINT_FAIL_INTERNAL0(...) \ - s_cunit_failure_message0(FAIL_PREFIX, __FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__, (const char *)NULL) + s_cunit_failure_message0(FAIL_PREFIX, __func__, __FILE__, __LINE__, ##__VA_ARGS__, (const char *)NULL) #define POSTFAIL_INTERNAL() \ do { \ diff --git a/source/array_list.c b/source/array_list.c index 45c8a3cc7..b6ea5a090 100644 --- a/source/array_list.c +++ b/source/array_list.c @@ -206,3 +206,11 @@ void aws_array_list_swap(struct aws_array_list *AWS_RESTRICT list, size_t a, siz aws_array_list_mem_swap(item1, item2, list->item_size); AWS_POSTCONDITION(aws_array_list_is_valid(list)); } + +void aws_array_list_sort(struct aws_array_list *AWS_RESTRICT list, aws_array_list_comparator_fn *compare_fn) { + AWS_PRECONDITION(aws_array_list_is_valid(list)); + if (list->data) { + qsort(list->data, aws_array_list_length(list), list->item_size, compare_fn); + } + AWS_POSTCONDITION(aws_array_list_is_valid(list)); +}