From da06e60fb5a095a91c9a4f509466667878624cb3 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Tue, 3 Nov 2015 15:08:31 -0500 Subject: Revert "Revert "Revert "Cleanup some numeric code.""" This reverts commit e0e922db5fb77df9a5a9cc802096f484ed21da1c. Broke Windows build. FAILED: ninja -t msvc -e environment.x86 -- "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\amd64_x86\cl.exe" /nologo /showIncludes /FC @obj\core\src\fxcrt\fxcrt.fx_basic_gcc.obj.rsp /c ..\..\core\src\fxcrt\fx_basic_gcc.cpp /Foobj\core\src\fxcrt\fxcrt.fx_basic_gcc.obj /Fdobj\fxcrt.cc.pdb e:\b\build\slave\windows\build\pdfium\core\src\fxcrt\fx_basic_gcc.cpp(28) : error C2220: warning treated as error - no 'object' file generated e:\b\build\slave\windows\build\pdfium\core\src\fxcrt\fx_basic_gcc.cpp(75) : see reference to function template instantiation 'T FXSYS_StrToInt(STR_T)' being compiled with [ T=int32_t , STR_T=const FX_WCHAR * ] e:\b\build\slave\windows\build\pdfium\core\src\fxcrt\fx_basic_gcc.cpp(28) : warning C4244: 'argument' : conversion from 'const FX_WCHAR' to 'char', possible loss of data FAILED: ninja -t msvc -e environment.x86 -- "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\amd64_x86\cl.exe" /nologo /showIncludes /FC @obj\core\src\fpdftext\fpdftext.fpdf_text.obj.rsp /c ..\..\core\src\fpdftext\fpdf_text.cpp /Foobj\core\src\fpdftext\fpdftext.fpdf_text.obj /Fdobj\fpdftext.cc.pdb e:\b\build\slave\windows\build\pdfium\core\src\fpdftext\fpdf_text.cpp(439) : error C2039: 'isdigit' : is not a member of 'std' FAILED: ninja -t msvc -e environment.x86 -- "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\amd64_x86\cl.exe" /nologo /showIncludes /FC @obj\core\src\fxcrt\fxcrt.fx_basic_wstring.obj.rsp /c ..\..\core\src\fxcrt\fx_basic_wstring.cpp /Foobj\core\src\fxcrt\fxcrt.fx_basic_wstring.obj /Fdobj\fxcrt.cc.pdb e:\b\build\slave\windows\build\pdfium\core\src\fxcrt\fx_basic_wstring.cpp(973) : error C2220: warning treated as error - no 'object' file generated e:\b\build\slave\windows\build\pdfium\core\src\fxcrt\fx_basic_wstring.cpp(973) : warning C4244: 'argument' : conversion from 'const FX_WCHAR' to 'char', possible loss of data e:\b\build\slave\windows\build\pdfium\core\src\fxcrt\fx_basic_wstring.cpp(981) : warning C4244: 'argument' : conversion from 'const FX_WCHAR' to 'char', possible loss of data FAILED: ninja -t msvc -e environment.x86 -- "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\amd64_x86\cl.exe" /nologo /showIncludes /FC @obj\core\src\fpdftext\fpdftext.fpdf_text_int.obj.rsp /c ..\..\core\src\fpdftext\fpdf_text_int.cpp /Foobj\core\src\fpdftext\fpdftext.fpdf_text_int.obj /Fdobj\fpdftext.cc.pdb e:\b\build\slave\windows\build\pdfium\core\src\fpdftext\fpdf_text_int.cpp(2436) : error C2039: 'isdigit' : is not a member of 'std' e:\b\build\slave\windows\build\pdfium\core\src\fpdftext\fpdf_text_int.cpp(2440) : error C2039: 'isdigit' : is not a member of 'std' ninja: build stopped: subcommand failed. TBR=tsepez@chromium.org Review URL: https://codereview.chromium.org/1431683008 . --- core/src/fxcrt/fx_basic_bstring.cpp | 9 ++++----- core/src/fxcrt/fx_basic_gcc.cpp | 16 +++++++++------- core/src/fxcrt/fx_basic_util.cpp | 20 +++++++++----------- core/src/fxcrt/fx_basic_wstring.cpp | 14 ++++++-------- core/src/fxcrt/fx_extension.cpp | 16 ++++++++++++---- core/src/fxcrt/fx_extension_unittest.cpp | 19 ------------------- core/src/fxcrt/fx_xml_parser.cpp | 9 ++++----- 7 files changed, 44 insertions(+), 59 deletions(-) delete mode 100644 core/src/fxcrt/fx_extension_unittest.cpp (limited to 'core/src/fxcrt') diff --git a/core/src/fxcrt/fx_basic_bstring.cpp b/core/src/fxcrt/fx_basic_bstring.cpp index 1b9d7a0344..c706912d9d 100644 --- a/core/src/fxcrt/fx_basic_bstring.cpp +++ b/core/src/fxcrt/fx_basic_bstring.cpp @@ -5,7 +5,6 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com #include // For offsetof(). -#include #include "../../include/fxcrt/fx_basic.h" #include "../../../third_party/base/numerics/safe_math.h" @@ -494,8 +493,8 @@ void CFX_ByteString::FormatV(const FX_CHAR* lpszFormat, va_list argList) { } if (nWidth == 0) { nWidth = FXSYS_atoi(lpsz); - while (std::isdigit(*lpsz)) - lpsz++; + for (; (*lpsz) >= '0' && (*lpsz) <= '9'; lpsz++) + ; } if (nWidth < 0 || nWidth > 128 * 1024) { lpszFormat = "Bad width"; @@ -510,8 +509,8 @@ void CFX_ByteString::FormatV(const FX_CHAR* lpszFormat, va_list argList) { lpsz++; } else { nPrecision = FXSYS_atoi(lpsz); - while (std::isdigit(*lpsz)) - lpsz++; + for (; (*lpsz) >= '0' && (*lpsz) <= '9'; lpsz++) + ; } } if (nPrecision < 0 || nPrecision > 128 * 1024) { diff --git a/core/src/fxcrt/fx_basic_gcc.cpp b/core/src/fxcrt/fx_basic_gcc.cpp index 250079913c..6f17482156 100644 --- a/core/src/fxcrt/fx_basic_gcc.cpp +++ b/core/src/fxcrt/fx_basic_gcc.cpp @@ -5,7 +5,6 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com #include -#include #include "../../include/fxcrt/fx_ext.h" #include "../../include/fxcrt/fx_string.h" @@ -13,19 +12,22 @@ template T FXSYS_StrToInt(STR_T str) { FX_BOOL neg = FALSE; - if (!str) + if (str == NULL) { return 0; - + } if (*str == '-') { neg = TRUE; str++; } T num = 0; - while (*str && std::isdigit(*str)) { - if (num > (std::numeric_limits::max() - 9) / 10) + while (*str) { + if ((*str) < '0' || (*str) > '9') { break; - - num = num * 10 + FXSYS_toDecimalDigit(*str); + } + if (num > (std::numeric_limits::max() - 9) / 10) { + break; + } + num = num * 10 + (*str) - '0'; str++; } return neg ? -num : num; diff --git a/core/src/fxcrt/fx_basic_util.cpp b/core/src/fxcrt/fx_basic_util.cpp index 78bdeee693..46a0dec1e5 100644 --- a/core/src/fxcrt/fx_basic_util.cpp +++ b/core/src/fxcrt/fx_basic_util.cpp @@ -5,17 +5,12 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com #include "../../include/fxcrt/fx_basic.h" -#include "../../include/fxcrt/fx_ext.h" - #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ #include #include #else #include #endif - -#include - CFX_PrivateData::~CFX_PrivateData() { ClearAll(); } @@ -105,11 +100,14 @@ void FX_atonum(const CFX_ByteStringC& strc, FX_BOOL& bInteger, void* pData) { bNegative = TRUE; cc++; } - while (cc < len && std::isdigit(str[cc])) { - integer = integer * 10 + FXSYS_toDecimalDigit(str[cc]); - if (integer < 0) + while (cc < len) { + if (str[cc] < '0' || str[cc] > '9') { break; - + } + integer = integer * 10 + str[cc] - '0'; + if (integer < 0) { + break; + } cc++; } if (bNegative) { @@ -146,7 +144,7 @@ FX_FLOAT FX_atof(const CFX_ByteStringC& strc) { if (str[cc] == '.') { break; } - value = value * 10 + FXSYS_toDecimalDigit(str[cc]); + value = value * 10 + str[cc] - '0'; cc++; } static const FX_FLOAT fraction_scales[] = { @@ -157,7 +155,7 @@ FX_FLOAT FX_atof(const CFX_ByteStringC& strc) { if (cc < len && str[cc] == '.') { cc++; while (cc < len) { - value += fraction_scales[scale] * FXSYS_toDecimalDigit(str[cc]); + value += fraction_scales[scale] * (str[cc] - '0'); scale++; if (scale == sizeof fraction_scales / sizeof(FX_FLOAT)) { break; diff --git a/core/src/fxcrt/fx_basic_wstring.cpp b/core/src/fxcrt/fx_basic_wstring.cpp index cb94d81196..c097e1fc09 100644 --- a/core/src/fxcrt/fx_basic_wstring.cpp +++ b/core/src/fxcrt/fx_basic_wstring.cpp @@ -5,10 +5,8 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com #include // For offsetof(). -#include #include "../../include/fxcrt/fx_basic.h" -#include "../../include/fxcrt/fx_ext.h" #include "../../../third_party/base/numerics/safe_math.h" // static @@ -767,8 +765,8 @@ void CFX_WideString::FormatV(const FX_WCHAR* lpszFormat, va_list argList) { } if (nWidth == 0) { nWidth = FXSYS_wtoi(lpsz); - while (std::isdigit(*lpsz)) - ++lpsz; + for (; *lpsz != 0 && (*lpsz) <= '9' && (*lpsz) >= '0'; lpsz++) + ; } if (nWidth < 0 || nWidth > 128 * 1024) { lpszFormat = L"Bad width"; @@ -783,8 +781,8 @@ void CFX_WideString::FormatV(const FX_WCHAR* lpszFormat, va_list argList) { lpsz++; } else { nPrecision = FXSYS_wtoi(lpsz); - while (std::isdigit(*lpsz)) - ++lpsz; + for (; *lpsz != 0 && (*lpsz) >= '0' && (*lpsz) <= '9'; lpsz++) + ; } } if (nPrecision < 0 || nPrecision > 128 * 1024) { @@ -970,7 +968,7 @@ FX_FLOAT FX_wtof(const FX_WCHAR* str, int len) { if (str[cc] == '.') { break; } - integer = integer * 10 + FXSYS_toDecimalDigit(str[cc]); + integer = integer * 10 + str[cc] - '0'; cc++; } FX_FLOAT fraction = 0; @@ -978,7 +976,7 @@ FX_FLOAT FX_wtof(const FX_WCHAR* str, int len) { cc++; FX_FLOAT scale = 0.1f; while (cc < len) { - fraction += scale * FXSYS_toDecimalDigit(str[cc]); + fraction += scale * (str[cc] - '0'); scale *= 0.1f; cc++; } diff --git a/core/src/fxcrt/fx_extension.cpp b/core/src/fxcrt/fx_extension.cpp index 4951fbde9c..d64a06d08b 100644 --- a/core/src/fxcrt/fx_extension.cpp +++ b/core/src/fxcrt/fx_extension.cpp @@ -7,7 +7,6 @@ #include "../../include/fxcrt/fx_basic.h" #include "../../include/fxcrt/fx_ext.h" #include "extension.h" - #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ #include #else @@ -51,7 +50,9 @@ IFX_MemoryStream* FX_CreateMemoryStream(uint8_t* pBuffer, IFX_MemoryStream* FX_CreateMemoryStream(FX_BOOL bConsecutive) { return new CFX_MemoryStream(bConsecutive); } - +#ifdef __cplusplus +extern "C" { +#endif FX_FLOAT FXSYS_tan(FX_FLOAT a) { return (FX_FLOAT)tan(a); } @@ -188,7 +189,12 @@ FX_DWORD FX_HashCode_String_GetW(const FX_WCHAR* pStr, } return dwHashCode; } - +#ifdef __cplusplus +} +#endif +#ifdef __cplusplus +extern "C" { +#endif void* FX_Random_MT_Start(FX_DWORD dwSeed) { FX_LPMTRANDOMCONTEXT pContext = FX_Alloc(FX_MTRANDOMCONTEXT, 1); pContext->mt[0] = dwSeed; @@ -291,4 +297,6 @@ void FX_Random_GenerateCrypto(FX_DWORD* pBuffer, int32_t iCount) { FX_Random_GenerateBase(pBuffer, iCount); #endif } - +#ifdef __cplusplus +} +#endif diff --git a/core/src/fxcrt/fx_extension_unittest.cpp b/core/src/fxcrt/fx_extension_unittest.cpp deleted file mode 100644 index 2cadbbfede..0000000000 --- a/core/src/fxcrt/fx_extension_unittest.cpp +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2015 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "testing/gtest/include/gtest/gtest.h" - -#include "../../include/fxcrt/fx_ext.h" - -TEST(fxcrt, FXSYS_toHexDigit) { - EXPECT_EQ(10, FXSYS_toHexDigit('a')); - EXPECT_EQ(10, FXSYS_toHexDigit('A')); - EXPECT_EQ(7, FXSYS_toHexDigit('7')); - EXPECT_EQ(0, FXSYS_toHexDigit('i')); -} - -TEST(fxcrt, FXSYS_toDecimalDigit) { - EXPECT_EQ(7, FXSYS_toDecimalDigit('7')); - EXPECT_EQ(0, FXSYS_toDecimalDigit('a')); -} diff --git a/core/src/fxcrt/fx_xml_parser.cpp b/core/src/fxcrt/fx_xml_parser.cpp index 845fd84cfd..dc59ded2b7 100644 --- a/core/src/fxcrt/fx_xml_parser.cpp +++ b/core/src/fxcrt/fx_xml_parser.cpp @@ -5,9 +5,7 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com #include "../../include/fxcrt/fx_xml.h" -#include "../../include/fxcrt/fx_ext.h" #include "xml_int.h" - CXML_Parser::~CXML_Parser() { if (m_bOwnedStream) { m_pDataAcc->Release(); @@ -228,8 +226,9 @@ FX_DWORD CXML_Parser::GetCharRef() { iState = 10; break; } - if (g_FXCRT_XML_IsDigital(ch)) - code = code * 10 + FXSYS_toDecimalDigit(ch); + if (g_FXCRT_XML_IsDigital(ch)) { + code = code * 10 + ch - '0'; + } break; case 4: m_dwIndex++; @@ -241,7 +240,7 @@ FX_DWORD CXML_Parser::GetCharRef() { g_FXCRT_XML_ByteTypes[ch] & FXCRTM_XML_CHARTYPE_HexChar; if (nHex) { if (nHex == FXCRTM_XML_CHARTYPE_HexDigital) { - code = (code << 4) + FXSYS_toDecimalDigit(ch); + code = (code << 4) + ch - '0'; } else if (nHex == FXCRTM_XML_CHARTYPE_HexLowerLetter) { code = (code << 4) + ch - 87; } else { -- cgit v1.2.3