diff options
Diffstat (limited to 'src/classlibnative/bcltype')
-rw-r--r-- | src/classlibnative/bcltype/BCLType.nativeproj | 47 | ||||
-rw-r--r-- | src/classlibnative/bcltype/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/classlibnative/bcltype/arraynative.cpp | 12 | ||||
-rw-r--r-- | src/classlibnative/bcltype/console.cpp | 152 | ||||
-rw-r--r-- | src/classlibnative/bcltype/console.h | 45 | ||||
-rw-r--r-- | src/classlibnative/bcltype/number.cpp | 459 | ||||
-rw-r--r-- | src/classlibnative/bcltype/number.h | 14 |
7 files changed, 49 insertions, 681 deletions
diff --git a/src/classlibnative/bcltype/BCLType.nativeproj b/src/classlibnative/bcltype/BCLType.nativeproj deleted file mode 100644 index 719a420313..0000000000 --- a/src/classlibnative/bcltype/BCLType.nativeproj +++ /dev/null @@ -1,47 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="dogfood"> - <!--*****************************************************--> - <!--This MSBuild project file was automatically generated--> - <!--from the original SOURCES/DIRS file by the KBC tool.--> - <!--*****************************************************--> - <!--Import the settings--> - <Import Project="$(_NTDRIVE)$(_NTROOT)\ndp\clr\clr.props" /> - <Import Project="$(ClrBase)\src\debug\SetDebugTargetLocal.props" /> - <PropertyGroup Label="Globals"> - <SccProjectName>SAK</SccProjectName> - <SccAuxPath>SAK</SccAuxPath> - <SccLocalPath>SAK</SccLocalPath> - <SccProvider>SAK</SccProvider> - </PropertyGroup> - <!--Leaf project Properties--> - <PropertyGroup> - <BuildCoreBinaries>true</BuildCoreBinaries> - <BuildSysBinaries>true</BuildSysBinaries> - <UserIncludes>..\..\inc;$(Clrbase)\src\vm;$(Clrbase)\src\vm\$(TargetCpu);..\..\debug\inc\$(TargetCpu);..\..\debug\inc\dump;$(UserIncludes);$(VCToolsIncPath)</UserIncludes> - <OutputName>bcltype</OutputName> - <OutputPath>$(ClrLibDest)</OutputPath> - <TargetType>LIBRARY</TargetType> - <CDefines>$(CDefines);UNICODE;_UNICODE</CDefines> - <ClAdditionalOptions Condition="'$(PerfCountersSupportedBuild)' == 'true'">$(ClAdditionalOptions) -DENABLE_PERF_COUNTERS</ClAdditionalOptions> - <ClWarningLevel>4</ClWarningLevel> - </PropertyGroup> - <!--Leaf Project Items--> - <ItemGroup> - <CppCompile Include="ArrayNative.cpp" /> - <CppCompile Include="ArrayHelpers.cpp" /> - <CppCompile Include="Console.cpp" /> - <CppCompile Include="Currency.cpp" /> - <CppCompile Include="Decimal.cpp" /> - <CppCompile Include="WindowsRuntimeBufferHelper.cpp" /> - <CppCompile Include="Number.cpp" /> - <CppCompile Include="OAVariant.cpp" /> - <CppCompile Include="ObjectNative.cpp" /> - <CppCompile Include="StringNative.cpp" /> - <CppCompile Include="StringBuffer.cpp" /> - <CppCompile Include="System.cpp" /> - <CppCompile Include="VarArgsNative.cpp" /> - <CppCompile Include="Variant.cpp" /> - </ItemGroup> - <!--Import the targets--> - <Import Project="$(_NTDRIVE)$(_NTROOT)\ndp\clr\clr.targets" /> -</Project> diff --git a/src/classlibnative/bcltype/CMakeLists.txt b/src/classlibnative/bcltype/CMakeLists.txt index 4df909ae35..7999c0c90f 100644 --- a/src/classlibnative/bcltype/CMakeLists.txt +++ b/src/classlibnative/bcltype/CMakeLists.txt @@ -7,7 +7,6 @@ endif(PerfCountersSupportedBuild) set(BCLTYPE_SOURCES arraynative.cpp arrayhelpers.cpp - console.cpp currency.cpp decimal.cpp windowsruntimebufferhelper.cpp diff --git a/src/classlibnative/bcltype/arraynative.cpp b/src/classlibnative/bcltype/arraynative.cpp index 58fa4dd3e6..0eae8b2d07 100644 --- a/src/classlibnative/bcltype/arraynative.cpp +++ b/src/classlibnative/bcltype/arraynative.cpp @@ -961,7 +961,7 @@ void memmoveGCRefs(void *dest, const void *src, size_t len) } } - GCHeapUtilities::GetGCHeap()->SetCardsAfterBulkCopy((Object**)dest, len); + SetCardsAfterBulkCopy((Object**)dest, len); } void ArrayNative::ArrayCopyNoTypeCheck(BASEARRAYREF pSrc, unsigned int srcIndex, BASEARRAYREF pDest, unsigned int destIndex, unsigned int length) @@ -1021,7 +1021,7 @@ FCIMPL6(void, ArrayNative::ArrayCopy, ArrayBase* m_pSrc, INT32 m_iSrcIndex, Arra // cannot pass null for source or destination if (gc.pSrc == NULL || gc.pDst == NULL) { - FCThrowArgumentNullVoid(gc.pSrc==NULL ? W("source") : W("dest")); + FCThrowArgumentNullVoid(gc.pSrc==NULL ? W("sourceArray") : W("destinationArray")); } // source and destination must be arrays @@ -1048,16 +1048,16 @@ FCIMPL6(void, ArrayNative::ArrayCopy, ArrayBase* m_pSrc, INT32 m_iSrcIndex, Arra FCThrowArgumentOutOfRangeVoid(W("length"), W("ArgumentOutOfRange_NeedNonNegNum")); if (m_iSrcIndex < srcLB || (m_iSrcIndex - srcLB < 0)) - FCThrowArgumentOutOfRangeVoid(W("srcIndex"), W("ArgumentOutOfRange_ArrayLB")); + FCThrowArgumentOutOfRangeVoid(W("sourceIndex"), W("ArgumentOutOfRange_ArrayLB")); if (m_iDstIndex < destLB || (m_iDstIndex - destLB < 0)) - FCThrowArgumentOutOfRangeVoid(W("dstIndex"), W("ArgumentOutOfRange_ArrayLB")); + FCThrowArgumentOutOfRangeVoid(W("destinationIndex"), W("ArgumentOutOfRange_ArrayLB")); if ((DWORD)(m_iSrcIndex - srcLB + m_iLength) > srcLen) - FCThrowResVoid(kArgumentException, W("Arg_LongerThanSrcArray")); + FCThrowArgumentVoid(W("sourceArray"), W("Arg_LongerThanSrcArray")); if ((DWORD)(m_iDstIndex - destLB + m_iLength) > destLen) - FCThrowResVoid(kArgumentException, W("Arg_LongerThanDestArray")); + FCThrowArgumentVoid(W("destinationArray"), W("Arg_LongerThanDestArray")); int r = 0; diff --git a/src/classlibnative/bcltype/console.cpp b/src/classlibnative/bcltype/console.cpp deleted file mode 100644 index 7dfb30a5f5..0000000000 --- a/src/classlibnative/bcltype/console.cpp +++ /dev/null @@ -1,152 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. -// -// File: Console.cpp -// - -// -// Purpose: Native methods on System.Console -// -// - -#ifndef FEATURE_CORECLR - -#include "common.h" -#include "sbuffer.h" -#include <windows.h> -#include "console.h" - -// GetConsoleTitle sometimes interprets the second parameter (nSize) as number of bytes and sometimes as the number of chars. -// Instead of doing complicated and dangerous logic to determine if this may or may not occur, -// we simply assume the worst and reserve a bigger buffer. This way we may use a bit more memory, -// but we will always be safe. This macro helps us doing that: -#define ADJUST_NUM_CHARS(numChars) ((numChars) * 2) - -#define BUFF_SIZE(numChars) ( ((numChars) + 1) * sizeof(TCHAR) ) - -// A buffer of size ConsoleNative::MaxConsoleTitleLength is quite big. -// First, we try allocating a smaller buffer because most often, the console title is short. -// If it turns out that the short buffer size is insufficient, we try again using a larger buffer. -INT32 QCALLTYPE ConsoleNative::GetTitle(QCall::StringHandleOnStack outTitle, INT32& outTitleLen) { - - QCALL_CONTRACT; - - INT32 result = 0; - - BEGIN_QCALL; - - // Reserve buffer: - InlineSBuffer< ADJUST_NUM_CHARS(BUFF_SIZE(ShortConsoleTitleLength)) > titleBuff; - - // Hold last error: - DWORD lastError; - - // Read console title, get length of the title: - - BYTE *buffPtr = titleBuff.OpenRawBuffer( ADJUST_NUM_CHARS(BUFF_SIZE(ShortConsoleTitleLength)) ); - - SetLastError(0); - DWORD len = GetConsoleTitle((TCHAR *) buffPtr, ADJUST_NUM_CHARS(ShortConsoleTitleLength + 1)); - lastError = GetLastError(); - - titleBuff.CloseRawBuffer(); - - // If the title length is larger than supported maximum, do not bother reading it, just return the length: - if (len > MaxConsoleTitleLength) { - - outTitleLen = len; - outTitle.Set(W("")); - result = 0; - - // If title length is within valid range: - } else { - - // If the title is longer than the short buffer, but can fit in the max supported length, - // read it again with the long buffer: - if (len > ShortConsoleTitleLength) { - - COUNT_T buffSize = ADJUST_NUM_CHARS(BUFF_SIZE(len)); - titleBuff.SetSize(buffSize); - - BYTE *buffPtr = titleBuff.OpenRawBuffer(buffSize); - - SetLastError(0); - len = GetConsoleTitle((TCHAR *) buffPtr, ADJUST_NUM_CHARS(len + 1)); - lastError = GetLastError(); - - titleBuff.CloseRawBuffer(); - } - - // Zero may indicate error or empty title. Check for error: - result = (INT32) (0 == len ? lastError : 0); - - // If no error, set title and length: - if (0 == result) { - const BYTE *cBuffPtr = (const BYTE *) titleBuff; - outTitle.Set((TCHAR *) cBuffPtr); - outTitleLen = (INT32) len; - - // If error, set to empty: - } else { - outTitleLen = (INT32) -1; - // No need to set the title string if we have an error anyway. - } - } // if title length is within valid range. - - END_QCALL; - - return result; -} - -// Block waiting for data to become available on the console stream indicated by the safe file handle passed. -// Ensure that the thread remains abortable in the process. -FCIMPL2(void, ConsoleStreamHelper::WaitForAvailableConsoleInput, SafeHandle* refThisUNSAFE, CLR_BOOL bIsPipe) -{ - FCALL_CONTRACT; - - SAFEHANDLEREF refConsoleHandle(refThisUNSAFE); - - HELPER_METHOD_FRAME_BEGIN_1(refConsoleHandle); - - // Prevent the console handle being closed under our feet. - SafeHandleHolder shh(&refConsoleHandle); - - // Don't pass the address of the native handle within the safe handle to DoAppropriateWait since the safe - // handle is on the GC heap and could be moved. Instead copy the native handle out into a stack location - // (this is safe because we've ref-counted the safe handle to prevent it being disposed on us). - HANDLE hNativeConsoleHandle = refConsoleHandle->GetHandle(); - - bool skipWait = false; - - // If we are reading from a pipe and the other end of the pipe was closed, then do not block. No one can write to it. - // Also we can skip blocking if we do have data available. We should block if nothing is available, with the assumption - // that Windows is smart enough to handle pipes where the other end is closed. - if (bIsPipe) - { - DWORD cBytesRead, cTotalBytesAvailable, cBytesLeftThisMessage; - int r = PeekNamedPipe(hNativeConsoleHandle, NULL, 0, &cBytesRead, &cTotalBytesAvailable, &cBytesLeftThisMessage); - if (r != 0) - { - skipWait = cTotalBytesAvailable > 0; - } - else - { - // Windows returns ERROR_BROKEN_PIPE if the other side of a pipe is closed. However, we've seen - // pipes return ERROR_NO_DATA and ERROR_PIPE_NOT_CONNECTED. Check for those too. - int errorCode = GetLastError(); - skipWait = errorCode == ERROR_BROKEN_PIPE || errorCode == ERROR_NO_DATA || errorCode == ERROR_PIPE_NOT_CONNECTED; - } - } - - // Perform the wait (DoAppropriateWait automatically handles thread aborts). - if (!skipWait) - { - GetThread()->DoAppropriateWait(1, &hNativeConsoleHandle, TRUE, INFINITE, WaitMode_Alertable); - } - - HELPER_METHOD_FRAME_END(); -} -FCIMPLEND - -#endif // ifndef FEATURE_CORECLR diff --git a/src/classlibnative/bcltype/console.h b/src/classlibnative/bcltype/console.h deleted file mode 100644 index b3772f2425..0000000000 --- a/src/classlibnative/bcltype/console.h +++ /dev/null @@ -1,45 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. -// -// File: Console.h -// - -// -// Purpose: Native methods on System.Console -// - -// -#ifndef _CONSOLE_H_ -#define _CONSOLE_H_ - -#ifndef FEATURE_CORECLR - -#include "qcall.h" - -class ConsoleNative { - -private: - - // Short buffer len to try using first: - static const INT32 ShortConsoleTitleLength = 200; - -public: - - // This value is copied from Console.cs. There is said: - // MSDN says console titles can be up to 64KB in length. - // But there is an exception if the buffer lengths longer than - // ~24500 Unicode characters are used. Oh well. - static const INT32 MaxConsoleTitleLength = 24500; - - static INT32 QCALLTYPE GetTitle(QCall::StringHandleOnStack outTitle, INT32& outTitleLen); -}; - -class ConsoleStreamHelper { -public: - static FCDECL2(void, WaitForAvailableConsoleInput, SafeHandle* refThisUNSAFE, CLR_BOOL bIsPipe); -}; - -#endif // ifndef FEATURE_CORECLR - -#endif // _CONSOLE_H_ diff --git a/src/classlibnative/bcltype/number.cpp b/src/classlibnative/bcltype/number.cpp index 6ca24d8672..3f2d63c70e 100644 --- a/src/classlibnative/bcltype/number.cpp +++ b/src/classlibnative/bcltype/number.cpp @@ -142,12 +142,6 @@ void DoubleToNumber(double value, int precision, NUMBER* number) WRAPPER_NO_CONTRACT _ASSERTE(number != NULL); -#ifndef FEATURE_BCL_FORMATTING - number->palNumber=PAL_DoubleToNumber(value); - IfNullThrow(number->palNumber); - number->palNumberType=PALNUMBERTYPE_DOUBLE; -#endif - number->precision = precision; if (((FPDOUBLE*)&value)->exp == 0x7FF) { number->scale = (((FPDOUBLE*)&value)->mantLo || ((FPDOUBLE*)&value)->mantHi) ? SCALE_NAN: SCALE_INF; @@ -736,13 +730,6 @@ void Int32ToNumber(int value, NUMBER* number) WRAPPER_NO_CONTRACT _ASSERTE(number != NULL); -#ifndef FEATURE_BCL_FORMATTING - number->palNumber=PAL_IntToNumber(value); - IfNullThrow(number->palNumber); - number->palNumberType=PALNUMBERTYPE_INT; -#endif - - wchar buffer[INT32_PRECISION+1]; number->precision = INT32_PRECISION; if (value >= 0) { @@ -769,12 +756,6 @@ void UInt32ToNumber(unsigned int value, NUMBER* number) WRAPPER_NO_CONTRACT _ASSERTE(number != NULL); -#ifndef FEATURE_BCL_FORMATTING - number->palNumber=PAL_UIntToNumber(value); - IfNullThrow(number->palNumber); - number->palNumberType=PALNUMBERTYPE_UINT; -#endif - wchar buffer[UINT32_PRECISION+1]; number->precision = UINT32_PRECISION; number->sign = 0; @@ -880,12 +861,6 @@ void Int64ToNumber(__int64 value, NUMBER* number) { WRAPPER_NO_CONTRACT -#ifndef FEATURE_BCL_FORMATTING - number->palNumber=PAL_Int64ToNumber(value); - IfNullThrow(number->palNumber); - number->palNumberType=PALNUMBERTYPE_INT64; -#endif - wchar buffer[INT64_PRECISION+1]; number->precision = INT64_PRECISION; if (value >= 0) { @@ -934,29 +909,6 @@ void UInt64ToNumber(unsigned __int64 value, NUMBER* number) } -#ifndef FEATURE_BCL_FORMATTING -void NumberToUInt64(NUMBER * number, unsigned __int64* value) -{ - _ASSERTE(NULL != number); - _ASSERTE(NULL != value); - - if (NULL != number && NULL != value) { - (*value) = 0; - int i = 0; - while (i < NUMBER_MAXDIGITS && i < number->precision && number->digits[i] != NULL) { - _ASSERTE((number->digits[i] - '0') >= 0 && (number->digits[i] - '0') <= 9); - *value = (10 * (*value)) + (number->digits[i] - '0'); - i++; - } - while (i < number->scale) { - *value = (10 * (*value)); - i++; - } - } -} -#endif - - void RoundNumber(NUMBER* number, int pos) { LIMITED_METHOD_CONTRACT @@ -985,50 +937,6 @@ void RoundNumber(NUMBER* number, int pos) } digits[i] = 0; -#ifndef FEATURE_BCL_FORMATTING -// -// The PAL stores PALNUMBER as the actual numeric type where as NUMBER is in string form; -// Convert NUMBER back into its original type and pass it to the PAL for later use -// - if (0 != number->palNumber) { - if (PALNUMBERTYPE_DOUBLE == number->palNumberType) { - // no need to round NaN or infinity double values - if (SCALE_NAN != ((unsigned int)number->scale) && SCALE_INF != ((unsigned int)number->scale)) { - double value = 0.0; - NumberToDouble(number, &value); - // make sure the rounding didn't accidently cause the good value - // to be turned into NaN or infinity - if (((FPDOUBLE*)&value)->exp != 0x7FF) { - number->palNumber=PAL_DoubleToNumber(value); - } - } - } - else { - unsigned __int64 value = 0; - NumberToUInt64(number, &value); - switch(number->palNumberType) { - case PALNUMBERTYPE_INT: - _ASSERTE((value >> 32) == 0); - number->palNumber=PAL_IntToNumber(((unsigned int)value) * (number->sign ? -1 : 1)); - break; - case PALNUMBERTYPE_UINT: - _ASSERTE((value >> 32) == 0); - number->palNumber=PAL_UIntToNumber((unsigned int)value); - break; - case PALNUMBERTYPE_INT64: - _ASSERTE((value >> 63) == 0); - number->palNumber=PAL_Int64ToNumber(((__int64)value) * (number->sign ? -1 : 1)); - break; - case PALNUMBERTYPE_UINT64: - number->palNumber=PAL_UInt64ToNumber(value); - break; - default: - CONSISTENCY_CHECK_MSGF(0, ("This palNumberType is not understood '(%d)''\n", number->palNumberType)); - break; - } - } - } -#endif } #if defined(_MSC_VER) && defined(_TARGET_X86_) @@ -1112,29 +1020,6 @@ wchar* FormatGeneral(__in_ecount(cchBuffer) wchar* buffer, SIZE_T cchBuffer, NUM } } -#ifndef FEATURE_BCL_FORMATTING - if (number->palNumber) - { - WCHAR sExp[2]={expChar}; - LPCWSTR strNumberDecimal(sNumberDecimal!=NULL?sNumberDecimal->GetBuffer():NULL); - LPCWSTR strPositive(sPositive!=NULL?sPositive->GetBuffer():NULL); - LPCWSTR strNegative(sNegative!=NULL?sNegative->GetBuffer():NULL); - LPCWSTR strZero(sZero!=NULL?sZero->GetBuffer():NULL); - - int nChars; - - // nMaxDigits for Scientific are 1 more than needed - if (scientific) - nChars=PAL_FormatScientific(NULL, buffer, cchBuffer, number->palNumber,-1,nMaxDigits-1,sExp,strNumberDecimal,strPositive,strNegative,strZero); - else - nChars=PAL_FormatDecimal(NULL, buffer, cchBuffer, number->palNumber,-1,nMaxDigits,-1, -1,-1,strNumberDecimal,NULL,strNegative,strZero); - - if(nChars<0) - return NULL; - return buffer+nChars; - } -#endif - wchar* dig = GetDigitsBuffer(number); _ASSERT(dig != NULL); if (digPos > 0) { @@ -1162,26 +1047,9 @@ wchar* FormatGeneral(__in_ecount(cchBuffer) wchar* buffer, SIZE_T cchBuffer, NUM wchar* FormatScientific(__in_ecount(cchBuffer) wchar* buffer, SIZE_T cchBuffer, NUMBER* number, int nMinDigits, int nMaxDigits, wchar expChar, STRINGREF sNumberDecimal, STRINGREF sPositive, STRINGREF sNegative, STRINGREF sZero) { - WRAPPER_NO_CONTRACT - _ASSERTE(number != NULL); - _ASSERTE(buffer != NULL); -#ifndef FEATURE_BCL_FORMATTING - if (number->palNumber) - { - WCHAR sExp[2]={expChar}; - LPCWSTR strNumberDecimal(sNumberDecimal!=NULL?sNumberDecimal->GetBuffer():NULL); - LPCWSTR strPositive(sPositive!=NULL?sPositive->GetBuffer():NULL); - LPCWSTR strNegative(sNegative!=NULL?sNegative->GetBuffer():NULL); - LPCWSTR strZero(sZero!=NULL?sZero->GetBuffer():NULL); - - // nMaxDigits passed into FormatScientific are 1 more than requested - int nChars=PAL_FormatScientific(NULL, buffer, cchBuffer, number->palNumber,nMinDigits, nMaxDigits-1,sExp,strNumberDecimal,strPositive,strNegative,strZero); - if(nChars<0) - ThrowLastError(); - return buffer+nChars; - } -#endif - + WRAPPER_NO_CONTRACT + _ASSERTE(number != NULL); + _ASSERTE(buffer != NULL); wchar* dig = GetDigitsBuffer(number); _ASSERTE(dig != NULL); @@ -1207,21 +1075,6 @@ wchar* FormatFixed(__in_ecount(cchBuffer) wchar* buffer, SIZE_T cchBuffer, NUMBE PRECONDITION(CheckPointer(number)); } CONTRACTL_END; -#ifndef FEATURE_BCL_FORMATTING - if (number->palNumber) - { - LPCWSTR strDecimal(sDecimal!=NULL?sDecimal->GetBuffer():NULL); - LPCWSTR strNegative(sNegative!=NULL?sNegative->GetBuffer():NULL); - LPCWSTR strZero(sZero!=NULL?sZero->GetBuffer():NULL); - - int nChars=PAL_FormatDecimal(NULL, buffer, cchBuffer, number->palNumber,nMinDigits,nMaxDigits,-1, -1,-1,strDecimal,W(""),strNegative,strZero); - if(nChars<0) - return NULL; - return buffer+nChars; - } -#endif - - int digPos = number->scale; wchar* dig = GetDigitsBuffer(number); const I4* groupDigits = NULL; @@ -1328,33 +1181,6 @@ wchar* FormatNumber(__in_ecount(cchBuffer) wchar* buffer, SIZE_T cchBuffer, NUMB PRECONDITION(CheckPointer(buffer)); PRECONDITION(CheckPointer(number)); } CONTRACTL_END; -#ifndef FEATURE_BCL_FORMATTING - if (number->palNumber) - { - LPCWSTR strDecimal(sNumberDecimal!=NULL?sNumberDecimal->GetBuffer():NULL); - LPCWSTR strGroup(sNumberGroup!=NULL?sNumberGroup->GetBuffer():NULL); - LPCWSTR strNegative(sNegative!=NULL?sNegative->GetBuffer():NULL); - LPCWSTR strZero(sZero!=NULL?sZero->GetBuffer():NULL); - int iPrimaryGroup=0; - int iSecondaryGroup=0; - if(cNumberGroup!=NULL) - { - int nGroups = cNumberGroup->GetNumComponents(); - I4* pGroups=(I4*)cNumberGroup->GetDataPtr(); - - if(nGroups>0) - iPrimaryGroup=pGroups[0]; - if(nGroups>1) - iSecondaryGroup=pGroups[1]; - } - - int nChars=PAL_FormatDecimal(NULL, buffer, cchBuffer, number->palNumber,nMinDigits,nMaxDigits, cNegativeNumberFormat, - iPrimaryGroup,iSecondaryGroup,strDecimal,strGroup,strNegative,strZero); - if(nChars<0) - return NULL; - return buffer+nChars; - } -#endif char ch; const char* fmt; @@ -1391,36 +1217,6 @@ wchar* FormatCurrency(__in_ecount(cchBuffer) wchar* buffer, SIZE_T cchBuffer, NU PRECONDITION(CheckPointer(number)); } CONTRACTL_END; -#ifndef FEATURE_BCL_FORMATTING - if (number->palNumber) - { - LPCWSTR strCurrencyDecimal(sCurrencyDecimal!=NULL?sCurrencyDecimal->GetBuffer():NULL); - LPCWSTR strCurrencyGroup(sCurrencyGroup!=NULL?sCurrencyGroup->GetBuffer():NULL); - LPCWSTR strNegative(sNegative!=NULL?sNegative->GetBuffer():NULL); - LPCWSTR strCurrency(sCurrency!=NULL?sCurrency->GetBuffer():NULL); - LPCWSTR strZero(sZero!=NULL?sZero->GetBuffer():NULL); - int iPrimaryGroup=0; - int iSecondaryGroup=0; - - if(cCurrencyGroup!=NULL) - { - int nGroups = cCurrencyGroup->GetNumComponents(); - I4* pGroups=(I4*)cCurrencyGroup->GetDataPtr(); - - if(nGroups>0) - iPrimaryGroup=pGroups[0]; - if(nGroups>1) - iSecondaryGroup=pGroups[1]; - } - - int nChars=PAL_FormatCurrency(NULL, buffer, cchBuffer, number->palNumber,nMinDigits,nMaxDigits,cNegCurrencyFormat, cPosCurrencyFormat, - iPrimaryGroup, iSecondaryGroup, strCurrencyDecimal,strCurrencyGroup,strNegative, strCurrency,strZero); - if (nChars<0) - return NULL; - - return buffer+nChars; - } -#endif char ch; const char* fmt; fmt = number->sign? @@ -1458,39 +1254,6 @@ wchar* FormatPercent(__in_ecount(cchBuffer) wchar* buffer, SIZE_T cchBuffer, NUM PRECONDITION(CheckPointer(number)); } CONTRACTL_END; - -#ifndef FEATURE_BCL_FORMATTING - if (number->palNumber) - { - LPCWSTR strPercentDecimal(sPercentDecimal!=NULL?sPercentDecimal->GetBuffer():NULL); - LPCWSTR strPercentGroup(sPercentGroup!=NULL?sPercentGroup->GetBuffer():NULL); - LPCWSTR strNegative(sNegative!=NULL?sNegative->GetBuffer():NULL); - LPCWSTR strPercent(sPercent!=NULL?sPercent->GetBuffer():NULL); - LPCWSTR strZero(sZero!=NULL?sZero->GetBuffer():NULL); - - int iPrimaryGroup=0; - int iSecondaryGroup=0; - - if(cPercentGroup!=NULL) - { - int nGroups = cPercentGroup->GetNumComponents(); - I4* pGroups=(I4*)cPercentGroup->GetDataPtr(); - - if(nGroups>0) - iPrimaryGroup=pGroups[0]; - if(nGroups>1) - iSecondaryGroup=pGroups[1]; - } - - int nChars=PAL_FormatPercent(NULL, buffer, cchBuffer, number->palNumber,nMinDigits,nMaxDigits,cNegativePercentFormat, cPositivePercentFormat, - iPrimaryGroup, iSecondaryGroup,strPercentDecimal,strPercentGroup,strNegative, strPercent,strZero); - if(nChars<0) - return NULL; - - return buffer+nChars; - } -#endif - char ch; const char* fmt; fmt = number->sign? @@ -1612,12 +1375,6 @@ STRINGREF NumberToString(NUMBER* number, wchar format, int nMaxDigits, NUMFMTREF STRINGREF sCurrencyGroup = numfmt->sCurrencyGroup; STRINGREF sNegative = numfmt->sNegative; STRINGREF sCurrency = numfmt->sCurrency; -#ifndef FEATURE_BCL_FORMATTING - if (numfmt->bIsInvariant || 0 == number->palNumber) - { - // So that FormatCurrency uses BCL format - number->palNumber = 0; -#endif // Prefix: bogus warning 22011: newBufferLen+=digCount may be smaller than MIN_BUFFER_SIZE PREFIX_ASSUME(digCount >=0 && digCount <= INT32_MAX); newBufferLen += digCount; @@ -1637,22 +1394,6 @@ STRINGREF NumberToString(NUMBER* number, wchar format, int nMaxDigits, NUMFMTREF RoundNumber(number, number->scale + nMaxDigits); // Don't change this line to use digPos since digCount could have its sign changed. dst = FormatCurrency(dst, static_cast<SIZE_T>(newBufferLen/sizeof(WCHAR)), number, nMinDigits,nMaxDigits, cNegCurrencyFormat, cPosCurrencyFormat, cCurrencyGroup, sCurrencyDecimal, sCurrencyGroup, sNegative, sCurrency,sZero); -#ifndef FEATURE_BCL_FORMATTING - } - else - { - for ( SIZE_T nChars=128;;nChars*=2) - { - dst = buffer = (WCHAR*)buf.AllocThrows(nChars * sizeof(WCHAR)); - dst = FormatCurrency(dst, nChars, number, nMinDigits, nMaxDigits, cNegCurrencyFormat, cPosCurrencyFormat, cCurrencyGroup, sCurrencyDecimal, sCurrencyGroup, sNegative, sCurrency,sZero); - if (dst) - break; - if (GetLastError()!=ERROR_INSUFFICIENT_BUFFER) - ThrowLastError(); - } - } -#endif - break; } case 'F': @@ -1672,49 +1413,25 @@ STRINGREF NumberToString(NUMBER* number, wchar format, int nMaxDigits, NUMFMTREF // It is critical to format with the same values that we use to calculate buffer size. STRINGREF sNumberDecimal = numfmt->sNumberDecimal; STRINGREF sNegative = numfmt->sNegative; -#ifndef FEATURE_BCL_FORMATTING - if (numfmt->bIsInvariant || 0 == number->palNumber) - { - // So that FormatFixed uses BCL format - number->palNumber = 0; -#endif - - newBufferLen += digCount; - newBufferLen += sNegative->GetStringLength(); // For number and exponent - newBufferLen += sNumberDecimal->GetStringLength(); - - _ASSERTE(newBufferLen >= MIN_BUFFER_SIZE); - if (newBufferLen > INT32_MAX) { - COMPlusThrowOM(); - } - newBufferLen = newBufferLen * sizeof(WCHAR); - dst = buffer = (WCHAR*)buf.AllocThrows(static_cast<SIZE_T>(newBufferLen)); - - RoundNumber(number, number->scale + nMaxDigits); + + newBufferLen += digCount; + newBufferLen += sNegative->GetStringLength(); // For number and exponent + newBufferLen += sNumberDecimal->GetStringLength(); + + _ASSERTE(newBufferLen >= MIN_BUFFER_SIZE); + if (newBufferLen > INT32_MAX) { + COMPlusThrowOM(); + } + newBufferLen = newBufferLen * sizeof(WCHAR); + dst = buffer = (WCHAR*)buf.AllocThrows(static_cast<SIZE_T>(newBufferLen)); + + RoundNumber(number, number->scale + nMaxDigits); if (number->sign) { AddStringRef(&dst, sNegative); } dst = FormatFixed(dst, static_cast<SIZE_T>(newBufferLen/sizeof(WCHAR)-(dst-buffer)), number, nMinDigits,nMaxDigits, NULL, sNumberDecimal, NULL, sNegative, sZero); -#ifndef FEATURE_BCL_FORMATTING - } - else - { - for( SIZE_T nChars=128;;nChars*=2) - { - dst = buffer = (WCHAR*)buf.AllocThrows(nChars * sizeof(WCHAR)); - dst = FormatFixed(dst, nChars, number, nMinDigits,nMaxDigits, - NULL, - sNumberDecimal, NULL,sNegative,sZero); - - if (dst) - break; - if (GetLastError()!=ERROR_INSUFFICIENT_BUFFER) - ThrowLastError(); - } - } -#endif break; } @@ -1737,44 +1454,21 @@ STRINGREF NumberToString(NUMBER* number, wchar format, int nMaxDigits, NUMFMTREF STRINGREF sNumberDecimal = numfmt->sNumberDecimal; STRINGREF sNumberGroup = numfmt->sNumberGroup; int cNegativeNumberFormat = numfmt->cNegativeNumberFormat; -#ifndef FEATURE_BCL_FORMATTING - if (numfmt->bIsInvariant || 0 == number->palNumber) - { - // So that FormatNumber uses BCL format - number->palNumber = 0; -#endif - - newBufferLen += digCount; - newBufferLen += sNegative->GetStringLength(); // For number and exponent - if (!ClrSafeInt<UINT64>::addition((UINT64)sNumberGroup->GetStringLength() * digCount, newBufferLen, newBufferLen)) - COMPlusThrowOM(); - newBufferLen += sNumberDecimal->GetStringLength(); - - _ASSERTE(newBufferLen >= MIN_BUFFER_SIZE); - if (newBufferLen > INT32_MAX) { - COMPlusThrowOM(); - } - newBufferLen = newBufferLen * sizeof(WCHAR); - dst = buffer = (WCHAR*)buf.AllocThrows(static_cast<SIZE_T>(newBufferLen)); - - RoundNumber(number, number->scale + nMaxDigits); - dst = FormatNumber(dst, static_cast<SIZE_T>(newBufferLen/sizeof(WCHAR)),number, nMinDigits, nMaxDigits, cNegativeNumberFormat, cNumberGroup, sNumberDecimal, sNumberGroup, sNegative, sZero); -#ifndef FEATURE_BCL_FORMATTING - } - else - { - for( SIZE_T nChars=128;;nChars*=2) - { - dst = buffer = (WCHAR*)buf.AllocThrows(nChars * sizeof(WCHAR)); - dst = FormatNumber(dst, nChars, number, nMinDigits,nMaxDigits, cNegativeNumberFormat, cNumberGroup, sNumberDecimal, sNumberGroup, sNegative,sZero); - - if (dst) - break; - if (GetLastError()!=ERROR_INSUFFICIENT_BUFFER) - ThrowLastError(); - } + newBufferLen += digCount; + newBufferLen += sNegative->GetStringLength(); // For number and exponent + if (!ClrSafeInt<UINT64>::addition((UINT64)sNumberGroup->GetStringLength() * digCount, newBufferLen, newBufferLen)) + COMPlusThrowOM(); + newBufferLen += sNumberDecimal->GetStringLength(); + + _ASSERTE(newBufferLen >= MIN_BUFFER_SIZE); + if (newBufferLen > INT32_MAX) { + COMPlusThrowOM(); } -#endif + newBufferLen = newBufferLen * sizeof(WCHAR); + dst = buffer = (WCHAR*)buf.AllocThrows(static_cast<SIZE_T>(newBufferLen)); + + RoundNumber(number, number->scale + nMaxDigits); + dst = FormatNumber(dst, static_cast<SIZE_T>(newBufferLen/sizeof(WCHAR)),number, nMinDigits, nMaxDigits, cNegativeNumberFormat, cNumberGroup, sNumberDecimal, sNumberGroup, sNegative, sZero); break; } @@ -1792,45 +1486,22 @@ STRINGREF NumberToString(NUMBER* number, wchar format, int nMaxDigits, NUMFMTREF nMinDigits=nMaxDigits; nMaxDigits++; -#ifndef FEATURE_BCL_FORMATTING - if (numfmt->bIsInvariant || 0 == number->palNumber) - { - // So that FormatScientific uses BCL format - number->palNumber = 0; -#endif - - newBufferLen += nMaxDigits; - newBufferLen += (((INT64)sNegative->GetStringLength() + sPositive->GetStringLength()) *2); // For number and exponent - newBufferLen += sNumberDecimal->GetStringLength(); - - _ASSERTE(newBufferLen >= MIN_BUFFER_SIZE); - if (newBufferLen > INT32_MAX) { - COMPlusThrowOM(); - } - newBufferLen = newBufferLen * sizeof(WCHAR); - dst = buffer = (WCHAR*)buf.AllocThrows(static_cast<SIZE_T>(newBufferLen)); + newBufferLen += nMaxDigits; + newBufferLen += (((INT64)sNegative->GetStringLength() + sPositive->GetStringLength()) *2); // For number and exponent + newBufferLen += sNumberDecimal->GetStringLength(); - RoundNumber(number, nMaxDigits); - if (number->sign) { - AddStringRef(&dst, sNegative); - } - dst = FormatScientific(dst, static_cast<SIZE_T>(newBufferLen * sizeof(WCHAR)-(dst-buffer)),number, nMinDigits,nMaxDigits, format, sNumberDecimal, sPositive, sNegative,sZero); -#ifndef FEATURE_BCL_FORMATTING + _ASSERTE(newBufferLen >= MIN_BUFFER_SIZE); + if (newBufferLen > INT32_MAX) { + COMPlusThrowOM(); } - else - { - for( SIZE_T nChars=128;;nChars*=2) - { - dst = buffer = (WCHAR*)buf.AllocThrows(nChars * sizeof(WCHAR)); - dst = FormatScientific(dst, nChars, number, nMinDigits, nMaxDigits, format, sNumberDecimal, sPositive, sNegative,sZero); + newBufferLen = newBufferLen * sizeof(WCHAR); + dst = buffer = (WCHAR*)buf.AllocThrows(static_cast<SIZE_T>(newBufferLen)); - if (dst) - break; - if (GetLastError()!=ERROR_INSUFFICIENT_BUFFER) - ThrowLastError(); - } + RoundNumber(number, nMaxDigits); + if (number->sign) { + AddStringRef(&dst, sNegative); } -#endif + dst = FormatScientific(dst, static_cast<SIZE_T>(newBufferLen * sizeof(WCHAR)-(dst-buffer)),number, nMinDigits,nMaxDigits, format, sNumberDecimal, sPositive, sNegative,sZero); break; } @@ -1878,30 +1549,7 @@ STRINGREF NumberToString(NUMBER* number, wchar format, int nMaxDigits, NUMFMTREF } -#ifndef FEATURE_BCL_FORMATTING - if (numfmt->bIsInvariant || 0 == number->palNumber) - { - // So that FormatScientific uses BCL format - number->palNumber = 0; -#endif - - dst = FormatGeneral(dst, static_cast<SIZE_T>(newBufferLen/sizeof(WCHAR)), number, nMinDigits,nMaxDigits, format - ('G' - 'E'), sNumberDecimal, sPositive, sNegative, sZero, !enableRounding); -#ifndef FEATURE_BCL_FORMATTING - } - else - { - for( SIZE_T nChars=128;;nChars*=2) - { - dst = buffer = (WCHAR*)buf.AllocThrows(nChars * sizeof(WCHAR)); - dst = FormatGeneral(dst, nChars, number, nMinDigits,nMaxDigits, format - ('G' - 'E'), sNumberDecimal, sPositive, sNegative, sZero, !enableRounding); - - if (dst) - break; - if (GetLastError()!=ERROR_INSUFFICIENT_BUFFER) - ThrowLastError(); - } - } -#endif + dst = FormatGeneral(dst, static_cast<SIZE_T>(newBufferLen/sizeof(WCHAR)), number, nMinDigits,nMaxDigits, format - ('G' - 'E'), sNumberDecimal, sPositive, sNegative, sZero, !enableRounding); } break; @@ -1930,10 +1578,6 @@ STRINGREF NumberToString(NUMBER* number, wchar format, int nMaxDigits, NUMFMTREF STRINGREF sNegative = numfmt->sNegative; STRINGREF sPercent = numfmt->sPercent; -#ifndef FEATURE_BCL_FORMATTING - // So that FormatPercent uses BCL format - number->palNumber = 0; -#endif newBufferLen += digCount; newBufferLen += sNegative->GetStringLength(); // For number and exponent if (!ClrSafeInt<UINT64>::addition((UINT64)sPercentGroup->GetStringLength() * digCount, newBufferLen, newBufferLen)) @@ -1957,7 +1601,6 @@ STRINGREF NumberToString(NUMBER* number, wchar format, int nMaxDigits, NUMFMTREF COMPlusThrow(kFormatException, W("Argument_BadFormatSpecifier")); } // check for overflow of the preallocated buffer -#ifdef FEATURE_BCL_FORMATTING // when not defined the buffer could be resized, so skip the check // Review signed/unsigned mismatch in '<=' comparison. #pragma warning(push) #pragma warning(disable:4018) @@ -1965,7 +1608,6 @@ STRINGREF NumberToString(NUMBER* number, wchar format, int nMaxDigits, NUMFMTREF #pragma warning(pop) DoJITFailFast(); } -#endif return StringObject::NewString(buffer, (int) (dst - buffer)); } @@ -2047,12 +1689,6 @@ STRINGREF NumberToStringFormat(NUMBER* number, STRINGREF str, NUMFMTREF numfmt) section = FindSection(format, (GetDigitsBuffer(number))[0] == 0 ? 2 : number->sign ? 1 : 0); -#ifndef FEATURE_BCL_FORMATTING - // custom formatting is all done in the VM without the PAL. Blanking - // the palNumber field avoids unnecessary RoundNumber calculations - number->palNumber = 0; -#endif - ParseSection: digitCount = 0; decimalPos = -1; @@ -2607,11 +2243,6 @@ FCIMPL3_VII(Object*, COMNumber::FormatSingle, float value, StringObject* formatU //and display that. DoubleToNumber(argsValue, FLOAT_PRECISION, &number); -#ifndef FEATURE_BCL_FORMATTING - // Make sure that BCL formatting is used for Single to avoid lossy conversion to Double - number.palNumber = 0; -#endif - if (number.scale == (int) SCALE_NAN) { gc.refRetVal = gc.numfmt->sNaN; goto lExit; @@ -2654,10 +2285,6 @@ FCIMPL3_VII(Object*, COMNumber::FormatSingle, float value, StringObject* formatU } DoubleToNumber(value, precision, &number); -#ifndef FEATURE_BCL_FORMATTING - // Make sure that BCL formatting is used for Single to avoid lossy conversion to Double - number.palNumber = 0; -#endif if (number.scale == (int) SCALE_NAN) { gc.refRetVal = gc.numfmt->sNaN; diff --git a/src/classlibnative/bcltype/number.h b/src/classlibnative/bcltype/number.h index 3b72781a18..87bab3b9f6 100644 --- a/src/classlibnative/bcltype/number.h +++ b/src/classlibnative/bcltype/number.h @@ -14,26 +14,12 @@ #define NUMBER_MAXDIGITS 50 -#ifndef FEATURE_BCL_FORMATTING -enum PAL_NUMBERType { - PALNUMBERTYPE_INT = 1, // PAL_IntToNumber - PALNUMBERTYPE_INT64 = 2, // PAL_Int64ToNumber - PALNUMBERTYPE_UINT = 3, // PAL_UIntToNumber - PALNUMBERTYPE_UINT64 = 4, // PAL_UInt64ToNumber - PALNUMBERTYPE_DOUBLE = 5, // PAL_DoubleToNumber -}; -#endif - struct NUMBER { int precision; int scale; int sign; wchar_t digits[NUMBER_MAXDIGITS + 1]; wchar_t* allDigits; -#ifndef FEATURE_BCL_FORMATTING - PAL_NUMBERHolder palNumber; - PAL_NUMBERType palNumberType; -#endif NUMBER() : precision(0), scale(0), sign(0), allDigits(NULL) {} }; |