diff --git a/CMakeLists.txt b/CMakeLists.txt index b00ccb9c..ecf9d0d5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -134,6 +134,10 @@ endif() if(LINUX) set (CMAKE_C_FLAGS "-fPIC ${CMAKE_C_FLAGS}") set (CMAKE_CXX_FLAGS "-fPIC ${CMAKE_CXX_FLAGS}") +elseif(APPLE) + # Warnings as errors + set (CMAKE_C_FLAGS "-Werror ${CMAKE_C_FLAGS}") + set (CMAKE_CXX_FLAGS "-Werror ${CMAKE_CXX_FLAGS}") endif() function(add_module_to_solution undecoratedModuleName) @@ -197,9 +201,7 @@ endfunction(linkSharedUtil) include_directories(./deps/parson) function(link_broker whatIsBuilding) - -target_link_libraries(${whatIsBuilding} nanomsg ${NN_REQUIRED_LIBRARIES}) - + target_link_libraries(${whatIsBuilding} nanomsg ${NN_REQUIRED_LIBRARIES}) endfunction(link_broker) function(install_broker whatIsBuilding whatIsBuildingLocation) @@ -225,8 +227,6 @@ function(copy_gateway_dll whatIsBuilding whatIsBuildingLocation) "${azure_c_shared_utility_DIR}/../bin/${SHARED_UTIL_LIB}.dll" ${whatIsBuildingLocation}) endif() - - endif() endfunction(copy_gateway_dll) diff --git a/bindings/java/CMakeLists.txt b/bindings/java/CMakeLists.txt index df24e1f2..515ced83 100644 --- a/bindings/java/CMakeLists.txt +++ b/bindings/java/CMakeLists.txt @@ -65,6 +65,17 @@ elseif(LINUX) set(java_libs $ENV{JAVA_HOME}/jre/lib/${JDK_ARCH}/server/libjvm.so ) +elseif(APPLE) + set(java_include_dirs + $ENV{JAVA_HOME}/include + $ENV{JAVA_HOME}/include/darwin + ) + set(java_link_dirs + $ENV{JAVA_HOME}/jre/lib/server + ) + set(java_libs + $ENV{JAVA_HOME}/jre/lib/server/libjvm.dylib + ) endif() set(LIBS ${java_libs} gateway) diff --git a/bindings/java/src/java_module_host.c b/bindings/java/src/java_module_host.c index 40c6a4ba..bdea74f0 100644 --- a/bindings/java/src/java_module_host.c +++ b/bindings/java/src/java_module_host.c @@ -418,7 +418,7 @@ static void JavaModuleHost_Receive(MODULE_HANDLE module, MESSAGE_HANDLE message) else { /*Codes_SRS_JAVA_MODULE_HOST_14_044: [This function shall set the contents of the jbyteArray to the serialized_message.]*/ - JNIFunc(moduleHandle->env, SetByteArrayRegion, arr, 0, size, serialized_message); + JNIFunc(moduleHandle->env, SetByteArrayRegion, arr, 0, size, (jbyte*)serialized_message); jthrowable exception = JNIFunc(moduleHandle->env, ExceptionOccurred); if (exception) { @@ -564,7 +564,7 @@ JNIEXPORT jint JNICALL Java_com_microsoft_azure_gateway_core_Broker_publishMessa else { /*Codes_SRS_JAVA_MODULE_HOST_14_025: [This function shall convert the jbyteArray message into an unsigned char array.]*/ - JNIFunc(env, GetByteArrayRegion, serialized_message, 0, (jsize)length, arr); + JNIFunc(env, GetByteArrayRegion, serialized_message, 0, (jsize)length, (jbyte*)arr); jthrowable exception = JNIFunc(env, ExceptionOccurred); if (exception) { diff --git a/bindings/java/tests/host_ut/host_ut.c b/bindings/java/tests/host_ut/host_ut.c index 36fcb7ed..4898a27f 100644 --- a/bindings/java/tests/host_ut/host_ut.c +++ b/bindings/java/tests/host_ut/host_ut.c @@ -416,7 +416,7 @@ MOCK_FUNCTION_END(num) MOCK_FUNCTION_WITH_CODE(, const char*, json_array_get_string, const JSON_Array*, arr, size_t, index) const char* str = NULL; -if (arr != NULL && index >= 0) +if (arr != NULL) { str = "hello_world"; } diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 9e63a7a8..5f8dd9a4 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -5,7 +5,12 @@ cmake_minimum_required(VERSION 2.8.12) if(POLICY CMP0054) cmake_policy(SET CMP0054 OLD) endif() -cmake_policy(SET CMP0022 NEW) +if(POLICY CMP0022) + cmake_policy(SET CMP0022 NEW) +endif() +if(POLICY CMP0042) + cmake_policy(SET CMP0042 NEW) +endif() add_subdirectory(deps) @@ -16,19 +21,19 @@ set(GW_SRC ${CMAKE_CURRENT_LIST_DIR}/src CACHE INTERNAL "Needs to be included fo #setting the dynamic_loader file based on OS that it is used if(WIN32) include_directories(${GW_INC}/windows ) -elseif(LINUX) +elseif(UNIX) # LINUX or APPLE include_directories(${GW_INC}/linux) endif() #setting the dynamic_loader file based on OS that it is used if(WIN32) set(dynamic_library_c_file ./adapters/dynamic_library_windows.c ./adapters/gb_library_windows.c) -elseif(LINUX) +elseif(UNIX) # LINUX or APPLE set(dynamic_library_c_file ./adapters/dynamic_library_linux.c ./adapters/gb_library_linux.c ) endif() #setting specific libraries to be loaded based on OS (for example, Linux needs "-ldl", windows does not) -if(LINUX) +if(UNIX) # LINUX or APPLE set(dynamic_loader_library dl) endif() @@ -228,9 +233,17 @@ if(NOT ${use_xplat_uuid}) else() find_package(PkgConfig REQUIRED) pkg_search_module(UUID REQUIRED uuid) - target_link_libraries(gateway ${UUID_LIBRARIES}) - target_link_libraries(gateway_static ${UUID_LIBRARIES}) - target_link_libraries(module_host_static ${UUID_LIBRARIES}) + link_directories(${UUID_LIBRARY_DIRS}) + + if(APPLE) + target_link_libraries(gateway -L${UUID_LIBRARY_DIRS} ${UUID_LIBRARIES}) + target_link_libraries(gateway_static -L${UUID_LIBRARY_DIRS} ${UUID_LIBRARIES}) + target_link_libraries(module_host_static -L${UUID_LIBRARY_DIRS} ${UUID_LIBRARIES}) + elseif(LINUX) + target_link_libraries(gateway ${UUID_LIBRARIES}) + target_link_libraries(gateway_static ${UUID_LIBRARIES}) + target_link_libraries(module_host_static ${UUID_LIBRARIES}) + endif() endif() endif() diff --git a/core/src/control_message.c b/core/src/control_message.c index 582d0c66..bc120e99 100644 --- a/core/src/control_message.c +++ b/core/src/control_message.c @@ -19,7 +19,7 @@ DEFINE_ENUM_STRINGS(CONTROL_MESSAGE_TYPE, CONTROL_MESSAGE_TYPE_VALUES); #define BASE_CREATE_SIZE (BASE_MESSAGE_SIZE+10) #define BASE_CREATE_REPLY_SIZE (BASE_MESSAGE_SIZE+1) -static int parse_int32_t(const unsigned char* source, size_t sourceSize, size_t position, int32_t *parsed, int32_t* value) +static int parse_uint32_t(const unsigned char* source, size_t sourceSize, size_t position, int32_t *parsed, uint32_t* value) { int result; if (position + 4 > sourceSize) @@ -41,12 +41,12 @@ static int parse_int32_t(const unsigned char* source, size_t sourceSize, size_t return result; } -static int parse_memory_chunk(const unsigned char* source, size_t sourceSize, size_t position, int32_t *parsed, int32_t *size, unsigned char** value) +static int parse_memory_chunk(const unsigned char* source, size_t sourceSize, size_t position, int32_t *parsed, uint32_t *size, char** value) { int result; - int32_t chunk_size; + uint32_t chunk_size; int32_t current_parsed; - result = parse_int32_t(source, sourceSize, position, ¤t_parsed, &chunk_size); + result = parse_uint32_t(source, sourceSize, position, ¤t_parsed, &chunk_size); if (result == 0) { position += current_parsed; @@ -68,7 +68,7 @@ static int parse_memory_chunk(const unsigned char* source, size_t sourceSize, si else { /* allocate 1 more for null-termination */ - *value = (unsigned char *)malloc(chunk_size); + *value = (char *)malloc(chunk_size); if (*value == NULL) { LogError("unable to allocate memory chunk"); @@ -163,7 +163,7 @@ int parse_create_message(const unsigned char* source, size_t sourceSize, size_t position, ¤t_parsed, &(create_msg->args_size), - (unsigned char**)&(create_msg->args)) != 0) + &(create_msg->args)) != 0) { LogError("unable to parse a module args"); result = __LINE__; @@ -211,9 +211,9 @@ CONTROL_MESSAGE * ControlMessage_CreateFromByteArray(const unsigned char* source /*Codes_SRS_CONTROL_MESSAGE_17_005: [ This function shall read the version, type and size from the byte stream. ]*/ uint8_t messageVersion = (uint8_t)source[currentPosition++]; uint8_t messageType = (uint8_t)source[currentPosition++]; - int32_t messageSize; + uint32_t messageSize; /* we already know buffer is at least BASE_MESSAGE_SIZE - this will always return OK */ - (void)parse_int32_t(source, size, currentPosition, &parsed, &messageSize); + (void)parse_uint32_t(source, size, currentPosition, &parsed, &messageSize); currentPosition += parsed; /*Codes_SRS_CONTROL_MESSAGE_17_006: [ If the size embedded in the message is not the same as size parameter then this function shall fail and return NULL. ]*/ if (messageSize != size) diff --git a/core/tests/dynamic_library_ut/CMakeLists.txt b/core/tests/dynamic_library_ut/CMakeLists.txt index c74fd0c6..fc3f927a 100644 --- a/core/tests/dynamic_library_ut/CMakeLists.txt +++ b/core/tests/dynamic_library_ut/CMakeLists.txt @@ -12,7 +12,7 @@ if(WIN32) ${testSuiteName}_windows.cpp) set(${testSuiteName}_c_files ../../adapters/dynamic_library_windows.c) -elseif(LINUX) +elseif(UNIX) # LINUX or APPLE set(${testSuiteName}_cpp_files ${testSuiteName}_linux.cpp) set(${testSuiteName}_c_files diff --git a/core/tests/dynamic_loader_ut/dynamic_loader_ut.c b/core/tests/dynamic_loader_ut/dynamic_loader_ut.c index 71dd265b..a2318f2a 100644 --- a/core/tests/dynamic_loader_ut/dynamic_loader_ut.c +++ b/core/tests/dynamic_loader_ut/dynamic_loader_ut.c @@ -142,7 +142,7 @@ MOCK_FUNCTION_END(arr) MOCK_FUNCTION_WITH_CODE(, JSON_Value*, json_array_get_value, const JSON_Array*, arr, size_t, index) JSON_Value* val = NULL; - if (arr != NULL && index >= 0) + if (arr != NULL && index != 0) { val = (JSON_Value*)0x42; } diff --git a/core/tests/gateway_createfromjson_ut/gateway_createfromjson_ut.cpp b/core/tests/gateway_createfromjson_ut/gateway_createfromjson_ut.cpp index 3c9b8c34..90e7d7fe 100644 --- a/core/tests/gateway_createfromjson_ut/gateway_createfromjson_ut.cpp +++ b/core/tests/gateway_createfromjson_ut/gateway_createfromjson_ut.cpp @@ -91,7 +91,7 @@ TYPED_MOCK_CLASS(CGatewayMocks, CGlobalMock) MOCK_STATIC_METHOD_2(, JSON_Object*, json_array_get_object, const JSON_Array*, arr, size_t, index) JSON_Object* object = NULL; - if (arr != NULL && index >= 0) + if (arr != NULL) { object = (JSON_Object*)0x42; } diff --git a/core/tests/gateway_e2e/CMakeLists.txt b/core/tests/gateway_e2e/CMakeLists.txt index df3d6abd..69ac64c9 100644 --- a/core/tests/gateway_e2e/CMakeLists.txt +++ b/core/tests/gateway_e2e/CMakeLists.txt @@ -17,7 +17,7 @@ ${theseTestsName}.cpp #setting the dynamic_loader file based on OS that it is used if(WIN32) set(modules_c_file ./module_config_windows.c) -elseif(LINUX) +elseif(UNIX) # LINUX OR APPLE set(modules_c_file ./module_config_linux.c) endif() diff --git a/core/tests/gateway_ut/gateway_ut.cpp b/core/tests/gateway_ut/gateway_ut.cpp index 5b254b2b..63ebc623 100644 --- a/core/tests/gateway_ut/gateway_ut.cpp +++ b/core/tests/gateway_ut/gateway_ut.cpp @@ -119,7 +119,7 @@ TYPED_MOCK_CLASS(CGatewayLLMocks, CGlobalMock) MOCK_STATIC_METHOD_0(, BROKER_HANDLE, Broker_Create) BROKER_HANDLE result1; currentBroker_Create_call++; - if (whenShallBroker_Create_fail >= 0 && whenShallBroker_Create_fail == currentBroker_Create_call) + if (whenShallBroker_Create_fail == currentBroker_Create_call) { result1 = NULL; } @@ -173,7 +173,7 @@ TYPED_MOCK_CLASS(CGatewayLLMocks, CGlobalMock) MOCK_STATIC_METHOD_2(, MODULE_LIBRARY_HANDLE, DynamicModuleLoader_Load, const struct MODULE_LOADER_TAG*, loader, const void*, entrypoint) currentModuleLoader_Load_call++; MODULE_LIBRARY_HANDLE handle = NULL; - if (whenShallModuleLoader_Load_fail >= 0 && whenShallModuleLoader_Load_fail != currentModuleLoader_Load_call) + if (whenShallModuleLoader_Load_fail != currentModuleLoader_Load_call) { handle = (MODULE_LIBRARY_HANDLE)BASEIMPLEMENTATION::gballoc_malloc(1); } diff --git a/core/tests/gwmessage_ut/gwmessage_ut.c b/core/tests/gwmessage_ut/gwmessage_ut.c index 35b5b3d0..f98b8242 100644 --- a/core/tests/gwmessage_ut/gwmessage_ut.c +++ b/core/tests/gwmessage_ut/gwmessage_ut.c @@ -1147,7 +1147,7 @@ BEGIN_TEST_SUITE(gwmessage_ut) ///cleanup } - /*Tests_SRS_MESSAGE_02_020: [Otherwise, Message_Destroy shall decrement the internal ref count of the message.] + /*Tests_SRS_MESSAGE_02_020: [Otherwise, Message_Destroy shall decrement the internal ref count of the message.]*/ /*Tests_SRS_MESSAGE_02_021: [If the ref count is zero then the allocated resources are freed.]*/ /*Tests_SRS_MESSAGE_17_002: [Message_Destroy shall destroy the CONSTMAP properties.]*/ /*Tests_SRS_MESSAGE_17_005: [Message_Destroy shall destroy the CONSTBUFFER.]*/ diff --git a/core/tests/java_loader_ut/java_loader_ut.c b/core/tests/java_loader_ut/java_loader_ut.c index 8664bbc8..f5156411 100644 --- a/core/tests/java_loader_ut/java_loader_ut.c +++ b/core/tests/java_loader_ut/java_loader_ut.c @@ -149,7 +149,7 @@ MOCK_FUNCTION_END(arr) MOCK_FUNCTION_WITH_CODE(, JSON_Value*, json_array_get_value, const JSON_Array*, arr, size_t, index) JSON_Value* val = NULL; -if (arr != NULL && index >= 0) +if (arr != NULL) { val = (JSON_Value*)0x42; } @@ -197,7 +197,7 @@ MOCK_FUNCTION_END(num) MOCK_FUNCTION_WITH_CODE(, const char*, json_array_get_string, const JSON_Array*, arr, size_t, index) const char* str = NULL; -if (arr != NULL && index >= 0) +if (arr != NULL) { str = "hello_world"; } diff --git a/core/tests/module_loader_ut/module_loader_ut.c b/core/tests/module_loader_ut/module_loader_ut.c index f9b9e9e9..6a5d0e94 100644 --- a/core/tests/module_loader_ut/module_loader_ut.c +++ b/core/tests/module_loader_ut/module_loader_ut.c @@ -335,7 +335,7 @@ MOCK_FUNCTION_END(arr) MOCK_FUNCTION_WITH_CODE(, JSON_Value*, json_array_get_value, const JSON_Array*, arr, size_t, index) JSON_Value* val = NULL; - if (arr != NULL && index >= 0) + if (arr != NULL && index != 0) { val = (JSON_Value*)0x42; } diff --git a/dependencies.cmake b/dependencies.cmake index 4a67b2ee..6a05bb40 100644 --- a/dependencies.cmake +++ b/dependencies.cmake @@ -10,6 +10,11 @@ include("gatewayFunctions.cmake") ############################################################################### ###################Find/Install/Build azure_c_shared_utility################### ############################################################################### +set(PASSVARS) +if(DEFINED OPENSSL_ROOT_DIR) + set(PASSVARS ${PASSVARS} -DOPENSSL_ROOT_DIR:PATH=${OPENSSL_ROOT_DIR}) +endif() + findAndInstall(azure_c_shared_utility 1.0.25 ${PROJECT_SOURCE_DIR}/deps/c-utility ${PROJECT_SOURCE_DIR}/deps/c-utility @@ -17,6 +22,7 @@ findAndInstall(azure_c_shared_utility 1.0.25 -Drun_unittests=${run_unittests} -Dbuild_as_dynamic=ON -Duse_default_uuid=${use_xplat_uuid} + ${PASSVARS} -G "${CMAKE_GENERATOR}") set(SHARED_UTIL_INC_FOLDER ${AZURE_C_SHARED_UTILITY_INCLUDE_DIR} CACHE INTERNAL "this is what needs to be included if using sharedLib lib" FORCE) set(SHARED_UTIL_LIB_FOLDER ${AZURE_C_SHARED_LIBRARY_DIR} CACHE INTERNAL "this is what needs to be included if using sharedLib lib" FORCE) @@ -48,32 +54,36 @@ if(WIN32) set(NANOMSG_INCLUDES "${CMAKE_INSTALL_PREFIX}/../nanomsg/include" CACHE INTERNAL "") endif() else() - include(FindPkgConfig) find_package(PkgConfig REQUIRED) #If using a custom install prefix, tell find pkg to use it instead of defaults set(PKG_CONFIG_USE_CMAKE_PREFIX_PATH TRUE) - pkg_search_module(NANOMSG QUIET nanomsg) if(NOT NANOMSG_FOUND) - findAndInstallNonFindPkg(nanomsg ${PROJECT_SOURCE_DIR}/deps/nanomsg ${PROJECT_SOURCE_DIR}/deps/nanomsg -G "${CMAKE_GENERATOR}") + findAndInstallNonFindPkg(nanomsg + ${PROJECT_SOURCE_DIR}/deps/nanomsg + ${PROJECT_SOURCE_DIR}/deps/nanomsg + -G "${CMAKE_GENERATOR}" + -DNN_TESTS=OFF + -DNN_TOOLS=OFF) endif() #If earlier cmake if("${CMAKE_VERSION}" VERSION_GREATER 3.0.2) pkg_search_module(NANOMSG REQUIRED nanomsg) - set (NANOMSG_LIB_LOCATION "${NANOMSG_LIBDIR}/lib${NANOMSG_LIBRARIES}.so") + set (NANOMSG_LIB_LOCATION + "${NANOMSG_LIBDIR}/${CMAKE_SHARED_LIBRARY_PREFIX}${NANOMSG_LIBRARIES}${CMAKE_SHARED_LIBRARY_SUFFIX}") else() if(DEFINED ${dependency_install_prefix}) set(NANOMSG_INCLUDEDIR "${dependency_install_prefix}/include") set(NANOMSG_LIBRARIES nanomsg) set(NANOMSG_LIBRARY_DIRS "${dependency_install_prefix}/${CMAKE_INSTALL_LIBDIR}") - set(NANOMSG_LDFLAGS "-L${NANOMSG_LIBRARY_DIRS};-l${NANOMSG_LIBRARIES}") else() pkg_search_module(NANOMSG REQUIRED nanomsg) set(NANOMSG_LIBRARY_DIRS "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}") endif() - set (NANOMSG_LIB_LOCATION "${NANOMSG_LIBRARY_DIRS}/lib${NANOMSG_LIBRARIES}.so") + set (NANOMSG_LIB_LOCATION + "${NANOMSG_LIBRARY_DIRS}/${CMAKE_SHARED_LIBRARY_PREFIX}${NANOMSG_LIBRARIES}${CMAKE_SHARED_LIBRARY_SUFFIX}") endif() @@ -88,11 +98,9 @@ else() set_target_properties(nanomsg PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${NANOMSG_INCLUDEDIR}" INTERFACE_LINK_LIBRARIES "${NANOMSG_LIBRARIES}" - INTERFACE_COMPILE_OPTIONS "${NANOMSG_LDFLAGS}" IMPORTED_LOCATION "${NANOMSG_LIB_LOCATION}" ) message(STATUS "NANOMSG LIBRARIES: ${NANOMSG_LIBRARIES}") - message(STATUS "NANOMSG LDFLAGS: ${NANOMSG_LDFLAGS}") message(STATUS "NANOMSG CFLAGS: ${NANOMSG_CFLAGS}") message(STATUS "NANOMSG LOCATION: ${NANOMSG_LIB_LOCATION}") endif() diff --git a/gatewayFunctions.cmake b/gatewayFunctions.cmake index f8d072e6..b38aa27d 100644 --- a/gatewayFunctions.cmake +++ b/gatewayFunctions.cmake @@ -36,7 +36,8 @@ function(findAndInstallNonFindPkg libraryName submoduleRootDirectory cmakeRootDi endif() #Create the build directory to run cmake, and run cmake - #generate comand + + #generate command set(CMD cmake) foreach(arg ${ARGN}) set(CMD ${CMD} ${arg}) @@ -139,7 +140,7 @@ function(findAndInstall libraryName version submoduleRootDirectory cmakeRootDire set(CMD ${CMD} -DCMAKE_INSTALL_PREFIX=${dependency_install_prefix}) endif() if(CMAKE_TOOLCHAIN_FILE) - set( CMD ${CMD} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}) + set(CMD ${CMD} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}) endif() set(CMD ${CMD} ../) diff --git a/jenkins/osx_c.sh b/jenkins/osx_c.sh new file mode 100755 index 00000000..419e23cd --- /dev/null +++ b/jenkins/osx_c.sh @@ -0,0 +1,35 @@ +#!/bin/bash +# Copyright (c) Microsoft. All rights reserved. +# Licensed under the MIT license. See LICENSE file in the project root for full license information. +# + +set -e + +script_dir=$(cd "$(dirname "$0")" && pwd) +build_root=$(cd "${script_dir}/.." && pwd) +build_folder=$build_root"/build" + +CORES=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu) + +# Java binding +pushd $build_root/bindings/java/gateway-java-binding +mvn clean install +popd + +rm -rf $build_folder +mkdir -p $build_folder +pushd $build_folder + +cmake \ + -Ddependency_install_prefix:PATH=$build_root/install-deps \ + -DOPENSSL_ROOT_DIR:PATH=/usr/local/opt/openssl \ + -Dbuild_cores=$CORES \ + -Denable_ble_module:BOOL=OFF \ + -Denable_java_binding=ON \ + -Drun_unittests:BOOL=ON \ + -Drun_e2e_tests:BOOL=ON \ + .. + +cmake --build . -- --jobs=$CORES +ctest -C "debug" -V +popd diff --git a/modules/azure_functions/src/azure_functions.c b/modules/azure_functions/src/azure_functions.c index 87f784f6..67c3447b 100644 --- a/modules/azure_functions/src/azure_functions.c +++ b/modules/azure_functions/src/azure_functions.c @@ -393,7 +393,8 @@ static void AzureFunctions_Receive(MODULE_HANDLE moduleHandle, MESSAGE_HANDLE me { //Add here the content on the body. - BUFFER_HANDLE postContent = BUFFER_create(STRING_c_str(jsonToBeAppended), STRING_length(jsonToBeAppended)); + size_t appendLength = STRING_length(jsonToBeAppended); + BUFFER_HANDLE postContent = BUFFER_create((const unsigned char*)STRING_c_str(jsonToBeAppended), appendLength); if (postContent == NULL) { diff --git a/modules/hello_world/src/hello_world.c b/modules/hello_world/src/hello_world.c index 627c434b..1b35b8ee 100644 --- a/modules/hello_world/src/hello_world.c +++ b/modules/hello_world/src/hello_world.c @@ -40,7 +40,7 @@ int helloWorldThread(void *param) else { msgConfig.size = strlen(HELLOWORLD_MESSAGE); - msgConfig.source = HELLOWORLD_MESSAGE; + msgConfig.source = (unsigned char*)HELLOWORLD_MESSAGE; msgConfig.sourceProperties = propertiesMap; @@ -82,9 +82,7 @@ int helloWorldThread(void *param) static MODULE_HANDLE HelloWorld_Create(BROKER_HANDLE broker, const void* configuration) { HELLOWORLD_HANDLE_DATA* result; - if ( - (broker == NULL) /*configuration is not used*/ - ) + if (broker == NULL) /*configuration is not used*/ { LogError("invalid arg broker=%p", broker); result = NULL; diff --git a/modules/identitymap/tests/idmap_ut/idmap_ut.cpp b/modules/identitymap/tests/idmap_ut/idmap_ut.cpp index 8805bc0e..cc75ba21 100644 --- a/modules/identitymap/tests/idmap_ut/idmap_ut.cpp +++ b/modules/identitymap/tests/idmap_ut/idmap_ut.cpp @@ -431,7 +431,7 @@ TYPED_MOCK_CLASS(CIdentitymapMocks, CGlobalMock) MOCK_STATIC_METHOD_2(, void*, VECTOR_element, const VECTOR_HANDLE, handle, size_t, index) currentVectorElement_call++; void * result1; - if (currentVectorElement_call = whenShallVectorElement_fail) + if (currentVectorElement_call == whenShallVectorElement_fail) { result1 = NULL; } diff --git a/proxy/gateway/native/tests/proxy_gateway_ut/proxy_gateway_ut.c b/proxy/gateway/native/tests/proxy_gateway_ut/proxy_gateway_ut.c index 6bf2b1ee..35c4f9cd 100644 --- a/proxy/gateway/native/tests/proxy_gateway_ut/proxy_gateway_ut.c +++ b/proxy/gateway/native/tests/proxy_gateway_ut/proxy_gateway_ut.c @@ -884,10 +884,10 @@ TEST_FUNCTION(attach_SCENARIO_negative_tests) ASSERT_ARE_EQUAL(int, negative_test_index, umock_c_negative_tests_call_count()); for (size_t i = 0; i < umock_c_negative_tests_call_count(); ++i) { if ( skipNegativeTest(i) ) { - printf("%s: Skipping negative tests: %d\n", __FUNCTION__, i); + printf("%s: Skipping negative tests: %zx\n", __FUNCTION__, i); continue; } - printf("%s: Running negative tests: %d\n", __FUNCTION__, i); + printf("%s: Running negative tests: %zx\n", __FUNCTION__, i); umock_c_negative_tests_reset(); umock_c_negative_tests_fail_call(i); @@ -1014,10 +1014,10 @@ TEST_FUNCTION(startWorkerThread_SCENARIO_negative_tests) ASSERT_ARE_EQUAL(int, negative_test_index, umock_c_negative_tests_call_count()); for (size_t i = 0; i < umock_c_negative_tests_call_count(); ++i) { if (skipNegativeTest(i)) { - printf("%s: Skipping negative tests: %d\n", __FUNCTION__, i); + printf("%s: Skipping negative tests: %zx\n", __FUNCTION__, i); continue; } - printf("%s: Running negative tests: %d\n", __FUNCTION__, i); + printf("%s: Running negative tests: %zx\n", __FUNCTION__, i); umock_c_negative_tests_reset(); umock_c_negative_tests_fail_call(i); @@ -2033,10 +2033,10 @@ TEST_FUNCTION(connect_to_message_channel_SCENARIO_negative_tests) ASSERT_ARE_EQUAL(int, negative_test_index, umock_c_negative_tests_call_count()); for (size_t i = 0; i < umock_c_negative_tests_call_count(); ++i) { if (skipNegativeTest(i)) { - printf("%s: Skipping negative tests: %d\n", __FUNCTION__, i); + printf("%s: Skipping negative tests: %zx\n", __FUNCTION__, i); continue; } - printf("%s: Running negative tests: %d\n", __FUNCTION__, i); + printf("%s: Running negative tests: %zx\n", __FUNCTION__, i); umock_c_negative_tests_reset(); umock_c_negative_tests_fail_call(i); @@ -2200,10 +2200,10 @@ TEST_FUNCTION(invoke_add_module_procedure_SCENARIO_negative_tests) ASSERT_ARE_EQUAL(int, negative_test_index, umock_c_negative_tests_call_count()); for (size_t i = 0; i < umock_c_negative_tests_call_count(); ++i) { if (skipNegativeTest(i)) { - printf("%s: Skipping negative tests: %d\n", __FUNCTION__, i); + printf("%s: Skipping negative tests: %zx\n", __FUNCTION__, i); continue; } - printf("%s: Running negative tests: %d\n", __FUNCTION__, i); + printf("%s: Running negative tests: %zx\n", __FUNCTION__, i); umock_c_negative_tests_reset(); umock_c_negative_tests_fail_call(i); @@ -2409,10 +2409,10 @@ TEST_FUNCTION(process_module_create_message_SCENARIO_negative_tests) ASSERT_ARE_EQUAL(int, negative_test_index, umock_c_negative_tests_call_count()); for (size_t i = 0; i < umock_c_negative_tests_call_count(); ++i) { if (skipNegativeTest(i)) { - printf("%s: Skipping negative tests: %d\n", __FUNCTION__, i); + printf("%s: Skipping negative tests: %zx\n", __FUNCTION__, i); continue; } - printf("%s: Running negative tests: %d\n", __FUNCTION__, i); + printf("%s: Running negative tests: %zx\n", __FUNCTION__, i); umock_c_negative_tests_reset(); umock_c_negative_tests_fail_call(i); @@ -2495,10 +2495,10 @@ TEST_FUNCTION(send_control_reply_SCENARIO_negative_tests) ASSERT_ARE_EQUAL(int, negative_test_index, umock_c_negative_tests_call_count()); for (size_t i = 0; i < umock_c_negative_tests_call_count(); ++i) { if (skipNegativeTest(i)) { - printf("%s: Skipping negative tests: %d\n", __FUNCTION__, i); + printf("%s: Skipping negative tests: %zx\n", __FUNCTION__, i); continue; } - printf("%s: Running negative tests: %d\n", __FUNCTION__, i); + printf("%s: Running negative tests: %zx\n", __FUNCTION__, i); umock_c_negative_tests_reset(); umock_c_negative_tests_fail_call(i); diff --git a/proxy/message/src/control_message.c b/proxy/message/src/control_message.c index 54e858d0..bc120e99 100644 --- a/proxy/message/src/control_message.c +++ b/proxy/message/src/control_message.c @@ -19,7 +19,7 @@ DEFINE_ENUM_STRINGS(CONTROL_MESSAGE_TYPE, CONTROL_MESSAGE_TYPE_VALUES); #define BASE_CREATE_SIZE (BASE_MESSAGE_SIZE+10) #define BASE_CREATE_REPLY_SIZE (BASE_MESSAGE_SIZE+1) -static int parse_int32_t(const unsigned char* source, size_t sourceSize, size_t position, int32_t *parsed, int32_t* value) +static int parse_uint32_t(const unsigned char* source, size_t sourceSize, size_t position, int32_t *parsed, uint32_t* value) { int result; if (position + 4 > sourceSize) @@ -41,12 +41,12 @@ static int parse_int32_t(const unsigned char* source, size_t sourceSize, size_t return result; } -static int parse_memory_chunk(const unsigned char* source, size_t sourceSize, size_t position, int32_t *parsed, int32_t *size, unsigned char** value) +static int parse_memory_chunk(const unsigned char* source, size_t sourceSize, size_t position, int32_t *parsed, uint32_t *size, char** value) { int result; - int32_t chunk_size; + uint32_t chunk_size; int32_t current_parsed; - result = parse_int32_t(source, sourceSize, position, ¤t_parsed, &chunk_size); + result = parse_uint32_t(source, sourceSize, position, ¤t_parsed, &chunk_size); if (result == 0) { position += current_parsed; @@ -68,7 +68,7 @@ static int parse_memory_chunk(const unsigned char* source, size_t sourceSize, si else { /* allocate 1 more for null-termination */ - *value = (unsigned char *)malloc(chunk_size); + *value = (char *)malloc(chunk_size); if (*value == NULL) { LogError("unable to allocate memory chunk"); @@ -137,7 +137,7 @@ int parse_create_message(const unsigned char* source, size_t sourceSize, size_t position, ¤t_parsed, &(create_msg->uri.uri_size), - (unsigned char**)&(create_msg->uri.uri)) != 0) + &(create_msg->uri.uri)) != 0) { LogError("unable to parse a uri"); result = __LINE__; @@ -163,7 +163,7 @@ int parse_create_message(const unsigned char* source, size_t sourceSize, size_t position, ¤t_parsed, &(create_msg->args_size), - (unsigned char**)&(create_msg->args)) != 0) + &(create_msg->args)) != 0) { LogError("unable to parse a module args"); result = __LINE__; @@ -211,9 +211,9 @@ CONTROL_MESSAGE * ControlMessage_CreateFromByteArray(const unsigned char* source /*Codes_SRS_CONTROL_MESSAGE_17_005: [ This function shall read the version, type and size from the byte stream. ]*/ uint8_t messageVersion = (uint8_t)source[currentPosition++]; uint8_t messageType = (uint8_t)source[currentPosition++]; - int32_t messageSize; + uint32_t messageSize; /* we already know buffer is at least BASE_MESSAGE_SIZE - this will always return OK */ - (void)parse_int32_t(source, size, currentPosition, &parsed, &messageSize); + (void)parse_uint32_t(source, size, currentPosition, &parsed, &messageSize); currentPosition += parsed; /*Codes_SRS_CONTROL_MESSAGE_17_006: [ If the size embedded in the message is not the same as size parameter then this function shall fail and return NULL. ]*/ if (messageSize != size) @@ -376,7 +376,7 @@ int32_t ControlMessage_ToByteArray(CONTROL_MESSAGE * message, unsigned char* buf if (message == NULL) { /*Codes_SRS_CONTROL_MESSAGE_17_031: [ If message is NULL, then this function shall return -1. ]*/ - LogError("invalid (NULL) message parameter detected", message, size); + LogError("invalid (NULL) message parameter detected buffer=[%p], size=[%d]", message, size); result = -1; } else if ( diff --git a/proxy/modules/native_module_host/CMakeLists.txt b/proxy/modules/native_module_host/CMakeLists.txt index b4c6dcb7..b2ab9513 100644 --- a/proxy/modules/native_module_host/CMakeLists.txt +++ b/proxy/modules/native_module_host/CMakeLists.txt @@ -3,6 +3,10 @@ cmake_minimum_required(VERSION 2.8.12) +if(POLICY CMP0042) + cmake_policy(SET CMP0042 NEW) +endif() + set(native_module_host_sources ./src/native_module_host.c ) diff --git a/proxy/modules/native_module_host/src/native_module_host.c b/proxy/modules/native_module_host/src/native_module_host.c index 25cba790..cfeb6cfd 100644 --- a/proxy/modules/native_module_host/src/native_module_host.c +++ b/proxy/modules/native_module_host/src/native_module_host.c @@ -1,5 +1,7 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +#include + #include "azure_c_shared_utility/gballoc.h" #include "azure_c_shared_utility/xlogging.h" #include "azure_c_shared_utility/macro_utils.h"