diff options
author | Sam James <sam@gentoo.org> | 2022-03-31 07:25:35 +0100 |
---|---|---|
committer | William Hubbs <w.d.hubbs@gmail.com> | 2022-05-08 14:56:26 -0500 |
commit | 17de4e5dfdf614332091b856bc05837b2e204a5a (patch) | |
tree | 0ac908a666db0685b1890972166cbb326bc41e0e /meson.build | |
parent | 1afcc37803dc9bde0cc8f336fe1f42e2f971ef14 (diff) |
librc: mark stringlist functions as mallocs
This gives a hint to the compiler that allocations (return values)
from this function should be paired with a corresponding dealloc/free
function
In this case, it means that every rc_stringlist that rc_stringlist_new()
returns should eventually be freed by calling rc_stringlist_free(ptr)
where ptr is the relevant rc_stringlist.
We have to add a test for this into the build system
because only GCC supports this for now. In future, we might
be able to use meson's has_function_attribute (it does support
'malloc', just not AFAICT 'malloc with arguments').
Signed-off-by: Sam James <sam@gentoo.org>
Diffstat (limited to 'meson.build')
-rw-r--r-- | meson.build | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/meson.build b/meson.build index 11d146a5..e770eab0 100644 --- a/meson.build +++ b/meson.build @@ -182,6 +182,16 @@ cc_warning_flags = cc.get_supported_arguments(cc_warning_flags_test) cc_flags = [cc_debug_flags, cc_os_flags, cc_warning_flags] add_project_arguments(cc_flags, language : 'c') +# Meson's has_function_attribute doesn't know about GCC's extended +# version (with arguments), so we have to build a test program instead. +malloc_attribute_test = '''#include<stdlib.h> +__attribute__ ((malloc (free, 1))) +int func() { return 0; } +''' +if cc.compiles(malloc_attribute_test, name : 'malloc attribute with arguments') + add_project_arguments('-DHAVE_MALLOC_EXTENDED_ATTRIBUTE', language: 'c') +endif + incdir = include_directories('src/shared') einfo_incdir = include_directories('src/libeinfo') rc_incdir = include_directories('src/librc') |