]> xenbits.xensource.com Git - libvirt.git/commitdiff
docs: hacking: extend goto documentation
authorJán Tomko <jtomko@redhat.com>
Fri, 18 Oct 2019 21:17:51 +0000 (23:17 +0200)
committerJán Tomko <jtomko@redhat.com>
Tue, 22 Oct 2019 20:15:02 +0000 (22:15 +0200)
Replace reference to VIR_FREE with g_free and mention the use
of g_auto cleanup attributes that eliminate most of label use.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
docs/hacking.html.in

index 030d7818e363a4e9c3cde9ea9d64947199c65544..661b262a116bb5f012cf6a1f10f2ac4ea7b20b6e 100644 (file)
@@ -1447,11 +1447,16 @@ BAD:
       single label at the end of the function.  It's almost always ok
       to use this style.  In particular, if the cleanup code only
       involves free'ing memory, then having multiple labels is
-      overkill.  VIR_FREE() and every function named XXXFree() in
-      libvirt is required to handle NULL as its arg.  Thus you can
+      overkill.  g_free() and most of the functions named XXXFree() in
+      libvirt is required to handle NULL as its arg. This does not
+      apply to libvirt's public APIs. Thus you can
       safely call free on all the variables even if they were not yet
       allocated (yes they have to have been initialized to NULL).
       This is much simpler and clearer than having multiple labels.
+      Note that most of libvirt's type declarations can be marked with
+      either <code>g_autofree</code> or <code>g_autoptr</code> which uses
+      the compiler's <code>__attribute__((cleanup))</code> that calls
+      the appropriate free function when the variable goes out of scope.
     </p>
 
     <p>