From c22ccc6eb0b23079e2c4088d4cbbc3d680d2b171 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Wed, 7 Jan 2015 11:41:26 -0800 Subject: [PATCH] Update ASL to version 20150107 --- src/asl/solvers/00lastchange | 5 ++- src/asl/solvers/asldate.c | 2 +- src/asl/solvers/changes | 14 +++++++++ src/asl/solvers/funcadd1.c | 61 +++++++++++++++++++++++------------- src/asl/solvers/mqpcheckv.c | 29 +++++++++-------- src/asl/solvers/objconst.c | 2 +- src/asl/solvers/xsum0.out | 10 +++--- 7 files changed, 79 insertions(+), 44 deletions(-) diff --git a/src/asl/solvers/00lastchange b/src/asl/solvers/00lastchange index 3cb976812..e5d5deffe 100644 --- a/src/asl/solvers/00lastchange +++ b/src/asl/solvers/00lastchange @@ -1,3 +1,2 @@ -20141202 - mqpcheckv.c: fix a glitch (missed zeroing of an array element) that -somehow escaped earlier testing. +20150101 + funcadd1.c: tweaks to error messages. diff --git a/src/asl/solvers/asldate.c b/src/asl/solvers/asldate.c index 7eceb843f..b1f5ed7e2 100644 --- a/src/asl/solvers/asldate.c +++ b/src/asl/solvers/asldate.c @@ -1 +1 @@ -long ASLdate_ASL = 20141202; +long ASLdate_ASL = 20150101; diff --git a/src/asl/solvers/changes b/src/asl/solvers/changes index 135279e36..2480cca34 100644 --- a/src/asl/solvers/changes +++ b/src/asl/solvers/changes @@ -2439,3 +2439,17 @@ free(qpi) to dispose of qpi. 20141202 mqpcheckv.c: fix a glitch (missed zeroing of an array element) that somehow escaped earlier testing. + +20141223 + mqpcheckv.c: fix a bug (possible invalid free() call) with problems +where ASL_obj_replace_eq or ASL_obj_replace_ineq matters. + +20141229 + objconst.c: adjust objconst() to work correctly after qp_read(). + +20150101 + funcadd1.c: tweaks to error messages. + +20150107 + funcadd.h: change line 271 from "#ifdef _WIN32" to +"#if defined(_WIN32) && !defined(__MINGW32__)"; no change to asldate.c. diff --git a/src/asl/solvers/funcadd1.c b/src/asl/solvers/funcadd1.c index 9433e18d4..9cf386293 100644 --- a/src/asl/solvers/funcadd1.c +++ b/src/asl/solvers/funcadd1.c @@ -49,6 +49,17 @@ funcadd(AmplExports *ae) #include "string.h" #include "funcadd.h" #include "arith.h" /* for X64_bit_pointers */ +#include +#include +#ifndef S_IFREG /*{*/ +#ifdef __S_IFREG +#define S_IFREG __S_IFREG +#define S_IFDIR __S_IFDIR +#elif defined(_S_IFREG) +#define S_IFREG _S_IFREG +#define S_IFDIR _S_IFDIR +#endif +#endif /*}*/ #ifdef X64_bit_pointers static char Bits[] = "64", BitsAlt[] = "32"; #else @@ -100,6 +111,20 @@ extern const char *i_option_ASL; static int first = 1; + static int +file_kind(const char *name) /* 1 == regular file, 2 ==> directory; else 0 */ +{ + struct stat sb; + + if (stat(name,&sb)) + return 0; + if (sb.st_mode & S_IFDIR) + return 2; + if (sb.st_mode & S_IFREG) + return 1; + return 0; + } + #ifdef WIN32 #define SLASH '\\' @@ -109,7 +134,6 @@ typedef HINSTANCE shl_t; #define find_dlsym(a,b,c) (a = (Funcadd*)GetProcAddress(b,c)) #define dlclose(x) FreeLibrary((HMODULE)x) #define NO_DLERROR -#define reg_file(x) 1 static int Abspath(const char *s) @@ -133,16 +157,6 @@ char afdll[] = "/amplfunc.dll"; #include "unistd.h" /* for getcwd */ #define GetCurrentDirectory(a,b) getcwd(b,(int)(a)) -#include -#include - - static int -reg_file(const char *name) -{ - struct stat sb; - return stat(name,&sb) ? 0 : S_ISREG(sb.st_mode); - } - #ifdef __hpux #include "dl.h" #define dlopen(x,y) shl_load(x, BIND_IMMEDIATE, 0) @@ -241,7 +255,7 @@ dl_open(AmplExports *ae, char *name, int *warned, int *pns) #ifdef Old_APPLE NS_pair p; #endif - d = d0 = 0; + d = d0 = dz = 0; for(s = name; *s; ++s) switch(*s) { case '.': @@ -254,7 +268,6 @@ dl_open(AmplExports *ae, char *name, int *warned, int *pns) d = 0; } ns = s - name; - dz = 0; if (d && d - name > 3 && d[-3] == '_') { @@ -317,16 +330,16 @@ dl_open(AmplExports *ae, char *name, int *warned, int *pns) d = dz = 0; goto tryagain; } + if (d0) + for(s = d0; (s[0] = s[3]); ++s); if (!warned && (f = fopen(name,"rb"))) { fclose(f); - if (reg_file(name)) { + if (file_kind(name) == 1) { *warned = 1; - if (d0) - for(s = d0; (s[0] = s[3]); ++s); #ifdef NO_DLERROR - fprintf(Stderr, "Cannot load library %s.\n", name); + fprintf(Stderr, "Cannot load library \"%s\".\n", name); #else - fprintf(Stderr, "Cannot load library %s", name); + fprintf(Stderr, "Cannot load library \"%s\"", name); cs = dlerror(); fprintf(Stderr, cs ? ":\n%s\n" : ".\n", cs); #endif @@ -410,9 +423,15 @@ libload_ASL(AmplExports *ae, const char *s, int ns, int warn) else { notfound: rc = rcnf; - if (warn) - fprintf(Stderr, "Cannot find library %.*s\nor %.*s%s\n", - ns, s, ns, s, afdll); + if (warn) { + buf[nx+ns] = 0; + if (file_kind(buf) == 2) { + buf[nx+ns] = SLASH; + fprintf(Stderr, "Cannot find library \"%s\".\n", buf); + } + else + fprintf(Stderr, "Cannot find library \"%.*s\".\n", ns, s); + } } if (buf != buf0) free(buf); diff --git a/src/asl/solvers/mqpcheckv.c b/src/asl/solvers/mqpcheckv.c index 67204aaa8..08da437f2 100644 --- a/src/asl/solvers/mqpcheckv.c +++ b/src/asl/solvers/mqpcheckv.c @@ -614,7 +614,7 @@ mqpcheckv_ASL(ASL *a, int co, QPinfo **QPIp, void **vp) expr *e; expr_n *en; int *cm, *colno, *qm, *rowq, *rowq0, *rowq1, *s, *vmi, *w, *z; - int arrays, co0, ftn, i, icol, j, ncol, ncom, nv, nz, pass; + int arrays, co0, ftn, i, icol, j, ncol, ncom, nv, nva, nz, pass; ograd *og, *og1, *og2, **ogp; real *L, *U, *delsq, *delsq0, *delsq1, objadj, t, *x; size_t *colq, *colq1, nelq; @@ -659,7 +659,10 @@ mqpcheckv_ASL(ASL *a, int co, QPinfo **QPIp, void **vp) nv = n_var; ncom = ncom0 + ncom1; if (!(S = *(Static**)vp)) { - x = (double *)Malloc(nv*(sizeof(double) + i = asl->i.n_var0 + asl->i.nsufext[0]; + if ((nva = nv) < i) + nva = i; + x = (double *)Malloc(nva*(sizeof(double) +sizeof(dyad*) +sizeof(ograd*) +sizeof(dispatch*) @@ -667,7 +670,7 @@ mqpcheckv_ASL(ASL *a, int co, QPinfo **QPIp, void **vp) +3*sizeof(int)) + sizeof(Memblock) + sizeof(Static)); - mb = (Memblock*)(x + nv); + mb = (Memblock*)(x + nva); mb->prev = mb->next = 0; S = (Static*)(mb + 1); *vp = (void*)S; @@ -676,16 +679,16 @@ mqpcheckv_ASL(ASL *a, int co, QPinfo **QPIp, void **vp) s_x = x; S->asl = asl; s_q = q = (dyad**)(S+1); - S->oq = (ograd**)(q + nv); - S->cdisp = cdisp = (dispatch**)(S->oq + nv); - S->cd0 = cd0 = (dispatch*)(cdisp + nv); - s_z = z = (int*)(cd0 + nv); - s_s = s = z + nv; - S->w = (int*)(s + nv); - memset(s, 0, nv*sizeof(int)); - memset(cdisp, 0, nv*sizeof(dispatch*)); - memset(q, 0, nv*sizeof(dyad *)); - memset(S->w, 0, nv*sizeof(int)); + S->oq = (ograd**)(q + nva); + S->cdisp = cdisp = (dispatch**)(S->oq + nva); + S->cd0 = cd0 = (dispatch*)(cdisp + nva); + s_z = z = (int*)(cd0 + nva); + s_s = s = z + nva; + S->w = (int*)(s + nva); + memset(s, 0, nva*sizeof(int)); + memset(cdisp, 0, nva*sizeof(dispatch*)); + memset(q, 0, nva*sizeof(dyad *)); + memset(S->w, 0, nva*sizeof(int)); if (ncom) { cterms = (term **)Malloc(ncom*(sizeof(term*)+sizeof(int))); memset(cterms, 0, ncom*sizeof(term*)); diff --git a/src/asl/solvers/objconst.c b/src/asl/solvers/objconst.c index 085d8364d..3c26e69d8 100644 --- a/src/asl/solvers/objconst.c +++ b/src/asl/solvers/objconst.c @@ -65,7 +65,7 @@ objconst_ASL(ASL *asl, int n) default: e = (expr_n*)(((ASL_fg*)asl)->I.obj_de_ + n)->e; } - if (e->op == opnum) + if (e->op == opnum || e->op == (efunc_n *)f_OPNUM) return e->v; } return 0; diff --git a/src/asl/solvers/xsum0.out b/src/asl/solvers/xsum0.out index bf3a9f019..f21b4f78a 100644 --- a/src/asl/solvers/xsum0.out +++ b/src/asl/solvers/xsum0.out @@ -8,7 +8,7 @@ arithchk.c 91ee1e0 5988 asl.h f654881e 41016 asl_pfg.h 6483336 1268 asl_pfgh.h 49b5a53 1288 -asldate.c 1aaf2c8 29 +asldate.c fee89a64 29 atof.c 1fabc7d3 1747 auxinfo.c 1a3c8690 1488 avltree.c 10aeaa58 11346 @@ -49,9 +49,9 @@ fpsetprec64.s 987339e 488 fullhes.c eeea81e 3978 func_add.c f0fbaf4e 11444 funcadd.c f4e86ce3 3493 -funcadd.h 1f9107e8 16174 +funcadd.h ea4c340e 16205 funcadd0.c 10310942 1338 -funcadd1.c 1606928f 10153 +funcadd1.c ec16454a 10574 funcaddk.c 1913fb94 3359 funcaddr.c fc16b89a 1197 g_fmt.c efcfdd3b 3452 @@ -80,7 +80,7 @@ mip_pri.c f1dd1d47 7887 misc.c f14430af 28836 mpec_adj.c e172a389 9468 mpec_adj0.c efb8be74 70 -mqpcheckv.c f59e1148 19285 +mqpcheckv.c 58f6e67 19377 mypow.c 1571ef65 2294 names.c f8260637 3984 nl_obj.c e8fa1e1 2560 @@ -93,7 +93,7 @@ obj_adj.c f415c1b4 13409 obj_adj.h eed794cf 2218 obj_adj0.c ffe042be 67 obj_prec.c fd065560 1440 -objconst.c 11aa4770 2257 +objconst.c b53a63b 2288 objval.c 1ba4b273 5294 objval_.c f830a04e 3516 op_type.c f0c0c4a8 1255