Qhull and scripts/geometry

Jaroslav Hajek highegg at gmail.com
Tue Feb 3 05:34:50 CST 2009


On Tue, Feb 3, 2009 at 11:46 AM, Jaroslav Hajek <highegg at gmail.com> wrote:
> On Tue, Feb 3, 2009 at 10:45 AM, Petr Mikulik <mikulik at physics.muni.cz> wrote:
>>> >> | Yes; configuring Qhull with
>>> >> |     CFLAGS="-fno-strict-aliasing -O2" ./configure $*
>>> >> | does not crash the testing command
>>> >> |      rbox c D3 | qconvex s G
>>> >> |
>>> >> | Could Octave's ./configure test the Qhull library? I propose that if the
>>> >> | above test command (or some C++ source test case) crashes, then Octave does
>>> >> | not link to Qhull library and writes a hint like
>>> >> |   Crashing Qhull found; please recompile the Qhull library by
>>> >> |     CFLAGS="-fno-strict-aliasing -O2" ./configure; make
>>> >>
>>> >> Can you provide an autoconf macro that does the test and does not
>>> >> require an external program?  My Debian sysstem has the library but
>>> >> the test programs are not installed.
>>> >>
>>> >> There is also the issue that running test programs limits the
>>> >> usefulness of configure scripts when cross-compiling.  In this case, I
>>> >> guess we would just have to assume that the library works when cross
>>> >> compiling.
>>> >
>>> > I've prepared the shortest code that leads to crash if the Qhull library has
>>> > been compiled without the appropriate CFLAGS.
>>> >
>>> > Usage:
>>> >    gcc -o QhullCrashTest QhullCrashTest.c -lqhull -lm
>>> >    echo "2 4 -0.5 -0.5 -0.5 0.5 0.5 -0.5 0.5 0.5" | ./QhullCrashTest
>>> >
>>> > If it crashes, nothing is written on stdout.
>>> > If it does not crash, an "OK message" is written on stdout.
>>> >
>>> > Could this testing program be used in the Octave configure?
>>> > I don't know how to write an autoconf macro for it.
>>> >
>>>
>>> Hi Petr,
>>>
>>> I'll take care of the inclusion into configure. However, for best
>>> suitability for autoconf macros (AC_RUN_IFELSE), please modify the
>>> test program in the following manner:
>>> 1. make the inputs part of the source
>>> 2. indicate success by returning exit code zero. If you can do it, to
>>> make the test more complete, I suggest also to check the results for
>>> correctness (if a crash doesn't happen on some system, but instead
>>> incorrect results are produced).
>>
>> I have no idea how to put the input data into the testing program.
>>
>
> I have taken a quick look at it and it seems the attached source is
> able to reproduce the crash. Would you please verify with your
> configuration?
>
>
>> The success is indicated by zero exit code ("return 0"); failure is
>> indicated by crash with a "Segmentation fault" ... the return value seems to
>> be 139.
>
> Yes, this is indicated by the system (and autoconf macro handles it).
> I am, however, very suspicious about regarding a segfault as something
> predictable; it depends on the OS and perhaps other circumstances.
> It would be even better to check the results for correctness (see, for
> instance, the analogous checks for correctness of BLAS library called
> from Fortran); still, I'd be happy even with this. I'll turn this into
> a patch.
>


Patch attached. Comments? OK to push?



-- 
RNDr. Jaroslav Hajek
computing expert
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz

# HG changeset patch
# User Jaroslav Hajek <highegg at gmail.com>
# Date 1233660883 -3600
# Node ID 54891fbeca5d12ab4a8dd6f445f1578e2f5b8eaf
# Parent  e3041433a57e0d15fccb68429b3606b00005ca4f
configure: check whether qhull works

diff --git a/ChangeLog b/ChangeLog
--- a/ChangeLog
+++ b/ChangeLog
@@ -0,0 +1,6 @@
+2009-02-03  Jaroslav Hajek  <highegg at gmail.com>
+
+	* aclocal.m4 (AC_CHECK_QHULL_OK): New macro, based on suggestion by
+	Petr Mikulik <mikulik at physics.muni.cz>.
+	* configure.in: Call it.
+
diff --git a/aclocal.m4 b/aclocal.m4
--- a/aclocal.m4
+++ b/aclocal.m4
@@ -955,6 +955,44 @@
 fi
 ])
 dnl
+dnl Check whether QHull works (does not crash)
+dnl
+AC_DEFUN(AC_CHECK_QHULL_OK,
+[AC_MSG_CHECKING([whether the qhull library works])
+AC_CACHE_VAL(octave_cv_lib_qhull_ok,
+[
+  save_LIBS="$LIBS"
+  LIBS="$LIBS -lqhull -lm"
+AC_RUN_IFELSE([AC_LANG_SOURCE([[
+#include <stdio.h>
+#include <qhull/qhull.h>
+
+#ifdef NEED_QHULL_VERSION
+char *qh_version = "version";
+#endif
+int main()
+{
+  int dim = 2, n = 4;
+  coordT points[8] = { -0.5, -0.5, -0.5, 0.5, 0.5, -0.5, 0.5, 0.5 };
+  boolT ismalloc = 0;
+
+  return qh_new_qhull (dim, n, points, ismalloc, "qhull ", 0, stderr);
+}
+]])],
+  [octave_cv_lib_qhull_ok=yes],
+  [octave_cv_lib_qhull_ok=no],
+  [octave_cv_lib_qhull_ok=yes])
+  LIBS="$save_LIBS"
+])
+if test "$octave_cv_lib_qhull_ok" = "yes"; then
+  AC_MSG_RESULT(yes)
+  ifelse([$1], , , [$1])
+else
+  AC_MSG_RESULT(no)
+  ifelse([$2], , , [$2])
+fi
+])
+dnl
 dnl Check for OpenGL. If found, define OPENGL_LIBS
 dnl
 dnl FIXME -- add tests for apple
diff --git a/configure.in b/configure.in
--- a/configure.in
+++ b/configure.in
@@ -424,6 +424,9 @@
   if test "$have_qhull" != yes; then
     AC_CHECK_QHULL_VERSION(have_qhull=yes, have_qhull=no)
     AC_DEFINE(NEED_QHULL_VERSION, 1, [Define if the QHull library
needs a wh_version variable defined.])
+  fi
+  if test "$have_qhull" == yes; then
+    AC_CHECK_QHULL_OK(have_qhull=yes, have_qhull=no)
   fi
 fi
 if test "$have_qhull" = yes; then


More information about the Bug-octave mailing list