On Wed, Apr 16, 2025 at 05:14:06PM +0900, Kohei Tokunaga wrote:
> On emscripten, function pointer casts can cause function call failure.
> This commit fixes the function definition to match to the type of the
> function call using g_list_sort_with_data.
> 
> Signed-off-by: Kohei Tokunaga <ktokunaga.m...@gmail.com>
> ---
>  hw/core/loader.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/core/loader.c b/hw/core/loader.c
> index 2e35f0aa90..93a8b45d28 100644
> --- a/hw/core/loader.c
> +++ b/hw/core/loader.c
> @@ -1410,7 +1410,7 @@ typedef struct RomSec {
>   * work, but this way saves a little work later by avoiding
>   * dealing with "gaps" of 0 length.
>   */
> -static gint sort_secs(gconstpointer a, gconstpointer b)
> +static gint sort_secs(gconstpointer a, gconstpointer b, gpointer d)
>  {
>      RomSec *ra = (RomSec *) a;
>      RomSec *rb = (RomSec *) b;
> @@ -1463,7 +1463,7 @@ RomGap rom_find_largest_gap_between(hwaddr base, size_t 
> size)
>      /* sentinel */
>      secs = add_romsec_to_list(secs, base + size, 1);
>  
> -    secs = g_list_sort(secs, sort_secs);
> +    secs = g_list_sort_with_data(secs, sort_secs, NULL);

I don't see what the problem is with the original code.

The commit message says we have a bad function cast, but the original
method decl is

  GList *g_list_sort(GList*list, GCompareFunc compare_func);

where the callback is

   typedef gint (*GCompareFunc)(gconstpointer a, gconstpointer b);

Our code complies with that GCompareFunc signature.

For comparison the new code uses:

  GList *g_list_sort_with_data(GList *list, GCompareDataFunc  compare_func, 
gpointer user_data);

where the callback is

  typedef gint (*GCompareDataFunc)(gconstpointer a, gconstpointer b, gpointer 
user_data);

which the new code complies with, but it is undesirable since we
have no use for the data parameter.

With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|


Reply via email to