summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-04-11 09:03:14 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-04-11 14:24:24 +0000
commitd7120eead6f6e0b05c1197e55e899081deae1289 (patch)
tree824819037adf17bc2b291f5f0dbc922510a8ffe2
parent96e65ae3a3a328022f025805e9db02cbed1b5607 (diff)
downloadpdfium-d7120eead6f6e0b05c1197e55e899081deae1289.tar.xz
Disabiguate CreateStream calls
This CL creates a CreateReadStream and CreateWriteStream method instead of having a single overloaded method. This removes the need for the cast at the call sites. The access parameter has been rolled into the method as it was always passed the same way to each Create*Stream method. Change-Id: I845951c3fe386b8051daf4f6b2ee5ba29b5c7d54 Reviewed-on: https://pdfium-review.googlesource.com/4032 Reviewed-by: Nicolás Peña <npm@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
-rw-r--r--xfa/fde/xml/cfde_xmlsyntaxparser_unittest.cpp30
-rw-r--r--xfa/fgas/crt/ifgas_stream.cpp38
-rw-r--r--xfa/fgas/crt/ifgas_stream.h14
-rw-r--r--xfa/fxfa/parser/cxfa_dataexporter.cpp12
-rw-r--r--xfa/fxfa/parser/cxfa_node.cpp7
-rw-r--r--xfa/fxfa/parser/cxfa_simple_parser.cpp3
-rw-r--r--xfa/fxfa/parser/cxfa_widetextread.cpp2
7 files changed, 39 insertions, 67 deletions
diff --git a/xfa/fde/xml/cfde_xmlsyntaxparser_unittest.cpp b/xfa/fde/xml/cfde_xmlsyntaxparser_unittest.cpp
index 66f4bbf928..aa7c17901a 100644
--- a/xfa/fde/xml/cfde_xmlsyntaxparser_unittest.cpp
+++ b/xfa/fde/xml/cfde_xmlsyntaxparser_unittest.cpp
@@ -30,7 +30,7 @@ TEST_F(CFDE_XMLSyntaxParserTest, CData) {
// We * sizeof(wchar_t) because we pass in the uint8_t, not the wchar_t.
size_t len = FXSYS_wcslen(input) * sizeof(wchar_t);
CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream(
- reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len, 0);
+ reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len);
CFDE_XMLSyntaxParser parser(stream);
EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
@@ -77,7 +77,7 @@ TEST_F(CFDE_XMLSyntaxParserTest, CDataWithInnerScript) {
// We * sizeof(wchar_t) because we pass in the uint8_t, not the wchar_t.
size_t len = FXSYS_wcslen(input) * sizeof(wchar_t);
CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream(
- reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len, 0);
+ reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len);
CFDE_XMLSyntaxParser parser(stream);
EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
@@ -113,7 +113,7 @@ TEST_F(CFDE_XMLSyntaxParserTest, ArrowBangArrow) {
// We * sizeof(wchar_t) because we pass in the uint8_t, not the wchar_t.
size_t len = FXSYS_wcslen(input) * sizeof(wchar_t);
CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream(
- reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len, 0);
+ reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len);
CFDE_XMLSyntaxParser parser(stream);
EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
@@ -147,7 +147,7 @@ TEST_F(CFDE_XMLSyntaxParserTest, ArrowBangBracketArrow) {
// We * sizeof(wchar_t) because we pass in the uint8_t, not the wchar_t.
size_t len = FXSYS_wcslen(input) * sizeof(wchar_t);
CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream(
- reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len, 0);
+ reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len);
CFDE_XMLSyntaxParser parser(stream);
EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
@@ -176,7 +176,7 @@ TEST_F(CFDE_XMLSyntaxParserTest, IncompleteCData) {
// We * sizeof(wchar_t) because we pass in the uint8_t, not the wchar_t.
size_t len = FXSYS_wcslen(input) * sizeof(wchar_t);
CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream(
- reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len, 0);
+ reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len);
CFDE_XMLSyntaxParser parser(stream);
EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
@@ -205,7 +205,7 @@ TEST_F(CFDE_XMLSyntaxParserTest, UnClosedCData) {
// We * sizeof(wchar_t) because we pass in the uint8_t, not the wchar_t.
size_t len = FXSYS_wcslen(input) * sizeof(wchar_t);
CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream(
- reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len, 0);
+ reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len);
CFDE_XMLSyntaxParser parser(stream);
EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
@@ -234,7 +234,7 @@ TEST_F(CFDE_XMLSyntaxParserTest, EmptyCData) {
// We * sizeof(wchar_t) because we pass in the uint8_t, not the wchar_t.
size_t len = FXSYS_wcslen(input) * sizeof(wchar_t);
CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream(
- reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len, 0);
+ reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len);
CFDE_XMLSyntaxParser parser(stream);
EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
@@ -270,7 +270,7 @@ TEST_F(CFDE_XMLSyntaxParserTest, Comment) {
// We * sizeof(wchar_t) because we pass in the uint8_t, not the wchar_t.
size_t len = FXSYS_wcslen(input) * sizeof(wchar_t);
CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream(
- reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len, 0);
+ reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len);
CFDE_XMLSyntaxParser parser(stream);
EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
@@ -303,7 +303,7 @@ TEST_F(CFDE_XMLSyntaxParserTest, IncorrectCommentStart) {
// We * sizeof(wchar_t) because we pass in the uint8_t, not the wchar_t.
size_t len = FXSYS_wcslen(input) * sizeof(wchar_t);
CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream(
- reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len, 0);
+ reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len);
CFDE_XMLSyntaxParser parser(stream);
EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
@@ -336,7 +336,7 @@ TEST_F(CFDE_XMLSyntaxParserTest, CommentEmpty) {
// We * sizeof(wchar_t) because we pass in the uint8_t, not the wchar_t.
size_t len = FXSYS_wcslen(input) * sizeof(wchar_t);
CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream(
- reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len, 0);
+ reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len);
CFDE_XMLSyntaxParser parser(stream);
EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
@@ -369,7 +369,7 @@ TEST_F(CFDE_XMLSyntaxParserTest, CommentThreeDash) {
// We * sizeof(wchar_t) because we pass in the uint8_t, not the wchar_t.
size_t len = FXSYS_wcslen(input) * sizeof(wchar_t);
CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream(
- reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len, 0);
+ reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len);
CFDE_XMLSyntaxParser parser(stream);
EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
@@ -396,7 +396,7 @@ TEST_F(CFDE_XMLSyntaxParserTest, CommentTwoDash) {
// We * sizeof(wchar_t) because we pass in the uint8_t, not the wchar_t.
size_t len = FXSYS_wcslen(input) * sizeof(wchar_t);
CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream(
- reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len, 0);
+ reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len);
CFDE_XMLSyntaxParser parser(stream);
EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
@@ -427,7 +427,7 @@ TEST_F(CFDE_XMLSyntaxParserTest, Entities) {
// We * sizeof(wchar_t) because we pass in the uint8_t, not the wchar_t.
size_t len = FXSYS_wcslen(input) * sizeof(wchar_t);
CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream(
- reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len, 0);
+ reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len);
CFDE_XMLSyntaxParser parser(stream);
EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
@@ -458,7 +458,7 @@ TEST_F(CFDE_XMLSyntaxParserTest, EntityOverflowHex) {
// We * sizeof(wchar_t) because we pass in the uint8_t, not the wchar_t.
size_t len = FXSYS_wcslen(input) * sizeof(wchar_t);
CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream(
- reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len, 0);
+ reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len);
CFDE_XMLSyntaxParser parser(stream);
EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
@@ -489,7 +489,7 @@ TEST_F(CFDE_XMLSyntaxParserTest, EntityOverflowDecimal) {
// We * sizeof(wchar_t) because we pass in the uint8_t, not the wchar_t.
size_t len = FXSYS_wcslen(input) * sizeof(wchar_t);
CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream(
- reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len, 0);
+ reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len);
CFDE_XMLSyntaxParser parser(stream);
EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
diff --git a/xfa/fgas/crt/ifgas_stream.cpp b/xfa/fgas/crt/ifgas_stream.cpp
index 209532476d..a4330dcd67 100644
--- a/xfa/fgas/crt/ifgas_stream.cpp
+++ b/xfa/fgas/crt/ifgas_stream.cpp
@@ -911,7 +911,7 @@ void CFGAS_TextStream::InitStream() {
}
uint32_t CFGAS_TextStream::GetAccessModes() const {
- return m_pStreamImp->GetAccessModes() | FX_STREAMACCESS_Text;
+ return m_pStreamImp->GetAccessModes();
}
int32_t CFGAS_TextStream::GetLength() const {
@@ -1368,44 +1368,30 @@ bool CFGAS_FileRead::ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) {
} // namespace
// static
-CFX_RetainPtr<IFGAS_Stream> IFGAS_Stream::CreateStream(
- const CFX_RetainPtr<IFX_SeekableReadStream>& pFileRead,
- uint32_t dwAccess) {
+CFX_RetainPtr<IFGAS_Stream> IFGAS_Stream::CreateReadStream(
+ const CFX_RetainPtr<IFX_SeekableReadStream>& pFileRead) {
auto pSR = pdfium::MakeRetain<CFGAS_Stream>();
- if (!pSR->LoadFileRead(pFileRead, dwAccess))
+ if (!pSR->LoadFileRead(pFileRead, FX_STREAMACCESS_Read))
return nullptr;
-
- if (dwAccess & FX_STREAMACCESS_Text)
- return pdfium::MakeRetain<CFGAS_TextStream>(pSR);
-
- return pSR;
+ return pdfium::MakeRetain<CFGAS_TextStream>(pSR);
}
// static
-CFX_RetainPtr<IFGAS_Stream> IFGAS_Stream::CreateStream(
- const CFX_RetainPtr<IFX_SeekableWriteStream>& pFileWrite,
- uint32_t dwAccess) {
+CFX_RetainPtr<IFGAS_Stream> IFGAS_Stream::CreateWriteStream(
+ const CFX_RetainPtr<IFX_SeekableWriteStream>& pFileWrite) {
auto pSR = pdfium::MakeRetain<CFGAS_Stream>();
- if (!pSR->LoadFileWrite(pFileWrite, dwAccess))
+ if (!pSR->LoadFileWrite(pFileWrite,
+ FX_STREAMACCESS_Write | FX_STREAMACCESS_Append))
return nullptr;
-
- if (dwAccess & FX_STREAMACCESS_Text)
- return pdfium::MakeRetain<CFGAS_TextStream>(pSR);
-
- return pSR;
+ return pdfium::MakeRetain<CFGAS_TextStream>(pSR);
}
// static
CFX_RetainPtr<IFGAS_Stream> IFGAS_Stream::CreateStream(uint8_t* pData,
- int32_t length,
- uint32_t dwAccess) {
+ int32_t length) {
auto pSR = pdfium::MakeRetain<CFGAS_Stream>();
- if (!pSR->LoadBuffer(pData, length, dwAccess))
+ if (!pSR->LoadBuffer(pData, length, 0))
return nullptr;
-
- if (dwAccess & FX_STREAMACCESS_Text)
- return pdfium::MakeRetain<CFGAS_TextStream>(pSR);
-
return pSR;
}
diff --git a/xfa/fgas/crt/ifgas_stream.h b/xfa/fgas/crt/ifgas_stream.h
index 01a148019f..31d1e67589 100644
--- a/xfa/fgas/crt/ifgas_stream.h
+++ b/xfa/fgas/crt/ifgas_stream.h
@@ -13,7 +13,6 @@
enum FX_STREAMACCESS {
FX_STREAMACCESS_Binary = 0x00,
- FX_STREAMACCESS_Text = 0x01,
FX_STREAMACCESS_Read = 0x02,
FX_STREAMACCESS_Write = 0x04,
FX_STREAMACCESS_Truncate = 0x10,
@@ -29,15 +28,12 @@ enum FX_STREAMSEEK {
class IFGAS_Stream : public CFX_Retainable {
public:
- static CFX_RetainPtr<IFGAS_Stream> CreateStream(
- const CFX_RetainPtr<IFX_SeekableReadStream>& pFileRead,
- uint32_t dwAccess);
- static CFX_RetainPtr<IFGAS_Stream> CreateStream(
- const CFX_RetainPtr<IFX_SeekableWriteStream>& pFileWrite,
- uint32_t dwAccess);
+ static CFX_RetainPtr<IFGAS_Stream> CreateReadStream(
+ const CFX_RetainPtr<IFX_SeekableReadStream>& pFileRead);
+ static CFX_RetainPtr<IFGAS_Stream> CreateWriteStream(
+ const CFX_RetainPtr<IFX_SeekableWriteStream>& pFileWrite);
static CFX_RetainPtr<IFGAS_Stream> CreateStream(uint8_t* pData,
- int32_t length,
- uint32_t dwAccess);
+ int32_t length);
virtual uint32_t GetAccessModes() const = 0;
virtual int32_t GetLength() const = 0;
diff --git a/xfa/fxfa/parser/cxfa_dataexporter.cpp b/xfa/fxfa/parser/cxfa_dataexporter.cpp
index fda29c2201..3963b162cb 100644
--- a/xfa/fxfa/parser/cxfa_dataexporter.cpp
+++ b/xfa/fxfa/parser/cxfa_dataexporter.cpp
@@ -226,12 +226,8 @@ void RegenerateFormFile_Changed(CXFA_Node* pNode,
CFX_RetainPtr<IFX_MemoryStream> pMemStream =
IFX_MemoryStream::Create(true);
-
- // Note: ambiguous without cast below.
- CFX_RetainPtr<IFGAS_Stream> pTempStream = IFGAS_Stream::CreateStream(
- CFX_RetainPtr<IFX_SeekableWriteStream>(pMemStream),
- FX_STREAMACCESS_Text | FX_STREAMACCESS_Write |
- FX_STREAMACCESS_Append);
+ CFX_RetainPtr<IFGAS_Stream> pTempStream =
+ IFGAS_Stream::CreateWriteStream(pMemStream);
pTempStream->SetCodePage(FX_CODEPAGE_UTF8);
pRichTextXML->SaveXMLNode(pTempStream);
@@ -489,9 +485,7 @@ bool CXFA_DataExporter::Export(
if (!pWrite)
return false;
- CFX_RetainPtr<IFGAS_Stream> pStream = IFGAS_Stream::CreateStream(
- pWrite,
- FX_STREAMACCESS_Text | FX_STREAMACCESS_Write | FX_STREAMACCESS_Append);
+ CFX_RetainPtr<IFGAS_Stream> pStream = IFGAS_Stream::CreateWriteStream(pWrite);
if (!pStream)
return false;
diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp
index 5ed013c259..5f582458de 100644
--- a/xfa/fxfa/parser/cxfa_node.cpp
+++ b/xfa/fxfa/parser/cxfa_node.cpp
@@ -1411,11 +1411,8 @@ void CXFA_Node::Script_NodeClass_SaveXML(CFXJSE_Arguments* pArguments) {
}
CFX_RetainPtr<IFX_MemoryStream> pMemoryStream =
IFX_MemoryStream::Create(true);
-
- // Note: ambiguious below without static_cast.
- CFX_RetainPtr<IFGAS_Stream> pStream = IFGAS_Stream::CreateStream(
- CFX_RetainPtr<IFX_SeekableWriteStream>(pMemoryStream),
- FX_STREAMACCESS_Text | FX_STREAMACCESS_Write | FX_STREAMACCESS_Append);
+ CFX_RetainPtr<IFGAS_Stream> pStream =
+ IFGAS_Stream::CreateWriteStream(pMemoryStream);
if (!pStream) {
pArguments->GetReturnValue()->SetString(bsXMLHeader);
diff --git a/xfa/fxfa/parser/cxfa_simple_parser.cpp b/xfa/fxfa/parser/cxfa_simple_parser.cpp
index 55a85fd6d9..d423bba56d 100644
--- a/xfa/fxfa/parser/cxfa_simple_parser.cpp
+++ b/xfa/fxfa/parser/cxfa_simple_parser.cpp
@@ -277,8 +277,7 @@ int32_t CXFA_SimpleParser::StartParse(
XFA_XDPPACKET ePacketID) {
CloseParser();
m_pFileRead = pStream;
- m_pStream = IFGAS_Stream::CreateStream(
- pStream, FX_STREAMACCESS_Read | FX_STREAMACCESS_Text);
+ m_pStream = IFGAS_Stream::CreateReadStream(pStream);
if (!m_pStream)
return XFA_PARSESTATUS_StreamErr;
diff --git a/xfa/fxfa/parser/cxfa_widetextread.cpp b/xfa/fxfa/parser/cxfa_widetextread.cpp
index 842e7ba0cd..be2da8c70c 100644
--- a/xfa/fxfa/parser/cxfa_widetextread.cpp
+++ b/xfa/fxfa/parser/cxfa_widetextread.cpp
@@ -18,7 +18,7 @@ CXFA_WideTextRead::CXFA_WideTextRead(const CFX_WideString& wsBuffer)
CXFA_WideTextRead::~CXFA_WideTextRead() {}
uint32_t CXFA_WideTextRead::GetAccessModes() const {
- return FX_STREAMACCESS_Read | FX_STREAMACCESS_Text;
+ return FX_STREAMACCESS_Read;
}
int32_t CXFA_WideTextRead::GetLength() const {