From cedd28252d3db9ae2ec725f4229101aca5e4edb5 Mon Sep 17 00:00:00 2001 From: stevenj Date: Wed, 25 May 2011 15:19:57 -0400 Subject: [PATCH] make luksan routines re-entrant; thanks to Gert Wollny for the bug report (fixes gentoo bug #368685) darcs-hash:20110525191957-c8de0-474429e4fdda69649248a32806f57f027760b645.gz --- luksan/luksan.h | 7 ++++++- luksan/plip.c | 4 +++- luksan/plis.c | 4 +++- luksan/pnet.c | 4 +++- luksan/pssubs.c | 20 +++++++++++++++++--- 5 files changed, 32 insertions(+), 7 deletions(-) diff --git a/luksan/luksan.h b/luksan/luksan.h index 66b9281..5161bf5 100644 --- a/luksan/luksan.h +++ b/luksan/luksan.h @@ -32,6 +32,11 @@ nlopt_result luksan_pnet(int n, nlopt_func f, void *f_data, int mf, int mos1, int mos2); +typedef struct { + double fl, fu, pl, rl, pu, ru; + int mes1, mes2, mes3, mode; +} ps1l01_state; + /***************************** internal routines *************************/ /* mssubs.c: */ @@ -88,7 +93,7 @@ void luksan_ps1l01__(double *r__, double *rp, tolp, double *par1, double *par2, int *kd, int *ld, int *nit, int *kit, int *nred, int *mred, int * maxst, int *iest, int *inits, int *iters, int *kters, - int *mes, int *isys); + int *mes, int *isys, ps1l01_state *state); void luksan_pulsp3__(int *n, int *m, int *mf, double *xm, double *gr, double *xo, double *go, double *r__, double *po, double *sig, int *iterh, diff --git a/luksan/plip.c b/luksan/plip.c index 8f42b3a..8bce79e 100644 --- a/luksan/plip.c +++ b/luksan/plip.c @@ -153,6 +153,7 @@ static void plip_(int *nf, int *nb, double *x, int * int iters, irest, inits, kters, maxst; double snorm; int mtesx, ntesx; + ps1l01_state state; /* INITIATION */ @@ -375,7 +376,8 @@ L11130: L11170: luksan_ps1l01__(&r__, &rp, f, &fo, &fp, &p, &po, &pp, minf_est, &maxf, &rmin, &rmax, &tols, &tolp, &par1, &par2, &kd, &ld, &stat_1->nit, &kit, & - nred, &mred, &maxst, iest, &inits, &iters, &kters, &mes, &isys); + nred, &mred, &maxst, iest, &inits, &iters, &kters, &mes, + &isys, &state); if (isys == 0) { goto L11174; } diff --git a/luksan/plis.c b/luksan/plis.c index 84d4c0a..11d371f 100644 --- a/luksan/plis.c +++ b/luksan/plis.c @@ -144,6 +144,7 @@ static void plis_(int *nf, int *nb, double *x, int * int iters, irest, inits, kters, maxst; double snorm; int mtesx, ntesx; + ps1l01_state state; /* INITIATION */ @@ -382,7 +383,8 @@ L12620: L11170: luksan_ps1l01__(&r__, &rp, f, &fo, &fp, &p, &po, &pp, minf_est, &maxf, &rmin, &rmax, &tols, &tolp, &par1, &par2, &kd, &ld, &stat_1->nit, &kit, & - nred, &mred, &maxst, iest, &inits, &iters, &kters, &mes, &isys); + nred, &mred, &maxst, iest, &inits, &iters, &kters, &mes, + &isys, &state); if (isys == 0) { goto L11174; } diff --git a/luksan/pnet.c b/luksan/pnet.c index bf6192e..d57461c 100644 --- a/luksan/pnet.c +++ b/luksan/pnet.c @@ -172,6 +172,7 @@ static void pnet_(int *nf, int *nb, double *x, int * int iters, irest, inits, kters, maxst; double snorm; int mtesx, ntesx; + ps1l01_state state; /* INITIATION */ @@ -517,7 +518,8 @@ L12560: L11060: luksan_ps1l01__(&r__, &rp, f, &fo, &fp, &p, &po, &pp, minf_est, &maxf, &rmin, &rmax, &tols, &tolp, &par1, &par2, &kd, &ld, &stat_1->nit, &kit, & - nred, &mred, &maxst, iest, &inits, &iters, &kters, &mes, &isys); + nred, &mred, &maxst, iest, &inits, &iters, &kters, &mes, + &isys, &state); if (isys == 0) { goto L11064; } diff --git a/luksan/pssubs.c b/luksan/pssubs.c index 2d3f948..5393d74 100644 --- a/luksan/pssubs.c +++ b/luksan/pssubs.c @@ -202,6 +202,16 @@ L1: return; } /* luksan_pnint1__ */ +/* save and restore state, replacing old non-reeentrant implementation + that used static local variables */ +#define SS(var) state->var = var +#define SAVE_STATE SS(fl); SS(fu); SS(pl); SS(rl); SS(pu); SS(ru); \ + SS(mes1); SS(mes2); SS(mes3); SS(mode) +#define RS(var) var = state->var +#define RESTORE_STATE RS(fl); RS(fu); RS(pl); RS(rl); RS(pu); RS(ru); \ + RS(mes1); RS(mes2); RS(mes3); RS(mode) + + /* cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc */ /* SUBROUTINE PS1L01 ALL SYSTEMS 97/12/01 * PURPOSE : @@ -276,20 +286,22 @@ void luksan_ps1l01__(double *r__, double *rp, tolp, double *par1, double *par2, int *kd, int *ld, int *nit, int *kit, int *nred, int *mred, int * maxst, int *iest, int *inits, int *iters, int *kters, - int *mes, int *isys) + int *mes, int *isys, ps1l01_state *state) { /* System generated locals */ double d__1, d__2; /* Local variables */ unsigned l1, l2, l3, m1, l5, m2, l7, m3; - static double fl, fu, pl, rl, pu, ru; - static int mes1, mes2, mes3, mode; + double fl, fu, pl, rl, pu, ru; + int mes1, mes2, mes3, mode; int merr; static int mtyp; int init1; double rtemp; + RESTORE_STATE; + if (*isys == 1) { goto L3; } @@ -363,6 +375,7 @@ L2: *kd = 1; *ld = -1; *isys = 1; + SAVE_STATE; return; L3: if (mode == 0) { @@ -463,6 +476,7 @@ L3: goto L2; L4: *isys = 0; + SAVE_STATE; return; } /* luksan_ps1l01__ */ -- 2.30.2