From c0bdc61879c5119de1bdf141c43bfa66dbcb87f0 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 30 May 2023 13:43:38 +0100 Subject: [PATCH] meson: Export HAVE_FREE_SIZED in glibconfig.h for use in g_free() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This allows the `g_free()` wrapper introduced in the previous commit to only be defined if `free_sized()` is actually available to improve performance. This avoids passing an allocation size to every `g_free()` call if it’s not going to be used, saving a register store instruction each time. Suggested by Marco Trevisan in https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3252#note_1660032 Signed-off-by: Philip Withnall --- glib/glibconfig.h.in | 2 ++ glib/gmem.h | 4 ++-- meson.build | 4 ++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/glib/glibconfig.h.in b/glib/glibconfig.h.in index 0d533c9f7..4e018a5f1 100644 --- a/glib/glibconfig.h.in +++ b/glib/glibconfig.h.in @@ -212,6 +212,8 @@ typedef @g_pid_type@ GPid; #define G_SEARCHPATH_SEPARATOR '@g_searchpath_separator@' #define G_SEARCHPATH_SEPARATOR_S "@g_searchpath_separator@" +#mesondefine G_HAVE_FREE_SIZED + G_END_DECLS #endif /* __GLIBCONFIG_H__ */ diff --git a/glib/gmem.h b/glib/gmem.h index 6e9b8ae16..9f3d42733 100644 --- a/glib/gmem.h +++ b/glib/gmem.h @@ -166,13 +166,13 @@ void g_aligned_free_sized (gpointer mem, #endif /* __GNUC__ */ -#if G_GNUC_CHECK_VERSION (4, 1) && GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_78 +#if G_GNUC_CHECK_VERSION (4, 1) && GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_78 && defined(G_HAVE_FREE_SIZED) #define g_free(mem) \ (__builtin_object_size ((mem), 0) != ((size_t) - 1)) ? \ g_free_sized (mem, __builtin_object_size ((mem), 0)) : (g_free) (mem) -#endif /* G_GNUC_CHECK_VERSION (4, 1) && && GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_78 */ +#endif /* G_GNUC_CHECK_VERSION (4, 1) && && GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_78 && defined(G_HAVE_FREE_SIZED) */ /** * g_steal_pointer: diff --git a/meson.build b/meson.build index 1d3754abb..1c62ea352 100644 --- a/meson.build +++ b/meson.build @@ -729,6 +729,10 @@ foreach f : functions endif endforeach +# Export the information about free_sized() so we can correctly define a macro +# wrapper around g_free()/g_free_sized() depending on whether it’s available +glibconfig_conf.set('G_HAVE_FREE_SIZED', have_func_free_sized) + # Check that stpcpy() is usable; must use header. # See: # https://github.com/mesonbuild/meson/issues/5628.