mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-16 00:43:00 +03:00
replace new
by new (std::nothrow)
, remove arduino_new
This commit is contained in:
@ -740,17 +740,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;
|
||||
|
@ -7,7 +7,7 @@ typedef void (*voidFuncPtr)(void);
|
||||
typedef void (*voidFuncPtrArg)(void*);
|
||||
|
||||
// Helper functions for Functional interrupt routines
|
||||
extern "C" void __attachInterruptFunctionalArg(uint8_t pin, voidFuncPtr userFunc, void*fp, int mode, bool functional);
|
||||
extern "C" bool __attachInterruptFunctionalArg(uint8_t pin, voidFuncPtr userFunc, void*fp, int mode, bool functional);
|
||||
|
||||
|
||||
void ICACHE_RAM_ATTR interruptFunctional(void* arg)
|
||||
@ -34,32 +34,52 @@ extern "C"
|
||||
}
|
||||
}
|
||||
|
||||
void attachInterrupt(uint8_t pin, std::function<void(void)> intRoutine, int mode)
|
||||
bool attachInterrupt(uint8_t pin, std::function<void(void)> intRoutine, int mode)
|
||||
{
|
||||
// use the local interrupt routine which takes the ArgStructure as argument
|
||||
|
||||
InterruptInfo* ii = nullptr;
|
||||
|
||||
FunctionInfo* fi = new FunctionInfo;
|
||||
FunctionInfo* fi = new (std::nothrow) FunctionInfo;
|
||||
if (fi == nullptr)
|
||||
return false;
|
||||
fi->reqFunction = intRoutine;
|
||||
|
||||
ArgStructure* as = new ArgStructure;
|
||||
ArgStructure* as = new (std::nothrow) ArgStructure;
|
||||
if (as == nullptr)
|
||||
{
|
||||
delete(fi);
|
||||
return false;
|
||||
}
|
||||
as->interruptInfo = ii;
|
||||
as->functionInfo = fi;
|
||||
|
||||
__attachInterruptFunctionalArg(pin, (voidFuncPtr)interruptFunctional, as, mode, true);
|
||||
return __attachInterruptFunctionalArg(pin, (voidFuncPtr)interruptFunctional, as, mode, true);
|
||||
}
|
||||
|
||||
void attachScheduledInterrupt(uint8_t pin, std::function<void(InterruptInfo)> scheduledIntRoutine, int mode)
|
||||
bool attachScheduledInterrupt(uint8_t pin, std::function<void(InterruptInfo)> scheduledIntRoutine, int mode)
|
||||
{
|
||||
InterruptInfo* ii = new InterruptInfo;
|
||||
InterruptInfo* ii = new (std::nothrow) InterruptInfo;
|
||||
if (ii == nullptr)
|
||||
return false;
|
||||
|
||||
FunctionInfo* fi = new FunctionInfo;
|
||||
if (fi == nullptr)
|
||||
{
|
||||
delete ii;
|
||||
return false;
|
||||
}
|
||||
fi->reqScheduledFunction = scheduledIntRoutine;
|
||||
|
||||
ArgStructure* as = new ArgStructure;
|
||||
ArgStructure* as = new (std::nothrow) ArgStructure;
|
||||
if (as == nullptr)
|
||||
{
|
||||
delete ii;
|
||||
delete fi;
|
||||
return false;
|
||||
}
|
||||
as->interruptInfo = ii;
|
||||
as->functionInfo = fi;
|
||||
|
||||
__attachInterruptFunctionalArg(pin, (voidFuncPtr)interruptFunctional, as, mode, true);
|
||||
return __attachInterruptFunctionalArg(pin, (voidFuncPtr)interruptFunctional, as, mode, true);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
|
@ -180,7 +180,7 @@ bool UpdaterClass::begin(size_t size, int command, int ledPin, uint8_t ledOn) {
|
||||
} else {
|
||||
_bufferSize = 256;
|
||||
}
|
||||
_buffer = new uint8_t[_bufferSize];
|
||||
_buffer = new (std::nothrow) uint8_t[_bufferSize];
|
||||
_command = command;
|
||||
|
||||
#ifdef DEBUG_UPDATER
|
||||
|
@ -43,7 +43,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) {
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user