From 960d4f73580348f73efa86fcf62f4cfa1e57b585 Mon Sep 17 00:00:00 2001 From: Dan Rose Date: Fri, 18 Oct 2019 20:04:24 -0500 Subject: [PATCH 01/12] Use PROJECT_NAME instead of CMAKE_PROJECT_NAME CMAKE_PROJECT_NAME refers to the top-level project name, not the most recent project. So any CMake project that pulls this in as a dependency was in for a nasty surprise. https://cmake.org/cmake/help/latest/variable/CMAKE_PROJECT_NAME.html Signed-off-by: Dan Rose --- CMakeLists.txt | 10 +++--- cmake/Modules/Packaging.cmake | 36 +++++++++---------- .../Modules/Packaging/PackageConfig.cmake.in | 2 +- .../Packaging/PackageConfigNoIdlc.cmake.in | 2 +- examples/CMakeLists.txt | 2 +- ports/freertos-posix/CMakeLists.txt | 4 +-- ports/freertos-posix/freertos-sim.cmake.in | 2 +- src/core/CMakeLists.txt | 4 +-- src/core/ddsc/cmake/ddsc_project.h.in | 8 ++--- src/core/ddsc/tests/CMakeLists.txt | 2 +- src/ddsrt/include/dds/version.h.in | 8 ++--- src/idlc/CMakeLists.txt | 6 ++-- .../org/eclipse/cyclonedds/Project.java.in | 4 +-- src/tools/CMakeLists.txt | 2 +- 14 files changed, 46 insertions(+), 46 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2ca2613..7b20cc9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,7 @@ # SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause # cmake_minimum_required(VERSION 3.7) +project(CycloneDDS VERSION 0.1.0) # Set a default build type if none was specified set(default_build_type "RelWithDebInfo") @@ -42,13 +43,12 @@ ENDFUNCTION(PREPEND) # Set module path before defining project so platform files will work. set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/Modules") -set(CMAKE_PROJECT_NAME_FULL "Eclipse Cyclone DDS") -project(CycloneDDS VERSION 0.1.0) +set(PROJECT_NAME_FULL "Eclipse Cyclone DDS") # Set some convenience variants of the project-name -string(REPLACE " " "-" CMAKE_PROJECT_NAME_DASHED "${CMAKE_PROJECT_NAME_FULL}") -string(TOUPPER ${CMAKE_PROJECT_NAME} CMAKE_PROJECT_NAME_CAPS) -string(TOLOWER ${CMAKE_PROJECT_NAME} CMAKE_PROJECT_NAME_SMALL) +string(REPLACE " " "-" PROJECT_NAME_DASHED "${PROJECT_NAME_FULL}") +string(TOUPPER ${PROJECT_NAME} PROJECT_NAME_CAPS) +string(TOLOWER ${PROJECT_NAME} PROJECT_NAME_SMALL) set(CMAKE_C_STANDARD 99) if(CMAKE_SYSTEM_NAME STREQUAL "VxWorks") diff --git a/cmake/Modules/Packaging.cmake b/cmake/Modules/Packaging.cmake index da2d7d6..b2d647c 100644 --- a/cmake/Modules/Packaging.cmake +++ b/cmake/Modules/Packaging.cmake @@ -18,39 +18,39 @@ include(CMakePackageConfigHelpers) include(GNUInstallDirs) set(PACKAGING_MODULE_DIR "${PROJECT_SOURCE_DIR}/cmake/Modules/Packaging") -set(CMAKE_INSTALL_CMAKEDIR "${CMAKE_INSTALL_DATADIR}/${CMAKE_PROJECT_NAME}") +set(CMAKE_INSTALL_CMAKEDIR "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}") # Generates Config.cmake. if(BUILD_IDLC) configure_package_config_file( "${PACKAGING_MODULE_DIR}/PackageConfig.cmake.in" - "${CMAKE_PROJECT_NAME}Config.cmake" + "${PROJECT_NAME}Config.cmake" INSTALL_DESTINATION "${CMAKE_INSTALL_CMAKEDIR}") else() configure_package_config_file( "${PACKAGING_MODULE_DIR}/PackageConfigNoIdlc.cmake.in" - "${CMAKE_PROJECT_NAME}Config.cmake" + "${PROJECT_NAME}Config.cmake" INSTALL_DESTINATION "${CMAKE_INSTALL_CMAKEDIR}") endif() # Generates Version.cmake. write_basic_package_version_file( - "${CMAKE_PROJECT_NAME}Version.cmake" + "${PROJECT_NAME}Version.cmake" VERSION ${PROJECT_VERSION} COMPATIBILITY SameMajorVersion) install( - FILES "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}Config.cmake" - "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}Version.cmake" + FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Version.cmake" DESTINATION "${CMAKE_INSTALL_CMAKEDIR}" COMPONENT dev) if((NOT DEFINED BUILD_SHARED_LIBS) OR BUILD_SHARED_LIBS) # Generates Targets.cmake file included by Config.cmake. # The files are placed in CMakeFiles/Export in the build tree. install( - EXPORT "${CMAKE_PROJECT_NAME}" - FILE "${CMAKE_PROJECT_NAME}Targets.cmake" - NAMESPACE "${CMAKE_PROJECT_NAME}::" + EXPORT "${PROJECT_NAME}" + FILE "${PROJECT_NAME}Targets.cmake" + NAMESPACE "${PROJECT_NAME}::" DESTINATION "${CMAKE_INSTALL_CMAKEDIR}" COMPONENT dev) endif() @@ -61,7 +61,7 @@ set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH}) set(CPACK_PACKAGE_VERSION_TWEAK ${PROJECT_VERSION_TWEAK}) set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION}) -set(CPACK_PACKAGE_NAME ${CMAKE_PROJECT_NAME}) +set(CPACK_PACKAGE_NAME ${PROJECT_NAME}) set(CPACK_PACKAGE_VENDOR "Eclipse Cyclone DDS project") set(CPACK_PACKAGE_CONTACT "https://github.com/eclipse-cyclonedds/cyclonedds") set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Implementation of the OMG DDS standard") @@ -84,10 +84,10 @@ set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_BINARY_DIR}/license.txt") # does help to clearify which settings are required for a platform. set(CPACK_COMPONENTS_ALL dev lib) -set(CPACK_COMPONENT_LIB_DISPLAY_NAME "${CMAKE_PROJECT_NAME_FULL} library") -set(CPACK_COMPONENT_LIB_DESCRIPTION "Library used to run programs with ${CMAKE_PROJECT_NAME_FULL}") -set(CPACK_COMPONENT_DEV_DISPLAY_NAME "${CMAKE_PROJECT_NAME_FULL} development") -set(CPACK_COMPONENT_DEV_DESCRIPTION "Development files for use with ${CMAKE_PROJECT_NAME_FULL}") +set(CPACK_COMPONENT_LIB_DISPLAY_NAME "${PROJECT_NAME_FULL} library") +set(CPACK_COMPONENT_LIB_DESCRIPTION "Library used to run programs with ${PROJECT_NAME_FULL}") +set(CPACK_COMPONENT_DEV_DISPLAY_NAME "${PROJECT_NAME_FULL} development") +set(CPACK_COMPONENT_DEV_DESCRIPTION "Development files for use with ${PROJECT_NAME_FULL}") if(WIN32 AND NOT UNIX) if(CMAKE_SIZEOF_VOID_P EQUAL 8) @@ -99,8 +99,8 @@ if(WIN32 AND NOT UNIX) set(CPACK_GENERATOR "WIX;ZIP;${CPACK_GENERATOR}" CACHE STRING "List of package generators") - set(CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${CPACK_PACKAGE_VERSION}-${__arch}") - set(CPACK_PACKAGE_INSTALL_DIRECTORY "${CMAKE_PROJECT_NAME_FULL}") + set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${CPACK_PACKAGE_VERSION}-${__arch}") + set(CPACK_PACKAGE_INSTALL_DIRECTORY "${PROJECT_NAME_FULL}") include(InstallRequiredSystemLibraries) elseif(CMAKE_SYSTEM_NAME MATCHES "Linux") @@ -123,7 +123,7 @@ elseif(CMAKE_SYSTEM_NAME MATCHES "Linux") set(CPACK_RPM_COMPONENT_INSTALL ON) # FIXME: The package file name must be updated to include the distribution. # See Fedora and Red Hat packaging guidelines for details. - set(CPACK_RPM_LIB_PACKAGE_NAME "${CMAKE_PROJECT_NAME_DASHED}") + set(CPACK_RPM_LIB_PACKAGE_NAME "${PROJECT_NAME_DASHED}") set(CPACK_RPM_LIB_FILE_NAME "${CPACK_RPM_LIB_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${__arch}.rpm") set(CPACK_RPM_DEV_PACKAGE_NAME "${CPACK_RPM_LIB_PACKAGE_NAME}-devel") set(CPACK_RPM_DEV_FILE_NAME "${CPACK_RPM_DEV_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${__arch}.rpm") @@ -138,7 +138,7 @@ elseif(CMAKE_SYSTEM_NAME MATCHES "Linux") set(CPACK_GENERATOR "DEB;TGZ;${CPACK_GENERATOR}" CACHE STRING "List of package generators") - string(TOLOWER "${CMAKE_PROJECT_NAME_DASHED}" CPACK_DEBIAN_LIB_PACKAGE_NAME) + string(TOLOWER "${PROJECT_NAME_DASHED}" CPACK_DEBIAN_LIB_PACKAGE_NAME) set(CPACK_DEBIAN_LIB_FILE_NAME "${CPACK_DEBIAN_LIB_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}_${__arch}.deb") set(CPACK_DEBIAN_DEV_PACKAGE_DEPENDS "${CPACK_DEBIAN_LIB_PACKAGE_NAME} (= ${CPACK_PACKAGE_VERSION}), libc6 (>= 2.23)") set(CPACK_DEBIAN_DEV_PACKAGE_NAME "${CPACK_DEBIAN_LIB_PACKAGE_NAME}-dev") diff --git a/cmake/Modules/Packaging/PackageConfig.cmake.in b/cmake/Modules/Packaging/PackageConfig.cmake.in index a1b8344..c8d6d78 100644 --- a/cmake/Modules/Packaging/PackageConfig.cmake.in +++ b/cmake/Modules/Packaging/PackageConfig.cmake.in @@ -11,5 +11,5 @@ # @PACKAGE_INIT@ -include("${CMAKE_CURRENT_LIST_DIR}/@CMAKE_PROJECT_NAME@Targets.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") include("${CMAKE_CURRENT_LIST_DIR}/idlc/IdlcGenerate.cmake") diff --git a/cmake/Modules/Packaging/PackageConfigNoIdlc.cmake.in b/cmake/Modules/Packaging/PackageConfigNoIdlc.cmake.in index 415b481..038e6f9 100644 --- a/cmake/Modules/Packaging/PackageConfigNoIdlc.cmake.in +++ b/cmake/Modules/Packaging/PackageConfigNoIdlc.cmake.in @@ -11,4 +11,4 @@ # @PACKAGE_INIT@ -include("${CMAKE_CURRENT_LIST_DIR}/@CMAKE_PROJECT_NAME@Targets.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 2129d74..d78ff71 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -9,7 +9,7 @@ # # SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause # -set(CMAKE_INSTALL_EXAMPLESDIR "${CMAKE_INSTALL_DATADIR}/${CMAKE_PROJECT_NAME}/examples") +set(CMAKE_INSTALL_EXAMPLESDIR "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/examples") add_subdirectory(helloworld) add_subdirectory(roundtrip) diff --git a/ports/freertos-posix/CMakeLists.txt b/ports/freertos-posix/CMakeLists.txt index 005e13b..0c161ce 100644 --- a/ports/freertos-posix/CMakeLists.txt +++ b/ports/freertos-posix/CMakeLists.txt @@ -24,7 +24,7 @@ endif() # default system locations, i.e. /usr/lib and /usr/include on *NIX platforms. # The install prefix must therefore be postfixed with the project name. if(UNIX) - set(CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/${CMAKE_PROJECT_NAME}") + set(CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}") endif() set(ENTRYPOINT "real_main" @@ -119,7 +119,7 @@ install( install( TARGETS freertos-sim freertos-sim-loader - EXPORT "${CMAKE_PROJECT_NAME}" + EXPORT "${PROJECT_NAME}" RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}") diff --git a/ports/freertos-posix/freertos-sim.cmake.in b/ports/freertos-posix/freertos-sim.cmake.in index 73b85f2..3ad08f5 100644 --- a/ports/freertos-posix/freertos-sim.cmake.in +++ b/ports/freertos-posix/freertos-sim.cmake.in @@ -11,7 +11,7 @@ # # -# CMake toolchain file generated by @CMAKE_PROJECT_NAME@ +# CMake toolchain file generated by @PROJECT_NAME@ # set(CMAKE_C_COMPILER "@CMAKE_C_COMPILER@") diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index b29c53d..46506aa 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -70,11 +70,11 @@ set_target_properties(ddsc PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PRO # Create a pseudo-target that other targets (i.e. examples, tests) can depend # on and can also be provided as import-target by a package-file when building # those targets outside the regular Cyclone build-tree (i.e. the installed tree) -add_library(${CMAKE_PROJECT_NAME}::ddsc ALIAS ddsc) +add_library(${PROJECT_NAME}::ddsc ALIAS ddsc) install( TARGETS ddsc - EXPORT "${CMAKE_PROJECT_NAME}" + EXPORT "${PROJECT_NAME}" RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT lib LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT lib ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT lib diff --git a/src/core/ddsc/cmake/ddsc_project.h.in b/src/core/ddsc/cmake/ddsc_project.h.in index 6eb3884..3b27447 100644 --- a/src/core/ddsc/cmake/ddsc_project.h.in +++ b/src/core/ddsc/cmake/ddsc_project.h.in @@ -17,9 +17,9 @@ #define DDSC_VERSION_MINOR @CycloneDDS_VERSION_MINOR@ #define DDSC_VERSION_PATCH @CycloneDDS_VERSION_PATCH@ #define DDSC_VERSION_TWEAK @CycloneDDS_VERSION_TWEAK@ -#define DDSC_PROJECT_NAME_NOSPACE_CAPS "@CMAKE_PROJECT_NAME_CAPS@" -#define DDSC_PROJECT_NAME_NOSPACE_SMALL "@CMAKE_PROJECT_NAME_SMALL@" -#define DDSC_PROJECT_NAME_NOSPACE "@CMAKE_PROJECT_NAME@" -#define DDSC_PROJECT_NAME "@CMAKE_PROJECT_NAME@" +#define DDSC_PROJECT_NAME_NOSPACE_CAPS "@PROJECT_NAME_CAPS@" +#define DDSC_PROJECT_NAME_NOSPACE_SMALL "@PROJECT_NAME_SMALL@" +#define DDSC_PROJECT_NAME_NOSPACE "@PROJECT_NAME@" +#define DDSC_PROJECT_NAME "@PROJECT_NAME@" #endif /* DDSC_PROJECT_H */ diff --git a/src/core/ddsc/tests/CMakeLists.txt b/src/core/ddsc/tests/CMakeLists.txt index a15d9b2..6c977a0 100644 --- a/src/core/ddsc/tests/CMakeLists.txt +++ b/src/core/ddsc/tests/CMakeLists.txt @@ -62,7 +62,7 @@ get_test_property(CUnit_ddsc_config_simple_udp ENVIRONMENT CUnit_ddsc_config_sim set(CUnit_ddsc_config_simple_udp_file "${CMAKE_CURRENT_LIST_DIR}/config_simple_udp.xml") set(CUnit_ddsc_config_simple_udp_uri "file://${CUnit_ddsc_config_simple_udp_file}") set(CUnit_ddsc_config_simple_udp_max_participants "0") -set(CUnit_ddsc_config_simple_udp_env "${CMAKE_PROJECT_NAME_CAPS}_URI=${CUnit_ddsc_config_simple_udp_uri};MAX_PARTICIPANTS=${CUnit_ddsc_config_simple_udp_max_participants};${CUnit_ddsc_config_simple_udp_env}") +set(CUnit_ddsc_config_simple_udp_env "${PROJECT_NAME_CAPS}_URI=${CUnit_ddsc_config_simple_udp_uri};MAX_PARTICIPANTS=${CUnit_ddsc_config_simple_udp_max_participants};${CUnit_ddsc_config_simple_udp_env}") set_tests_properties( CUnit_ddsc_config_simple_udp diff --git a/src/ddsrt/include/dds/version.h.in b/src/ddsrt/include/dds/version.h.in index 3bab290..6eb821c 100644 --- a/src/ddsrt/include/dds/version.h.in +++ b/src/ddsrt/include/dds/version.h.in @@ -17,10 +17,10 @@ #define DDS_VERSION_MINOR @CycloneDDS_VERSION_MINOR@ #define DDS_VERSION_PATCH @CycloneDDS_VERSION_PATCH@ #define DDS_VERSION_TWEAK @CycloneDDS_VERSION_TWEAK@ -#define DDS_PROJECT_NAME_NOSPACE_CAPS "@CMAKE_PROJECT_NAME_CAPS@" -#define DDS_PROJECT_NAME_NOSPACE_SMALL "@CMAKE_PROJECT_NAME_SMALL@" -#define DDS_PROJECT_NAME_NOSPACE "@CMAKE_PROJECT_NAME@" -#define DDS_PROJECT_NAME "@CMAKE_PROJECT_NAME@" +#define DDS_PROJECT_NAME_NOSPACE_CAPS "@PROJECT_NAME_CAPS@" +#define DDS_PROJECT_NAME_NOSPACE_SMALL "@PROJECT_NAME_SMALL@" +#define DDS_PROJECT_NAME_NOSPACE "@PROJECT_NAME@" +#define DDS_PROJECT_NAME "@PROJECT_NAME@" #define DDS_HOST_NAME "@CMAKE_HOST_SYSTEM_NAME@" #define DDS_TARGET_NAME "@CMAKE_SYSTEM_NAME@" diff --git a/src/idlc/CMakeLists.txt b/src/idlc/CMakeLists.txt index 417aa50..5616658 100644 --- a/src/idlc/CMakeLists.txt +++ b/src/idlc/CMakeLists.txt @@ -45,17 +45,17 @@ include(cmake/IdlcGenerate.cmake) install( FILES "cmake/IdlcGenerate.cmake" - DESTINATION "${CMAKE_INSTALL_DATADIR}/${CMAKE_PROJECT_NAME}/idlc" + DESTINATION "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/idlc" COMPONENT dev) install( FILES "${IDLC_SCRIPT_IN}" - DESTINATION "${CMAKE_INSTALL_DATADIR}/${CMAKE_PROJECT_NAME}/idlc" + DESTINATION "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/idlc" COMPONENT dev) install( FILES "${IDLC_JAR}" - DESTINATION "${CMAKE_INSTALL_DATADIR}/${CMAKE_PROJECT_NAME}/idlc" + DESTINATION "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/idlc" PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_WRITE GROUP_EXECUTE WORLD_READ WORLD_EXECUTE COMPONENT dev) diff --git a/src/idlc/src/org/eclipse/cyclonedds/Project.java.in b/src/idlc/src/org/eclipse/cyclonedds/Project.java.in index cce4f8d..bb01a3b 100644 --- a/src/idlc/src/org/eclipse/cyclonedds/Project.java.in +++ b/src/idlc/src/org/eclipse/cyclonedds/Project.java.in @@ -14,6 +14,6 @@ package org.eclipse.cyclonedds; public class Project { public static String version = "@PROJECT_VERSION@"; - public static String name = "@CMAKE_PROJECT_NAME@"; - public static String nameCaps = "@CMAKE_PROJECT_NAME_CAPS@"; + public static String name = "@PROJECT_NAME@"; + public static String nameCaps = "@PROJECT_NAME_CAPS@"; } diff --git a/src/tools/CMakeLists.txt b/src/tools/CMakeLists.txt index 3ba29bf..fe1e2a7 100644 --- a/src/tools/CMakeLists.txt +++ b/src/tools/CMakeLists.txt @@ -9,7 +9,7 @@ # # SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause # -set(CMAKE_INSTALL_TOOLSDIR "${CMAKE_INSTALL_DATADIR}/${CMAKE_PROJECT_NAME}/tools") +set(CMAKE_INSTALL_TOOLSDIR "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/tools") add_subdirectory(pubsub) add_subdirectory(ddsls) if(BUILD_IDLC) From 418a70e7c37ff1710a561c4e46d37c9a0f02d070 Mon Sep 17 00:00:00 2001 From: Dan Rose Date: Fri, 18 Oct 2019 20:50:53 -0500 Subject: [PATCH 02/12] Fix CI not finding pip3 Signed-off-by: Dan Rose --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 30d38c2..08b30fa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -81,7 +81,7 @@ osx_xcode10_3: &osx_xcode10_3 - eval "export COV_COMPTYPE=clang COV_PLATFORM=macOSX" - eval "export PATH=\"${PATH}:$(python3 -m site --user-base)/bin\"" install: - - pip3 install conan --upgrade --user + - python3 -m pip install conan --upgrade --user osx_xcode9: &osx_xcode9 <<: *osx_xcode10_3 From 98ce7d1971add163875fc08c9504ee2ff11ea7ce Mon Sep 17 00:00:00 2001 From: Dan Rose Date: Mon, 21 Oct 2019 22:35:35 -0500 Subject: [PATCH 03/12] Stylistic CMake changes No functional impact intended Signed-off-by: Dan Rose --- src/core/ddsc/CMakeLists.txt | 27 ++++++++------------------- src/core/ddsi/CMakeLists.txt | 2 +- src/ddsrt/CMakeLists.txt | 17 +++-------------- 3 files changed, 12 insertions(+), 34 deletions(-) diff --git a/src/core/ddsc/CMakeLists.txt b/src/core/ddsc/CMakeLists.txt index e10f21f..b28a481 100644 --- a/src/core/ddsc/CMakeLists.txt +++ b/src/core/ddsc/CMakeLists.txt @@ -87,11 +87,6 @@ generate_export_header( EXPORT_FILE_NAME "${CMAKE_CURRENT_BINARY_DIR}/include/dds/export.h" ) -target_include_directories( - ddsc PUBLIC - "$" - "$") - target_sources(ddsc PRIVATE ${srcs_ddsc} @@ -103,27 +98,21 @@ target_sources(ddsc target_include_directories(ddsc PUBLIC + "$" + "$" "$" PRIVATE - "${CMAKE_CURRENT_LIST_DIR}/src") - -target_include_directories(ddsc INTERFACE $) + "${CMAKE_CURRENT_LIST_DIR}/src" + INTERFACE + $) install( - DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/include/dds" + DIRECTORY + "${CMAKE_CURRENT_LIST_DIR}/include/" + "${CMAKE_CURRENT_BINARY_DIR}/include/" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" COMPONENT dev) -install( - DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/include/ddsc" - DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" - COMPONENT dev) - -install( - FILES "${CMAKE_CURRENT_BINARY_DIR}/include/dds/export.h" - DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/dds" - COMPONENT dev) - # TODO: improve test inclusion. if((BUILD_TESTING) AND ((NOT DEFINED MSVC_VERSION) OR (MSVC_VERSION GREATER "1800"))) add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/tests") diff --git a/src/core/ddsi/CMakeLists.txt b/src/core/ddsi/CMakeLists.txt index 8ba1f8f..abde8ad 100644 --- a/src/core/ddsi/CMakeLists.txt +++ b/src/core/ddsi/CMakeLists.txt @@ -125,7 +125,7 @@ target_include_directories(ddsc PRIVATE "${CMAKE_CURRENT_LIST_DIR}/include") install( - DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/include/dds" + DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/include/" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" COMPONENT dev) diff --git a/src/ddsrt/CMakeLists.txt b/src/ddsrt/CMakeLists.txt index 32ab777..0b241d9 100644 --- a/src/ddsrt/CMakeLists.txt +++ b/src/ddsrt/CMakeLists.txt @@ -260,20 +260,9 @@ if(BUILD_TESTING) endif() install( - DIRECTORY "include/dds" + DIRECTORY + "include/" + ${CMAKE_CURRENT_BINARY_DIR}/include/ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" COMPONENT dev FILES_MATCHING PATTERN "*.h") - -install( - FILES "${CMAKE_CURRENT_BINARY_DIR}/include/dds/version.h" - DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/dds" - COMPONENT dev) - -if(WIN32) - install( - FILES "${CMAKE_CURRENT_BINARY_DIR}/include/getopt.h" - DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" - COMPONENT dev) -endif() - From 94e4c0915de68e6d973e909fe5cdbd2ab91cd895 Mon Sep 17 00:00:00 2001 From: Scott K Logan Date: Mon, 21 Oct 2019 17:02:22 -0700 Subject: [PATCH 04/12] Skip some tests when BUILD_IDLC=OFF These tests use `idlc_generate`, which is not available when `BUILD_IDLC` is not `ON`. Signed-off-by: Scott K Logan --- src/core/ddsc/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/ddsc/CMakeLists.txt b/src/core/ddsc/CMakeLists.txt index b28a481..b32a4b5 100644 --- a/src/core/ddsc/CMakeLists.txt +++ b/src/core/ddsc/CMakeLists.txt @@ -114,7 +114,7 @@ install( COMPONENT dev) # TODO: improve test inclusion. -if((BUILD_TESTING) AND ((NOT DEFINED MSVC_VERSION) OR (MSVC_VERSION GREATER "1800"))) +if((BUILD_TESTING) AND (BUILD_IDLC) AND ((NOT DEFINED MSVC_VERSION) OR (MSVC_VERSION GREATER "1800"))) add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/tests") endif() From a3b35a2aa4fca28c75c1acc2c1d09529c1480470 Mon Sep 17 00:00:00 2001 From: Scott K Logan Date: Mon, 21 Oct 2019 17:26:27 -0700 Subject: [PATCH 05/12] Fix some unreliable STREQUAL calls in CMakeLists.txt These conditionals may fail if the variable they're checking isn't defined at all. Adding quotes makes the comparison against an empty string in this case, which avoids the syntax error. Signed-off-by: Scott K Logan --- CMakeLists.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7b20cc9..f7aaa38 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -170,17 +170,17 @@ endif() # the address sanitizer for ordinary debug builds; gcc is giving some grief on # Travis, so don't enable it for gcc by default if(NOT USE_SANITIZER) - if(${CMAKE_BUILD_TYPE} STREQUAL "Debug" AND - NOT (${CMAKE_GENERATOR} STREQUAL "Xcode") AND - (${CMAKE_C_COMPILER_ID} STREQUAL "Clang" - OR ${CMAKE_C_COMPILER_ID} STREQUAL "AppleClang")) + if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug" AND + NOT ("${CMAKE_GENERATOR}" STREQUAL "Xcode") AND + ("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" + OR "${CMAKE_C_COMPILER_ID}" STREQUAL "AppleClang")) message(STATUS "Enabling address sanitizer; set USE_SANITIZER=none to prevent this") set(USE_SANITIZER address) else() set(USE_SANITIZER none) endif() endif() -if(NOT (${USE_SANITIZER} STREQUAL "none")) +if(NOT ("${USE_SANITIZER}" STREQUAL "none")) message(STATUS "Sanitizer set to ${USE_SANITIZER}") add_compile_options(-fno-omit-frame-pointer -fsanitize=${USE_SANITIZER}) link_libraries(-fno-omit-frame-pointer -fsanitize=${USE_SANITIZER}) From 36b1b9da3d8d322cf494a4f6470b8964fdf756e7 Mon Sep 17 00:00:00 2001 From: Thijs Sassen Date: Tue, 22 Oct 2019 14:35:36 +0200 Subject: [PATCH 06/12] Adjusted mpt qos test includes to be in line with other tests Signed-off-by: Thijs Sassen --- src/mpt/tests/qos/CMakeLists.txt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/mpt/tests/qos/CMakeLists.txt b/src/mpt/tests/qos/CMakeLists.txt index 0632570..d154298 100644 --- a/src/mpt/tests/qos/CMakeLists.txt +++ b/src/mpt/tests/qos/CMakeLists.txt @@ -11,14 +11,17 @@ # include(${MPT_CMAKE}) -add_compile_options("-I${PROJECT_SOURCE_DIR}/src/core/ddsi/include") - idlc_generate(mpt_rwdata_lib "procs/rwdata.idl") set(sources_qosmatch "procs/rw.c" "qosmatch.c") add_mpt_executable(mpt_qosmatch ${sources_qosmatch}) + +target_include_directories( +mpt_qosmatch PRIVATE +"$") + target_link_libraries(mpt_qosmatch PRIVATE mpt_rwdata_lib) set(sources_ppuserdata From 41d36d59b2504794fb0242ffd038183f44d4063c Mon Sep 17 00:00:00 2001 From: Martin Bremmer Date: Mon, 21 Oct 2019 09:48:57 +0200 Subject: [PATCH 07/12] Removed duplicate build from travis Signed-off-by: Martin Bremmer --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 08b30fa..e60fe9a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -159,8 +159,6 @@ jobs: env: [ ARCH=x86_64, ASAN=none, BUILD_TYPE=Release, SSL=YES, GENERATOR="Unix Makefiles" ] - <<: *linux_gcc8 env: [ ARCH=x86_64, ASAN=none, BUILD_TYPE=Debug, SSL=NO, GENERATOR="Unix Makefiles" ] - - <<: *linux_gcc8 - env: [ ARCH=x86_64, ASAN=none, BUILD_TYPE=Release, SSL=YES, GENERATOR="Unix Makefiles" ] - <<: *linux_clang env: [ ARCH=x86_64, ASAN=address, BUILD_TYPE=Debug, SSL=YES, GENERATOR="Unix Makefiles" ] - <<: *linux_clang From 1cc6caff14ba79a817a4a266d561da23786e791e Mon Sep 17 00:00:00 2001 From: Scott K Logan Date: Tue, 22 Oct 2019 10:53:18 -0700 Subject: [PATCH 08/12] First check the CMake Package Registry for CUnit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is useful when building CycloneDDS on platforms that provide CMake configuration for CUnit outside of Conan. If no configuration is found in the system CMake registry the module continues as before. Co-authored-by: Steven! Ragnarök Signed-off-by: Scott K Logan --- cmake/Modules/FindCUnit.cmake | 44 ++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/cmake/Modules/FindCUnit.cmake b/cmake/Modules/FindCUnit.cmake index 518ed8a..c17b859 100644 --- a/cmake/Modules/FindCUnit.cmake +++ b/cmake/Modules/FindCUnit.cmake @@ -9,31 +9,37 @@ # # SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause # -set(CUNIT_HEADER "CUnit/CUnit.h") - -if(CONAN_INCLUDE_DIRS) - find_path(CUNIT_INCLUDE_DIR ${CUNIT_HEADER} HINTS ${CONAN_INCLUDE_DIRS}) +find_package(CUnit CONFIG QUIET) +if(CUnit_FOUND) + message(STATUS "Found CUnit via Config file: ${CUnit_DIR}") + set(CUNIT_FOUND ${CUnit_FOUND}) else() - find_path(CUNIT_INCLUDE_DIR ${CUNIT_HEADER}) -endif() + set(CUNIT_HEADER "CUnit/CUnit.h") -mark_as_advanced(CUNIT_INCLUDE_DIR) + if(CONAN_INCLUDE_DIRS) + find_path(CUNIT_INCLUDE_DIR ${CUNIT_HEADER} HINTS ${CONAN_INCLUDE_DIRS}) + else() + find_path(CUNIT_INCLUDE_DIR ${CUNIT_HEADER}) + endif() -if(CUNIT_INCLUDE_DIR AND EXISTS "${CUNIT_INCLUDE_DIR}/${CUNIT_HEADER}") - set(PATTERN "^#define CU_VERSION \"([0-9]+)\\.([0-9]+)\\-([0-9]+)\"$") - file(STRINGS "${CUNIT_INCLUDE_DIR}/${CUNIT_HEADER}" CUNIT_H REGEX "${PATTERN}") + mark_as_advanced(CUNIT_INCLUDE_DIR) - string(REGEX REPLACE "${PATTERN}" "\\1" CUNIT_VERSION_MAJOR "${CUNIT_H}") - string(REGEX REPLACE "${PATTERN}" "\\2" CUNIT_VERSION_MINOR "${CUNIT_H}") - string(REGEX REPLACE "${PATTERN}" "\\3" CUNIT_VERSION_PATCH "${CUNIT_H}") + if(CUNIT_INCLUDE_DIR AND EXISTS "${CUNIT_INCLUDE_DIR}/${CUNIT_HEADER}") + set(PATTERN "^#define CU_VERSION \"([0-9]+)\\.([0-9]+)\\-([0-9]+)\"$") + file(STRINGS "${CUNIT_INCLUDE_DIR}/${CUNIT_HEADER}" CUNIT_H REGEX "${PATTERN}") - set(CUNIT_VERSION "${CUNIT_VERSION_MAJOR}.${CUNIT_VERSION_MINOR}-${CUNIT_VERSION_PATCH}") -endif() + string(REGEX REPLACE "${PATTERN}" "\\1" CUNIT_VERSION_MAJOR "${CUNIT_H}") + string(REGEX REPLACE "${PATTERN}" "\\2" CUNIT_VERSION_MINOR "${CUNIT_H}") + string(REGEX REPLACE "${PATTERN}" "\\3" CUNIT_VERSION_PATCH "${CUNIT_H}") -if(CONAN_LIB_DIRS) - find_library(CUNIT_LIBRARY cunit HINTS ${CONAN_LIB_DIRS}) -else() - find_library(CUNIT_LIBRARY cunit) + set(CUNIT_VERSION "${CUNIT_VERSION_MAJOR}.${CUNIT_VERSION_MINOR}-${CUNIT_VERSION_PATCH}") + endif() + + if(CONAN_LIB_DIRS) + find_library(CUNIT_LIBRARY cunit HINTS ${CONAN_LIB_DIRS}) + else() + find_library(CUNIT_LIBRARY cunit) + endif() endif() include(FindPackageHandleStandardArgs) From 860a6aadae5c6e31456454496d5b918892434d18 Mon Sep 17 00:00:00 2001 From: Scott K Logan Date: Tue, 22 Oct 2019 11:49:47 -0700 Subject: [PATCH 09/12] Drop IDLC when building with colcon This will eliminate two large dependencies when building CycloneDDS with colcon for ROS 2, which doesn't appear to need the IDLC. Signed-off-by: Scott K Logan --- colcon.pkg | 3 +++ package.xml | 2 -- 2 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 colcon.pkg diff --git a/colcon.pkg b/colcon.pkg new file mode 100644 index 0000000..2d2a3ae --- /dev/null +++ b/colcon.pkg @@ -0,0 +1,3 @@ +{ + "cmake-args": [ "-DBUILD_IDLC=OFF" ] +} diff --git a/package.xml b/package.xml index 5b4b661..9d0980d 100644 --- a/package.xml +++ b/package.xml @@ -12,8 +12,6 @@ https://github.com/eclipse-cyclonedds/cyclonedds cmake - java - maven openssl libcunit-dev python3-sphinx From 76fa68808682a15dd8aff26da20622ac574fa1a1 Mon Sep 17 00:00:00 2001 From: Dan Rose Date: Tue, 22 Oct 2019 15:55:13 -0500 Subject: [PATCH 10/12] CMAKE_SOURCE_DIR -> CMAKE_CURRENT_SOURCE_DIR Signed-off-by: Dan Rose --- examples/helloworld/CMakeLists.export | 2 +- examples/roundtrip/CMakeLists.export | 2 +- examples/throughput/CMakeLists.export | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/helloworld/CMakeLists.export b/examples/helloworld/CMakeLists.export index 3fcb0af..5712559 100644 --- a/examples/helloworld/CMakeLists.export +++ b/examples/helloworld/CMakeLists.export @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.5) if (NOT TARGET CycloneDDS::ddsc) # Find the CycloneDDS package. If it is not in a default location, try # finding it relative to the example where it most likely resides. - find_package(CycloneDDS REQUIRED PATHS "${CMAKE_SOURCE_DIR}/../../") + find_package(CycloneDDS REQUIRED PATHS "${CMAKE_CURRENT_SOURCE_DIR}/../../") endif() # This is a convenience function, provided by the CycloneDDS package, diff --git a/examples/roundtrip/CMakeLists.export b/examples/roundtrip/CMakeLists.export index 58a36ac..9554013 100644 --- a/examples/roundtrip/CMakeLists.export +++ b/examples/roundtrip/CMakeLists.export @@ -14,7 +14,7 @@ cmake_minimum_required(VERSION 3.5) if (NOT TARGET CycloneDDS::ddsc) # Find the CycloneDDS package. If it is not in a default location, try # finding it relative to the example where it most likely resides. - find_package(CycloneDDS REQUIRED PATHS "${CMAKE_SOURCE_DIR}/../../") + find_package(CycloneDDS REQUIRED PATHS "${CMAKE_CURRENT_SOURCE_DIR}/../../") endif() # This is a convenience function, provided by the CycloneDDS package, diff --git a/examples/throughput/CMakeLists.export b/examples/throughput/CMakeLists.export index dfce4b4..52415e0 100644 --- a/examples/throughput/CMakeLists.export +++ b/examples/throughput/CMakeLists.export @@ -14,7 +14,7 @@ cmake_minimum_required(VERSION 3.5) if (NOT TARGET CycloneDDS::ddsc) # Find the CycloneDDS package. If it is not in a default location, try # finding it relative to the example where it most likely resides. - find_package(CycloneDDS REQUIRED PATHS "${CMAKE_SOURCE_DIR}/../../") + find_package(CycloneDDS REQUIRED PATHS "${CMAKE_CURRENT_SOURCE_DIR}/../../") endif() # This is a convenience function, provided by the CycloneDDS package, From c8aa6fee5a9bc1057e371e46362289bf78d66014 Mon Sep 17 00:00:00 2001 From: dennis-adlink <45659984+dennis-adlink@users.noreply.github.com> Date: Mon, 28 Oct 2019 15:03:46 +0100 Subject: [PATCH 11/12] Moved bswap functions to ddsrt (#297) * Moved bswap functions to ddsrt Moved the byte swapping functions from ddsi to ddsrt so that these can be re-used in e.g. the security plugins and tests. Signed-off-by: Dennis Potman * Moved decarations for bswap functions to ddsrt Signed-off-by: Dennis Potman --- src/core/ddsc/src/dds_sertopic_builtintopic.c | 1 - src/core/ddsc/src/dds_stream.c | 40 ++++----- src/core/ddsi/CMakeLists.txt | 1 - src/core/ddsi/include/dds/ddsi/q_bswap.h | 65 +------------- src/core/ddsi/src/ddsi_serdata_default.c | 4 +- src/core/ddsi/src/q_bswap.c | 21 +++-- src/core/ddsi/src/q_init.c | 2 +- src/core/ddsi/src/q_lease.c | 2 +- src/core/ddsi/src/q_pcap.c | 8 +- src/core/ddsi/src/q_plist.c | 22 ++--- src/core/ddsi/src/q_receive.c | 34 ++++---- src/core/ddsi/src/q_xevent.c | 2 +- src/core/ddsi/src/q_xmsg.c | 6 +- src/ddsrt/CMakeLists.txt | 1 + src/ddsrt/include/dds/ddsrt/bswap.h | 87 +++++++++++++++++++ .../q_bswap_inlines.c => ddsrt/src/bswap.c} | 16 ++-- 16 files changed, 170 insertions(+), 142 deletions(-) create mode 100644 src/ddsrt/include/dds/ddsrt/bswap.h rename src/{core/ddsi/src/q_bswap_inlines.c => ddsrt/src/bswap.c} (55%) diff --git a/src/core/ddsc/src/dds_sertopic_builtintopic.c b/src/core/ddsc/src/dds_sertopic_builtintopic.c index 3479fa4..07f730c 100644 --- a/src/core/ddsc/src/dds_sertopic_builtintopic.c +++ b/src/core/ddsc/src/dds_sertopic_builtintopic.c @@ -17,7 +17,6 @@ #include "dds/dds.h" #include "dds/ddsrt/heap.h" #include "dds/ddsrt/md5.h" -#include "dds/ddsi/q_bswap.h" #include "dds/ddsi/q_config.h" #include "dds/ddsi/q_freelist.h" #include "dds/ddsi/ddsi_sertopic.h" diff --git a/src/core/ddsc/src/dds_stream.c b/src/core/ddsc/src/dds_stream.c index 3f12777..9be8810 100644 --- a/src/core/ddsc/src/dds_stream.c +++ b/src/core/ddsc/src/dds_stream.c @@ -175,17 +175,17 @@ static void dds_os_put1be (dds_ostreamBE_t * __restrict s, uint8_t v) static void dds_os_put2be (dds_ostreamBE_t * __restrict s, uint16_t v) { - dds_os_put2 (&s->x, toBE2u (v)); + dds_os_put2 (&s->x, ddsrt_toBE2u (v)); } static void dds_os_put4be (dds_ostreamBE_t * __restrict s, uint32_t v) { - dds_os_put4 (&s->x, toBE4u (v)); + dds_os_put4 (&s->x, ddsrt_toBE4u (v)); } static void dds_os_put8be (dds_ostreamBE_t * __restrict s, uint64_t v) { - dds_os_put8 (&s->x, toBE8u (v)); + dds_os_put8 (&s->x, ddsrt_toBE8u (v)); } static void dds_os_put_bytes (dds_ostream_t * __restrict s, const void * __restrict b, uint32_t l) @@ -782,7 +782,7 @@ static bool normalize_uint16 (char * __restrict data, uint32_t * __restrict off, if ((*off = check_align_prim (*off, size, 1)) == UINT32_MAX) return false; if (bswap) - *((uint16_t *) (data + *off)) = bswap2u (*((uint16_t *) (data + *off))); + *((uint16_t *) (data + *off)) = ddsrt_bswap2u (*((uint16_t *) (data + *off))); (*off) += 2; return true; } @@ -792,7 +792,7 @@ static bool normalize_uint32 (char * __restrict data, uint32_t * __restrict off, if ((*off = check_align_prim (*off, size, 2)) == UINT32_MAX) return false; if (bswap) - *((uint32_t *) (data + *off)) = bswap4u (*((uint32_t *) (data + *off))); + *((uint32_t *) (data + *off)) = ddsrt_bswap4u (*((uint32_t *) (data + *off))); (*off) += 4; return true; } @@ -802,7 +802,7 @@ static bool read_and_normalize_uint32 (uint32_t * __restrict val, char * __restr if ((*off = check_align_prim (*off, size, 2)) == UINT32_MAX) return false; if (bswap) - *((uint32_t *) (data + *off)) = bswap4u (*((uint32_t *) (data + *off))); + *((uint32_t *) (data + *off)) = ddsrt_bswap4u (*((uint32_t *) (data + *off))); *val = *((uint32_t *) (data + *off)); (*off) += 4; return true; @@ -813,7 +813,7 @@ static bool normalize_uint64 (char * __restrict data, uint32_t * __restrict off, if ((*off = check_align_prim (*off, size, 3)) == UINT32_MAX) return false; if (bswap) - *((uint64_t *) (data + *off)) = bswap8u (*((uint64_t *) (data + *off))); + *((uint64_t *) (data + *off)) = ddsrt_bswap8u (*((uint64_t *) (data + *off))); (*off) += 8; return true; } @@ -847,7 +847,7 @@ static bool normalize_primarray (char * __restrict data, uint32_t * __restrict o { uint16_t *xs = (uint16_t *) (data + *off); for (uint32_t i = 0; i < num; i++) - xs[i] = bswap2u (xs[i]); + xs[i] = ddsrt_bswap2u (xs[i]); } *off += 2 * num; return true; @@ -858,7 +858,7 @@ static bool normalize_primarray (char * __restrict data, uint32_t * __restrict o { uint32_t *xs = (uint32_t *) (data + *off); for (uint32_t i = 0; i < num; i++) - xs[i] = bswap4u (xs[i]); + xs[i] = ddsrt_bswap4u (xs[i]); } *off += 4 * num; return true; @@ -869,7 +869,7 @@ static bool normalize_primarray (char * __restrict data, uint32_t * __restrict o { uint64_t *xs = (uint64_t *) (data + *off); for (uint32_t i = 0; i < num; i++) - xs[i] = bswap8u (xs[i]); + xs[i] = ddsrt_bswap8u (xs[i]); } *off += 8 * num; return true; @@ -956,7 +956,7 @@ static bool normalize_uni_disc (uint32_t * __restrict val, char * __restrict dat if ((*off = check_align_prim (*off, size, 1)) == UINT32_MAX) return false; if (bswap) - *((uint16_t *) (data + *off)) = bswap2u (*((uint16_t *) (data + *off))); + *((uint16_t *) (data + *off)) = ddsrt_bswap2u (*((uint16_t *) (data + *off))); *val = *((uint16_t *) (data + *off)); (*off) += 2; return true; @@ -964,7 +964,7 @@ static bool normalize_uni_disc (uint32_t * __restrict val, char * __restrict dat if ((*off = check_align_prim (*off, size, 2)) == UINT32_MAX) return false; if (bswap) - *((uint32_t *) (data + *off)) = bswap4u (*((uint32_t *) (data + *off))); + *((uint32_t *) (data + *off)) = ddsrt_bswap4u (*((uint32_t *) (data + *off))); *val = *((uint32_t *) (data + *off)); (*off) += 4; return true; @@ -1180,19 +1180,19 @@ static void dds_stream_swap_insitu (void * __restrict vbuf, uint32_t size, uint3 case 2: { uint16_t *buf = vbuf; for (uint32_t i = 0; i < num; i++) - buf[i] = bswap2u (buf[i]); + buf[i] = ddsrt_bswap2u (buf[i]); break; } case 4: { uint32_t *buf = vbuf; for (uint32_t i = 0; i < num; i++) - buf[i] = bswap4u (buf[i]); + buf[i] = ddsrt_bswap4u (buf[i]); break; } case 8: { uint64_t *buf = vbuf; for (uint32_t i = 0; i < num; i++) - buf[i] = bswap8u (buf[i]); + buf[i] = ddsrt_bswap8u (buf[i]); break; } } @@ -1294,21 +1294,21 @@ static void dds_stream_swap_copy (void * __restrict vdst, const void * __restric const uint16_t *src = vsrc; uint16_t *dst = vdst; for (uint32_t i = 0; i < num; i++) - dst[i] = bswap2u (src[i]); + dst[i] = ddsrt_bswap2u (src[i]); break; } case 4: { const uint32_t *src = vsrc; uint32_t *dst = vdst; for (uint32_t i = 0; i < num; i++) - dst[i] = bswap4u (src[i]); + dst[i] = ddsrt_bswap4u (src[i]); break; } case 8: { const uint64_t *src = vsrc; uint64_t *dst = vdst; for (uint32_t i = 0; i < num; i++) - dst[i] = bswap8u (src[i]); + dst[i] = ddsrt_bswap8u (src[i]); break; } } @@ -1943,7 +1943,7 @@ void dds_ostream_add_to_serdata_default (dds_ostream_t * __restrict s, struct dd (*d) = (void *) s->m_buffer; (*d)->pos = (s->m_index - (uint32_t) offsetof (struct ddsi_serdata_default, data)); (*d)->size = (s->m_size - (uint32_t) offsetof (struct ddsi_serdata_default, data)); - (*d)->hdr.options = toBE2u ((uint16_t) pad); + (*d)->hdr.options = ddsrt_toBE2u ((uint16_t) pad); } void dds_ostreamBE_from_serdata_default (dds_ostreamBE_t * __restrict s, struct ddsi_serdata_default * __restrict d) @@ -1966,5 +1966,5 @@ void dds_ostreamBE_add_to_serdata_default (dds_ostreamBE_t * __restrict s, struc (*d) = (void *) s->x.m_buffer; (*d)->pos = (s->x.m_index - (uint32_t) offsetof (struct ddsi_serdata_default, data)); (*d)->size = (s->x.m_size - (uint32_t) offsetof (struct ddsi_serdata_default, data)); - (*d)->hdr.options = toBE2u ((uint16_t) pad); + (*d)->hdr.options = ddsrt_toBE2u ((uint16_t) pad); } diff --git a/src/core/ddsi/CMakeLists.txt b/src/core/ddsi/CMakeLists.txt index abde8ad..9e8c6a7 100644 --- a/src/core/ddsi/CMakeLists.txt +++ b/src/core/ddsi/CMakeLists.txt @@ -30,7 +30,6 @@ PREPEND(srcs_ddsi "${CMAKE_CURRENT_LIST_DIR}/src" q_addrset.c q_bitset_inlines.c q_bswap.c - q_bswap_inlines.c q_config.c q_ddsi_discovery.c q_debmon.c diff --git a/src/core/ddsi/include/dds/ddsi/q_bswap.h b/src/core/ddsi/include/dds/ddsi/q_bswap.h index d7f058d..93a3706 100644 --- a/src/core/ddsi/include/dds/ddsi/q_bswap.h +++ b/src/core/ddsi/include/dds/ddsi/q_bswap.h @@ -14,7 +14,7 @@ #include -#include "dds/ddsrt/endian.h" +#include "dds/ddsrt/bswap.h" #include "dds/ddsrt/misc.h" #include "dds/ddsi/q_rtps.h" /* for nn_guid_t, nn_guid_prefix_t */ #include "dds/ddsi/q_protocol.h" /* for nn_sequence_number_t */ @@ -23,71 +23,12 @@ extern "C" { #endif -inline uint16_t bswap2u (uint16_t x) -{ - return (uint16_t) ((x >> 8) | (x << 8)); -} - -inline int16_t bswap2 (int16_t x) -{ - return (int16_t) bswap2u ((uint16_t) x); -} - -inline uint32_t bswap4u (uint32_t x) -{ - return (x >> 24) | ((x >> 8) & 0xff00) | ((x << 8) & 0xff0000) | (x << 24); -} - -inline int32_t bswap4 (int32_t x) -{ - return (int32_t) bswap4u ((uint32_t) x); -} - -inline uint64_t bswap8u (uint64_t x) -{ - const uint32_t newhi = bswap4u ((uint32_t) x); - const uint32_t newlo = bswap4u ((uint32_t) (x >> 32)); - return ((uint64_t) newhi << 32) | (uint64_t) newlo; -} - -inline int64_t bswap8 (int64_t x) -{ - return (int64_t) bswap8u ((uint64_t) x); -} - inline void bswapSN (nn_sequence_number_t *sn) { - sn->high = bswap4 (sn->high); - sn->low = bswap4u (sn->low); + sn->high = ddsrt_bswap4 (sn->high); + sn->low = ddsrt_bswap4u (sn->low); } -#if DDSRT_ENDIAN == DDSRT_LITTLE_ENDIAN -#define toBE2(x) bswap2 (x) -#define toBE2u(x) bswap2u (x) -#define toBE4(x) bswap4 (x) -#define toBE4u(x) bswap4u (x) -#define toBE8(x) bswap8 (x) -#define toBE8u(x) bswap8u (x) -#define fromBE2(x) bswap2 (x) -#define fromBE2u(x) bswap2u (x) -#define fromBE4(x) bswap4 (x) -#define fromBE4u(x) bswap4u (x) -#define fromBE8(x) bswap8 (x) -#define fromBE8u(x) bswap8u (x) -#else -#define toBE2u(x) (x) -#define toBE4(x) (x) -#define toBE4u(x) (x) -#define toBE8(x) (x) -#define toBE8u(x) (x) -#define fromBE2(x) (x) -#define fromBE2u(x) (x) -#define fromBE4(x) (x) -#define fromBE4u(x) (x) -#define fromBE8(x) (x) -#define fromBE8u(x) (x) -#endif - ddsi_guid_prefix_t nn_hton_guid_prefix (ddsi_guid_prefix_t p); ddsi_guid_prefix_t nn_ntoh_guid_prefix (ddsi_guid_prefix_t p); ddsi_entityid_t nn_hton_entityid (ddsi_entityid_t e); diff --git a/src/core/ddsi/src/ddsi_serdata_default.c b/src/core/ddsi/src/ddsi_serdata_default.c index 39879f4..666e0d3 100644 --- a/src/core/ddsi/src/ddsi_serdata_default.c +++ b/src/core/ddsi/src/ddsi_serdata_default.c @@ -296,7 +296,7 @@ static struct ddsi_serdata_default *serdata_default_from_ser_common (const struc const bool needs_bswap = (d->hdr.identifier != NATIVE_ENCODING); d->hdr.identifier = NATIVE_ENCODING; - const uint32_t pad = fromBE2u (d->hdr.options) & 2; + const uint32_t pad = ddsrt_fromBE2u (d->hdr.options) & 2; if (d->pos < pad) { ddsi_serdata_unref (&d->c); @@ -474,7 +474,7 @@ static struct ddsi_serdata *serdata_default_from_sample_plist (const struct ddsi ddsrt_md5_state_t md5st; ddsrt_md5_byte_t digest[16]; topic_name_sz = (uint32_t) strlen (topic_name) + 1; - topic_name_sz_BE = toBE4u (topic_name_sz); + topic_name_sz_BE = ddsrt_toBE4u (topic_name_sz); d->keyhash.m_set = 1; d->keyhash.m_iskey = 0; ddsrt_md5_init (&md5st); diff --git a/src/core/ddsi/src/q_bswap.c b/src/core/ddsi/src/q_bswap.c index 73e1778..c2d11c1 100644 --- a/src/core/ddsi/src/q_bswap.c +++ b/src/core/ddsi/src/q_bswap.c @@ -11,11 +11,13 @@ */ #include "dds/ddsi/q_bswap.h" +extern inline void bswapSN (nn_sequence_number_t *sn); + ddsi_guid_prefix_t nn_hton_guid_prefix (ddsi_guid_prefix_t p) { int i; for (i = 0; i < 3; i++) - p.u[i] = toBE4u (p.u[i]); + p.u[i] = ddsrt_toBE4u (p.u[i]); return p; } @@ -23,19 +25,19 @@ ddsi_guid_prefix_t nn_ntoh_guid_prefix (ddsi_guid_prefix_t p) { int i; for (i = 0; i < 3; i++) - p.u[i] = fromBE4u (p.u[i]); + p.u[i] = ddsrt_fromBE4u (p.u[i]); return p; } ddsi_entityid_t nn_hton_entityid (ddsi_entityid_t e) { - e.u = toBE4u (e.u); + e.u = ddsrt_toBE4u (e.u); return e; } ddsi_entityid_t nn_ntoh_entityid (ddsi_entityid_t e) { - e.u = fromBE4u (e.u); + e.u = ddsrt_fromBE4u (e.u); return e; } @@ -56,25 +58,26 @@ ddsi_guid_t nn_ntoh_guid (ddsi_guid_t g) void bswap_sequence_number_set_hdr (nn_sequence_number_set_header_t *snset) { bswapSN (&snset->bitmap_base); - snset->numbits = bswap4u (snset->numbits); + snset->numbits = ddsrt_bswap4u (snset->numbits); } void bswap_sequence_number_set_bitmap (nn_sequence_number_set_header_t *snset, uint32_t *bits) { const uint32_t n = (snset->numbits + 31) / 32; for (uint32_t i = 0; i < n; i++) - bits[i] = bswap4u (bits[i]); + bits[i] = ddsrt_bswap4u (bits[i]); } void bswap_fragment_number_set_hdr (nn_fragment_number_set_header_t *fnset) { - fnset->bitmap_base = bswap4u (fnset->bitmap_base); - fnset->numbits = bswap4u (fnset->numbits); + fnset->bitmap_base = ddsrt_bswap4u (fnset->bitmap_base); + fnset->numbits = ddsrt_bswap4u (fnset->numbits); } void bswap_fragment_number_set_bitmap (nn_fragment_number_set_header_t *fnset, uint32_t *bits) { const uint32_t n = (fnset->numbits + 31) / 32; for (uint32_t i = 0; i < n; i++) - bits[i] = bswap4u (bits[i]); + bits[i] = ddsrt_bswap4u (bits[i]); } + diff --git a/src/core/ddsi/src/q_init.c b/src/core/ddsi/src/q_init.c index f2bb0d9..c73a39e 100644 --- a/src/core/ddsi/src/q_init.c +++ b/src/core/ddsi/src/q_init.c @@ -1038,7 +1038,7 @@ int rtps_init (struct q_globals *gv) that won't repeat in the lifetime of the process. Seems like it ought to work to keep the risks of collisions low. */ { - uint64_t iid = toBE8u (ddsi_iid_gen ()); + uint64_t iid = ddsrt_toBE8u (ddsi_iid_gen ()); ddsrt_md5_state_t st; ddsrt_md5_byte_t digest[16]; ddsrt_md5_init (&st); diff --git a/src/core/ddsi/src/q_lease.c b/src/core/ddsi/src/q_lease.c index 4015085..e35abda 100644 --- a/src/core/ddsi/src/q_lease.c +++ b/src/core/ddsi/src/q_lease.c @@ -320,7 +320,7 @@ void handle_PMD (const struct receiver_state *rst, nn_wctime_t timestamp, uint32 const ParticipantMessageData_t *pmd = (ParticipantMessageData_t *) (data + 1); ddsi_guid_prefix_t p = nn_ntoh_guid_prefix (pmd->participantGuidPrefix); uint32_t kind = ntohl (pmd->kind); - uint32_t length = bswap ? bswap4u (pmd->length) : pmd->length; + uint32_t length = bswap ? ddsrt_bswap4u (pmd->length) : pmd->length; RSTTRACE (" pp %"PRIx32":%"PRIx32":%"PRIx32" kind %u data %u", p.u[0], p.u[1], p.u[2], kind, length); if (len - sizeof (struct CDRHeader) - offsetof (ParticipantMessageData_t, value) < length) debug_print_rawdata (rst->gv, " SHORT2", pmd->value, len - sizeof (struct CDRHeader) - offsetof (ParticipantMessageData_t, value)); diff --git a/src/core/ddsi/src/q_pcap.c b/src/core/ddsi/src/q_pcap.c index 3fb0e68..f588bbc 100644 --- a/src/core/ddsi/src/q_pcap.c +++ b/src/core/ddsi/src/q_pcap.c @@ -144,7 +144,7 @@ void write_pcap_received (struct q_globals *gv, nn_wctime_t tstamp, const struct pcap_hdr.incl_len = pcap_hdr.orig_len = (uint32_t) sz_iud; fwrite (&pcap_hdr, sizeof (pcap_hdr), 1, gv->pcap_fp); u.ipv4_hdr = ipv4_hdr_template; - u.ipv4_hdr.totallength = toBE2u ((unsigned short) sz_iud); + u.ipv4_hdr.totallength = ddsrt_toBE2u ((unsigned short) sz_iud); u.ipv4_hdr.ttl = 128; u.ipv4_hdr.srcip = ((struct sockaddr_in*) src)->sin_addr.s_addr; u.ipv4_hdr.dstip = ((struct sockaddr_in*) dst)->sin_addr.s_addr; @@ -152,7 +152,7 @@ void write_pcap_received (struct q_globals *gv, nn_wctime_t tstamp, const struct fwrite (&u.ipv4_hdr, sizeof (u.ipv4_hdr), 1, gv->pcap_fp); udp_hdr.srcport = ((struct sockaddr_in*) src)->sin_port; udp_hdr.dstport = ((struct sockaddr_in*) dst)->sin_port; - udp_hdr.length = toBE2u ((unsigned short) sz_ud); + udp_hdr.length = ddsrt_toBE2u ((unsigned short) sz_ud); udp_hdr.checksum = 0; /* don't have to compute a checksum for UDPv4 */ fwrite (&udp_hdr, sizeof (udp_hdr), 1, gv->pcap_fp); fwrite (buf, sz, 1, gv->pcap_fp); @@ -177,7 +177,7 @@ void write_pcap_sent (struct q_globals *gv, nn_wctime_t tstamp, const struct soc pcap_hdr.incl_len = pcap_hdr.orig_len = (uint32_t) sz_iud; fwrite (&pcap_hdr, sizeof (pcap_hdr), 1, gv->pcap_fp); u.ipv4_hdr = ipv4_hdr_template; - u.ipv4_hdr.totallength = toBE2u ((unsigned short) sz_iud); + u.ipv4_hdr.totallength = ddsrt_toBE2u ((unsigned short) sz_iud); u.ipv4_hdr.ttl = 255; u.ipv4_hdr.srcip = ((struct sockaddr_in*) src)->sin_addr.s_addr; u.ipv4_hdr.dstip = ((struct sockaddr_in*) hdr->msg_name)->sin_addr.s_addr; @@ -185,7 +185,7 @@ void write_pcap_sent (struct q_globals *gv, nn_wctime_t tstamp, const struct soc fwrite (&u.ipv4_hdr, sizeof (u.ipv4_hdr), 1, gv->pcap_fp); udp_hdr.srcport = ((struct sockaddr_in*) src)->sin_port; udp_hdr.dstport = ((struct sockaddr_in*) hdr->msg_name)->sin_port; - udp_hdr.length = toBE2u ((unsigned short) sz_ud); + udp_hdr.length = ddsrt_toBE2u ((unsigned short) sz_ud); udp_hdr.checksum = 0; /* don't have to compute a checksum for UDPv4 */ fwrite (&udp_hdr, sizeof (udp_hdr), 1, gv->pcap_fp); write_data (gv->pcap_fp, hdr, sz); diff --git a/src/core/ddsi/src/q_plist.c b/src/core/ddsi/src/q_plist.c index 50a9721..b11931e 100644 --- a/src/core/ddsi/src/q_plist.c +++ b/src/core/ddsi/src/q_plist.c @@ -163,7 +163,7 @@ static dds_return_t deser_uint32 (uint32_t *dst, const struct dd * __restrict dd return DDS_RETCODE_BAD_PARAMETER; tmp = *((uint32_t *) (dd->buf + off1)); if (dd->bswap) - tmp = bswap4u (tmp); + tmp = ddsrt_bswap4u (tmp); *dst = tmp; *off = off1 + 4; return 0; @@ -231,7 +231,7 @@ static dds_return_t deser_statusinfo (void * __restrict dst, size_t * __restrict /* status info is always in BE format (it is an array of 4 octets according to the spec) -- fortunately we have 4 byte alignment anyway -- and can have bits set we don't grok (which we discard) */ - *x = fromBE4u (*((uint32_t *) (dd->buf + srcoff1))) & NN_STATUSINFO_STANDARDIZED; + *x = ddsrt_fromBE4u (*((uint32_t *) (dd->buf + srcoff1))) & NN_STATUSINFO_STANDARDIZED; *dstoff += sizeof (*x); *srcoff = srcoff1 + 4; *flagset->present |= flag; @@ -242,7 +242,7 @@ static dds_return_t ser_statusinfo (struct nn_xmsg *xmsg, nn_parameterid_t pid, { uint32_t const * const x = deser_generic_src (src, &srcoff, alignof (uint32_t)); uint32_t * const p = nn_xmsg_addpar (xmsg, pid, sizeof (uint32_t)); - *p = toBE4u (*x); + *p = ddsrt_toBE4u (*x); return 0; } @@ -1876,8 +1876,8 @@ static dds_return_t do_locator (nn_locators_t *ls, uint64_t *present, uint64_t w memcpy (&loc, dd->buf, sizeof (loc)); if (dd->bswap) { - loc.kind = bswap4 (loc.kind); - loc.port = bswap4u (loc.port); + loc.kind = ddsrt_bswap4 (loc.kind); + loc.port = ddsrt_bswap4u (loc.port); } switch (loc.kind) { @@ -2031,7 +2031,7 @@ static dds_return_t do_port (nn_plist_t *dest, nn_ipaddress_params_tmp_t *dest_t } memcpy (p, dd->buf, sizeof (*p)); if (dd->bswap) - *p = bswap4u (*p); + *p = ddsrt_bswap4u (*p); if (*p <= 0 || *p > 65535) return DDS_RETCODE_BAD_PARAMETER; dest_tmp->present |= fl_tmp; @@ -2331,8 +2331,8 @@ dds_return_t nn_plist_init_frommsg (nn_plist_t *dest, char **nextafterplist, uin /* swapping header partially based on wireshark dissector output, partially on intuition, and in a small part based on the spec */ - pid = (nn_parameterid_t) (dd.bswap ? bswap2u (par->parameterid) : par->parameterid); - length = (uint16_t) (dd.bswap ? bswap2u (par->length) : par->length); + pid = (nn_parameterid_t) (dd.bswap ? ddsrt_bswap2u (par->parameterid) : par->parameterid); + length = (uint16_t) (dd.bswap ? ddsrt_bswap2u (par->length) : par->length); if (pid == PID_SENTINEL) { /* Sentinel terminates list, the length is ignored, DDSI 9.4.2.11. */ @@ -2450,8 +2450,8 @@ unsigned char *nn_plist_quickscan (struct nn_rsample_info *dest, const struct nn nn_parameter_t *par = (nn_parameter_t *) pl; nn_parameterid_t pid; uint16_t length; - pid = (nn_parameterid_t) (dest->bswap ? bswap2u (par->parameterid) : par->parameterid); - length = (uint16_t) (dest->bswap ? bswap2u (par->length) : par->length); + pid = (nn_parameterid_t) (dest->bswap ? ddsrt_bswap2u (par->parameterid) : par->parameterid); + length = (uint16_t) (dest->bswap ? ddsrt_bswap2u (par->length) : par->length); pl += sizeof (*par); if (pid == PID_SENTINEL) return (unsigned char *) pl; @@ -2482,7 +2482,7 @@ unsigned char *nn_plist_quickscan (struct nn_rsample_info *dest, const struct nn { /* can only represent 2 LSBs of statusinfo in "dest", so if others are set, mark it as a "complex_qos" and accept the hit of parsing the data completely. */ - uint32_t stinfo = fromBE4u (*((uint32_t *) pl)); + uint32_t stinfo = ddsrt_fromBE4u (*((uint32_t *) pl)); dest->statusinfo = stinfo & 3u; if ((stinfo & ~3u)) dest->complex_qos = 1; diff --git a/src/core/ddsi/src/q_receive.c b/src/core/ddsi/src/q_receive.c index ada45a0..6f4b7a8 100644 --- a/src/core/ddsi/src/q_receive.c +++ b/src/core/ddsi/src/q_receive.c @@ -145,7 +145,7 @@ static int valid_AckNack (const struct receiver_state *rst, AckNack_t *msg, size if (byteswap) { bswap_sequence_number_set_bitmap (&msg->readerSNState, msg->bits); - *count = bswap4 (*count); + *count = ddsrt_bswap4 (*count); } return 1; } @@ -199,8 +199,8 @@ static int valid_InfoTS (InfoTS_t *msg, size_t size, int byteswap) { if (byteswap) { - msg->time.seconds = bswap4 (msg->time.seconds); - msg->time.fraction = bswap4u (msg->time.fraction); + msg->time.seconds = ddsrt_bswap4 (msg->time.seconds); + msg->time.fraction = ddsrt_bswap4u (msg->time.fraction); } return valid_ddsi_timestamp (msg->time); } @@ -214,7 +214,7 @@ static int valid_Heartbeat (Heartbeat_t *msg, size_t size, int byteswap) { bswapSN (&msg->firstSN); bswapSN (&msg->lastSN); - msg->count = bswap4 (msg->count); + msg->count = ddsrt_bswap4 (msg->count); } msg->readerId = nn_ntoh_entityid (msg->readerId); msg->writerId = nn_ntoh_entityid (msg->writerId); @@ -231,8 +231,8 @@ static int valid_HeartbeatFrag (HeartbeatFrag_t *msg, size_t size, int byteswap) if (byteswap) { bswapSN (&msg->writerSN); - msg->lastFragmentNum = bswap4u (msg->lastFragmentNum); - msg->count = bswap4 (msg->count); + msg->lastFragmentNum = ddsrt_bswap4u (msg->lastFragmentNum); + msg->count = ddsrt_bswap4 (msg->count); } msg->readerId = nn_ntoh_entityid (msg->readerId); msg->writerId = nn_ntoh_entityid (msg->writerId); @@ -267,7 +267,7 @@ static int valid_NackFrag (NackFrag_t *msg, size_t size, int byteswap) if (byteswap) { bswap_fragment_number_set_bitmap (&msg->fragmentNumberState, msg->bits); - *count = bswap4 (*count); + *count = ddsrt_bswap4 (*count); } return 1; } @@ -292,8 +292,8 @@ static int valid_Data (const struct receiver_state *rst, struct nn_rmsg *rmsg, D return 0; if (byteswap) { - msg->x.extraFlags = bswap2u (msg->x.extraFlags); - msg->x.octetsToInlineQos = bswap2u (msg->x.octetsToInlineQos); + msg->x.extraFlags = ddsrt_bswap2u (msg->x.extraFlags); + msg->x.octetsToInlineQos = ddsrt_bswap2u (msg->x.octetsToInlineQos); bswapSN (&msg->x.writerSN); } msg->x.readerId = nn_ntoh_entityid (msg->x.readerId); @@ -400,13 +400,13 @@ static int valid_DataFrag (const struct receiver_state *rst, struct nn_rmsg *rms if (byteswap) { - msg->x.extraFlags = bswap2u (msg->x.extraFlags); - msg->x.octetsToInlineQos = bswap2u (msg->x.octetsToInlineQos); + msg->x.extraFlags = ddsrt_bswap2u (msg->x.extraFlags); + msg->x.octetsToInlineQos = ddsrt_bswap2u (msg->x.octetsToInlineQos); bswapSN (&msg->x.writerSN); - msg->fragmentStartingNum = bswap4u (msg->fragmentStartingNum); - msg->fragmentsInSubmessage = bswap2u (msg->fragmentsInSubmessage); - msg->fragmentSize = bswap2u (msg->fragmentSize); - msg->sampleSize = bswap4u (msg->sampleSize); + msg->fragmentStartingNum = ddsrt_bswap4u (msg->fragmentStartingNum); + msg->fragmentsInSubmessage = ddsrt_bswap2u (msg->fragmentsInSubmessage); + msg->fragmentSize = ddsrt_bswap2u (msg->fragmentSize); + msg->sampleSize = ddsrt_bswap4u (msg->sampleSize); } msg->x.readerId = nn_ntoh_entityid (msg->x.readerId); msg->x.writerId = nn_ntoh_entityid (msg->x.writerId); @@ -2662,7 +2662,7 @@ static int handle_submsg_sequence } if (byteswap) { - sm->smhdr.octetsToNextHeader = bswap2u (sm->smhdr.octetsToNextHeader); + sm->smhdr.octetsToNextHeader = ddsrt_bswap2u (sm->smhdr.octetsToNextHeader); } octetsToNextHeader = sm->smhdr.octetsToNextHeader; @@ -2929,7 +2929,7 @@ static bool do_packet (struct thread_state1 * const ts1, struct q_globals *gv, d } if (swap) { - ml->length = bswap4u (ml->length); + ml->length = ddsrt_bswap4u (ml->length); } if (ml->smhdr.submessageId != SMID_PT_MSG_LEN) diff --git a/src/core/ddsi/src/q_xevent.c b/src/core/ddsi/src/q_xevent.c index 9deee7a..775b2f4 100644 --- a/src/core/ddsi/src/q_xevent.c +++ b/src/core/ddsi/src/q_xevent.c @@ -1109,7 +1109,7 @@ static void write_pmd_message (struct thread_state1 * const ts1, struct nn_xpack } u.pmd.participantGuidPrefix = nn_hton_guid_prefix (pp->e.guid.prefix); - u.pmd.kind = toBE4u (pmd_kind); + u.pmd.kind = ddsrt_toBE4u (pmd_kind); u.pmd.length = PMD_DATA_LENGTH; memset (u.pmd.value, 0, u.pmd.length); diff --git a/src/core/ddsi/src/q_xmsg.c b/src/core/ddsi/src/q_xmsg.c index 28c6200..abb4685 100644 --- a/src/core/ddsi/src/q_xmsg.c +++ b/src/core/ddsi/src/q_xmsg.c @@ -786,7 +786,7 @@ void nn_xmsg_addpar_keyhash (struct nn_xmsg *m, const struct ddsi_serdata *serda static void nn_xmsg_addpar_BE4u (struct nn_xmsg *m, nn_parameterid_t pid, uint32_t x) { unsigned *p = nn_xmsg_addpar (m, pid, sizeof (x)); - *p = toBE4u (x); + *p = ddsrt_toBE4u (x); } void nn_xmsg_addpar_statusinfo (struct nn_xmsg *m, unsigned statusinfo) @@ -800,8 +800,8 @@ void nn_xmsg_addpar_statusinfo (struct nn_xmsg *m, unsigned statusinfo) assert ((statusinfo & ~NN_STATUSINFO_STANDARDIZED) == NN_STATUSINFO_OSPL_AUTO); if (statusinfo & NN_STATUSINFO_OSPL_AUTO) statusinfox |= NN_STATUSINFOX_OSPL_AUTO; - p[0] = toBE4u (statusinfo & NN_STATUSINFO_STANDARDIZED); - p[1] = toBE4u (statusinfox); + p[0] = ddsrt_toBE4u (statusinfo & NN_STATUSINFO_STANDARDIZED); + p[1] = ddsrt_toBE4u (statusinfox); } } diff --git a/src/ddsrt/CMakeLists.txt b/src/ddsrt/CMakeLists.txt index 0b241d9..19b99df 100644 --- a/src/ddsrt/CMakeLists.txt +++ b/src/ddsrt/CMakeLists.txt @@ -116,6 +116,7 @@ list(APPEND headers "${include_path}/dds/ddsrt/static_assert.h") list(APPEND sources + "${source_path}/bswap.c" "${source_path}/io.c" "${source_path}/log.c" "${source_path}/retcode.c" diff --git a/src/ddsrt/include/dds/ddsrt/bswap.h b/src/ddsrt/include/dds/ddsrt/bswap.h new file mode 100644 index 0000000..3e1ff56 --- /dev/null +++ b/src/ddsrt/include/dds/ddsrt/bswap.h @@ -0,0 +1,87 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#ifndef DDSRT_BSWAP_H +#define DDSRT_BSWAP_H + +#include +#include + +#include "dds/ddsrt/endian.h" + +#if defined (__cplusplus) +extern "C" { +#endif + +inline uint16_t ddsrt_bswap2u (uint16_t x) +{ + return (uint16_t) ((x >> 8) | (x << 8)); +} + +inline int16_t ddsrt_bswap2 (int16_t x) +{ + return (int16_t) ddsrt_bswap2u ((uint16_t) x); +} + +inline uint32_t ddsrt_bswap4u (uint32_t x) +{ + return (x >> 24) | ((x >> 8) & 0xff00) | ((x << 8) & 0xff0000) | (x << 24); +} + +inline int32_t ddsrt_bswap4 (int32_t x) +{ + return (int32_t) ddsrt_bswap4u ((uint32_t) x); +} + +inline uint64_t ddsrt_bswap8u (uint64_t x) +{ + const uint32_t newhi = ddsrt_bswap4u ((uint32_t) x); + const uint32_t newlo = ddsrt_bswap4u ((uint32_t) (x >> 32)); + return ((uint64_t) newhi << 32) | (uint64_t) newlo; +} + +inline int64_t ddsrt_bswap8 (int64_t x) +{ + return (int64_t) ddsrt_bswap8u ((uint64_t) x); +} + +#if DDSRT_ENDIAN == DDSRT_LITTLE_ENDIAN +#define ddsrt_toBE2(x) ddsrt_bswap2 (x) +#define ddsrt_toBE2u(x) ddsrt_bswap2u (x) +#define ddsrt_toBE4(x) ddsrt_bswap4 (x) +#define ddsrt_toBE4u(x) ddsrt_bswap4u (x) +#define ddsrt_toBE8(x) ddsrt_bswap8 (x) +#define ddsrt_toBE8u(x) ddsrt_bswap8u (x) +#define ddsrt_fromBE2(x) ddsrt_bswap2 (x) +#define ddsrt_fromBE2u(x) ddsrt_bswap2u (x) +#define ddsrt_fromBE4(x) ddsrt_bswap4 (x) +#define ddsrt_fromBE4u(x) ddsrt_bswap4u (x) +#define ddsrt_fromBE8(x) ddsrt_bswap8 (x) +#define ddsrt_fromBE8u(x) ddsrt_bswap8u (x) +#else +#define ddsrt_toBE2u(x) (x) +#define ddsrt_toBE4(x) (x) +#define ddsrt_toBE4u(x) (x) +#define ddsrt_toBE8(x) (x) +#define ddsrt_toBE8u(x) (x) +#define ddsrt_fromBE2(x) (x) +#define ddsrt_fromBE2u(x) (x) +#define ddsrt_fromBE4(x) (x) +#define ddsrt_fromBE4u(x) (x) +#define ddsrt_fromBE8(x) (x) +#define ddsrt_fromBE8u(x) (x) +#endif + +#if defined (__cplusplus) +} +#endif + +#endif /* DDSRT_BSWAP_H */ \ No newline at end of file diff --git a/src/core/ddsi/src/q_bswap_inlines.c b/src/ddsrt/src/bswap.c similarity index 55% rename from src/core/ddsi/src/q_bswap_inlines.c rename to src/ddsrt/src/bswap.c index 7d5f070..0423eab 100644 --- a/src/core/ddsi/src/q_bswap_inlines.c +++ b/src/ddsrt/src/bswap.c @@ -9,13 +9,11 @@ * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ -#include "dds/ddsi/q_bswap.h" - -extern inline uint16_t bswap2u (uint16_t x); -extern inline uint32_t bswap4u (uint32_t x); -extern inline uint64_t bswap8u (uint64_t x); -extern inline int16_t bswap2 (int16_t x); -extern inline int32_t bswap4 (int32_t x); -extern inline int64_t bswap8 (int64_t x); -extern inline void bswapSN (nn_sequence_number_t *sn); +#include "dds/ddsrt/bswap.h" +extern inline uint16_t ddsrt_bswap2u (uint16_t x); +extern inline uint32_t ddsrt_bswap4u (uint32_t x); +extern inline uint64_t ddsrt_bswap8u (uint64_t x); +extern inline int16_t ddsrt_bswap2 (int16_t x); +extern inline int32_t ddsrt_bswap4 (int32_t x); +extern inline int64_t ddsrt_bswap8 (int64_t x); From 43ee3f87cac4ac0d1dd01059f0b7406c43927dc4 Mon Sep 17 00:00:00 2001 From: Marcel Jordense Date: Mon, 28 Oct 2019 10:52:15 +0100 Subject: [PATCH 12/12] use ddsrt_malloc for allocating iov array Signed-off-by: Marcel Jordense --- src/core/ddsi/src/q_xmsg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/ddsi/src/q_xmsg.c b/src/core/ddsi/src/q_xmsg.c index abb4685..5e704a3 100644 --- a/src/core/ddsi/src/q_xmsg.c +++ b/src/core/ddsi/src/q_xmsg.c @@ -1374,7 +1374,7 @@ int nn_xpack_addmsg (struct nn_xpack *xp, struct nn_xmsg *m, const uint32_t flag assert (m->refd_payload == NULL || (m->refd_payload_iov.iov_len % 4) == 0); if (xp->iov == NULL) - xp->iov = malloc (NN_XMSG_MAX_MESSAGE_IOVECS * sizeof (*xp->iov)); + xp->iov = ddsrt_malloc (NN_XMSG_MAX_MESSAGE_IOVECS * sizeof (*xp->iov)); if (!nn_xpack_mayaddmsg (xp, m, flags)) {