Skip to content

Commit

Permalink
Turn NULLs into nullptr
Browse files Browse the repository at this point in the history
Avoids overload problems with Callback(nullptr) versus Callback(fnptr).
  • Loading branch information
kjbracey committed Jan 9, 2020
1 parent 9577b08 commit d6a48b5
Show file tree
Hide file tree
Showing 31 changed files with 82 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ static void rf_if_reset_radio(void)
#else
rf->spi.frequency(MBED_CONF_ATMEL_RF_LOW_SPI_SPEED);
#endif
rf->IRQ.rise(0);
rf->IRQ.rise(nullptr);
rf->RST = 1;
ThisThread::sleep_for(2);
rf->RST = 0;
Expand Down
2 changes: 1 addition & 1 deletion components/wifi/esp8266-driver/ESP8266/ESP8266.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ ESP8266::ESP8266(PinName tx, PinName rx, bool debug, PinName rts, PinName cts)
: _sdk_v(-1, -1, -1),
_at_v(-1, -1, -1),
_tcp_passive(false),
_callback(0),
_callback(),
_serial(tx, rx, MBED_CONF_ESP8266_SERIAL_BAUDRATE),
_serial_rts(rts),
_serial_cts(cts),
Expand Down
4 changes: 2 additions & 2 deletions components/wifi/esp8266-driver/ESP8266Interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ ESP8266Interface::ESP8266Interface()
_connect_retval(NSAPI_ERROR_OK),
_disconnect_retval(NSAPI_ERROR_OK),
_conn_stat(NSAPI_STATUS_DISCONNECTED),
_conn_stat_cb(NULL),
_conn_stat_cb(),
_global_event_queue(mbed_event_queue()), // Needs to be set before attaching event() to SIGIO
_oob_event_id(0),
_connect_event_id(0),
Expand Down Expand Up @@ -113,7 +113,7 @@ ESP8266Interface::ESP8266Interface(PinName tx, PinName rx, bool debug, PinName r
_connect_retval(NSAPI_ERROR_OK),
_disconnect_retval(NSAPI_ERROR_OK),
_conn_stat(NSAPI_STATUS_DISCONNECTED),
_conn_stat_cb(NULL),
_conn_stat_cb(),
_global_event_queue(mbed_event_queue()), // Needs to be set before attaching event() to SIGIO
_oob_event_id(0),
_connect_event_id(0),
Expand Down
8 changes: 4 additions & 4 deletions drivers/SerialBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ class SerialBase : private NonCopyable<SerialBase> {
/** Begin asynchronous write using 8bit buffer.
*
* The write operation ends with any of the enabled events and invokes
* registered callback function (which can be NULL to not receive callback at all).
* registered callback function (which can be empty to not receive callback at all).
* Events that are not enabled by event argument are simply ignored.
* Operation has to be ended explicitly by calling abort_write() when
* no events are enabled.
Expand All @@ -233,7 +233,7 @@ class SerialBase : private NonCopyable<SerialBase> {
/** Begin asynchronous write using 16bit buffer.
*
* The write operation ends with any of the enabled events and invokes
* registered callback function (which can be NULL to not receive callback at all).
* registered callback function (which can be empty to not receive callback at all).
* Events that are not enabled by event argument are simply ignored.
* Operation has to be ended explicitly by calling abort_write() when
* no events are enabled.
Expand All @@ -256,7 +256,7 @@ class SerialBase : private NonCopyable<SerialBase> {
/** Begin asynchronous reading using 8bit buffer.
*
* The read operation ends with any of the enabled events and invokes registered
* callback function (which can be NULL to not receive callback at all).
* callback function (which can be empty to not receive callback at all).
* Events that are not enabled by event argument are simply ignored.
* Operation has to be ended explicitly by calling abort_read() when
* no events are enabled.
Expand All @@ -274,7 +274,7 @@ class SerialBase : private NonCopyable<SerialBase> {
/** Begin asynchronous reading using 16bit buffer.
*
* The read operation ends with any of the enabled events and invokes registered
* callback function (which can be NULL to not receive callback at all).
* callback function (which can be empty to not receive callback at all).
* Events that are not enabled by event argument are simply ignored.
* Operation has to be ended explicitly by calling abort_read() when
* no events are enabled.
Expand Down
2 changes: 1 addition & 1 deletion drivers/internal/PolledQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class PolledQueue: public TaskQueue {
*
* @param cb Callback called when dispatch needs to be called
*/
PolledQueue(mbed::Callback<void()> cb = NULL);
PolledQueue(mbed::Callback<void()> cb = nullptr);

virtual ~PolledQueue();

Expand Down
2 changes: 1 addition & 1 deletion drivers/internal/USBDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class USBDevice: public USBPhyEvents {
* @param callback Method pointer to be called when a packet is transferred
* @returns true if successful, false otherwise
*/
bool endpoint_add(usb_ep_t endpoint, uint32_t max_packet, usb_ep_type_t type, mbed::Callback<void()> callback = NULL);
bool endpoint_add(usb_ep_t endpoint, uint32_t max_packet, usb_ep_type_t type, mbed::Callback<void()> callback = nullptr);

/**
* Add an endpoint
Expand Down
4 changes: 2 additions & 2 deletions drivers/source/CAN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ CAN::~CAN()

// Detaching interrupts releases the sleep lock if it was locked
for (int irq = 0; irq < IrqCnt; irq++) {
attach(NULL, (IrqType)irq);
attach(nullptr, (IrqType)irq);
}
can_irq_free(&_can);
can_free(&_can);
Expand Down Expand Up @@ -147,7 +147,7 @@ void CAN::attach(Callback<void()> func, IrqType type)
if (_irq[(CanIrqType)type]) {
sleep_manager_unlock_deep_sleep();
}
_irq[(CanIrqType)type] = NULL;
_irq[(CanIrqType)type] = nullptr;
can_irq_set(&_can, (CanIrqType)type, 0);
}
unlock();
Expand Down
12 changes: 6 additions & 6 deletions drivers/source/InterruptIn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ namespace mbed {
// constructor, with a default value for the PinMode.
InterruptIn::InterruptIn(PinName pin) : gpio(),
gpio_irq(),
_rise(NULL),
_fall(NULL)
_rise(),
_fall()
{
// No lock needed in the constructor
irq_init(pin);
Expand All @@ -37,8 +37,8 @@ InterruptIn::InterruptIn(PinName pin) : gpio(),
InterruptIn::InterruptIn(PinName pin, PinMode mode) :
gpio(),
gpio_irq(),
_rise(NULL),
_fall(NULL)
_rise(),
_fall()
{
// No lock needed in the constructor
irq_init(pin);
Expand Down Expand Up @@ -76,7 +76,7 @@ void InterruptIn::rise(Callback<void()> func)
_rise = func;
gpio_irq_set(&gpio_irq, IRQ_RISE, 1);
} else {
_rise = NULL;
_rise = nullptr;
gpio_irq_set(&gpio_irq, IRQ_RISE, 0);
}
core_util_critical_section_exit();
Expand All @@ -89,7 +89,7 @@ void InterruptIn::fall(Callback<void()> func)
_fall = func;
gpio_irq_set(&gpio_irq, IRQ_FALL, 1);
} else {
_fall = NULL;
_fall = nullptr;
gpio_irq_set(&gpio_irq, IRQ_FALL, 0);
}
core_util_critical_section_exit();
Expand Down
4 changes: 2 additions & 2 deletions drivers/source/SPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,14 @@ SPI::~SPI()
lock();
/* Make sure a stale pointer isn't left in peripheral's owner field */
if (_peripheral->owner == this) {
_peripheral->owner = NULL;
_peripheral->owner = nullptr;
}
unlock();
}

SPI::spi_peripheral_s *SPI::_lookup(SPI::SPIName name)
{
SPI::spi_peripheral_s *result = NULL;
SPI::spi_peripheral_s *result = nullptr;
core_util_critical_section_enter();
for (int idx = 0; idx < _peripherals_used; idx++) {
if (_peripherals[idx].name == name) {
Expand Down
4 changes: 2 additions & 2 deletions drivers/source/Serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ Serial::Serial(const serial_pinmap_t &static_pinmap, const char *name, int baud)
{
}

Serial::Serial(PinName tx, PinName rx, int baud): SerialBase(tx, rx, baud), Stream(NULL)
Serial::Serial(PinName tx, PinName rx, int baud): SerialBase(tx, rx, baud), Stream()
{
}

Serial::Serial(const serial_pinmap_t &static_pinmap, int baud): SerialBase(static_pinmap, baud), Stream(NULL)
Serial::Serial(const serial_pinmap_t &static_pinmap, int baud): SerialBase(static_pinmap, baud), Stream()
{
}

Expand Down
34 changes: 11 additions & 23 deletions drivers/source/SerialBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,13 @@ SerialBase::SerialBase(PinName tx, PinName rx, int baud) :
{
// No lock needed in the constructor

for (size_t i = 0; i < sizeof _irq / sizeof _irq[0]; i++) {
_irq[i] = NULL;
}

(this->*_init_func)();
}

SerialBase::SerialBase(const serial_pinmap_t &static_pinmap, int baud) :
#if DEVICE_SERIAL_ASYNCH
_thunk_irq(this), _tx_usage(DMA_USAGE_NEVER),
_rx_usage(DMA_USAGE_NEVER), _tx_callback(NULL),
_rx_callback(NULL), _tx_asynch_set(false),
_rx_asynch_set(false),
_thunk_irq(this),
#endif
_serial(),
_baud(baud),
_tx_pin(static_pinmap.tx_pin),
_rx_pin(static_pinmap.rx_pin),
Expand All @@ -57,10 +49,6 @@ SerialBase::SerialBase(const serial_pinmap_t &static_pinmap, int baud) :
{
// No lock needed in the constructor

for (size_t i = 0; i < sizeof _irq / sizeof _irq[0]; i++) {
_irq[i] = NULL;
}

(this->*_init_func)();
}

Expand Down Expand Up @@ -118,7 +106,7 @@ void SerialBase::attach(Callback<void()> func, IrqType type)
if (_irq[type]) {
sleep_manager_unlock_deep_sleep();
}
_irq[type] = NULL;
_irq[type] = nullptr;
serial_irq_set(&_serial, (SerialIrq)type, 0);
}
core_util_critical_section_exit();
Expand Down Expand Up @@ -187,7 +175,7 @@ void SerialBase::enable_input(bool enable)
core_util_critical_section_enter();
if (enable) {
// Enable rx IRQ and lock deep sleep if a rx handler is attached
// (indicated by rx IRQ callback not NULL)
// (indicated by rx IRQ callback not empty)
if (_irq[RxIrq]) {
_irq[RxIrq].call();
sleep_manager_lock_deep_sleep();
Expand All @@ -197,7 +185,7 @@ void SerialBase::enable_input(bool enable)
// Disable rx IRQ
serial_irq_set(&_serial, (SerialIrq)RxIrq, 0);
// Unlock deep sleep if a rx handler is attached
// (indicated by rx IRQ callback not NULL)
// (indicated by rx IRQ callback not empty)
if (_irq[RxIrq]) {
sleep_manager_unlock_deep_sleep();
}
Expand All @@ -224,7 +212,7 @@ void SerialBase::enable_output(bool enable)
core_util_critical_section_enter();
if (enable) {
// Enable tx IRQ and lock deep sleep if a tx handler is attached
// (indicated by tx IRQ callback not NULL)
// (indicated by tx IRQ callback not empty)
if (_irq[TxIrq]) {
_irq[TxIrq].call();
sleep_manager_lock_deep_sleep();
Expand All @@ -234,7 +222,7 @@ void SerialBase::enable_output(bool enable)
// Disable tx IRQ
serial_irq_set(&_serial, (SerialIrq)TxIrq, 0);
// Unlock deep sleep if a tx handler is attached
// (indicated by tx IRQ callback not NULL)
// (indicated by tx IRQ callback not empty)
if (_irq[TxIrq]) {
sleep_manager_unlock_deep_sleep();
}
Expand Down Expand Up @@ -297,7 +285,7 @@ SerialBase::~SerialBase()

// Detaching interrupts releases the sleep lock if it was locked
for (int irq = 0; irq < IrqCnt; irq++) {
attach(NULL, (IrqType)irq);
attach(nullptr, (IrqType)irq);
}
}

Expand Down Expand Up @@ -389,7 +377,7 @@ void SerialBase::abort_write(void)
lock();
core_util_critical_section_enter();
if (_tx_asynch_set) {
_tx_callback = NULL;
_tx_callback = nullptr;
_tx_asynch_set = false;
serial_tx_abort_asynch(&_serial);
sleep_manager_unlock_deep_sleep();
Expand All @@ -403,7 +391,7 @@ void SerialBase::abort_read(void)
lock();
core_util_critical_section_enter();
if (_rx_asynch_set) {
_rx_callback = NULL;
_rx_callback = nullptr;
_rx_asynch_set = false;
serial_rx_abort_asynch(&_serial);
sleep_manager_unlock_deep_sleep();
Expand Down Expand Up @@ -475,7 +463,7 @@ void SerialBase::interrupt_handler_asynch(void)
if (_rx_asynch_set && rx_event) {
event_callback_t cb = _rx_callback;
_rx_asynch_set = false;
_rx_callback = NULL;
_rx_callback = nullptr;
if (cb) {
cb.call(rx_event);
}
Expand All @@ -486,7 +474,7 @@ void SerialBase::interrupt_handler_asynch(void)
if (_tx_asynch_set && tx_event) {
event_callback_t cb = _tx_callback;
_tx_asynch_set = false;
_tx_callback = NULL;
_tx_callback = nullptr;
if (cb) {
cb.call(tx_event);
}
Expand Down
4 changes: 2 additions & 2 deletions drivers/source/Ticker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@

namespace mbed {

Ticker::Ticker() : TimerEvent(), _delay(0), _function(0), _lock_deepsleep(true)
Ticker::Ticker() : TimerEvent(), _delay(0), _lock_deepsleep(true)
{
}

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

Expand Down
6 changes: 3 additions & 3 deletions drivers/source/UARTSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void UARTSerial::set_baud(int baud)
void UARTSerial::set_data_carrier_detect(PinName dcd_pin, bool active_high)
{
delete _dcd_irq;
_dcd_irq = NULL;
_dcd_irq = nullptr;

if (dcd_pin != NC) {
_dcd_irq = new InterruptIn(dcd_pin);
Expand Down Expand Up @@ -361,7 +361,7 @@ void UARTSerial::enable_rx_irq()

void UARTSerial::disable_rx_irq()
{
SerialBase::attach(NULL, RxIrq);
SerialBase::attach(nullptr, RxIrq);
_rx_irq_enabled = false;
}

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

void UARTSerial::disable_tx_irq()
{
SerialBase::attach(NULL, TxIrq);
SerialBase::attach(nullptr, TxIrq);
_tx_irq_enabled = false;
}

Expand Down
12 changes: 6 additions & 6 deletions drivers/source/usb/AsyncOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ void AsyncOp::complete()
core_util_critical_section_enter();

mbed::Callback<void()> cb = _callback;
_callback = NULL;
_list = NULL;
if (_wait != NULL) {
_callback = nullptr;
_list = nullptr;
if (_wait != nullptr) {
_wait->release();
}

Expand Down Expand Up @@ -115,11 +115,11 @@ void AsyncOp::_abort(bool timeout)
core_util_critical_section_enter();
OperationListBase *list = _list;
if (list) {
_callback = NULL;
_callback = nullptr;
_aborted = true;
_wait = NULL;
_wait = nullptr;
_timeout = timeout;
_list = NULL;
_list = nullptr;
}
core_util_critical_section_exit();
if (list) {
Expand Down
2 changes: 1 addition & 1 deletion drivers/source/usb/USBDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1177,7 +1177,7 @@ void USBDevice::endpoint_remove(usb_ep_t endpoint)
_phy->endpoint_abort(endpoint);
}

info->callback = NULL;
info->callback = nullptr;
info->flags = 0;
info->pending = 0;
info->max_packet_size = 0;
Expand Down
8 changes: 4 additions & 4 deletions features/cellular/framework/AT/AT_CellularDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ AT_CellularDevice::AT_CellularDevice(FileHandle *fh) : CellularDevice(fh),
AT_CellularDevice::~AT_CellularDevice()
{
if (get_property(PROPERTY_AT_CGEREP)) {
_at->set_urc_handler("+CGEV: NW DEACT", 0);
_at->set_urc_handler("+CGEV: ME DEACT", 0);
_at->set_urc_handler("+CGEV: NW PDN D", 0);
_at->set_urc_handler("+CGEV: ME PDN D", 0);
_at->set_urc_handler("+CGEV: NW DEACT", nullptr);
_at->set_urc_handler("+CGEV: ME DEACT", nullptr);
_at->set_urc_handler("+CGEV: NW PDN D", nullptr);
_at->set_urc_handler("+CGEV: ME PDN D", nullptr);
}

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

0 comments on commit d6a48b5

Please sign in to comment.