Skip to contentSkip to conversation

contrib/plugins/execlog: Fix compiler warning

PATCH Superseded Yao Xingtao via 4 participants 16 messages Mar 20, 2024 – Mar 27, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 contrib/plugins/execlog: Fix compiler warning

1. The g_pattern_match_string() is deprecated when glib2 version >= 2.70. Use g_pattern_spec_match_string() instead to avoid this problem.

2. The type of second parameter in g_ptr_array_add() is 'gpointer' {aka 'void *'}, but the type of reg->name is 'const char*'. Cast the type of reg->name to 'gpointer' to avoid this problem.

compiler warning message:
/root/qemu/contrib/plugins/execlog.c:330:17: warning: ‘g_pattern_match_string’ is deprecated: Use 'g_pattern_spec_match_string'
instead [-Wdeprecated-declarations]

  330 |                 if (g_pattern_match_string(pat, rd->name) ||
      |                 ^~
In file included from /usr/include/glib-2.0/glib.h:67,
                 from /root/qemu/contrib/plugins/execlog.c:9:
/usr/include/glib-2.0/glib/gpattern.h:57:15: note: declared here
   57 | gboolean      g_pattern_match_string   (GPatternSpec *pspec,
      |               ^~~~~~~~~~~~~~~~~~~~~~
/root/qemu/contrib/plugins/execlog.c:331:21: warning: ‘g_pattern_match_string’
is deprecated: Use 'g_pattern_spec_match_string'
instead [-Wdeprecated-declarations]
  331 |                     g_pattern_match_string(pat, rd_lower)) {
      |                     ^~~~~~~~~~~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gpattern.h:57:15: note: declared here
   57 | gboolean      g_pattern_match_string   (GPatternSpec *pspec,
      |               ^~~~~~~~~~~~~~~~~~~~~~

/root/qemu/contrib/plugins/execlog.c:339:63: warning: passing argument 2 of ‘g_ptr_array_add’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
339 | g_ptr_array_add(all_reg_names, reg->name);
| ~~~^~~~~~
In file included from /usr/include/glib-2.0/glib.h:33:
/usr/include/glib-2.0/glib/garray.h:198:62: note: expected ‘gpointer’ {aka ‘void *’} but argument is of type ‘const char *’

  198 |                                            gpointer          data);
      |                                            ~~~~~~~~~~~~~~~~~~^~~~
---
 contrib/plugins/execlog.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
contrib/plugins/execlog.c +6 -1
index a1dfd59ab7..41f6774116 100644
@@ -327,8 +327,13 @@ static GPtrArray *registers_init(int vcpu_index)
             for (int p = 0; p < rmatches->len; p++) {
                 g_autoptr(GPatternSpec) pat = g_pattern_spec_new(rmatches->pdata[p]);
                 g_autofree gchar *rd_lower = g_utf8_strdown(rd->name, -1);
+#if GLIB_VERSION_MAX_ALLOWED < G_ENCODE_VERSION(2, 70)
                 if (g_pattern_match_string(pat, rd->name) ||
                     g_pattern_match_string(pat, rd_lower)) {
+#else
+                if (g_pattern_spec_match_string(pat, rd->name) ||
+                    g_pattern_spec_match_string(pat, rd_lower)) {
+#endif
                     Register *reg = init_vcpu_register(rd);
                     g_ptr_array_add(registers, reg);
 
@@ -336,7 +341,7 @@ static GPtrArray *registers_init(int vcpu_index)
                     if (disas_assist) {
                         g_mutex_lock(&add_reg_name_lock);
                         if (!g_ptr_array_find(all_reg_names, reg->name, NULL)) {
-                            g_ptr_array_add(all_reg_names, reg->name);
+                            g_ptr_array_add(all_reg_names, (gpointer)reg->name);
                         }
                         g_mutex_unlock(&add_reg_name_lock);
                     }
Signature · 1 line
2.37.3
#1 lore raw
Quoted 35 lines · Yao Xingtao via

1. The g_pattern_match_string() is deprecated when glib2 version >= 2.70. Use g_pattern_spec_match_string() instead to avoid this problem.

2. The type of second parameter in g_ptr_array_add() is 'gpointer' {aka 'void *'}, but the type of reg->name is 'const char*'. Cast the type of reg->name to 'gpointer' to avoid this problem.

compiler warning message:
/root/qemu/contrib/plugins/execlog.c:330:17: warning: ‘g_pattern_match_string’ is deprecated: Use 'g_pattern_spec_match_string'
instead [-Wdeprecated-declarations]

  330 |                 if (g_pattern_match_string(pat, rd->name) ||
      |                 ^~
In file included from /usr/include/glib-2.0/glib.h:67,
                 from /root/qemu/contrib/plugins/execlog.c:9:
/usr/include/glib-2.0/glib/gpattern.h:57:15: note: declared here
   57 | gboolean      g_pattern_match_string   (GPatternSpec *pspec,
      |               ^~~~~~~~~~~~~~~~~~~~~~
/root/qemu/contrib/plugins/execlog.c:331:21: warning: ‘g_pattern_match_string’
is deprecated: Use 'g_pattern_spec_match_string'
instead [-Wdeprecated-declarations]
  331 |                     g_pattern_match_string(pat, rd_lower)) {
      |                     ^~~~~~~~~~~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gpattern.h:57:15: note: declared here
   57 | gboolean      g_pattern_match_string   (GPatternSpec *pspec,
      |               ^~~~~~~~~~~~~~~~~~~~~~

/root/qemu/contrib/plugins/execlog.c:339:63: warning: passing argument 2 of ‘g_ptr_array_add’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
339 | g_ptr_array_add(all_reg_names, reg->name);
| ~~~^~~~~~
In file included from /usr/include/glib-2.0/glib.h:33:
/usr/include/glib-2.0/glib/garray.h:198:62: note: expected ‘gpointer’ {aka ‘void *’} but argument is of type ‘const char *’

Quoted 3 lines
  198 |                                            gpointer          data);
      |                                            ~~~~~~~~~~~~~~~~~~^~~~

Hi; thanks for this patch.

This fixes a bug reported in the bug tracker so we should put

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2210

in the commit message just above your signed-off-by tag.

Quoted 10 lines
---
 contrib/plugins/execlog.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
contrib/plugins/execlog.c +0 -0
index a1dfd59ab7..41f6774116 100644

contrib/plugins/execlog.c static GPtrArray *registers_init(int vcpu_index) · line 330

Quoted 4 lines
contrib/plugins/execlog.c +1 -0
@@ -327,8 +327,13 @@ static GPtrArray *registers_init(int vcpu_index)
             for (int p = 0; p < rmatches->len; p++) {
                 g_autoptr(GPatternSpec) pat = g_pattern_spec_new(rmatches->pdata[p]);
                 g_autofree gchar *rd_lower = g_utf8_strdown(rd->name, -1);
+#if GLIB_VERSION_MAX_ALLOWED < G_ENCODE_VERSION(2, 70)

Elsewhere we do glib version checks with

#if GLIB_CHECK_VERSION(2, 70, 0)
    code for 2.70.0 and up;

#else
code for older versions
#endif

so I think we should probably do that here too.

contrib/plugins/execlog.c static GPtrArray *registers_init(int vcpu_index) · line 336

Quoted 6 lines
contrib/plugins/execlog.c +4 -0
                 if (g_pattern_match_string(pat, rd->name) ||
                     g_pattern_match_string(pat, rd_lower)) {
+#else
+                if (g_pattern_spec_match_string(pat, rd->name) ||
+                    g_pattern_spec_match_string(pat, rd_lower)) {
+#endif

Rather than putting this ifdef in the middle of this function, I think it would be easier to read if we abstract out a function which does the pattern matching and whose body calls the right glib function depending on glib version. We generally call these functions the same as the glib function but with a _qemu suffix (compare the ones in include/glib-compat.h), so here that would be g_pattern_spec_match_string_qemu().

contrib/plugins/execlog.c static GPtrArray *registers_init(int vcpu_index) · line 347

Quoted 12 lines
contrib/plugins/execlog.c +1 -1
                     Register *reg = init_vcpu_register(rd);
                     g_ptr_array_add(registers, reg);
 
@@ -336,7 +341,7 @@ static GPtrArray *registers_init(int vcpu_index)
                     if (disas_assist) {
                         g_mutex_lock(&add_reg_name_lock);
                         if (!g_ptr_array_find(all_reg_names, reg->name, NULL)) {
-                            g_ptr_array_add(all_reg_names, reg->name);
+                            g_ptr_array_add(all_reg_names, (gpointer)reg->name);
                         }
                         g_mutex_unlock(&add_reg_name_lock);
                     }

thanks
-- PMM

#2 lore raw

Pete:
Thanks for your comment.

I also find a similar patch written by Pierrick: https://lore.kernel.org/qemu-devel/[email protected]/
but for some reason, the patch was not merged yet.

shall I need to continue tracking the fixes of this bug?

Quoted 55 lines

-----Original Message-----
From: Peter Maydell <[email protected]>
Sent: Friday, March 22, 2024 7:50 PM
To: Yao, Xingtao/姚 幸涛 <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH] contrib/plugins/execlog: Fix compiler warning

Quoted 10 lines · Yao Xingtao via

1. The g_pattern_match_string() is deprecated when glib2 version >= 2.70. Use g_pattern_spec_match_string() instead to avoid this problem.

2. The type of second parameter in g_ptr_array_add() is 'gpointer' {aka 'void *'}, but the type of reg->name is 'const char*'. Cast the type of reg->name to 'gpointer' to avoid this problem.

compiler warning message:
/root/qemu/contrib/plugins/execlog.c:330:17: warning:

‘g_pattern_match_string’

Quoted 10 lines

is deprecated: Use 'g_pattern_spec_match_string'
instead [-Wdeprecated-declarations]

  330 |                 if (g_pattern_match_string(pat, rd->name) ||
      |                 ^~
In file included from /usr/include/glib-2.0/glib.h:67,
                 from /root/qemu/contrib/plugins/execlog.c:9:
/usr/include/glib-2.0/glib/gpattern.h:57:15: note: declared here
   57 | gboolean      g_pattern_match_string   (GPatternSpec *pspec,
      |               ^~~~~~~~~~~~~~~~~~~~~~

/root/qemu/contrib/plugins/execlog.c:331:21: warning:

‘g_pattern_match_string’

Quoted 11 lines

is deprecated: Use 'g_pattern_spec_match_string'
instead [-Wdeprecated-declarations]

  331 |                     g_pattern_match_string(pat, rd_lower)) {
      |                     ^~~~~~~~~~~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gpattern.h:57:15: note: declared here
   57 | gboolean      g_pattern_match_string   (GPatternSpec *pspec,
      |               ^~~~~~~~~~~~~~~~~~~~~~

/root/qemu/contrib/plugins/execlog.c:339:63: warning: passing argument 2 of ‘g_ptr_array_add’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
339 | g_ptr_array_add(all_reg_names,

reg->name);

Quoted 1 line
      |

~~~^~~~~~

Quoted 4 lines

In file included from /usr/include/glib-2.0/glib.h:33:
/usr/include/glib-2.0/glib/garray.h:198:62: note: expected ‘gpointer’ {aka ‘void *’} but argument is of type ‘const char *’
198 | gpointer

data);

Quoted 1 line
      |

~~~~~~~~~~~~~~~~~~^~~~

Quoted 1 line
Quoted 10 lines

Hi; thanks for this patch.

This fixes a bug reported in the bug tracker so we should put

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2210

in the commit message just above your signed-off-by tag.

Quoted 1 line

I will if needed.

Quoted 24 lines

contrib/plugins/execlog.c static GPtrArray *registers_init(int vcpu_index) · line 328

Quoted 11 lines
---
 contrib/plugins/execlog.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
contrib/plugins/execlog.c +0 -0
index a1dfd59ab7..41f6774116 100644
@@ -327,8 +327,13 @@ static GPtrArray *registers_init(int vcpu_index)
             for (int p = 0; p < rmatches->len; p++) {
                 g_autoptr(GPatternSpec) pat =

g_pattern_spec_new(rmatches->pdata[p]);

contrib/plugins/execlog.c static GPtrArray *registers_init(int vcpu_index) · line 330

Quoted 3 lines
contrib/plugins/execlog.c +1 -1
                 g_autofree gchar *rd_lower = g_utf8_strdown(rd->name,
-1);
+#if GLIB_VERSION_MAX_ALLOWED < G_ENCODE_VERSION(2, 70)

Elsewhere we do glib version checks with

#if GLIB_CHECK_VERSION(2, 70, 0)
    code for 2.70.0 and up;

#else
code for older versions
#endif

Quoted 8 lines

so I think we should probably do that here too.

contrib/plugins/execlog.c static GPtrArray *registers_init(int vcpu_index) · line 336

Quoted 6 lines
contrib/plugins/execlog.c +4 -0
                 if (g_pattern_match_string(pat, rd->name) ||
                     g_pattern_match_string(pat, rd_lower)) {
+#else
+                if (g_pattern_spec_match_string(pat, rd->name) ||
+                    g_pattern_spec_match_string(pat, rd_lower)) {
+#endif

thanks, I got it.

Quoted 8 lines

Rather than putting this ifdef in the middle of this function, I think it would be easier to read if we abstract out a function which does the pattern matching and whose body calls the right glib function depending on glib version. We generally call these functions the same as the glib function but with a _qemu suffix (compare the ones in include/glib-compat.h), so here that would be g_pattern_spec_match_string_qemu().

Quoted 15 lines

contrib/plugins/execlog.c static GPtrArray *registers_init(int vcpu_index) · line 343

Quoted 7 lines
contrib/plugins/execlog.c +0 -0
                     Register *reg = init_vcpu_register(rd);
                     g_ptr_array_add(registers, reg);
@@ -336,7 +341,7 @@ static GPtrArray *registers_init(int vcpu_index)
                     if (disas_assist) {
                         g_mutex_lock(&add_reg_name_lock);
                         if (!g_ptr_array_find(all_reg_names, reg->name,

NULL)) {

Quoted 6 lines
contrib/plugins/execlog.c +2 -1
-                            g_ptr_array_add(all_reg_names, reg->name);
+                            g_ptr_array_add(all_reg_names,
+ (gpointer)reg->name);
                         }
                         g_mutex_unlock(&add_reg_name_lock);
                     }

I think it's not worth adding this to glib-compat.h too.

Quoted 2 lines

thanks
-- PMM

thanks
Xingtao

#3 lore raw
Quoted 8 lines · Xingtao Yao (Fujitsu)

Pete:
Thanks for your comment.

I also find a similar patch written by Pierrick: https://lore.kernel.org/qemu-devel/[email protected]/
but for some reason, the patch was not merged yet.

shall I need to continue tracking the fixes of this bug?

Hi Xingtao,

you're doing the right thing here. In my original patch, there was no consideration for backward compatibility, to the opposite of what you did.

Alex will be out for several weeks, so it might take some time to get this merged, but I'm definitely voting for this 👍.

Pierrick

Quoted 131 lines
Quoted 55 lines

-----Original Message-----
From: Peter Maydell <[email protected]>
Sent: Friday, March 22, 2024 7:50 PM
To: Yao, Xingtao/姚 幸涛 <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH] contrib/plugins/execlog: Fix compiler warning

Quoted 10 lines · Yao Xingtao via

1. The g_pattern_match_string() is deprecated when glib2 version >= 2.70. Use g_pattern_spec_match_string() instead to avoid this problem.

2. The type of second parameter in g_ptr_array_add() is

    'gpointer' {aka 'void *'}, but the type of reg->name is 'const char*'.
    Cast the type of reg->name to 'gpointer' to avoid this problem.

compiler warning message:
/root/qemu/contrib/plugins/execlog.c:330:17: warning:

‘g_pattern_match_string’

Quoted 10 lines

is deprecated: Use 'g_pattern_spec_match_string'
instead [-Wdeprecated-declarations]

   330 |                 if (g_pattern_match_string(pat, rd->name) ||
       |                 ^~
In file included from /usr/include/glib-2.0/glib.h:67,
                  from /root/qemu/contrib/plugins/execlog.c:9:
/usr/include/glib-2.0/glib/gpattern.h:57:15: note: declared here
    57 | gboolean      g_pattern_match_string   (GPatternSpec *pspec,
       |               ^~~~~~~~~~~~~~~~~~~~~~

/root/qemu/contrib/plugins/execlog.c:331:21: warning:

‘g_pattern_match_string’

Quoted 11 lines

is deprecated: Use 'g_pattern_spec_match_string'
instead [-Wdeprecated-declarations]

   331 |                     g_pattern_match_string(pat, rd_lower)) {
       |                     ^~~~~~~~~~~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gpattern.h:57:15: note: declared here
    57 | gboolean      g_pattern_match_string   (GPatternSpec *pspec,
       |               ^~~~~~~~~~~~~~~~~~~~~~

/root/qemu/contrib/plugins/execlog.c:339:63: warning: passing argument 2 of ‘g_ptr_array_add’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
339 | g_ptr_array_add(all_reg_names,

reg->name);

Quoted 1 line
       |

~~~^~~~~~

Quoted 4 lines

In file included from /usr/include/glib-2.0/glib.h:33:
/usr/include/glib-2.0/glib/garray.h:198:62: note: expected ‘gpointer’ {aka ‘void *’} but argument is of type ‘const char *’
198 | gpointer

data);

Quoted 1 line
       |

~~~~~~~~~~~~~~~~~~^~~~

Quoted 1 line
Quoted 10 lines

Hi; thanks for this patch.

This fixes a bug reported in the bug tracker so we should put

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2210

in the commit message just above your signed-off-by tag.

Quoted 1 line

I will if needed.

Quoted 24 lines

contrib/plugins/execlog.c static GPtrArray *registers_init(int vcpu_index) · line 328

Quoted 11 lines
---
  contrib/plugins/execlog.c | 7 ++++++-
  1 file changed, 6 insertions(+), 1 deletion(-)
contrib/plugins/execlog.c +0 -0
index a1dfd59ab7..41f6774116 100644
@@ -327,8 +327,13 @@ static GPtrArray *registers_init(int vcpu_index)
              for (int p = 0; p < rmatches->len; p++) {
                  g_autoptr(GPatternSpec) pat =

g_pattern_spec_new(rmatches->pdata[p]);

contrib/plugins/execlog.c static GPtrArray *registers_init(int vcpu_index) · line 330

Quoted 3 lines
contrib/plugins/execlog.c +1 -1
                  g_autofree gchar *rd_lower = g_utf8_strdown(rd->name,
-1);
+#if GLIB_VERSION_MAX_ALLOWED < G_ENCODE_VERSION(2, 70)

Elsewhere we do glib version checks with

#if GLIB_CHECK_VERSION(2, 70, 0)
     code for 2.70.0 and up;

#else
code for older versions
#endif

Quoted 8 lines

so I think we should probably do that here too.

contrib/plugins/execlog.c static GPtrArray *registers_init(int vcpu_index) · line 336

Quoted 6 lines
contrib/plugins/execlog.c +4 -0
                  if (g_pattern_match_string(pat, rd->name) ||
                      g_pattern_match_string(pat, rd_lower)) {
+#else
+                if (g_pattern_spec_match_string(pat, rd->name) ||
+                    g_pattern_spec_match_string(pat, rd_lower)) {
+#endif

thanks, I got it.

Quoted 8 lines

Rather than putting this ifdef in the middle of this function, I think it would be easier to read if we abstract out a function which does the pattern matching and whose body calls the right glib function depending on glib version. We generally call these functions the same as the glib function but with a _qemu suffix (compare the ones in include/glib-compat.h), so here that would be g_pattern_spec_match_string_qemu().

Quoted 15 lines

contrib/plugins/execlog.c static GPtrArray *registers_init(int vcpu_index) · line 343

Quoted 7 lines
contrib/plugins/execlog.c +0 -0
                      Register *reg = init_vcpu_register(rd);
                      g_ptr_array_add(registers, reg);
@@ -336,7 +341,7 @@ static GPtrArray *registers_init(int vcpu_index)
                      if (disas_assist) {
                          g_mutex_lock(&add_reg_name_lock);
                          if (!g_ptr_array_find(all_reg_names, reg->name,

NULL)) {

Quoted 6 lines
contrib/plugins/execlog.c +2 -1
-                            g_ptr_array_add(all_reg_names, reg->name);
+                            g_ptr_array_add(all_reg_names,
+ (gpointer)reg->name);
                          }
                          g_mutex_unlock(&add_reg_name_lock);
                      }

I think it's not worth adding this to glib-compat.h too.

Quoted 2 lines

thanks
-- PMM

thanks
Xingtao

#4 lore raw

Hi Pierrick,

thanks for your reply, and I will modify and push the patch later.

thanks
Xingtao

Quoted 168 lines

-----Original Message-----
From: Pierrick Bouvier <[email protected]>
Sent: Monday, March 25, 2024 12:31 PM
To: Yao, Xingtao/姚 幸涛 <[email protected]>; Peter Maydell <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH] contrib/plugins/execlog: Fix compiler warning

Quoted 9 lines · Xingtao Yao (Fujitsu)

Pete:
Thanks for your comment.

I also find a similar patch written by Pierrick:
https://lore.kernel.org/qemu-devel/20240118032400.3762658-15-pierrick.
[email protected]/ but for some reason, the patch was not merged yet.

shall I need to continue tracking the fixes of this bug?

Hi Xingtao,

you're doing the right thing here. In my original patch, there was no consideration for backward compatibility, to the opposite of what you did.

Alex will be out for several weeks, so it might take some time to get this merged, but I'm definitely voting for this 👍.

Pierrick

Quoted 8 lines
Quoted 8 lines

-----Original Message-----
From: Peter Maydell <[email protected]>
Sent: Friday, March 22, 2024 7:50 PM
To: Yao, Xingtao/姚 幸涛 <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH] contrib/plugins/execlog: Fix compiler warning

Quoted 4 lines
Quoted 4 lines
Quoted 2 lines · Yao Xingtao via

1. The g_pattern_match_string() is deprecated when glib2 version >=

2.70.

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines

Use g_pattern_spec_match_string() instead to avoid this problem.

2. The type of second parameter in g_ptr_array_add() is

    'gpointer' {aka 'void *'}, but the type of reg->name is 'const char*'.
    Cast the type of reg->name to 'gpointer' to avoid this problem.

compiler warning message:
/root/qemu/contrib/plugins/execlog.c:330:17: warning:

‘g_pattern_match_string’

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

is deprecated: Use 'g_pattern_spec_match_string'
instead [-Wdeprecated-declarations]

   330 |                 if (g_pattern_match_string(pat, rd->name) ||
       |                 ^~

In file included from /usr/include/glib-2.0/glib.h:67,
from /root/qemu/contrib/plugins/execlog.c:9:
/usr/include/glib-2.0/glib/gpattern.h:57:15: note: declared here
57 | gboolean g_pattern_match_string (GPatternSpec

*pspec,

Quoted 9 lines
Quoted 9 lines
Quoted 2 lines
       |               ^~~~~~~~~~~~~~~~~~~~~~

/root/qemu/contrib/plugins/execlog.c:331:21: warning:

‘g_pattern_match_string’

Quoted 6 lines

is deprecated: Use 'g_pattern_spec_match_string'
instead [-Wdeprecated-declarations]

   331 |                     g_pattern_match_string(pat, rd_lower)) {
       |                     ^~~~~~~~~~~~~~~~~~~~~~

/usr/include/glib-2.0/glib/gpattern.h:57:15: note: declared here
57 | gboolean g_pattern_match_string (GPatternSpec

*pspec,

Quoted 56 lines
Quoted 18 lines
Quoted 6 lines
       |               ^~~~~~~~~~~~~~~~~~~~~~

/root/qemu/contrib/plugins/execlog.c:339:63: warning: passing argument
2 of ‘g_ptr_array_add’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
339 | g_ptr_array_add(all_reg_names,

reg->name);

Quoted 1 line
       |

~~~^~~~~~

Quoted 4 lines

In file included from /usr/include/glib-2.0/glib.h:33:
/usr/include/glib-2.0/glib/garray.h:198:62: note: expected ‘gpointer’ {aka ‘void *’} but argument is of type ‘const char *’
198 | gpointer

data);

Quoted 1 line
       |

~~~~~~~~~~~~~~~~~~^~~~

Quoted 1 line
Quoted 10 lines

Hi; thanks for this patch.

This fixes a bug reported in the bug tracker so we should put

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2210

in the commit message just above your signed-off-by tag.

Quoted 1 line

I will if needed.

Quoted 26 lines

contrib/plugins/execlog.c static GPtrArray *registers_init(int vcpu_index) · line 328

Quoted 11 lines
---
  contrib/plugins/execlog.c | 7 ++++++-
  1 file changed, 6 insertions(+), 1 deletion(-)
contrib/plugins/execlog.c +0 -0
index a1dfd59ab7..41f6774116 100644
@@ -327,8 +327,13 @@ static GPtrArray *registers_init(int vcpu_index)
              for (int p = 0; p < rmatches->len; p++) {
                  g_autoptr(GPatternSpec) pat =

g_pattern_spec_new(rmatches->pdata[p]);

contrib/plugins/execlog.c static GPtrArray *registers_init(int vcpu_index) · line 331

Quoted 3 lines
contrib/plugins/execlog.c +1 -0
                  g_autofree gchar *rd_lower =
 g_utf8_strdown(rd->name, -1);
+#if GLIB_VERSION_MAX_ALLOWED < G_ENCODE_VERSION(2, 70)

Elsewhere we do glib version checks with

#if GLIB_CHECK_VERSION(2, 70, 0)
     code for 2.70.0 and up;

#else
code for older versions
#endif

so I think we should probably do that here too.

Quoted 15 lines
Quoted 6 lines

contrib/plugins/execlog.c static GPtrArray *registers_init(int vcpu_index) · line 336

Quoted 6 lines
contrib/plugins/execlog.c +4 -0
                  if (g_pattern_match_string(pat, rd->name) ||
                      g_pattern_match_string(pat, rd_lower)) {
+#else
+                if (g_pattern_spec_match_string(pat, rd->name) ||
+                    g_pattern_spec_match_string(pat, rd_lower)) {
+#endif

thanks, I got it.

Quoted 7 lines

Rather than putting this ifdef in the middle of this function, I think it would be easier to read if we abstract out a function which does the pattern matching and whose body calls the right glib function depending on glib version. We generally call these functions the same as the glib function but with a _qemu suffix (compare the ones in include/glib-compat.h), so here that would be

g_pattern_spec_match_string_qemu().

Quoted 11 lines
Quoted 11 lines

contrib/plugins/execlog.c static GPtrArray *registers_init(int vcpu_index) · line 344

Quoted 9 lines
contrib/plugins/execlog.c +0 -0
                      Register *reg = init_vcpu_register(rd);
                      g_ptr_array_add(registers, reg);
@@ -336,7 +341,7 @@ static GPtrArray *registers_init(int vcpu_index)
                      if (disas_assist) {
                          g_mutex_lock(&add_reg_name_lock);
                          if (!g_ptr_array_find(all_reg_names,
 reg->name,

NULL)) {

Quoted 1 line
contrib/plugins/execlog.c +0 -1
-                            g_ptr_array_add(all_reg_names,

reg->name);

Quoted 13 lines
Quoted 6 lines

contrib/plugins/execlog.c static GPtrArray *registers_init(int vcpu_index) · line 347

Quoted 5 lines
contrib/plugins/execlog.c +2 -0
+                            g_ptr_array_add(all_reg_names,
+ (gpointer)reg->name);
                          }
                          g_mutex_unlock(&add_reg_name_lock);
                      }

I think it's not worth adding this to glib-compat.h too.

Quoted 2 lines

thanks
-- PMM

thanks
Xingtao

#5 lore raw

PATCH v2 1/1 contrib/plugins/execlog: Fix compiler warning

In reply to Yao Xingtao via

1. The g_pattern_match_string() is deprecated when glib2 version >= 2.70. Use g_pattern_spec_match_string() instead to avoid this problem.

2. The type of second parameter in g_ptr_array_add() is 'gpointer' {aka 'void *'}, but the type of reg->name is 'const char*'. Cast the type of reg->name to 'gpointer' to avoid this problem.

compiler warning message:
/root/qemu/contrib/plugins/execlog.c:330:17: warning: ‘g_pattern_match_string’ is deprecated: Use 'g_pattern_spec_match_string'
instead [-Wdeprecated-declarations]

  330 |                 if (g_pattern_match_string(pat, rd->name) ||
      |                 ^~
In file included from /usr/include/glib-2.0/glib.h:67,
                 from /root/qemu/contrib/plugins/execlog.c:9:
/usr/include/glib-2.0/glib/gpattern.h:57:15: note: declared here
   57 | gboolean      g_pattern_match_string   (GPatternSpec *pspec,
      |               ^~~~~~~~~~~~~~~~~~~~~~
/root/qemu/contrib/plugins/execlog.c:331:21: warning: ‘g_pattern_match_string’
is deprecated: Use 'g_pattern_spec_match_string'
instead [-Wdeprecated-declarations]
  331 |                     g_pattern_match_string(pat, rd_lower)) {
      |                     ^~~~~~~~~~~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gpattern.h:57:15: note: declared here
   57 | gboolean      g_pattern_match_string   (GPatternSpec *pspec,
      |               ^~~~~~~~~~~~~~~~~~~~~~

/root/qemu/contrib/plugins/execlog.c:339:63: warning: passing argument 2 of ‘g_ptr_array_add’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
339 | g_ptr_array_add(all_reg_names, reg->name);
| ~~~^~~~~~
In file included from /usr/include/glib-2.0/glib.h:33:
/usr/include/glib-2.0/glib/garray.h:198:62: note: expected ‘gpointer’ {aka ‘void *’} but argument is of type ‘const char *’

  198 |                                            gpointer          data);
      |                                            ~~~~~~~~~~~~~~~~~~^~~~

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2210

---
 contrib/plugins/execlog.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
contrib/plugins/execlog.c +6 -1
index a1dfd59ab7..09654910ee 100644
@@ -327,8 +327,13 @@ static GPtrArray *registers_init(int vcpu_index)
             for (int p = 0; p < rmatches->len; p++) {
                 g_autoptr(GPatternSpec) pat = g_pattern_spec_new(rmatches->pdata[p]);
                 g_autofree gchar *rd_lower = g_utf8_strdown(rd->name, -1);
+#if GLIB_CHECK_VERSION(2, 70, 0)
+                if (g_pattern_spec_match_string(pat, rd->name) ||
+                    g_pattern_spec_match_string(pat, rd_lower)) {
+#else
                 if (g_pattern_match_string(pat, rd->name) ||
                     g_pattern_match_string(pat, rd_lower)) {
+#endif
                     Register *reg = init_vcpu_register(rd);
                     g_ptr_array_add(registers, reg);
 
@@ -336,7 +341,7 @@ static GPtrArray *registers_init(int vcpu_index)
                     if (disas_assist) {
                         g_mutex_lock(&add_reg_name_lock);
                         if (!g_ptr_array_find(all_reg_names, reg->name, NULL)) {
-                            g_ptr_array_add(all_reg_names, reg->name);
+                            g_ptr_array_add(all_reg_names, (gpointer)reg->name);
                         }
                         g_mutex_unlock(&add_reg_name_lock);
                     }
Signature · 1 line
2.37.3
#6 lore raw
Quoted 51 lines · Yao Xingtao

1. The g_pattern_match_string() is deprecated when glib2 version >= 2.70. Use g_pattern_spec_match_string() instead to avoid this problem.

2. The type of second parameter in g_ptr_array_add() is

    'gpointer' {aka 'void *'}, but the type of reg->name is 'const char*'.
    Cast the type of reg->name to 'gpointer' to avoid this problem.

compiler warning message:
/root/qemu/contrib/plugins/execlog.c:330:17: warning: ‘g_pattern_match_string’ is deprecated: Use 'g_pattern_spec_match_string'
instead [-Wdeprecated-declarations]

   330 |                 if (g_pattern_match_string(pat, rd->name) ||
       |                 ^~
In file included from /usr/include/glib-2.0/glib.h:67,
                  from /root/qemu/contrib/plugins/execlog.c:9:
/usr/include/glib-2.0/glib/gpattern.h:57:15: note: declared here
    57 | gboolean      g_pattern_match_string   (GPatternSpec *pspec,
       |               ^~~~~~~~~~~~~~~~~~~~~~
/root/qemu/contrib/plugins/execlog.c:331:21: warning: ‘g_pattern_match_string’
is deprecated: Use 'g_pattern_spec_match_string'
instead [-Wdeprecated-declarations]
   331 |                     g_pattern_match_string(pat, rd_lower)) {
       |                     ^~~~~~~~~~~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gpattern.h:57:15: note: declared here
    57 | gboolean      g_pattern_match_string   (GPatternSpec *pspec,
       |               ^~~~~~~~~~~~~~~~~~~~~~

/root/qemu/contrib/plugins/execlog.c:339:63: warning: passing argument 2 of ‘g_ptr_array_add’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
339 | g_ptr_array_add(all_reg_names, reg->name);
| ~~~^~~~~~
In file included from /usr/include/glib-2.0/glib.h:33:
/usr/include/glib-2.0/glib/garray.h:198:62: note: expected ‘gpointer’ {aka ‘void *’} but argument is of type ‘const char *’

   198 |                                            gpointer          data);
       |                                            ~~~~~~~~~~~~~~~~~~^~~~

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2210

---
  contrib/plugins/execlog.c | 7 ++++++-
  1 file changed, 6 insertions(+), 1 deletion(-)
contrib/plugins/execlog.c +0 -0
index a1dfd59ab7..09654910ee 100644
@@ -327,8 +327,13 @@ static GPtrArray *registers_init(int vcpu_index)
              for (int p = 0; p < rmatches->len; p++) {
                  g_autoptr(GPatternSpec) pat = g_pattern_spec_new(rmatches->pdata[p]);
                  g_autofree gchar *rd_lower = g_utf8_strdown(rd->name, -1);

contrib/plugins/execlog.c static GPtrArray *registers_init(int vcpu_index) · line 339

Quoted 10 lines
contrib/plugins/execlog.c +5 -0
+#if GLIB_CHECK_VERSION(2, 70, 0)
+                if (g_pattern_spec_match_string(pat, rd->name) ||
+                    g_pattern_spec_match_string(pat, rd_lower)) {
+#else
                  if (g_pattern_match_string(pat, rd->name) ||
                      g_pattern_match_string(pat, rd_lower)) {
+#endif
                      Register *reg = init_vcpu_register(rd);
                      g_ptr_array_add(registers, reg);
 

As suggested by Peter on previous version, you can declare a new function g_pattern_match_string_qemu in include/glib-compat.h which abstract this. You'll need to add include/ to Makefile as well, so glib-compat.h will be accessible to contrib plugins too.

Quoted 9 lines
contrib/plugins/execlog.c +1 -1
@@ -336,7 +341,7 @@ static GPtrArray *registers_init(int vcpu_index)
                      if (disas_assist) {
                          g_mutex_lock(&add_reg_name_lock);
                          if (!g_ptr_array_find(all_reg_names, reg->name, NULL)) {
-                            g_ptr_array_add(all_reg_names, reg->name);
+                            g_ptr_array_add(all_reg_names, (gpointer)reg->name);
                          }
                          g_mutex_unlock(&add_reg_name_lock);
                      }
#7 lore raw
Quoted 16 lines · Pierrick Bouvier
Quoted 14 lines · Yao Xingtao
contrib/plugins/execlog.c +4 -0
index a1dfd59ab7..09654910ee 100644
@@ -327,8 +327,13 @@ static GPtrArray *registers_init(int vcpu_index)
              for (int p = 0; p < rmatches->len; p++) {
                  g_autoptr(GPatternSpec) pat = g_pattern_spec_new(rmatches->pdata[p]);
                  g_autofree gchar *rd_lower = g_utf8_strdown(rd->name, -1);
+#if GLIB_CHECK_VERSION(2, 70, 0)
+                if (g_pattern_spec_match_string(pat, rd->name) ||
+                    g_pattern_spec_match_string(pat, rd_lower)) {
+#else
                  if (g_pattern_match_string(pat, rd->name) ||
                      g_pattern_match_string(pat, rd_lower)) {
Quoted 8 lines

contrib/plugins/execlog.c static GPtrArray *registers_init(int vcpu_index) · line 339

Quoted 4 lines
contrib/plugins/execlog.c +1 -0
+#endif
                      Register *reg = init_vcpu_register(rd);
                      g_ptr_array_add(registers, reg);
 

As suggested by Peter on previous version, you can declare a new function g_pattern_match_string_qemu in include/glib-compat.h which abstract this.

We should have an abstraction function, but it should *not* be in glib-compat.h, but local to this plugin's .c file. This is because the plugins are deliberately standalone binaries which do not rely on any of QEMU's include files or build process (you'll see they don't use osdep.h, for example).

thanks
-- PMM

#8 lore raw
Quoted 27 lines · Peter Maydell
Quoted 16 lines · Pierrick Bouvier
Quoted 14 lines · Yao Xingtao
contrib/plugins/execlog.c +4 -0
index a1dfd59ab7..09654910ee 100644
@@ -327,8 +327,13 @@ static GPtrArray *registers_init(int vcpu_index)
               for (int p = 0; p < rmatches->len; p++) {
                   g_autoptr(GPatternSpec) pat = g_pattern_spec_new(rmatches->pdata[p]);
                   g_autofree gchar *rd_lower = g_utf8_strdown(rd->name, -1);
+#if GLIB_CHECK_VERSION(2, 70, 0)
+                if (g_pattern_spec_match_string(pat, rd->name) ||
+                    g_pattern_spec_match_string(pat, rd_lower)) {
+#else
                   if (g_pattern_match_string(pat, rd->name) ||
                       g_pattern_match_string(pat, rd_lower)) {
Quoted 8 lines

contrib/plugins/execlog.c static GPtrArray *registers_init(int vcpu_index) · line 339

Quoted 4 lines
contrib/plugins/execlog.c +1 -0
+#endif
                       Register *reg = init_vcpu_register(rd);
                       g_ptr_array_add(registers, reg);
 

As suggested by Peter on previous version, you can declare a new function g_pattern_match_string_qemu in include/glib-compat.h which abstract this.

Quoted 6 lines

We should have an abstraction function, but it should *not* be in glib-compat.h, but local to this plugin's .c file. This is because the plugins are deliberately standalone binaries which do not rely on any of QEMU's include files or build process (you'll see they don't use osdep.h, for example).

Sorry, I misunderstood that, as it was discussed with Alex that maybe plugins should be able to access glib-compat.h.

Quoted 2 lines

thanks
-- PMM

#9 lore raw

PATCH v3 1/1 contrib/plugins/execlog: Fix compiler warning

In reply to Yao Xingtao via

1. The g_pattern_match_string() is deprecated when glib2 version >= 2.70. Use g_pattern_spec_match_string() instead to avoid this problem.

2. The type of second parameter in g_ptr_array_add() is 'gpointer' {aka 'void *'}, but the type of reg->name is 'const char*'. Cast the type of reg->name to 'gpointer' to avoid this problem.

compiler warning message:
/root/qemu/contrib/plugins/execlog.c:330:17: warning: ‘g_pattern_match_string’ is deprecated: Use 'g_pattern_spec_match_string'
instead [-Wdeprecated-declarations]

  330 |                 if (g_pattern_match_string(pat, rd->name) ||
      |                 ^~
In file included from /usr/include/glib-2.0/glib.h:67,
                 from /root/qemu/contrib/plugins/execlog.c:9:
/usr/include/glib-2.0/glib/gpattern.h:57:15: note: declared here
   57 | gboolean      g_pattern_match_string   (GPatternSpec *pspec,
      |               ^~~~~~~~~~~~~~~~~~~~~~
/root/qemu/contrib/plugins/execlog.c:331:21: warning: ‘g_pattern_match_string’
is deprecated: Use 'g_pattern_spec_match_string'
instead [-Wdeprecated-declarations]
  331 |                     g_pattern_match_string(pat, rd_lower)) {
      |                     ^~~~~~~~~~~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gpattern.h:57:15: note: declared here
   57 | gboolean      g_pattern_match_string   (GPatternSpec *pspec,
      |               ^~~~~~~~~~~~~~~~~~~~~~

/root/qemu/contrib/plugins/execlog.c:339:63: warning: passing argument 2 of ‘g_ptr_array_add’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
339 | g_ptr_array_add(all_reg_names, reg->name);
| ~~~^~~~~~
In file included from /usr/include/glib-2.0/glib.h:33:
/usr/include/glib-2.0/glib/garray.h:198:62: note: expected ‘gpointer’ {aka ‘void *’} but argument is of type ‘const char *’

  198 |                                            gpointer          data);
      |                                            ~~~~~~~~~~~~~~~~~~^~~~

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2210

---
 contrib/plugins/execlog.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)
contrib/plugins/execlog.c +21 -3
index a1dfd59ab7..fab18113d4 100644
@@ -311,6 +311,24 @@ static Register *init_vcpu_register(qemu_plugin_reg_descriptor *desc)
     return reg;
 }
 
+/*
+ * g_pattern_match_string has been deprecated in Glib since 2.70 and
+ * will complain about it if you try to use it. Fortunately the
+ * signature of both functions is the same making it easy to work
+ * around.
+ */
+static inline
+gboolean g_pattern_spec_match_string_qemu(GPatternSpec *pspec,
+                                          const gchar *string)
+{
+#if GLIB_CHECK_VERSION(2, 70, 0)
+    return g_pattern_spec_match_string(pspec, string);
+#else
+    return g_pattern_match_string(pspec, string);
+#endif
+};
+#define g_pattern_spec_match_string(p, s) g_pattern_spec_match_string_qemu(p, s)
+
 static GPtrArray *registers_init(int vcpu_index)
 {
     g_autoptr(GPtrArray) registers = g_ptr_array_new();
@@ -327,8 +345,8 @@ static GPtrArray *registers_init(int vcpu_index)
             for (int p = 0; p < rmatches->len; p++) {
                 g_autoptr(GPatternSpec) pat = g_pattern_spec_new(rmatches->pdata[p]);
                 g_autofree gchar *rd_lower = g_utf8_strdown(rd->name, -1);
-                if (g_pattern_match_string(pat, rd->name) ||
-                    g_pattern_match_string(pat, rd_lower)) {
+                if (g_pattern_spec_match_string(pat, rd->name) ||
+                    g_pattern_spec_match_string(pat, rd_lower)) {
                     Register *reg = init_vcpu_register(rd);
                     g_ptr_array_add(registers, reg);
 
@@ -336,7 +354,7 @@ static GPtrArray *registers_init(int vcpu_index)
                     if (disas_assist) {
                         g_mutex_lock(&add_reg_name_lock);
                         if (!g_ptr_array_find(all_reg_names, reg->name, NULL)) {
-                            g_ptr_array_add(all_reg_names, reg->name);
+                            g_ptr_array_add(all_reg_names, (gpointer)reg->name);
                         }
                         g_mutex_unlock(&add_reg_name_lock);
                     }
Signature · 1 line
2.37.3
Reviewed-by on v3 1/1
#10 lore raw
Quoted 84 lines · Yao Xingtao

1. The g_pattern_match_string() is deprecated when glib2 version >= 2.70. Use g_pattern_spec_match_string() instead to avoid this problem.

2. The type of second parameter in g_ptr_array_add() is

    'gpointer' {aka 'void *'}, but the type of reg->name is 'const char*'.
    Cast the type of reg->name to 'gpointer' to avoid this problem.

compiler warning message:
/root/qemu/contrib/plugins/execlog.c:330:17: warning: ‘g_pattern_match_string’ is deprecated: Use 'g_pattern_spec_match_string'
instead [-Wdeprecated-declarations]

   330 |                 if (g_pattern_match_string(pat, rd->name) ||
       |                 ^~
In file included from /usr/include/glib-2.0/glib.h:67,
                  from /root/qemu/contrib/plugins/execlog.c:9:
/usr/include/glib-2.0/glib/gpattern.h:57:15: note: declared here
    57 | gboolean      g_pattern_match_string   (GPatternSpec *pspec,
       |               ^~~~~~~~~~~~~~~~~~~~~~
/root/qemu/contrib/plugins/execlog.c:331:21: warning: ‘g_pattern_match_string’
is deprecated: Use 'g_pattern_spec_match_string'
instead [-Wdeprecated-declarations]
   331 |                     g_pattern_match_string(pat, rd_lower)) {
       |                     ^~~~~~~~~~~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gpattern.h:57:15: note: declared here
    57 | gboolean      g_pattern_match_string   (GPatternSpec *pspec,
       |               ^~~~~~~~~~~~~~~~~~~~~~

/root/qemu/contrib/plugins/execlog.c:339:63: warning: passing argument 2 of ‘g_ptr_array_add’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
339 | g_ptr_array_add(all_reg_names, reg->name);
| ~~~^~~~~~
In file included from /usr/include/glib-2.0/glib.h:33:
/usr/include/glib-2.0/glib/garray.h:198:62: note: expected ‘gpointer’ {aka ‘void *’} but argument is of type ‘const char *’

   198 |                                            gpointer          data);
       |                                            ~~~~~~~~~~~~~~~~~~^~~~

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2210

---
  contrib/plugins/execlog.c | 24 +++++++++++++++++++++---
  1 file changed, 21 insertions(+), 3 deletions(-)
contrib/plugins/execlog.c +20 -2
index a1dfd59ab7..fab18113d4 100644
@@ -311,6 +311,24 @@ static Register *init_vcpu_register(qemu_plugin_reg_descriptor *desc)
      return reg;
  }
 
+/*
+ * g_pattern_match_string has been deprecated in Glib since 2.70 and
+ * will complain about it if you try to use it. Fortunately the
+ * signature of both functions is the same making it easy to work
+ * around.
+ */
+static inline
+gboolean g_pattern_spec_match_string_qemu(GPatternSpec *pspec,
+                                          const gchar *string)
+{
+#if GLIB_CHECK_VERSION(2, 70, 0)
+    return g_pattern_spec_match_string(pspec, string);
+#else
+    return g_pattern_match_string(pspec, string);
+#endif
+};
+#define g_pattern_spec_match_string(p, s) g_pattern_spec_match_string_qemu(p, s)
+
  static GPtrArray *registers_init(int vcpu_index)
  {
      g_autoptr(GPtrArray) registers = g_ptr_array_new();
@@ -327,8 +345,8 @@ static GPtrArray *registers_init(int vcpu_index)
              for (int p = 0; p < rmatches->len; p++) {
                  g_autoptr(GPatternSpec) pat = g_pattern_spec_new(rmatches->pdata[p]);
                  g_autofree gchar *rd_lower = g_utf8_strdown(rd->name, -1);
-                if (g_pattern_match_string(pat, rd->name) ||
-                    g_pattern_match_string(pat, rd_lower)) {
+                if (g_pattern_spec_match_string(pat, rd->name) ||
+                    g_pattern_spec_match_string(pat, rd_lower)) {
                      Register *reg = init_vcpu_register(rd);
                      g_ptr_array_add(registers, reg);
 

contrib/plugins/execlog.c static GPtrArray *registers_init(int vcpu_index) · line 360

Quoted 8 lines
contrib/plugins/execlog.c +1 -1
@@ -336,7 +354,7 @@ static GPtrArray *registers_init(int vcpu_index)
                      if (disas_assist) {
                          g_mutex_lock(&add_reg_name_lock);
                          if (!g_ptr_array_find(all_reg_names, reg->name, NULL)) {
-                            g_ptr_array_add(all_reg_names, reg->name);
+                            g_ptr_array_add(all_reg_names, (gpointer)reg->name);
                          }
                          g_mutex_unlock(&add_reg_name_lock);
                      }

Would be nice if it's still possible to merge this in 9.0 Peter.

#11 lore raw
Quoted 88 lines · Pierrick Bouvier
Quoted 87 lines · Yao Xingtao

1. The g_pattern_match_string() is deprecated when glib2 version >= 2.70. Use g_pattern_spec_match_string() instead to avoid this problem.

2. The type of second parameter in g_ptr_array_add() is 'gpointer' {aka 'void *'}, but the type of reg->name is 'const char*'. Cast the type of reg->name to 'gpointer' to avoid this problem.

compiler warning message:
/root/qemu/contrib/plugins/execlog.c:330:17: warning: ‘g_pattern_match_string’ is deprecated: Use 'g_pattern_spec_match_string'
instead [-Wdeprecated-declarations]
   330 |                 if (g_pattern_match_string(pat, rd->name) || |                 ^~
In file included from /usr/include/glib-2.0/glib.h:67,
                  from /root/qemu/contrib/plugins/execlog.c:9:
/usr/include/glib-2.0/glib/gpattern.h:57:15: note: declared here 57 | gboolean      g_pattern_match_string   (GPatternSpec *pspec, |               ^~~~~~~~~~~~~~~~~~~~~~ /root/qemu/contrib/plugins/execlog.c:331:21: warning: ‘g_pattern_match_string’ is deprecated: Use 'g_pattern_spec_match_string'
instead [-Wdeprecated-declarations]
   331 |                     g_pattern_match_string(pat, rd_lower)) { |                     ^~~~~~~~~~~~~~~~~~~~~~ /usr/include/glib-2.0/glib/gpattern.h:57:15: note: declared here 57 | gboolean      g_pattern_match_string   (GPatternSpec *pspec, |               ^~~~~~~~~~~~~~~~~~~~~~ /root/qemu/contrib/plugins/execlog.c:339:63: warning: passing argument 2 of ‘g_ptr_array_add’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
   339 |                             g_ptr_array_add(all_reg_names, reg->name);
       | ~~~^~~~~~
In file included from /usr/include/glib-2.0/glib.h:33:
/usr/include/glib-2.0/glib/garray.h:198:62: note: expected ‘gpointer’ {aka ‘void *’} but argument is of type ‘const char *’
   198 |                                            gpointer data);
       | ~~~~~~~~~~~~~~~~~~^~~~

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2210

---
  contrib/plugins/execlog.c | 24 +++++++++++++++++++++---

  1 file changed, 21 insertions(+), 3 deletions(-)
contrib/plugins/execlog.c +18 -0
index a1dfd59ab7..fab18113d4 100644
@@ -311,6 +311,24 @@ static Register 
 *init_vcpu_register(qemu_plugin_reg_descriptor *desc)
       return reg;
   }
+/*
+ * g_pattern_match_string has been deprecated in Glib since 2.70 and
+ * will complain about it if you try to use it. Fortunately the
+ * signature of both functions is the same making it easy to work
+ * around.
+ */
+static inline
+gboolean g_pattern_spec_match_string_qemu(GPatternSpec *pspec,
+                                          const gchar *string)
+{
+#if GLIB_CHECK_VERSION(2, 70, 0)
+    return g_pattern_spec_match_string(pspec, string);
+#else
+    return g_pattern_match_string(pspec, string);
+#endif
+};
+#define g_pattern_spec_match_string(p, s) 
 g_pattern_spec_match_string_qemu(p, s)
+
   static GPtrArray *registers_init(int vcpu_index)
   {

      g_autoptr(GPtrArray) registers = g_ptr_array_new();

contrib/plugins/execlog.c +2 -2
@@ -327,8 +345,8 @@ static GPtrArray *registers_init(int vcpu_index)
               for (int p = 0; p < rmatches->len; p++) {
                   g_autoptr(GPatternSpec) pat = g_pattern_spec_new(rmatches->pdata[p]);
                   g_autofree gchar *rd_lower = g_utf8_strdown(rd->name, -1);
-                if (g_pattern_match_string(pat, rd->name) ||
-                    g_pattern_match_string(pat, rd_lower)) {
+                if (g_pattern_spec_match_string(pat, rd->name) ||
+                    g_pattern_spec_match_string(pat, rd_lower)) {
                       Register *reg = init_vcpu_register(rd);
                       g_ptr_array_add(registers, reg);
@@ -336,7 +354,7 @@ static GPtrArray *registers_init(int vcpu_index)
                       if (disas_assist) {
                           g_mutex_lock(&add_reg_name_lock);
                           if (!g_ptr_array_find(all_reg_names, reg->name, NULL)) {
Quoted 8 lines
Quoted 6 lines
contrib/plugins/execlog.c +1 -1
-                            g_ptr_array_add(all_reg_names, reg->name);
+                            g_ptr_array_add(all_reg_names, 
 (gpointer)reg->name);
                           }
                           g_mutex_unlock(&add_reg_name_lock);

                      }

Would be nice if it's still possible to merge this in 9.0 Peter.

I will post a small PR later today, so until Peter has something else planned, I can take it, since the patch LGTM now.

Quoted 1 line
Reviewed-by
#12 lore raw
Quoted 110 lines · Philippe Mathieu-Daudé
Quoted 99 lines · Pierrick Bouvier
Quoted 98 lines · Yao Xingtao

1. The g_pattern_match_string() is deprecated when glib2 version >= 2.70. Use g_pattern_spec_match_string() instead to avoid this problem.

2. The type of second parameter in g_ptr_array_add() is

    'gpointer' {aka 'void *'}, but the type of reg->name is 'const
char*'.
    Cast the type of reg->name to 'gpointer' to avoid this problem.

compiler warning message:
/root/qemu/contrib/plugins/execlog.c:330:17: warning:
‘g_pattern_match_string’
is deprecated: Use 'g_pattern_spec_match_string' instead [-Wdeprecated-declarations]

   330 |                 if (g_pattern_match_string(pat, rd->name) ||
       |                 ^~
In file included from /usr/include/glib-2.0/glib.h:67,
                  from /root/qemu/contrib/plugins/execlog.c:9:
/usr/include/glib-2.0/glib/gpattern.h:57:15: note: declared here
    57 | gboolean      g_pattern_match_string   (GPatternSpec *pspec,
       |               ^~~~~~~~~~~~~~~~~~~~~~

/root/qemu/contrib/plugins/execlog.c:331:21: warning:
‘g_pattern_match_string’
is deprecated: Use 'g_pattern_spec_match_string' instead [-Wdeprecated-declarations]

   331 |                     g_pattern_match_string(pat, rd_lower)) {
       |                     ^~~~~~~~~~~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gpattern.h:57:15: note: declared here
    57 | gboolean      g_pattern_match_string   (GPatternSpec *pspec,
       |               ^~~~~~~~~~~~~~~~~~~~~~

/root/qemu/contrib/plugins/execlog.c:339:63: warning: passing argument 2 of
‘g_ptr_array_add’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
339 | g_ptr_array_add(all_reg_names,

reg->name);
       |

~~~^~~~~~
In file included from /usr/include/glib-2.0/glib.h:33:
/usr/include/glib-2.0/glib/garray.h:198:62: note: expected ‘gpointer’ {aka ‘void *’} but argument is of type ‘const char *’
198 | gpointer

data);
       |

~~~~~~~~~~~~~~~~~~^~~~

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2210

---
  contrib/plugins/execlog.c | 24 +++++++++++++++++++++---
  1 file changed, 21 insertions(+), 3 deletions(-)
contrib/plugins/execlog.c +18 -0
index a1dfd59ab7..fab18113d4 100644
@@ -311,6 +311,24 @@ static Register
 *init_vcpu_register(qemu_plugin_reg_descriptor *desc)
      return reg;
  }
+/*
+ * g_pattern_match_string has been deprecated in Glib since 2.70 and
+ * will complain about it if you try to use it. Fortunately the
+ * signature of both functions is the same making it easy to work
+ * around.
+ */
+static inline
+gboolean g_pattern_spec_match_string_qemu(GPatternSpec *pspec,
+                                          const gchar *string)
+{
+#if GLIB_CHECK_VERSION(2, 70, 0)
+    return g_pattern_spec_match_string(pspec, string);
+#else
+    return g_pattern_match_string(pspec, string);
+#endif
+};
+#define g_pattern_spec_match_string(p, s)
 g_pattern_spec_match_string_qemu(p, s)
+
  static GPtrArray *registers_init(int vcpu_index)
  {
      g_autoptr(GPtrArray) registers = g_ptr_array_new();
contrib/plugins/execlog.c +2 -2
@@ -327,8 +345,8 @@ static GPtrArray *registers_init(int vcpu_index)
              for (int p = 0; p < rmatches->len; p++) {
                  g_autoptr(GPatternSpec) pat =
 g_pattern_spec_new(rmatches->pdata[p]);
                  g_autofree gchar *rd_lower =
 g_utf8_strdown(rd->name, -1);
-                if (g_pattern_match_string(pat, rd->name) ||
-                    g_pattern_match_string(pat, rd_lower)) {
+                if (g_pattern_spec_match_string(pat, rd->name) ||
+                    g_pattern_spec_match_string(pat, rd_lower)) {
                      Register *reg = init_vcpu_register(rd);
                      g_ptr_array_add(registers, reg);
contrib/plugins/execlog.c +0 -0
@@ -336,7 +354,7 @@ static GPtrArray *registers_init(int vcpu_index)
                      if (disas_assist) {
                          g_mutex_lock(&add_reg_name_lock);
                          if (!g_ptr_array_find(all_reg_names,
 reg->name, NULL)) {
Quoted 8 lines
Quoted 6 lines
contrib/plugins/execlog.c +1 -1
-                            g_ptr_array_add(all_reg_names, reg->name);
+                            g_ptr_array_add(all_reg_names,
 (gpointer)reg->name);
                          }
                          g_mutex_unlock(&add_reg_name_lock);
                      }

Would be nice if it's still possible to merge this in 9.0 Peter.

Quoted 2 lines

I will post a small PR later today, so until Peter has something else planned, I can take it, since the patch LGTM now.

That would be great (I don't have any more patches I wanted to put in a PR).

thanks
-- PMM

#13 lore raw
Quoted 111 lines · Peter Maydell
Quoted 110 lines · Philippe Mathieu-Daudé
Quoted 107 lines · Pierrick Bouvier
Quoted 102 lines · Yao Xingtao

1. The g_pattern_match_string() is deprecated when glib2 version >= 2.70. Use g_pattern_spec_match_string() instead to avoid this problem.

2. The type of second parameter in g_ptr_array_add() is

     'gpointer' {aka 'void *'}, but the type of reg->name is 'const
char*'.
     Cast the type of reg->name to 'gpointer' to avoid this problem.

compiler warning message:
/root/qemu/contrib/plugins/execlog.c:330:17: warning:
‘g_pattern_match_string’
is deprecated: Use 'g_pattern_spec_match_string' instead [-Wdeprecated-declarations]

    330 |                 if (g_pattern_match_string(pat, rd->name) ||
        |                 ^~
In file included from /usr/include/glib-2.0/glib.h:67,
                   from /root/qemu/contrib/plugins/execlog.c:9:
/usr/include/glib-2.0/glib/gpattern.h:57:15: note: declared here
     57 | gboolean      g_pattern_match_string   (GPatternSpec *pspec,
        |               ^~~~~~~~~~~~~~~~~~~~~~

/root/qemu/contrib/plugins/execlog.c:331:21: warning:
‘g_pattern_match_string’
is deprecated: Use 'g_pattern_spec_match_string' instead [-Wdeprecated-declarations]

    331 |                     g_pattern_match_string(pat, rd_lower)) {
        |                     ^~~~~~~~~~~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gpattern.h:57:15: note: declared here
     57 | gboolean      g_pattern_match_string   (GPatternSpec *pspec,
        |               ^~~~~~~~~~~~~~~~~~~~~~

/root/qemu/contrib/plugins/execlog.c:339:63: warning: passing argument 2 of
‘g_ptr_array_add’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
339 | g_ptr_array_add(all_reg_names,

reg->name);
        |

~~~^~~~~~
In file included from /usr/include/glib-2.0/glib.h:33:
/usr/include/glib-2.0/glib/garray.h:198:62: note: expected ‘gpointer’ {aka ‘void *’} but argument is of type ‘const char *’
198 | gpointer

data);
        |

~~~~~~~~~~~~~~~~~~^~~~

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2210

---
   contrib/plugins/execlog.c | 24 +++++++++++++++++++++---
   1 file changed, 21 insertions(+), 3 deletions(-)
contrib/plugins/execlog.c +18 -0
index a1dfd59ab7..fab18113d4 100644
@@ -311,6 +311,24 @@ static Register
 *init_vcpu_register(qemu_plugin_reg_descriptor *desc)
       return reg;
   }
+/*
+ * g_pattern_match_string has been deprecated in Glib since 2.70 and
+ * will complain about it if you try to use it. Fortunately the
+ * signature of both functions is the same making it easy to work
+ * around.
+ */
+static inline
+gboolean g_pattern_spec_match_string_qemu(GPatternSpec *pspec,
+                                          const gchar *string)
+{
+#if GLIB_CHECK_VERSION(2, 70, 0)
+    return g_pattern_spec_match_string(pspec, string);
+#else
+    return g_pattern_match_string(pspec, string);
+#endif
+};
+#define g_pattern_spec_match_string(p, s)
 g_pattern_spec_match_string_qemu(p, s)
+
   static GPtrArray *registers_init(int vcpu_index)
   {
       g_autoptr(GPtrArray) registers = g_ptr_array_new();
contrib/plugins/execlog.c +2 -2
@@ -327,8 +345,8 @@ static GPtrArray *registers_init(int vcpu_index)
               for (int p = 0; p < rmatches->len; p++) {
                   g_autoptr(GPatternSpec) pat =
 g_pattern_spec_new(rmatches->pdata[p]);
                   g_autofree gchar *rd_lower =
 g_utf8_strdown(rd->name, -1);
-                if (g_pattern_match_string(pat, rd->name) ||
-                    g_pattern_match_string(pat, rd_lower)) {
+                if (g_pattern_spec_match_string(pat, rd->name) ||
+                    g_pattern_spec_match_string(pat, rd_lower)) {
                       Register *reg = init_vcpu_register(rd);
                       g_ptr_array_add(registers, reg);
contrib/plugins/execlog.c +1 -1
@@ -336,7 +354,7 @@ static GPtrArray *registers_init(int vcpu_index)
                       if (disas_assist) {
                           g_mutex_lock(&add_reg_name_lock);
                           if (!g_ptr_array_find(all_reg_names,
 reg->name, NULL)) {
-                            g_ptr_array_add(all_reg_names, reg->name);
+                            g_ptr_array_add(all_reg_names,
 (gpointer)reg->name);
                           }
Quoted 2 lines
                           g_mutex_unlock(&add_reg_name_lock);
                       }

Would be nice if it's still possible to merge this in 9.0 Peter.

Quoted 7 lines
Quoted 2 lines

I will post a small PR later today, so until Peter has something else planned, I can take it, since the patch LGTM now.

That would be great (I don't have any more patches I wanted to put in a PR).

OK, patch queued then.

Yao, for your future contributions, please post patch iterations as new thread rather than replying to previous versions. You can see tips here:
https://www.qemu.org/docs/master/devel/submitting-a-patch.html#submitting-your-patches
in particular:

Patches are easier to find if they start a new top-level thread, rather than being buried in-reply-to another existing thread.

Regards,

Phil.

#14 lore raw
Quoted 140 lines

-----Original Message-----
From: Philippe Mathieu-Daudé <[email protected]>
Sent: Tuesday, March 26, 2024 8:04 PM
To: Peter Maydell <[email protected]>
Cc: Pierrick Bouvier <[email protected]>; Yao, Xingtao/姚 幸涛 <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v3] contrib/plugins/execlog: Fix compiler warning

Quoted 1 line · Peter Maydell

On Tue, 26 Mar 2024 at 09:54, Philippe Mathieu-Daudé <[email protected]>

Quoted 4 lines · wrote:
Quoted 4 lines · Pierrick Bouvier
Quoted 2 lines · Yao Xingtao
Quoted 1 line

1. The g_pattern_match_string() is deprecated when glib2 version >=

2.70.

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Use g_pattern_spec_match_string() instead to avoid this

problem.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

2. The type of second parameter in g_ptr_array_add() is

     'gpointer' {aka 'void *'}, but the type of reg->name is 'const
char*'.
     Cast the type of reg->name to 'gpointer' to avoid this problem.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

compiler warning message:
/root/qemu/contrib/plugins/execlog.c:330:17: warning:
‘g_pattern_match_string’
is deprecated: Use 'g_pattern_spec_match_string' instead [-Wdeprecated-declarations]

    330 |                 if (g_pattern_match_string(pat, rd->name)
||
>>>>         |                 ^~
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

In file included from /usr/include/glib-2.0/glib.h:67,
from /root/qemu/contrib/plugins/execlog.c:9:
/usr/include/glib-2.0/glib/gpattern.h:57:15: note: declared here
57 | gboolean g_pattern_match_string (GPatternSpec

*pspec,

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
        |               ^~~~~~~~~~~~~~~~~~~~~~

/root/qemu/contrib/plugins/execlog.c:331:21: warning:
‘g_pattern_match_string’
is deprecated: Use 'g_pattern_spec_match_string' instead [-Wdeprecated-declarations]
331 | g_pattern_match_string(pat, rd_lower))

{

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
        |                     ^~~~~~~~~~~~~~~~~~~~~~

/usr/include/glib-2.0/glib/gpattern.h:57:15: note: declared here
57 | gboolean g_pattern_match_string (GPatternSpec

*pspec,

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
        |               ^~~~~~~~~~~~~~~~~~~~~~

/root/qemu/contrib/plugins/execlog.c:339:63: warning: passing argument
2 of
‘g_ptr_array_add’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]

    339 |

g_ptr_array_add(all_reg_names,

Quoted 54 lines
Quoted 54 lines
Quoted 54 lines
Quoted 54 lines
reg->name);
        |

~~~^~~~~~
In file included from /usr/include/glib-2.0/glib.h:33:
/usr/include/glib-2.0/glib/garray.h:198:62: note: expected ‘gpointer’ {aka ‘void *’} but argument is of type ‘const char *’
198 | gpointer

data);
        |

~~~~~~~~~~~~~~~~~~^~~~

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2210

---
   contrib/plugins/execlog.c | 24 +++++++++++++++++++++---
   1 file changed, 21 insertions(+), 3 deletions(-)
contrib/plugins/execlog.c +15 -1
index a1dfd59ab7..fab18113d4 100644
@@ -311,6 +311,24 @@ static Register
 *init_vcpu_register(qemu_plugin_reg_descriptor *desc)
       return reg;
   }
+/*
+ * g_pattern_match_string has been deprecated in Glib since 2.70
+and
+ * will complain about it if you try to use it. Fortunately the
+ * signature of both functions is the same making it easy to work
+ * around.
+ */
+static inline
+gboolean g_pattern_spec_match_string_qemu(GPatternSpec *pspec,
+                                          const gchar *string) {
+#if GLIB_CHECK_VERSION(2, 70, 0)
+    return g_pattern_spec_match_string(pspec, string); #else
+    return g_pattern_match_string(pspec, string); #endif };
+#define g_pattern_spec_match_string(p, s)
 g_pattern_spec_match_string_qemu(p, s)
+
   static GPtrArray *registers_init(int vcpu_index)
   {
       g_autoptr(GPtrArray) registers = g_ptr_array_new(); @@
-327,8 +345,8 @@ static GPtrArray *registers_init(int vcpu_index)
               for (int p = 0; p < rmatches->len; p++) {
                   g_autoptr(GPatternSpec) pat =

g_pattern_spec_new(rmatches->pdata[p]);
g_autofree gchar *rd_lower =
g_utf8_strdown(rd->name, -1);

contrib/plugins/execlog.c +2 -2
-                if (g_pattern_match_string(pat, rd->name) ||
-                    g_pattern_match_string(pat, rd_lower)) {
+                if (g_pattern_spec_match_string(pat, rd->name) ||
+                    g_pattern_spec_match_string(pat, rd_lower)) {
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
                       Register *reg = init_vcpu_register(rd);
                       g_ptr_array_add(registers, reg); @@ -336,7
+354,7 @@ static GPtrArray *registers_init(int vcpu_index)
                       if (disas_assist) {
                           g_mutex_lock(&add_reg_name_lock);
                           if (!g_ptr_array_find(all_reg_names,

reg->name, NULL)) {
- g_ptr_array_add(all_reg_names,

reg->name);

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 5 lines

+ g_ptr_array_add(all_reg_names,

(gpointer)reg->name);
                           }
                           g_mutex_unlock(&add_reg_name_lock);
                       }

Would be nice if it's still possible to merge this in 9.0 Peter.

Quoted 7 lines
Quoted 2 lines

I will post a small PR later today, so until Peter has something else planned, I can take it, since the patch LGTM now.

That would be great (I don't have any more patches I wanted to put in a PR).

OK, patch queued then.

Quoted 9 lines

Yao, for your future contributions, please post patch iterations as new thread rather than replying to previous versions. You can see tips here:
https://www.qemu.org/docs/master/devel/submitting-a-patch.html#submit
ting-your-patches
in particular:

Patches are easier to find if they start a new top-level thread, rather than being buried in-reply-to another existing thread.

thanks, I will.

Quoted 3 lines

Regards,

Phil.