summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author AJR <ajrhacker@users.noreply.github.com>2018-01-24 21:06:25 -0500
committer AJR <ajrhacker@users.noreply.github.com>2018-01-24 21:06:25 -0500
commit57bd62a1fbd890d2bb546acea9c52dcb1e56a7ec (patch)
tree1656bc5b83717f2b98dd9e75a1332bcb5ac42caa
parente6b81449f8515d3e102d6940ab74b59b4a37869d (diff)
Eliminate core_strdup (nw)
-rw-r--r--src/frontend/mame/pluginopts.cpp3
-rw-r--r--src/frontend/mame/pluginopts.h1
-rw-r--r--src/lib/util/corestr.cpp17
-rw-r--r--src/lib/util/corestr.h8
-rw-r--r--src/osd/modules/lib/osdobj_common.cpp11
-rw-r--r--src/osd/modules/lib/osdobj_common.h3
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<std::string> 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
@@ -119,23 +119,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<const char *> &values) const
+void osd_common_t::update_option(const std::string &key, std::vector<const char *> &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<const char *> &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<const char *> &values) const;
+ void update_option(const std::string &key, std::vector<const char *> &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<const char *> m_video_names;
+ std::unordered_map<std::string, std::string> m_option_descs;
};