From: Steven G. Johnson Date: Thu, 28 Mar 2013 15:27:33 +0000 (-0400) Subject: added nlopt_munge_data to fix bug in C++ (and Python, and Guile) copy constructor X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=1ca386e26c0dbda7374da22e9f2cd9314555c07b;p=nlopt.git added nlopt_munge_data to fix bug in C++ (and Python, and Guile) copy constructor --- diff --git a/NEWS b/NEWS index 8c0d188..67f4e9c 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,11 @@ +NLopt 2.4 + +* New genetic algorithm ESCH, thanks to Carlos Henrique da Silva Santos. + +* Fix swig dir for VPATH builds, thanks to Sandro Vitenti for the bug report. + +* Bugfix in copy constructor for C++ and Python interfaces. + NLopt 2.3.1 (16 September 2012) * Bug fix: COBLYA should return ROUNDOFF_LIMITED rather than XTOL_REACHED diff --git a/api/nlopt.h b/api/nlopt.h index eecf231..beb7fa9 100644 --- a/api/nlopt.h +++ b/api/nlopt.h @@ -305,6 +305,9 @@ typedef void* (*nlopt_munge)(void *p); NLOPT_EXTERN(void) nlopt_set_munge(nlopt_opt opt, nlopt_munge munge_on_destroy, nlopt_munge munge_on_copy); +typedef void* (*nlopt_munge2)(void *p, void *data); +NLOPT_EXTERN(void) nlopt_munge_data(nlopt_opt opt, + nlopt_munge2 munge, void *data); /*************************** DEPRECATED API **************************/ /* The new "object-oriented" API is preferred, since it allows us to diff --git a/api/options.c b/api/options.c index 8b75c15..9bfb6eb 100644 --- a/api/options.c +++ b/api/options.c @@ -738,4 +738,16 @@ void NLOPT_STDCALL nlopt_set_munge(nlopt_opt opt, } } +void NLOPT_STDCALL nlopt_munge_data(nlopt_opt opt, + nlopt_munge2 munge, void *data) { + if (opt && munge) { + unsigned i; + opt->f_data = munge(opt->f_data, data); + for (i = 0; i < opt->m; ++i) + opt->fc[i].f_data = munge(opt->fc[i].f_data, data); + for (i = 0; i < opt->p; ++i) + opt->h[i].f_data = munge(opt->h[i].f_data, data); + } +} + /*************************************************************************/