From bebec5eee40eda345cac0698ec17b3500e041975 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Tue, 11 Feb 2025 12:13:46 -0400 Subject: [PATCH] MT#55283 add extra typed GPtrArray methods Change-Id: If67ac73a5f7f7e767d8f8eb09a77ca552ab81148 --- lib/containers.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/containers.h b/lib/containers.h index 163a0d2c4..25fc2f0e0 100644 --- a/lib/containers.h +++ b/lib/containers.h @@ -425,6 +425,7 @@ static inline void g_queue_clear_full(GQueue *q, GDestroyNotify free_func) { contained_type **pdata; \ unsigned int len; \ }; \ + const contained_type *__ct; \ } type_name; \ static_assert(sizeof(GPtrArray) == sizeof(type_name), "sizeof ptrarray type mismatch"); \ static_assert(G_STRUCT_OFFSET(GPtrArray, pdata) == G_STRUCT_OFFSET(type_name, pdata), \ @@ -437,7 +438,11 @@ static inline void g_queue_clear_full(GQueue *q, GDestroyNotify free_func) { } \ static inline type_name *type_name##_new(void) { \ return type_name##_new_sized(0); \ - } + } \ + static inline void type_name##_destroy_ptr(type_name *A) { \ + g_ptr_array_free(&(A)->a, TRUE); \ + } \ + G_DEFINE_AUTOPTR_CLEANUP_FUNC(type_name, type_name##_destroy_ptr) #define TYPED_GPTRARRAY(type_name, contained_type) \ TYPED_GPTRARRAY_FULL(type_name, contained_type, NULL) @@ -446,6 +451,11 @@ static inline void g_queue_clear_full(GQueue *q, GDestroyNotify free_func) { g_ptr_array_set_size(&(A)->a, l); \ }) +#define t_ptr_array_sort(A, f) ({ \ + int (*__f)(__typeof__((A)->__ct), __typeof__((A)->__ct)) = f; \ + g_ptr_array_sort(&(A)->a, (GCompareFunc) __f); \ + }) + #define t_ptr_array_free(A, fd) ({ \ g_ptr_array_free(&(A)->a, fd); \ }) @@ -455,5 +465,9 @@ static inline void g_queue_clear_full(GQueue *q, GDestroyNotify free_func) { g_ptr_array_add(&(A)->a, __e); \ }) +#define t_ptr_array_remove_index(A, i) ({ \ + g_ptr_array_remove_index(&(A)->a, i); \ + }) + #endif