QAPI patches for 2018-05-04
-----BEGIN PGP SIGNATURE----- iQIcBAABAgAGBQJa7BLUAAoJEDhwtADrkYZTumIQAJC6wXmN+wBYc2MoR2Y8SQgY +gTM9J6R6H50ijb7RkkERLTgys7IxCDD/jy2p0yX/Re3ReXbYwzYQXmSFpF1KWGe SXB84uDtwSILbvR5iS0TBdQSyO+u5DRboukuLfTEZHjYQUP+guT1we3YwqWGzIKp o5kV/7Nq0vPWO5Sbs4FWB0t9hWzWV3Kef9b4gRPn05sWPaq2/sU6A3xai+ty6qS7 PCm7VwT4z5SACdR4LRiL45h3HdThgr/alJJ6lUr2kaNCBiDBvM4h6d7W+lI/Vi3Y rG+wqyPQFyWLXf0uuI3AmSScVUzfYv9C4TcBTJkFnebrFcybPsGwEJLGtaIgFnBU 1Mcz/TCl1bB4fDvhwV2qexxlXryOWXKn+ygdu9sBSY/QSA+NEqbJQo6cCDqMQ9Qy 6zqrGxUrM/peVLvhfle4cIbyPslGRGn2s95oQzCJi8TlZxBj8lgW1x1kr7OhSlf4 rNteSYAHDNSiNVL1PcW3vOS7ndTA6O0vHAtGa+0vbQzAf+RUfFG0sfggG6350O8e 97Hp4LKT3VpGEuwyQEw6wk3zODNfAgtkkwjQHTnQYHriKB/fcVfY3g7gpYp4zMLF GJ3h5KZj71JNoFoxVJniAgkWY8+IP11ggXMyYWSMxMZ3M81EqQ/rbvOvGxn1wjd8 kHbpUEMmGBHF1VmKs7e1 =Kukn -----END PGP SIGNATURE----- Merge remote-tracking branch 'remotes/armbru/tags/pull-qapi-2018-05-04' into staging QAPI patches for 2018-05-04 # gpg: Signature made Fri 04 May 2018 08:59:16 BST # gpg: using RSA key 3870B400EB918653 # gpg: Good signature from "Markus Armbruster <armbru@redhat.com>" # gpg: aka "Markus Armbruster <armbru@pond.sub.org>" # Primary key fingerprint: 354B C8B3 D7EB 2A6B 6867 4E5F 3870 B400 EB91 8653 * remotes/armbru/tags/pull-qapi-2018-05-04: qapi: deprecate CpuInfoFast.arch qapi: discriminate CpuInfoFast on SysEmuTarget, not CpuInfoArch qapi: change the type of TargetInfo.arch from string to enum SysEmuTarget qapi: add SysEmuTarget to "common.json" qapi: fill in CpuInfoFast.arch in query-cpus-fast qobject: Modify qobject_ref() to return obj qobject: Replace qobject_incref/QINCREF qobject_decref/QDECREF qobject: use a QObjectBase_ struct qobject: Ensure base is at offset 0 qobject: Use qobject_to() instead of type cast Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
commit
7c867af89a
106 changed files with 816 additions and 703 deletions
|
|
@ -17,7 +17,7 @@
|
|||
#include "qapi/qmp/qobject.h"
|
||||
|
||||
struct QBool {
|
||||
QObject base;
|
||||
struct QObjectBase_ base;
|
||||
bool value;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ typedef struct QDictEntry {
|
|||
} QDictEntry;
|
||||
|
||||
struct QDict {
|
||||
QObject base;
|
||||
struct QObjectBase_ base;
|
||||
size_t size;
|
||||
QLIST_HEAD(,QDictEntry) table[QDICT_BUCKET_MAX];
|
||||
};
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ typedef struct QListEntry {
|
|||
} QListEntry;
|
||||
|
||||
struct QList {
|
||||
QObject base;
|
||||
struct QObjectBase_ base;
|
||||
QTAILQ_HEAD(,QListEntry) head;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -16,15 +16,14 @@
|
|||
#include "qapi/qmp/qobject.h"
|
||||
|
||||
struct QNull {
|
||||
QObject base;
|
||||
struct QObjectBase_ base;
|
||||
};
|
||||
|
||||
extern QNull qnull_;
|
||||
|
||||
static inline QNull *qnull(void)
|
||||
{
|
||||
QINCREF(&qnull_);
|
||||
return &qnull_;
|
||||
return qobject_ref(&qnull_);
|
||||
}
|
||||
|
||||
bool qnull_is_equal(const QObject *x, const QObject *y);
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ typedef enum {
|
|||
* convert under the hood.
|
||||
*/
|
||||
struct QNum {
|
||||
QObject base;
|
||||
struct QObjectBase_ base;
|
||||
QNumKind kind;
|
||||
union {
|
||||
int64_t i64;
|
||||
|
|
|
|||
|
|
@ -15,17 +15,17 @@
|
|||
* ------------------------------------
|
||||
*
|
||||
* - Returning references: A function that returns an object may
|
||||
* return it as either a weak or a strong reference. If the reference
|
||||
* is strong, you are responsible for calling QDECREF() on the reference
|
||||
* when you are done.
|
||||
* return it as either a weak or a strong reference. If the
|
||||
* reference is strong, you are responsible for calling
|
||||
* qobject_unref() on the reference when you are done.
|
||||
*
|
||||
* If the reference is weak, the owner of the reference may free it at
|
||||
* any time in the future. Before storing the reference anywhere, you
|
||||
* should call QINCREF() to make the reference strong.
|
||||
* should call qobject_ref() to make the reference strong.
|
||||
*
|
||||
* - Transferring ownership: when you transfer ownership of a reference
|
||||
* by calling a function, you are no longer responsible for calling
|
||||
* QDECREF() when the reference is no longer needed. In other words,
|
||||
* qobject_unref() when the reference is no longer needed. In other words,
|
||||
* when the function returns you must behave as if the reference to the
|
||||
* passed object was weak.
|
||||
*/
|
||||
|
|
@ -34,21 +34,21 @@
|
|||
|
||||
#include "qapi/qapi-builtin-types.h"
|
||||
|
||||
struct QObject {
|
||||
/* Not for use outside include/qapi/qmp/ */
|
||||
struct QObjectBase_ {
|
||||
QType type;
|
||||
size_t refcnt;
|
||||
};
|
||||
|
||||
/* Get the 'base' part of an object */
|
||||
#define QOBJECT(obj) (&(obj)->base)
|
||||
/* this struct must have no other members than base */
|
||||
struct QObject {
|
||||
struct QObjectBase_ base;
|
||||
};
|
||||
|
||||
/* High-level interface for qobject_incref() */
|
||||
#define QINCREF(obj) \
|
||||
qobject_incref(QOBJECT(obj))
|
||||
|
||||
/* High-level interface for qobject_decref() */
|
||||
#define QDECREF(obj) \
|
||||
qobject_decref(obj ? QOBJECT(obj) : NULL)
|
||||
#define QOBJECT(obj) ({ \
|
||||
typeof(obj) _obj = (obj); \
|
||||
_obj ? container_of(&(_obj)->base, QObject, base) : NULL; \
|
||||
})
|
||||
|
||||
/* Required for qobject_to() */
|
||||
#define QTYPE_CAST_TO_QNull QTYPE_QNULL
|
||||
|
|
@ -61,25 +61,22 @@ struct QObject {
|
|||
QEMU_BUILD_BUG_MSG(QTYPE__MAX != 7,
|
||||
"The QTYPE_CAST_TO_* list needs to be extended");
|
||||
|
||||
#define qobject_to(type, obj) ({ \
|
||||
QObject *_tmp = qobject_check_type(obj, glue(QTYPE_CAST_TO_, type)); \
|
||||
_tmp ? container_of(_tmp, type, base) : (type *)NULL; })
|
||||
#define qobject_to(type, obj) \
|
||||
((type *)qobject_check_type(obj, glue(QTYPE_CAST_TO_, type)))
|
||||
|
||||
/* Initialize an object to default values */
|
||||
static inline void qobject_init(QObject *obj, QType type)
|
||||
{
|
||||
assert(QTYPE_NONE < type && type < QTYPE__MAX);
|
||||
obj->refcnt = 1;
|
||||
obj->type = type;
|
||||
obj->base.refcnt = 1;
|
||||
obj->base.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* qobject_incref(): Increment QObject's reference count
|
||||
*/
|
||||
static inline void qobject_incref(QObject *obj)
|
||||
static inline void qobject_ref_impl(QObject *obj)
|
||||
{
|
||||
if (obj)
|
||||
obj->refcnt++;
|
||||
if (obj) {
|
||||
obj->base.refcnt++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -96,25 +93,39 @@ bool qobject_is_equal(const QObject *x, const QObject *y);
|
|||
*/
|
||||
void qobject_destroy(QObject *obj);
|
||||
|
||||
/**
|
||||
* qobject_decref(): Decrement QObject's reference count, deallocate
|
||||
* when it reaches zero
|
||||
*/
|
||||
static inline void qobject_decref(QObject *obj)
|
||||
static inline void qobject_unref_impl(QObject *obj)
|
||||
{
|
||||
assert(!obj || obj->refcnt);
|
||||
if (obj && --obj->refcnt == 0) {
|
||||
assert(!obj || obj->base.refcnt);
|
||||
if (obj && --obj->base.refcnt == 0) {
|
||||
qobject_destroy(obj);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* qobject_ref(): Increment QObject's reference count
|
||||
*
|
||||
* Returns: the same @obj. The type of @obj will be propagated to the
|
||||
* return type.
|
||||
*/
|
||||
#define qobject_ref(obj) ({ \
|
||||
typeof(obj) _o = (obj); \
|
||||
qobject_ref_impl(QOBJECT(_o)); \
|
||||
_o; \
|
||||
})
|
||||
|
||||
/**
|
||||
* qobject_unref(): Decrement QObject's reference count, deallocate
|
||||
* when it reaches zero
|
||||
*/
|
||||
#define qobject_unref(obj) qobject_unref_impl(QOBJECT(obj))
|
||||
|
||||
/**
|
||||
* qobject_type(): Return the QObject's type
|
||||
*/
|
||||
static inline QType qobject_type(const QObject *obj)
|
||||
{
|
||||
assert(QTYPE_NONE < obj->type && obj->type < QTYPE__MAX);
|
||||
return obj->type;
|
||||
assert(QTYPE_NONE < obj->base.type && obj->base.type < QTYPE__MAX);
|
||||
return obj->base.type;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
#include "qapi/qmp/qobject.h"
|
||||
|
||||
struct QString {
|
||||
QObject base;
|
||||
struct QObjectBase_ base;
|
||||
char *string;
|
||||
size_t length;
|
||||
size_t capacity;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue