summaryrefslogtreecommitdiff
path: root/configure.in
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2006-09-19 22:36:48 +0000
committerNick Mathewson <nickm@torproject.org>2006-09-19 22:36:48 +0000
commit2d4950c8373676b9b5ae0a3c8013e780b5c18e19 (patch)
tree88a609b1bd0590b32168a6d503aea7c5e4c8a838 /configure.in
parent7b0ec744bc8afa691873f97cfb6a3b7822376d7b (diff)
downloadtor-2d4950c8373676b9b5ae0a3c8013e780b5c18e19.tar.gz
tor-2d4950c8373676b9b5ae0a3c8013e780b5c18e19.zip
Malloc and friends are critical-path: Thus, add an it-wont-happen branch prediction for NULL returns, and skip the malloc(0) check on platforms where malloc(0) returns a pointer.
svn:r8431
Diffstat (limited to 'configure.in')
-rw-r--r--configure.in27
1 files changed, 27 insertions, 0 deletions
diff --git a/configure.in b/configure.in
index acedafc7af..7527bed5cc 100644
--- a/configure.in
+++ b/configure.in
@@ -558,6 +558,33 @@ if test $tor_cv_null_is_zero = yes; then
[Define to 1 iff memset(0) sets pointers to NULL])
fi
+# And what happens when we malloc zero?
+
+if test -z "$CROSS_COMPILE"; then
+AC_CACHE_CHECK([whether we can malloc(0) safely.], tor_cv_malloc_zero_works,
+[AC_RUN_IFELSE([AC_LANG_SOURCE(
+[[#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#ifdef HAVE_STDDEF_H
+#include <stddef.h>
+#endif
+int main () { return malloc(0)?0:1; }]])],
+ [tor_cv_malloc_zero_works=yes],
+ [tor_cv_malloc_zero_works=no],
+ [tor_cv_malloc_zero_works=cross])])
+
+else
+ # Cross-compiling; let's hope that the target isn't raving mad.
+ AC_MSG_NOTICE([Cross-compiling: we'll assume that we need to check malloc() arguments for 0.])
+ tor_cv_malloc_zero_works=no
+fi
+
+if test $tor_cv_malloc_zero_works = yes; then
+ AC_DEFINE([MALLOC_ZERO_WORKS], 1,
+ [Define to 1 iff malloc(0) returns a pointer])
+fi
+
# Whether we should use the dmalloc memory allocation debugging library.
AC_MSG_CHECKING(whether to use dmalloc (debug memory allocation library))
AC_ARG_WITH(dmalloc,