meson: Export HAVE_FREE_SIZED in glibconfig.h for use in g_free()

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 <pwithnall@endlessos.org>
This commit is contained in:
Philip Withnall 2023-05-30 13:43:38 +01:00
parent c580b5c2f4
commit c0bdc61879
3 changed files with 8 additions and 2 deletions

View File

@ -212,6 +212,8 @@ typedef @g_pid_type@ GPid;
#define G_SEARCHPATH_SEPARATOR '@g_searchpath_separator@' #define G_SEARCHPATH_SEPARATOR '@g_searchpath_separator@'
#define G_SEARCHPATH_SEPARATOR_S "@g_searchpath_separator@" #define G_SEARCHPATH_SEPARATOR_S "@g_searchpath_separator@"
#mesondefine G_HAVE_FREE_SIZED
G_END_DECLS G_END_DECLS
#endif /* __GLIBCONFIG_H__ */ #endif /* __GLIBCONFIG_H__ */

View File

@ -166,13 +166,13 @@ void g_aligned_free_sized (gpointer mem,
#endif /* __GNUC__ */ #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) \ #define g_free(mem) \
(__builtin_object_size ((mem), 0) != ((size_t) - 1)) ? \ (__builtin_object_size ((mem), 0) != ((size_t) - 1)) ? \
g_free_sized (mem, __builtin_object_size ((mem), 0)) : (g_free) (mem) 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: * g_steal_pointer:

View File

@ -729,6 +729,10 @@ foreach f : functions
endif endif
endforeach endforeach
# Export the information about free_sized() so we can correctly define a macro
# wrapper around g_free()/g_free_sized() depending on whether its available
glibconfig_conf.set('G_HAVE_FREE_SIZED', have_func_free_sized)
# Check that stpcpy() is usable; must use header. # Check that stpcpy() is usable; must use header.
# See: # See:
# https://github.com/mesonbuild/meson/issues/5628. # https://github.com/mesonbuild/meson/issues/5628.