diff options
author | Stephen Toub <stoub@microsoft.com> | 2017-09-18 14:22:19 -0400 |
---|---|---|
committer | Stephen Toub <stoub@microsoft.com> | 2017-09-18 19:52:26 -0400 |
commit | f9116ac9567bfc15d8fc07413b50f40df3193d7c (patch) | |
tree | 55c6d28d6fb7a1980a0c4eecefdbd57f89169a24 /src/vm | |
parent | 8390c4213e60a5cc2507e133f158cbf530b70b1d (diff) | |
download | coreclr-f9116ac9567bfc15d8fc07413b50f40df3193d7c.tar.gz coreclr-f9116ac9567bfc15d8fc07413b50f40df3193d7c.tar.bz2 coreclr-f9116ac9567bfc15d8fc07413b50f40df3193d7c.zip |
Remove now dead ParseNumbers code in runtime
Diffstat (limited to 'src/vm')
-rw-r--r-- | src/vm/comutilnative.cpp | 645 | ||||
-rw-r--r-- | src/vm/comutilnative.h | 36 | ||||
-rw-r--r-- | src/vm/ecalllist.h | 8 |
3 files changed, 0 insertions, 689 deletions
diff --git a/src/vm/comutilnative.cpp b/src/vm/comutilnative.cpp index 766336ee7f..5c5a1e9eaa 100644 --- a/src/vm/comutilnative.cpp +++ b/src/vm/comutilnative.cpp @@ -44,20 +44,6 @@ #define STACK_OVERFLOW_MESSAGE W("StackOverflowException") -//These are defined in System.ParseNumbers and should be kept in sync. -#define PARSE_TREATASUNSIGNED 0x200 -#define PARSE_TREATASI1 0x400 -#define PARSE_TREATASI2 0x800 -#define PARSE_ISTIGHT 0x1000 -#define PARSE_NOSPACE 0x2000 - - -// -// -// PARSENUMBERS (and helper functions) -// -// - /*===================================IsDigit==================================== **Returns a bool indicating whether the character passed in represents a ** **digit. @@ -119,638 +105,7 @@ INT32 wtoi(__in_ecount(length) WCHAR* wstr, DWORD length) return result; } -INT32 ParseNumbers::GrabInts(const INT32 radix, __in_ecount(length) WCHAR *buffer, const int length, int *i, BOOL isUnsigned) -{ - CONTRACTL - { - THROWS; - GC_NOTRIGGER; - MODE_COOPERATIVE; - PRECONDITION(CheckPointer(buffer)); - PRECONDITION(CheckPointer(i)); - PRECONDITION(*i >= 0); - PRECONDITION(length >= 0); - PRECONDITION( radix==2 || radix==8 || radix==10 || radix==16 ); - } - CONTRACTL_END; - - UINT32 result=0; - int value; - UINT32 maxVal; - - // Allow all non-decimal numbers to set the sign bit. - if (radix==10 && !isUnsigned) { - maxVal = (0x7FFFFFFF / 10); - - //Read all of the digits and convert to a number - while (*i<length&&(IsDigit(buffer[*i],radix,&value))) { - // Check for overflows - this is sufficient & correct. - if (result > maxVal || ((INT32)result)<0) - COMPlusThrow(kOverflowException, W("Overflow_Int32")); - result = result*radix + value; - (*i)++; - } - if ((INT32)result<0 && result!=0x80000000) - COMPlusThrow(kOverflowException, W("Overflow_Int32")); - - } - else { - maxVal = ((UINT32) -1) / radix; - - //Read all of the digits and convert to a number - while (*i<length&&(IsDigit(buffer[*i],radix,&value))) { - // Check for overflows - this is sufficient & correct. - if (result > maxVal) - COMPlusThrow(kOverflowException, W("Overflow_UInt32")); - // the above check won't cover 4294967296 to 4294967299 - UINT32 temp = result*radix + value; - if( temp < result) { // this means overflow as well - COMPlusThrow(kOverflowException, W("Overflow_UInt32")); - } - - result = temp; - (*i)++; - } - } - return(INT32) result; -} - -INT64 ParseNumbers::GrabLongs(const INT32 radix, __in_ecount(length) WCHAR *buffer, const int length, int *i, BOOL isUnsigned) -{ - CONTRACTL - { - THROWS; - GC_NOTRIGGER; - MODE_COOPERATIVE; - PRECONDITION(CheckPointer(buffer)); - PRECONDITION(CheckPointer(i)); - PRECONDITION(*i >= 0); - PRECONDITION(length >= 0); - } - CONTRACTL_END; - - UINT64 result=0; - int value; - UINT64 maxVal; - - // Allow all non-decimal numbers to set the sign bit. - if (radix==10 && !isUnsigned) { - maxVal = (UI64(0x7FFFFFFFFFFFFFFF) / 10); - - //Read all of the digits and convert to a number - while (*i<length&&(IsDigit(buffer[*i],radix,&value))) { - // Check for overflows - this is sufficient & correct. - if (result > maxVal || ((INT64)result)<0) - COMPlusThrow(kOverflowException, W("Overflow_Int64")); - result = result*radix + value; - (*i)++; - } - if ((INT64)result<0 && result!=UI64(0x8000000000000000)) - COMPlusThrow(kOverflowException, W("Overflow_Int64")); - - } - else { - maxVal = ((UINT64) -1L) / radix; - - //Read all of the digits and convert to a number - while (*i<length&&(IsDigit(buffer[*i],radix,&value))) { - // Check for overflows - this is sufficient & correct. - if (result > maxVal) - COMPlusThrow(kOverflowException, W("Overflow_UInt64")); - - UINT64 temp = result*radix + value; - if( temp < result) { // this means overflow as well - COMPlusThrow(kOverflowException, W("Overflow_UInt64")); - } - result = temp; - - (*i)++; - } - } - return(INT64) result; -} - -void EatWhiteSpace(__in_ecount(length) WCHAR *buffer, int length, int *i) -{ - CONTRACTL - { - NOTHROW; - GC_NOTRIGGER; - MODE_ANY; - PRECONDITION(CheckPointer(buffer)); - PRECONDITION(CheckPointer(i)); - PRECONDITION(length >= 0); - } - CONTRACTL_END; - - for (; *i<length && COMCharacter::nativeIsWhiteSpace(buffer[*i]); (*i)++); -} - -FCIMPL5_VII(LPVOID, ParseNumbers::LongToString, INT64 n, INT32 radix, INT32 width, CLR_CHAR paddingChar, INT32 flags) -{ - FCALL_CONTRACT; - - LPVOID rv = NULL; - - HELPER_METHOD_FRAME_BEGIN_RET_0(); - - bool isNegative = false; - int index=0; - int charVal; - UINT64 l; - INT32 i; - INT32 buffLength=0; - WCHAR buffer[67];//Longest possible string length for an integer in binary notation with prefix - - if (radix<MinRadix || radix>MaxRadix) - COMPlusThrowArgumentException(W("radix"), W("Arg_InvalidBase")); - - //If the number is negative, make it positive and remember the sign. - if (n<0) { - isNegative=true; - - // For base 10, write out -num, but other bases write out the - // 2's complement bit pattern - if (10==radix) - l = (UINT64)(-n); - else - l = (UINT64)n; - } - else { - l=(UINT64)n; - } - - if (flags&PrintAsI1) - l = l&0xFF; - else if (flags&PrintAsI2) - l = l&0xFFFF; - else if (flags&PrintAsI4) - l=l&0xFFFFFFFF; - - //Special case the 0. - if (0==l) { - buffer[0]='0'; - index=1; - } - else { - //Pull apart the number and put the digits (in reverse order) into the buffer. - for (index=0; l>0; l=l/radix, index++) { - if ((charVal=(int)(l%radix))<10) - buffer[index] = (WCHAR)(charVal + '0'); - else - buffer[index] = (WCHAR)(charVal + 'a' - 10); - } - } - - //If they want the base, append that to the string (in reverse order) - if (radix!=10 && ((flags&PrintBase)!=0)) { - if (16==radix) { - buffer[index++]='x'; - buffer[index++]='0'; - } - else if (8==radix) { - buffer[index++]='0'; - } - else if ((flags&PrintRadixBase)!=0) { - buffer[index++]='#'; - buffer[index++]=((radix%10)+'0'); - buffer[index++]=((static_cast<char>(radix)/10)+'0'); - } - } - - if (10==radix) { - //If it was negative, append the sign. - if (isNegative) { - buffer[index++]='-'; - } - - //else if they requested, add the '+'; - else if ((flags&PrintSign)!=0) { - buffer[index++]='+'; - } - - //If they requested a leading space, put it on. - else if ((flags&PrefixSpace)!=0) { - buffer[index++]=' '; - } - } - - //Figure out the size of our string. - if (width<=index) - buffLength=index; - else - buffLength=width; - - STRINGREF Local = StringObject::NewString(buffLength); - WCHAR *LocalBuffer = Local->GetBuffer(); - - //Put the characters into the String in reverse order - //Fill the remaining space -- if there is any -- - //with the correct padding character. - if ((flags&LeftAlign)!=0) { - for (i=0; i<index; i++) { - LocalBuffer[i]=buffer[index-i-1]; - } - for (;i<buffLength; i++) { - LocalBuffer[i]=paddingChar; - } - } - else { - for (i=0; i<index; i++) { - LocalBuffer[buffLength-i-1]=buffer[i]; - } - for (int j=buffLength-i-1; j>=0; j--) { - LocalBuffer[j]=paddingChar; - } - } - - *((STRINGREF *)&rv)=Local; - - HELPER_METHOD_FRAME_END(); - - return rv; -} -FCIMPLEND - - -FCIMPL5(LPVOID, ParseNumbers::IntToString, INT32 n, INT32 radix, INT32 width, CLR_CHAR paddingChar, INT32 flags) -{ - FCALL_CONTRACT; - - LPVOID rv = NULL; - - HELPER_METHOD_FRAME_BEGIN_RET_0(); - - bool isNegative = false; - int index=0; - int charVal; - int buffLength; - int i; - UINT32 l; - WCHAR buffer[66]; //Longest possible string length for an integer in binary notation with prefix - - if (radix<MinRadix || radix>MaxRadix) - COMPlusThrowArgumentException(W("radix"), W("Arg_InvalidBase")); - - //If the number is negative, make it positive and remember the sign. - //If the number is MIN_VALUE, this will still be negative, so we'll have to - //special case this later. - if (n<0) { - isNegative=true; - // For base 10, write out -num, but other bases write out the - // 2's complement bit pattern - if (10==radix) - l = (UINT32)(-n); - else - l = (UINT32)n; - } - else { - l=(UINT32)n; - } - - //The conversion to a UINT will sign extend the number. In order to ensure - //that we only get as many bits as we expect, we chop the number. - if (flags&PrintAsI1) { - l = l&0xFF; - } - else if (flags&PrintAsI2) { - l = l&0xFFFF; - } - else if (flags&PrintAsI4) { - l=l&0xFFFFFFFF; - } - - //Special case the 0. - if (0==l) { - buffer[0]='0'; - index=1; - } - else { - do { - charVal = l%radix; - l=l/radix; - if (charVal<10) { - buffer[index++] = (WCHAR)(charVal + '0'); - } - else { - buffer[index++] = (WCHAR)(charVal + 'a' - 10); - } - } - while (l!=0); - } - - //If they want the base, append that to the string (in reverse order) - if (radix!=10 && ((flags&PrintBase)!=0)) { - if (16==radix) { - buffer[index++]='x'; - buffer[index++]='0'; - } - else if (8==radix) { - buffer[index++]='0'; - } - } - - if (10==radix) { - //If it was negative, append the sign. - if (isNegative) { - buffer[index++]='-'; - } - - //else if they requested, add the '+'; - else if ((flags&PrintSign)!=0) { - buffer[index++]='+'; - } - - //If they requested a leading space, put it on. - else if ((flags&PrefixSpace)!=0) { - buffer[index++]=' '; - } - } - - //Figure out the size of our string. - if (width<=index) { - buffLength=index; - } - else { - buffLength=width; - } - - STRINGREF Local = StringObject::NewString(buffLength); - WCHAR *LocalBuffer = Local->GetBuffer(); - - //Put the characters into the String in reverse order - //Fill the remaining space -- if there is any -- - //with the correct padding character. - if ((flags&LeftAlign)!=0) { - for (i=0; i<index; i++) { - LocalBuffer[i]=buffer[index-i-1]; - } - for (;i<buffLength; i++) { - LocalBuffer[i]=paddingChar; - } - } - else { - for (i=0; i<index; i++) { - LocalBuffer[buffLength-i-1]=buffer[i]; - } - for (int j=buffLength-i-1; j>=0; j--) { - LocalBuffer[j]=paddingChar; - } - } - - *((STRINGREF *)&rv)=Local; - - HELPER_METHOD_FRAME_END(); - - return rv; -} -FCIMPLEND - - -/*===================================FixRadix=================================== -**It's possible that we parsed the radix in a base other than 10 by accident. -**This method will take that number, verify that it only contained valid base 10 -**digits, and then do the conversion to base 10. If it contained invalid digits, -**they tried to pass us a radix such as 1A, so we throw a FormatException. -** -**Args: oldVal: The value that we had actually parsed in some arbitrary base. -** oldBase: The base in which we actually did the parsing. -** -**Returns: oldVal as if it had been parsed as a base-10 number. -**Exceptions: FormatException if either of the digits in the radix aren't -** valid base-10 numbers. -==============================================================================*/ -int FixRadix(int oldVal, int oldBase) -{ - CONTRACTL - { - THROWS; - GC_NOTRIGGER; - MODE_COOPERATIVE; - } - CONTRACTL_END; - - int firstDigit = (oldVal/oldBase); - int secondDigit = (oldVal%oldBase); - - if ((firstDigit>=10) || (secondDigit>=10)) - COMPlusThrow(kFormatException, W("Format_BadBase")); - - return(firstDigit*10)+secondDigit; -} - -/*=================================StringToLong================================= -**Action: -**Returns: -**Exceptions: -==============================================================================*/ -FCIMPL4(INT64, ParseNumbers::StringToLong, StringObject * s, INT32 radix, INT32 flags, INT32 *currPos) -{ - FCALL_CONTRACT; - - INT64 result = 0; - - HELPER_METHOD_FRAME_BEGIN_RET_1(s); - - int sign = 1; - WCHAR *input; - int length; - int i; - int grabNumbersStart=0; - INT32 r; - - _ASSERTE((flags & PARSE_TREATASI1) == 0 && (flags & PARSE_TREATASI2) == 0); - - if (s) { - i = currPos ? *currPos : 0; - - //Do some radix checking. - //A radix of -1 says to use whatever base is spec'd on the number. - //Parse in Base10 until we figure out what the base actually is. - r = (-1==radix)?10:radix; - - if (r!=2 && r!=10 && r!=8 && r!=16) - COMPlusThrow(kArgumentException, W("Arg_InvalidBase")); - - s->RefInterpretGetStringValuesDangerousForGC(&input, &length); - - if (i<0 || i>=length) - COMPlusThrowArgumentOutOfRange(W("startIndex"), W("ArgumentOutOfRange_Index")); - - //Get rid of the whitespace and then check that we've still got some digits to parse. - if (!(flags & PARSE_ISTIGHT) && !(flags & PARSE_NOSPACE)) { - EatWhiteSpace(input,length,&i); - if (i==length) - COMPlusThrow(kFormatException, W("Format_EmptyInputString")); - } - - //Check for a sign - if (input[i]=='-') { - if (r != 10) - COMPlusThrow(kArgumentException, W("Arg_CannotHaveNegativeValue")); - - if (flags & PARSE_TREATASUNSIGNED) - COMPlusThrow(kOverflowException, W("Overflow_NegativeUnsigned")); - - sign = -1; - i++; - } - else if (input[i]=='+') { - i++; - } - - if ((radix==-1 || radix==16) && (i+1<length) && input[i]=='0') { - if (input[i+1]=='x' || input [i+1]=='X') { - r=16; - i+=2; - } - } - - grabNumbersStart=i; - result = GrabLongs(r,input,length,&i, (flags & PARSE_TREATASUNSIGNED)); - - //Check if they passed us a string with no parsable digits. - if (i==grabNumbersStart) - COMPlusThrow(kFormatException, W("Format_NoParsibleDigits")); - - if (flags & PARSE_ISTIGHT) { - //If we've got effluvia left at the end of the string, complain. - if (i<length) - COMPlusThrow(kFormatException, W("Format_ExtraJunkAtEnd")); - } - - //Put the current index back into the correct place. - if (currPos != NULL) *currPos = i; - - //Return the value properly signed. - if ((UINT64) result==UI64(0x8000000000000000) && sign==1 && r==10 && !(flags & PARSE_TREATASUNSIGNED)) - COMPlusThrow(kOverflowException, W("Overflow_Int64")); - - if (r == 10) - result *= sign; - } - else { - result = 0; - } - - HELPER_METHOD_FRAME_END(); - - return result; -} -FCIMPLEND - -FCIMPL4(INT32, ParseNumbers::StringToInt, StringObject * s, INT32 radix, INT32 flags, INT32* currPos) -{ - FCALL_CONTRACT; - - INT32 result = 0; - - HELPER_METHOD_FRAME_BEGIN_RET_1(s); - - int sign = 1; - WCHAR *input; - int length; - int i; - int grabNumbersStart=0; - INT32 r; - - // TreatAsI1 and TreatAsI2 are mutually exclusive. - _ASSERTE(!((flags & PARSE_TREATASI1) != 0 && (flags & PARSE_TREATASI2) != 0)); - - if (s) { - //They're requied to tell me where to start parsing. - i = currPos ? (*currPos) : 0; - - //Do some radix checking. - //A radix of -1 says to use whatever base is spec'd on the number. - //Parse in Base10 until we figure out what the base actually is. - r = (-1==radix)?10:radix; - if (r!=2 && r!=10 && r!=8 && r!=16) - COMPlusThrow(kArgumentException, W("Arg_InvalidBase")); - - s->RefInterpretGetStringValuesDangerousForGC(&input, &length); - - if (i<0 || i>=length) - COMPlusThrowArgumentOutOfRange(W("startIndex"), W("ArgumentOutOfRange_Index")); - - //Get rid of the whitespace and then check that we've still got some digits to parse. - if (!(flags & PARSE_ISTIGHT) && !(flags & PARSE_NOSPACE)) { - EatWhiteSpace(input,length,&i); - if (i==length) - COMPlusThrow(kFormatException, W("Format_EmptyInputString")); - } - - //Check for a sign - if (input[i]=='-') { - if (r != 10) - COMPlusThrow(kArgumentException, W("Arg_CannotHaveNegativeValue")); - - if (flags & PARSE_TREATASUNSIGNED) - COMPlusThrow(kOverflowException, W("Overflow_NegativeUnsigned")); - - sign = -1; - i++; - } - else if (input[i]=='+') { - i++; - } - - //Consume the 0x if we're in an unknown base or in base-16. - if ((radix==-1||radix==16) && (i+1<length) && input[i]=='0') { - if (input[i+1]=='x' || input [i+1]=='X') { - r=16; - i+=2; - } - } - - grabNumbersStart=i; - result = GrabInts(r,input,length,&i, (flags & PARSE_TREATASUNSIGNED)); - - //Check if they passed us a string with no parsable digits. - if (i==grabNumbersStart) - COMPlusThrow(kFormatException, W("Format_NoParsibleDigits")); - - if (flags & PARSE_ISTIGHT) { - //If we've got effluvia left at the end of the string, complain. - if (i<(length)) - COMPlusThrow(kFormatException, W("Format_ExtraJunkAtEnd")); - } - - //Put the current index back into the correct place. - if (currPos != NULL) *currPos = i; - - //Return the value properly signed. - if (flags & PARSE_TREATASI1) { - if ((UINT32)result > 0xFF) - COMPlusThrow(kOverflowException, W("Overflow_SByte")); - - // result looks positive when parsed as an I4 - _ASSERTE(sign==1 || r==10); - } - else if (flags & PARSE_TREATASI2) { - if ((UINT32)result > 0xFFFF) - COMPlusThrow(kOverflowException, W("Overflow_Int16")); - - // result looks positive when parsed as an I4 - _ASSERTE(sign==1 || r==10); - } - else if ((UINT32) result==0x80000000U && sign==1 && r==10 && !(flags & PARSE_TREATASUNSIGNED)) { - COMPlusThrow(kOverflowException, W("Overflow_Int32")); - } - - if (r == 10) - result *= sign; - } - else { - result = 0; - } - - HELPER_METHOD_FRAME_END(); - - return result; -} -FCIMPLEND // // diff --git a/src/vm/comutilnative.h b/src/vm/comutilnative.h index 831e1c071e..07c57c1312 100644 --- a/src/vm/comutilnative.h +++ b/src/vm/comutilnative.h @@ -37,42 +37,6 @@ // // -// PARSE NUMBERS -// -// - -#define MinRadix 2 -#define MaxRadix 36 - -class ParseNumbers { - - enum FmtFlags { - LeftAlign = 0x1, //Ensure that these conform to the values specified in the managed files. - CenterAlign = 0x2, - RightAlign = 0x4, - PrefixSpace = 0x8, - PrintSign = 0x10, - PrintBase = 0x20, - TreatAsUnsigned = 0x10, - PrintAsI1 = 0x40, - PrintAsI2 = 0x80, - PrintAsI4 = 0x100, - PrintRadixBase = 0x200, - AlternateForm = 0x400}; - -public: - - static INT32 GrabInts(const INT32 radix, __in_ecount(length) WCHAR *buffer, const int length, int *i, BOOL isUnsigned); - static INT64 GrabLongs(const INT32 radix, __in_ecount(length) WCHAR *buffer, const int length, int *i, BOOL isUnsigned); - - static FCDECL5(LPVOID, IntToString, INT32 l, INT32 radix, INT32 width, CLR_CHAR paddingChar, INT32 flags); - static FCDECL5_VII(LPVOID, LongToString, INT64 l, INT32 radix, INT32 width, CLR_CHAR paddingChar, INT32 flags); - static FCDECL4(INT32, StringToInt, StringObject * s, INT32 radix, INT32 flags, INT32* currPos); - static FCDECL4(INT64, StringToLong, StringObject * s, INT32 radix, INT32 flags, INT32* currPos); -}; - -// -// // EXCEPTION NATIVE // // diff --git a/src/vm/ecalllist.h b/src/vm/ecalllist.h index 76be0b172c..6997d0f65c 100644 --- a/src/vm/ecalllist.h +++ b/src/vm/ecalllist.h @@ -89,13 +89,6 @@ FCFuncStart(gSymWrapperCodePunkSafeHandleFuncs) FCFuncElement("nGetDReleaseTarget", COMPunkSafeHandle::nGetDReleaseTarget) FCFuncEnd() -FCFuncStart(gParseNumbersFuncs) - FCFuncElement("IntToString", ParseNumbers::IntToString) - FCFuncElement("LongToString", ParseNumbers::LongToString) - FCFuncElement("StringToInt", ParseNumbers::StringToInt) - FCFuncElement("StringToLong", ParseNumbers::StringToLong) -FCFuncEnd() - FCFuncStart(gObjectFuncs) FCIntrinsic("GetType", ObjectNative::GetClass, CORINFO_INTRINSIC_Object_GetType) @@ -1400,7 +1393,6 @@ FCClassElement("Object", "System", gObjectFuncs) FCClassElement("ObjectMarshaler", "System.StubHelpers", gObjectMarshalerFuncs) #endif FCClassElement("OverlappedData", "System.Threading", gOverlappedFuncs) -FCClassElement("ParseNumbers", "System", gParseNumbersFuncs) FCClassElement("PunkSafeHandle", "System.Reflection.Emit", gSymWrapperCodePunkSafeHandleFuncs) |