Skip to content

Commit f1c8982

Browse files
authored
Merge branch 'master' into noboom
2 parents cf1b8e0 + 8b7126d commit f1c8982

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+2097
-540
lines changed

.github/workflows/pull-request.yml

+7
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,16 @@ jobs:
251251
- uses: actions/setup-python@v2
252252
with:
253253
python-version: '3.x'
254+
- name: Cache Linux toolchain
255+
id: cache-linux
256+
uses: actions/cache@v2
257+
with:
258+
path: ./tools/dist
259+
key: key-linux-toolchain
254260
- name: Boards.txt diff
255261
env:
256262
TRAVIS_BUILD_DIR: ${{ github.workspace }}
257263
TRAVIS_TAG: ${{ github.ref }}
258264
run: |
259265
bash ./tests/ci/build_boards.sh
266+
bash ./tests/ci/eboot_test.sh

boards.txt

+80-170
Large diffs are not rendered by default.

cores/esp8266/Esp.cpp

+3-10
Original file line numberDiff line numberDiff line change
@@ -264,13 +264,6 @@ uint8_t EspClass::getBootMode(void)
264264
return system_get_boot_mode();
265265
}
266266

267-
#ifndef F_CPU
268-
uint8_t EspClass::getCpuFreqMHz(void)
269-
{
270-
return system_get_cpu_freq();
271-
}
272-
#endif
273-
274267
uint32_t EspClass::getFlashChipId(void)
275268
{
276269
static uint32_t flash_chip_id = 0;
@@ -740,17 +733,17 @@ String EspClass::getSketchMD5()
740733
}
741734
uint32_t lengthLeft = getSketchSize();
742735
const size_t bufSize = 512;
743-
std::unique_ptr<uint8_t[]> buf(new uint8_t[bufSize]);
736+
std::unique_ptr<uint8_t[]> buf(new (std::nothrow) uint8_t[bufSize]);
744737
uint32_t offset = 0;
745738
if(!buf.get()) {
746-
return String();
739+
return emptyString;
747740
}
748741
MD5Builder md5;
749742
md5.begin();
750743
while( lengthLeft > 0) {
751744
size_t readBytes = (lengthLeft < bufSize) ? lengthLeft : bufSize;
752745
if (!flashRead(offset, reinterpret_cast<uint32_t*>(buf.get()), (readBytes + 3) & ~3)) {
753-
return String();
746+
return emptyString;
754747
}
755748
md5.add(buf.get(), readBytes);
756749
lengthLeft -= readBytes;

cores/esp8266/Esp.h

+9-19
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,12 @@ class EspClass {
122122
uint8_t getBootMode();
123123

124124
#if defined(F_CPU) || defined(CORE_MOCK)
125-
constexpr uint8_t getCpuFreqMHz() const
126-
{
127-
return esp_get_cpu_freq_mhz();
128-
}
129-
#else
130-
uint8_t getCpuFreqMHz() const
125+
constexpr
126+
#endif
127+
inline uint8_t getCpuFreqMHz() const __attribute__((always_inline))
131128
{
132129
return esp_get_cpu_freq_mhz();
133130
}
134-
#endif
135131

136132
uint32_t getFlashChipId();
137133
uint8_t getFlashChipVendorId();
@@ -170,21 +166,15 @@ class EspClass {
170166
uint8_t *random(uint8_t *resultArray, const size_t outputSizeBytes) const;
171167
uint32_t random() const;
172168

173-
#ifndef CORE_MOCK
174-
inline uint32_t getCycleCount() __attribute__((always_inline));
169+
#if !defined(CORE_MOCK)
170+
inline uint32_t getCycleCount() __attribute__((always_inline))
171+
{
172+
return esp_get_cycle_count();
173+
}
175174
#else
176175
uint32_t getCycleCount();
177-
#endif
178-
};
179-
180-
#ifndef CORE_MOCK
181-
182-
uint32_t EspClass::getCycleCount()
183-
{
184-
return esp_get_cycle_count();
185-
}
186-
187176
#endif // !defined(CORE_MOCK)
177+
};
188178

189179
extern EspClass ESP;
190180

cores/esp8266/Print.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ size_t Print::printf(const char *format, ...) {
6363
size_t len = vsnprintf(temp, sizeof(temp), format, arg);
6464
va_end(arg);
6565
if (len > sizeof(temp) - 1) {
66-
buffer = new char[len + 1];
66+
buffer = new (std::nothrow) char[len + 1];
6767
if (!buffer) {
6868
return 0;
6969
}
@@ -86,7 +86,7 @@ size_t Print::printf_P(PGM_P format, ...) {
8686
size_t len = vsnprintf_P(temp, sizeof(temp), format, arg);
8787
va_end(arg);
8888
if (len > sizeof(temp) - 1) {
89-
buffer = new char[len + 1];
89+
buffer = new (std::nothrow) char[len + 1];
9090
if (!buffer) {
9191
return 0;
9292
}

cores/esp8266/Stream.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ float Stream::parseFloat(char skipChar) {
173173
boolean isFraction = false;
174174
long value = 0;
175175
int c;
176-
float fraction = 1.0;
176+
float fraction = 1.0f;
177177

178178
c = peekNextDigit();
179179
// ignore non numeric leading characters
@@ -190,7 +190,7 @@ float Stream::parseFloat(char skipChar) {
190190
else if(c >= '0' && c <= '9') { // is c a digit?
191191
value = value * 10 + c - '0';
192192
if(isFraction)
193-
fraction *= 0.1;
193+
fraction *= 0.1f;
194194
}
195195
read(); // consume the character we got with peek
196196
c = timedPeek();

cores/esp8266/WString.cpp

+24-24
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,9 @@ String::~String() {
124124
invalidate();
125125
}
126126

127-
// /*********************************************/
128-
// /* Memory Management */
129-
// /*********************************************/
127+
/*********************************************/
128+
/* Memory Management */
129+
/*********************************************/
130130

131131
inline void String::init(void) {
132132
setSSO(true);
@@ -199,9 +199,9 @@ unsigned char String::changeBuffer(unsigned int maxStrLen) {
199199
return 0;
200200
}
201201

202-
// /*********************************************/
203-
// /* Copy and Move */
204-
// /*********************************************/
202+
/*********************************************/
203+
/* Copy and Move */
204+
/*********************************************/
205205

206206
String & String::copy(const char *cstr, unsigned int length) {
207207
if (!reserve(length)) {
@@ -297,9 +297,9 @@ String & String::operator = (const __FlashStringHelper *pstr)
297297
return *this;
298298
}
299299

300-
// /*********************************************/
301-
// /* concat */
302-
// /*********************************************/
300+
/*********************************************/
301+
/* concat */
302+
/*********************************************/
303303

304304
unsigned char String::concat(const String &s) {
305305
// Special case if we're concatting ourself (s += s;) since we may end up
@@ -483,9 +483,9 @@ StringSumHelper & operator + (const StringSumHelper &lhs, const __FlashStringHel
483483
return a;
484484
}
485485

486-
// /*********************************************/
487-
// /* Comparison */
488-
// /*********************************************/
486+
/*********************************************/
487+
/* Comparison */
488+
/*********************************************/
489489

490490
int String::compareTo(const String &s) const {
491491
if(!buffer() || !s.buffer()) {
@@ -587,9 +587,9 @@ unsigned char String::endsWith(const String &s2) const {
587587
return strcmp(&buffer()[len() - s2.len()], s2.buffer()) == 0;
588588
}
589589

590-
// /*********************************************/
591-
// /* Character Access */
592-
// /*********************************************/
590+
/*********************************************/
591+
/* Character Access */
592+
/*********************************************/
593593

594594
char String::charAt(unsigned int loc) const {
595595
return operator[](loc);
@@ -629,9 +629,9 @@ void String::getBytes(unsigned char *buf, unsigned int bufsize, unsigned int ind
629629
buf[n] = 0;
630630
}
631631

632-
// /*********************************************/
633-
// /* Search */
634-
// /*********************************************/
632+
/*********************************************/
633+
/* Search */
634+
/*********************************************/
635635

636636
int String::indexOf(char c) const {
637637
return indexOf(c, 0);
@@ -713,9 +713,9 @@ String String::substring(unsigned int left, unsigned int right) const {
713713
return out;
714714
}
715715

716-
// /*********************************************/
717-
// /* Modification */
718-
// /*********************************************/
716+
/*********************************************/
717+
/* Modification */
718+
/*********************************************/
719719

720720
void String::replace(char find, char replace) {
721721
if (!buffer())
@@ -828,9 +828,9 @@ void String::trim(void) {
828828
wbuffer()[newlen] = 0;
829829
}
830830

831-
// /*********************************************/
832-
// /* Parsing / Conversion */
833-
// /*********************************************/
831+
/*********************************************/
832+
/* Parsing / Conversion */
833+
/*********************************************/
834834

835835
long String::toInt(void) const {
836836
if (buffer())

cores/esp8266/abi.cpp

+31-5
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,33 @@ extern "C" void __cxa_pure_virtual(void) __attribute__ ((__noreturn__));
3232
extern "C" void __cxa_deleted_virtual(void) __attribute__ ((__noreturn__));
3333

3434

35-
#if !defined(__cpp_exceptions) && !defined(NEW_OOM_ABORT)
36-
void *operator new(size_t size)
35+
#if !defined(__cpp_exceptions)
36+
37+
// overwrite weak operators new/new[] definitions
38+
39+
void* operator new(size_t size)
40+
{
41+
void *ret = malloc(size);
42+
if (0 != size && 0 == ret) {
43+
umm_last_fail_alloc_addr = __builtin_return_address(0);
44+
umm_last_fail_alloc_size = size;
45+
__unhandled_exception(PSTR("OOM"));
46+
}
47+
return ret;
48+
}
49+
50+
void* operator new[](size_t size)
3751
{
3852
void *ret = malloc(size);
3953
if (0 != size && 0 == ret) {
4054
umm_last_fail_alloc_addr = __builtin_return_address(0);
4155
umm_last_fail_alloc_size = size;
56+
__unhandled_exception(PSTR("OOM"));
4257
}
43-
return ret;
58+
return ret;
4459
}
4560

46-
void *operator new[](size_t size)
61+
void* operator new (size_t size, const std::nothrow_t&)
4762
{
4863
void *ret = malloc(size);
4964
if (0 != size && 0 == ret) {
@@ -52,7 +67,18 @@ void *operator new[](size_t size)
5267
}
5368
return ret;
5469
}
55-
#endif // arduino's std::new legacy
70+
71+
void* operator new[] (size_t size, const std::nothrow_t&)
72+
{
73+
void *ret = malloc(size);
74+
if (0 != size && 0 == ret) {
75+
umm_last_fail_alloc_addr = __builtin_return_address(0);
76+
umm_last_fail_alloc_size = size;
77+
}
78+
return ret;
79+
}
80+
81+
#endif // !defined(__cpp_exceptions)
5682

5783
void __cxa_pure_virtual(void)
5884
{

cores/esp8266/cbuf.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1919
*/
2020

21+
#include <new> // std::nothrow
2122
#include "cbuf.h"
2223
#include "c_types.h"
2324

@@ -43,7 +44,7 @@ size_t cbuf::resize(size_t newSize) {
4344
return _size;
4445
}
4546

46-
char *newbuf = new char[newSize];
47+
char *newbuf = new (std::nothrow) char[newSize];
4748
char *oldbuf = _buf;
4849

4950
if(!newbuf) {

cores/esp8266/core_esp8266_features.h

-29
Original file line numberDiff line numberDiff line change
@@ -36,35 +36,6 @@
3636
#include <stddef.h> // size_t
3737
#include <stdint.h>
3838

39-
#ifdef __cplusplus
40-
41-
namespace arduino
42-
{
43-
extern "C++"
44-
template <typename T, typename ...TConstructorArgs>
45-
T* new0 (size_t n, TConstructorArgs... TconstructorArgs)
46-
{
47-
// n==0: single allocation, otherwise it is an array
48-
size_t offset = n? sizeof(size_t): 0;
49-
size_t arraysize = n? n: 1;
50-
T* ptr = (T*)malloc(offset + (arraysize * sizeof(T)));
51-
if (ptr)
52-
{
53-
if (n)
54-
*(size_t*)(ptr) = n;
55-
for (size_t i = 0; i < arraysize; i++)
56-
new (ptr + offset + i * sizeof(T)) T(TconstructorArgs...);
57-
return ptr + offset;
58-
}
59-
return nullptr;
60-
}
61-
}
62-
63-
#define arduino_new(Type, ...) arduino::new0<Type>(0, ##__VA_ARGS__)
64-
#define arduino_newarray(Type, n, ...) arduino::new0<Type>(n, ##__VA_ARGS__)
65-
66-
#endif // __cplusplus
67-
6839
#ifndef __STRINGIFY
6940
#define __STRINGIFY(a) #a
7041
#endif

cores/esp8266/core_esp8266_postmortem.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,12 @@ void __wrap_system_restart_local() {
220220

221221
cut_here();
222222

223+
if (s_unhandled_exception && umm_last_fail_alloc_addr) {
224+
// now outside from the "cut-here" zone, print correctly the `new` caller address,
225+
// idf-monitor.py will be able to decode this one and show exact location in sources
226+
ets_printf_P(PSTR("\nlast failed alloc caller: 0x%08x\n"), (uint32_t)umm_last_fail_alloc_addr);
227+
}
228+
223229
custom_crash_callback( &rst_info, sp_dump + offset, stack_end );
224230

225231
ets_delay_us(10000);

cores/esp8266/debug.h

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ void hexdump(const void *mem, uint32_t len, uint8_t cols);
2222
extern "C" {
2323
#endif
2424

25+
void __unhandled_exception(const char *str) __attribute__((noreturn));
2526
void __panic_func(const char* file, int line, const char* func) __attribute__((noreturn));
2627
#define panic() __panic_func(PSTR(__FILE__), __LINE__, __func__)
2728

0 commit comments

Comments
 (0)