diff options
author | Vas Crabb <vas@vastheman.com> | 2018-07-31 16:12:22 +1000 |
---|---|---|
committer | Vas Crabb <vas@vastheman.com> | 2018-07-31 16:12:22 +1000 |
commit | 8999ac2c15c808bb967871fcfeb8aba797f9b503 (patch) | |
tree | 0922276efcbc15eb6a16176db9dee62c05db3e3b | |
parent | 279d066e1b68808a22c5fbc3f276a79f93a878e0 (diff) |
(nw) add warning comment to dangerous API
I'm not sure this API is a great idea - see inline comment on https://github.com/mamedev/mame/commit/796abaf7f3200a96499440a4c40bec3440d55209
I realise it seems intuitive, but it breaks with a use-after-free (not even a
validity error) if you replace/remove the target device. Implementing it in a
way that isn't fragile and doesn't hurt the performance of -romident,
-validate and -listxml seems impossible. If it causes developer confusing and
things start breaking, back to literal tags we go for this case.
-rw-r--r-- | src/emu/devfind.h | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/src/emu/devfind.h b/src/emu/devfind.h index d49d48be6c9..1fe2ed78439 100644 --- a/src/emu/devfind.h +++ b/src/emu/devfind.h @@ -508,6 +508,8 @@ template <class DeviceClass, bool Required> class device_finder : public object_finder_base<DeviceClass, Required> { public: + using object_finder_base<DeviceClass, Required>::set_tag; + /// \brief Device finder constructor /// \param [in] base Base device to search from. /// \param [in] tag Device tag to search for. This is not copied, @@ -518,19 +520,13 @@ public: /// \brief Set search tag /// /// Allows search tag to be changed after construction. Note that - /// this must be done before resolution time to take effect. + /// this must be done before resolution time to take effect. Note + /// that this binds to a particular instance, so the device must not + /// be removed or replaced, as it will cause a use-after-free when + /// resolving objects. /// \param [in] object Object to refer to. void set_tag(DeviceClass &object) { set_tag(object, DEVICE_SELF); } - /// \brief Set search tag - /// - /// Allows search tag to be changed after construction. Note that - /// this must be done before resolution time to take effect. - /// \param [in] object Object to refer to. - void set_tag(DeviceClass *object) { assert(object != nullptr); set_tag(*object, DEVICE_SELF); } - - using object_finder_base<DeviceClass, Required>::set_tag; - /// \brief Set target during configuration /// /// During configuration, device_finder instances may be assigned |