Skip to content

Commit

Permalink
[new new] Prepare for upcoming changes of 'new' in esp8266/Arduino
Browse files Browse the repository at this point in the history
  • Loading branch information
TD-er committed Aug 30, 2020
1 parent 6622ac8 commit 6f1dcae
Show file tree
Hide file tree
Showing 45 changed files with 115 additions and 80 deletions.
5 changes: 3 additions & 2 deletions lib/SerialDevices/jkSDS011.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ CjkSDS011::CjkSDS011(int16_t pinRX, int16_t pinTX)
_command.SetPacketLength(19);
_working_period = -1;
_sleepmode_active = false;
_serial = new ESPeasySerial(pinRX, pinTX);
_serial->begin(9600);
_serial = new (std::nothrow) ESPeasySerial(pinRX, pinTX);
if (_serial != nullptr)
_serial->begin(9600);
}

CjkSDS011::~CjkSDS011() {
Expand Down
2 changes: 1 addition & 1 deletion lib/SerialDevices/jkSDS011.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class CjkSDS011
void ParseCommandReply();

// SensorSerial _serial;
ESPeasySerial *_serial;
ESPeasySerial *_serial = nullptr;
CSensorSerialBuffer _data;
CSensorSerialBuffer _command;
float _pm2_5;
Expand Down
2 changes: 1 addition & 1 deletion src/ESPeasyControllerCache.ino
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct ControllerCache_struct {

void init() {
if (_RTC_cache_handler == nullptr) {
_RTC_cache_handler = new RTC_cache_handler_struct;
_RTC_cache_handler = new (std::nothrow) RTC_cache_handler_struct;
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/Networking.ino
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,7 @@ bool SSDP_begin() {

if (_server) {
_server->unref();

_server = 0;
}

Expand Down Expand Up @@ -650,7 +651,8 @@ void SSDP_send(byte method) {
(uint16_t)((chipId >> 8) & 0xff),
(uint16_t)chipId & 0xff);

char *buffer = new char[1460]();
char *buffer = new (std::nothrow) char[1460]();
if (buffer == nullptr) { return; }
int len = snprintf(buffer, 1460,
_ssdp_packet_template.c_str(),
(method == 0) ? _ssdp_response_template.c_str() : _ssdp_notify_template.c_str(),
Expand Down
2 changes: 1 addition & 1 deletion src/_C018.ino
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ struct C018_data_struct {
_baudrate = baudrate;

// FIXME TD-er: Make force SW serial a proper setting.
C018_easySerial = new ESPeasySerial(serial_rx, serial_tx, false, 64, C018_FORCE_SW_SERIAL);
C018_easySerial = new (std::nothrow) ESPeasySerial(serial_rx, serial_tx, false, 64, C018_FORCE_SW_SERIAL);

if (C018_easySerial != nullptr) {
myLora = new rn2xx3(*C018_easySerial);
Expand Down
2 changes: 1 addition & 1 deletion src/_P002_ADC.ino
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ boolean Plugin_002(byte function, struct EventStruct *event, String& string)

case PLUGIN_INIT:
{
initPluginTaskData(event->TaskIndex, new P002_data_struct());
initPluginTaskData(event->TaskIndex, new (std::nothrow) P002_data_struct());
P002_data_struct *P002_data =
static_cast<P002_data_struct *>(getPluginTaskData(event->TaskIndex));

Expand Down
2 changes: 1 addition & 1 deletion src/_P014_SI7021.ino
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ boolean Plugin_014(byte function, struct EventStruct *event, String& string)
{
// Get sensor resolution configuration
uint8_t res = PCONFIG(0);
initPluginTaskData(event->TaskIndex, new P014_data_struct(res));
initPluginTaskData(event->TaskIndex, new (std::nothrow) P014_data_struct(res));
P014_data_struct *P014_data =
static_cast<P014_data_struct *>(getPluginTaskData(event->TaskIndex));

Expand Down
2 changes: 1 addition & 1 deletion src/_P031_SHT1X.ino
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ boolean Plugin_031(byte function, struct EventStruct *event, String& string)

case PLUGIN_INIT:
{
initPluginTaskData(event->TaskIndex, new P031_data_struct());
initPluginTaskData(event->TaskIndex, new (std::nothrow) P031_data_struct());
P031_data_struct *P031_data =
static_cast<P031_data_struct *>(getPluginTaskData(event->TaskIndex));
if (nullptr == P031_data) {
Expand Down
8 changes: 4 additions & 4 deletions src/_P035_IRTX.ino
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,13 @@ boolean Plugin_035(byte function, struct EventStruct *event, String &command)
}

#ifdef P016_P035_Extended_AC
if (Plugin_035_commonAc == 0 && irPin != -1)
if (Plugin_035_commonAc == nullptr && irPin != -1)
{
addLog(LOG_LEVEL_INFO, F("INIT AC: IR TX"));
addLog(LOG_LEVEL_INFO, String(F("Supported Protocols by IRSENDAC: ")) + listACProtocols());
Plugin_035_commonAc = new IRac(irPin);
Plugin_035_commonAc = new (std::nothrow) IRac(irPin);
}
if (Plugin_035_commonAc != 0 && irPin == -1)
if (Plugin_035_commonAc != nullptr && irPin == -1)
{
addLog(LOG_LEVEL_INFO, F("INIT AC: IR TX Removed"));
delete Plugin_035_commonAc;
Expand Down Expand Up @@ -298,7 +298,7 @@ boolean handleRawRaw2Encoding(const String &cmd) {

uint16_t idx = 0; //If this goes above the buf.size then the esp will throw a 28 EXCCAUSE
uint16_t *buf;
buf = new uint16_t[P35_Ntimings]; //The Raw Timings that we can buffer.
buf = new (std::nothrow) uint16_t[P35_Ntimings]; //The Raw Timings that we can buffer.
if (buf == nullptr)
{ // error assigning memory.
return false;
Expand Down
6 changes: 3 additions & 3 deletions src/_P036_FrameOLED.ino
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ boolean Plugin_036(uint8_t function, struct EventStruct *event, String& string)
// For load and save of the display lines, we must not rely on the data in memory.
// This data in memory can be altered through write commands.
// Therefore we must read the lines from flash in a temporary object.
P036_data_struct *P036_data = new P036_data_struct();
P036_data_struct *P036_data = new (std::nothrow) P036_data_struct();

if (nullptr != P036_data) {
uint8_t version = get4BitFromUL(PCONFIG_LONG(0), 20); // Bit23-20 Version CustomTaskSettings
Expand Down Expand Up @@ -302,7 +302,7 @@ boolean Plugin_036(uint8_t function, struct EventStruct *event, String& string)
// For load and save of the display lines, we must not rely on the data in memory.
// This data in memory can be altered through write commands.
// Therefore we must use a temporary version to store the settings.
P036_data_struct *P036_data = new P036_data_struct();
P036_data_struct *P036_data = new (std::nothrow) P036_data_struct();

if (nullptr != P036_data) {
String error;
Expand Down Expand Up @@ -349,7 +349,7 @@ boolean Plugin_036(uint8_t function, struct EventStruct *event, String& string)

case PLUGIN_INIT:
{
initPluginTaskData(event->TaskIndex, new P036_data_struct());
initPluginTaskData(event->TaskIndex, new (std::nothrow) P036_data_struct());
P036_data_struct *P036_data =
static_cast<P036_data_struct *>(getPluginTaskData(event->TaskIndex));

Expand Down
2 changes: 1 addition & 1 deletion src/_P044_P1WifiGateway.ino
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ boolean Plugin_044(byte function, struct EventStruct *event, String& string)
// It was already created and initialzed
// So don't recreate to keep the webserver running.
} else {
initPluginTaskData(event->TaskIndex, new P044_Task());
initPluginTaskData(event->TaskIndex, new (std::nothrow) P044_Task());
task = static_cast<P044_Task *>(getPluginTaskData(event->TaskIndex));
}
if (nullptr == task) {
Expand Down
7 changes: 5 additions & 2 deletions src/_P049_MHZ19.ino
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,10 @@ struct P049_data_struct : public PluginTaskData_base {
if (serial_rx < 0 || serial_tx < 0)
return false;
reset();
easySerial = new ESPeasySerial(serial_rx, serial_tx);
easySerial = new (std::nothrow) ESPeasySerial(serial_rx, serial_tx);
if (easySerial == nullptr) {
return false;
}
easySerial->begin(9600);
ABC_Disable = setABCdisabled;
if (ABC_Disable) {
Expand Down Expand Up @@ -443,7 +446,7 @@ boolean Plugin_049(byte function, struct EventStruct *event, String& string)

case PLUGIN_INIT:
{
initPluginTaskData(event->TaskIndex, new P049_data_struct());
initPluginTaskData(event->TaskIndex, new (std::nothrow) P049_data_struct());
success = P049_performInit(event);
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/_P052_SenseAir.ino
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ boolean Plugin_052(byte function, struct EventStruct *event, String& string) {
case PLUGIN_INIT: {
const int16_t serial_rx = CONFIG_PIN1;
const int16_t serial_tx = CONFIG_PIN2;
initPluginTaskData(event->TaskIndex, new P052_data_struct());
initPluginTaskData(event->TaskIndex, new (std::nothrow) P052_data_struct());
P052_data_struct *P052_data =
static_cast<P052_data_struct *>(getPluginTaskData(event->TaskIndex));

Expand Down
5 changes: 4 additions & 1 deletion src/_P053_PMSx003.ino
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,10 @@ boolean Plugin_053(byte function, struct EventStruct *event, String& string)
log = F("PMSx003: using software serial");
addLog(LOG_LEVEL_INFO, log);
}
P053_easySerial = new ESPeasySerial(rxPin, txPin, false, 96); // 96 Bytes buffer, enough for up to 3 packets.
P053_easySerial = new (std::nothrow) ESPeasySerial(rxPin, txPin, false, 96); // 96 Bytes buffer, enough for up to 3 packets.
if (P053_easySerial == nullptr) {
break;
}
P053_easySerial->begin(9600);
P053_easySerial->flush();

Expand Down
5 changes: 4 additions & 1 deletion src/_P064_APDS9960.ino
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,10 @@ boolean Plugin_064(byte function, struct EventStruct *event, String& string)
if (PLUGIN_064_pds) {
delete PLUGIN_064_pds;
}
PLUGIN_064_pds = new SparkFun_APDS9960();
PLUGIN_064_pds = new (std::nothrow) SparkFun_APDS9960();
if (PLUGIN_064_pds == nullptr) {
break;
}

String log = F("APDS : ");

Expand Down
12 changes: 6 additions & 6 deletions src/_P065_DRF0299_MP3.ino
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ boolean Plugin_065(byte function, struct EventStruct *event, String& string)
#pragma GCC diagnostic pop


P065_easySerial = new ESPeasySerial(-1, CONFIG_PIN1); // no RX, only TX
P065_easySerial = new (std::nothrow) ESPeasySerial(-1, CONFIG_PIN1); // no RX, only TX
if (P065_easySerial != nullptr) {
P065_easySerial->begin(9600);
Plugin_065_SetVol(PCONFIG(0)); // set default volume

P065_easySerial->begin(9600);

Plugin_065_SetVol(PCONFIG(0)); // set default volume

success = true;
success = true;
}
break;
}

Expand Down
2 changes: 1 addition & 1 deletion src/_P068_SHT3x.ino
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ boolean Plugin_068(byte function, struct EventStruct *event, String& string)

case PLUGIN_INIT:
{
initPluginTaskData(event->TaskIndex, new SHT3X(PCONFIG(0)));
initPluginTaskData(event->TaskIndex, new (std::nothrow) SHT3X(PCONFIG(0)));
success = true;
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/_P069_LM75A.ino
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ boolean Plugin_069(byte function, struct EventStruct *event, String& string)
if (PLUGIN_069_LM75A) {
delete PLUGIN_069_LM75A;
}
PLUGIN_069_LM75A = new LM75A((uint8_t)PCONFIG(0));
PLUGIN_069_LM75A = new (std::nothrow) LM75A((uint8_t)PCONFIG(0));

success = true;
break;
Expand Down
7 changes: 5 additions & 2 deletions src/_P070_NeoPixel_Clock.ino
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ struct P070_data_struct : public PluginTaskData_base {
void init(struct EventStruct *event) {
if (!Plugin_070_pixels)
{
Plugin_070_pixels = new Adafruit_NeoPixel(NUMBER_LEDS, CONFIG_PIN1, NEO_GRB + NEO_KHZ800);
Plugin_070_pixels = new (std::nothrow) Adafruit_NeoPixel(NUMBER_LEDS, CONFIG_PIN1, NEO_GRB + NEO_KHZ800);
if (Plugin_070_pixels == nullptr) {
return;
}
Plugin_070_pixels->begin(); // This initializes the NeoPixel library.
}
set(event);
Expand Down Expand Up @@ -236,7 +239,7 @@ boolean Plugin_070(byte function, struct EventStruct *event, String& string)

case PLUGIN_INIT:
{
initPluginTaskData(event->TaskIndex, new P070_data_struct());
initPluginTaskData(event->TaskIndex, new (std::nothrow) P070_data_struct());
P070_data_struct* P070_data = static_cast<P070_data_struct*>(getPluginTaskData(event->TaskIndex));
if (nullptr == P070_data) {
return success;
Expand Down
2 changes: 1 addition & 1 deletion src/_P073_7DGT.ino
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ boolean Plugin_073(byte function, struct EventStruct *event, String& string) {
}

case PLUGIN_INIT: {
initPluginTaskData(event->TaskIndex, new P073_data_struct());
initPluginTaskData(event->TaskIndex, new (std::nothrow) P073_data_struct());
P073_data_struct *P073_data =
static_cast<P073_data_struct *>(getPluginTaskData(event->TaskIndex));

Expand Down
2 changes: 1 addition & 1 deletion src/_P074_TSL2591.ino
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ boolean Plugin_074(byte function, struct EventStruct *event, String& string) {
}

case PLUGIN_INIT: {
initPluginTaskData(event->TaskIndex, new P074_data_struct());
initPluginTaskData(event->TaskIndex, new (std::nothrow) P074_data_struct());
P074_data_struct *P074_data =
static_cast<P074_data_struct *>(getPluginTaskData(event->TaskIndex));

Expand Down
4 changes: 2 additions & 2 deletions src/_P075_Nextion.ino
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ struct P075_data_struct : public PluginTaskData_base {
if (baudrate < 9600 || baudrate > 115200) {
baudrate = 9600;
}
easySerial = new ESPeasySerial(rx, tx, false, RXBUFFSZ);
easySerial = new (std::nothrow) ESPeasySerial(rx, tx, false, RXBUFFSZ);
if (easySerial != nullptr) {
easySerial->begin(baudrate);
easySerial->flush();
Expand Down Expand Up @@ -239,7 +239,7 @@ boolean Plugin_075(byte function, struct EventStruct *event, String& string)

if(BaudCode > P075_B115200) BaudCode = P075_B9600;
const uint32_t BaudArray[4] = {9600UL, 38400UL, 57600UL, 115200UL};
initPluginTaskData(event->TaskIndex, new P075_data_struct(CONFIG_PIN1, CONFIG_PIN2, BaudArray[BaudCode]));
initPluginTaskData(event->TaskIndex, new (std::nothrow) P075_data_struct(CONFIG_PIN1, CONFIG_PIN2, BaudArray[BaudCode]));
P075_data_struct* P075_data = static_cast<P075_data_struct*>(getPluginTaskData(event->TaskIndex));
if (nullptr != P075_data) {
P075_data->loadDisplayLines(event->TaskIndex);
Expand Down
2 changes: 1 addition & 1 deletion src/_P076_HLW8012.ino
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ boolean Plugin_076(byte function, struct EventStruct *event, String &string) {
const byte SEL_PIN = CONFIG_PIN1;

if (CF_PIN != -1 && CF1_PIN != -1 && SEL_PIN != -1) {
Plugin_076_hlw = new HLW8012;
Plugin_076_hlw = new (std::nothrow) HLW8012;
if (Plugin_076_hlw) {
byte currentRead = PCONFIG(4);
byte cf_trigger = PCONFIG(5);
Expand Down
2 changes: 1 addition & 1 deletion src/_P077_CSE7766.ino
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ boolean Plugin_077(byte function, struct EventStruct *event, String &string) {
}

case PLUGIN_INIT: {
initPluginTaskData(event->TaskIndex, new P077_data_struct());
initPluginTaskData(event->TaskIndex, new (std::nothrow) P077_data_struct());
if (PCONFIG(0) == 0) PCONFIG(0) = HLW_UREF_PULSE;
if (PCONFIG(1) == 0) PCONFIG(1) = HLW_IREF_PULSE;
if (PCONFIG(2) == 0) PCONFIG(2) = HLW_PREF_PULSE;
Expand Down
11 changes: 8 additions & 3 deletions src/_P078_Eastron.ino
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,10 @@ boolean Plugin_078(byte function, struct EventStruct *event, String& string)
delete Plugin_078_SoftSerial;
Plugin_078_SoftSerial=NULL;
}
Plugin_078_SoftSerial = new ESPeasySerial(CONFIG_PIN1, CONFIG_PIN2);
Plugin_078_SoftSerial = new (std::nothrow) ESPeasySerial(CONFIG_PIN1, CONFIG_PIN2);
if (Plugin_078_SoftSerial == nullptr) {
break;
}
unsigned int baudrate = p078_storageValueToBaudrate(P078_BAUDRATE);
Plugin_078_SoftSerial->begin(baudrate);

Expand All @@ -218,8 +221,10 @@ boolean Plugin_078(byte function, struct EventStruct *event, String& string)
Plugin_078_SDM=NULL;
}
Plugin_078_SDM = new SDM(*Plugin_078_SoftSerial, baudrate, P078_DEPIN);
Plugin_078_SDM->begin();
success = true;
if (Plugin_078_SDM != nullptr) {
Plugin_078_SDM->begin();
success = true;
}
break;
}

Expand Down
2 changes: 1 addition & 1 deletion src/_P081_Cron.ino
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ boolean Plugin_081(byte function, struct EventStruct *event, String& string)

case PLUGIN_INIT:
{
initPluginTaskData(event->TaskIndex, new P081_data_struct(P081_getCronExpr(event->TaskIndex)));
initPluginTaskData(event->TaskIndex, new (std::nothrow) P081_data_struct(P081_getCronExpr(event->TaskIndex)));
P081_data_struct *P081_data =
static_cast<P081_data_struct *>(getPluginTaskData(event->TaskIndex));

Expand Down
10 changes: 6 additions & 4 deletions src/_P082_GPS.ino
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,11 @@ struct P082_data_struct : public PluginTaskData_base {
return false;
}
reset();
gps = new TinyGPSPlus();
P082_easySerial = new ESPeasySerial(serial_rx, serial_tx);
P082_easySerial->begin(9600);
gps = new (std::nothrow) TinyGPSPlus();
P082_easySerial = new (std::nothrow) ESPeasySerial(serial_rx, serial_tx);
if (P082_easySerial != nullptr) {
P082_easySerial->begin(9600);
}
return isInitialized();
}

Expand Down Expand Up @@ -393,7 +395,7 @@ boolean Plugin_082(byte function, struct EventStruct *event, String& string) {
const int16_t serial_rx = CONFIG_PIN1;
const int16_t serial_tx = CONFIG_PIN2;
const int16_t pps_pin = CONFIG_PIN3;
initPluginTaskData(event->TaskIndex, new P082_data_struct());
initPluginTaskData(event->TaskIndex, new (std::nothrow) P082_data_struct());
P082_data_struct *P082_data =
static_cast<P082_data_struct *>(getPluginTaskData(event->TaskIndex));

Expand Down
2 changes: 1 addition & 1 deletion src/_P085_AcuDC243.ino
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ boolean Plugin_085(byte function, struct EventStruct *event, String& string) {
case PLUGIN_INIT: {
const int16_t serial_rx = CONFIG_PIN1;
const int16_t serial_tx = CONFIG_PIN2;
initPluginTaskData(event->TaskIndex, new P085_data_struct());
initPluginTaskData(event->TaskIndex, new (std::nothrow) P085_data_struct());
P085_data_struct *P085_data =
static_cast<P085_data_struct *>(getPluginTaskData(event->TaskIndex));

Expand Down
2 changes: 1 addition & 1 deletion src/_P087_SerialProxy.ino
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ boolean Plugin_087(byte function, struct EventStruct *event, String& string) {
case PLUGIN_INIT: {
const int16_t serial_rx = CONFIG_PIN1;
const int16_t serial_tx = CONFIG_PIN2;
initPluginTaskData(event->TaskIndex, new P087_data_struct());
initPluginTaskData(event->TaskIndex, new (std::nothrow) P087_data_struct());
P087_data_struct *P087_data =
static_cast<P087_data_struct *>(getPluginTaskData(event->TaskIndex));

Expand Down
Loading

0 comments on commit 6f1dcae

Please sign in to comment.