Message ID | 1393600696-24118-6-git-send-email-stefanha@redhat.com |
---|---|
State | New |
Headers | show |
Am 28.02.2014 16:18, schrieb Stefan Hajnoczi: > From: Igor Mammedov <imammedo@redhat.com> > > get_pointer()'s print() callback might return a heap allocated > string, to avoid adding dedicated get_pointer_foo for this case > convert current print() callbacks to return temporary heap > allocated string and make get_pointer() free it. > > Signed-off-by: Igor Mammedov <imammedo@redhat.com> > Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> > --- > hw/core/qdev-properties-system.c | 19 +++++++++++-------- > 1 file changed, 11 insertions(+), 8 deletions(-) Not aware of the history of this patch (not CC'ed?) but looks okay, Reviewed-by: Andreas Färber <afaerber@suse.de> Do we have any users outside of this series? Regards, Andreas
On Fri, Feb 28, 2014 at 05:49:09PM +0100, Andreas Färber wrote: > Am 28.02.2014 16:18, schrieb Stefan Hajnoczi: > > From: Igor Mammedov <imammedo@redhat.com> > > > > get_pointer()'s print() callback might return a heap allocated > > string, to avoid adding dedicated get_pointer_foo for this case > > convert current print() callbacks to return temporary heap > > allocated string and make get_pointer() free it. > > > > Signed-off-by: Igor Mammedov <imammedo@redhat.com> > > Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> > > --- > > hw/core/qdev-properties-system.c | 19 +++++++++++-------- > > 1 file changed, 11 insertions(+), 8 deletions(-) > > Not aware of the history of this patch (not CC'ed?) but looks okay, > > Reviewed-by: Andreas Färber <afaerber@suse.de> > > Do we have any users outside of this series? The patch comes from Igor originally so maybe he has future patches that will use it. Stefan
On Mon, 3 Mar 2014 10:41:30 +0100 Stefan Hajnoczi <stefanha@redhat.com> wrote: > On Fri, Feb 28, 2014 at 05:49:09PM +0100, Andreas Färber wrote: > > Am 28.02.2014 16:18, schrieb Stefan Hajnoczi: > > > From: Igor Mammedov <imammedo@redhat.com> > > > > > > get_pointer()'s print() callback might return a heap allocated > > > string, to avoid adding dedicated get_pointer_foo for this case > > > convert current print() callbacks to return temporary heap > > > allocated string and make get_pointer() free it. > > > > > > Signed-off-by: Igor Mammedov <imammedo@redhat.com> > > > Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> > > > --- > > > hw/core/qdev-properties-system.c | 19 +++++++++++-------- > > > 1 file changed, 11 insertions(+), 8 deletions(-) > > > > Not aware of the history of this patch (not CC'ed?) but looks okay, > > > > Reviewed-by: Andreas Färber <afaerber@suse.de> > > > > Do we have any users outside of this series? > > The patch comes from Igor originally so maybe he has future patches that > will use it. > > Stefan I don't have other users/plans to use it. Patch was suggested as alternative to adding a new API: http://lists.gnu.org/archive/html/qemu-devel/2014-02/msg04704.html
diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c index 5f5957e..878c3bc 100644 --- a/hw/core/qdev-properties-system.c +++ b/hw/core/qdev-properties-system.c @@ -20,15 +20,16 @@ #include "sysemu/char.h" static void get_pointer(Object *obj, Visitor *v, Property *prop, - const char *(*print)(void *ptr), + char *(*print)(void *ptr), const char *name, Error **errp) { DeviceState *dev = DEVICE(obj); void **ptr = qdev_get_prop_ptr(dev, prop); char *p; - p = (char *) (*ptr ? print(*ptr) : ""); + p = *ptr ? print(*ptr) : g_strdup(""); visit_type_str(v, &p, name, errp); + g_free(p); } static void set_pointer(Object *obj, Visitor *v, Property *prop, @@ -91,9 +92,9 @@ static void release_drive(Object *obj, const char *name, void *opaque) } } -static const char *print_drive(void *ptr) +static char *print_drive(void *ptr) { - return bdrv_get_device_name(ptr); + return g_strdup(bdrv_get_device_name(ptr)); } static void get_drive(Object *obj, Visitor *v, void *opaque, @@ -145,11 +146,12 @@ static void release_chr(Object *obj, const char *name, void *opaque) } -static const char *print_chr(void *ptr) +static char *print_chr(void *ptr) { CharDriverState *chr = ptr; + const char *val = chr->label ? chr->label : ""; - return chr->label ? chr->label : ""; + return g_strdup(val); } static void get_chr(Object *obj, Visitor *v, void *opaque, @@ -224,11 +226,12 @@ err: return ret; } -static const char *print_netdev(void *ptr) +static char *print_netdev(void *ptr) { NetClientState *netdev = ptr; + const char *val = netdev->name ? netdev->name : ""; - return netdev->name ? netdev->name : ""; + return g_strdup(val); } static void get_netdev(Object *obj, Visitor *v, void *opaque,