From e353d123fda0476a2e79e4305c545e6053136bba Mon Sep 17 00:00:00 2001 From: Kumar Gala Date: Wed, 27 May 2020 13:16:44 -0500 Subject: [PATCH] zephyr: Make Zephyr int types deprecated by default As the int types defined in include/zephyr/types.h are typdef's we utilize a Kconfig option (LEGACY_ZEPHYR_INT_TYPES) to enable/disable the support for them. By default to LEGACY_ZEPHYR_INT_TYPES not being enabled and add an explicit test to ensure the types continue to function until removed in the future. Signed-off-by: Kumar Gala --- Kconfig.zephyr | 6 ++++++ include/zephyr/types.h | 4 ++++ tests/deprecated/inttype/CMakeLists.txt | 8 ++++++++ tests/deprecated/inttype/prj.conf | 1 + tests/deprecated/inttype/src/main.c | 20 ++++++++++++++++++++ tests/deprecated/inttype/testcase.yaml | 4 ++++ 6 files changed, 43 insertions(+) create mode 100644 tests/deprecated/inttype/CMakeLists.txt create mode 100644 tests/deprecated/inttype/prj.conf create mode 100644 tests/deprecated/inttype/src/main.c create mode 100644 tests/deprecated/inttype/testcase.yaml diff --git a/Kconfig.zephyr b/Kconfig.zephyr index 4043e771104..9821e2067d9 100644 --- a/Kconfig.zephyr +++ b/Kconfig.zephyr @@ -363,6 +363,12 @@ config LEGACY_DEVICETREE_MACROS Zephyr 2.2 and previous versions, rather than the devicetree.h API introduced during the Zephyr 2.3 development cycle. +config LEGACY_ZEPHYR_INT_TYPES + bool "Allow the use of the legacy zephyr integer types" + help + Allows the use of the legacy Zephyr integer typedefs defined in + Zephyr 2.3 and previous versions. + endmenu endmenu diff --git a/include/zephyr/types.h b/include/zephyr/types.h index e875a351800..bd97c8e9387 100644 --- a/include/zephyr/types.h +++ b/include/zephyr/types.h @@ -13,6 +13,8 @@ extern "C" { #endif +#ifdef CONFIG_LEGACY_ZEPHYR_INT_TYPES + typedef signed char s8_t; typedef signed short s16_t; typedef signed int s32_t; @@ -23,6 +25,8 @@ typedef unsigned short u16_t; typedef unsigned int u32_t; typedef unsigned long long u64_t; +#endif + /* 32 bits on ILP32 builds, 64 bits on LP64 builts */ typedef unsigned long ulong_t; diff --git a/tests/deprecated/inttype/CMakeLists.txt b/tests/deprecated/inttype/CMakeLists.txt new file mode 100644 index 00000000000..30b8735806e --- /dev/null +++ b/tests/deprecated/inttype/CMakeLists.txt @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.13.1) + +find_package(Zephyr HINTS $ENV{ZEPHYR_BASE}) +project(test_inttypes) + +target_sources(app PRIVATE src/main.c) diff --git a/tests/deprecated/inttype/prj.conf b/tests/deprecated/inttype/prj.conf new file mode 100644 index 00000000000..b230bb0ce6e --- /dev/null +++ b/tests/deprecated/inttype/prj.conf @@ -0,0 +1 @@ +CONFIG_LEGACY_ZEPHYR_INT_TYPES=y diff --git a/tests/deprecated/inttype/src/main.c b/tests/deprecated/inttype/src/main.c new file mode 100644 index 00000000000..74bc769ede6 --- /dev/null +++ b/tests/deprecated/inttype/src/main.c @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2020 Linaro + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +void main(void) +{ + BUILD_ASSERT(sizeof(u8_t) == 1, "sizeof u8_t mismatch"); + BUILD_ASSERT(sizeof(u16_t) == 2, "sizeof u16_t mismatch"); + BUILD_ASSERT(sizeof(u32_t) == 4, "sizeof u32_t mismatch"); + BUILD_ASSERT(sizeof(u64_t) == 8, "sizeof u64_t mismatch"); + + BUILD_ASSERT(sizeof(s8_t) == 1, "sizeof s8_t mismatch"); + BUILD_ASSERT(sizeof(s16_t) == 2, "sizeof s16_t mismatch"); + BUILD_ASSERT(sizeof(s32_t) == 4, "sizeof s32_t mismatch"); + BUILD_ASSERT(sizeof(s64_t) == 8, "sizeof s64_t mismatch"); +} diff --git a/tests/deprecated/inttype/testcase.yaml b/tests/deprecated/inttype/testcase.yaml new file mode 100644 index 00000000000..707f79127b3 --- /dev/null +++ b/tests/deprecated/inttype/testcase.yaml @@ -0,0 +1,4 @@ +tests: + deprecated.inttypes: + build_only: true + tags: deprecated