From 90f3e3b5d322a09a8dfbed6a3c7ce48da271bfd7 Mon Sep 17 00:00:00 2001 From: Carlo Wood Date: Sat, 22 Oct 2016 03:39:10 +0200 Subject: [PATCH] Do not include headers inside __BEGIN_DECLS ... __END_DECLS blocks. We don't have C++ unsafe headers (anymore). I added a test to fix_headers.sh that checks if certain "unsafe" headers are ONLY included inside a __BEGIN_DECLS ... __END_DECLS (because after all, they are unsafe), as well as checking that no other header files are included inside such a block. The rationale of the latter is that if a file is a C header and it declares function prototypes (otherwise it doesn't matter) and is sometimes included outside a __BEGIN_DECLS ... __END_DECLS block (from a C++ source file) then it has to be C++ safe and doesn't ever to be included from inside such a block; while if a file is a C++ header then obviously it should never be included from such a block. fix_headers.sh subsequently found several safe headers to be included from inside such a block, and those that were (apparently in the past) unsafe were included only sometimes inside such a block and often outside it. I had a look at those files and saw that at least an attempt has been made to make them C++ safe, but especially because they already are included OFTEN outside a __BEGIN_DECLS ... __END_DECLS (from C++ source files) the best decision seems to treat them as safe. This is not risky: .c files that define such functions still generate C-linkage for their functions. If a C++ unsafe C header is included outside a __BEGIN_DECLS ... __END_DECLS block then the only possible result would be an undefined reference to a function with C++-linkage that will not exist. Aka, when something links after this commit, then the commit was correct. I did build all targets and they all linked. --- src/drivers/boards/aerocore/board_config.h | 5 ++--- src/drivers/boards/asc-v1/board_config.h | 7 ++++--- src/drivers/boards/crazyflie/board_config.h | 10 +--------- src/drivers/boards/mindpx-v2/board_config.h | 5 ++--- src/drivers/boards/px4-stm32f4discovery/board_config.h | 5 ++--- src/drivers/boards/px4fmu-v1/board_config.h | 5 ++--- src/drivers/boards/px4fmu-v2/board_config.h | 7 +++---- src/drivers/boards/px4fmu-v4/board_config.h | 6 ++---- src/drivers/boards/px4io-v1/board_config.h | 1 - src/drivers/boards/px4io-v2/board_config.h | 2 -- src/drivers/boards/tap-v1/board_config.h | 8 ++++---- src/drivers/drv_pwm_output.h | 4 +++- src/lib/geo/geo.h | 3 ++- src/modules/mavlink/mavlink_bridge_header.h | 3 +-- src/modules/systemlib/cpuload.h | 4 ++-- src/modules/systemlib/otp.h | 3 +-- src/modules/systemlib/printload.h | 5 +++-- 17 files changed, 34 insertions(+), 49 deletions(-) diff --git a/src/drivers/boards/aerocore/board_config.h b/src/drivers/boards/aerocore/board_config.h index 9eb97d559a..84446e575b 100644 --- a/src/drivers/boards/aerocore/board_config.h +++ b/src/drivers/boards/aerocore/board_config.h @@ -47,9 +47,6 @@ #include #include -__BEGIN_DECLS - -/* these headers are not C++ safe */ #include #include @@ -189,6 +186,8 @@ __BEGIN_DECLS {GPIO_GPIO10_INPUT, GPIO_GPIO10_OUTPUT, 0}, \ {GPIO_GPIO11_INPUT, GPIO_GPIO11_OUTPUT, 0}, } +__BEGIN_DECLS + /**************************************************************************************************** * Public Types ****************************************************************************************************/ diff --git a/src/drivers/boards/asc-v1/board_config.h b/src/drivers/boards/asc-v1/board_config.h index 071fbd2cf3..d2e3f67419 100644 --- a/src/drivers/boards/asc-v1/board_config.h +++ b/src/drivers/boards/asc-v1/board_config.h @@ -50,9 +50,6 @@ #include #include -__BEGIN_DECLS - -/* these headers are not C++ safe */ #include #include @@ -259,6 +256,9 @@ __BEGIN_DECLS #define TEMP_CONTROL(_on_true) px4_arch_gpiowrite(GPIO_TEMP_CONT, (_on_true)) #define FLASH_BASED_PARAMS + +__BEGIN_DECLS + /**************************************************************************************************** * Public Types ****************************************************************************************************/ @@ -351,4 +351,5 @@ bool board_pwr_button_down(void); void board_pwr(bool on_not_off); #endif /* __ASSEMBLY__ */ + __END_DECLS diff --git a/src/drivers/boards/crazyflie/board_config.h b/src/drivers/boards/crazyflie/board_config.h index b331085e40..0146ef9d79 100644 --- a/src/drivers/boards/crazyflie/board_config.h +++ b/src/drivers/boards/crazyflie/board_config.h @@ -47,9 +47,6 @@ #include #include -__BEGIN_DECLS - -/* these headers are not C++ safe */ #include #include @@ -168,8 +165,7 @@ __BEGIN_DECLS #define BOARD_FMU_GPIO_TAB { {0, 0, 0}, } - - +__BEGIN_DECLS /**************************************************************************************************** * Public Types @@ -219,9 +215,6 @@ extern void board_peripheral_reset(int ms); int nsh_archinitialize(void); #endif - - - /**************************************************************************** * Name: board_i2c_initialize * @@ -232,7 +225,6 @@ int nsh_archinitialize(void); int board_i2c_initialize(void); - #endif /* __ASSEMBLY__ */ __END_DECLS diff --git a/src/drivers/boards/mindpx-v2/board_config.h b/src/drivers/boards/mindpx-v2/board_config.h index 9176246e66..07fc8200a7 100644 --- a/src/drivers/boards/mindpx-v2/board_config.h +++ b/src/drivers/boards/mindpx-v2/board_config.h @@ -47,9 +47,6 @@ #include #include -__BEGIN_DECLS - -/* these headers are not C++ safe */ #include #include @@ -328,6 +325,8 @@ __BEGIN_DECLS #define BOARD_DMA_ALLOC_POOL_SIZE 5120 +__BEGIN_DECLS + /**************************************************************************************************** * Public Types ****************************************************************************************************/ diff --git a/src/drivers/boards/px4-stm32f4discovery/board_config.h b/src/drivers/boards/px4-stm32f4discovery/board_config.h index 2b476bf644..f5775fd9f4 100644 --- a/src/drivers/boards/px4-stm32f4discovery/board_config.h +++ b/src/drivers/boards/px4-stm32f4discovery/board_config.h @@ -47,9 +47,6 @@ #include #include -__BEGIN_DECLS - -/* these headers are not C++ safe */ #include #include @@ -89,6 +86,8 @@ __BEGIN_DECLS #define BOARD_NAME "PX4_STM32F4DISCOVERY" +__BEGIN_DECLS + /**************************************************************************************************** * Public Types ****************************************************************************************************/ diff --git a/src/drivers/boards/px4fmu-v1/board_config.h b/src/drivers/boards/px4fmu-v1/board_config.h index 5f6edb6d70..3fa0058444 100644 --- a/src/drivers/boards/px4fmu-v1/board_config.h +++ b/src/drivers/boards/px4fmu-v1/board_config.h @@ -47,9 +47,6 @@ #include #include -__BEGIN_DECLS - -/* these headers are not C++ safe */ #include #include @@ -224,6 +221,8 @@ __BEGIN_DECLS */ #define BOARD_HAS_MULTI_PURPOSE_GPIO 1 +__BEGIN_DECLS + /**************************************************************************************************** * Public Types ****************************************************************************************************/ diff --git a/src/drivers/boards/px4fmu-v2/board_config.h b/src/drivers/boards/px4fmu-v2/board_config.h index c2c408b7af..9a833a0a85 100644 --- a/src/drivers/boards/px4fmu-v2/board_config.h +++ b/src/drivers/boards/px4fmu-v2/board_config.h @@ -47,9 +47,6 @@ #include #include -__BEGIN_DECLS - -/* these headers are not C++ safe */ #include #include @@ -271,8 +268,10 @@ __BEGIN_DECLS {GPIO_VDD_5V_PERIPH_OC, 0, 0}, } /* This board provides a DMA pool and APIs */ - #define BOARD_DMA_ALLOC_POOL_SIZE 5120 + +__BEGIN_DECLS + /**************************************************************************************************** * Public Types ****************************************************************************************************/ diff --git a/src/drivers/boards/px4fmu-v4/board_config.h b/src/drivers/boards/px4fmu-v4/board_config.h index 733c633eff..e01538df88 100644 --- a/src/drivers/boards/px4fmu-v4/board_config.h +++ b/src/drivers/boards/px4fmu-v4/board_config.h @@ -47,9 +47,6 @@ #include #include -__BEGIN_DECLS - -/* these headers are not C++ safe */ #include #include @@ -298,9 +295,10 @@ __BEGIN_DECLS {GPIO_VDD_BRICK_VALID, 0, 0}, } /* This board provides a DMA pool and APIs */ - #define BOARD_DMA_ALLOC_POOL_SIZE 5120 +__BEGIN_DECLS + /**************************************************************************************************** * Public Types ****************************************************************************************************/ diff --git a/src/drivers/boards/px4io-v1/board_config.h b/src/drivers/boards/px4io-v1/board_config.h index 862112ccac..b0f79b073c 100644 --- a/src/drivers/boards/px4io-v1/board_config.h +++ b/src/drivers/boards/px4io-v1/board_config.h @@ -47,7 +47,6 @@ #include #include -/* these headers are not C++ safe */ #include #include diff --git a/src/drivers/boards/px4io-v2/board_config.h b/src/drivers/boards/px4io-v2/board_config.h index 5269c825d2..c9551674a0 100644 --- a/src/drivers/boards/px4io-v2/board_config.h +++ b/src/drivers/boards/px4io-v2/board_config.h @@ -47,7 +47,6 @@ #include #include -/* these headers are not C++ safe */ #include #include @@ -143,4 +142,3 @@ #define LED_SIGNAL 5 /* LED? + LED? */ #define LED_ASSERTION 6 /* LED? + LED? + LED? */ #define LED_PANIC 7 /* N/C + N/C + N/C + LED? */ - diff --git a/src/drivers/boards/tap-v1/board_config.h b/src/drivers/boards/tap-v1/board_config.h index 8218f61bda..f502f3ec3e 100644 --- a/src/drivers/boards/tap-v1/board_config.h +++ b/src/drivers/boards/tap-v1/board_config.h @@ -48,9 +48,6 @@ #include #include -__BEGIN_DECLS - -/* these headers are not C++ safe */ #include #include @@ -262,6 +259,9 @@ __BEGIN_DECLS #define TEMP_CONTROL(_on_true) px4_arch_gpiowrite(GPIO_TEMP_CONT, (_on_true)) #define FLASH_BASED_PARAMS + +__BEGIN_DECLS + /**************************************************************************************************** * Public Types ****************************************************************************************************/ @@ -320,7 +320,6 @@ extern int board_sdio_initialize(void); int nsh_archinitialize(void); #endif - /************************************************************************************ * Name: board_pwr_init() * @@ -364,4 +363,5 @@ void board_pwr(bool on_not_off); int board_i2c_initialize(void); #endif /* __ASSEMBLY__ */ + __END_DECLS diff --git a/src/drivers/drv_pwm_output.h b/src/drivers/drv_pwm_output.h index 32bee29efd..e22039dbb4 100644 --- a/src/drivers/drv_pwm_output.h +++ b/src/drivers/drv_pwm_output.h @@ -44,6 +44,9 @@ #pragma once #include + +#include "uORB/topics/output_pwm.h" + #include #include @@ -61,7 +64,6 @@ __BEGIN_DECLS #define PWM_OUTPUT_BASE_DEVICE_PATH "/dev/pwm_output" #define PWM_OUTPUT0_DEVICE_PATH "/dev/pwm_output0" -#include #define pwm_output_values output_pwm_s #ifndef PWM_OUTPUT_MAX_CHANNELS diff --git a/src/lib/geo/geo.h b/src/lib/geo/geo.h index 11451fcf19..b266ee0ed5 100644 --- a/src/lib/geo/geo.h +++ b/src/lib/geo/geo.h @@ -45,7 +45,6 @@ #pragma once #include -__BEGIN_DECLS #include "geo_lookup/geo_mag_declination.h" @@ -79,6 +78,8 @@ struct globallocal_converter_reference_s { bool init_done; }; +__BEGIN_DECLS + /** * Checks if global projection was initialized * @return true if map was initialized before, false else diff --git a/src/modules/mavlink/mavlink_bridge_header.h b/src/modules/mavlink/mavlink_bridge_header.h index e0f67e60c8..6d10ec9c3f 100644 --- a/src/modules/mavlink/mavlink_bridge_header.h +++ b/src/modules/mavlink/mavlink_bridge_header.h @@ -42,8 +42,6 @@ #ifndef MAVLINK_BRIDGE_HEADER_H #define MAVLINK_BRIDGE_HEADER_H -__BEGIN_DECLS - #define MAVLINK_USE_CONVENIENCE_FUNCTIONS /* use efficient approach, see mavlink_helpers.h */ @@ -57,6 +55,7 @@ __BEGIN_DECLS #include #include +__BEGIN_DECLS /* Struct that stores the communication settings of this system. you can also define / alter these settings elsewhere, as long diff --git a/src/modules/systemlib/cpuload.h b/src/modules/systemlib/cpuload.h index 1c63964cee..b5be48b59e 100644 --- a/src/modules/systemlib/cpuload.h +++ b/src/modules/systemlib/cpuload.h @@ -35,8 +35,6 @@ #ifdef CONFIG_SCHED_INSTRUMENTATION -__BEGIN_DECLS - #include #include @@ -58,6 +56,8 @@ struct system_load_s { int sleeping_count; }; +__BEGIN_DECLS + __EXPORT extern struct system_load_s system_load; __EXPORT void cpuload_initialize_once(void); diff --git a/src/modules/systemlib/otp.h b/src/modules/systemlib/otp.h index 3ea0f80bd3..d3ef475684 100644 --- a/src/modules/systemlib/otp.h +++ b/src/modules/systemlib/otp.h @@ -43,8 +43,6 @@ #ifndef OTP_H_ #define OTP_H_ -__BEGIN_DECLS - #define ADDR_OTP_START 0x1FFF7800 #define ADDR_OTP_LOCK_START 0x1FFF7A00 @@ -130,6 +128,7 @@ union udid { }; #pragma pack(pop) +__BEGIN_DECLS /** * s diff --git a/src/modules/systemlib/printload.h b/src/modules/systemlib/printload.h index ee210f8903..f195b44d5a 100644 --- a/src/modules/systemlib/printload.h +++ b/src/modules/systemlib/printload.h @@ -41,9 +41,8 @@ #pragma once -__BEGIN_DECLS - #include + #include #ifndef CONFIG_MAX_TASKS @@ -63,6 +62,8 @@ struct print_load_s { float interval_time_ms_inv; }; +__BEGIN_DECLS + __EXPORT void init_print_load_s(uint64_t t, struct print_load_s *s); __EXPORT void print_load(uint64_t t, int fd, struct print_load_s *print_state);