bug-gnulib
[Top][All Lists]
Advanced

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

malloc-h: Fix compilation error in C++ mode on Android


From: Bruno Haible
Subject: malloc-h: Fix compilation error in C++ mode on Android
Date: Mon, 09 Jan 2023 09:56:58 +0100

Building a testdir on Android, I get this compilation error:

clang++ -DNO_INLINE_GETPASS=1 -DHAVE_CONFIG_H -DEXEEXT=\"\" -DEXEEXT=\"\" -I. 
-I../../gltests -I..  -DGNULIB_STRICT_CHECKING=1 -DIN_GNULIB_TESTS=1 -I. 
-I../../gltests -I.. -I../../gltests/.. -I../gllib -I../../gltests/../gllib 
-I/data/data/com.termux/files/home/local/include -Wall  -Wno-error -g -O2 -c -o 
test-malloc-h-c++.o ../../gltests/test-malloc-h-c++.cc
In file included from ../../gltests/test-malloc-h-c++.cc:22:
In file included from ../gllib/malloc.h:27:
In file included from /data/data/com.termux/files/usr/include/malloc.h:30:
In file included from ../gllib/stdio.h:71:
In file included from ../gllib/sys/stat.h:44:
In file included from ../gllib/time.h:47:
In file included from /data/data/com.termux/files/usr/include/time.h:33:
In file included from ../gllib/sys/time.h:39:
In file included from /data/data/com.termux/files/usr/include/sys/time.h:37:
In file included from ../gllib/sys/select.h:102:
In file included from /data/data/com.termux/files/usr/include/sys/select.h:40:
In file included from ../gllib/signal.h:75:
In file included from ../gllib/pthread.h:56:
In file included from ../gllib/stdlib.h:28:
In file included from 
/data/data/com.termux/files/usr/include/c++/v1/stdlib.h:97:
In file included from /data/data/com.termux/files/usr/include/stdlib.h:34:
../gllib/malloc.h:542:19: error: no member named 'memalign' in the global 
namespace
_GL_CXXALIAS_SYS (memalign, void *, (size_t alignment, size_t size));
~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../gllib/strings.h:258:20: note: expanded from macro '_GL_CXXALIAS_SYS'
          return ::func;                                      \
                 ~~^

The function memalign is declared where it should. The problem is merely that
a sequence of nested includes causes the declaration to come too late. This
patch fixes it.


2023-01-09  Bruno Haible  <bruno@clisp.org>

        malloc-h: Fix compilation error in C++ mode on Android.
        * lib/malloc.in.h (_GL_ALREADY_INCLUDING_MALLOC_H): New macro.

diff --git a/lib/malloc.in.h b/lib/malloc.in.h
index de661f0f4b..c39d6e218f 100644
--- a/lib/malloc.in.h
+++ b/lib/malloc.in.h
@@ -14,18 +14,35 @@
    You should have received a copy of the GNU Lesser General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
 
-#ifndef _@GUARD_PREFIX@_MALLOC_H
-
 #if __GNUC__ >= 3
 @PRAGMA_SYSTEM_HEADER@
 #endif
 @PRAGMA_COLUMNS@
 
+#if defined _GL_ALREADY_INCLUDING_MALLOC_H
+/* Special invocation convention:
+   - On Android we have a sequence of nested includes
+       <malloc.h> -> <stdio.h> -> <sys/stat.h> -> <time.h> -> <sys/time.h> ->
+       <sys/select.h> -> <signal.h> -> <pthread.h> -> <stdlib.h> -> "malloc.h"
+     In this situation, in C++ mode, the declaration of memalign might be used
+     before it actually occurs.  */
+
+#@INCLUDE_NEXT@ @NEXT_MALLOC_H@
+
+#else
+/* Normal invocation convention.  */
+
+#ifndef _@GUARD_PREFIX@_MALLOC_H
+
+#define _GL_ALREADY_INCLUDING_MALLOC_H
+
 /* The include_next requires a split double-inclusion guard.  */
 #if @HAVE_MALLOC_H@
 # @INCLUDE_NEXT@ @NEXT_MALLOC_H@
 #endif
 
+#undef _GL_ALREADY_INCLUDING_MALLOC_H
+
 #ifndef _@GUARD_PREFIX@_MALLOC_H
 #define _@GUARD_PREFIX@_MALLOC_H
 
@@ -83,3 +100,4 @@ _GL_WARN_ON_USE (memalign, "memalign is not portable - "
 
 #endif /* _@GUARD_PREFIX@_MALLOC_H */
 #endif /* _@GUARD_PREFIX@_MALLOC_H */
+#endif






reply via email to

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