[libvirt] [libvirt-glib 1/6] Getters for GVirConfigDomainInterface attributes

Christophe Fergeau cfergeau at redhat.com
Wed Feb 29 13:49:51 UTC 2012


On Wed, Feb 29, 2012 at 03:44:20PM +0200, Zeeshan Ali (Khattak) wrote:
> On Wed, Feb 29, 2012 at 2:57 PM, Christophe Fergeau <cfergeau at redhat.com> wrote:
> > On Tue, Feb 28, 2012 at 08:25:02PM +0200, Zeeshan Ali (Khattak) wrote:
> >> From: "Zeeshan Ali (Khattak)" <zeeshanak at gnome.org>
> >>
> >> ---
> >>  libvirt-gconfig/libvirt-gconfig-domain-interface.c |   35 ++++++++++++++++++++
> >>  libvirt-gconfig/libvirt-gconfig-domain-interface.h |    4 ++
> >>  libvirt-gconfig/libvirt-gconfig.sym                |    4 ++
> >>  3 files changed, 43 insertions(+), 0 deletions(-)
> >>
> >> diff --git a/libvirt-gconfig/libvirt-gconfig-domain-interface.c b/libvirt-gconfig/libvirt-gconfig-domain-interface.c
> >> index 85cc194..61d35bd 100644
> >> --- a/libvirt-gconfig/libvirt-gconfig-domain-interface.c
> >> +++ b/libvirt-gconfig/libvirt-gconfig-domain-interface.c
> >> @@ -96,6 +96,41 @@ void gvir_config_domain_interface_set_model(GVirConfigDomainInterface *interface
> >>                                                      "model", "type", model);
> >>  }
> >>
> >> +const char *gvir_config_domain_interface_get_ifname(GVirConfigDomainInterface *interface)
> >
> > Unless I'm missing something, this should not be const (caller needs to
> > free the returned string).
> 
> String getters usually do return const in the gobject world[1] as
> opposed to object getters as one require allocation/de-allocation and
> the other only requires incrementing/decrementing a counter. Also is
> the fact that strings are readily usable so you can just make a call
> to the getter and thats it but objects are not usually readily usable
> in the sense that you have to pass it to to some other function to do
> something with it. Note that I'm just making educated guesses here as
> to why 'const' for strings makes more sense as to why this practice is
> followed.

Strings are const in the gobject world when they are owned by the object
and not by the caller of the getter (ie the caller doesn't need to free
them). They are non-const when the caller has to free them. In this case,
the strings need to be freed by the caller, thus "const" should not be
used.

Christophe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20120229/35bdd631/attachment-0001.sig>


More information about the libvir-list mailing list