<div dir="ltr"><div>Hey folks,</div><div><br></div><div>We appreciate the feedback, and we've used this to complete some initial work on issue 11.</div><div><br></div><div>We started with small changes in src/util, and we submitted them via email (following <a href="https://libvirt.org/submitting-patches.html">these guidelines on submitting patches</a>) to ensure we are on the right path.</div><div><br></div><div>We do not see the patch we submitted via email showing up in the threads, and we are wondering if we are submitting incorrectly or if the patch goes through some approval process before appearing in the threads.</div><div><br></div><div>Best regards,</div><div>Barrett Schonefeld<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Nov 3, 2020 at 4:02 AM Michal Privoznik <<a href="mailto:mprivozn@redhat.com">mprivozn@redhat.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 11/3/20 12:47 AM, Barrett J Schonefeld wrote:<br>
> Hey folks,<br>
> <br>
> We have started work on issue 11<br>
> <<a href="https://gitlab.com/libvirt/libvirt/-/issues/11" rel="noreferrer" target="_blank">https://gitlab.com/libvirt/libvirt/-/issues/11</a>>, and we have some<br>
> questions to ensure we tackle the issue properly.<br>
> <br>
> <br>
>     - What are the different use cases for g_autoptr vs g_autofree? We found<br>
>     that g_autofree is preferred for anything that uses g_malloc according to<br>
>     the Glib documentation<br>
>     <<a href="https://developer.gnome.org/glib/stable/glib-Miscellaneous-Macros.html#g-autofree" rel="noreferrer" target="_blank">https://developer.gnome.org/glib/stable/glib-Miscellaneous-Macros.html#g-autofree</a>>,<br>
>     and g_autoptr is for types with custom destructors. However, when using<br>
>     g_autoptr, we got compile errors when trying to pass the g_autoptr as an<br>
>     argument (the argument seems to be converted to an integer). When should we<br>
>     use each of these, and when should we not convert them at all?<br>
<br>
Right. g_autofree instructs compiler to call plain free() over the <br>
variable when it goes out of scope (mind you, not only at the end of a <br>
function, but also inside a loop, if-else bodies, etc.) while <br>
g_autoptr() does two things: it declares variable as a pointer to given <br>
type, and calls previously registered destructor when the variable goes <br>
out of scope (instead of plain free()). For instance:<br>
<br>
   g_autofree char *tmp = g_strdup("my awesome string");<br>
   g_autoptr(virBitmap) b = virBitmapNew(..);<br>
<br>
And since virBitmap module lives under src/util/virbitmap.* that's also <br>
where you can find the destructor registration:<br>
<br>
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virBitmap, virBitmapFree);<br>
<br>
We are currently in transition state of adopting glib so you can find a <br>
mixture of our old approach (VIR_FREE() and/or explicit destructor calls <br>
like virBitmapFree()) and the new approach (where glib is used). Not <br>
ideal, but for any new code we try to use glib if possible. Sometimes we <br>
just rewrite a module/file into glib, for instance:<br>
<br>
<a href="https://www.redhat.com/archives/libvir-list/2020-October/msg00210.html" rel="noreferrer" target="_blank">https://www.redhat.com/archives/libvir-list/2020-October/msg00210.html</a><br>
<br>
Hence, any rewrite to glib is welcome!<br>
<br>
> <br>
>     - We see that some work has been done to convert files to use the Glib<br>
>     API. In some cases, files contain code that uses both the old memory<br>
>     management API and the Glib API. Should we focus our attention on files<br>
>     where these conversions are not yet underway? Or should we expect that many<br>
>     of the files are only partially converted?<br>
<br>
You are free to chose whatever you want. I'd start with small files <br>
(e.g. src/util/*) because they are usually self contained and have small <br>
functions in them (i.e. no complicated branching is happening inside a <br>
function).<br>
<br>
> <br>
>     - In some cases, we found that converting to the Glib API might require<br>
>     cascading changes to code structure (function parameter types, function<br>
>     return types). Is it advisable to pursue these cases as well, or should we<br>
>     limit changes to pointers which are declared and then freed within one<br>
>     method?<br>
<br>
This is a tougher question. Libvirt has a promise of stable API which <br>
includes public C API and ABI. Therefore an user facing function can't <br>
change its parameters or their order. These are declared in <br>
include/libvirt/*.h and implemented in src/libvirt-. Note, the body of <br>
these functions can be changed, it's signature that can never change.<br>
Having said that, our internal APIs are free to change as we please.<br>
<br>
> <br>
>     - Do you know of a directory or set of files where the conversions to<br>
>     the Glib API are needed?<br>
<br>
IMO, it's best to start with something smaller (like src/util/, tools/) <br>
send that for review to make sure you're on the right path and then <br>
continue with something bigger.<br>
<br>
<br>
Michal<br>
<br>
</blockquote></div>