From cc91160a1ea5e18fcb2ccadb32e857d365581f53 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Mon, 25 Oct 2021 00:34:24 +0200 Subject: [PATCH] string: Avoid syntax error re strdup in string.in.h (regr. 2021-09-07). Reported by Jan Engelhardt and by Arash Esbati via Andy Moreton in . * lib/string.in.h (_GL_ATTRIBUTE_DEALLOC, _GL_ATTRIBUTE_DEALLOC_FREE, _GL_ATTRIBUTE_MALLOC): Add fallback declarations, like in lib/stdlib.in.h. * lib/wchar.in.h (_GL_ATTRIBUTE_DEALLOC, _GL_ATTRIBUTE_DEALLOC_FREE, _GL_ATTRIBUTE_MALLOC): Likewise. --- ChangeLog | 12 ++++++++++++ lib/string.in.h | 29 +++++++++++++++++++++++++++++ lib/wchar.in.h | 29 +++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+) diff --git a/ChangeLog b/ChangeLog index 2f19e30a2a..6aaa539918 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2021-10-24 Bruno Haible + + string: Avoid syntax error re strdup in string.in.h (regr. 2021-09-07). + Reported by Jan Engelhardt + and by Arash Esbati via Andy Moreton in + . + * lib/string.in.h (_GL_ATTRIBUTE_DEALLOC, _GL_ATTRIBUTE_DEALLOC_FREE, + _GL_ATTRIBUTE_MALLOC): Add fallback declarations, like in + lib/stdlib.in.h. + * lib/wchar.in.h (_GL_ATTRIBUTE_DEALLOC, _GL_ATTRIBUTE_DEALLOC_FREE, + _GL_ATTRIBUTE_MALLOC): Likewise. + 2021-10-19 Paul Eggert xalloc: new function xinmalloc diff --git a/lib/string.in.h b/lib/string.in.h index 8d77ae3800..afe7350867 100644 --- a/lib/string.in.h +++ b/lib/string.in.h @@ -67,6 +67,35 @@ # include #endif +/* _GL_ATTRIBUTE_DEALLOC (F, I) declares that the function returns pointers + that can be freed by passing them as the Ith argument to the + function F. */ +#ifndef _GL_ATTRIBUTE_DEALLOC +# if __GNUC__ >= 11 +# define _GL_ATTRIBUTE_DEALLOC(f, i) __attribute__ ((__malloc__ (f, i))) +# else +# define _GL_ATTRIBUTE_DEALLOC(f, i) +# endif +#endif + +/* _GL_ATTRIBUTE_DEALLOC_FREE declares that the function returns pointers that + can be freed via 'free'; it can be used only after declaring 'free'. */ +/* Applies to: functions. Cannot be used on inline functions. */ +#ifndef _GL_ATTRIBUTE_DEALLOC_FREE +# define _GL_ATTRIBUTE_DEALLOC_FREE _GL_ATTRIBUTE_DEALLOC (free, 1) +#endif + +/* _GL_ATTRIBUTE_MALLOC declares that the function returns a pointer to freshly + allocated memory. */ +/* Applies to: functions. */ +#ifndef _GL_ATTRIBUTE_MALLOC +# if __GNUC__ >= 3 || defined __clang__ +# define _GL_ATTRIBUTE_MALLOC __attribute__ ((__malloc__)) +# else +# define _GL_ATTRIBUTE_MALLOC +# endif +#endif + /* The __attribute__ feature is available in gcc versions 2.5 and later. The attribute __pure__ was added in gcc 2.96. */ #ifndef _GL_ATTRIBUTE_PURE diff --git a/lib/wchar.in.h b/lib/wchar.in.h index f13379ad84..20315dd7bb 100644 --- a/lib/wchar.in.h +++ b/lib/wchar.in.h @@ -84,6 +84,35 @@ #ifndef _@GUARD_PREFIX@_WCHAR_H #define _@GUARD_PREFIX@_WCHAR_H +/* _GL_ATTRIBUTE_DEALLOC (F, I) declares that the function returns pointers + that can be freed by passing them as the Ith argument to the + function F. */ +#ifndef _GL_ATTRIBUTE_DEALLOC +# if __GNUC__ >= 11 +# define _GL_ATTRIBUTE_DEALLOC(f, i) __attribute__ ((__malloc__ (f, i))) +# else +# define _GL_ATTRIBUTE_DEALLOC(f, i) +# endif +#endif + +/* _GL_ATTRIBUTE_DEALLOC_FREE declares that the function returns pointers that + can be freed via 'free'; it can be used only after declaring 'free'. */ +/* Applies to: functions. Cannot be used on inline functions. */ +#ifndef _GL_ATTRIBUTE_DEALLOC_FREE +# define _GL_ATTRIBUTE_DEALLOC_FREE _GL_ATTRIBUTE_DEALLOC (free, 1) +#endif + +/* _GL_ATTRIBUTE_MALLOC declares that the function returns a pointer to freshly + allocated memory. */ +/* Applies to: functions. */ +#ifndef _GL_ATTRIBUTE_MALLOC +# if __GNUC__ >= 3 || defined __clang__ +# define _GL_ATTRIBUTE_MALLOC __attribute__ ((__malloc__)) +# else +# define _GL_ATTRIBUTE_MALLOC +# endif +#endif + /* The __attribute__ feature is available in gcc versions 2.5 and later. The attribute __pure__ was added in gcc 2.96. */ #ifndef _GL_ATTRIBUTE_PURE -- 2.39.5