mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-26 07:02:15 +03:00
Move all exception strings to IRAM and out of both PMEM (illegal) and add output of any assert() failinf conditions. The exception handler may be called while the SPI interface is in a bad state. This means no PROGMEM reads are allowed, and all data and functions used must be in system RAM or IRAM. Add a new helper macro, ets_printf_P(), which places a constant string in IRAM and copies it to the stack before calling the real ets_printf(). This makes the code simpler to read as no unwieldy combinations of ets_putc/ets_printf/... are required to output anything. The old handler also mistakenly used PSTR() strings in some places, so fix those with this patch as well. Gives back ~180 bytes of heap to every sketch built as the exception handler is always included an application.
52 lines
1.2 KiB
C
52 lines
1.2 KiB
C
/*
|
|
assert.h
|
|
*/
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#include "_ansi.h"
|
|
#include <pgmspace.h>
|
|
|
|
#undef assert
|
|
|
|
#ifdef NDEBUG /* required by ANSI standard */
|
|
# define assert(__e) ((void)0)
|
|
#else
|
|
# define assert(__e) ((__e) ? (void)0 : __assert_func (PSTR(__FILE__), __LINE__, \
|
|
__ASSERT_FUNC, PSTR(#__e)))
|
|
|
|
# ifndef __ASSERT_FUNC
|
|
/* Use g++'s demangled names in C++. */
|
|
# if defined __cplusplus && defined __GNUC__
|
|
# define __ASSERT_FUNC __PRETTY_FUNCTION__
|
|
|
|
/* C99 requires the use of __func__. */
|
|
# elif __STDC_VERSION__ >= 199901L
|
|
# define __ASSERT_FUNC __func__
|
|
|
|
/* Older versions of gcc don't have __func__ but can use __FUNCTION__. */
|
|
# elif __GNUC__ >= 2
|
|
# define __ASSERT_FUNC __FUNCTION__
|
|
|
|
/* failed to detect __func__ support. */
|
|
# else
|
|
# define __ASSERT_FUNC ((char *) 0)
|
|
# endif
|
|
# endif /* !__ASSERT_FUNC */
|
|
#endif /* !NDEBUG */
|
|
|
|
void _EXFUN(__assert, (const char *, int, const char *)
|
|
_ATTRIBUTE ((__noreturn__)));
|
|
void _EXFUN(__assert_func, (const char *, int, const char *, const char *)
|
|
_ATTRIBUTE ((__noreturn__)));
|
|
|
|
#if __STDC_VERSION__ >= 201112L && !defined __cplusplus
|
|
# define static_assert _Static_assert
|
|
#endif
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|