mirror of
https://github.com/holub/mame
synced 2025-07-03 17:08:39 +03:00
Eliminate core_strdup (nw)
This commit is contained in:
parent
e6b81449f8
commit
57bd62a1fb
@ -75,7 +75,8 @@ void plugin_options::parse_json(std::string path)
|
|||||||
|
|
||||||
if (type=="plugin")
|
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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ public:
|
|||||||
void parse_json(std::string path);
|
void parse_json(std::string path);
|
||||||
private:
|
private:
|
||||||
static const options_entry s_option_entries[];
|
static const options_entry s_option_entries[];
|
||||||
|
std::vector<std::string> m_descriptions;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* __PLUGIN_OPTS_H__ */
|
#endif /* __PLUGIN_OPTS_H__ */
|
||||||
|
@ -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
|
std::string helpers
|
||||||
-------------------------------------------------*/
|
-------------------------------------------------*/
|
||||||
|
@ -49,14 +49,6 @@ int core_strnicmp(const char *s1, const char *s2, size_t n);
|
|||||||
#define strncasecmp MUST_USE_CORE_STRNICMP_INSTEAD
|
#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) */
|
/* additional string compare helper (up to 16 characters at the moment) */
|
||||||
int core_strwildcmp(const char *sp1, const char *sp2);
|
int core_strwildcmp(const char *sp1, const char *sp2);
|
||||||
bool core_iswildstr(const char *sp);
|
bool core_iswildstr(const char *sp);
|
||||||
|
@ -354,9 +354,9 @@ void osd_common_t::register_options()
|
|||||||
update_option(OSDOPTION_VIDEO, m_video_names);
|
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("");
|
std::string new_option_value("");
|
||||||
for (unsigned int index = 0; index < values.size(); index++)
|
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);
|
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)
|
void osd_common_t::video_options_add(const char *name, void *type)
|
||||||
{
|
{
|
||||||
//m_video_options.add(name, type, false);
|
//m_video_options.add(name, type, false);
|
||||||
m_video_names.push_back(core_strdup(name));
|
m_video_names.push_back(name);
|
||||||
}
|
}
|
||||||
|
@ -265,7 +265,7 @@ private:
|
|||||||
osd_module_manager m_mod_man;
|
osd_module_manager m_mod_man;
|
||||||
font_module *m_font_module;
|
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
|
// FIXME: should be elsewhere
|
||||||
osd_module *select_module_options(const core_options &opts, const std::string &opt_name)
|
osd_module *select_module_options(const core_options &opts, const std::string &opt_name)
|
||||||
{
|
{
|
||||||
@ -301,6 +301,7 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<const char *> m_video_names;
|
std::vector<const char *> m_video_names;
|
||||||
|
std::unordered_map<std::string, std::string> m_option_descs;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user