Skip to content

Commit d683535

Browse files
committed
linux: make NumberUtilities_strtod.cpp compile
Two issues here: - wchar_t and WCHAR have different sizes on Linux (32bit and 16bit). This can happen since wchar_t is compiler defined and WCHAR is defined as an unsigned short. To avoid ambiguities just change all uses of wchar_t for wchar16 in NumberUtilities*. This should probably done everywhere, including changing WCHAR to wchar16 too, but for now this is the minimum patch that makes this file compile while leaving it in a consistent state. - The way the DECIMAL structure is accessed does not match its definition in pal/. According to the MSDN documentation the tagDEC struct has its unions defined as anonymous, and pal/ does not do that. So change the definition and remove the apparently unused macros below.
1 parent bea508d commit d683535

5 files changed

Lines changed: 49 additions & 61 deletions

File tree

lib/Common/Common/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ add_library (Chakra.Common.Common
1010
Jobs.cpp
1111
MathUtil.cpp
1212
NumberUtilities.cpp
13-
# NumberUtilities_strtod.cpp
13+
NumberUtilities_strtod.cpp
1414
RejitReason.cpp
1515
SmartFpuControl.cpp
1616
Tick.cpp

lib/Common/Common/NumberUtilities.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ namespace Js
3737
return ch >= '0' && ch <= '9';
3838
}
3939

40-
BOOL NumberUtilities::FHexDigit(wchar_t ch, int *pw)
40+
BOOL NumberUtilities::FHexDigit(wchar16 ch, int *pw)
4141
{
4242
if ((ch -= '0') <= 9)
4343
{
@@ -231,7 +231,7 @@ namespace Js
231231
return cchWritten;
232232
}
233233

234-
BOOL NumberUtilities::TryConvertToUInt32(const wchar_t* str, int length, uint32* intVal)
234+
BOOL NumberUtilities::TryConvertToUInt32(const wchar16* str, int length, uint32* intVal)
235235
{
236236
if (length <= 0 || length > 10)
237237
{
@@ -628,12 +628,12 @@ namespace Js
628628
return Js::NumberUtilities::StrToDbl<EncodedChar>(psz, ppchLim, likelyInt);
629629
}
630630

631-
template double NumberUtilities::StrToDbl<wchar_t>(const wchar_t * psz, const wchar_t **ppchLim, Js::ScriptContext *const scriptContext);
631+
template double NumberUtilities::StrToDbl<wchar16>(const wchar16 * psz, const wchar16 **ppchLim, Js::ScriptContext *const scriptContext);
632632
template double NumberUtilities::StrToDbl<utf8char_t>(const utf8char_t * psz, const utf8char_t **ppchLim, Js::ScriptContext *const scriptContext);
633-
template double NumberUtilities::DblFromHex<wchar_t>(const wchar_t *psz, const wchar_t **ppchLim);
633+
template double NumberUtilities::DblFromHex<wchar16>(const wchar16 *psz, const wchar16 **ppchLim);
634634
template double NumberUtilities::DblFromHex<utf8char_t>(const utf8char_t *psz, const utf8char_t **ppchLim);
635-
template double NumberUtilities::DblFromBinary<wchar_t>(const wchar_t *psz, const wchar_t **ppchLim);
635+
template double NumberUtilities::DblFromBinary<wchar16>(const wchar16 *psz, const wchar16 **ppchLim);
636636
template double NumberUtilities::DblFromBinary<utf8char_t>(const utf8char_t *psz, const utf8char_t **ppchLim);
637-
template double NumberUtilities::DblFromOctal<wchar_t>(const wchar_t *psz, const wchar_t **ppchLim);
637+
template double NumberUtilities::DblFromOctal<wchar16>(const wchar16 *psz, const wchar16 **ppchLim);
638638
template double NumberUtilities::DblFromOctal<utf8char_t>(const utf8char_t *psz, const utf8char_t **ppchLim);
639639
}

lib/Common/Common/NumberUtilities.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ namespace Js
5555
{
5656
public:
5757
static bool IsDigit(int ch);
58-
static BOOL NumberUtilities::FHexDigit(wchar_t ch, int *pw);
58+
static BOOL NumberUtilities::FHexDigit(wchar16 ch, int *pw);
5959
static ulong MulLu(ulong lu1, ulong lu2, ulong *pluHi);
6060
static int AddLu(ulong *plu1, ulong lu2);
6161

@@ -79,7 +79,7 @@ namespace Js
7979
static charcount_t UInt16ToString(uint16 integer, __out __ecount(outBufferSize) WCHAR* outBuffer, charcount_t outBufferSize, char widthForPaddingZerosInsteadSpaces);
8080

8181
// Try to parse an integer string to find out if the string contains an index property name.
82-
static BOOL TryConvertToUInt32(const wchar_t* str, int length, uint32* intVal);
82+
static BOOL TryConvertToUInt32(const wchar16* str, int length, uint32* intVal);
8383

8484
static double Modulus(double dblLeft, double dblRight);
8585

@@ -94,15 +94,15 @@ namespace Js
9494
template<typename EncodedChar>
9595
static double StrToDbl(const EncodedChar *psz, const EncodedChar **ppchLim, bool& likelyInt);
9696

97-
static BOOL FDblToStr(double dbl, __out_ecount(nDstBufSize) wchar_t *psz, int nDstBufSize);
98-
static int FDblToStr(double dbl, NumberUtilities::FormatType ft, int nDigits, __out_ecount(cchDst) wchar_t *pchDst, int cchDst);
97+
static BOOL FDblToStr(double dbl, __out_ecount(nDstBufSize) wchar16 *psz, int nDstBufSize);
98+
static int FDblToStr(double dbl, NumberUtilities::FormatType ft, int nDigits, __out_ecount(cchDst) wchar16 *pchDst, int cchDst);
9999

100100
static BOOL FNonZeroFiniteDblToStr(double dbl, _Out_writes_(nDstBufSize) WCHAR* psz, int nDstBufSize);
101101
_Success_(return) static BOOL FNonZeroFiniteDblToStr(double dbl, _In_range_(2, 36) int radix, _Out_writes_(nDstBufSize) WCHAR* psz, int nDstBufSize);
102102

103103
static double DblFromDecimal(DECIMAL * pdecIn);
104104

105-
static void CodePointAsSurrogatePair(codepoint_t codePointValue, __out wchar_t* first, __out wchar_t* second);
105+
static void CodePointAsSurrogatePair(codepoint_t codePointValue, __out wchar16* first, __out wchar16* second);
106106
static codepoint_t SurrogatePairAsCodePoint(codepoint_t first, codepoint_t second);
107107

108108
static bool IsSurrogateUpperPart(codepoint_t codePointValue);

lib/Common/Common/NumberUtilities_strtod.cpp

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ static const double g_rgdblTens[] =
2424
1e20, 1e21, 1e22, 1e23, 1e24, 1e25, 1e26, 1e27, 1e28
2525
};
2626

27-
static inline wchar_t ToDigit(long wVal)
27+
static inline wchar16 ToDigit(long wVal)
2828
{
29-
//return reinterpret_cast<wchar_t>((wVal < 10) ? '0' + (ushort) wVal : 'a' - 10 + (ushort) wVal);
29+
//return reinterpret_cast<wchar16>((wVal < 10) ? '0' + (ushort) wVal : 'a' - 10 + (ushort) wVal);
3030
return (ushort)((wVal < 10) ? '0' + (ushort) wVal : 'a' - 10 + (ushort) wVal);
3131
}
3232

@@ -1256,7 +1256,7 @@ double Js::NumberUtilities::StrToDbl( const EncodedChar *psz, const EncodedChar
12561256
return dbl;
12571257
}
12581258

1259-
template double Js::NumberUtilities::StrToDbl<wchar_t>( const wchar_t * psz, const wchar_t **ppchLim, bool& likelyInt );
1259+
template double Js::NumberUtilities::StrToDbl<wchar16>( const wchar16 * psz, const wchar16 **ppchLim, bool& likelyInt );
12601260
template double Js::NumberUtilities::StrToDbl<utf8char_t>(const utf8char_t * psz, const utf8char_t **ppchLim, bool& likelyInt);
12611261

12621262
/***************************************************************************
@@ -1919,18 +1919,18 @@ static BOOL FormatDigits(_In_reads_(pbLim - pbSrc) byte *pbSrc, byte *pbLim, int
19191919
Assert(wExp10 < 1000);
19201920
if (wExp10 >= 100)
19211921
{
1922-
*pchDst++ = (wchar_t)('0' + wExp10 / 100);
1922+
*pchDst++ = (wchar16)('0' + wExp10 / 100);
19231923
wExp10 %= 100;
1924-
*pchDst++ = (wchar_t)('0' + wExp10 / 10);
1924+
*pchDst++ = (wchar16)('0' + wExp10 / 10);
19251925
wExp10 %= 10;
19261926
}
19271927
else if (wExp10 >= 10)
19281928
{
1929-
*pchDst++ = (wchar_t)('0' + wExp10 / 10);
1929+
*pchDst++ = (wchar16)('0' + wExp10 / 10);
19301930
wExp10 %= 10;
19311931
}
19321932
#pragma prefast(suppress:26014, "We have calculate the check the buffer size above already")
1933-
*pchDst++ = (wchar_t)('0' + wExp10);
1933+
*pchDst++ = (wchar16)('0' + wExp10);
19341934
*pchDst = 0;
19351935
}
19361936
else if (wExp10 <= 0)
@@ -1963,7 +1963,7 @@ static BOOL FormatDigits(_In_reads_(pbLim - pbSrc) byte *pbSrc, byte *pbLim, int
19631963

19641964
__success(return <= nDstBufSize)
19651965
#pragma prefast(suppress:6101, "when return value is > nDstBufSize, the pchDst is not initialized. Prefast doesn't seems to pick that up in the annotation")
1966-
static int FormatDigitsFixed(byte *pbSrc, byte *pbLim, int wExp10, int nFractionDigits, __out_ecount_part(nDstBufSize, return) wchar_t *pchDst, int nDstBufSize)
1966+
static int FormatDigitsFixed(byte *pbSrc, byte *pbLim, int wExp10, int nFractionDigits, __out_ecount_part(nDstBufSize, return) wchar16 *pchDst, int nDstBufSize)
19671967
{
19681968
AnalysisAssert(pbLim > pbSrc);
19691969
AssertArrMem(pbSrc, pbLim - pbSrc);
@@ -2054,7 +2054,7 @@ static int FormatDigitsExponential(
20542054
byte * pbLim,
20552055
int wExp10,
20562056
int nFractionDigits,
2057-
__out_ecount_part(cchDst,return) wchar_t * pchDst,
2057+
__out_ecount_part(cchDst,return) wchar16 * pchDst,
20582058
int cchDst
20592059
)
20602060
{
@@ -2105,7 +2105,7 @@ static int FormatDigitsExponential(
21052105
if (cchDst < n) return n;
21062106

21072107
#if DBG // save pchDst to validate n
2108-
wchar_t * pchDstStart = pchDst;
2108+
wchar16 * pchDstStart = pchDst;
21092109
#endif
21102110

21112111
// First digit
@@ -2148,17 +2148,17 @@ static int FormatDigitsExponential(
21482148
// Exponent Digits
21492149
if (wExp10 >= 100)
21502150
{
2151-
*pchDst++ = (wchar_t)('0' + wExp10 / 100);
2151+
*pchDst++ = (wchar16)('0' + wExp10 / 100);
21522152
wExp10 %= 100;
2153-
*pchDst++ = (wchar_t)('0' + wExp10 / 10);
2153+
*pchDst++ = (wchar16)('0' + wExp10 / 10);
21542154
wExp10 %= 10;
21552155
}
21562156
else if (wExp10 >= 10)
21572157
{
2158-
*pchDst++ = (wchar_t)('0' + wExp10 / 10);
2158+
*pchDst++ = (wchar16)('0' + wExp10 / 10);
21592159
wExp10 %= 10;
21602160
}
2161-
*pchDst++ = (wchar_t)('0' + wExp10);
2161+
*pchDst++ = (wchar16)('0' + wExp10);
21622162

21632163
*pchDst = 0;
21642164
Assert(1 + pchDst - pchDstStart == n);
@@ -2241,7 +2241,7 @@ static int RoundTo(byte *pbSrc, byte *pbLim, int nDigits, __out_bcount(nDigits+1
22412241
* Returns the number of chars. in the result. If 'nDstBufSize'
22422242
* is less than this number, no data is written to the buffer 'pchDst'.
22432243
*/
2244-
int Js::NumberUtilities::FDblToStr(double dbl, Js::NumberUtilities::FormatType ft, int nDigits, __out_ecount(cchDst) wchar_t *pchDst, int cchDst)
2244+
int Js::NumberUtilities::FDblToStr(double dbl, Js::NumberUtilities::FormatType ft, int nDigits, __out_ecount(cchDst) wchar16 *pchDst, int cchDst)
22452245
{
22462246
int n = 0; // the no. of chars in the result.
22472247
int wExp10;
@@ -2254,7 +2254,7 @@ int Js::NumberUtilities::FDblToStr(double dbl, Js::NumberUtilities::FormatType f
22542254
{
22552255
n = 4; //(int)wcslen(OLESTR("NaN")) + 1;
22562256
if( cchDst >= n )
2257-
wcscpy_s(pchDst, cchDst, L"NaN");
2257+
wcscpy_s(pchDst, cchDst, CH_WSTR("NaN"));
22582258
}
22592259
else
22602260
{
@@ -2269,7 +2269,7 @@ int Js::NumberUtilities::FDblToStr(double dbl, Js::NumberUtilities::FormatType f
22692269
{
22702270
if (neg)
22712271
*pchDst++ = '-';
2272-
wcscpy_s(pchDst, cchDst - neg, L"Infinity");
2272+
wcscpy_s(pchDst, cchDst - neg, CH_WSTR("Infinity"));
22732273
}
22742274
}
22752275
return n;
@@ -2362,12 +2362,12 @@ int Js::NumberUtilities::FDblToStr(double dbl, Js::NumberUtilities::FormatType f
23622362
return n;
23632363
}
23642364

2365-
BOOL Js::NumberUtilities::FDblToStr(double dbl, __out_ecount(cchDst) wchar_t *pchDst, int cchDst)
2365+
BOOL Js::NumberUtilities::FDblToStr(double dbl, __out_ecount(cchDst) wchar16 *pchDst, int cchDst)
23662366
{
23672367
if (!Js::NumberUtilities::IsFinite(dbl))
23682368
{
23692369
if (Js::NumberUtilities::IsNan(dbl))
2370-
return 0 == wcscpy_s(pchDst, cchDst, L"NaN");
2370+
return 0 == wcscpy_s(pchDst, cchDst, CH_WSTR("NaN"));
23712371
else
23722372
{
23732373
if (dbl < 0)
@@ -2377,7 +2377,7 @@ BOOL Js::NumberUtilities::FDblToStr(double dbl, __out_ecount(cchDst) wchar_t *pc
23772377
cchDst--;
23782378
}
23792379

2380-
return 0 == wcscpy_s(pchDst, cchDst, L"Infinity");
2380+
return 0 == wcscpy_s(pchDst, cchDst, CH_WSTR("Infinity"));
23812381
}
23822382
}
23832383

@@ -2412,15 +2412,15 @@ BOOL Js::NumberUtilities::FNonZeroFiniteDblToStr(double dbl, __out_ecount(cchDst
24122412

24132413
#if DBG
24142414
double dblT;
2415-
const wchar_t *pch;
2415+
const wchar16 *pch;
24162416

24172417
// In Debug, always call FDblToRgbPrecise and verify that it converts back.
24182418
if (FDblToRgbPrecise(dbl, rgb, &wExp10, &pbLim))
24192419
{
24202420
if (FormatDigits(rgb, pbLim, wExp10, pchDst, cchDst))
24212421
{
24222422
bool likelyInt = true;
2423-
dblT = StrToDbl<wchar_t>(pchDst, &pch,likelyInt);
2423+
dblT = StrToDbl<wchar16>(pchDst, &pch,likelyInt);
24242424
Assert(0 == *pch);
24252425
Assert(dblT == dbl);
24262426
}
@@ -2446,7 +2446,7 @@ BOOL Js::NumberUtilities::FNonZeroFiniteDblToStr(double dbl, __out_ecount(cchDst
24462446

24472447
#if DBG
24482448
bool likelyInt = true;
2449-
dblT = StrToDbl<wchar_t>(pchDst, &pch, likelyInt);
2449+
dblT = StrToDbl<wchar16>(pchDst, &pch, likelyInt);
24502450
Assert(0 == *pch);
24512451
Assert(dblT == dbl);
24522452
#endif //DBG
@@ -2484,7 +2484,7 @@ BOOL Js::NumberUtilities::FNonZeroFiniteDblToStr(double dbl, _In_range_(2, 36) i
24842484
int wExp2, wExp, wDig;
24852485
int maxOutDigits, cchSig, cch;
24862486
int len = nDstBufSize;
2487-
wchar_t * ppsz = psz;
2487+
wchar16 * ppsz = psz;
24882488

24892489
if (0x80000000 & Js::NumberUtilities::LuHiDbl(dbl))
24902490
{
@@ -2611,16 +2611,16 @@ BOOL Js::NumberUtilities::FNonZeroFiniteDblToStr(double dbl, _In_range_(2, 36) i
26112611
{
26122612
if (wExp >= 1000)
26132613
{
2614-
*ppsz++ = (wchar_t)('0' + wExp / 1000);
2614+
*ppsz++ = (wchar16)('0' + wExp / 1000);
26152615
wExp %= 1000;
26162616
}
2617-
*ppsz++ = (wchar_t)('0' + wExp / 100);
2617+
*ppsz++ = (wchar16)('0' + wExp / 100);
26182618
wExp %= 100;
26192619
}
2620-
*ppsz++ = (wchar_t)('0' + wExp / 10);
2620+
*ppsz++ = (wchar16)('0' + wExp / 10);
26212621
wExp %= 10;
26222622
}
2623-
*ppsz++ = (wchar_t)('0' + wExp);
2623+
*ppsz++ = (wchar16)('0' + wExp);
26242624
*ppsz++ = ')';
26252625
*ppsz = 0;
26262626

@@ -2747,13 +2747,13 @@ double Js::NumberUtilities::DblFromDecimal(DECIMAL * pdecIn)
27472747
return dblRet;
27482748
}
27492749

2750-
void Js::NumberUtilities::CodePointAsSurrogatePair(codepoint_t codePointValue, __out wchar_t* first, __out wchar_t* second)
2750+
void Js::NumberUtilities::CodePointAsSurrogatePair(codepoint_t codePointValue, __out wchar16* first, __out wchar16* second)
27512751
{
27522752
AssertMsg(first != nullptr && second != nullptr, "Null ptr's passed in for out.");
27532753
AssertMsg(IsInSupplementaryPlane(codePointValue), "Code point is not a surrogate pair.");
27542754
codePointValue -= 0x10000;
2755-
*first = (wchar_t)(codePointValue >> 10) + 0xD800;
2756-
*second = (wchar_t)(codePointValue & 0x3FF /* This is same as cpv % 0x400 */) + 0xDC00;
2755+
*first = (wchar16)(codePointValue >> 10) + 0xD800;
2756+
*second = (wchar16)(codePointValue & 0x3FF /* This is same as cpv % 0x400 */) + 0xDC00;
27572757
}
27582758

27592759
codepoint_t Js::NumberUtilities::SurrogatePairAsCodePoint(codepoint_t first, codepoint_t second)

pal/inc/rt/palrt.h

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -486,42 +486,30 @@ typedef struct tagDEC {
486486
struct {
487487
BYTE sign;
488488
BYTE scale;
489-
} u;
489+
};
490490
USHORT signscale;
491-
} u;
491+
};
492492
USHORT wReserved;
493493
#else
494494
USHORT wReserved;
495495
union {
496496
struct {
497497
BYTE scale;
498498
BYTE sign;
499-
} u;
499+
};
500500
USHORT signscale;
501-
} u;
501+
};
502502
#endif
503503
ULONG Hi32;
504504
union {
505505
struct {
506506
ULONG Lo32;
507507
ULONG Mid32;
508-
} v;
508+
};
509509
ULONGLONG Lo64;
510-
} v;
510+
};
511511
} DECIMAL, *LPDECIMAL;
512512

513-
#define DECIMAL_NEG ((BYTE)0x80)
514-
#define DECIMAL_SCALE(dec) ((dec).u.u.scale)
515-
#define DECIMAL_SIGN(dec) ((dec).u.u.sign)
516-
#define DECIMAL_SIGNSCALE(dec) ((dec).u.signscale)
517-
#define DECIMAL_LO32(dec) ((dec).v.v.Lo32)
518-
#define DECIMAL_MID32(dec) ((dec).v.v.Mid32)
519-
#define DECIMAL_HI32(dec) ((dec).Hi32)
520-
#define DECIMAL_LO64_GET(dec) ((dec).v.Lo64)
521-
#define DECIMAL_LO64_SET(dec,value) {(dec).v.Lo64 = value; }
522-
523-
#define DECIMAL_SETZERO(dec) {DECIMAL_LO32(dec) = 0; DECIMAL_MID32(dec) = 0; DECIMAL_HI32(dec) = 0; DECIMAL_SIGNSCALE(dec) = 0;}
524-
525513
typedef struct tagBLOB {
526514
ULONG cbSize;
527515
BYTE *pBlobData;

0 commit comments

Comments
 (0)