Skip to content

Commit ea16a6b

Browse files
committed
Add MBED_NORETURN attributes
Save some ROM space by putting MBED_NORETURN attributes on error functions and failed asserts. mbed_error was documented as returning an error code. It never actually could return, so documentation updated, but return type kept.
1 parent 57748bd commit ea16a6b

File tree

8 files changed

+17
-20
lines changed

8 files changed

+17
-20
lines changed

features/lwipstack/lwip-sys/arch/cc.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
void lwip_mbed_tracef_debug(const char *fmt, ...);
9898
void lwip_mbed_tracef_error(const char *fmt, ...);
9999
void lwip_mbed_tracef_warn(const char *fmt, ...);
100-
void lwip_mbed_assert_fail(const char *msg, const char *func, const char *file, unsigned int line);
100+
MBED_NORETURN void lwip_mbed_assert_fail(const char *msg, const char *func, const char *file, unsigned int line);
101101

102102
#define LWIP_PLATFORM_DIAG(vars) lwip_mbed_tracef_debug vars
103103
#define LWIP_PLATFORM_DIAG_SEVERE(vars) lwip_mbed_tracef_error vars
@@ -109,7 +109,7 @@ void lwip_mbed_assert_fail(const char *msg, const char *func, const char *file,
109109
#else // MBED_CONF_LWIP_USE_MBED_TRACE
110110
#include <stdio.h>
111111

112-
void assert_printf(char *msg, int line, char *file);
112+
MBED_NORETURN void assert_printf(char *msg, int line, char *file);
113113

114114
/* Plaform specific diagnostic output */
115115
#define LWIP_PLATFORM_DIAG(vars) printf vars

features/lwipstack/lwip-sys/arch/lwip_sys_arch.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ void lwip_mbed_tracef_error(const char *fmt, ...)
589589
va_end(ap);
590590
}
591591

592-
void lwip_mbed_assert_fail(const char *msg, const char *func, const char *file, unsigned int line)
592+
MBED_NORETURN void lwip_mbed_assert_fail(const char *msg, const char *func, const char *file, unsigned int line)
593593
{
594594
mbed_tracef(TRACE_LEVEL_ERROR, "lwIP", "Assertion failed: %s, function %s, file %s, line %u.", msg, func, file, line);
595595
exit(EXIT_FAILURE); // XXX how about abort? mbed_assert uses exit, so follow suit
@@ -605,7 +605,7 @@ void lwip_mbed_assert_fail(const char *msg, const char *func, const char *file,
605605
\param[in] line Line number in file with error
606606
\param[in] file Filename with error
607607
*/
608-
void assert_printf(char *msg, int line, char *file) {
608+
MBED_NORETURN void assert_printf(char *msg, int line, char *file) {
609609
if (msg)
610610
error("%s:%d in file %s\n", msg, line, file);
611611
else

platform/mbed_assert.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include "platform/mbed_critical.h"
2121
#include "platform/mbed_error.h"
2222

23-
void mbed_assert_internal(const char *expr, const char *file, int line)
23+
MBED_NORETURN void mbed_assert_internal(const char *expr, const char *file, int line)
2424
{
2525
core_util_critical_section_enter();
2626
mbed_error(MBED_ERROR_ASSERTION_FAILED, expr, 0, file, line);

platform/mbed_assert.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#define MBED_ASSERT_H
2525

2626
#include "mbed_preprocessor.h"
27+
#include "mbed_toolchain.h"
2728

2829
#ifdef __cplusplus
2930
extern "C" {
@@ -37,7 +38,7 @@ extern "C" {
3738
* @param file File where assertation failed.
3839
* @param line Failing assertation line number.
3940
*/
40-
void mbed_assert_internal(const char *expr, const char *file, int line);
41+
MBED_NORETURN void mbed_assert_internal(const char *expr, const char *file, int line);
4142

4243
#ifdef __cplusplus
4344
}

platform/mbed_board.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include "platform/mbed_retarget.h"
2222
#include "platform/mbed_critical.h"
2323

24-
WEAK void mbed_die(void)
24+
WEAK MBED_NORETURN void mbed_die(void)
2525
{
2626
#if !defined (NRF51_H) && !defined(TARGET_EFM32)
2727
core_util_critical_section_enter();

platform/mbed_error.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ static mbed_error_hook_t error_hook = NULL;
4545
static mbed_error_status_t handle_error(mbed_error_status_t error_status, unsigned int error_value, const char *filename, int line_number, void *caller);
4646

4747
//Helper function to halt the system
48-
static void mbed_halt_system(void)
48+
static MBED_NORETURN void mbed_halt_system(void)
4949
{
5050
// Prevent recursion if halt is called again during halt attempt - try
5151
// something simple instead.
@@ -66,7 +66,7 @@ static void mbed_halt_system(void)
6666
exit(1);
6767
}
6868

69-
WEAK void error(const char *format, ...)
69+
WEAK MBED_NORETURN void error(const char *format, ...)
7070
{
7171
// Prevent recursion if error is called again during store+print attempt
7272
if (!core_util_atomic_flag_test_and_set(&error_in_progress)) {
@@ -169,14 +169,14 @@ int mbed_get_error_count(void)
169169
return error_count;
170170
}
171171

172-
//Sets a fatal error
172+
//Sets a non-fatal error
173173
mbed_error_status_t mbed_warning(mbed_error_status_t error_status, const char *error_msg, unsigned int error_value, const char *filename, int line_number)
174174
{
175175
return handle_error(error_status, error_value, filename, line_number, MBED_CALLER_ADDR());
176176
}
177177

178178
//Sets a fatal error, this function is marked WEAK to be able to override this for some tests
179-
WEAK mbed_error_status_t mbed_error(mbed_error_status_t error_status, const char *error_msg, unsigned int error_value, const char *filename, int line_number)
179+
WEAK MBED_NORETURN mbed_error_status_t mbed_error(mbed_error_status_t error_status, const char *error_msg, unsigned int error_value, const char *filename, int line_number)
180180
{
181181
// Prevent recursion if error is called again during store+print attempt
182182
if (!core_util_atomic_flag_test_and_set(&error_in_progress)) {
@@ -188,8 +188,6 @@ WEAK mbed_error_status_t mbed_error(mbed_error_status_t error_status, const char
188188
}
189189

190190
mbed_halt_system();
191-
192-
return MBED_ERROR_FAILED_OPERATION;
193191
}
194192

195193
//Register an application defined callback with error handling

platform/mbed_error.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,7 @@ typedef int mbed_error_status_t;
169169
* @param error_status mbed_error_status_t status to be set(See mbed_error_status_t enum above for available error status values).
170170
* @param error_msg The error message to be printed out to STDIO/Serial.
171171
* @param error_value Value associated with the error status. This would depend on error code/error scenario. Only available with MBED_ERROR1
172-
* @return 0 or MBED_SUCCESS.
173-
* MBED_ERROR_INVALID_ARGUMENT if called with invalid error status/codes
172+
* @return Does not return
174173
*
175174
* @code
176175
*
@@ -872,7 +871,7 @@ typedef struct _mbed_error_ctx {
872871
*
873872
*/
874873

875-
void error(const char *format, ...);
874+
MBED_NORETURN void error(const char *format, ...);
876875

877876
/**
878877
* Call this Macro to generate a mbed_error_status_t value for a System error
@@ -979,8 +978,7 @@ int mbed_get_error_count(void);
979978
* @param error_value Value associated with the error status. This would depend on error code/error scenario.
980979
* @param filename Name of the source file originating the error( Most callers can pass __FILE__ here ).
981980
* @param line_number The line number of the source file originating the error( Most callers can pass __LINE__ here ) .
982-
* @return 0 or MBED_SUCCESS.
983-
* MBED_ERROR_INVALID_ARGUMENT if called with invalid error status/codes
981+
* @return Does not return.
984982
*
985983
* @code
986984
*
@@ -990,7 +988,7 @@ int mbed_get_error_count(void);
990988
*
991989
* @note See MBED_WARNING/MBED_ERROR macros which provides a wrapper on this API
992990
*/
993-
mbed_error_status_t mbed_error(mbed_error_status_t error_status, const char *error_msg, unsigned int error_value, const char *filename, int line_number);
991+
MBED_NORETURN mbed_error_status_t mbed_error(mbed_error_status_t error_status, const char *error_msg, unsigned int error_value, const char *filename, int line_number);
994992

995993
/**
996994
* Registers an application defined error callback with the error handling system.

platform/mbed_interface.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ void mbed_mac_address(char *mac);
121121

122122
/** Cause the mbed to flash the BLOD (Blue LEDs Of Death) sequence
123123
*/
124-
void mbed_die(void);
124+
MBED_NORETURN void mbed_die(void);
125125

126126
/** Print out an error message. This is typically called when
127127
* handling a crash.

0 commit comments

Comments
 (0)