From 986c0d109ae64b07ac8de1678f542a151d2bdec8 Mon Sep 17 00:00:00 2001 From: stevenj Date: Sat, 22 Nov 2008 17:29:58 -0500 Subject: [PATCH] work around broken solaris gcc darcs-hash:20081122222958-c8de0-e8509a08196f53a05ba2c77513bd297c01f47637.gz --- NEWS | 5 +++++ api/f77api.c | 2 +- api/nlopt.c | 13 +++---------- cdirect/cdirect.c | 1 - cdirect/hybrid.c | 1 - configure.ac | 21 +++++++++++++++++++-- direct/Makefile.am | 2 ++ direct/direct-internal.h | 1 + mma/mma.c | 2 +- octave/Makefile.am | 8 +++++++- octave/dummy.c | 2 ++ octave/nlopt_minimize_constrained-mex.c | 1 + util/mt19937ar.c | 1 - util/nlopt-util.h | 8 ++++++++ util/qsort_r.c | 3 +-- util/redblack_test.c | 7 +++++++ util/sobolseq.c | 4 +--- util/timer.c | 1 - 18 files changed, 59 insertions(+), 24 deletions(-) create mode 100644 octave/dummy.c diff --git a/NEWS b/NEWS index ea14eb6..9acbdcf 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,8 @@ +* Workaround for gcc 3.4.x conflict with HUGE_VAL definition in Solaris + (gcc bug 19933). + +* Better identification of Matlab-plugin installation directory. + NLopt 1.0.1 (13 Nov. 2008) * Allow user to override Matlab-plugin installation directory with diff --git a/api/f77api.c b/api/f77api.c index 1adf45c..2a52f2a 100644 --- a/api/f77api.c +++ b/api/f77api.c @@ -23,7 +23,7 @@ #include #include "nlopt.h" -#include "config.h" +#include "nlopt-util.h" /*-----------------------------------------------------------------------*/ /* wrappers around f77 procedures */ diff --git a/api/nlopt.c b/api/nlopt.c index 3e49753..056165f 100644 --- a/api/nlopt.c +++ b/api/nlopt.c @@ -27,18 +27,11 @@ #include "nlopt.h" #include "nlopt-util.h" -#include "config.h" #define MIN(a,b) ((a) < (b) ? (a) : (b)) /*************************************************************************/ -#ifdef INFINITY -# define MY_INF INFINITY -#else -# define MY_INF HUGE_VAL -#endif - int nlopt_isinf(double x) { return fabs(x) >= HUGE_VAL * 0.99 #ifdef HAVE_ISINF @@ -182,10 +175,10 @@ static double f_bound(int n, const double *x, void *data_) discontinuous objectives so we can just return Inf for invalid x */ for (i = 0; i < n; ++i) if (x[i] < data->lb[i] || x[i] > data->ub[i]) - return MY_INF; + return HUGE_VAL; f = data->f(n, x, NULL, data->f_data); - return (isnan(f) || nlopt_isinf(f) ? MY_INF : f); + return (isnan(f) || nlopt_isinf(f) ? HUGE_VAL : f); } static double f_noderiv(int n, const double *x, void *data_) @@ -306,7 +299,7 @@ static nlopt_result nlopt_minimize_( stop.n = n; stop.minf_max = (isnan(minf_max) || (nlopt_isinf(minf_max) && minf_max < 0)) - ? -MY_INF : minf_max; + ? -HUGE_VAL : minf_max; stop.ftol_rel = ftol_rel; stop.ftol_abs = ftol_abs; stop.xtol_rel = xtol_rel; diff --git a/cdirect/cdirect.c b/cdirect/cdirect.c index 49d4836..f61df07 100644 --- a/cdirect/cdirect.c +++ b/cdirect/cdirect.c @@ -28,7 +28,6 @@ #include "nlopt.h" #include "cdirect.h" #include "redblack.h" -#include "config.h" #define MIN(a,b) ((a) < (b) ? (a) : (b)) #define MAX(a,b) ((a) > (b) ? (a) : (b)) diff --git a/cdirect/hybrid.c b/cdirect/hybrid.c index 3e683ea..7277699 100644 --- a/cdirect/hybrid.c +++ b/cdirect/hybrid.c @@ -28,7 +28,6 @@ #include "nlopt.h" #include "cdirect.h" #include "redblack.h" -#include "config.h" /* Hybrid algorithm, inspired by DIRECT, that uses another local * optimization algorithm within each rectangle, and then looks diff --git a/configure.ac b/configure.ac index d839226..992732d 100644 --- a/configure.ac +++ b/configure.ac @@ -1,7 +1,7 @@ dnl Process this file with autoconf to produce a configure script. -AC_INIT(nlopt, 1.0.1, stevenj@alum.mit.edu) +AC_INIT(nlopt, 1.0.2, stevenj@alum.mit.edu) AC_CONFIG_SRCDIR(api/nlopt.h) -SHARED_VERSION_INFO="0:1:0" # CURRENT:REVISION:AGE +SHARED_VERSION_INFO="0:2:0" # CURRENT:REVISION:AGE AM_INIT_AUTOMAKE(1.7) AM_CONFIG_HEADER(config.h) @@ -165,6 +165,23 @@ AC_SUBST(MEX_INSTALL_DIR) AC_SUBST(MEX) AC_SUBST(MEXSUFF) +dnl ----------------------------------------------------------------------- +dnl Check for broken Solaris HUGE_VAL macro under gcc 3.4.x and similar + +AC_MSG_CHECKING([for working HUGE_VAL]) +AC_TRY_COMPILE([#include ], [double x = -HUGE_VAL;], +[AC_MSG_RESULT([ok])], +[AC_TRY_COMPILE([#include +#ifdef __GNUC__ +#undef HUGE_VAL +#define HUGE_VAL __builtin_huge_val() +#endif], [double x = -HUGE_VAL;], +[AC_MSG_RESULT([__builtin_huge_val()]) +AC_DEFINE(REPLACEMENT_HUGE_VAL,[__builtin_huge_val()], + [replacement for broken HUGE_VAL macro, if needed])], +[AC_MSG_RESULT([unknown]) +AC_MSG_ERROR([broken HUGE_VAL macro with this compiler, unknown workaround])])]) + dnl ----------------------------------------------------------------------- dnl Debugging diff --git a/direct/Makefile.am b/direct/Makefile.am index 4fae9bc..161dded 100644 --- a/direct/Makefile.am +++ b/direct/Makefile.am @@ -1,3 +1,5 @@ +AM_CPPFLAGS = -I$(top_srcdir)/util -I$(top_srcdir)/api + noinst_LTLIBRARIES = libdirect.la libdirect_la_SOURCES = DIRect.c direct_wrap.c DIRserial.c DIRsubrout.c \ direct-internal.h direct.h diff --git a/direct/direct-internal.h b/direct/direct-internal.h index c9cb685..d937832 100644 --- a/direct/direct-internal.h +++ b/direct/direct-internal.h @@ -6,6 +6,7 @@ #include #include "direct.h" +#include "nlopt-util.h" #ifdef __cplusplus extern "C" diff --git a/mma/mma.c b/mma/mma.c index 31d6089..ab12dc1 100644 --- a/mma/mma.c +++ b/mma/mma.c @@ -26,7 +26,7 @@ #include #include "mma.h" -#include "config.h" +#include "nlopt-util.h" int mma_verbose = 0; /* > 0 for verbose output */ diff --git a/octave/Makefile.am b/octave/Makefile.am index d06a143..c03ffed 100644 --- a/octave/Makefile.am +++ b/octave/Makefile.am @@ -1,7 +1,13 @@ -AM_CPPFLAGS = -I$(top_srcdir)/api +AM_CPPFLAGS = -I$(top_srcdir)/api -I$(top_srcdir)/util MFILES = NLOPT_GN_DIRECT.m NLOPT_GN_DIRECT_L.m NLOPT_GN_DIRECT_L_RAND.m NLOPT_GN_DIRECT_NOSCAL.m NLOPT_GN_DIRECT_L_NOSCAL.m NLOPT_GN_DIRECT_L_RAND_NOSCAL.m NLOPT_GN_ORIG_DIRECT.m NLOPT_GN_ORIG_DIRECT_L.m NLOPT_GD_STOGO.m NLOPT_GD_STOGO_RAND.m NLOPT_LD_LBFGS_NOCEDAL.m NLOPT_LD_LBFGS.m NLOPT_LN_PRAXIS.m NLOPT_LD_VAR1.m NLOPT_LD_VAR2.m NLOPT_LD_TNEWTON.m NLOPT_LD_TNEWTON_RESTART.m NLOPT_LD_TNEWTON_PRECOND.m NLOPT_LD_TNEWTON_PRECOND_RESTART.m NLOPT_GN_CRS2_LM.m NLOPT_GN_MLSL.m NLOPT_GD_MLSL.m NLOPT_GN_MLSL_LDS.m NLOPT_GD_MLSL_LDS.m NLOPT_LD_MMA.m NLOPT_LN_COBYLA.m NLOPT_LN_NEWUOA.m NLOPT_LN_NEWUOA_BOUND.m NLOPT_LN_NELDERMEAD.m NLOPT_LN_SBPLX.m +####################################################################### +# dummy C program to fool automake into making sure that CPPFLAGS etc. +# are all defined +noinst_PROGRAMS = dummy +dummy_SOURCES = dummy.c + ####################################################################### octdir = $(OCT_INSTALL_DIR) mdir = $(M_INSTALL_DIR) diff --git a/octave/dummy.c b/octave/dummy.c new file mode 100644 index 0000000..dc34341 --- /dev/null +++ b/octave/dummy.c @@ -0,0 +1,2 @@ +#include +int main(void) { printf("Hello world.\n"); return 0; } diff --git a/octave/nlopt_minimize_constrained-mex.c b/octave/nlopt_minimize_constrained-mex.c index 92620f3..538bcb1 100644 --- a/octave/nlopt_minimize_constrained-mex.c +++ b/octave/nlopt_minimize_constrained-mex.c @@ -29,6 +29,7 @@ #include #include "nlopt.h" +#include "nlopt-util.h" #define xSTRIZE(x) #x #define STRIZE(x) xSTRIZE(x) diff --git a/util/mt19937ar.c b/util/mt19937ar.c index 03ae83e..2e82376 100644 --- a/util/mt19937ar.c +++ b/util/mt19937ar.c @@ -46,7 +46,6 @@ */ #include "nlopt-util.h" -#include "config.h" #if defined(HAVE_STDINT_H) # include diff --git a/util/nlopt-util.h b/util/nlopt-util.h index 46e2ca6..586f35e 100644 --- a/util/nlopt-util.h +++ b/util/nlopt-util.h @@ -24,6 +24,14 @@ #define NLOPT_UTIL_H #include +#include +#include "config.h" + +/* workaround for Solaris + gcc 3.4.x bug (see configure.ac) */ +#if defined(__GNUC__) && defined(REPLACEMENT_HUGE_VAL) +# undef HUGE_VAL +# define HUGE_VAL REPLACEMENT_HUGE_VAL +#endif #ifdef __cplusplus extern "C" diff --git a/util/qsort_r.c b/util/qsort_r.c index 583cdc5..ebbc649 100644 --- a/util/qsort_r.c +++ b/util/qsort_r.c @@ -20,8 +20,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include -#include "config.h" +#include "nlopt-util.h" /* Simple replacement for the BSD qsort_r function (re-entrant sorting), if it is not available. (It looks like glibc 2.8 will include qsort_r diff --git a/util/redblack_test.c b/util/redblack_test.c index 467c755..3ee8cc8 100644 --- a/util/redblack_test.c +++ b/util/redblack_test.c @@ -26,6 +26,13 @@ #include #include "redblack.h" +#include "config.h" +/* workaround for Solaris + gcc 3.4.x bug (see configure.ac) */ +#if defined(__GNUC__) && defined(REPLACEMENT_HUGE_VAL) +# undef HUGE_VAL +# define HUGE_VAL REPLACEMENT_HUGE_VAL +#endif + static int comp(rb_key k1, rb_key k2) { if (*k1 < *k2) return -1; diff --git a/util/sobolseq.c b/util/sobolseq.c index 42120fc..b3bee05 100644 --- a/util/sobolseq.c +++ b/util/sobolseq.c @@ -47,11 +47,10 @@ a free/open-source implementation. */ #include +#include #include "nlopt-util.h" -#include "config.h" - #if defined(HAVE_STDINT_H) # include #endif @@ -250,7 +249,6 @@ void nlopt_sobol_skip(nlopt_sobol s, unsigned n, double *x) /* compile with -DSOBOLSEQ_TEST for test program */ #ifdef SOBOLSEQ_TEST #include -#include #include /* test integrand from Joe and Kuo paper ... integrates to 1 */ diff --git a/util/timer.c b/util/timer.c index ed06b42..d8e053f 100644 --- a/util/timer.c +++ b/util/timer.c @@ -21,7 +21,6 @@ */ #include "nlopt-util.h" -#include "config.h" #if TIME_WITH_SYS_TIME # include -- 2.30.2