Skip to content

Commit d6a48b5

Browse files
committed
Turn NULLs into nullptr
Avoids overload problems with Callback(nullptr) versus Callback(fnptr).
1 parent 9577b08 commit d6a48b5

31 files changed

+82
-95
lines changed

components/802.15.4_RF/atmel-rf-driver/source/NanostackRfPhyAtmel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ static void rf_if_reset_radio(void)
524524
#else
525525
rf->spi.frequency(MBED_CONF_ATMEL_RF_LOW_SPI_SPEED);
526526
#endif
527-
rf->IRQ.rise(0);
527+
rf->IRQ.rise(nullptr);
528528
rf->RST = 1;
529529
ThisThread::sleep_for(2);
530530
rf->RST = 0;

components/wifi/esp8266-driver/ESP8266/ESP8266.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ ESP8266::ESP8266(PinName tx, PinName rx, bool debug, PinName rts, PinName cts)
4141
: _sdk_v(-1, -1, -1),
4242
_at_v(-1, -1, -1),
4343
_tcp_passive(false),
44-
_callback(0),
44+
_callback(),
4545
_serial(tx, rx, MBED_CONF_ESP8266_SERIAL_BAUDRATE),
4646
_serial_rts(rts),
4747
_serial_cts(cts),

components/wifi/esp8266-driver/ESP8266Interface.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ ESP8266Interface::ESP8266Interface()
7171
_connect_retval(NSAPI_ERROR_OK),
7272
_disconnect_retval(NSAPI_ERROR_OK),
7373
_conn_stat(NSAPI_STATUS_DISCONNECTED),
74-
_conn_stat_cb(NULL),
74+
_conn_stat_cb(),
7575
_global_event_queue(mbed_event_queue()), // Needs to be set before attaching event() to SIGIO
7676
_oob_event_id(0),
7777
_connect_event_id(0),
@@ -113,7 +113,7 @@ ESP8266Interface::ESP8266Interface(PinName tx, PinName rx, bool debug, PinName r
113113
_connect_retval(NSAPI_ERROR_OK),
114114
_disconnect_retval(NSAPI_ERROR_OK),
115115
_conn_stat(NSAPI_STATUS_DISCONNECTED),
116-
_conn_stat_cb(NULL),
116+
_conn_stat_cb(),
117117
_global_event_queue(mbed_event_queue()), // Needs to be set before attaching event() to SIGIO
118118
_oob_event_id(0),
119119
_connect_event_id(0),

drivers/SerialBase.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ class SerialBase : private NonCopyable<SerialBase> {
216216
/** Begin asynchronous write using 8bit buffer.
217217
*
218218
* The write operation ends with any of the enabled events and invokes
219-
* registered callback function (which can be NULL to not receive callback at all).
219+
* registered callback function (which can be empty to not receive callback at all).
220220
* Events that are not enabled by event argument are simply ignored.
221221
* Operation has to be ended explicitly by calling abort_write() when
222222
* no events are enabled.
@@ -233,7 +233,7 @@ class SerialBase : private NonCopyable<SerialBase> {
233233
/** Begin asynchronous write using 16bit buffer.
234234
*
235235
* The write operation ends with any of the enabled events and invokes
236-
* registered callback function (which can be NULL to not receive callback at all).
236+
* registered callback function (which can be empty to not receive callback at all).
237237
* Events that are not enabled by event argument are simply ignored.
238238
* Operation has to be ended explicitly by calling abort_write() when
239239
* no events are enabled.
@@ -256,7 +256,7 @@ class SerialBase : private NonCopyable<SerialBase> {
256256
/** Begin asynchronous reading using 8bit buffer.
257257
*
258258
* The read operation ends with any of the enabled events and invokes registered
259-
* callback function (which can be NULL to not receive callback at all).
259+
* callback function (which can be empty to not receive callback at all).
260260
* Events that are not enabled by event argument are simply ignored.
261261
* Operation has to be ended explicitly by calling abort_read() when
262262
* no events are enabled.
@@ -274,7 +274,7 @@ class SerialBase : private NonCopyable<SerialBase> {
274274
/** Begin asynchronous reading using 16bit buffer.
275275
*
276276
* The read operation ends with any of the enabled events and invokes registered
277-
* callback function (which can be NULL to not receive callback at all).
277+
* callback function (which can be empty to not receive callback at all).
278278
* Events that are not enabled by event argument are simply ignored.
279279
* Operation has to be ended explicitly by calling abort_read() when
280280
* no events are enabled.

drivers/internal/PolledQueue.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class PolledQueue: public TaskQueue {
4242
*
4343
* @param cb Callback called when dispatch needs to be called
4444
*/
45-
PolledQueue(mbed::Callback<void()> cb = NULL);
45+
PolledQueue(mbed::Callback<void()> cb = nullptr);
4646

4747
virtual ~PolledQueue();
4848

drivers/internal/USBDevice.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ class USBDevice: public USBPhyEvents {
147147
* @param callback Method pointer to be called when a packet is transferred
148148
* @returns true if successful, false otherwise
149149
*/
150-
bool endpoint_add(usb_ep_t endpoint, uint32_t max_packet, usb_ep_type_t type, mbed::Callback<void()> callback = NULL);
150+
bool endpoint_add(usb_ep_t endpoint, uint32_t max_packet, usb_ep_type_t type, mbed::Callback<void()> callback = nullptr);
151151

152152
/**
153153
* Add an endpoint

drivers/source/CAN.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ CAN::~CAN()
5656

5757
// Detaching interrupts releases the sleep lock if it was locked
5858
for (int irq = 0; irq < IrqCnt; irq++) {
59-
attach(NULL, (IrqType)irq);
59+
attach(nullptr, (IrqType)irq);
6060
}
6161
can_irq_free(&_can);
6262
can_free(&_can);
@@ -147,7 +147,7 @@ void CAN::attach(Callback<void()> func, IrqType type)
147147
if (_irq[(CanIrqType)type]) {
148148
sleep_manager_unlock_deep_sleep();
149149
}
150-
_irq[(CanIrqType)type] = NULL;
150+
_irq[(CanIrqType)type] = nullptr;
151151
can_irq_set(&_can, (CanIrqType)type, 0);
152152
}
153153
unlock();

drivers/source/InterruptIn.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ namespace mbed {
2626
// constructor, with a default value for the PinMode.
2727
InterruptIn::InterruptIn(PinName pin) : gpio(),
2828
gpio_irq(),
29-
_rise(NULL),
30-
_fall(NULL)
29+
_rise(),
30+
_fall()
3131
{
3232
// No lock needed in the constructor
3333
irq_init(pin);
@@ -37,8 +37,8 @@ InterruptIn::InterruptIn(PinName pin) : gpio(),
3737
InterruptIn::InterruptIn(PinName pin, PinMode mode) :
3838
gpio(),
3939
gpio_irq(),
40-
_rise(NULL),
41-
_fall(NULL)
40+
_rise(),
41+
_fall()
4242
{
4343
// No lock needed in the constructor
4444
irq_init(pin);
@@ -76,7 +76,7 @@ void InterruptIn::rise(Callback<void()> func)
7676
_rise = func;
7777
gpio_irq_set(&gpio_irq, IRQ_RISE, 1);
7878
} else {
79-
_rise = NULL;
79+
_rise = nullptr;
8080
gpio_irq_set(&gpio_irq, IRQ_RISE, 0);
8181
}
8282
core_util_critical_section_exit();
@@ -89,7 +89,7 @@ void InterruptIn::fall(Callback<void()> func)
8989
_fall = func;
9090
gpio_irq_set(&gpio_irq, IRQ_FALL, 1);
9191
} else {
92-
_fall = NULL;
92+
_fall = nullptr;
9393
gpio_irq_set(&gpio_irq, IRQ_FALL, 0);
9494
}
9595
core_util_critical_section_exit();

drivers/source/SPI.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,14 @@ SPI::~SPI()
151151
lock();
152152
/* Make sure a stale pointer isn't left in peripheral's owner field */
153153
if (_peripheral->owner == this) {
154-
_peripheral->owner = NULL;
154+
_peripheral->owner = nullptr;
155155
}
156156
unlock();
157157
}
158158

159159
SPI::spi_peripheral_s *SPI::_lookup(SPI::SPIName name)
160160
{
161-
SPI::spi_peripheral_s *result = NULL;
161+
SPI::spi_peripheral_s *result = nullptr;
162162
core_util_critical_section_enter();
163163
for (int idx = 0; idx < _peripherals_used; idx++) {
164164
if (_peripherals[idx].name == name) {

drivers/source/Serial.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ Serial::Serial(const serial_pinmap_t &static_pinmap, const char *name, int baud)
2828
{
2929
}
3030

31-
Serial::Serial(PinName tx, PinName rx, int baud): SerialBase(tx, rx, baud), Stream(NULL)
31+
Serial::Serial(PinName tx, PinName rx, int baud): SerialBase(tx, rx, baud), Stream()
3232
{
3333
}
3434

35-
Serial::Serial(const serial_pinmap_t &static_pinmap, int baud): SerialBase(static_pinmap, baud), Stream(NULL)
35+
Serial::Serial(const serial_pinmap_t &static_pinmap, int baud): SerialBase(static_pinmap, baud), Stream()
3636
{
3737
}
3838

drivers/source/SerialBase.cpp

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,13 @@ SerialBase::SerialBase(PinName tx, PinName rx, int baud) :
3434
{
3535
// No lock needed in the constructor
3636

37-
for (size_t i = 0; i < sizeof _irq / sizeof _irq[0]; i++) {
38-
_irq[i] = NULL;
39-
}
40-
4137
(this->*_init_func)();
4238
}
4339

4440
SerialBase::SerialBase(const serial_pinmap_t &static_pinmap, int baud) :
4541
#if DEVICE_SERIAL_ASYNCH
46-
_thunk_irq(this), _tx_usage(DMA_USAGE_NEVER),
47-
_rx_usage(DMA_USAGE_NEVER), _tx_callback(NULL),
48-
_rx_callback(NULL), _tx_asynch_set(false),
49-
_rx_asynch_set(false),
42+
_thunk_irq(this),
5043
#endif
51-
_serial(),
5244
_baud(baud),
5345
_tx_pin(static_pinmap.tx_pin),
5446
_rx_pin(static_pinmap.rx_pin),
@@ -57,10 +49,6 @@ SerialBase::SerialBase(const serial_pinmap_t &static_pinmap, int baud) :
5749
{
5850
// No lock needed in the constructor
5951

60-
for (size_t i = 0; i < sizeof _irq / sizeof _irq[0]; i++) {
61-
_irq[i] = NULL;
62-
}
63-
6452
(this->*_init_func)();
6553
}
6654

@@ -118,7 +106,7 @@ void SerialBase::attach(Callback<void()> func, IrqType type)
118106
if (_irq[type]) {
119107
sleep_manager_unlock_deep_sleep();
120108
}
121-
_irq[type] = NULL;
109+
_irq[type] = nullptr;
122110
serial_irq_set(&_serial, (SerialIrq)type, 0);
123111
}
124112
core_util_critical_section_exit();
@@ -187,7 +175,7 @@ void SerialBase::enable_input(bool enable)
187175
core_util_critical_section_enter();
188176
if (enable) {
189177
// Enable rx IRQ and lock deep sleep if a rx handler is attached
190-
// (indicated by rx IRQ callback not NULL)
178+
// (indicated by rx IRQ callback not empty)
191179
if (_irq[RxIrq]) {
192180
_irq[RxIrq].call();
193181
sleep_manager_lock_deep_sleep();
@@ -197,7 +185,7 @@ void SerialBase::enable_input(bool enable)
197185
// Disable rx IRQ
198186
serial_irq_set(&_serial, (SerialIrq)RxIrq, 0);
199187
// Unlock deep sleep if a rx handler is attached
200-
// (indicated by rx IRQ callback not NULL)
188+
// (indicated by rx IRQ callback not empty)
201189
if (_irq[RxIrq]) {
202190
sleep_manager_unlock_deep_sleep();
203191
}
@@ -224,7 +212,7 @@ void SerialBase::enable_output(bool enable)
224212
core_util_critical_section_enter();
225213
if (enable) {
226214
// Enable tx IRQ and lock deep sleep if a tx handler is attached
227-
// (indicated by tx IRQ callback not NULL)
215+
// (indicated by tx IRQ callback not empty)
228216
if (_irq[TxIrq]) {
229217
_irq[TxIrq].call();
230218
sleep_manager_lock_deep_sleep();
@@ -234,7 +222,7 @@ void SerialBase::enable_output(bool enable)
234222
// Disable tx IRQ
235223
serial_irq_set(&_serial, (SerialIrq)TxIrq, 0);
236224
// Unlock deep sleep if a tx handler is attached
237-
// (indicated by tx IRQ callback not NULL)
225+
// (indicated by tx IRQ callback not empty)
238226
if (_irq[TxIrq]) {
239227
sleep_manager_unlock_deep_sleep();
240228
}
@@ -297,7 +285,7 @@ SerialBase::~SerialBase()
297285

298286
// Detaching interrupts releases the sleep lock if it was locked
299287
for (int irq = 0; irq < IrqCnt; irq++) {
300-
attach(NULL, (IrqType)irq);
288+
attach(nullptr, (IrqType)irq);
301289
}
302290
}
303291

@@ -389,7 +377,7 @@ void SerialBase::abort_write(void)
389377
lock();
390378
core_util_critical_section_enter();
391379
if (_tx_asynch_set) {
392-
_tx_callback = NULL;
380+
_tx_callback = nullptr;
393381
_tx_asynch_set = false;
394382
serial_tx_abort_asynch(&_serial);
395383
sleep_manager_unlock_deep_sleep();
@@ -403,7 +391,7 @@ void SerialBase::abort_read(void)
403391
lock();
404392
core_util_critical_section_enter();
405393
if (_rx_asynch_set) {
406-
_rx_callback = NULL;
394+
_rx_callback = nullptr;
407395
_rx_asynch_set = false;
408396
serial_rx_abort_asynch(&_serial);
409397
sleep_manager_unlock_deep_sleep();
@@ -475,7 +463,7 @@ void SerialBase::interrupt_handler_asynch(void)
475463
if (_rx_asynch_set && rx_event) {
476464
event_callback_t cb = _rx_callback;
477465
_rx_asynch_set = false;
478-
_rx_callback = NULL;
466+
_rx_callback = nullptr;
479467
if (cb) {
480468
cb.call(rx_event);
481469
}
@@ -486,7 +474,7 @@ void SerialBase::interrupt_handler_asynch(void)
486474
if (_tx_asynch_set && tx_event) {
487475
event_callback_t cb = _tx_callback;
488476
_tx_asynch_set = false;
489-
_tx_callback = NULL;
477+
_tx_callback = nullptr;
490478
if (cb) {
491479
cb.call(tx_event);
492480
}

drivers/source/Ticker.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323

2424
namespace mbed {
2525

26-
Ticker::Ticker() : TimerEvent(), _delay(0), _function(0), _lock_deepsleep(true)
26+
Ticker::Ticker() : TimerEvent(), _delay(0), _lock_deepsleep(true)
2727
{
2828
}
2929

3030
// When low power ticker is in use, then do not disable deep sleep.
31-
Ticker::Ticker(const ticker_data_t *data) : TimerEvent(data), _delay(0), _function(0), _lock_deepsleep(!data->interface->runs_in_deep_sleep)
31+
Ticker::Ticker(const ticker_data_t *data) : TimerEvent(data), _delay(0), _lock_deepsleep(!data->interface->runs_in_deep_sleep)
3232
{
3333
}
3434

drivers/source/UARTSerial.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ void UARTSerial::set_baud(int baud)
6767
void UARTSerial::set_data_carrier_detect(PinName dcd_pin, bool active_high)
6868
{
6969
delete _dcd_irq;
70-
_dcd_irq = NULL;
70+
_dcd_irq = nullptr;
7171

7272
if (dcd_pin != NC) {
7373
_dcd_irq = new InterruptIn(dcd_pin);
@@ -361,7 +361,7 @@ void UARTSerial::enable_rx_irq()
361361

362362
void UARTSerial::disable_rx_irq()
363363
{
364-
SerialBase::attach(NULL, RxIrq);
364+
SerialBase::attach(nullptr, RxIrq);
365365
_rx_irq_enabled = false;
366366
}
367367

@@ -373,7 +373,7 @@ void UARTSerial::enable_tx_irq()
373373

374374
void UARTSerial::disable_tx_irq()
375375
{
376-
SerialBase::attach(NULL, TxIrq);
376+
SerialBase::attach(nullptr, TxIrq);
377377
_tx_irq_enabled = false;
378378
}
379379

drivers/source/usb/AsyncOp.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ void AsyncOp::complete()
8585
core_util_critical_section_enter();
8686

8787
mbed::Callback<void()> cb = _callback;
88-
_callback = NULL;
89-
_list = NULL;
90-
if (_wait != NULL) {
88+
_callback = nullptr;
89+
_list = nullptr;
90+
if (_wait != nullptr) {
9191
_wait->release();
9292
}
9393

@@ -115,11 +115,11 @@ void AsyncOp::_abort(bool timeout)
115115
core_util_critical_section_enter();
116116
OperationListBase *list = _list;
117117
if (list) {
118-
_callback = NULL;
118+
_callback = nullptr;
119119
_aborted = true;
120-
_wait = NULL;
120+
_wait = nullptr;
121121
_timeout = timeout;
122-
_list = NULL;
122+
_list = nullptr;
123123
}
124124
core_util_critical_section_exit();
125125
if (list) {

drivers/source/usb/USBDevice.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1177,7 +1177,7 @@ void USBDevice::endpoint_remove(usb_ep_t endpoint)
11771177
_phy->endpoint_abort(endpoint);
11781178
}
11791179

1180-
info->callback = NULL;
1180+
info->callback = nullptr;
11811181
info->flags = 0;
11821182
info->pending = 0;
11831183
info->max_packet_size = 0;

features/cellular/framework/AT/AT_CellularDevice.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ AT_CellularDevice::AT_CellularDevice(FileHandle *fh) : CellularDevice(fh),
5353
AT_CellularDevice::~AT_CellularDevice()
5454
{
5555
if (get_property(PROPERTY_AT_CGEREP)) {
56-
_at->set_urc_handler("+CGEV: NW DEACT", 0);
57-
_at->set_urc_handler("+CGEV: ME DEACT", 0);
58-
_at->set_urc_handler("+CGEV: NW PDN D", 0);
59-
_at->set_urc_handler("+CGEV: ME PDN D", 0);
56+
_at->set_urc_handler("+CGEV: NW DEACT", nullptr);
57+
_at->set_urc_handler("+CGEV: ME DEACT", nullptr);
58+
_at->set_urc_handler("+CGEV: NW PDN D", nullptr);
59+
_at->set_urc_handler("+CGEV: ME PDN D", nullptr);
6060
}
6161

6262
// make sure that all is deleted even if somewhere close was not called and reference counting is messed up.

0 commit comments

Comments
 (0)