acl-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v2 1/2] Add __attribute__((malloc))


From: Pavel Simovec
Subject: [PATCH v2 1/2] Add __attribute__((malloc))
Date: Tue, 13 Feb 2024 13:24:05 +0100

- Import ax_gcc_malloc_call.m4 from autoconf-archive
  to enable configure-time checks.
- Apply ATTR_MALLOC to __acl_user_name and __acl_group_name
  to assist compiler in optimizations and enhance memory safety.
---
 configure.ac             |  1 +
 include/misc.h           | 10 ++++++++--
 m4/.gitignore            |  1 +
 m4/ax_gcc_malloc_call.m4 | 37 +++++++++++++++++++++++++++++++++++++
 4 files changed, 47 insertions(+), 2 deletions(-)
 create mode 100644 m4/ax_gcc_malloc_call.m4

diff --git a/configure.ac b/configure.ac
index 96fd96a..0b64b5f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -28,6 +28,7 @@ AC_PROG_CC
 AM_PROG_CC_C_O
 AC_USE_SYSTEM_EXTENSIONS
 AC_FUNC_GCC_VISIBILITY
+AX_GCC_MALLOC_CALL
 AC_C_BIGENDIAN
 AC_SYS_LARGEFILE
 
diff --git a/include/misc.h b/include/misc.h
index 5dd99a6..8700610 100644
--- a/include/misc.h
+++ b/include/misc.h
@@ -30,9 +30,15 @@
 # define hidden /* hidden */
 #endif
 
+#if defined(GCC_MALLOC_CALL)
+# define ATTR_MALLOC __attribute__((malloc))
+#else
+# define ATTR_MALLOC /* malloc */
+#endif
+
 
-char *__acl_user_name(uid_t uid, int numeric);
-char *__acl_group_name(gid_t uid, int numeric);
+hidden ATTR_MALLOC char *__acl_user_name(uid_t uid, int numeric);
+hidden ATTR_MALLOC char *__acl_group_name(gid_t uid, int numeric);
 
 
 hidden char *__acl_grow_buffer(char **buffer, size_t *bufsize, int type);
diff --git a/m4/.gitignore b/m4/.gitignore
index 73d27ec..077a049 100644
--- a/m4/.gitignore
+++ b/m4/.gitignore
@@ -1,3 +1,4 @@
 !.gitignore
 !package_attrdev.m4
 !visibility_hidden.m4
+!ax_gcc_malloc_call.m4
diff --git a/m4/ax_gcc_malloc_call.m4 b/m4/ax_gcc_malloc_call.m4
new file mode 100644
index 0000000..7c0e34f
--- /dev/null
+++ b/m4/ax_gcc_malloc_call.m4
@@ -0,0 +1,37 @@
+# ===========================================================================
+#    https://www.gnu.org/software/autoconf-archive/ax_gcc_malloc_call.html
+# ===========================================================================
+#
+# SYNOPSIS
+#
+#   AX_GCC_MALLOC_CALL
+#
+# DESCRIPTION
+#
+#   The macro will compile a test program to see whether the compiler does
+#   understand the per-function postfix pragma.
+#
+# LICENSE
+#
+#   Copyright (c) 2008 Guido U. Draheim <guidod@gmx.de>
+#
+#   Copying and distribution of this file, with or without modification, are
+#   permitted in any medium without royalty provided the copyright notice
+#   and this notice are preserved.  This file is offered as-is, without any
+#   warranty.
+
+#serial 10
+
+AC_DEFUN([AX_GCC_MALLOC_CALL],[dnl
+AC_CACHE_CHECK(
+ [whether the compiler supports function __attribute__((__malloc__))],
+ ax_cv_gcc_malloc_call,[
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[__attribute__((__malloc__))
+ int f(int i) { return i; }]],
+ [])],
+ [ax_cv_gcc_malloc_call=yes], [ax_cv_gcc_malloc_call=no])])
+ if test "$ax_cv_gcc_malloc_call" = yes; then
+   AC_DEFINE([GCC_MALLOC_CALL],[__attribute__((__malloc__))],
+    [most gcc compilers know a function __attribute__((__malloc__))])
+ fi
+])
-- 
2.43.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]