[libvirt PATCH 0/2] bump minimum glib version to 2.68

Ján Tomko (2): build: bump minimum glib version to 2.68 util: remove glibcompat.c meson.build | 2 +- src/conf/virdomainjob.c | 6 +- src/esx/esx_vi_types.c | 9 +- src/internal.h | 24 ---- src/libvirt_private.syms | 4 - src/qemu/qemu_capabilities.c | 8 +- src/util/glibcompat.c | 213 ----------------------------------- src/util/glibcompat.h | 29 ----- src/util/meson.build | 1 - 9 files changed, 13 insertions(+), 283 deletions(-) delete mode 100644 src/util/glibcompat.c -- 2.50.1

From: Ján Tomko <jtomko@redhat.com> We removed support for Debian 11 which only had 2.66.8. Next stop: 2.72 after we drop Ubuntu 22.04 For libvirt, the update to the 2.68 GLib release: * introduces g_string_replace * deprecates g_memdup in favor of g_memdup2 * removes the need for some warning workarounds * deprecates g_time_zone_new in favor of g_time_zone_new_identifier which returns NULL on error instead of returning UTC Signed-off-by: Ján Tomko <jtomko@redhat.com> --- meson.build | 2 +- src/conf/virdomainjob.c | 6 +- src/esx/esx_vi_types.c | 9 ++- src/internal.h | 24 ------ src/libvirt_private.syms | 4 - src/qemu/qemu_capabilities.c | 8 +- src/util/glibcompat.c | 149 ----------------------------------- src/util/glibcompat.h | 29 ------- 8 files changed, 13 insertions(+), 218 deletions(-) diff --git a/meson.build b/meson.build index 0d64a77a4c..5d261a0e4f 100644 --- a/meson.build +++ b/meson.build @@ -981,7 +981,7 @@ else endif endif -glib_version = '2.66.0' +glib_version = '2.68' glib_dep = dependency('glib-2.0', version: '>=' + glib_version) gobject_dep = dependency('gobject-2.0', version: '>=' + glib_version) if host_machine.system() == 'windows' diff --git a/src/conf/virdomainjob.c b/src/conf/virdomainjob.c index 2d5a857a8c..99c362d593 100644 --- a/src/conf/virdomainjob.c +++ b/src/conf/virdomainjob.c @@ -129,8 +129,8 @@ virDomainObjInitJob(virDomainJobObj *job, virDomainJobDataPrivateDataCallbacks *jobDataPrivateCb) { memset(job, 0, sizeof(*job)); - job->cb = g_memdup(cb, sizeof(*cb)); - job->jobDataPrivateCb = g_memdup(jobDataPrivateCb, sizeof(*jobDataPrivateCb)); + job->cb = g_memdup2(cb, sizeof(*cb)); + job->jobDataPrivateCb = g_memdup2(jobDataPrivateCb, sizeof(*jobDataPrivateCb)); if (virCondInit(&job->cond) < 0) return -1; @@ -212,7 +212,7 @@ virDomainObjPreserveJob(virDomainJobObj *currJob, if (currJob->cb && currJob->cb->allocJobPrivate && !(currJob->privateData = currJob->cb->allocJobPrivate())) return -1; - job->cb = g_memdup(currJob->cb, sizeof(*currJob->cb)); + job->cb = g_memdup2(currJob->cb, sizeof(*currJob->cb)); virDomainObjResetJob(currJob); virDomainObjResetAsyncJob(currJob); diff --git a/src/esx/esx_vi_types.c b/src/esx/esx_vi_types.c index 9386727fcf..614e7939c3 100644 --- a/src/esx/esx_vi_types.c +++ b/src/esx/esx_vi_types.c @@ -1512,11 +1512,12 @@ esxVI_DateTime_ConvertToCalendarTime(esxVI_DateTime *dateTime, } /* parse timezone offset if present. if missing assume UTC */ - if (*tmp == '+' || *tmp == '-') { - tz = g_time_zone_new(tmp); - } else if (STREQ(tmp, "Z")) { + if (STREQ(tmp, "Z")) tz = g_time_zone_new_utc(); - } else { + + if (*tmp == '+' || *tmp == '-') + tz = g_time_zone_new_identifier(tmp); + if (!tz) { virReportError(VIR_ERR_INTERNAL_ERROR, _("xsd:dateTime value '%1$s' has unexpected format"), dateTime->value); diff --git a/src/internal.h b/src/internal.h index bd62a25ef8..8200480394 100644 --- a/src/internal.h +++ b/src/internal.h @@ -152,30 +152,6 @@ # endif #endif -/** - * - * G_GNUC_FALLTHROUGH - * - * silence the compiler warning when falling through a switch case - * - * Note: GLib 2.69.0 introduced version checks on the - * macro usage. Thus an app setting GLIB_VERSION_MAX_ALLOWED - * to less than 2.60 will trigger a warning using G_GNUC_FALLTHROUGH - * Normally the warning is a good thing, but we want to use our - * fallback impl, so we have to temporarily cull the GLib macro. - * - * All this should be removed once updating to min GLib >= 2.60 - */ -#if GLIB_CHECK_VERSION(2, 69, 0) -# undef G_GNUC_FALLTHROUGH -#endif -#ifndef G_GNUC_FALLTHROUGH -# if __GNUC_PREREQ (7, 0) -# define G_GNUC_FALLTHROUGH __attribute__((fallthrough)) -# else -# define G_GNUC_FALLTHROUGH do {} while(0) -# endif -#endif /** * diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index b846011f0f..fe72402527 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1899,10 +1899,6 @@ virStorageSourceUpdateCapacity; virStorageSourceUpdatePhysicalSize; -# util/glibcompat.h -vir_g_string_replace; - - # util/viracpi.c virAcpiHasSMMU; virAcpiParseIORT; diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 7f6abed1aa..618291e5b6 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -2070,8 +2070,8 @@ virQEMUCaps *virQEMUCapsNewCopy(virQEMUCaps *qemuCaps) if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_SGX_EPC)) virQEMUCapsSGXInfoCopy(&ret->sgxCapabilities, qemuCaps->sgxCapabilities); - ret->hypervCapabilities = g_memdup(qemuCaps->hypervCapabilities, - sizeof(virDomainCapsFeatureHyperv)); + ret->hypervCapabilities = g_memdup2(qemuCaps->hypervCapabilities, + sizeof(virDomainCapsFeatureHyperv)); return g_steal_pointer(&ret); } @@ -6930,8 +6930,8 @@ static void virQEMUCapsFillDomainFeatureHypervCaps(virQEMUCaps *qemuCaps, virDomainCaps *domCaps) { - domCaps->hyperv = g_memdup(qemuCaps->hypervCapabilities, - sizeof(virDomainCapsFeatureHyperv)); + domCaps->hyperv = g_memdup2(qemuCaps->hypervCapabilities, + sizeof(virDomainCapsFeatureHyperv)); } diff --git a/src/util/glibcompat.c b/src/util/glibcompat.c index 47e3edef13..dd19c7ac43 100644 --- a/src/util/glibcompat.c +++ b/src/util/glibcompat.c @@ -62,152 +62,3 @@ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated-declarations" - -/** - * Adapted (to pass syntax check) from 'g_string_replace' from - * glib-2.83.3. Drop once minimum glib is bumped to 2.68. - * - * g_string_replace: - * @string: a #GString - * @find: the string to find in @string - * @replace: the string to insert in place of @find - * @limit: the maximum instances of @find to replace with @replace, or `0` for - * no limit - * - * Replaces the string @find with the string @replace in a #GString up to - * @limit times. If the number of instances of @find in the #GString is - * less than @limit, all instances are replaced. If @limit is `0`, - * all instances of @find are replaced. - * - * If @find is the empty string, since versions 2.69.1 and 2.68.4 the - * replacement will be inserted no more than once per possible position - * (beginning of string, end of string and between characters). This did - * not work correctly in earlier versions. - * - * Returns: the number of find and replace operations performed. - * - * Since: 2.68 - */ -guint -vir_g_string_replace(GString *string, - const gchar *find, - const gchar *replace, - guint limit) -{ - GString *new_string = NULL; - gsize f_len, r_len, new_len; - gchar *cur, *next, *first, *dst; - guint n; - - g_return_val_if_fail(string != NULL, 0); - g_return_val_if_fail(find != NULL, 0); - g_return_val_if_fail(replace != NULL, 0); - - first = strstr(string->str, find); - - if (first == NULL) - return 0; - - new_len = string->len; - f_len = strlen(find); - r_len = strlen(replace); - - /* It removes a lot of branches and possibility for infinite loops if we - * handle the case of an empty @find string separately. */ - if (G_UNLIKELY(f_len == 0)) { - size_t i; - if (limit == 0 || limit > string->len) { - if (string->len > G_MAXSIZE - 1) - g_error("inserting in every position in string would overflow"); - - limit = string->len + 1; - } - - if (r_len > 0 && - (limit > G_MAXSIZE / r_len || - limit * r_len > G_MAXSIZE - string->len)) - g_error("inserting in every position in string would overflow"); - - new_len = string->len + limit * r_len; - new_string = g_string_sized_new(new_len); - for (i = 0; i < limit; i++) { - g_string_append_len(new_string, replace, r_len); - if (i < string->len) - g_string_append_c(new_string, string->str[i]); - } - if (limit < string->len) - g_string_append_len(new_string, string->str + limit, string->len - limit); - - g_free(string->str); - string->allocated_len = new_string->allocated_len; - string->len = new_string->len; - string->str = g_string_free(g_steal_pointer(&new_string), FALSE); - - return limit; - } - /* Potentially do two passes: the first to calculate the length of the new string, - * new_len, if it’s going to be longer than the original string; and the second to - * do the replacements. The first pass is skipped if the new string is going to be - * no longer than the original. - * - * The second pass calls various g_string_insert_len() (and similar) methods - * which would normally potentially reallocate string->str, and hence - * invalidate the cur/next/first/dst pointers. Because we’ve pre-calculated - * the new_len and do all the string manipulations on new_string, that - * shouldn’t happen. This means we scan `string` while modifying - * `new_string`. */ - do { - dst = first; - cur = first; - n = 0; - while ((next = strstr(cur, find)) != NULL) { - n++; - - if (r_len <= f_len) { - memmove(dst, cur, next - cur); - dst += next - cur; - memcpy(dst, replace, r_len); - dst += r_len; - } else { - if (new_string == NULL) { - new_len += r_len - f_len; - } else { - g_string_append_len(new_string, cur, next - cur); - g_string_append_len(new_string, replace, r_len); - } - } - cur = next + f_len; - - if (n == limit) - break; - } - - /* Append the trailing characters from after the final instance of @find - * in the input string. */ - if (r_len <= f_len) { - /* First pass skipped. */ - gchar *end = string->str + string->len; - memmove(dst, cur, end - cur); - end = dst + (end - cur); - *end = 0; - string->len = end - string->str; - break; - } else { - if (new_string == NULL) { - /* First pass. */ - new_string = g_string_sized_new(new_len); - g_string_append_len(new_string, string->str, first - string->str); - } else { - /* Second pass. */ - g_string_append_len(new_string, cur, (string->str + string->len) - cur); - g_free(string->str); - string->allocated_len = new_string->allocated_len; - string->len = new_string->len; - string->str = g_string_free(g_steal_pointer(&new_string), FALSE); - break; - } - } - } while (1); - - return n; -} diff --git a/src/util/glibcompat.h b/src/util/glibcompat.h index a3d01089e6..5eb63e3cce 100644 --- a/src/util/glibcompat.h +++ b/src/util/glibcompat.h @@ -22,35 +22,6 @@ #include <glib/gstdio.h> #include <glib-object.h> -#if !GLIB_CHECK_VERSION(2, 67, 0) - -/* - * ...meanwhile GCC >= 11 has started issuing warnings about volatile - * from the old G_DEFINE_TYPE macro impl. IOW the new macros impls fixed - * new GCC, but broke CLang - */ -# if !defined(__clang__) && __GNUC_PREREQ (11, 0) -# undef _G_DEFINE_TYPE_EXTENDED_BEGIN - -# define _G_DEFINE_TYPE_EXTENDED_BEGIN(TypeName, type_name, TYPE_PARENT, flags) \ - _Pragma("GCC diagnostic push") \ - _Pragma("GCC diagnostic ignored \"-Wincompatible-pointer-types\"") \ - _G_DEFINE_TYPE_EXTENDED_BEGIN_PRE(TypeName, type_name, TYPE_PARENT) \ - _G_DEFINE_TYPE_EXTENDED_BEGIN_REGISTER(TypeName, type_name, TYPE_PARENT, flags) \ - _Pragma("GCC diagnostic pop") -# endif /* !clang && GCC >= 11.0 */ - -#endif /* GLib < 2.67.0 */ - -/* Drop once we require glib-2.68 at minimum */ -guint -vir_g_string_replace(GString *string, - const gchar *find, - const gchar *replace, - guint limit); -#undef g_string_replace -#define g_string_replace vir_g_string_replace - #if !GLIB_CHECK_VERSION(2, 73, 2) # if (defined(__has_attribute) && __has_attribute(__noinline__)) || G_GNUC_CHECK_VERSION (2, 96) # if defined (__cplusplus) && __cplusplus >= 201103L -- 2.50.1

From: Ján Tomko <jtomko@redhat.com> There are no functions reimplemented here anymore. Signed-off-by: Ján Tomko <jtomko@redhat.com> --- src/util/glibcompat.c | 64 ------------------------------------------- src/util/meson.build | 1 - 2 files changed, 65 deletions(-) delete mode 100644 src/util/glibcompat.c diff --git a/src/util/glibcompat.c b/src/util/glibcompat.c deleted file mode 100644 index dd19c7ac43..0000000000 --- a/src/util/glibcompat.c +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) 2019 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see - * <http://www.gnu.org/licenses/>. - */ - -#include <config.h> - -#include <stdlib.h> -#include <string.h> -#include <unistd.h> - -#include "glibcompat.h" - -/* - * Note that because of the GLIB_VERSION_MAX_ALLOWED constant in - * config-post.h, allowing use of functions from newer GLib via - * this compat impl needs a little trickery to prevent warnings - * being emitted. - * - * Consider a function from newer glib-X.Y that we want to use - * - * int g_foo(const char *wibble) - * - * We must define a function with the same signature that does - * what we need, but with a "vir_" prefix e.g. - * - * void vir_g_foo(const char *wibble) - * { - * #if GLIB_CHECK_VERSION(X, Y, 0) - * g_foo(wibble) - * #else - * g_something_equivalent_in_older_glib(wibble); - * #endif - * } - * - * The #pragma at the top of this file turns off -Wdeprecated-declarations, - * ensuring this wrapper function impl doesn't trigger the compiler - * warning about using too new glib APIs. Finally in glibcompat.h we can - * add - * - * #define g_foo(a) vir_g_foo(a) - * - * Thus all the code elsewhere in libvirt, which *does* have the - * -Wdeprecated-declarations warning active, can call g_foo(...) as - * normal, without generating warnings. The cost is an extra function - * call when using new glib, but this compat code will go away over - * time as we update the supported platforms target. - */ - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" diff --git a/src/util/meson.build b/src/util/meson.build index 69ef49139a..4950a795cc 100644 --- a/src/util/meson.build +++ b/src/util/meson.build @@ -1,5 +1,4 @@ util_sources = [ - 'glibcompat.c', 'viracpi.c', 'viralloc.c', 'virarch.c', -- 2.50.1

On 9/10/25 10:43, Ján Tomko via Devel wrote:
Ján Tomko (2): build: bump minimum glib version to 2.68 util: remove glibcompat.c
meson.build | 2 +- src/conf/virdomainjob.c | 6 +- src/esx/esx_vi_types.c | 9 +- src/internal.h | 24 ---- src/libvirt_private.syms | 4 - src/qemu/qemu_capabilities.c | 8 +- src/util/glibcompat.c | 213 ----------------------------------- src/util/glibcompat.h | 29 ----- src/util/meson.build | 1 - 9 files changed, 13 insertions(+), 283 deletions(-) delete mode 100644 src/util/glibcompat.c
Reviewed-by: Michal Privoznik <mprivozn@redhat.com> Michal
participants (2)
-
Ján Tomko
-
Michal Prívozník