diff options
| author | Peter Maydell <peter.maydell@linaro.org> | 2015-12-17 11:50:46 +0000 |
|---|---|---|
| committer | Peter Maydell <peter.maydell@linaro.org> | 2015-12-17 11:50:46 +0000 |
| commit | c1a5f950cdeeaea6a835b2b33f040a0e62c18662 (patch) | |
| tree | 1ed3aec2cd6480d626b30082ff3230c2c117014e /include/qapi/qmp/qobject.h | |
| parent | fc77eb20d78e303ef11482288e185d856431f02f (diff) | |
| parent | bac5429ccb4f41d421ec641b11f1852c8420fdb7 (diff) | |
| download | focaccia-qemu-c1a5f950cdeeaea6a835b2b33f040a0e62c18662.tar.gz focaccia-qemu-c1a5f950cdeeaea6a835b2b33f040a0e62c18662.zip | |
Merge remote-tracking branch 'remotes/armbru/tags/pull-qapi-2015-12-17' into staging
QAPI patches for 2015-12-17 # gpg: Signature made Thu 17 Dec 2015 07:33:41 GMT using RSA key ID EB918653 # gpg: Good signature from "Markus Armbruster <armbru@redhat.com>" # gpg: aka "Markus Armbruster <armbru@pond.sub.org>" * remotes/armbru/tags/pull-qapi-2015-12-17: (40 commits) qapi: Detect base class loops qapi: Move duplicate collision checks to schema check() qapi: Enforce (or whitelist) case conventions on qapi members qapi: Track enum values by QAPISchemaMember, not string qapi: Prepare new QAPISchemaMember base class qapi: Shorter visits of optional fields qapi: Simplify visits of optional fields qapi: Fix alternates that accept 'number' but not 'int' qapi: Inline _make_implicit_tag() qapi-types: Drop unnedeed ._fwdefn qapi: Simplify visiting of alternate types qapi: Convert QType into QAPI built-in enum type qobject: Rename qtype_code to QType qobject: Simplify QObject qapi: Change munging of CamelCase enum values qapi: Add alias for ErrorClass cpu: Convert CpuInfo into flat union qapi: Remove obsolete tests for MAX collision qapi: Don't let implicit enum MAX member collide qapi: Tighten the regex on valid names ... Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'include/qapi/qmp/qobject.h')
| -rw-r--r-- | include/qapi/qmp/qobject.h | 50 |
1 files changed, 19 insertions, 31 deletions
diff --git a/include/qapi/qmp/qobject.h b/include/qapi/qmp/qobject.h index 4b96ed5837..74459ae14b 100644 --- a/include/qapi/qmp/qobject.h +++ b/include/qapi/qmp/qobject.h @@ -34,30 +34,12 @@ #include <stddef.h> #include <assert.h> +#include "qapi-types.h" -typedef enum { - QTYPE_NONE, /* sentinel value, no QObject has this type code */ - QTYPE_QNULL, - QTYPE_QINT, - QTYPE_QSTRING, - QTYPE_QDICT, - QTYPE_QLIST, - QTYPE_QFLOAT, - QTYPE_QBOOL, - QTYPE_MAX, -} qtype_code; - -struct QObject; - -typedef struct QType { - qtype_code code; - void (*destroy)(struct QObject *); -} QType; - -typedef struct QObject { - const QType *type; +struct QObject { + QType type; size_t refcnt; -} QObject; +}; /* Get the 'base' part of an object */ #define QOBJECT(obj) (&(obj)->base) @@ -71,9 +53,12 @@ typedef struct QObject { qobject_decref(obj ? QOBJECT(obj) : NULL) /* Initialize an object to default values */ -#define QOBJECT_INIT(obj, qtype_type) \ - obj->base.refcnt = 1; \ - obj->base.type = qtype_type +static inline void qobject_init(QObject *obj, QType type) +{ + assert(QTYPE_NONE < type && type < QTYPE__MAX); + obj->refcnt = 1; + obj->type = type; +} /** * qobject_incref(): Increment QObject's reference count @@ -85,6 +70,11 @@ static inline void qobject_incref(QObject *obj) } /** + * qobject_destroy(): Free resources used by the object + */ +void qobject_destroy(QObject *obj); + +/** * qobject_decref(): Decrement QObject's reference count, deallocate * when it reaches zero */ @@ -92,19 +82,17 @@ static inline void qobject_decref(QObject *obj) { assert(!obj || obj->refcnt); if (obj && --obj->refcnt == 0) { - assert(obj->type != NULL); - assert(obj->type->destroy != NULL); - obj->type->destroy(obj); + qobject_destroy(obj); } } /** * qobject_type(): Return the QObject's type */ -static inline qtype_code qobject_type(const QObject *obj) +static inline QType qobject_type(const QObject *obj) { - assert(obj->type != NULL); - return obj->type->code; + assert(QTYPE_NONE < obj->type && obj->type < QTYPE__MAX); + return obj->type; } extern QObject qnull_; |