glibcompat: Provide proper override for 'g_hash_table_steal_extended'

We've emulated the function in virHashSteal, with a note pointing to use
the proper version. Move the code to glibcomapt.c and make it such that
builds using newer glib already use the new function.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2022-05-04 17:23:56 +02:00
parent 37356e1dc8
commit 00509d2d6a
3 changed files with 31 additions and 8 deletions

View File

@ -64,6 +64,7 @@
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#undef g_canonicalize_filename
#undef g_hash_table_steal_extended
#undef g_fsync
#undef g_strdup_printf
#undef g_strdup_vprintf
@ -173,6 +174,25 @@ vir_g_canonicalize_filename(const gchar *filename,
}
gboolean
vir_g_hash_table_steal_extended(GHashTable *hash_table,
gconstpointer lookup_key,
gpointer *stolen_key,
gpointer *stolen_value)
{
#if GLIB_CHECK_VERSION(2, 58, 0)
return g_hash_table_steal_extended(hash_table, lookup_key, stolen_key, stolen_value);
#else /* ! GLIB_CHECK_VERSION(2, 58, 0) */
if (!(g_hash_table_lookup_extended(hash_table, lookup_key, stolen_key, stolen_value)))
return FALSE;
g_hash_table_steal(hash_table, lookup_key);
return TRUE;
#endif /* ! GLIB_CHECK_VERSION(2, 58, 0) */
}
/* Drop when min glib >= 2.63.0 */
gint
vir_g_fsync(gint fd)

View File

@ -70,6 +70,14 @@
gchar * vir_g_canonicalize_filename(const gchar *filename,
const gchar *relative_to);
gboolean
vir_g_hash_table_steal_extended(GHashTable *hash_table,
gconstpointer lookup_key,
gpointer *stolen_key,
gpointer *stolen_value);
#define g_hash_table_steal_extended vir_g_hash_table_steal_extended
gint vir_g_fsync(gint fd);
char *vir_g_strdup_printf(const char *msg, ...)
G_GNUC_PRINTF(1, 2);

View File

@ -242,24 +242,19 @@ virHashHasEntry(GHashTable *table,
* Find the userdata specified by @name
* and remove it from the hash without freeing it.
*
* Deprecated: consider using g_hash_table_steal_extended once we upgrade to
* glib 2.58
* Deprecated: consider using g_hash_table_steal_extended instead
*
* Returns a pointer to the userdata
*/
void *virHashSteal(GHashTable *table, const char *name)
{
g_autofree void *orig_name = NULL;
g_autofree void *orig_name = NULL; /* the original key needs to be freed */
void *val = NULL;
if (!table || !name)
return NULL;
/* we can replace this by g_hash_table_steal_extended with glib 2.58 */
if (!(g_hash_table_lookup_extended(table, name, &orig_name, &val)))
return NULL;
g_hash_table_steal(table, name);
g_hash_table_steal_extended(table, name, &orig_name, &val);
return val;
}