]> Savannah Git Hosting - gnulib.git/commitdiff
gnulib-common: update for gcc -Wmismatched-dealloc
authorPaul Eggert <eggert@cs.ucla.edu>
Fri, 30 Jul 2021 19:56:24 +0000 (12:56 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 31 Jul 2021 19:00:34 +0000 (12:00 -0700)
* m4/gnulib-common.m4 (gl_COMMON_BODY): Define the macros
_GL_ATTRIBUTE_DEALLOC and _GL_ATTRIBUTE_DEALLOC_FREE.  These can
be useful with gcc -Wmismatched-dealloc.

ChangeLog
m4/gnulib-common.m4

index 7e388c4ddcb5af7604e74aca4407403596df4463..33a472f5e017be1125a7db8a5286f1a0b7295d66 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2021-07-30  Paul Eggert  <eggert@cs.ucla.edu>
 
+       gnulib-common: update for gcc -Wmismatched-dealloc
+       * m4/gnulib-common.m4 (gl_COMMON_BODY): Define the macros
+       _GL_ATTRIBUTE_DEALLOC and _GL_ATTRIBUTE_DEALLOC_FREE.  These can
+       be useful with gcc -Wmismatched-dealloc.
+
        gnulib-common: update for C2x 2020-12-11 draft
        Use blessed-by-draft-standard way to test for [[__deprecated__]]
        etc.; this is supported by GCC 11 and the fallback code should
index 347462d1d9d74b09954ef19393d6fdb7355e2f08..2872ecdf77de1f6aafd5224e7c53b71ca23003c9 100644 (file)
@@ -148,6 +148,18 @@ AC_DEFUN([gl_COMMON_BODY], [
 # define _GL_ATTRIBUTE_CONST
 #endif
 
+/* _GL_ATTRIBUTE_DEALLOC (F, I) is for functions returning pointers
+   that can be freed by passing them as the Ith argument to the
+   function F.  _GL_ATTRIBUTE_DEALLOC_FREE is for functions that
+   return pointers that can be freed via 'free'; it can be used
+   only after including stdlib.h.  */
+#if _GL_GNUC_PREREQ (11, 0)
+# define _GL_ATTRIBUTE_DEALLOC(f, i) __attribute__ ((__malloc__ (f, i)))
+#else
+# define _GL_ATTRIBUTE_DEALLOC(f, i)
+#endif
+#define _GL_ATTRIBUTE_DEALLOC_FREE _GL_ATTRIBUTE_DEALLOC (free, 1)
+
 #if _GL_HAS_C_ATTRIBUTE (deprecated)
 # define _GL_ATTRIBUTE_DEPRECATED [[__deprecated__]]
 #elif _GL_HAS_ATTRIBUTE (deprecated)