diff options
Diffstat (limited to 'qobject')
-rw-r--r-- | qobject/json-parser.c | 10 | ||||
-rw-r--r-- | qobject/qdict.c | 49 | ||||
-rw-r--r-- | qobject/qjson.c | 2 | ||||
-rw-r--r-- | qobject/qlist.c | 4 | ||||
-rw-r--r-- | qobject/qobject.c | 21 |
5 files changed, 42 insertions, 44 deletions
diff --git a/qobject/json-parser.c b/qobject/json-parser.c index 769b960c9f..a5aa790d62 100644 --- a/qobject/json-parser.c +++ b/qobject/json-parser.c @@ -222,7 +222,7 @@ static QString *qstring_from_escaped_str(JSONParserContext *ctxt, return str; out: - QDECREF(str); + qobject_unref(str); return NULL; } @@ -311,12 +311,12 @@ static int parse_pair(JSONParserContext *ctxt, QDict *dict, va_list *ap) qdict_put_obj(dict, qstring_get_str(key), value); - QDECREF(key); + qobject_unref(key); return 0; out: - QDECREF(key); + qobject_unref(key); return -1; } @@ -371,7 +371,7 @@ static QObject *parse_object(JSONParserContext *ctxt, va_list *ap) return QOBJECT(dict); out: - QDECREF(dict); + qobject_unref(dict); return NULL; } @@ -435,7 +435,7 @@ static QObject *parse_array(JSONParserContext *ctxt, va_list *ap) return QOBJECT(list); out: - QDECREF(list); + qobject_unref(list); return NULL; } diff --git a/qobject/qdict.c b/qobject/qdict.c index d1997a0d8a..22800eeceb 100644 --- a/qobject/qdict.c +++ b/qobject/qdict.c @@ -123,7 +123,7 @@ void qdict_put_obj(QDict *qdict, const char *key, QObject *value) entry = qdict_find(qdict, key, bucket); if (entry) { /* replace key's value */ - qobject_decref(entry->value); + qobject_unref(entry->value); entry->value = value; } else { /* allocate a new entry */ @@ -373,8 +373,7 @@ QDict *qdict_clone_shallow(const QDict *src) for (i = 0; i < QDICT_BUCKET_MAX; i++) { QLIST_FOREACH(entry, &src->table[i], next) { - qobject_incref(entry->value); - qdict_put_obj(dest, entry->key, entry->value); + qdict_put_obj(dest, entry->key, qobject_ref(entry->value)); } } @@ -390,7 +389,7 @@ static void qentry_destroy(QDictEntry *e) assert(e->key != NULL); assert(e->value != NULL); - qobject_decref(e->value); + qobject_unref(e->value); g_free(e->key); g_free(e); } @@ -480,8 +479,7 @@ void qdict_copy_default(QDict *dst, QDict *src, const char *key) val = qdict_get(src, key); if (val) { - qobject_incref(val); - qdict_put_obj(dst, key, val); + qdict_put_obj(dst, key, qobject_ref(val)); } } @@ -526,8 +524,7 @@ static void qdict_flatten_qlist(QList *qlist, QDict *target, const char *prefix) qdict_flatten_qlist(qobject_to(QList, value), target, new_key); } else { /* All other types are moved to the target unchanged. */ - qobject_incref(value); - qdict_put_obj(target, new_key, value); + qdict_put_obj(target, new_key, qobject_ref(value)); } g_free(new_key); @@ -566,8 +563,7 @@ static void qdict_flatten_qdict(QDict *qdict, QDict *target, const char *prefix) delete = true; } else if (prefix) { /* All other objects are moved to the target unchanged. */ - qobject_incref(value); - qdict_put_obj(target, new_key, value); + qdict_put_obj(target, new_key, qobject_ref(value)); delete = true; } @@ -610,8 +606,7 @@ void qdict_extract_subqdict(QDict *src, QDict **dst, const char *start) while (entry != NULL) { next = qdict_next(src, entry); if (strstart(entry->key, start, &p)) { - qobject_incref(entry->value); - qdict_put_obj(*dst, p, entry->value); + qdict_put_obj(*dst, p, qobject_ref(entry->value)); qdict_del(src, entry->key); } entry = next; @@ -684,7 +679,7 @@ void qdict_array_split(QDict *src, QList **dst) qdict_extract_subqdict(src, &subqdict, prefix); assert(qdict_size(subqdict) > 0); } else { - qobject_incref(subqobj); + qobject_ref(subqobj); qdict_del(src, indexstr); } @@ -894,16 +889,14 @@ QObject *qdict_crumple(const QDict *src, Error **errp) qdict_put_obj(two_level, prefix, QOBJECT(child_dict)); } - qobject_incref(ent->value); - qdict_put_obj(child_dict, suffix, ent->value); + qdict_put_obj(child_dict, suffix, qobject_ref(ent->value)); } else { if (child) { error_setg(errp, "Key %s prefix is already set as a dict", prefix); goto error; } - qobject_incref(ent->value); - qdict_put_obj(two_level, prefix, ent->value); + qdict_put_obj(two_level, prefix, qobject_ref(ent->value)); } g_free(prefix); @@ -924,11 +917,10 @@ QObject *qdict_crumple(const QDict *src, Error **errp) qdict_put_obj(multi_level, ent->key, child); } else { - qobject_incref(ent->value); - qdict_put_obj(multi_level, ent->key, ent->value); + qdict_put_obj(multi_level, ent->key, qobject_ref(ent->value)); } } - QDECREF(two_level); + qobject_unref(two_level); two_level = NULL; /* Step 3: detect if we need to turn our dict into list */ @@ -951,10 +943,9 @@ QObject *qdict_crumple(const QDict *src, Error **errp) goto error; } - qobject_incref(child); - qlist_append_obj(qobject_to(QList, dst), child); + qlist_append_obj(qobject_to(QList, dst), qobject_ref(child)); } - QDECREF(multi_level); + qobject_unref(multi_level); multi_level = NULL; } else { dst = QOBJECT(multi_level); @@ -964,9 +955,9 @@ QObject *qdict_crumple(const QDict *src, Error **errp) error: g_free(prefix); - QDECREF(multi_level); - QDECREF(two_level); - qobject_decref(dst); + qobject_unref(multi_level); + qobject_unref(two_level); + qobject_unref(dst); return NULL; } @@ -1055,8 +1046,7 @@ void qdict_join(QDict *dest, QDict *src, bool overwrite) next = qdict_next(src, entry); if (overwrite || !qdict_haskey(dest, entry->key)) { - qobject_incref(entry->value); - qdict_put_obj(dest, entry->key, entry->value); + qdict_put_obj(dest, entry->key, qobject_ref(entry->value)); qdict_del(src, entry->key); } @@ -1088,8 +1078,7 @@ bool qdict_rename_keys(QDict *qdict, const QDictRenames *renames, Error **errp) } qobj = qdict_get(qdict, renames->from); - qobject_incref(qobj); - qdict_put_obj(qdict, renames->to, qobj); + qdict_put_obj(qdict, renames->to, qobject_ref(qobj)); qdict_del(qdict, renames->from); } diff --git a/qobject/qjson.c b/qobject/qjson.c index 655d38adf1..9816a65c7d 100644 --- a/qobject/qjson.c +++ b/qobject/qjson.c @@ -104,7 +104,7 @@ static void to_json_dict_iter(const char *key, QObject *obj, void *opaque) qkey = qstring_from_str(key); to_json(QOBJECT(qkey), s->str, s->pretty, s->indent); - QDECREF(qkey); + qobject_unref(qkey); qstring_append(s->str, ": "); to_json(obj, s->str, s->pretty, s->indent); diff --git a/qobject/qlist.c b/qobject/qlist.c index 954fe98375..37c1c167f1 100644 --- a/qobject/qlist.c +++ b/qobject/qlist.c @@ -39,7 +39,7 @@ static void qlist_copy_elem(QObject *obj, void *opaque) { QList *dst = opaque; - qobject_incref(obj); + qobject_ref(obj); qlist_append_obj(dst, obj); } @@ -196,7 +196,7 @@ void qlist_destroy_obj(QObject *obj) QTAILQ_FOREACH_SAFE(entry, &qlist->head, next, next_entry) { QTAILQ_REMOVE(&qlist->head, entry, next); - qobject_decref(entry->value); + qobject_unref(entry->value); g_free(entry); } diff --git a/qobject/qobject.c b/qobject/qobject.c index 23600aa1c1..cf4b7e229e 100644 --- a/qobject/qobject.c +++ b/qobject/qobject.c @@ -16,6 +16,15 @@ #include "qapi/qmp/qlist.h" #include "qapi/qmp/qstring.h" +QEMU_BUILD_BUG_MSG( + offsetof(QNull, base) != 0 || + offsetof(QNum, base) != 0 || + offsetof(QString, base) != 0 || + offsetof(QDict, base) != 0 || + offsetof(QList, base) != 0 || + offsetof(QBool, base) != 0, + "base qobject must be at offset 0"); + static void (*qdestroy[QTYPE__MAX])(QObject *) = { [QTYPE_NONE] = NULL, /* No such object exists */ [QTYPE_QNULL] = NULL, /* qnull_ is indestructible */ @@ -28,9 +37,9 @@ static void (*qdestroy[QTYPE__MAX])(QObject *) = { void qobject_destroy(QObject *obj) { - assert(!obj->refcnt); - assert(QTYPE_QNULL < obj->type && obj->type < QTYPE__MAX); - qdestroy[obj->type](obj); + assert(!obj->base.refcnt); + assert(QTYPE_QNULL < obj->base.type && obj->base.type < QTYPE__MAX); + qdestroy[obj->base.type](obj); } @@ -53,11 +62,11 @@ bool qobject_is_equal(const QObject *x, const QObject *y) return true; } - if (!x || !y || x->type != y->type) { + if (!x || !y || x->base.type != y->base.type) { return false; } - assert(QTYPE_NONE < x->type && x->type < QTYPE__MAX); + assert(QTYPE_NONE < x->base.type && x->base.type < QTYPE__MAX); - return qis_equal[x->type](x, y); + return qis_equal[x->base.type](x, y); } |