diff --git a/js/src/dtoa.c b/js/src/dtoa.c index ebdec083329..24f6a338268 100644 --- a/js/src/dtoa.c +++ b/js/src/dtoa.c @@ -1,3 +1,4 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /**************************************************************** * * The author of this software is David M. Gay. @@ -141,11 +142,6 @@ * floating-point numbers and flushes underflows to zero rather * than implementing gradual underflow, then you must also #define * Sudden_Underflow. - * #define YES_ALIAS to permit aliasing certain double values with - * arrays of ULongs. This leads to slightly better code with - * some compilers and was always used prior to 19990916, but it - * is not strictly legal and can cause trouble with aggressively - * optimizing compilers (e.g., gcc 2.95.1 under -O2). * #define USE_LOCALE to use the current locale's decimal_point value. * #define SET_INEXACT if IEEE arithmetic is being used and extra * computation should be done to set the inexact flag when the @@ -277,24 +273,13 @@ Exactly one of IEEE_8087, IEEE_MC68k, VAX, or IBM should be defined. typedef union { double d; ULong L[2]; } U; -#ifdef YES_ALIAS -#define dval(x) x +#define dval(x) ((x).d) #ifdef IEEE_8087 -#define word0(x) ((ULong *)&x)[1] -#define word1(x) ((ULong *)&x)[0] +#define word0(x) ((x).L[1]) +#define word1(x) ((x).L[0]) #else -#define word0(x) ((ULong *)&x)[0] -#define word1(x) ((ULong *)&x)[1] -#endif -#else -#ifdef IEEE_8087 -#define word0(x) ((U*)&x)->L[1] -#define word1(x) ((U*)&x)->L[0] -#else -#define word0(x) ((U*)&x)->L[0] -#define word1(x) ((U*)&x)->L[1] -#endif -#define dval(x) ((U*)&x)->d +#define word0(x) ((x).L[0]) +#define word1(x) ((x).L[1]) #endif /* The following definition of Storeinc is appropriate for MIPS processors. @@ -1103,13 +1088,13 @@ diff static double ulp #ifdef KR_headers - (x) double x; + (x) U x; #else - (double x) + (U x) #endif { register Long L; - double a; + U a; L = (word0(x) & Exp_mask) - (P-1)*Exp_msk1; #ifndef Avoid_Underflow @@ -1152,7 +1137,7 @@ b2d { ULong *xa, *xa0, w, y, z; int k; - double d; + U d; #ifdef VAX ULong d0, d1; #else @@ -1215,9 +1200,9 @@ b2d static Bigint * d2b #ifdef KR_headers - (d, e, bits) double d; int *e, *bits; + (d, e, bits) U d; int *e, *bits; #else - (double d, int *e, int *bits) + (U d, int *e, int *bits) #endif { Bigint *b; @@ -1358,7 +1343,7 @@ ratio (Bigint *a, Bigint *b) #endif { - double da, db; + U da, db; int k, ka, kb; dval(da) = b2d(a, &ka); @@ -1463,9 +1448,9 @@ match static void hexnan #ifdef KR_headers - (rvp, sp) double *rvp; CONST char **sp; + (rvp, sp) U *rvp; CONST char **sp; #else - (double *rvp, CONST char **sp) + (U *rvp, CONST char **sp) #endif { ULong c, x[2]; @@ -1545,7 +1530,8 @@ _strtod int bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, dsign, e, e1, esign, i, j, k, nd, nd0, nf, nz, nz0, sign; CONST char *s, *s0, *s1; - double aadj, aadj1, adj, rv, rv0; + double aadj, adj; + U aadj1, rv, rv0; Long L; ULong y, z; Bigint *bb, *bb1, *bd, *bd0, *bs, *delta; @@ -1560,7 +1546,7 @@ _strtod #endif #ifdef __GNUC__ - delta = bb = bd = bs = 0; + delta = bb = bd = bs = 0; #endif sign = nz0 = nz = 0; @@ -1962,7 +1948,7 @@ _strtod for(;;) { bd = Balloc(bd0->k); Bcopy(bd, bd0); - bb = d2b(dval(rv), &bbe, &bbbits); /* rv = bb * 2^bbe */ + bb = d2b(rv, &bbe, &bbbits); /* rv = bb * 2^bbe */ bs = i2b(1); if (e >= 0) { @@ -2079,13 +2065,13 @@ _strtod if ((word0(rv) & Exp_mask) <= P*Exp_msk1) { word0(rv) += P*Exp_msk1; - dval(rv) += adj*ulp(dval(rv)); + dval(rv) += adj*ulp(rv); word0(rv) -= P*Exp_msk1; } else #endif /*Sudden_Underflow*/ #endif /*Avoid_Underflow*/ - dval(rv) += adj*ulp(dval(rv)); + dval(rv) += adj*ulp(rv); } break; } @@ -2108,7 +2094,7 @@ _strtod #ifdef Sudden_Underflow if ((word0(rv) & Exp_mask) <= P*Exp_msk1) { word0(rv) += P*Exp_msk1; - adj *= ulp(dval(rv)); + adj *= ulp(rv); if (dsign) dval(rv) += adj; else @@ -2118,7 +2104,7 @@ _strtod } #endif /*Sudden_Underflow*/ #endif /*Avoid_Underflow*/ - adj *= ulp(dval(rv)); + adj *= ulp(rv); if (dsign) dval(rv) += adj; else @@ -2227,10 +2213,10 @@ _strtod break; #endif if (dsign) - dval(rv) += ulp(dval(rv)); + dval(rv) += ulp(rv); #ifndef ROUND_BIASED else { - dval(rv) -= ulp(dval(rv)); + dval(rv) -= ulp(rv); #ifndef Sudden_Underflow if (!dval(rv)) goto undfl; @@ -2244,14 +2230,14 @@ _strtod } if ((aadj = ratio(delta, bs)) <= 2.) { if (dsign) - aadj = aadj1 = 1.; + aadj = dval(aadj1) = 1.; else if (word1(rv) || word0(rv) & Bndry_mask) { #ifndef Sudden_Underflow if (word1(rv) == Tiny1 && !word0(rv)) goto undfl; #endif aadj = 1.; - aadj1 = -1.; + dval(aadj1) = -1.; } else { /* special case -- power of FLT_RADIX to be */ @@ -2261,24 +2247,24 @@ _strtod aadj = 1./FLT_RADIX; else aadj *= 0.5; - aadj1 = -aadj; + dval(aadj1) = -aadj; } } else { aadj *= 0.5; - aadj1 = dsign ? aadj : -aadj; + dval(aadj1) = dsign ? aadj : -aadj; #ifdef Check_FLT_ROUNDS switch(Rounding) { case 2: /* towards +infinity */ - aadj1 -= 0.5; + dval(aadj1) -= 0.5; break; case 0: /* towards 0 */ case 3: /* towards -infinity */ - aadj1 += 0.5; + dval(aadj1) += 0.5; } #else if (Flt_Rounds == 0) - aadj1 += 0.5; + dval(aadj1) += 0.5; #endif /*Check_FLT_ROUNDS*/ } y = word0(rv) & Exp_mask; @@ -2288,7 +2274,7 @@ _strtod if (y == Exp_msk1*(DBL_MAX_EXP+Bias-1)) { dval(rv0) = dval(rv); word0(rv) -= P*Exp_msk1; - adj = aadj1 * ulp(dval(rv)); + adj = dval(aadj1) * ulp(rv); dval(rv) += adj; if ((word0(rv) & Exp_mask) >= Exp_msk1*(DBL_MAX_EXP+Bias-P)) { @@ -2308,18 +2294,18 @@ _strtod if ((z = (ULong) aadj) <= 0) z = 1; aadj = z; - aadj1 = dsign ? aadj : -aadj; + dval(aadj1) = dsign ? aadj : -aadj; } word0(aadj1) += (2*P+1)*Exp_msk1 - y; } - adj = aadj1 * ulp(dval(rv)); + adj = dval(aadj1) * ulp(rv); dval(rv) += adj; #else #ifdef Sudden_Underflow if ((word0(rv) & Exp_mask) <= P*Exp_msk1) { dval(rv0) = dval(rv); word0(rv) += P*Exp_msk1; - adj = aadj1 * ulp(dval(rv)); + adj = dval(aadj1) * ulp(rv); dval(rv) += adj; #ifdef IBM if ((word0(rv) & Exp_mask) < P*Exp_msk1) @@ -2338,7 +2324,7 @@ _strtod word0(rv) -= P*Exp_msk1; } else { - adj = aadj1 * ulp(dval(rv)); + adj = dval(aadj1) * ulp(rv); dval(rv) += adj; } #else /*Sudden_Underflow*/ @@ -2350,11 +2336,11 @@ _strtod * example: 1.2e-307 . */ if (y <= (P-1)*Exp_msk1 && aadj > 1.) { - aadj1 = (double)(int)(aadj + 0.5); + dval(aadj1) = (double)(int)(aadj + 0.5); if (!dsign) - aadj1 = -aadj1; + dval(aadj1) = -dval(aadj1); } - adj = aadj1 * ulp(dval(rv)); + adj = dval(aadj1) * ulp(rv); dval(rv) += adj; #endif /*Sudden_Underflow*/ #endif /*Avoid_Underflow*/ @@ -2646,9 +2632,9 @@ freedtoa(char *s) dtoa #ifdef KR_headers (d, mode, ndigits, decpt, sign, rve) - double d; int mode, ndigits, *decpt, *sign; char **rve; + U d; int mode, ndigits, *decpt, *sign; char **rve; #else - (double d, int mode, int ndigits, int *decpt, int *sign, char **rve) + (U d, int mode, int ndigits, int *decpt, int *sign, char **rve) #endif { /* Arguments ndigits, decpt, sign are similar to those @@ -2694,7 +2680,8 @@ dtoa ULong x; #endif Bigint *b, *b1, *delta, *mlo, *mhi, *S; - double d2, ds, eps; + U d2, eps; + double ds; char *s, *s0; #ifdef Honor_FLT_ROUNDS int rounding; @@ -2704,8 +2691,8 @@ dtoa #endif #ifdef __GNUC__ - ilim = ilim1 = 0; - mlo = NULL; + ilim = ilim1 = 0; + mlo = NULL; #endif #ifndef MULTIPLE_THREADS @@ -2761,7 +2748,7 @@ dtoa } #endif - b = d2b(dval(d), &be, &bbits); + b = d2b(d, &be, &bbits); #ifdef Sudden_Underflow i = (int)(word0(d) >> Exp_shift1 & (Exp_mask>>Exp_shift1)); #else diff --git a/js/src/jsapi.cpp b/js/src/jsapi.cpp index 4d06c661ee7..b2f0bd72d4a 100644 --- a/js/src/jsapi.cpp +++ b/js/src/jsapi.cpp @@ -1361,10 +1361,12 @@ JS_InitStandardClasses(JSContext *cx, JSObject *obj) js_InitDateClass(cx, obj); } -#define CLASP(name) ((JSClass *)&js_##name##Class) +#define CLASP(name) (&js_##name##Class) +#define EXT_CLASP(name) (&js_##name##Class.base) #define EAGER_ATOM(name) ATOM_OFFSET(name), NULL #define EAGER_CLASS_ATOM(name) CLASS_ATOM_OFFSET(name), NULL #define EAGER_ATOM_AND_CLASP(name) EAGER_CLASS_ATOM(name), CLASP(name) +#define EAGER_ATOM_AND_EXT_CLASP(name) EAGER_CLASS_ATOM(name), EXT_CLASP(name) #define LAZY_ATOM(name) ATOM_OFFSET(lazy.name), js_##name##_str typedef struct JSStdName { @@ -1415,8 +1417,8 @@ static JSStdName standard_class_atoms[] = { #endif #if JS_HAS_XML_SUPPORT {js_InitXMLClass, EAGER_ATOM_AND_CLASP(XML)}, - {js_InitNamespaceClass, EAGER_ATOM_AND_CLASP(Namespace)}, - {js_InitQNameClass, EAGER_ATOM_AND_CLASP(QName)}, + {js_InitNamespaceClass, EAGER_ATOM_AND_EXT_CLASP(Namespace)}, + {js_InitQNameClass, EAGER_ATOM_AND_EXT_CLASP(QName)}, #endif #if JS_HAS_FILE_OBJECT {js_InitFileClass, EAGER_ATOM_AND_CLASP(File)}, diff --git a/js/src/jscntxt.cpp b/js/src/jscntxt.cpp index 8476cd3170c..2c3815c6522 100644 --- a/js/src/jscntxt.cpp +++ b/js/src/jscntxt.cpp @@ -510,9 +510,7 @@ js_ContextIterator(JSRuntime *rt, JSBool unlocked, JSContext **iterp) if (unlocked) JS_LOCK_GC(rt); - if (!cx) - cx = (JSContext *)&rt->contextList; - cx = (JSContext *)cx->links.next; + cx = (JSContext *) (cx ? cx->links.next : rt->contextList.next); if (&cx->links == &rt->contextList) cx = NULL; *iterp = cx; diff --git a/js/src/jsdbgapi.cpp b/js/src/jsdbgapi.cpp index 63e1a952a74..6e2075779c6 100644 --- a/js/src/jsdbgapi.cpp +++ b/js/src/jsdbgapi.cpp @@ -86,7 +86,7 @@ FindTrap(JSRuntime *rt, JSScript *script, jsbytecode *pc) JSTrap *trap; for (trap = (JSTrap *)rt->trapList.next; - trap != (JSTrap *)&rt->trapList; + &trap->links != &rt->trapList; trap = (JSTrap *)trap->links.next) { if (trap->script == script && trap->pc == pc) return trap; @@ -105,7 +105,8 @@ js_UntrapScriptCode(JSContext *cx, JSScript *script) rt = cx->runtime; DBG_LOCK(rt); for (trap = (JSTrap *)rt->trapList.next; - trap != (JSTrap *)&rt->trapList; + &trap->links != + &rt->trapList; trap = (JSTrap *)trap->links.next) { if (trap->script == script && (size_t)(trap->pc - script->code) < script->length) { @@ -240,7 +241,7 @@ JS_ClearScriptTraps(JSContext *cx, JSScript *script) rt = cx->runtime; DBG_LOCK(rt); for (trap = (JSTrap *)rt->trapList.next; - trap != (JSTrap *)&rt->trapList; + &trap->links != &rt->trapList; trap = next) { next = (JSTrap *)trap->links.next; if (trap->script == script) { @@ -264,7 +265,7 @@ JS_ClearAllTraps(JSContext *cx) rt = cx->runtime; DBG_LOCK(rt); for (trap = (JSTrap *)rt->trapList.next; - trap != (JSTrap *)&rt->trapList; + &trap->links != &rt->trapList; trap = next) { next = (JSTrap *)trap->links.next; sample = rt->debuggerMutations; @@ -430,7 +431,7 @@ js_TraceWatchPoints(JSTracer *trc, JSObject *obj) rt = trc->context->runtime; for (wp = (JSWatchPoint *)rt->watchPointList.next; - wp != (JSWatchPoint *)&rt->watchPointList; + &wp->links != &rt->watchPointList; wp = (JSWatchPoint *)wp->links.next) { if (wp->object == obj) { TRACE_SCOPE_PROPERTY(trc, wp->sprop); @@ -454,7 +455,7 @@ js_SweepWatchPoints(JSContext *cx) rt = cx->runtime; DBG_LOCK(rt); for (wp = (JSWatchPoint *)rt->watchPointList.next; - wp != (JSWatchPoint *)&rt->watchPointList; + &wp->links != &rt->watchPointList; wp = next) { next = (JSWatchPoint *)wp->links.next; if (js_IsAboutToBeFinalized(cx, wp->object)) { @@ -481,7 +482,7 @@ FindWatchPoint(JSRuntime *rt, JSScope *scope, jsid id) JSWatchPoint *wp; for (wp = (JSWatchPoint *)rt->watchPointList.next; - wp != (JSWatchPoint *)&rt->watchPointList; + &wp->links != &rt->watchPointList; wp = (JSWatchPoint *)wp->links.next) { if (wp->object == scope->object && wp->sprop->id == id) return wp; @@ -517,7 +518,7 @@ js_GetWatchedSetter(JSRuntime *rt, JSScope *scope, if (scope) DBG_LOCK(rt); for (wp = (JSWatchPoint *)rt->watchPointList.next; - wp != (JSWatchPoint *)&rt->watchPointList; + &wp->links != &rt->watchPointList; wp = (JSWatchPoint *)wp->links.next) { if ((!scope || wp->object == scope->object) && wp->sprop == sprop) { setter = wp->setter; @@ -542,7 +543,7 @@ js_watch_set(JSContext *cx, JSObject *obj, jsval id, jsval *vp) rt = cx->runtime; DBG_LOCK(rt); for (wp = (JSWatchPoint *)rt->watchPointList.next; - wp != (JSWatchPoint *)&rt->watchPointList; + &wp->links != &rt->watchPointList; wp = (JSWatchPoint *)wp->links.next) { sprop = wp->sprop; if (wp->object == obj && SPROP_USERID(sprop) == id && @@ -860,7 +861,7 @@ JS_ClearWatchPoint(JSContext *cx, JSObject *obj, jsval id, rt = cx->runtime; DBG_LOCK(rt); for (wp = (JSWatchPoint *)rt->watchPointList.next; - wp != (JSWatchPoint *)&rt->watchPointList; + &wp->links != &rt->watchPointList; wp = (JSWatchPoint *)wp->links.next) { if (wp->object == obj && SPROP_USERID(wp->sprop) == id) { if (handlerp) @@ -888,7 +889,7 @@ JS_ClearWatchPointsForObject(JSContext *cx, JSObject *obj) rt = cx->runtime; DBG_LOCK(rt); for (wp = (JSWatchPoint *)rt->watchPointList.next; - wp != (JSWatchPoint *)&rt->watchPointList; + &wp->links != &rt->watchPointList; wp = next) { next = (JSWatchPoint *)wp->links.next; if (wp->object == obj) { @@ -914,7 +915,7 @@ JS_ClearAllWatchPoints(JSContext *cx) rt = cx->runtime; DBG_LOCK(rt); for (wp = (JSWatchPoint *)rt->watchPointList.next; - wp != (JSWatchPoint *)&rt->watchPointList; + &wp->links != &rt->watchPointList; wp = next) { next = (JSWatchPoint *)wp->links.next; sample = rt->debuggerMutations; diff --git a/js/src/jsdtoa.cpp b/js/src/jsdtoa.cpp index 8d7bf8ab9bc..48a15cfa725 100644 --- a/js/src/jsdtoa.cpp +++ b/js/src/jsdtoa.cpp @@ -139,8 +139,9 @@ JS_strtod(const char *s00, char **se, int *err) } JS_FRIEND_API(char *) -JS_dtostr(char *buffer, size_t bufferSize, JSDToStrMode mode, int precision, double d) +JS_dtostr(char *buffer, size_t bufferSize, JSDToStrMode mode, int precision, double dinput) { + U d; int decPt; /* Offset of decimal point from first digit */ int sign; /* Nonzero if the sign bit was set in d */ int nDigits; /* Number of significand digits returned by js_dtoa */ @@ -155,10 +156,11 @@ JS_dtostr(char *buffer, size_t bufferSize, JSDToStrMode mode, int precision, dou * Change mode here rather than below because the buffer may not be large * enough to hold a large integer. */ - if (mode == DTOSTR_FIXED && (d >= 1e21 || d <= -1e21)) + if (mode == DTOSTR_FIXED && (dinput >= 1e21 || dinput <= -1e21)) mode = DTOSTR_STANDARD; LOCK_DTOA(); + dval(d) = dinput; numBegin = dtoa(d, dtoaModes[mode], precision, &decPt, &sign, &numEnd); if (!numBegin) { UNLOCK_DTOA(); @@ -352,28 +354,30 @@ static uint32 quorem2(Bigint *b, int32 k) #define BASEDIGIT(digit) ((char)(((digit) >= 10) ? 'a' - 10 + (digit) : '0' + (digit))) JS_FRIEND_API(char *) -JS_dtobasestr(int base, double d) +JS_dtobasestr(int base, double dinput) { + U d; char *buffer; /* The output string */ char *p; /* Pointer to current position in the buffer */ char *pInt; /* Pointer to the beginning of the integer part of the string */ char *q; uint32 digit; - double di; /* d truncated to an integer */ - double df; /* The fractional part of d */ + U di; /* d truncated to an integer */ + U df; /* The fractional part of d */ JS_ASSERT(base >= 2 && base <= 36); + dval(d) = dinput; buffer = (char*) malloc(DTOBASESTR_BUFFER_SIZE); if (buffer) { p = buffer; - if (d < 0.0 + if (dval(d) < 0.0 #if defined(XP_WIN) || defined(XP_OS2) && !((word0(d) & Exp_mask) == Exp_mask && ((word0(d) & Frac_mask) || word1(d))) /* Visual C++ doesn't know how to compare against NaN */ #endif ) { *p++ = '-'; - d = -d; + dval(d) = -dval(d); } /* Check for Infinity and NaN */ @@ -385,9 +389,9 @@ JS_dtobasestr(int base, double d) LOCK_DTOA(); /* Output the integer part of d with the digits in reverse order. */ pInt = p; - di = fd_floor(d); - if (di <= 4294967295.0) { - uint32 n = (uint32)di; + dval(di) = fd_floor(dval(d)); + if (dval(di) <= 4294967295.0) { + uint32 n = (uint32)dval(di); if (n) do { uint32 m = n / base; @@ -426,8 +430,8 @@ JS_dtobasestr(int base, double d) *q-- = ch; } - df = d - di; - if (df != 0.0) { + dval(df) = dval(d) - dval(di); + if (dval(df) != 0.0) { /* We have a fraction. */ int e, bbits; int32 s2, done;