diff options
author | 2020-10-03 02:50:49 +1000 | |
---|---|---|
committer | 2020-10-03 03:00:24 +1000 | |
commit | 4f05917494b22943ab0e7c466e4eb9f7a5896daa (patch) | |
tree | b05a6b7820548f21ab8df21c4e4ca034eff0659f /src/osd/modules/midi | |
parent | 3340fc0d2171011e3f6d7f41f0414e9d3952e364 (diff) |
Got rid of global_alloc/global_free.
The global_alloc/global_free functions have outlived their usefulness.
They don't allow consistently overriding the default memory allocation
behaviour because they aren't used consistently, and we don't have
standard library allocator wrappers for them that we'd need to use them
consistently with all the standard library containers we're using. If
you need to change the default allocator behaviour, you can override the
new/delete operators, and there are ways to get more fine-grained
control that way. We're already doing that to pre-fill memory in debug
builds.
Code was already starting to depend on global_alloc/global_free wrapping
new/delete. For example some parts of the code (including the UI and
Windows debugger) was putting the result of global_alloc in a
std::unique_ptr wrappers without custom deleters, and the SPU sound
device was assuming it could use global_free to release memory allocated
with operator new. There was also code misunderstanding the behaviour
of global_alloc, for example the GROM port cartridge code was checking
for nullptr when a failure will actually throw std::bad_alloc.
As well as substituting new/delete, I've made several things use smart
pointers to reduce the chance of leaks, and fixed a couple of leaks,
too.
Diffstat (limited to 'src/osd/modules/midi')
-rw-r--r-- | src/osd/modules/midi/midi_module.h | 15 | ||||
-rw-r--r-- | src/osd/modules/midi/none.cpp | 9 | ||||
-rw-r--r-- | src/osd/modules/midi/portmidi.cpp | 6 |
3 files changed, 16 insertions, 14 deletions
diff --git a/src/osd/modules/midi/midi_module.h b/src/osd/modules/midi/midi_module.h index 6c50cdd3edc..8e64800622e 100644 --- a/src/osd/modules/midi/midi_module.h +++ b/src/osd/modules/midi/midi_module.h @@ -4,13 +4,17 @@ * midi_module.h * */ +#ifndef MAME_OSD_MODULES_MIDI_MIDI_MODULE_H +#define MAME_OSD_MODULES_MIDI_MIDI_MODULE_H -#ifndef MIDI_MODULE_H_ -#define MIDI_MODULE_H_ +#pragma once #include "osdepend.h" #include "modules/osdmodule.h" +#include <memory> + + //============================================================ // CONSTANTS //============================================================ @@ -23,10 +27,9 @@ public: virtual ~midi_module() { } // specific routines - virtual osd_midi_device *create_midi_device() = 0; + virtual std::unique_ptr<osd_midi_device> create_midi_device() = 0; // FIXME: should return a list of strings ... - virtual void list_midi_devices(void) = 0; + virtual void list_midi_devices() = 0; }; - -#endif /* MIDI_MODULE_H_ */ +#endif // MAME_OSD_MODULES_MIDI_MIDI_MODULE_H diff --git a/src/osd/modules/midi/none.cpp b/src/osd/modules/midi/none.cpp index 822de79bd08..25f83b45fbe 100644 --- a/src/osd/modules/midi/none.cpp +++ b/src/osd/modules/midi/none.cpp @@ -17,8 +17,7 @@ class none_module : public osd_module, public midi_module { public: - none_module() - : osd_module(OSD_MIDI_PROVIDER, "pm"), midi_module() + none_module() : osd_module(OSD_MIDI_PROVIDER, "pm"), midi_module() { } virtual ~none_module() { } @@ -26,7 +25,7 @@ public: virtual int init(const osd_options &options) override; virtual void exit() override; - virtual osd_midi_device *create_midi_device() override; + virtual std::unique_ptr<osd_midi_device> create_midi_device() override; virtual void list_midi_devices() override; }; @@ -43,9 +42,9 @@ public: virtual void write(uint8_t data) override; }; -osd_midi_device *none_module::create_midi_device() +std::unique_ptr<osd_midi_device> none_module::create_midi_device() { - return global_alloc(osd_midi_device_none()); + return std::make_unique<osd_midi_device_none>(); } diff --git a/src/osd/modules/midi/portmidi.cpp b/src/osd/modules/midi/portmidi.cpp index 64f71ca6689..9deca98ea2d 100644 --- a/src/osd/modules/midi/portmidi.cpp +++ b/src/osd/modules/midi/portmidi.cpp @@ -29,7 +29,7 @@ public: virtual int init(const osd_options &options)override; virtual void exit()override; - virtual osd_midi_device *create_midi_device() override; + virtual std::unique_ptr<osd_midi_device> create_midi_device() override; virtual void list_midi_devices() override; }; @@ -60,9 +60,9 @@ private: bool rx_sysex; }; -osd_midi_device *pm_module::create_midi_device() +std::unique_ptr<osd_midi_device> pm_module::create_midi_device() { - return global_alloc(osd_midi_device_pm()); + return std::make_unique<osd_midi_device_pm>(); } |