[PATCH 13/32] error-report: replace deprecated g_get_current_time() with glib >= 2.62

marcandre.lureau@redhat.com posted 32 patches 2 years, 2 months ago
Maintainers: Cameron Esfahani <dirty@apple.com>, Roman Bolshakov <r.bolshakov@yadro.com>, Paolo Bonzini <pbonzini@redhat.com>, Richard Henderson <richard.henderson@linaro.org>, Gerd Hoffmann <kraxel@redhat.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, David Hildenbrand <david@redhat.com>, Igor Mammedov <imammedo@redhat.com>, Stefan Berger <stefanb@linux.vnet.ibm.com>, Kevin Wolf <kwolf@redhat.com>, Hanna Reitz <hreitz@redhat.com>, Stefan Hajnoczi <stefanha@redhat.com>, Fam Zheng <fam@euphon.net>, Aarushi Mehta <mehta.aaru20@gmail.com>, Julia Suvorova <jusual@redhat.com>, Stefano Garzarella <sgarzare@redhat.com>, Ronnie Sahlberg <ronniesahlberg@gmail.com>, Peter Lieven <pl@kamp.de>, "Philippe Mathieu-Daudé" <f4bug@amsat.org>, "Denis V. Lunev" <den@openvz.org>, Vladimir Sementsov-Ogievskiy <v.sementsov-og@mail.ru>, Warner Losh <imp@bsdimp.com>, Kyle Evans <kevans@freebsd.org>, Laurent Vivier <laurent@vivier.eu>, "Michael S. Tsirkin" <mst@redhat.com>, Eduardo Habkost <eduardo@habkost.net>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, Yanan Wang <wangyanan55@huawei.com>, "Daniel P. Berrangé" <berrange@redhat.com>, Greg Kurz <groug@kaod.org>, Christian Schoenebeck <qemu_oss@crudebyte.com>, "Alex Bennée" <alex.bennee@linaro.org>, Peter Maydell <peter.maydell@linaro.org>, Michael Rolnik <mrolnik@gmail.com>, Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>, Alistair Francis <alistair@alistair23.me>, "Edgar E. Iglesias" <edgar.iglesias@gmail.com>, Helge Deller <deller@gmx.de>, Cornelia Huck <cohuck@redhat.com>, Thomas Huth <thuth@redhat.com>, Halil Pasic <pasic@linux.ibm.com>, Christian Borntraeger <borntraeger@linux.ibm.com>, "Cédric Le Goater" <clg@kaod.org>, Daniel Henrique Barboza <danielhb413@gmail.com>, David Gibson <david@gibson.dropbear.id.au>, Huacai Chen <chenhuacai@kernel.org>, Jiaxun Yang <jiaxun.yang@flygoat.com>, Aurelien Jarno <aurelien@aurel32.net>, "Hervé Poussineau" <hpoussin@reactos.org>, Aleksandar Rikalo <aleksandar.rikalo@syrmia.com>, Pavel Pisa <pisa@cmp.felk.cvut.cz>, Vikram Garhwal <fnu.vikram@xilinx.com>, Jason Wang <jasowang@redhat.com>, Subbaraya Sundeep <sundeep.lkml@gmail.com>, Havard Skinnemoen <hskinnemoen@google.com>, Tyrone Ting <kfting@nuvoton.com>, Dmitry Fleytman <dmitry.fleytman@gmail.com>, Chris Wulff <crwulff@gmail.com>, Marek Vasut <marex@denx.de>, BALATON Zoltan <balaton@eik.bme.hu>, Elena Ufimtseva <elena.ufimtseva@oracle.com>, Jagannathan Raman <jag.raman@oracle.com>, John G Johnson <john.g.johnson@oracle.com>, Alexey Kardashevskiy <aik@ozlabs.ru>, Yuval Shaia <yuval.shaia.ml@gmail.com>, Palmer Dabbelt <palmer@dabbelt.com>, Bin Meng <bin.meng@windriver.com>, Yoshinori Sato <ysato@users.sourceforge.jp>, Eric Farman <farman@linux.ibm.com>, Fabien Chouteau <chouteau@adacore.com>, KONRAD Frederic <frederic.konrad@adacore.com>, Artyom Tarasenko <atar4qemu@gmail.com>, Alex Williamson <alex.williamson@redhat.com>, Eric Auger <eric.auger@redhat.com>, Max Filippov <jcmvbkbc@gmail.com>, Peter Xu <peterx@redhat.com>, Markus Armbruster <armbru@redhat.com>, Stefan Weil <sw@weilnetz.de>, Taylor Simpson <tsimpson@quicinc.com>, Juan Quintela <quintela@redhat.com>, "Dr. David Alan Gilbert" <dgilbert@redhat.com>, Zhang Chen <chen.zhang@intel.com>, Li Zhijian <lizhijian@fujitsu.com>, Michael Roth <michael.roth@amd.com>, Alexander Graf <agraf@csgraf.de>, Wenchao Wang <wenchao.wang@intel.com>, Colin Xu <colin.xu@intel.com>, Marcelo Tosatti <mtosatti@redhat.com>, Kamil Rytarowski <kamil@netbsd.org>, Reinoud Zandijk <reinoud@netbsd.org>, Sunil Muthuswamy <sunilmut@microsoft.com>, Stafford Horne <shorne@gmail.com>, Bastian Koppelmann <kbastian@mail.uni-paderborn.de>, Ani Sinha <ani@anisinha.ca>, John Snow <jsnow@redhat.com>, Andrew Jeffery <andrew@aj.id.au>, Joel Stanley <joel@jms.id.au>, Alexander Bulekov <alxndr@bu.edu>, Bandan Das <bsd@redhat.com>, Darren Kenny <darren.kenny@oracle.com>, Qiuhao Li <Qiuhao.Li@outlook.com>, Corey Minyard <minyard@acm.org>, Coiby Xu <Coiby.Xu@gmail.com>, Akihiko Odaki <akihiko.odaki@gmail.com>
There is a newer version of this series
[PATCH 13/32] error-report: replace deprecated g_get_current_time() with glib >= 2.62
Posted by marcandre.lureau@redhat.com 2 years, 2 months ago
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
+
 #pragma GCC diagnostic pop
 
 #endif
diff --git a/util/qemu-error.c b/util/qemu-error.c
index 7769aee8e791..4ea380dd4169 100644
--- a/util/qemu-error.c
+++ b/util/qemu-error.c
@@ -180,6 +180,19 @@ static void print_loc(void)
     }
 }
 
+static char *
+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());
+    return g_date_time_format_iso8601(dt);
+#else
+    GTimeVal tv;
+    g_get_current_time(&tv);
+    return g_time_val_to_iso8601(&tv);
+#endif
+}
+
 /*
  * Print a message to current monitor if we have one, else to stderr.
  * @report_type is the type of message: error, warning or informational.
@@ -189,12 +202,10 @@ static void print_loc(void)
  */
 static void vreport(report_type type, const char *fmt, va_list ap)
 {
-    GTimeVal tv;
     gchar *timestr;
 
     if (message_with_timestamp && !monitor_cur()) {
-        g_get_current_time(&tv);
-        timestr = g_time_val_to_iso8601(&tv);
+        timestr = real_time_iso8601();
         error_printf("%s ", timestr);
         g_free(timestr);
     }
-- 
2.35.1.273.ge6ebfd0e8cbb


Re: [PATCH 13/32] error-report: replace deprecated g_get_current_time() with glib >= 2.62
Posted by Markus Armbruster 2 years, 2 months ago
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?

Else, I expect g_date_time_format_iso8601(dt) not to compile.

> +
>  #pragma GCC diagnostic pop
>  
>  #endif
> diff --git a/util/qemu-error.c b/util/qemu-error.c
> index 7769aee8e791..4ea380dd4169 100644
> --- a/util/qemu-error.c
> +++ b/util/qemu-error.c
> @@ -180,6 +180,19 @@ static void print_loc(void)
>      }
>  }
>  
> +static char *
> +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());
> +    return g_date_time_format_iso8601(dt);
> +#else
> +    GTimeVal tv;
> +    g_get_current_time(&tv);
> +    return g_time_val_to_iso8601(&tv);
> +#endif
> +}
> +
>  /*
>   * Print a message to current monitor if we have one, else to stderr.
>   * @report_type is the type of message: error, warning or informational.
> @@ -189,12 +202,10 @@ static void print_loc(void)
>   */
>  static void vreport(report_type type, const char *fmt, va_list ap)
>  {
> -    GTimeVal tv;
>      gchar *timestr;
>  
>      if (message_with_timestamp && !monitor_cur()) {
> -        g_get_current_time(&tv);
> -        timestr = g_time_val_to_iso8601(&tv);
> +        timestr = real_time_iso8601();
>          error_printf("%s ", timestr);
>          g_free(timestr);
>      }
Re: [PATCH 13/32] error-report: replace deprecated g_get_current_time() with glib >= 2.62
Posted by Marc-André Lureau 2 years, 2 months ago
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.

>
> Else, I expect g_date_time_format_iso8601(dt) not to compile.
>
> > +
> >  #pragma GCC diagnostic pop
> >
> >  #endif
> > diff --git a/util/qemu-error.c b/util/qemu-error.c
> > index 7769aee8e791..4ea380dd4169 100644
> > --- a/util/qemu-error.c
> > +++ b/util/qemu-error.c
> > @@ -180,6 +180,19 @@ static void print_loc(void)
> >      }
> >  }
> >
> > +static char *
> > +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());
> > +    return g_date_time_format_iso8601(dt);
> > +#else
> > +    GTimeVal tv;
> > +    g_get_current_time(&tv);
> > +    return g_time_val_to_iso8601(&tv);
> > +#endif
> > +}
> > +
> >  /*
> >   * Print a message to current monitor if we have one, else to stderr.
> >   * @report_type is the type of message: error, warning or informational.
> > @@ -189,12 +202,10 @@ static void print_loc(void)
> >   */
> >  static void vreport(report_type type, const char *fmt, va_list ap)
> >  {
> > -    GTimeVal tv;
> >      gchar *timestr;
> >
> >      if (message_with_timestamp && !monitor_cur()) {
> > -        g_get_current_time(&tv);
> > -        timestr = g_time_val_to_iso8601(&tv);
> > +        timestr = real_time_iso8601();
> >          error_printf("%s ", timestr);
> >          g_free(timestr);
> >      }
>
Re: [PATCH 13/32] error-report: replace deprecated g_get_current_time() with glib >= 2.62
Posted by Marc-André Lureau 2 years, 2 months ago
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.

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;


>
> >
> > Else, I expect g_date_time_format_iso8601(dt) not to compile.
> >
> > > +
> > >  #pragma GCC diagnostic pop
> > >
> > >  #endif
> > > diff --git a/util/qemu-error.c b/util/qemu-error.c
> > > index 7769aee8e791..4ea380dd4169 100644
> > > --- a/util/qemu-error.c
> > > +++ b/util/qemu-error.c
> > > @@ -180,6 +180,19 @@ static void print_loc(void)
> > >      }
> > >  }
> > >
> > > +static char *
> > > +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());
> > > +    return g_date_time_format_iso8601(dt);
> > > +#else
> > > +    GTimeVal tv;
> > > +    g_get_current_time(&tv);
> > > +    return g_time_val_to_iso8601(&tv);
> > > +#endif
> > > +}
> > > +
> > >  /*
> > >   * Print a message to current monitor if we have one, else to stderr.
> > >   * @report_type is the type of message: error, warning or informational.
> > > @@ -189,12 +202,10 @@ static void print_loc(void)
> > >   */
> > >  static void vreport(report_type type, const char *fmt, va_list ap)
> > >  {
> > > -    GTimeVal tv;
> > >      gchar *timestr;
> > >
> > >      if (message_with_timestamp && !monitor_cur()) {
> > > -        g_get_current_time(&tv);
> > > -        timestr = g_time_val_to_iso8601(&tv);
> > > +        timestr = real_time_iso8601();
> > >          error_printf("%s ", timestr);
> > >          g_free(timestr);
> > >      }
> >
Re: [PATCH 13/32] error-report: replace deprecated g_get_current_time() with glib >= 2.62
Posted by Markus Armbruster 2 years, 2 months ago
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?

[...]