Skip to content

gstrfuncs: Improve inline version of g_strdup() to avoid breaking C++ code

Xi Ruoyao requested to merge xry111/glib:xry111/issue2936 into main

Wrap the logic into a G_ALWAYS_INLINE function, instead of using a complex statement-expression which is not allowed in braced initializer lists and expanded into some bad thing when it's used as ::g_strdup(...).

We cannot use __builtin_constant_p (str) because GCC documentation clearly states that it always produces 0 when str is a const char * argument of an inline function. But __builtin_constant_p (!str), __builtin_constant_p (!!str), and __builtin_constant_p (strlen (str)) functions properly with -O1 or above enabled.

Fixes #2936 (closed).

Edited by Xi Ruoyao

Merge request reports