Skip to content

Commit ea5648b

Browse files
committed
Avoid Delegate anti-pattern (std::function with capture where C-style ptr with arg is possible).
1 parent 358f942 commit ea5648b

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ bool ESP8266WiFiGenericClass::mode(WiFiMode_t m) {
434434
//tasks to wait correctly.
435435
constexpr unsigned int timeoutValue = 1000; //1 second
436436
if(can_yield()) {
437-
esp_delay(timeoutValue, [m]() { return wifi_get_opmode() != (uint8)m; }, 5);
437+
esp_delay(timeoutValue, { [](void* m) { return wifi_get_opmode() != *static_cast<WiFiMode_t*>(m); }, (void*)&m }, 5);
438438

439439
//if at this point mode still hasn't been reached, give up
440440
if(wifi_get_opmode() != (uint8) m) {

libraries/ESP8266WiFi/src/include/ClientContext.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class ClientContext
145145
_op_start_time = millis();
146146
// will resume on timeout or when _connected or _notify_error fires
147147
// give scheduled functions a chance to run (e.g. Ethernet uses recurrent)
148-
esp_delay(_timeout_ms, [this]() { return _connect_pending; }, 1);
148+
esp_delay(_timeout_ms, { [](void* self) { return static_cast<ClientContext*>(self)->_connect_pending; }, this }, 1);
149149
_connect_pending = false;
150150
if (!_pcb) {
151151
DEBUGV(":cabrt\r\n");
@@ -486,7 +486,7 @@ class ClientContext
486486
_send_waiting = true;
487487
// will resume on timeout or when _write_some_from_cb or _notify_error fires
488488
// give scheduled functions a chance to run (e.g. Ethernet uses recurrent)
489-
esp_delay(_timeout_ms, [this]() { return _send_waiting; }, 1);
489+
esp_delay(_timeout_ms, { [](void* self) { return static_cast<ClientContext*>(self)->_send_waiting; }, this }, 1);
490490
_send_waiting = false;
491491
} while(true);
492492

0 commit comments

Comments
 (0)