On Tue, Jan 10, 2017 at 11:54:19PM +0000, Richard W.M. Jones wrote:
On Tue, Jan 10, 2017 at 10:00:31AM +0000, Daniel P. Berrange wrote:If we mandate use of gcc / clang, then we wouldn't need to hide it behind a macro - we'd be able to use it inline. That said, using a macro makes it smaller and gives a bit of standardization. eg with libguestfs style: #define CLEANUP_FREE __attribute__((cleanup(free))) #define CLEANUP_OBJECT_UNREF __attribute__((cleanup(virObjectUnref))) CLEANUP_FREE char *str; CLEANUP_OBJECT_UNREF virDomainPtr dom; vs full inline style: __attribute__((cleanup(free))) char *str; __attribute__((cleanup(virObjectUnref))) virDomainPtr dom; That said I see systemd took a halfway house #define _cleanup_(x) __attribute__((cleanup(x))) _cleanup(free) char *str; _cleanup(virObjectUnref) virDomainPtr dom;I think it's not quite as simple as that because GCC passes the pointer to the pointer. libguestfs uses: #define CLEANUP_FREE __attribute__((cleanup(guestfs_int_cleanup_free))) ... void guestfs_int_cleanup_free (void *ptr) { free (* (void **) ptr); }
Well, it is, since we already have that as virFree(), it's just usually called using VIR_FREE() so that you don't have to add an extra ampersand.
Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-builder quickly builds VMs from scratch http://libguestfs.org/virt-builder.1.html -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list
Attachment:
signature.asc
Description: Digital signature
-- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list