mirror of
https://github.com/yuzu-emu/unicorn.git
synced 2025-01-08 22:25:27 +00:00
machine: Ensure all TYPE_MACHINE subclasses have the right suffix
Now that all non-abstract TYPE_MACHINE subclasses have the -machine suffix, add an assert to ensure this will be always true. Backports commit dcb3d601115eed77aef543fe3a920adc17544e06 from qemu
This commit is contained in:
parent
1b2aee0a86
commit
0261df973b
|
@ -94,6 +94,66 @@ gboolean g_str_equal(gconstpointer v1, gconstpointer v2)
|
|||
return strcmp((const char*)v1, (const char*)v2) == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_str_has_suffix:
|
||||
* @str: a nul-terminated string.
|
||||
* @suffix: the nul-terminated suffix to look for.
|
||||
*
|
||||
* Looks whether the string @str ends with @suffix.
|
||||
*
|
||||
* Return value: %TRUE if @str end with @suffix, %FALSE otherwise.
|
||||
*
|
||||
* Since: 2.2
|
||||
**/
|
||||
gboolean
|
||||
g_str_has_suffix(const gchar *str, const gchar *suffix)
|
||||
{
|
||||
int str_len;
|
||||
int suffix_len;
|
||||
|
||||
if (str == NULL || suffix == NULL) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
str_len = strlen (str);
|
||||
suffix_len = strlen (suffix);
|
||||
|
||||
if (str_len < suffix_len)
|
||||
return FALSE;
|
||||
|
||||
return strcmp (str + str_len - suffix_len, suffix) == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_str_has_prefix:
|
||||
* @str: a nul-terminated string.
|
||||
* @prefix: the nul-terminated prefix to look for.
|
||||
*
|
||||
* Looks whether the string @str begins with @prefix.
|
||||
*
|
||||
* Return value: %TRUE if @str begins with @prefix, %FALSE otherwise.
|
||||
*
|
||||
* Since: 2.2
|
||||
**/
|
||||
gboolean
|
||||
g_str_has_prefix(const gchar *str, const gchar *prefix)
|
||||
{
|
||||
int str_len;
|
||||
int prefix_len;
|
||||
|
||||
if (str == NULL || prefix == NULL) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
str_len = strlen (str);
|
||||
prefix_len = strlen (prefix);
|
||||
|
||||
if (str_len < prefix_len)
|
||||
return FALSE;
|
||||
|
||||
return strncmp (str, prefix, prefix_len) == 0;
|
||||
}
|
||||
|
||||
// g_int_hash() is lifted from glib-2.28.0/glib/gutils.c
|
||||
/**
|
||||
* g_int_hash:
|
||||
|
|
|
@ -15,6 +15,14 @@
|
|||
#include "qapi/error.h"
|
||||
#include "qemu/cutils.h"
|
||||
|
||||
static void machine_class_base_init(ObjectClass *oc, void *data)
|
||||
{
|
||||
if (!object_class_is_abstract(oc)) {
|
||||
const char *cname = object_class_get_name(oc);
|
||||
assert(g_str_has_suffix(cname, TYPE_MACHINE_SUFFIX));
|
||||
}
|
||||
}
|
||||
|
||||
static void machine_initfn(struct uc_struct *uc, Object *obj, void *opaque)
|
||||
{
|
||||
}
|
||||
|
@ -38,7 +46,7 @@ static const TypeInfo machine_info = {
|
|||
NULL,
|
||||
|
||||
NULL,
|
||||
NULL,
|
||||
machine_class_base_init,
|
||||
NULL,
|
||||
|
||||
true,
|
||||
|
|
|
@ -59,8 +59,10 @@ typedef void (*GDestroyNotify)(gpointer data);
|
|||
|
||||
guint g_str_hash(gconstpointer v);
|
||||
gboolean g_str_equal(gconstpointer v1, gconstpointer v2);
|
||||
guint g_int_hash(gconstpointer v);
|
||||
gboolean g_str_has_suffix(const gchar *str, const gchar *prefix);
|
||||
gboolean g_str_has_prefix(const gchar *str, const gchar *prefix);
|
||||
|
||||
guint g_int_hash(gconstpointer v);
|
||||
gboolean g_int_equal(gconstpointer v1, gconstpointer v2);
|
||||
|
||||
typedef struct _GList {
|
||||
|
|
Loading…
Reference in a new issue