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
© 2016 - 2025 Red Hat, Inc.