mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 21:55:25 +00:00
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:
parent
37356e1dc8
commit
00509d2d6a
@ -64,6 +64,7 @@
|
|||||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||||
|
|
||||||
#undef g_canonicalize_filename
|
#undef g_canonicalize_filename
|
||||||
|
#undef g_hash_table_steal_extended
|
||||||
#undef g_fsync
|
#undef g_fsync
|
||||||
#undef g_strdup_printf
|
#undef g_strdup_printf
|
||||||
#undef g_strdup_vprintf
|
#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 */
|
/* Drop when min glib >= 2.63.0 */
|
||||||
gint
|
gint
|
||||||
vir_g_fsync(gint fd)
|
vir_g_fsync(gint fd)
|
||||||
|
@ -70,6 +70,14 @@
|
|||||||
|
|
||||||
gchar * vir_g_canonicalize_filename(const gchar *filename,
|
gchar * vir_g_canonicalize_filename(const gchar *filename,
|
||||||
const gchar *relative_to);
|
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);
|
gint vir_g_fsync(gint fd);
|
||||||
char *vir_g_strdup_printf(const char *msg, ...)
|
char *vir_g_strdup_printf(const char *msg, ...)
|
||||||
G_GNUC_PRINTF(1, 2);
|
G_GNUC_PRINTF(1, 2);
|
||||||
|
@ -242,24 +242,19 @@ virHashHasEntry(GHashTable *table,
|
|||||||
* Find the userdata specified by @name
|
* Find the userdata specified by @name
|
||||||
* and remove it from the hash without freeing it.
|
* and remove it from the hash without freeing it.
|
||||||
*
|
*
|
||||||
* Deprecated: consider using g_hash_table_steal_extended once we upgrade to
|
* Deprecated: consider using g_hash_table_steal_extended instead
|
||||||
* glib 2.58
|
|
||||||
*
|
*
|
||||||
* Returns a pointer to the userdata
|
* Returns a pointer to the userdata
|
||||||
*/
|
*/
|
||||||
void *virHashSteal(GHashTable *table, const char *name)
|
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;
|
void *val = NULL;
|
||||||
|
|
||||||
if (!table || !name)
|
if (!table || !name)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
/* we can replace this by g_hash_table_steal_extended with glib 2.58 */
|
g_hash_table_steal_extended(table, name, &orig_name, &val);
|
||||||
if (!(g_hash_table_lookup_extended(table, name, &orig_name, &val)))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
g_hash_table_steal(table, name);
|
|
||||||
|
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user