All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Daniel P. Berrange" <berrange@redhat.com>
To: "Andreas Färber" <afaerber@suse.de>
Cc: Paolo Bonzini <pbonzini@redhat.com>, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v4 5/8] qom: add object_new_with_props / object_new_withpropv constructors
Date: Tue, 19 May 2015 16:55:29 +0100	[thread overview]
Message-ID: <20150519155528.GF8535@redhat.com> (raw)
In-Reply-To: <555B5C2E.5050903@suse.de>

On Tue, May 19, 2015 at 05:52:14PM +0200, Andreas Färber wrote:
> Am 13.05.2015 um 18:14 schrieb Daniel P. Berrange:
> > +Object *object_new_with_propv(const char *typename,
> > +                              Object *parent,
> > +                              const char *id,
> > +                              Error **errp,
> > +                              va_list vargs)
> > +{
> > +    Object *obj;
> > +    ObjectClass *klass;
> > +    Error *local_err = NULL;
> > +
> > +    klass = object_class_by_name(typename);
> > +    if (!klass) {
> > +        error_setg(errp, "invalid object type: %s", typename);
> > +        return NULL;
> > +    }
> > +
> > +    if (object_class_is_abstract(klass)) {
> > +        error_setg(errp, "object type '%s' is abstract", typename);
> > +        return NULL;
> > +    }
> > +    obj = object_new(typename);
> > +
> > +    if (object_set_propv(obj, &local_err, vargs) < 0) {
> > +        goto error;
> > +    }
> > +
> > +    object_property_add_child(parent, id, obj, &local_err);
> > +    if (local_err) {
> > +        goto error;
> > +    }
> > +
> > +    if (object_dynamic_cast(obj, TYPE_USER_CREATABLE)) {
> > +        user_creatable_complete(obj, &local_err);
> > +        if (local_err) {
> > +            object_unparent(obj);
> > +            goto error;
> > +        }
> > +    }
> > +
> > +    object_unref(OBJECT(obj));
> > +    return obj;
> 
> This looks fishy. Either we return obj and need to retain a ref for that
> (caller's responsibility to unref) or we unref it and return void.
> Or am I misreading the code?

Paolo told me on previous posting that object_property_add_child()
holds a reference on 'obj' for as long as it is registered in the
object hierarchy composition. So it sufficient to rely on that long
term reference, and let the caller dispose of the object by calling
object_unparent(obj) when finally done.

Regards,
Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|

  reply	other threads:[~2015-05-19 15:55 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-13 16:14 [Qemu-devel] [PATCH v4 0/8] qom: misc fixes & enhancements to support TLS work Daniel P. Berrange
2015-05-13 16:14 ` [Qemu-devel] [PATCH v4 1/8] backends: fix typename of 'policy' enum property in hostmem obj Daniel P. Berrange
2015-05-13 16:14 ` [Qemu-devel] [PATCH v4 2/8] doc: document user creatable object types in help text Daniel P. Berrange
2015-05-13 16:14 ` [Qemu-devel] [PATCH v4 3/8] vl: create (most) objects before creating chardev backends Daniel P. Berrange
2015-05-13 16:14 ` [Qemu-devel] [PATCH v4 4/8] qom: add helper method for getting user objects root Daniel P. Berrange
2015-05-19 13:30   ` Andreas Färber
2015-05-13 16:14 ` [Qemu-devel] [PATCH v4 5/8] qom: add object_new_with_props / object_new_withpropv constructors Daniel P. Berrange
2015-05-19 15:52   ` Andreas Färber
2015-05-19 15:55     ` Daniel P. Berrange [this message]
2015-05-19 16:08       ` Andreas Färber
2015-05-19 16:11       ` Paolo Bonzini
2015-05-20 14:44         ` Eduardo Habkost
2015-05-20 15:18           ` Daniel P. Berrange
2015-05-20 15:32             ` Andreas Färber
2015-05-20 16:06             ` Eduardo Habkost
2015-05-20 16:10               ` Daniel P. Berrange
2015-05-20 16:11               ` Andreas Färber
2015-05-20 16:22                 ` Eduardo Habkost
2015-05-20 16:24                   ` Andreas Färber
2015-05-20 16:44                     ` Eduardo Habkost
2015-05-13 16:14 ` [Qemu-devel] [PATCH v4 6/8] qom: make enum string tables const-correct Daniel P. Berrange
2015-05-13 16:14 ` [Qemu-devel] [PATCH v4 7/8] qom: add a object_property_add_enum helper method Daniel P. Berrange
2015-05-13 16:14 ` [Qemu-devel] [PATCH v4 8/8] qom: don't pass string table to object_get_enum method Daniel P. Berrange

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=20150519155528.GF8535@redhat.com \
    --to=berrange@redhat.com \
    --cc=afaerber@suse.de \
    --cc=pbonzini@redhat.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.