[PATCH v2 10/20] include/glib-compat.h: Poison g_list_sort and g_slist_sort

Kohei Tokunaga posted 20 patches 6 months, 3 weeks ago
There is a newer version of this series
[PATCH v2 10/20] include/glib-compat.h: Poison g_list_sort and g_slist_sort
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>
---
 include/glib-compat.h | 6 ++++++
 1 file changed, 6 insertions(+)

V2:
- Fixed typo in the comment: s/insted/instead/
- Updated the commit message to explicitly explain that function pointer
  casts are performed internally by GLib.

diff --git a/include/glib-compat.h b/include/glib-compat.h
index 86be439ba0..53f8ea38d3 100644
--- a/include/glib-compat.h
+++ b/include/glib-compat.h
@@ -36,6 +36,12 @@
 #include <pwd.h>
 #endif
 
+/* These functions perform function pointer casts which can cause function call
+ * failure on Emscripten. Use g_slist_sort_with_data and g_list_sort_with_data
+ * instead of these functions.
+ */
+#pragma GCC poison g_slist_sort g_list_sort
+
 /*
  * Note that because of the GLIB_VERSION_MAX_ALLOWED constant above, allowing
  * use of functions from newer GLib via this compat header needs a little
-- 
2.25.1
Re: [PATCH v2 10/20] include/glib-compat.h: Poison g_list_sort and g_slist_sort
Posted by Thomas Huth 6 months, 3 weeks ago
On 22/04/2025 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>
> ---
>   include/glib-compat.h | 6 ++++++
>   1 file changed, 6 insertions(+)
> 
> V2:
> - Fixed typo in the comment: s/insted/instead/
> - Updated the commit message to explicitly explain that function pointer
>    casts are performed internally by GLib.
> 
> diff --git a/include/glib-compat.h b/include/glib-compat.h
> index 86be439ba0..53f8ea38d3 100644
> --- a/include/glib-compat.h
> +++ b/include/glib-compat.h
> @@ -36,6 +36,12 @@
>   #include <pwd.h>
>   #endif
>   
> +/* These functions perform function pointer casts which can cause function call

Cosmetic nit: Multiline comments in QEMU should start with "/*" on their own 
line.

> + * failure on Emscripten. Use g_slist_sort_with_data and g_list_sort_with_data
> + * instead of these functions.
> + */
> +#pragma GCC poison g_slist_sort g_list_sort
> +
>   /*
>    * Note that because of the GLIB_VERSION_MAX_ALLOWED constant above, allowing
>    * use of functions from newer GLib via this compat header needs a little

With the nit fixed:
Reviewed-by: Thomas Huth <thuth@redhat.com>
Re: [PATCH v2 10/20] include/glib-compat.h: Poison g_list_sort and g_slist_sort
Posted by Kohei Tokunaga 6 months, 3 weeks ago
Hi Thomas,

> Cosmetic nit: Multiline comments in QEMU should start with "/*" on their
own
> line.

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