GNOME Bugzilla – Bug 657433
g_queue_free_full() missing
Last modified: 2011-12-19 07:14:30 UTC
There is no function to free a GQueue, including its dynamically-allocated elements. I would like: g_queue_free_full(GQueue *queue, GDestroyNotify free_func); Without it, I have to iterate twice in the list with: g_queue_foreach (queue, (GFunc) free_func, NULL); g_queue_free (queue);
I guess you could just do g_list_free_full (queue->head, free_func, NULL); queue->head = NULL; g_queue_free (queue); or while ((elt = g_queue_pop_head (queue)) free_func (elt, NULL); g_queue_free (queue); to avoid the 'iterate twice'. But I guess both of these lack some elegance, and I would accept a patch for free_full, if only to keep the api parallel to list and slist.
Added proposed API and its test case. Please review the patch. void g_queue_free_full (GQueue *queue, GDestroyNotify free_func);
Created attachment 203330 [details] [review] Added new API to free a Queue including its dynamically-allocated elements. (On similar lines to List and Slist).
Review of attachment 203330 [details] [review]: looks good to me.
Created attachment 203478 [details] [review] API to free a Queue including its dynamically allocated elements. patch amended. + added Note to g_queue_free() API. + added g_queue_free_full() API to glib.symbols
Review of attachment 203478 [details] [review]: Looks good, thanks
The following fix has been pushed: 1d4009e Added API g_queue_free_full().
Created attachment 203678 [details] [review] Added API g_queue_free_full(). g_queue_free_full(), to free a Queue including its dynamically-allocated elements. On similar lines to List and Slist. void g_queue_free_full (GQueue *queue, GDestroyNotify free_func); Test case covering g_queue_free_full() is added. Added export symbol to glib.symbols. Closes Bug: https://bugzilla.gnome.org/show_bug.cgi?id=657433 Signed-off-by: Ravi Sankar Guntur <ravi.g@samsung.com>
Review of attachment 203678 [details] [review]: ::: glib/gqueue.c @@ +109,3 @@ + g_queue_foreach (queue, (GFunc) free_func, NULL); + g_queue_free (queue); +} Doesn't this iterate the list twice? Wouldn't it be better to do g_list_free_full (queue->head, free_func); g_slice_free (GQueue, queue);
Created attachment 203687 [details] [review] Patch to only iterate the list once
Doesn't g_list_free_full() also iterate twice? g_list_foreach() g_list_free()