#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
}
+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)
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);
* 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;
}