Skip to content

Commit

Permalink
Merge branch 'master' into noboom
Browse files Browse the repository at this point in the history
  • Loading branch information
devyte committed Sep 2, 2020
2 parents cf1b8e0 + 8b7126d commit f1c8982
Show file tree
Hide file tree
Showing 43 changed files with 2,097 additions and 540 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,16 @@ jobs:
- uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Cache Linux toolchain
id: cache-linux
uses: actions/cache@v2
with:
path: ./tools/dist
key: key-linux-toolchain
- name: Boards.txt diff
env:
TRAVIS_BUILD_DIR: ${{ github.workspace }}
TRAVIS_TAG: ${{ github.ref }}
run: |
bash ./tests/ci/build_boards.sh
bash ./tests/ci/eboot_test.sh
250 changes: 80 additions & 170 deletions boards.txt

Large diffs are not rendered by default.

13 changes: 3 additions & 10 deletions cores/esp8266/Esp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,6 @@ uint8_t EspClass::getBootMode(void)
return system_get_boot_mode();
}

#ifndef F_CPU
uint8_t EspClass::getCpuFreqMHz(void)
{
return system_get_cpu_freq();
}
#endif

uint32_t EspClass::getFlashChipId(void)
{
static uint32_t flash_chip_id = 0;
Expand Down Expand Up @@ -740,17 +733,17 @@ String EspClass::getSketchMD5()
}
uint32_t lengthLeft = getSketchSize();
const size_t bufSize = 512;
std::unique_ptr<uint8_t[]> buf(new uint8_t[bufSize]);
std::unique_ptr<uint8_t[]> buf(new (std::nothrow) uint8_t[bufSize]);
uint32_t offset = 0;
if(!buf.get()) {
return String();
return emptyString;
}
MD5Builder md5;
md5.begin();
while( lengthLeft > 0) {
size_t readBytes = (lengthLeft < bufSize) ? lengthLeft : bufSize;
if (!flashRead(offset, reinterpret_cast<uint32_t*>(buf.get()), (readBytes + 3) & ~3)) {
return String();
return emptyString;
}
md5.add(buf.get(), readBytes);
lengthLeft -= readBytes;
Expand Down
28 changes: 9 additions & 19 deletions cores/esp8266/Esp.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,12 @@ class EspClass {
uint8_t getBootMode();

#if defined(F_CPU) || defined(CORE_MOCK)
constexpr uint8_t getCpuFreqMHz() const
{
return esp_get_cpu_freq_mhz();
}
#else
uint8_t getCpuFreqMHz() const
constexpr
#endif
inline uint8_t getCpuFreqMHz() const __attribute__((always_inline))
{
return esp_get_cpu_freq_mhz();
}
#endif

uint32_t getFlashChipId();
uint8_t getFlashChipVendorId();
Expand Down Expand Up @@ -170,21 +166,15 @@ class EspClass {
uint8_t *random(uint8_t *resultArray, const size_t outputSizeBytes) const;
uint32_t random() const;

#ifndef CORE_MOCK
inline uint32_t getCycleCount() __attribute__((always_inline));
#if !defined(CORE_MOCK)
inline uint32_t getCycleCount() __attribute__((always_inline))
{
return esp_get_cycle_count();
}
#else
uint32_t getCycleCount();
#endif
};

#ifndef CORE_MOCK

uint32_t EspClass::getCycleCount()
{
return esp_get_cycle_count();
}

#endif // !defined(CORE_MOCK)
};

extern EspClass ESP;

Expand Down
4 changes: 2 additions & 2 deletions cores/esp8266/Print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ size_t Print::printf(const char *format, ...) {
size_t len = vsnprintf(temp, sizeof(temp), format, arg);
va_end(arg);
if (len > sizeof(temp) - 1) {
buffer = new char[len + 1];
buffer = new (std::nothrow) char[len + 1];
if (!buffer) {
return 0;
}
Expand All @@ -86,7 +86,7 @@ size_t Print::printf_P(PGM_P format, ...) {
size_t len = vsnprintf_P(temp, sizeof(temp), format, arg);
va_end(arg);
if (len > sizeof(temp) - 1) {
buffer = new char[len + 1];
buffer = new (std::nothrow) char[len + 1];
if (!buffer) {
return 0;
}
Expand Down
4 changes: 2 additions & 2 deletions cores/esp8266/Stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ float Stream::parseFloat(char skipChar) {
boolean isFraction = false;
long value = 0;
int c;
float fraction = 1.0;
float fraction = 1.0f;

c = peekNextDigit();
// ignore non numeric leading characters
Expand All @@ -190,7 +190,7 @@ float Stream::parseFloat(char skipChar) {
else if(c >= '0' && c <= '9') { // is c a digit?
value = value * 10 + c - '0';
if(isFraction)
fraction *= 0.1;
fraction *= 0.1f;
}
read(); // consume the character we got with peek
c = timedPeek();
Expand Down
48 changes: 24 additions & 24 deletions cores/esp8266/WString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ String::~String() {
invalidate();
}

// /*********************************************/
// /* Memory Management */
// /*********************************************/
/*********************************************/
/* Memory Management */
/*********************************************/

inline void String::init(void) {
setSSO(true);
Expand Down Expand Up @@ -199,9 +199,9 @@ unsigned char String::changeBuffer(unsigned int maxStrLen) {
return 0;
}

// /*********************************************/
// /* Copy and Move */
// /*********************************************/
/*********************************************/
/* Copy and Move */
/*********************************************/

String & String::copy(const char *cstr, unsigned int length) {
if (!reserve(length)) {
Expand Down Expand Up @@ -297,9 +297,9 @@ String & String::operator = (const __FlashStringHelper *pstr)
return *this;
}

// /*********************************************/
// /* concat */
// /*********************************************/
/*********************************************/
/* concat */
/*********************************************/

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

// /*********************************************/
// /* Comparison */
// /*********************************************/
/*********************************************/
/* Comparison */
/*********************************************/

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

// /*********************************************/
// /* Character Access */
// /*********************************************/
/*********************************************/
/* Character Access */
/*********************************************/

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

// /*********************************************/
// /* Search */
// /*********************************************/
/*********************************************/
/* Search */
/*********************************************/

int String::indexOf(char c) const {
return indexOf(c, 0);
Expand Down Expand Up @@ -713,9 +713,9 @@ String String::substring(unsigned int left, unsigned int right) const {
return out;
}

// /*********************************************/
// /* Modification */
// /*********************************************/
/*********************************************/
/* Modification */
/*********************************************/

void String::replace(char find, char replace) {
if (!buffer())
Expand Down Expand Up @@ -828,9 +828,9 @@ void String::trim(void) {
wbuffer()[newlen] = 0;
}

// /*********************************************/
// /* Parsing / Conversion */
// /*********************************************/
/*********************************************/
/* Parsing / Conversion */
/*********************************************/

long String::toInt(void) const {
if (buffer())
Expand Down
36 changes: 31 additions & 5 deletions cores/esp8266/abi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,33 @@ extern "C" void __cxa_pure_virtual(void) __attribute__ ((__noreturn__));
extern "C" void __cxa_deleted_virtual(void) __attribute__ ((__noreturn__));


#if !defined(__cpp_exceptions) && !defined(NEW_OOM_ABORT)
void *operator new(size_t size)
#if !defined(__cpp_exceptions)

// overwrite weak operators new/new[] definitions

void* operator new(size_t size)
{
void *ret = malloc(size);
if (0 != size && 0 == ret) {
umm_last_fail_alloc_addr = __builtin_return_address(0);
umm_last_fail_alloc_size = size;
__unhandled_exception(PSTR("OOM"));
}
return ret;
}

void* operator new[](size_t size)
{
void *ret = malloc(size);
if (0 != size && 0 == ret) {
umm_last_fail_alloc_addr = __builtin_return_address(0);
umm_last_fail_alloc_size = size;
__unhandled_exception(PSTR("OOM"));
}
return ret;
return ret;
}

void *operator new[](size_t size)
void* operator new (size_t size, const std::nothrow_t&)
{
void *ret = malloc(size);
if (0 != size && 0 == ret) {
Expand All @@ -52,7 +67,18 @@ void *operator new[](size_t size)
}
return ret;
}
#endif // arduino's std::new legacy

void* operator new[] (size_t size, const std::nothrow_t&)
{
void *ret = malloc(size);
if (0 != size && 0 == ret) {
umm_last_fail_alloc_addr = __builtin_return_address(0);
umm_last_fail_alloc_size = size;
}
return ret;
}

#endif // !defined(__cpp_exceptions)

void __cxa_pure_virtual(void)
{
Expand Down
3 changes: 2 additions & 1 deletion cores/esp8266/cbuf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include <new> // std::nothrow
#include "cbuf.h"
#include "c_types.h"

Expand All @@ -43,7 +44,7 @@ size_t cbuf::resize(size_t newSize) {
return _size;
}

char *newbuf = new char[newSize];
char *newbuf = new (std::nothrow) char[newSize];
char *oldbuf = _buf;

if(!newbuf) {
Expand Down
29 changes: 0 additions & 29 deletions cores/esp8266/core_esp8266_features.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,35 +36,6 @@
#include <stddef.h> // size_t
#include <stdint.h>

#ifdef __cplusplus

namespace arduino
{
extern "C++"
template <typename T, typename ...TConstructorArgs>
T* new0 (size_t n, TConstructorArgs... TconstructorArgs)
{
// n==0: single allocation, otherwise it is an array
size_t offset = n? sizeof(size_t): 0;
size_t arraysize = n? n: 1;
T* ptr = (T*)malloc(offset + (arraysize * sizeof(T)));
if (ptr)
{
if (n)
*(size_t*)(ptr) = n;
for (size_t i = 0; i < arraysize; i++)
new (ptr + offset + i * sizeof(T)) T(TconstructorArgs...);
return ptr + offset;
}
return nullptr;
}
}

#define arduino_new(Type, ...) arduino::new0<Type>(0, ##__VA_ARGS__)
#define arduino_newarray(Type, n, ...) arduino::new0<Type>(n, ##__VA_ARGS__)

#endif // __cplusplus

#ifndef __STRINGIFY
#define __STRINGIFY(a) #a
#endif
Expand Down
6 changes: 6 additions & 0 deletions cores/esp8266/core_esp8266_postmortem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,12 @@ void __wrap_system_restart_local() {

cut_here();

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

custom_crash_callback( &rst_info, sp_dump + offset, stack_end );

ets_delay_us(10000);
Expand Down
1 change: 1 addition & 0 deletions cores/esp8266/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ void hexdump(const void *mem, uint32_t len, uint8_t cols);
extern "C" {
#endif

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

Expand Down
Loading

0 comments on commit f1c8982

Please sign in to comment.