[PATCH] qom/object: Comment to use g_slist_free on object_class_get_list result

Philippe Mathieu-Daudé posted 1 patch 5 years, 8 months ago
Test docker-quick@centos7 failed
Test FreeBSD failed
Test docker-mingw@fedora failed
Test checkpatch failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20200227190942.8834-1-philmd@redhat.com
Maintainers: Paolo Bonzini <pbonzini@redhat.com>, Eduardo Habkost <ehabkost@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>
include/qom/object.h | 6 ++++++
1 file changed, 6 insertions(+)
[PATCH] qom/object: Comment to use g_slist_free on object_class_get_list result
Posted by Philippe Mathieu-Daudé 5 years, 8 months ago
Document the list returned by object_class_get_list() must be
released with g_slist_free() to avoid memory leaks.

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 include/qom/object.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/include/qom/object.h b/include/qom/object.h
index 29546496c1..5517b56508 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -984,6 +984,9 @@ void object_class_foreach(void (*fn)(ObjectClass *klass, void *opaque),
  * @include_abstract: Whether to include abstract classes.
  *
  * Returns: A singly-linked list of the classes in reverse hashtable order.
+ *
+ * The returned list must be released with g_slist_free()
+ * when no longer required.
  */
 GSList *object_class_get_list(const char *implements_type,
                               bool include_abstract);
@@ -995,6 +998,9 @@ GSList *object_class_get_list(const char *implements_type,
  *
  * Returns: A singly-linked list of the classes in alphabetical
  * case-insensitive order.
+ *
+ * The returned list must be released with g_slist_free()
+ * when no longer required.
  */
 GSList *object_class_get_list_sorted(const char *implements_type,
                               bool include_abstract);
-- 
2.21.1


Re: [PATCH] qom/object: Comment to use g_slist_free on object_class_get_list result
Posted by Daniel P. Berrangé 5 years, 8 months ago
On Thu, Feb 27, 2020 at 08:09:42PM +0100, Philippe Mathieu-Daudé wrote:
> Document the list returned by object_class_get_list() must be
> released with g_slist_free() to avoid memory leaks.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
>  include/qom/object.h | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/include/qom/object.h b/include/qom/object.h
> index 29546496c1..5517b56508 100644
> --- a/include/qom/object.h
> +++ b/include/qom/object.h
> @@ -984,6 +984,9 @@ void object_class_foreach(void (*fn)(ObjectClass *klass, void *opaque),
>   * @include_abstract: Whether to include abstract classes.
>   *
>   * Returns: A singly-linked list of the classes in reverse hashtable order.
> + *
> + * The returned list must be released with g_slist_free()
> + * when no longer required.

I'd suggest

  "The returned list, but not its elements, must be released with
   g_slist_free() or g_autoptr when no longer required"

>   */
>  GSList *object_class_get_list(const char *implements_type,
>                                bool include_abstract);
> @@ -995,6 +998,9 @@ GSList *object_class_get_list(const char *implements_type,
>   *
>   * Returns: A singly-linked list of the classes in alphabetical
>   * case-insensitive order.
> + *
> + * The returned list must be released with g_slist_free()
> + * when no longer required.
>   */
>  GSList *object_class_get_list_sorted(const char *implements_type,
>                                bool include_abstract);
> -- 
> 2.21.1
> 
> 

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|


Re: [PATCH] qom/object: Comment to use g_slist_free on object_class_get_list result
Posted by Marc-André Lureau 5 years, 8 months ago
Hi

On Fri, Feb 28, 2020 at 10:47 AM Daniel P. Berrangé <berrange@redhat.com> wrote:
>
> On Thu, Feb 27, 2020 at 08:09:42PM +0100, Philippe Mathieu-Daudé wrote:
> > Document the list returned by object_class_get_list() must be
> > released with g_slist_free() to avoid memory leaks.
> >
> > Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> > ---
> >  include/qom/object.h | 6 ++++++
> >  1 file changed, 6 insertions(+)
> >
> > diff --git a/include/qom/object.h b/include/qom/object.h
> > index 29546496c1..5517b56508 100644
> > --- a/include/qom/object.h
> > +++ b/include/qom/object.h
> > @@ -984,6 +984,9 @@ void object_class_foreach(void (*fn)(ObjectClass *klass, void *opaque),
> >   * @include_abstract: Whether to include abstract classes.
> >   *
> >   * Returns: A singly-linked list of the classes in reverse hashtable order.
> > + *
> > + * The returned list must be released with g_slist_free()
> > + * when no longer required.
>
> I'd suggest
>
>   "The returned list, but not its elements, must be released with
>    g_slist_free() or g_autoptr when no longer required"

As gobject-introspection annotations: "Returns: (transfer container)
(element-type ObjectClass): A list of #ObjectClass"

>
> >   */
> >  GSList *object_class_get_list(const char *implements_type,
> >                                bool include_abstract);
> > @@ -995,6 +998,9 @@ GSList *object_class_get_list(const char *implements_type,
> >   *
> >   * Returns: A singly-linked list of the classes in alphabetical
> >   * case-insensitive order.
> > + *
> > + * The returned list must be released with g_slist_free()
> > + * when no longer required.
> >   */
> >  GSList *object_class_get_list_sorted(const char *implements_type,
> >                                bool include_abstract);
> > --
> > 2.21.1
> >
> >
>
> Regards,
> Daniel
> --
> |: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
> |: https://libvirt.org         -o-            https://fstop138.berrange.com :|
> |: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
>
>


-- 
Marc-André Lureau

Re: [PATCH] qom/object: Comment to use g_slist_free on object_class_get_list result
Posted by Philippe Mathieu-Daudé 5 years, 8 months ago
On 2/28/20 11:06 AM, Marc-André Lureau wrote:
> Hi
> 
> On Fri, Feb 28, 2020 at 10:47 AM Daniel P. Berrangé <berrange@redhat.com> wrote:
>>
>> On Thu, Feb 27, 2020 at 08:09:42PM +0100, Philippe Mathieu-Daudé wrote:
>>> Document the list returned by object_class_get_list() must be
>>> released with g_slist_free() to avoid memory leaks.
>>>
>>> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
>>> ---
>>>   include/qom/object.h | 6 ++++++
>>>   1 file changed, 6 insertions(+)
>>>
>>> diff --git a/include/qom/object.h b/include/qom/object.h
>>> index 29546496c1..5517b56508 100644
>>> --- a/include/qom/object.h
>>> +++ b/include/qom/object.h
>>> @@ -984,6 +984,9 @@ void object_class_foreach(void (*fn)(ObjectClass *klass, void *opaque),
>>>    * @include_abstract: Whether to include abstract classes.
>>>    *
>>>    * Returns: A singly-linked list of the classes in reverse hashtable order.
>>> + *
>>> + * The returned list must be released with g_slist_free()
>>> + * when no longer required.
>>
>> I'd suggest
>>
>>    "The returned list, but not its elements, must be released with
>>     g_slist_free() or g_autoptr when no longer required"
> 
> As gobject-introspection annotations: "Returns: (transfer container)
> (element-type ObjectClass): A list of #ObjectClass"

Are you suggesting to replace "Returns: A singly-linked list of the 
classes in reverse hashtable order." by the line you quoted?

> 
>>
>>>    */
>>>   GSList *object_class_get_list(const char *implements_type,
>>>                                 bool include_abstract);
>>> @@ -995,6 +998,9 @@ GSList *object_class_get_list(const char *implements_type,
>>>    *
>>>    * Returns: A singly-linked list of the classes in alphabetical
>>>    * case-insensitive order.
>>> + *
>>> + * The returned list must be released with g_slist_free()
>>> + * when no longer required.
>>>    */
>>>   GSList *object_class_get_list_sorted(const char *implements_type,
>>>                                 bool include_abstract);
>>> --
>>> 2.21.1
>>>
>>>
>>
>> Regards,
>> Daniel
>> --
>> |: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
>> |: https://libvirt.org         -o-            https://fstop138.berrange.com :|
>> |: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
>>
>>
> 
> 


Re: [PATCH] qom/object: Comment to use g_slist_free on object_class_get_list result
Posted by Marc-André Lureau 5 years, 8 months ago
Hi

On Fri, Feb 28, 2020 at 11:09 AM Philippe Mathieu-Daudé
<philmd@redhat.com> wrote:
>
> On 2/28/20 11:06 AM, Marc-André Lureau wrote:
> > Hi
> >
> > On Fri, Feb 28, 2020 at 10:47 AM Daniel P. Berrangé <berrange@redhat.com> wrote:
> >>
> >> On Thu, Feb 27, 2020 at 08:09:42PM +0100, Philippe Mathieu-Daudé wrote:
> >>> Document the list returned by object_class_get_list() must be
> >>> released with g_slist_free() to avoid memory leaks.
> >>>
> >>> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> >>> ---
> >>>   include/qom/object.h | 6 ++++++
> >>>   1 file changed, 6 insertions(+)
> >>>
> >>> diff --git a/include/qom/object.h b/include/qom/object.h
> >>> index 29546496c1..5517b56508 100644
> >>> --- a/include/qom/object.h
> >>> +++ b/include/qom/object.h
> >>> @@ -984,6 +984,9 @@ void object_class_foreach(void (*fn)(ObjectClass *klass, void *opaque),
> >>>    * @include_abstract: Whether to include abstract classes.
> >>>    *
> >>>    * Returns: A singly-linked list of the classes in reverse hashtable order.
> >>> + *
> >>> + * The returned list must be released with g_slist_free()
> >>> + * when no longer required.
> >>
> >> I'd suggest
> >>
> >>    "The returned list, but not its elements, must be released with
> >>     g_slist_free() or g_autoptr when no longer required"
> >
> > As gobject-introspection annotations: "Returns: (transfer container)
> > (element-type ObjectClass): A list of #ObjectClass"
>
> Are you suggesting to replace "Returns: A singly-linked list of the
> classes in reverse hashtable order." by the line you quoted?

No, just a remark. I doubt this is compatible with kernel-doc at this
point, and we are not using GI.

fwiw, I don't think "in reverse hashtable order" is really meaningful anyway.

>
> >
> >>
> >>>    */
> >>>   GSList *object_class_get_list(const char *implements_type,
> >>>                                 bool include_abstract);
> >>> @@ -995,6 +998,9 @@ GSList *object_class_get_list(const char *implements_type,
> >>>    *
> >>>    * Returns: A singly-linked list of the classes in alphabetical
> >>>    * case-insensitive order.
> >>> + *
> >>> + * The returned list must be released with g_slist_free()
> >>> + * when no longer required.
> >>>    */
> >>>   GSList *object_class_get_list_sorted(const char *implements_type,
> >>>                                 bool include_abstract);
> >>> --
> >>> 2.21.1
> >>>
> >>>
> >>
> >> Regards,
> >> Daniel
> >> --
> >> |: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
> >> |: https://libvirt.org         -o-            https://fstop138.berrange.com :|
> >> |: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
> >>
> >>
> >
> >
>


-- 
Marc-André Lureau

Re: [PATCH] qom/object: Comment to use g_slist_free on object_class_get_list result
Posted by Daniel P. Berrangé 5 years, 8 months ago
On Fri, Feb 28, 2020 at 11:06:38AM +0100, Marc-André Lureau wrote:
> Hi
> 
> On Fri, Feb 28, 2020 at 10:47 AM Daniel P. Berrangé <berrange@redhat.com> wrote:
> >
> > On Thu, Feb 27, 2020 at 08:09:42PM +0100, Philippe Mathieu-Daudé wrote:
> > > Document the list returned by object_class_get_list() must be
> > > released with g_slist_free() to avoid memory leaks.
> > >
> > > Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> > > ---
> > >  include/qom/object.h | 6 ++++++
> > >  1 file changed, 6 insertions(+)
> > >
> > > diff --git a/include/qom/object.h b/include/qom/object.h
> > > index 29546496c1..5517b56508 100644
> > > --- a/include/qom/object.h
> > > +++ b/include/qom/object.h
> > > @@ -984,6 +984,9 @@ void object_class_foreach(void (*fn)(ObjectClass *klass, void *opaque),
> > >   * @include_abstract: Whether to include abstract classes.
> > >   *
> > >   * Returns: A singly-linked list of the classes in reverse hashtable order.
> > > + *
> > > + * The returned list must be released with g_slist_free()
> > > + * when no longer required.
> >
> > I'd suggest
> >
> >   "The returned list, but not its elements, must be released with
> >    g_slist_free() or g_autoptr when no longer required"
> 
> As gobject-introspection annotations: "Returns: (transfer container)
> (element-type ObjectClass): A list of #ObjectClass"

If we were using Gobject introspection and/or Gtk-Doc, then I'd certainly
suggest that syntax, but AFAIK this is not something that fits with our
intented docs tools. There might be sense in having our docs tools parse
these kind of annotations as it is useful to have it in standardized
format. I think we should decide on this before actually adding them to
the docs though.

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|