[PATCH v2 04/20] target/arm/helper.c: Fix type conflict of GLib function pointers

Kohei Tokunaga posted 20 patches 6 months, 3 weeks ago
There is a newer version of this series
[PATCH v2 04/20] target/arm/helper.c: Fix type conflict of GLib function pointers
Posted by Kohei Tokunaga 6 months, 3 weeks ago
On Emscripten, function pointer casts can result in runtime failures due to
strict function signature checks. This affects the use of g_list_sort and
g_slist_sort, which internally perform function pointer casts that are not
supported by Emscripten. To avoid these issues, g_list_sort_with_data and
g_slist_sort_with_data should be used instead, as they do not rely on
function pointer casting.

Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
---
 target/arm/helper.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

V2:
- Updated the commit message to explicitly explain that function pointer
  casts are performed internally by GLib.

diff --git a/target/arm/helper.c b/target/arm/helper.c
index bb445e30cd..05793a6c97 100644
--- a/target/arm/helper.c
+++ b/target/arm/helper.c
@@ -220,7 +220,7 @@ static void count_cpreg(gpointer key, gpointer opaque)
     }
 }
 
-static gint cpreg_key_compare(gconstpointer a, gconstpointer b)
+static gint cpreg_key_compare(gconstpointer a, gconstpointer b, void *d)
 {
     uint64_t aidx = cpreg_to_kvm_id((uintptr_t)a);
     uint64_t bidx = cpreg_to_kvm_id((uintptr_t)b);
@@ -244,7 +244,7 @@ void init_cpreg_list(ARMCPU *cpu)
     int arraylen;
 
     keys = g_hash_table_get_keys(cpu->cp_regs);
-    keys = g_list_sort(keys, cpreg_key_compare);
+    keys = g_list_sort_with_data(keys, cpreg_key_compare, NULL);
 
     cpu->cpreg_array_len = 0;
 
-- 
2.25.1
Re: [PATCH v2 04/20] target/arm/helper.c: Fix type conflict of GLib function pointers
Posted by Philippe Mathieu-Daudé 6 months, 3 weeks ago
Hi Kohei,

On 22/4/25 07:27, Kohei Tokunaga wrote:
> On Emscripten, function pointer casts can result in runtime failures due to
> strict function signature checks. This affects the use of g_list_sort and
> g_slist_sort, which internally perform function pointer casts that are not
> supported by Emscripten. To avoid these issues, g_list_sort_with_data and
> g_slist_sort_with_data should be used instead, as they do not rely on
> function pointer casting.
> 
> Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
> ---
>   target/arm/helper.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> V2:
> - Updated the commit message to explicitly explain that function pointer
>    casts are performed internally by GLib.
> 
> diff --git a/target/arm/helper.c b/target/arm/helper.c
> index bb445e30cd..05793a6c97 100644
> --- a/target/arm/helper.c
> +++ b/target/arm/helper.c
> @@ -220,7 +220,7 @@ static void count_cpreg(gpointer key, gpointer opaque)
>       }
>   }
>   
> -static gint cpreg_key_compare(gconstpointer a, gconstpointer b)
> +static gint cpreg_key_compare(gconstpointer a, gconstpointer b, void *d)

Why not use a gpointer for @d like in other patches?

>   {
>       uint64_t aidx = cpreg_to_kvm_id((uintptr_t)a);
>       uint64_t bidx = cpreg_to_kvm_id((uintptr_t)b);
> @@ -244,7 +244,7 @@ void init_cpreg_list(ARMCPU *cpu)
>       int arraylen;
>   
>       keys = g_hash_table_get_keys(cpu->cp_regs);
> -    keys = g_list_sort(keys, cpreg_key_compare);
> +    keys = g_list_sort_with_data(keys, cpreg_key_compare, NULL);
>   
>       cpu->cpreg_array_len = 0;
>
Re: [PATCH v2 04/20] target/arm/helper.c: Fix type conflict of GLib function pointers
Posted by Kohei Tokunaga 6 months, 3 weeks ago
Hi Philippe,

> Why not use a gpointer for @d like in other patches?

Thank you for the feedback. I'll fix this to use a gpointer in the next
version of the series.