Now that bug 320375 is fixed, trying once more to check in fix for bug 274777 (Update to Expat 1.95.8). r=bsmedberg, sr=bz.
git-svn-id: svn://10.0.0.236/trunk@186215 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -386,7 +386,7 @@ nsExpatDriver::HandleEndElement(const PRUnichar *aValue)
|
||||
if (mSink &&
|
||||
mSink->HandleEndElement(aValue) == NS_ERROR_HTMLPARSER_BLOCK) {
|
||||
mInternalState = NS_ERROR_HTMLPARSER_BLOCK;
|
||||
MOZ_XML_StopParser(mExpatParser, XML_TRUE);
|
||||
XML_StopParser(mExpatParser, XML_TRUE);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
@@ -453,7 +453,7 @@ nsExpatDriver::HandleProcessingInstruction(const PRUnichar *aTarget,
|
||||
mSink->HandleProcessingInstruction(aTarget, aData) ==
|
||||
NS_ERROR_HTMLPARSER_BLOCK) {
|
||||
mInternalState = NS_ERROR_HTMLPARSER_BLOCK;
|
||||
MOZ_XML_StopParser(mExpatParser, XML_TRUE);
|
||||
XML_StopParser(mExpatParser, XML_TRUE);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
@@ -573,10 +573,9 @@ ExternalDTDStreamReaderFunc(nsIUnicharInputStream* aIn,
|
||||
PRUint32 aCount,
|
||||
PRUint32 *aWriteCount)
|
||||
{
|
||||
// Pass the buffer to expat for parsing. XML_Parse returns 0 for
|
||||
// fatal errors.
|
||||
// Pass the buffer to expat for parsing.
|
||||
if (XML_Parse((XML_Parser)aClosure, (const char *)aFromSegment,
|
||||
aCount * sizeof(PRUnichar), 0)) {
|
||||
aCount * sizeof(PRUnichar), 0) == XML_STATUS_OK) {
|
||||
*aWriteCount = aCount;
|
||||
|
||||
return NS_OK;
|
||||
@@ -848,8 +847,16 @@ nsExpatDriver::ParseBuffer(const char* aBuffer,
|
||||
XML_GetCurrentByteIndex(mExpatParser) % sizeof(PRUnichar) == 0,
|
||||
"Consumed part of a PRUnichar?");
|
||||
|
||||
if (mExpatParser && mInternalState == NS_OK) {
|
||||
XML_Bool parsedAll = XML_Parse(mExpatParser, aBuffer, aLength, aIsFinal);
|
||||
if (mExpatParser && (mInternalState == NS_OK ||
|
||||
mInternalState == NS_ERROR_HTMLPARSER_BLOCK)) {
|
||||
XML_Status status;
|
||||
if (mInternalState == NS_ERROR_HTMLPARSER_BLOCK) {
|
||||
mInternalState = NS_OK; // Resume in case we're blocked.
|
||||
status = XML_ResumeParser(mExpatParser);
|
||||
}
|
||||
else {
|
||||
status = XML_Parse(mExpatParser, aBuffer, aLength, aIsFinal);
|
||||
}
|
||||
|
||||
PRInt32 parserBytesConsumed = XML_GetCurrentByteIndex(mExpatParser);
|
||||
|
||||
@@ -863,8 +870,10 @@ nsExpatDriver::ParseBuffer(const char* aBuffer,
|
||||
const PRUnichar* const buffer =
|
||||
NS_REINTERPRET_CAST(const PRUnichar*, aBuffer);
|
||||
PRUint32 startOffset;
|
||||
// we assume that if expat failed to consume some bytes last time it won't
|
||||
// consume them this time without also consuming some bytes from aBuffer.
|
||||
// If expat failed to consume some bytes last time it won't consume them
|
||||
// this time without also consuming some bytes from aBuffer. Note that when
|
||||
// resuming after suspending the parser, aBuffer will contain the data that
|
||||
// Expat also has in its internal buffer.
|
||||
// Note that if expat consumed everything we passed it, it will have nulled
|
||||
// out all its internal pointers to data, so parserBytesConsumed will come
|
||||
// out -1 in that case.
|
||||
@@ -905,46 +914,44 @@ nsExpatDriver::ParseBuffer(const char* aBuffer,
|
||||
}
|
||||
}
|
||||
|
||||
if (!parsedAll) {
|
||||
if (mInternalState == NS_ERROR_HTMLPARSER_BLOCK ||
|
||||
mInternalState == NS_ERROR_HTMLPARSER_STOPPARSING) {
|
||||
NS_ASSERTION((PRUint32)parserBytesConsumed >= mBytesParsed,
|
||||
"How'd this happen?");
|
||||
mBytePosition = parserBytesConsumed - mBytesParsed;
|
||||
mBytesParsed = parserBytesConsumed;
|
||||
if (buffer) {
|
||||
PRUint32 endOffset = mBytePosition / sizeof(PRUnichar);
|
||||
NS_ASSERTION(startOffset <= endOffset,
|
||||
"Something is confused about what we've consumed");
|
||||
// Only append the data we actually parsed. The rest will come
|
||||
// through this method again.
|
||||
mLastLine.Append(Substring(buffer + startOffset,
|
||||
buffer + endOffset));
|
||||
}
|
||||
}
|
||||
else {
|
||||
// An error occured, look for the next newline after the last one we
|
||||
// consumed.
|
||||
PRUint32 length = aLength / sizeof(PRUnichar);
|
||||
if (buffer) {
|
||||
PRUint32 endOffset = startOffset;
|
||||
while (endOffset < length && buffer[endOffset] != '\n' &&
|
||||
buffer[endOffset] != '\r') {
|
||||
++endOffset;
|
||||
}
|
||||
mLastLine.Append(Substring(buffer + startOffset,
|
||||
buffer + endOffset));
|
||||
}
|
||||
HandleError();
|
||||
mInternalState = NS_ERROR_HTMLPARSER_STOPPARSING;
|
||||
if (status == XML_STATUS_SUSPENDED) {
|
||||
NS_ASSERTION(mInternalState == NS_ERROR_HTMLPARSER_BLOCK,
|
||||
"mInternalState out of sync!");
|
||||
NS_ASSERTION((PRUint32)parserBytesConsumed >= mBytesParsed,
|
||||
"How'd this happen?");
|
||||
mBytePosition = parserBytesConsumed - mBytesParsed;
|
||||
mBytesParsed = parserBytesConsumed;
|
||||
if (buffer) {
|
||||
PRUint32 endOffset = mBytePosition / sizeof(PRUnichar);
|
||||
NS_ASSERTION(startOffset <= endOffset,
|
||||
"Something is confused about what we've consumed");
|
||||
// Only append the data we actually parsed. The rest will come
|
||||
// through this method again.
|
||||
mLastLine.Append(Substring(buffer + startOffset, buffer + endOffset));
|
||||
}
|
||||
|
||||
return mInternalState;
|
||||
}
|
||||
|
||||
PRUint32 length = aLength / sizeof(PRUnichar);
|
||||
if (status == XML_STATUS_ERROR) {
|
||||
// Look for the next newline after the last one we consumed
|
||||
if (buffer) {
|
||||
PRUint32 endOffset = startOffset;
|
||||
while (endOffset < length && buffer[endOffset] != '\n' &&
|
||||
buffer[endOffset] != '\r') {
|
||||
++endOffset;
|
||||
}
|
||||
mLastLine.Append(Substring(buffer + startOffset, buffer + endOffset));
|
||||
}
|
||||
HandleError();
|
||||
mInternalState = NS_ERROR_HTMLPARSER_STOPPARSING;
|
||||
|
||||
return mInternalState;
|
||||
}
|
||||
|
||||
if (!aIsFinal && buffer) {
|
||||
mLastLine.Append(Substring(buffer + startOffset,
|
||||
buffer + aLength / sizeof(PRUnichar)));
|
||||
mLastLine.Append(Substring(buffer + startOffset, buffer + length));
|
||||
}
|
||||
mBytesParsed += aLength;
|
||||
mBytePosition = 0;
|
||||
@@ -966,9 +973,6 @@ nsExpatDriver::ConsumeToken(nsScanner& aScanner,
|
||||
// Ask the scanner to send us all the data it has
|
||||
// scanned and pass that data to expat.
|
||||
|
||||
mInternalState = NS_OK; // Resume in case we're blocked.
|
||||
MOZ_XML_ResumeParser(mExpatParser);
|
||||
|
||||
nsScannerIterator start, end;
|
||||
aScanner.CurrentPosition(start);
|
||||
aScanner.EndReading(end);
|
||||
@@ -978,7 +982,7 @@ nsExpatDriver::ConsumeToken(nsScanner& aScanner,
|
||||
|
||||
mInternalState = ParseBuffer((const char*)start.get(),
|
||||
fragLength * sizeof(PRUnichar),
|
||||
aFlushTokens);
|
||||
PR_FALSE);
|
||||
|
||||
if (NS_FAILED(mInternalState)) {
|
||||
if (mInternalState == NS_ERROR_HTMLPARSER_BLOCK) {
|
||||
@@ -1128,7 +1132,8 @@ nsExpatDriver::WillInterruptParse(nsIContentSink* aSink)
|
||||
NS_IMETHODIMP
|
||||
nsExpatDriver::DidTokenize(PRBool aIsFinalChunk)
|
||||
{
|
||||
return ParseBuffer(nsnull, 0, aIsFinalChunk);
|
||||
return mInternalState == NS_OK ? ParseBuffer(nsnull, 0, aIsFinalChunk) :
|
||||
NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(const nsIID&)
|
||||
@@ -1142,7 +1147,7 @@ nsExpatDriver::Terminate()
|
||||
{
|
||||
// XXX - not sure what happens to the unparsed data.
|
||||
if (mExpatParser) {
|
||||
MOZ_XML_StopParser(mExpatParser, XML_FALSE);
|
||||
XML_StopParser(mExpatParser, XML_FALSE);
|
||||
}
|
||||
mInternalState = NS_ERROR_HTMLPARSER_STOPPARSING;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user