chiark / gitweb /
added API for free_f_data
authorstevenj <stevenj@alum.mit.edu>
Wed, 2 Jun 2010 00:36:32 +0000 (20:36 -0400)
committerstevenj <stevenj@alum.mit.edu>
Wed, 2 Jun 2010 00:36:32 +0000 (20:36 -0400)
darcs-hash:20100602003632-c8de0-b834db82c3ae5ccebd59fb656dd52f6d13f3bdb1.gz

api/f77api.c
api/f77funcs_.h
api/nlopt.h
api/options.c

index a3c9e1ae6191435be2b0293c9c532326026f9980..2961e4be0bcaa95d693c7da27457e28aeadff35b 100644 (file)
@@ -22,7 +22,7 @@
 
 #include <stdlib.h>
 
-#include "nlopt-internal.h"
+#include "nlopt.h"
 
 /*-----------------------------------------------------------------------*/
 /* wrappers around f77 procedures */
index 388a40c316297290568c32b416f8badd4abbf34a..61e29df1f21086f08b38b3bd0a1874104deec8ad 100644 (file)
@@ -36,7 +36,7 @@ void F77_(nlo_create,NLO_CREATE)(nlopt_opt *opt, int *alg, int *n)
      if (*n < 0) *opt = NULL;
      else {
          *opt = nlopt_create((nlopt_algorithm) *alg, (unsigned) *n);
-         (*opt)->free_f_data = 1;
+         nlopt_set_free_f_data(*opt, 1);
      }
 }
 
@@ -59,7 +59,6 @@ void F77_(nlo_set_min_objective,NLO_SET_MIN_OBJECTIVE)(
      d->f = f;
      d->f_data = f_data;
      *ret = (int) nlopt_set_min_objective(*opt, f77_func_wrap, d);
-     /* FIXME: memory leak in nlopt_destroy */
 }
 
 void F77_(nlo_set_max_objective,NLO_SET_MAX_OBJECTIVE)(
index 2f0975b19f0ce57dbe2b3dd8cb44251cc8522619..ec3ed54e901d4145a3b57c68642e7e5ec99be518 100644 (file)
@@ -248,6 +248,11 @@ NLOPT_EXTERN nlopt_result nlopt_set_initial_step1(nlopt_opt opt, double dx);
 NLOPT_EXTERN nlopt_result nlopt_get_initial_step(const nlopt_opt opt, 
                                                 const double *x, double *dx);
 
+/* set to 1: nlopt_destroy should call free() on all of the f_data pointers
+   (for the objective, constraints, etcetera) ... mainly for internal use */
+NLOPT_EXTERN nlopt_result nlopt_set_free_f_data(nlopt_opt opt, int val);
+NLOPT_EXTERN int nlopt_get_free_f_data(nlopt_opt opt);
+
 /*************************** DEPRECATED API **************************/
 /* The new "object-oriented" API is preferred, since it allows us to
    gracefully add new features and algorithm-specific options in a
index 890fbb9bb6d2425423bcc9c747c22e1ed26c0690..b217827e7af42a18e9dfab97f5bb58aa77e32e2a 100644 (file)
@@ -172,7 +172,6 @@ nlopt_result nlopt_set_min_objective(nlopt_opt opt, nlopt_func f, void *f_data)
 {
      if (opt) {
          opt->f = f; opt->f_data = f_data;
-         if (f_data) opt->free_f_data = 0;
          opt->maximize = 0;
          if (nlopt_isinf(opt->stopval) && opt->stopval > 0)
               opt->stopval = -HUGE_VAL; /* switch default from max to min */
@@ -185,7 +184,6 @@ nlopt_result nlopt_set_max_objective(nlopt_opt opt, nlopt_func f, void *f_data)
 {
      if (opt) {
          opt->f = f; opt->f_data = f_data;
-         if (f_data) opt->free_f_data = 0;
          opt->maximize = 1;
          if (nlopt_isinf(opt->stopval) && opt->stopval < 0)
               opt->stopval = +HUGE_VAL; /* switch default from min to max */
@@ -307,7 +305,6 @@ nlopt_result nlopt_add_inequality_constraint(nlopt_opt opt,
              && opt->algorithm != NLOPT_GN_ORIG_DIRECT
              && opt->algorithm != NLOPT_GN_ORIG_DIRECT_L)
               return NLOPT_INVALID_ARGS;
-         if (fc_data) opt->free_f_data = 0;
          return add_constraint(&opt->m, &opt->m_alloc, &opt->fc,
                                fc, fc_data, tol);
      }
@@ -330,7 +327,6 @@ nlopt_result nlopt_add_equality_constraint(nlopt_opt opt,
          /* equality constraints (h(x) = 0) only via some algorithms */
          if (!AUGLAG_ALG(opt->algorithm) && opt->algorithm != NLOPT_GN_ISRES)
               return NLOPT_INVALID_ARGS;
-         if (h_data) opt->free_f_data = 0;
          return add_constraint(&opt->p, &opt->p_alloc, &opt->h,
                                h, h_data, tol);
      }
@@ -527,3 +523,7 @@ nlopt_result nlopt_set_default_initial_step(nlopt_opt opt, const double *x)
 }
 
 /*************************************************************************/
+
+GETSET(free_f_data, int, free_f_data)
+
+/*************************************************************************/