From 3f20d0a700d33a68946b1a84af9163e7b7890a11 Mon Sep 17 00:00:00 2001 From: Maxim Poliakovski Date: Mon, 25 Oct 2021 00:26:02 +0200 Subject: [PATCH] heathrow: use unique_ptr with internal objects. --- devices/ioctrl/heathrow.cpp | 33 +++++++++++---------------------- devices/ioctrl/macio.h | 13 +++++++------ devices/sound/awacs.h | 2 +- 3 files changed, 19 insertions(+), 29 deletions(-) diff --git a/devices/ioctrl/heathrow.cpp b/devices/ioctrl/heathrow.cpp index 1ed3569..ee5c1b8 100644 --- a/devices/ioctrl/heathrow.cpp +++ b/devices/ioctrl/heathrow.cpp @@ -24,12 +24,13 @@ along with this program. If not, see . #include #include #include +#include #include #include #include #include -#include +#include /** Heathrow Mac I/O device emulation. @@ -39,35 +40,23 @@ along with this program. If not, see . using namespace std; HeathrowIC::HeathrowIC() : PCIDevice("mac-io/heathrow") { - this->nvram = new NVram(); + this->nvram = std::unique_ptr (new NVram()); - this->viacuda = new ViaCuda(); - gMachineObj->add_subdevice("ViaCuda", this->viacuda); + this->viacuda = std::unique_ptr (new ViaCuda()); + gMachineObj->add_subdevice("ViaCuda", this->viacuda.get()); // initialize sound chip and its DMA output channel, then wire them together - this->screamer = new AwacsScreamer(); - this->snd_out_dma = new DMAChannel(); - this->screamer->set_dma_out(this->snd_out_dma); + this->screamer = std::unique_ptr (new AwacsScreamer()); + this->snd_out_dma = std::unique_ptr (new DMAChannel()); + this->screamer->set_dma_out(this->snd_out_dma.get()); this->snd_out_dma->set_callbacks( - std::bind(&AwacsScreamer::dma_start, this->screamer), - std::bind(&AwacsScreamer::dma_end, this->screamer) + std::bind(&AwacsScreamer::dma_start, this->screamer.get()), + std::bind(&AwacsScreamer::dma_end, this->screamer.get()) ); - this->mesh = new MESHController(HeathrowMESHID); + this->mesh = std::unique_ptr (new MESHController(HeathrowMESHID)); } -HeathrowIC::~HeathrowIC() { - if (this->nvram) - delete (this->nvram); - - if (this->viacuda) - delete (this->viacuda); - - if (this->mesh) - delete (this->mesh); -} - - uint32_t HeathrowIC::pci_cfg_read(uint32_t reg_offs, uint32_t size) { return this->pci_cfg_hdr[reg_offs & 0xFF]; } diff --git a/devices/ioctrl/macio.h b/devices/ioctrl/macio.h index 9e371fd..1f8656b 100644 --- a/devices/ioctrl/macio.h +++ b/devices/ioctrl/macio.h @@ -63,6 +63,7 @@ along with this program. If not, see . #include #include +#include /** Heathrow ASIC emulation @@ -91,7 +92,7 @@ along with this program. If not, see . class HeathrowIC : public PCIDevice { public: HeathrowIC(); - ~HeathrowIC(); + ~HeathrowIC() = default; bool supports_type(HWCompType type) { return type == HWCompType::MMIO_DEV; @@ -148,12 +149,12 @@ private: uint32_t aux_ctrl = 0; // aux features control register /* device cells */ - ViaCuda* viacuda; // VIA cell with Cuda MCU attached to it - NVram* nvram; // NVRAM cell - AwacsScreamer *screamer; // Screamer audio codec instance - MESHController *mesh; // MESH SCSI cell instance + std::unique_ptr viacuda; // VIA cell with Cuda MCU attached to it + std::unique_ptr nvram; // NVRAM cell + std::unique_ptr screamer; // Screamer audio codec instance + std::unique_ptr mesh; // MESH SCSI cell instance - DMAChannel* snd_out_dma; + std::unique_ptr snd_out_dma; }; #endif /* MACIO_H */ diff --git a/devices/sound/awacs.h b/devices/sound/awacs.h index 327b7fa..e5e1d0b 100644 --- a/devices/sound/awacs.h +++ b/devices/sound/awacs.h @@ -149,7 +149,7 @@ private: class AwacsScreamer : public AwacsBase { public: AwacsScreamer(); - ~AwacsScreamer(); + ~AwacsScreamer() = default; uint32_t snd_ctrl_read(uint32_t offset, int size); void snd_ctrl_write(uint32_t offset, uint32_t value, int size);