From 57bd62a1fbd890d2bb546acea9c52dcb1e56a7ec Mon Sep 17 00:00:00 2001 From: AJR Date: Wed, 24 Jan 2018 21:06:25 -0500 Subject: Eliminate core_strdup (nw) --- src/frontend/mame/pluginopts.cpp | 3 ++- src/frontend/mame/pluginopts.h | 1 + src/lib/util/corestr.cpp | 17 ----------------- src/lib/util/corestr.h | 8 -------- src/osd/modules/lib/osdobj_common.cpp | 11 ++++++----- src/osd/modules/lib/osdobj_common.h | 3 ++- 6 files changed, 11 insertions(+), 32 deletions(-) diff --git a/src/frontend/mame/pluginopts.cpp b/src/frontend/mame/pluginopts.cpp index b9a9e8d3c3b..88119e52491 100644 --- a/src/frontend/mame/pluginopts.cpp +++ b/src/frontend/mame/pluginopts.cpp @@ -75,7 +75,8 @@ void plugin_options::parse_json(std::string path) if (type=="plugin") { - add_entry({ std::move(plugin_name) }, core_strdup(description.c_str()), option_type::BOOLEAN, start ? "1" : "0"); + m_descriptions.push_back(std::move(description)); + add_entry({ std::move(plugin_name) }, m_descriptions.back().c_str(), option_type::BOOLEAN, start ? "1" : "0"); } } diff --git a/src/frontend/mame/pluginopts.h b/src/frontend/mame/pluginopts.h index 91aa68c2208..4e78dfd0be6 100644 --- a/src/frontend/mame/pluginopts.h +++ b/src/frontend/mame/pluginopts.h @@ -24,6 +24,7 @@ public: void parse_json(std::string path); private: static const options_entry s_option_entries[]; + std::vector m_descriptions; }; #endif /* __PLUGIN_OPTS_H__ */ diff --git a/src/lib/util/corestr.cpp b/src/lib/util/corestr.cpp index b9e56c5cdc5..a2fef33a87a 100644 --- a/src/lib/util/corestr.cpp +++ b/src/lib/util/corestr.cpp @@ -118,23 +118,6 @@ bool core_iswildstr(const char *sp) } -/*------------------------------------------------- - core_strdup - string duplication via malloc --------------------------------------------------*/ - -char *core_strdup(const char *str) -{ - char *cpy = nullptr; - if (str != nullptr) - { - cpy = (char *)malloc(strlen(str) + 1); - if (cpy != nullptr) - strcpy(cpy, str); - } - return cpy; -} - - /*------------------------------------------------- std::string helpers -------------------------------------------------*/ diff --git a/src/lib/util/corestr.h b/src/lib/util/corestr.h index f4d8d7bed09..4df0a5ae812 100644 --- a/src/lib/util/corestr.h +++ b/src/lib/util/corestr.h @@ -49,14 +49,6 @@ int core_strnicmp(const char *s1, const char *s2, size_t n); #define strncasecmp MUST_USE_CORE_STRNICMP_INSTEAD -/* since strdup is not part of the standard, we use this instead - free with free() */ -char *core_strdup(const char *str); - -/* this macro prevents people from using strdup directly */ -#undef strdup -#define strdup MUST_USE_CORE_STRDUP_INSTEAD - - /* additional string compare helper (up to 16 characters at the moment) */ int core_strwildcmp(const char *sp1, const char *sp2); bool core_iswildstr(const char *sp); diff --git a/src/osd/modules/lib/osdobj_common.cpp b/src/osd/modules/lib/osdobj_common.cpp index 5e3846a2b68..f3ded43e81c 100644 --- a/src/osd/modules/lib/osdobj_common.cpp +++ b/src/osd/modules/lib/osdobj_common.cpp @@ -354,9 +354,9 @@ void osd_common_t::register_options() update_option(OSDOPTION_VIDEO, m_video_names); } -void osd_common_t::update_option(const char * key, std::vector &values) const +void osd_common_t::update_option(const std::string &key, std::vector &values) { - std::string current_value(m_options.description(key)); + std::string current_value(m_options.description(key.c_str())); std::string new_option_value(""); for (unsigned int index = 0; index < values.size(); index++) { @@ -370,8 +370,9 @@ void osd_common_t::update_option(const char * key, std::vector &va } new_option_value.append(t); } - // TODO: core_strdup() is leaked - m_options.set_description(key, core_strdup(current_value.append(new_option_value).c_str())); + + m_option_descs[key] = current_value + new_option_value; + m_options.set_description(key.c_str(), m_option_descs[key].c_str()); } @@ -751,5 +752,5 @@ void osd_common_t::osd_exit() void osd_common_t::video_options_add(const char *name, void *type) { //m_video_options.add(name, type, false); - m_video_names.push_back(core_strdup(name)); + m_video_names.push_back(name); } diff --git a/src/osd/modules/lib/osdobj_common.h b/src/osd/modules/lib/osdobj_common.h index 99acfb045f6..7d6e303fd8e 100644 --- a/src/osd/modules/lib/osdobj_common.h +++ b/src/osd/modules/lib/osdobj_common.h @@ -265,7 +265,7 @@ private: osd_module_manager m_mod_man; font_module *m_font_module; - void update_option(const char * key, std::vector &values) const; + void update_option(const std::string &key, std::vector &values); // FIXME: should be elsewhere osd_module *select_module_options(const core_options &opts, const std::string &opt_name) { @@ -301,6 +301,7 @@ protected: private: std::vector m_video_names; + std::unordered_map m_option_descs; }; -- cgit v1.2.3