[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 13/32] error-report: replace deprecated g_get_current_time()
From: |
Markus Armbruster |
Subject: |
Re: [PATCH 13/32] error-report: replace deprecated g_get_current_time() with glib >= 2.62 |
Date: |
Wed, 06 Apr 2022 12:38:16 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) |
Marc-André Lureau <marcandre.lureau@redhat.com> writes:
> On Wed, Apr 6, 2022 at 1:35 PM Marc-André Lureau
> <marcandre.lureau@redhat.com> wrote:
>>
>> Hi
>>
>> On Wed, Apr 6, 2022 at 1:08 PM Markus Armbruster <armbru@redhat.com> wrote:
>> >
>> > marcandre.lureau@redhat.com writes:
>> >
>> > > From: Marc-André Lureau <marcandre.lureau@redhat.com>
>> > >
>> > > According to GLib API:
>> > > g_get_current_time has been deprecated since version 2.62 and should not
>> > > be used in newly-written code. GTimeVal is not year-2038-safe. Use
>> > > g_get_real_time() instead.
>> > >
>> > > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
>> > > ---
>> > > include/glib-compat.h | 10 ++++++++++
>> > > util/qemu-error.c | 17 ++++++++++++++---
>> > > 2 files changed, 24 insertions(+), 3 deletions(-)
>> > >
>> > > diff --git a/include/glib-compat.h b/include/glib-compat.h
>> > > index 3113a7d2af84..dc14d3ec0d1e 100644
>> > > --- a/include/glib-compat.h
>> > > +++ b/include/glib-compat.h
>> > > @@ -145,6 +145,16 @@ qemu_g_test_slow(void)
>> > > #define g_test_thorough() qemu_g_test_slow()
>> > > #define g_test_quick() (!qemu_g_test_slow())
>> > >
>> > > +#if GLIB_CHECK_VERSION(2,62,0)
>> > > +static inline gchar *
>> > > +g_date_time_format_iso8601_compat(GDateTime *datetime)
>> > > +{
>> > > + return g_date_time_format_iso8601(datetime);
>> > > +}
>> > > +
>> > > +#define g_date_time_format_iso8601 g_date_time_format_iso8601_compat
>> > > +#endif
>> >
>> > I'm confused.
>> >
>> > If we're using v2.62 or later, g_time_val_to_iso8601(dt) calls GLib's
>> > g_time_val_to_iso8601(). Why do we need the inline function and the
>> > macro?
>>
>> To hide the "deprecation" warning because GLIB_VERSION_MAX_ALLOWED is 2.56.
Ah, now I see!
> This is probably a better solution, I will change the patch:
>
> --- a/util/qemu-error.c
> +++ b/util/qemu-error.c
> @@ -185,7 +185,10 @@ real_time_iso8601(void)
> {
> #if GLIB_CHECK_VERSION(2,62,0)
> g_autoptr(GDateTime) dt =
> g_date_time_new_from_unix_utc(g_get_real_time());
> +#pragma GCC diagnostic push
> +#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
> return g_date_time_format_iso8601(dt);
> +#pragma GCC diagnostic pop
> #else
> GTimeVal tv;
Yup, this is clearer. Throw in a comment, perhaps?
[...]