From: Anthony Liguori <anthony@codemonkey.ws>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: peter.maydell@linaro.org, aliguori@us.ibm.com,
qemu-devel@nongnu.org,
"Peter A. G. Crosthwaite" <peter.crosthwaite@petalogix.com>,
paul@codesourcery.com, edgar.iglesias@gmail.com,
afaerber@suse.de, john.williams@petalogix.com, avi@redhat.com
Subject: Re: [Qemu-devel] [RFC v0 6/8] xilinx dont cast to interface types with links
Date: Wed, 13 Jun 2012 08:55:23 -0500 [thread overview]
Message-ID: <4FD89BCB.7090407@codemonkey.ws> (raw)
In-Reply-To: <4FD86E40.1000100@redhat.com>
On 06/13/2012 05:41 AM, Paolo Bonzini wrote:
> Il 13/06/2012 11:38, Peter A. G. Crosthwaite ha scritto:
>> Something is broken with casting to an interface type then setting a link. Cast
>> these two to object for linking instead and it all works.
>
> I don't have a board image but I don't see anything visibly bad without this patch.
>
> However, something that _is_ bad indeed happens; we try to ref/unref an interface
> object. This patch fixes it while keeping things efficient (and in fact fixes one
> TODO). Can add a link to an image on http://wiki.qemu.org/Testing and/or test it?
>
> Anthony, is this above your disgust level?
Isn't there a patch floating around to make Object a proper TypeInfo? In which
case, couldn't we make Interface not inherit from Object and change the OBJECT()
cast macro to tell the difference?
Regards,
Anthony Liguori
>
> Paolo
>
>
> ------------------------ 8< -----------------------
>
> diff --git a/qom/object.c b/qom/object.c
> index c3a7a47..bd60838 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -63,7 +63,7 @@ struct TypeImpl
> InterfaceImpl interfaces[MAX_INTERFACES];
> };
>
> -#define INTERFACE(obj) INTERFACE_CHECK(obj, TYPE_INTERFACE)
> +#define INTERFACE(obj) ((Interface *)(obj))
>
> static Type type_interface;
>
> @@ -239,13 +239,21 @@ static void type_initialize(TypeImpl *ti)
> }
> }
>
> +#define INTERFACE_MAGIC ((GSList *) (intptr_t)0xBAD0BAD)
> +
> +static inline bool object_is_interface(Object *obj) {
> + return obj->interfaces == INTERFACE_MAGIC;
> +}
> +
> static void object_interface_init(Object *obj, InterfaceImpl *iface)
> {
> TypeImpl *ti = iface->type;
> Interface *iface_obj;
>
> + assert(!object_is_interface(obj));
> iface_obj = INTERFACE(object_new(ti->name));
> iface_obj->iface_obj = obj;
> + iface_obj->iface_parent.interfaces = INTERFACE_MAGIC;
>
> obj->interfaces = g_slist_prepend(obj->interfaces, iface_obj);
> }
> @@ -332,10 +340,12 @@ static void object_deinit(Object *obj, TypeImpl *type)
> type->instance_finalize(obj);
> }
>
> - while (obj->interfaces) {
> - Interface *iface_obj = obj->interfaces->data;
> - obj->interfaces = g_slist_delete_link(obj->interfaces, obj->interfaces);
> - object_delete(OBJECT(iface_obj));
> + if (!object_is_interface(obj)) {
> + while (obj->interfaces) {
> + Interface *iface_obj = obj->interfaces->data;
> + obj->interfaces = g_slist_delete_link(obj->interfaces, obj->interfaces);
> + object_delete(OBJECT(iface_obj));
> + }
> }
>
> if (type_has_parent(type)) {
> @@ -410,6 +420,13 @@ Object *object_dynamic_cast(Object *obj, const char *typename)
> TypeImpl *target_type = type_get_by_name(typename);
> GSList *i;
>
> + /* Check if obj is an interface and its containing object is a direct
> + * ancestor of typename. object_is_interface is a very fast test.
> + */
> + if (object_is_interface(obj)) {
> + obj = INTERFACE(obj)->iface_obj;
> + }
> +
> /* Check if typename is a direct ancestor. Special-case TYPE_OBJECT,
> * we want to go back from interfaces to the parent.
> */
> @@ -417,24 +434,6 @@ Object *object_dynamic_cast(Object *obj, const char *typename)
> return obj;
> }
>
> - /* Check if obj is an interface and its containing object is a direct
> - * ancestor of typename. In principle we could do this test at the very
> - * beginning of object_dynamic_cast, avoiding a second call to
> - * object_is_type. However, casting between interfaces is relatively
> - * rare, and object_is_type(obj, type_interface) would fail almost always.
> - *
> - * Perhaps we could add a magic value to the object header for increased
> - * (run-time) type safety and to speed up tests like this one. If we ever
> - * do that we can revisit the order here.
> - */
> - if (object_is_type(obj, type_interface)) {
> - assert(!obj->interfaces);
> - obj = INTERFACE(obj)->iface_obj;
> - if (object_is_type(obj, target_type)) {
> - return obj;
> - }
> - }
> -
> if (!target_type) {
> return obj;
> }
> @@ -597,11 +596,19 @@ GSList *object_class_get_list(const char *implements_type,
>
> void object_ref(Object *obj)
> {
> + if (object_is_interface(obj)) {
> + obj = INTERFACE(obj)->iface_obj;
> + }
> +
> obj->ref++;
> }
>
> void object_unref(Object *obj)
> {
> + if (object_is_interface(obj)) {
> + obj = INTERFACE(obj)->iface_obj;
> + }
> +
> g_assert(obj->ref> 0);
> obj->ref--;
>
> @@ -979,7 +986,7 @@ gchar *object_get_canonical_path(Object *obj)
> Object *root = object_get_root();
> char *newpath = NULL, *path = NULL;
>
> - if (object_is_type(obj, type_interface)) {
> + if (object_is_interface(obj)) {
> obj = INTERFACE(obj)->iface_obj;
> }
>
>
> Paolo
>
>
next prev parent reply other threads:[~2012-06-13 13:55 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-13 9:38 [Qemu-devel] [RFC v0 0/8] QOMify AXI stream for Xilinx AXI ethernet/DMA Peter A. G. Crosthwaite
2012-06-13 9:38 ` [Qemu-devel] [RFC v0 1/8] qom: revamp interfaces Peter A. G. Crosthwaite
2012-06-13 9:38 ` [Qemu-devel] [RFC v0 2/8] xilinx: remove PROP_PTR properties Peter A. G. Crosthwaite
2012-06-13 9:38 ` [Qemu-devel] [RFC v0 3/8] xilinx_axidma: Added missing TypeInfo Peter A. G. Crosthwaite
2012-06-13 10:05 ` Paolo Bonzini
2012-06-13 9:38 ` [Qemu-devel] [RFC v0 4/8] object: create default canonical paths for orphans Peter A. G. Crosthwaite
2012-06-13 10:08 ` Paolo Bonzini
2012-06-13 9:38 ` [Qemu-devel] [RFC v0 5/8] object: make interfaces concrete Peter A. G. Crosthwaite
2012-06-13 10:03 ` Paolo Bonzini
2012-06-13 10:28 ` Andreas Färber
2012-06-13 10:42 ` Paolo Bonzini
2012-06-13 12:59 ` Andreas Färber
2012-06-13 13:02 ` Paolo Bonzini
2012-06-13 13:30 ` Anthony Liguori
2012-06-13 13:33 ` Paolo Bonzini
2012-06-13 13:36 ` Anthony Liguori
2012-06-13 13:38 ` Paolo Bonzini
2012-06-13 13:50 ` Anthony Liguori
2012-06-13 20:22 ` Edgar E. Iglesias
2012-06-13 9:38 ` [Qemu-devel] [RFC v0 6/8] xilinx dont cast to interface types with links Peter A. G. Crosthwaite
2012-06-13 10:41 ` Paolo Bonzini
2012-06-13 10:55 ` Avi Kivity
2012-06-13 10:59 ` Paolo Bonzini
2012-06-13 11:02 ` Avi Kivity
2012-06-13 11:05 ` Paolo Bonzini
2012-06-13 11:08 ` Avi Kivity
2012-06-13 13:55 ` Anthony Liguori [this message]
2012-06-13 9:38 ` [Qemu-devel] [RFC v0 7/8] petalogix_ml605_mmu: fixed qdev create for dma Peter A. G. Crosthwaite
2012-06-13 9:38 ` [Qemu-devel] [RFC v0 8/8] axidma: renamed interconnect to axi-stream Peter A. G. Crosthwaite
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4FD89BCB.7090407@codemonkey.ws \
--to=anthony@codemonkey.ws \
--cc=afaerber@suse.de \
--cc=aliguori@us.ibm.com \
--cc=avi@redhat.com \
--cc=edgar.iglesias@gmail.com \
--cc=john.williams@petalogix.com \
--cc=paul@codesourcery.com \
--cc=pbonzini@redhat.com \
--cc=peter.crosthwaite@petalogix.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).