From 8492af92f2379cd8c1b68a4bd12c22c87b730190 Mon Sep 17 00:00:00 2001 From: "bienvenu%nventure.com" Date: Tue, 13 Apr 2004 14:37:53 +0000 Subject: [PATCH] make nsISeekableStream interface support 64 bit streams, part of 180154 also fix 207400 allow mail folders > 2GB r=darin, sr=mscott git-svn-id: svn://10.0.0.236/trunk@154796 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/mailnews/base/util/nsMsgDBFolder.cpp | 26 +++-- mozilla/mailnews/base/util/nsUInt32Array.cpp | 12 +++ mozilla/mailnews/base/util/nsUInt32Array.h | 1 + .../mailnews/db/msgdb/public/nsMsgDatabase.h | 2 +- .../mailnews/db/msgdb/src/nsMailDatabase.cpp | 5 +- .../mailnews/db/msgdb/src/nsMsgDatabase.cpp | 99 +++++++------------ .../mailnews/imap/src/nsImapMailFolder.cpp | 9 +- mozilla/mailnews/imap/src/nsImapService.cpp | 6 +- mozilla/mailnews/local/src/nsParseMailbox.cpp | 5 +- mozilla/mailnews/local/src/nsParseMailbox.h | 20 ++-- mozilla/mailnews/local/src/nsPop3Sink.cpp | 2 +- mozilla/mailnews/local/src/nsPop3Sink.h | 2 +- .../netwerk/base/src/nsBufferedStreams.cpp | 21 ++-- mozilla/netwerk/base/src/nsBufferedStreams.h | 4 +- mozilla/netwerk/base/src/nsFileStreams.cpp | 14 +-- .../netwerk/base/src/nsInputStreamPump.cpp | 15 ++- .../netwerk/base/src/nsMIMEInputStream.cpp | 6 +- mozilla/xpcom/io/nsFastLoadFile.cpp | 56 ++++++----- mozilla/xpcom/io/nsFastLoadFile.h | 2 +- mozilla/xpcom/io/nsFastLoadService.cpp | 6 +- mozilla/xpcom/io/nsISeekableStream.idl | 4 +- mozilla/xpcom/io/nsMultiplexInputStream.cpp | 13 ++- mozilla/xpcom/io/nsPipe3.cpp | 10 +- mozilla/xpcom/io/nsStorageStream.cpp | 19 ++-- mozilla/xpcom/io/nsStringStream.cpp | 15 ++- mozilla/xpcom/obsolete/nsFileStream.cpp | 7 +- mozilla/xpcom/obsolete/nsFileStream.h | 11 ++- mozilla/xpcom/obsolete/nsIFileStream.cpp | 26 ++--- 28 files changed, 229 insertions(+), 189 deletions(-) diff --git a/mozilla/mailnews/base/util/nsMsgDBFolder.cpp b/mozilla/mailnews/base/util/nsMsgDBFolder.cpp index e996ee8fee8..21765af25c8 100644 --- a/mozilla/mailnews/base/util/nsMsgDBFolder.cpp +++ b/mozilla/mailnews/base/util/nsMsgDBFolder.cpp @@ -75,6 +75,7 @@ #include "nsTextFormatter.h" #include "nsCPasswordManager.h" #include "nsMsgDBCID.h" +#include "nsInt64.h" #include @@ -1363,23 +1364,28 @@ nsresult nsMsgDBFolder::WriteStartOfNewLocalMessage() result += MSG_LINEBREAK; nsCOMPtr seekable; - PRUint32 curStorePos; + nsInt64 curStorePos; if (m_offlineHeader) seekable = do_QueryInterface(m_tempMessageStream); if (seekable) { - seekable->Tell(&curStorePos); - m_offlineHeader->SetMessageOffset(curStorePos); + PRInt64 tellPos; + seekable->Tell(&tellPos); + curStorePos = tellPos; + // ### todo - need to convert this to 64 bits + m_offlineHeader->SetMessageOffset((PRUint32) curStorePos); } m_tempMessageStream->Write(result.get(), result.Length(), &writeCount); if (seekable) { + PRInt64 tellPos; seekable->Seek(PR_SEEK_CUR, 0); // seeking causes a flush, w/o syncing - seekable->Tell(&curStorePos); - m_offlineHeader->SetStatusOffset(curStorePos); + seekable->Tell(&tellPos); + curStorePos = tellPos; + m_offlineHeader->SetStatusOffset((PRUint32) curStorePos); } result = "X-Mozilla-Status: 0001"; @@ -1416,7 +1422,7 @@ nsresult nsMsgDBFolder::StartNewOfflineMessage() nsresult nsMsgDBFolder::EndNewOfflineMessage() { nsCOMPtr seekable; - PRUint32 curStorePos; + nsInt64 curStorePos; PRUint32 messageOffset; nsMsgKey messageKey; @@ -1431,9 +1437,13 @@ nsresult nsMsgDBFolder::EndNewOfflineMessage() if (seekable) { seekable->Seek(PR_SEEK_CUR, 0); // seeking causes a flush, w/o syncing - seekable->Tell(&curStorePos); + PRInt64 tellPos; + seekable->Tell(&tellPos); + curStorePos = tellPos; + m_offlineHeader->GetMessageOffset(&messageOffset); - m_offlineHeader->SetOfflineMessageSize(curStorePos - messageOffset); + curStorePos -= messageOffset; + m_offlineHeader->SetOfflineMessageSize(curStorePos); m_offlineHeader->SetLineCount(m_numOfflineMsgLines); } m_offlineHeader = nsnull; diff --git a/mozilla/mailnews/base/util/nsUInt32Array.cpp b/mozilla/mailnews/base/util/nsUInt32Array.cpp index 31157e792e0..1f0b3cf8d4f 100644 --- a/mozilla/mailnews/base/util/nsUInt32Array.cpp +++ b/mozilla/mailnews/base/util/nsUInt32Array.cpp @@ -269,6 +269,18 @@ PRBool nsUInt32Array:: RemoveElement(PRUint32 element) } +PRUint32 nsUInt32Array::IndexOf(PRUint32 element) +{ + for (PRUint32 i = 0; i < GetSize(); i++) + { + if ((PRUint32)(m_pData[i]) == element) + { + return i; + } + } + return (PRUint32) kNotFound; +} + ///////////////////////////////////////////////////////////////////////////// void nsUInt32Array::CopyArray(nsUInt32Array *oldA) diff --git a/mozilla/mailnews/base/util/nsUInt32Array.h b/mozilla/mailnews/base/util/nsUInt32Array.h index fc70c5d8866..67d143cd94a 100644 --- a/mozilla/mailnews/base/util/nsUInt32Array.h +++ b/mozilla/mailnews/base/util/nsUInt32Array.h @@ -56,6 +56,7 @@ public: PRUint32 GetAt(PRUint32 nIndex) const; PRUint32 *GetData(); void SetAt(PRUint32 nIndex, PRUint32 newElement); + PRUint32 IndexOf(PRUint32 element); // Insertion/deletion member functions PRUint32 Add(PRUint32 newElement); diff --git a/mozilla/mailnews/db/msgdb/public/nsMsgDatabase.h b/mozilla/mailnews/db/msgdb/public/nsMsgDatabase.h index 797d05a1342..e8e53c9131c 100644 --- a/mozilla/mailnews/db/msgdb/public/nsMsgDatabase.h +++ b/mozilla/mailnews/db/msgdb/public/nsMsgDatabase.h @@ -220,7 +220,7 @@ protected: nsIMdbTable *m_mdbAllMsgHeadersTable; nsIMdbTable *m_mdbAllThreadsTable; nsFileSpec m_dbName; - nsMsgKeySet *m_newSet; // new messages since last open. + nsMsgKeyArray m_newSet; // new messages since last open. PRBool m_mdbTokensInitialized; nsCOMPtr m_ChangeListeners; mdb_token m_hdrRowScopeToken; diff --git a/mozilla/mailnews/db/msgdb/src/nsMailDatabase.cpp b/mozilla/mailnews/db/msgdb/src/nsMailDatabase.cpp index 1ee93f0483a..a5aa23d8389 100644 --- a/mozilla/mailnews/db/msgdb/src/nsMailDatabase.cpp +++ b/mozilla/mailnews/db/msgdb/src/nsMailDatabase.cpp @@ -376,7 +376,7 @@ void nsMailDatabase::UpdateFolderFlag(nsIMsgDBHdr *mailHdr, PRBool bSet, (void)mailHdr->GetMessageOffset(&msgOffset); PRUint32 statusPos = offset + msgOffset; PR_ASSERT(offset < 10000); - fileStream->seek(statusPos); + fileStream->seek(PR_SEEK_SET, statusPos); buf[0] = '\0'; if (fileStream->readline(buf, sizeof(buf))) { @@ -410,7 +410,7 @@ void nsMailDatabase::UpdateFolderFlag(nsIMsgDBHdr *mailHdr, PRBool bSet, PR_snprintf(buf, sizeof(buf), X_MOZILLA_STATUS_FORMAT, flags & 0x0000FFFF); PRInt32 lineLen = PL_strlen(buf); - PRInt32 status2Pos = statusPos + lineLen + MSG_LINEBREAK_LEN; + PRUint32 status2Pos = statusPos + lineLen + MSG_LINEBREAK_LEN; fileStream->write(buf, lineLen); // time to upate x-mozilla-status2 @@ -822,7 +822,6 @@ nsresult nsMailDatabase::SetFolderInfoValid(nsFileSpec *folderName, int num, int } { - pMessageDB->m_folderSpec = folderName; nsFileSpec::TimeStamp actualFolderTimeStamp = pMessageDB->GetMailboxModDate(); pMessageDB->m_dbFolderInfo->SetFolderSize(folderName->GetFileSize()); diff --git a/mozilla/mailnews/db/msgdb/src/nsMsgDatabase.cpp b/mozilla/mailnews/db/msgdb/src/nsMsgDatabase.cpp index ed802369661..7f9d567e0c6 100644 --- a/mozilla/mailnews/db/msgdb/src/nsMsgDatabase.cpp +++ b/mozilla/mailnews/db/msgdb/src/nsMsgDatabase.cpp @@ -718,7 +718,7 @@ nsMsgDatabase::nsMsgDatabase() m_nextPseudoMsgKey(kFirstPseudoKey), m_mdbEnv(nsnull), m_mdbStore(nsnull), m_mdbAllMsgHeadersTable(nsnull), m_mdbAllThreadsTable(nsnull), - m_dbName(""), m_newSet(nsnull), + m_dbName(""), m_mdbTokensInitialized(PR_FALSE), m_ChangeListeners(nsnull), m_hdrRowScopeToken(0), m_hdrTableKindToken(0), @@ -805,22 +805,6 @@ nsMsgDatabase::~nsMsgDatabase() NS_ASSERTION(count == 0, "shouldn't have any listeners"); m_ChangeListeners = nsnull; } - - if (m_newSet) - { -#ifdef DEBUG_MSGKEYSET - char *str = nsnull; - nsresult rv = m_newSet->Output(&str); - if (NS_SUCCEEDED(rv) && str) - { - printf("setStr = %s on destroy\n",str); - nsMemory::Free(str); - str = nsnull; - } -#endif - delete m_newSet; - m_newSet = nsnull; - } } NS_IMPL_ADDREF(nsMsgDatabase) @@ -1617,8 +1601,7 @@ NS_IMETHODIMP nsMsgDatabase::DeleteHeader(nsIMsgDBHdr *msg, nsIDBChangeListener // only need to do this for mail - will this speed up news expiration? SetHdrFlag(msg, PR_TRUE, MSG_FLAG_EXPUNGED); // tell mailbox (mail) - if (m_newSet) // if it's in the new set, better get rid of it. - m_newSet->Remove(key); + m_newSet.RemoveElement(key); if (m_dbFolderInfo != NULL) { @@ -1727,7 +1710,7 @@ PRUint32 nsMsgDatabase::GetStatusFlags(nsIMsgDBHdr *msgHdr, PRUint32 origFlags) nsMsgKey key; (void)msgHdr->GetMessageKey(&key); - if (m_newSet && m_newSet->IsMember(key)) + if (m_newSet.IndexOf(key) != kNotFound) statusFlags |= MSG_FLAG_NEW; else statusFlags &= ~MSG_FLAG_NEW; @@ -1813,8 +1796,7 @@ nsresult nsMsgDatabase::MarkHdrReadInDB(nsIMsgDBHdr *msgHdr, PRBool bRead, (void)msgHdr->GetMessageKey(&key); msgHdr->GetFlags(&oldFlags); - if (m_newSet) - m_newSet->Remove(key); + m_newSet.RemoveElement(key); (void) ContainsKey(key, &hdrInDB); if (hdrInDB && m_dbFolderInfo) { @@ -2267,52 +2249,40 @@ NS_IMETHODIMP nsMsgDatabase::MarkReadByDate (PRTime startDate, PRTime endDate, n NS_IMETHODIMP nsMsgDatabase::AddToNewList(nsMsgKey key) { - if (!m_newSet) - { - m_newSet = nsMsgKeySet::Create("" /* , this */); - if (!m_newSet) return NS_ERROR_OUT_OF_MEMORY; - } - - return m_newSet->Add(key); + return m_newSet.Add(key); } NS_IMETHODIMP nsMsgDatabase::ClearNewList(PRBool notify /* = FALSE */) { nsresult err = NS_OK; - if (m_newSet) + if (notify) // need to update view { - if (notify) // need to update view + PRInt32 firstMember; + nsMsgKeyArray saveNewSet; + saveNewSet.CopyArray(m_newSet); + // clear m_newSet so that the code that's listening to the key change + // doesn't think we have new messages and send notifications all over + // that we have new messages. + m_newSet.RemoveAll(); + for (PRUint32 elementIndex = saveNewSet.GetSize() - 1; ; elementIndex--) { - PRInt32 firstMember; - nsMsgKeySet *saveNewSet = m_newSet; - // set m_newSet to null so that the code that's listening to the key change - // doesn't think we have new messages and send notifications all over - // that we have new messages. - m_newSet = nsnull; - while ((firstMember = saveNewSet->GetFirstMember()) != 0) + nsMsgKey lastNewKey = saveNewSet.ElementAt(elementIndex); + nsCOMPtr msgHdr; + err = GetMsgHdrForKey(lastNewKey, getter_AddRefs(msgHdr)); + if (NS_SUCCEEDED(err)) { - saveNewSet->Remove(firstMember); // this bites, since this will cause us to regen new list many times. - nsCOMPtr msgHdr; - err = GetMsgHdrForKey(firstMember, getter_AddRefs(msgHdr)); - if (NS_SUCCEEDED(err)) - { - nsMsgKey key; - (void)msgHdr->GetMessageKey(&key); - PRUint32 flags; - (void)msgHdr->GetFlags(&flags); - - if ((flags | MSG_FLAG_NEW) != flags) - NotifyKeyChangeAll(key, flags | MSG_FLAG_NEW, flags, nsnull); - } + nsMsgKey key; + (void)msgHdr->GetMessageKey(&key); + PRUint32 flags; + (void)msgHdr->GetFlags(&flags); + + if ((flags | MSG_FLAG_NEW) != flags) + NotifyKeyChangeAll(key, flags | MSG_FLAG_NEW, flags, nsnull); } - m_newSet = saveNewSet; + if (elementIndex == 0) + break; } - delete m_newSet; - m_newSet = NULL; - } - else { - NS_ASSERTION(0, "no set!\n"); } return err; } @@ -2321,7 +2291,7 @@ NS_IMETHODIMP nsMsgDatabase::HasNew(PRBool *_retval) { if (!_retval) return NS_ERROR_NULL_POINTER; - *_retval = (m_newSet && m_newSet->getLength() > 0); + *_retval = (m_newSet.GetSize() > 0); return NS_OK; } @@ -2330,7 +2300,7 @@ NS_IMETHODIMP nsMsgDatabase::GetFirstNew(nsMsgKey *result) PRBool hasnew; nsresult rv = HasNew(&hasnew); if (NS_FAILED(rv)) return rv; - *result = (hasnew) ? m_newSet->GetFirstMember() : nsMsgKey_None; + *result = (hasnew) ? m_newSet.ElementAt(0) : nsMsgKey_None; return NS_OK; } @@ -4492,9 +4462,14 @@ nsMsgDatabase::GetNewList(nsMsgKeyArray * *aNewList) { NS_ENSURE_ARG_POINTER(aNewList); - if (m_newSet) - return m_newSet->ToMsgKeyArray(aNewList); - + if (m_newSet.GetSize() > 0) + { + *aNewList = new nsMsgKeyArray; + if (!*aNewList) + return NS_ERROR_OUT_OF_MEMORY; + (*aNewList)->CopyArray(m_newSet); + return NS_OK; + } // if there were no new messages, signal this by returning a null pointer // *aNewList = 0; diff --git a/mozilla/mailnews/imap/src/nsImapMailFolder.cpp b/mozilla/mailnews/imap/src/nsImapMailFolder.cpp index 517b1775807..a7a2a5c5fb6 100644 --- a/mozilla/mailnews/imap/src/nsImapMailFolder.cpp +++ b/mozilla/mailnews/imap/src/nsImapMailFolder.cpp @@ -107,6 +107,7 @@ #include "nsIMimeHeaders.h" #include "nsIMsgMdnGenerator.h" #include "nsISpamSettings.h" +#include "nsInt64.h" #include static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID); @@ -6061,19 +6062,21 @@ nsresult nsImapMailFolder::CopyOfflineMsgBody(nsIMsgFolder *srcFolder, nsIMsgDBH nsCOMPtr outputStream; nsresult rv = GetOfflineStoreOutputStream(getter_AddRefs(outputStream)); nsCOMPtr seekable; - PRUint32 curStorePos; seekable = do_QueryInterface(outputStream); if (seekable) { + nsMsgKey messageOffset; PRUint32 messageSize; origHdr->GetMessageOffset(&messageOffset); origHdr->GetOfflineMessageSize(&messageSize); - seekable->Tell(&curStorePos); - destHdr->SetMessageOffset(curStorePos); + PRInt64 tellPos; + seekable->Tell(&tellPos); + nsInt64 curStorePos = tellPos; + destHdr->SetMessageOffset((PRUint32) curStorePos); nsCOMPtr offlineStoreInputStream; rv = srcFolder->GetOfflineStoreInputStream(getter_AddRefs(offlineStoreInputStream)); if (NS_SUCCEEDED(rv) && offlineStoreInputStream) diff --git a/mozilla/mailnews/imap/src/nsImapService.cpp b/mozilla/mailnews/imap/src/nsImapService.cpp index 79173ba3bce..c860bc53cf2 100644 --- a/mozilla/mailnews/imap/src/nsImapService.cpp +++ b/mozilla/mailnews/imap/src/nsImapService.cpp @@ -100,6 +100,7 @@ #include "nsImapProtocol.h" #include "nsIMsgMailSession.h" #include "nsIStreamConverterService.h" +#include "nsInt64.h" #define PREF_MAIL_ROOT_IMAP "mail.root.imap" // old - for backward compatibility only #define PREF_MAIL_ROOT_IMAP_REL "mail.root.imap-rel" @@ -2091,7 +2092,7 @@ nsresult nsImapService::OfflineAppendFromFile(nsIFileSpec* aFileSpec, if (NS_SUCCEEDED(rv) && offlineStore) { - PRUint32 curOfflineStorePos = 0; + PRInt64 curOfflineStorePos = 0; nsCOMPtr seekable = do_QueryInterface(offlineStore); if (seekable) seekable->Tell(&curOfflineStorePos); @@ -2145,7 +2146,8 @@ nsresult nsImapService::OfflineAppendFromFile(nsIFileSpec* aFileSpec, if (NS_SUCCEEDED(rv) && fakeHdr) { PRUint32 resultFlags; - fakeHdr->SetMessageOffset(curOfflineStorePos); + nsInt64 tellPos = curOfflineStorePos; + fakeHdr->SetMessageOffset((PRUint32) tellPos); fakeHdr->OrFlags(MSG_FLAG_OFFLINE | MSG_FLAG_READ, &resultFlags); fakeHdr->SetOfflineMessageSize(fileSize); destDB->AddNewHdrToDB(fakeHdr, PR_TRUE /* notify */); diff --git a/mozilla/mailnews/local/src/nsParseMailbox.cpp b/mozilla/mailnews/local/src/nsParseMailbox.cpp index fd04383be58..65a8585f71a 100644 --- a/mozilla/mailnews/local/src/nsParseMailbox.cpp +++ b/mozilla/mailnews/local/src/nsParseMailbox.cpp @@ -276,7 +276,10 @@ void nsMsgMailboxParser::UpdateProgressPercent () { if (m_statusFeedback && m_graph_progress_total != 0) { - m_statusFeedback->ShowProgress((100 *(m_graph_progress_received)) / m_graph_progress_total); + // prevent overflow by dividing both by 100 + PRUint32 progressTotal = m_graph_progress_total / 100; + PRUint32 progressReceived = m_graph_progress_received / 100; + m_statusFeedback->ShowProgress((100 *(progressReceived)) / progressTotal); } } diff --git a/mozilla/mailnews/local/src/nsParseMailbox.h b/mozilla/mailnews/local/src/nsParseMailbox.h index 8dbc04c3bb7..398294eefb4 100644 --- a/mozilla/mailnews/local/src/nsParseMailbox.h +++ b/mozilla/mailnews/local/src/nsParseMailbox.h @@ -202,19 +202,19 @@ protected: void FreeBuffers(); // data - nsXPIDLString m_folderName; - nsXPIDLCString m_inboxUri; - nsByteArray m_inputStream; - PRInt32 m_obuffer_size; - char *m_obuffer; - PRInt32 m_graph_progress_total; - PRInt32 m_graph_progress_received; - PRBool m_parsingDone; - nsTime m_startTime; + nsXPIDLString m_folderName; + nsXPIDLCString m_inboxUri; + nsByteArray m_inputStream; + PRInt32 m_obuffer_size; + char *m_obuffer; + PRUint32 m_graph_progress_total; + PRUint32 m_graph_progress_received; + PRBool m_parsingDone; + nsTime m_startTime; private: // the following flag is used to determine when a url is currently being run. It is cleared on calls // to ::StopBinding and it is set whenever we call Load on a url - PRBool m_urlInProgress; + PRBool m_urlInProgress; nsWeakPtr m_folder; void Init(); void ReleaseFolderLock(); diff --git a/mozilla/mailnews/local/src/nsPop3Sink.cpp b/mozilla/mailnews/local/src/nsPop3Sink.cpp index df5b1260b8d..46a41276610 100644 --- a/mozilla/mailnews/local/src/nsPop3Sink.cpp +++ b/mozilla/mailnews/local/src/nsPop3Sink.cpp @@ -182,7 +182,7 @@ nsPop3Sink::BeginMailDelivery(PRBool uidlDownload, nsIMsgWindow *aMsgWindow, PRB if (!m_outFileStream) return NS_ERROR_OUT_OF_MEMORY; - m_outFileStream->seek(fileSpec.GetFileSize()); + m_outFileStream->seek(PR_SEEK_END, 0); if (!m_outFileStream->is_open()) return NS_ERROR_FAILURE; diff --git a/mozilla/mailnews/local/src/nsPop3Sink.h b/mozilla/mailnews/local/src/nsPop3Sink.h index cbedfbe91b6..e0c9e1f7081 100644 --- a/mozilla/mailnews/local/src/nsPop3Sink.h +++ b/mozilla/mailnews/local/src/nsPop3Sink.h @@ -70,7 +70,7 @@ protected: nsresult ReleaseFolderLock(); PRBool m_authed; - PRInt32 m_msgOffset; + PRInt64 m_msgOffset; char* m_accountUrl; PRUint32 m_biffState; PRInt32 m_numNewMessages; diff --git a/mozilla/netwerk/base/src/nsBufferedStreams.cpp b/mozilla/netwerk/base/src/nsBufferedStreams.cpp index f39c8b38bb3..9281464c49f 100644 --- a/mozilla/netwerk/base/src/nsBufferedStreams.cpp +++ b/mozilla/netwerk/base/src/nsBufferedStreams.cpp @@ -142,7 +142,7 @@ nsBufferedStream::Close() } NS_IMETHODIMP -nsBufferedStream::Seek(PRInt32 whence, PRInt32 offset) +nsBufferedStream::Seek(PRInt32 whence, PRInt64 offset) { if (mStream == nsnull) return NS_BASE_STREAM_CLOSED; @@ -155,13 +155,15 @@ nsBufferedStream::Seek(PRInt32 whence, PRInt32 offset) nsCOMPtr ras = do_QueryInterface(mStream, &rv); if (NS_FAILED(rv)) return rv; - PRInt32 absPos; + nsInt64 absPos; switch (whence) { case nsISeekableStream::NS_SEEK_SET: absPos = offset; break; case nsISeekableStream::NS_SEEK_CUR: - absPos = mBufferStartOffset + mCursor + offset; + absPos = mBufferStartOffset; + absPos += mCursor; + absPos += offset; break; case nsISeekableStream::NS_SEEK_END: absPos = -1; @@ -194,9 +196,12 @@ nsBufferedStream::Seek(PRInt32 whence, PRInt32 offset) METER(if (bufstats.mBigSeekIndex < MAX_BIG_SEEKS) bufstats.mBigSeek[bufstats.mBigSeekIndex].mOldOffset = mBufferStartOffset + mCursor); - if (absPos == -1) { + const nsInt64 minus1 = -1; + if (absPos == minus1) { // then we had the SEEK_END case, above - rv = ras->Tell(&mBufferStartOffset); + PRInt64 tellPos; + rv = ras->Tell(&tellPos); + mBufferStartOffset = tellPos; if (NS_FAILED(rv)) return rv; } else { @@ -211,12 +216,14 @@ nsBufferedStream::Seek(PRInt32 whence, PRInt32 offset) } NS_IMETHODIMP -nsBufferedStream::Tell(PRUint32 *result) +nsBufferedStream::Tell(PRInt64 *result) { if (mStream == nsnull) return NS_BASE_STREAM_CLOSED; - *result = mBufferStartOffset + mCursor; + nsInt64 result64 = mBufferStartOffset; + result64 += mCursor; + *result = result64; return NS_OK; } diff --git a/mozilla/netwerk/base/src/nsBufferedStreams.h b/mozilla/netwerk/base/src/nsBufferedStreams.h index 57929228e96..6c895ed2829 100644 --- a/mozilla/netwerk/base/src/nsBufferedStreams.h +++ b/mozilla/netwerk/base/src/nsBufferedStreams.h @@ -44,7 +44,7 @@ #include "nsISeekableStream.h" #include "nsIStreamBufferAccess.h" #include "nsCOMPtr.h" - +#include "nsInt64.h" //////////////////////////////////////////////////////////////////////////////// class nsBufferedStream : public nsISeekableStream @@ -67,7 +67,7 @@ protected: char* mBuffer; // mBufferStartOffset is the offset relative to the start of mStream. - PRUint32 mBufferStartOffset; + nsInt64 mBufferStartOffset; // mCursor is the read cursor for input streams, or write cursor for // output streams, and is relative to mBufferStartOffset. diff --git a/mozilla/netwerk/base/src/nsFileStreams.cpp b/mozilla/netwerk/base/src/nsFileStreams.cpp index 6de487e631c..c033ea0c0f7 100644 --- a/mozilla/netwerk/base/src/nsFileStreams.cpp +++ b/mozilla/netwerk/base/src/nsFileStreams.cpp @@ -129,26 +129,28 @@ nsFileStream::Close() } NS_IMETHODIMP -nsFileStream::Seek(PRInt32 whence, PRInt32 offset) +nsFileStream::Seek(PRInt32 whence, PRInt64 offset) { if (mFD == nsnull) return NS_BASE_STREAM_CLOSED; - PRInt32 cnt = PR_Seek(mFD, offset, (PRSeekWhence)whence); - if (cnt == -1) { + nsInt64 cnt = PR_Seek64(mFD, offset, (PRSeekWhence)whence); + const nsInt64 minus1(-1); + if (cnt == minus1) { return NS_ErrorAccordingToNSPR(); } return NS_OK; } NS_IMETHODIMP -nsFileStream::Tell(PRUint32 *result) +nsFileStream::Tell(PRInt64 *result) { if (mFD == nsnull) return NS_BASE_STREAM_CLOSED; - PRInt32 cnt = PR_Seek(mFD, 0, PR_SEEK_CUR); - if (cnt == -1) { + nsInt64 cnt = PR_Seek64(mFD, 0, PR_SEEK_CUR); + const nsInt64 minus1(-1); + if (cnt == minus1) { return NS_ErrorAccordingToNSPR(); } *result = cnt; diff --git a/mozilla/netwerk/base/src/nsInputStreamPump.cpp b/mozilla/netwerk/base/src/nsInputStreamPump.cpp index 8e806c080ed..feea7a0e1a6 100644 --- a/mozilla/netwerk/base/src/nsInputStreamPump.cpp +++ b/mozilla/netwerk/base/src/nsInputStreamPump.cpp @@ -45,6 +45,7 @@ #include "nsNetUtil.h" #include "nsCOMPtr.h" #include "prlog.h" +#include "nsInt64.h" static NS_DEFINE_CID(kStreamTransportServiceCID, NS_STREAMTRANSPORTSERVICE_CID); static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); @@ -424,7 +425,7 @@ nsInputStreamPump::OnStateTransfer() // in most cases this QI will succeed (mAsyncStream is almost always // a nsPipeInputStream, which implements nsISeekableStream::Tell). - PRUint32 offsetBefore; + PRInt64 offsetBefore; nsCOMPtr seekable = do_QueryInterface(mAsyncStream); if (seekable) seekable->Tell(&offsetBefore); @@ -436,10 +437,16 @@ nsInputStreamPump::OnStateTransfer() if (NS_SUCCEEDED(rv) && NS_SUCCEEDED(mStatus)) { // test to see if this ODA failed to consume data if (seekable) { - PRUint32 offsetAfter; + PRInt64 offsetAfter; seekable->Tell(&offsetAfter); - if (offsetAfter > offsetBefore) - mStreamOffset += (offsetAfter - offsetBefore); + nsInt64 offsetBefore64 = offsetBefore; + nsInt64 offsetAfter64 = offsetAfter; + if (offsetAfter64 > offsetBefore64) { + nsInt64 offsetDelta = offsetAfter64 - offsetBefore64; + const nsInt64 maxUint32 = PR_UINT32_MAX; + NS_ASSERTION(offsetDelta < maxUint32, "offset overflows PRUint32"); + mStreamOffset += (PRUint32) offsetDelta; + } else if (mSuspendCount == 0) { // // possible infinite loop if we continue pumping data! diff --git a/mozilla/netwerk/base/src/nsMIMEInputStream.cpp b/mozilla/netwerk/base/src/nsMIMEInputStream.cpp index 507a3360fa1..cfbc58607c1 100644 --- a/mozilla/netwerk/base/src/nsMIMEInputStream.cpp +++ b/mozilla/netwerk/base/src/nsMIMEInputStream.cpp @@ -207,11 +207,11 @@ if (!mStartedReading) { \ // Reset mStartedReading when Seek-ing to start NS_IMETHODIMP -nsMIMEInputStream::Seek(PRInt32 whence, PRInt32 offset) +nsMIMEInputStream::Seek(PRInt32 whence, PRInt64 offset) { nsresult rv; nsCOMPtr stream = do_QueryInterface(mStream); - if (whence == NS_SEEK_SET && offset == 0) { + if (whence == NS_SEEK_SET && LL_EQ(offset, LL_Zero())) { rv = stream->Seek(whence, offset); if (NS_SUCCEEDED(rv)) mStartedReading = PR_FALSE; @@ -263,7 +263,7 @@ NS_IMETHODIMP nsMIMEInputStream::Read(char * buf, PRUint32 count, PRUint32 *_ret NS_IMETHODIMP nsMIMEInputStream::IsNonBlocking(PRBool *aNonBlocking) { INITSTREAMS; return mStream->IsNonBlocking(aNonBlocking); } // nsISeekableStream -NS_IMETHODIMP nsMIMEInputStream::Tell(PRUint32 *_retval) +NS_IMETHODIMP nsMIMEInputStream::Tell(PRInt64 *_retval) { INITSTREAMS; nsCOMPtr stream = do_QueryInterface(mStream); diff --git a/mozilla/xpcom/io/nsFastLoadFile.cpp b/mozilla/xpcom/io/nsFastLoadFile.cpp index d4994199e85..812efd78dc6 100644 --- a/mozilla/xpcom/io/nsFastLoadFile.cpp +++ b/mozilla/xpcom/io/nsFastLoadFile.cpp @@ -55,7 +55,7 @@ #include "nsBinaryStream.h" #include "nsFastLoadFile.h" - +#include "nsInt64.h" #ifdef DEBUG_brendan # define METERING # define DEBUG_MUX @@ -322,7 +322,7 @@ struct nsDocumentMapReadEntry : public nsDocumentMapEntry { // Read, in case there is no Read before // another entry is Selected (to improve // input stream buffer utilization) - PRUint32 mSaveOffset; // in case demux schedule differs from + PRInt64 mSaveOffset; // in case demux schedule differs from // mux schedule }; @@ -633,7 +633,7 @@ nsFastLoadFileReader::ComputeChecksum(PRUint32 *aResult) nsCOMPtr stream = mInputStream; nsCOMPtr seekable(do_QueryInterface(stream)); - PRUint32 saveOffset; + PRInt64 saveOffset; nsresult rv = seekable->Tell(&saveOffset); if (NS_FAILED(rv)) return rv; @@ -959,12 +959,14 @@ nsFastLoadFileReader::Open() if (NS_FAILED(rv)) return rv; - PRUint32 fileSize; + PRInt64 fileSize; rv = seekable->Tell(&fileSize); if (NS_FAILED(rv)) return rv; - - if (fileSize != mHeader.mFileSize) + nsInt64 fileSize64(fileSize); + const nsInt64 maxUint32 = PR_UINT32_MAX; + NS_ASSERTION(maxUint32 > fileSize64, "fileSize must fit in 32 bits"); + if ((PRUint32) fileSize64 != mHeader.mFileSize) return NS_ERROR_UNEXPECTED; rv = seekable->Seek(nsISeekableStream::NS_SEEK_SET, @@ -1060,21 +1062,22 @@ nsFastLoadFileReader::ReadObject(PRBool aIsStrongRef, nsISupports* *aObject) object = entry->mReadObject; if (!object) { nsCOMPtr seekable(do_QueryInterface(mInputStream)); - PRUint32 saveOffset; + PRInt64 saveOffset; nsDocumentMapReadEntry* saveDocMapEntry = nsnull; rv = seekable->Tell(&saveOffset); if (NS_FAILED(rv)) return rv; - if (entry->mCIDOffset != saveOffset) { + PRUint32 saveOffset32 = saveOffset; + if (entry->mCIDOffset != saveOffset32) { // We skipped deserialization of this object from its position // earlier in the input stream, presumably due to the reference // there being an nsFastLoadPtr, or (more likely) because the // object was muxed in another document, and deserialization // order does not match serialization order. So we must seek // back and read it now. - NS_ASSERTION(entry->mCIDOffset < saveOffset, + NS_ASSERTION(entry->mCIDOffset < saveOffset32, "out of order object?!"); // Ape our Seek wrapper by clearing mCurrentDocumentMapEntry. @@ -1092,7 +1095,7 @@ nsFastLoadFileReader::ReadObject(PRBool aIsStrongRef, nsISupports* *aObject) if (NS_FAILED(rv)) return rv; - if (entry->mCIDOffset != saveOffset) { + if (entry->mCIDOffset != saveOffset32) { // Save the "skip offset" in case we need to skip this object // definition when reading forward, later on. rv = seekable->Tell(&entry->mSkipOffset); @@ -1173,7 +1176,7 @@ nsFastLoadFileReader::ReadID(nsID *aResult) } NS_IMETHODIMP -nsFastLoadFileReader::Seek(PRInt32 aWhence, PRInt32 aOffset) +nsFastLoadFileReader::Seek(PRInt32 aWhence, PRInt64 aOffset) { mCurrentDocumentMapEntry = nsnull; nsCOMPtr seekable(do_QueryInterface(mInputStream)); @@ -1181,7 +1184,7 @@ nsFastLoadFileReader::Seek(PRInt32 aWhence, PRInt32 aOffset) } NS_IMETHODIMP -nsFastLoadFileReader::Tell(PRUint32 *aResult) +nsFastLoadFileReader::Tell(PRInt64 *aResult) { nsCOMPtr seekable(do_QueryInterface(mInputStream)); return seekable->Tell(aResult); @@ -1436,11 +1439,12 @@ nsFastLoadFileWriter::SelectMuxedDocument(nsISupports* aURI, // Capture the current file offset (XXXbe maintain our own via Write?) nsresult rv; - PRUint32 currentSegmentOffset; + PRInt64 currentSegmentOffset; rv = seekable->Tell(¤tSegmentOffset); if (NS_FAILED(rv)) return rv; + PRUint32 currentSegmentOffset32 = currentSegmentOffset; // Look for an existing entry keyed by aURI, added by StartMuxedDocument. nsCOMPtr key(do_QueryInterface(aURI)); nsURIMapWriteEntry* uriMapEntry = @@ -1492,7 +1496,7 @@ nsFastLoadFileWriter::SelectMuxedDocument(nsISupports* aURI, // The length counts all bytes in the segment, including the header // that contains [nextSegmentOffset, length]. - rv = Write32(currentSegmentOffset - prevSegmentOffset); + rv = Write32(currentSegmentOffset32 - prevSegmentOffset); if (NS_FAILED(rv)) return rv; @@ -1511,14 +1515,14 @@ nsFastLoadFileWriter::SelectMuxedDocument(nsISupports* aURI, // Otherwise, seek back to write the next segment offset of the previous // segment for this document in the multiplex. if (!docMapEntry->mInitialSegmentOffset) { - docMapEntry->mInitialSegmentOffset = currentSegmentOffset; + docMapEntry->mInitialSegmentOffset = currentSegmentOffset32; } else { rv = seekable->Seek(nsISeekableStream::NS_SEEK_SET, docMapEntry->mCurrentSegmentOffset); if (NS_FAILED(rv)) return rv; - rv = Write32(currentSegmentOffset); + rv = Write32(currentSegmentOffset32); if (NS_FAILED(rv)) return rv; @@ -1531,7 +1535,7 @@ nsFastLoadFileWriter::SelectMuxedDocument(nsISupports* aURI, // Update this document's current segment offset so we can later fix its // next segment offset (unless it is last, in which case we leave the zero // placeholder as a terminator). - docMapEntry->mCurrentSegmentOffset = currentSegmentOffset; + docMapEntry->mCurrentSegmentOffset = currentSegmentOffset32; rv = Write32(0); // nextSegmentOffset placeholder if (NS_FAILED(rv)) @@ -1937,7 +1941,10 @@ nsFastLoadFileWriter::Close() nsCOMPtr seekable(do_QueryInterface(mOutputStream)); - rv = seekable->Tell(&mHeader.mFooterOffset); + PRInt64 footerOffset; + rv = seekable->Tell(&footerOffset); + + LL_L2UI(mHeader.mFooterOffset, footerOffset); if (NS_FAILED(rv)) return rv; @@ -1967,8 +1974,9 @@ nsFastLoadFileWriter::Close() rv = WriteFooter(); if (NS_FAILED(rv)) return rv; - - rv = seekable->Tell(&mHeader.mFileSize); + PRInt64 fileSize; + rv = seekable->Tell(&fileSize); + LL_L2UI(mHeader.mFileSize, fileSize); if (NS_FAILED(rv)) return rv; @@ -2106,7 +2114,7 @@ nsFastLoadFileWriter::WriteObjectCommon(nsISupports* aObject, if (!entry->mObject) { // First time we've seen this object address: add it to mObjectMap // and serialize the object at the current stream offset. - PRUint32 thisOffset; + PRInt64 thisOffset; rv = Tell(&thisOffset); if (NS_FAILED(rv)) { aObject->Release(); @@ -2261,7 +2269,7 @@ nsFastLoadFileWriter::WriteID(const nsID& aID) } NS_IMETHODIMP -nsFastLoadFileWriter::Seek(PRInt32 aWhence, PRInt32 aOffset) +nsFastLoadFileWriter::Seek(PRInt32 aWhence, PRInt64 aOffset) { mCurrentDocumentMapEntry = nsnull; nsCOMPtr seekable(do_QueryInterface(mOutputStream)); @@ -2269,7 +2277,7 @@ nsFastLoadFileWriter::Seek(PRInt32 aWhence, PRInt32 aOffset) } NS_IMETHODIMP -nsFastLoadFileWriter::Tell(PRUint32 *aResult) +nsFastLoadFileWriter::Tell(PRInt64 *aResult) { nsCOMPtr seekable(do_QueryInterface(mOutputStream)); return seekable->Tell(aResult); @@ -2391,7 +2399,7 @@ nsFastLoadFileUpdater::Open(nsFastLoadFileReader* aReader) // singleton object that might otherwise get written by this updater. nsDocumentMapReadEntry* saveDocMapEntry = nsnull; nsCOMPtr inputSeekable; - PRUint32 saveOffset = 0; + PRInt64 saveOffset = 0; for (i = 0, n = aReader->mFooter.mNumSharpObjects; i < n; i++) { nsFastLoadFileReader::nsObjectMapEntry* readEntry = &readObjectMap[i]; diff --git a/mozilla/xpcom/io/nsFastLoadFile.h b/mozilla/xpcom/io/nsFastLoadFile.h index 8452c4bba1c..dc9f20f1a39 100644 --- a/mozilla/xpcom/io/nsFastLoadFile.h +++ b/mozilla/xpcom/io/nsFastLoadFile.h @@ -303,7 +303,7 @@ class nsFastLoadFileReader */ struct nsObjectMapEntry : public nsFastLoadSharpObjectInfo { nsCOMPtr mReadObject; - PRUint32 mSkipOffset; + PRInt64 mSkipOffset; PRUint16 mSaveStrongRefCnt; // saved for an Update PRUint16 mSaveWeakRefCnt; // after a Read }; diff --git a/mozilla/xpcom/io/nsFastLoadService.cpp b/mozilla/xpcom/io/nsFastLoadService.cpp index 879d7c123b4..e09cbde9fb5 100644 --- a/mozilla/xpcom/io/nsFastLoadService.cpp +++ b/mozilla/xpcom/io/nsFastLoadService.cpp @@ -485,7 +485,7 @@ nsFastLoadService::ReadFastLoadPtr(nsIObjectInputStream* aInputStream, if (!seekable) return NS_ERROR_FAILURE; - PRUint32 thisOffset; + PRInt64 thisOffset; rv = seekable->Tell(&thisOffset); if (NS_FAILED(rv)) return rv; @@ -528,7 +528,7 @@ nsFastLoadService::WriteFastLoadPtr(nsIObjectOutputStream* aOutputStream, if (!seekable) return NS_ERROR_FAILURE; - PRUint32 saveOffset; + PRInt64 saveOffset; rv = seekable->Tell(&saveOffset); if (NS_FAILED(rv)) return rv; @@ -541,7 +541,7 @@ nsFastLoadService::WriteFastLoadPtr(nsIObjectOutputStream* aOutputStream, if (NS_FAILED(rv)) return rv; - PRUint32 nextOffset; + PRInt64 nextOffset; rv = seekable->Tell(&nextOffset); if (NS_FAILED(rv)) return rv; diff --git a/mozilla/xpcom/io/nsISeekableStream.idl b/mozilla/xpcom/io/nsISeekableStream.idl index cf2c3de6073..02b37fef352 100644 --- a/mozilla/xpcom/io/nsISeekableStream.idl +++ b/mozilla/xpcom/io/nsISeekableStream.idl @@ -82,7 +82,7 @@ interface nsISeekableStream : nsISupports * implementing stream. A negative value causes seeking in * the reverse direction. */ - void seek(in long whence, in long offset); + void seek(in long whence, in long long offset); /** * tell @@ -90,7 +90,7 @@ interface nsISeekableStream : nsISupports * This method reports the current offset, in bytes, from the start of the * stream. */ - unsigned long tell(); + long long tell(); /** diff --git a/mozilla/xpcom/io/nsMultiplexInputStream.cpp b/mozilla/xpcom/io/nsMultiplexInputStream.cpp index 3ad8e82ba11..ba04a842147 100644 --- a/mozilla/xpcom/io/nsMultiplexInputStream.cpp +++ b/mozilla/xpcom/io/nsMultiplexInputStream.cpp @@ -45,6 +45,7 @@ #include "nsIMultiplexInputStream.h" #include "nsISeekableStream.h" #include "nsSupportsArray.h" +#include "nsInt64.h" class nsMultiplexInputStream : public nsIMultiplexInputStream, public nsISeekableStream @@ -311,7 +312,7 @@ nsMultiplexInputStream::IsNonBlocking(PRBool *aNonBlocking) /* void seek (in PRInt32 whence, in PRInt32 offset); */ NS_IMETHODIMP -nsMultiplexInputStream::Seek(PRInt32 aWhence, PRInt32 aOffset) +nsMultiplexInputStream::Seek(PRInt32 aWhence, PRInt64 aOffset) { nsresult rv; @@ -338,21 +339,23 @@ nsMultiplexInputStream::Seek(PRInt32 aWhence, PRInt32 aOffset) /* PRUint32 tell (); */ NS_IMETHODIMP -nsMultiplexInputStream::Tell(PRUint32 *_retval) +nsMultiplexInputStream::Tell(PRInt64 *_retval) { nsresult rv; - *_retval = 0; + nsInt64 ret64 = 0; PRUint32 i, last; last = mStartedReadingCurrent ? mCurrentStream+1 : mCurrentStream; for (i = 0; i < last; ++i) { nsCOMPtr stream(do_QueryElementAt(&mStreams, i)); NS_ENSURE_TRUE(stream, NS_ERROR_NO_INTERFACE); - PRUint32 pos; + PRInt64 pos; rv = stream->Tell(&pos); NS_ENSURE_SUCCESS(rv, rv); - *_retval += pos; + ret64 += pos; } + *_retval = ret64; + return NS_OK; } diff --git a/mozilla/xpcom/io/nsPipe3.cpp b/mozilla/xpcom/io/nsPipe3.cpp index c0fcd4850b9..d64d8385f69 100644 --- a/mozilla/xpcom/io/nsPipe3.cpp +++ b/mozilla/xpcom/io/nsPipe3.cpp @@ -849,16 +849,16 @@ nsPipeInputStream::AsyncWait(nsIInputStreamCallback *callback, } NS_IMETHODIMP -nsPipeInputStream::Seek(PRInt32 whence, PRInt32 offset) +nsPipeInputStream::Seek(PRInt32 whence, PRInt64 offset) { NS_NOTREACHED("nsPipeInputStream::Seek"); return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP -nsPipeInputStream::Tell(PRUint32 *offset) +nsPipeInputStream::Tell(PRInt64 *offset) { - *offset = mLogicalOffset; + LL_UI2L(*offset, mLogicalOffset); return NS_OK; } @@ -1214,14 +1214,14 @@ nsPipeOutputStream::AsyncWait(nsIOutputStreamCallback *callback, } NS_IMETHODIMP -nsPipeOutputStream::Seek(PRInt32 whence, PRInt32 offset) +nsPipeOutputStream::Seek(PRInt32 whence, PRInt64 offset) { NS_NOTREACHED("nsPipeOutputStream::Seek"); return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP -nsPipeOutputStream::Tell(PRUint32 *offset) +nsPipeOutputStream::Tell(PRInt64 *offset) { *offset = mLogicalOffset; return NS_OK; diff --git a/mozilla/xpcom/io/nsStorageStream.cpp b/mozilla/xpcom/io/nsStorageStream.cpp index cece7220b99..e594972ebce 100644 --- a/mozilla/xpcom/io/nsStorageStream.cpp +++ b/mozilla/xpcom/io/nsStorageStream.cpp @@ -36,7 +36,7 @@ #include "nsIInputStream.h" #include "nsISeekableStream.h" #include "prlog.h" - +#include "nsInt64.h" #if defined(PR_LOGGING) // // Log module for StorageStream logging... @@ -473,35 +473,34 @@ nsStorageInputStream::IsNonBlocking(PRBool *aNonBlocking) } NS_IMETHODIMP -nsStorageInputStream::Seek(PRInt32 aWhence, PRInt32 aOffset) +nsStorageInputStream::Seek(PRInt32 aWhence, PRInt64 aOffset) { - PRUint32 pos; + nsInt64 pos = aOffset; switch (aWhence) { case NS_SEEK_SET: - pos = aOffset; break; case NS_SEEK_CUR: - pos = mLogicalCursor + aOffset; + pos += mLogicalCursor; break; case NS_SEEK_END: - pos = mStorageStream->mLogicalLength + aOffset; + pos += mStorageStream->mLogicalLength; break; default: NS_NOTREACHED("unexpected whence value"); return NS_ERROR_UNEXPECTED; } - - if (pos == mLogicalCursor) + nsInt64 logicalCursor(mLogicalCursor); + if (pos == logicalCursor) return NS_OK; return Seek(pos); } NS_IMETHODIMP -nsStorageInputStream::Tell(PRUint32 *aResult) +nsStorageInputStream::Tell(PRInt64 *aResult) { - *aResult = mLogicalCursor; + LL_UI2L(*aResult, mLogicalCursor); return NS_OK; } diff --git a/mozilla/xpcom/io/nsStringStream.cpp b/mozilla/xpcom/io/nsStringStream.cpp index b3b2b92e412..70f6c24aeed 100644 --- a/mozilla/xpcom/io/nsStringStream.cpp +++ b/mozilla/xpcom/io/nsStringStream.cpp @@ -58,6 +58,7 @@ #include "nsReadableUtils.h" #include "nsCRT.h" #include "nsISeekableStream.h" +#include "nsInt64.h" #define NS_FILE_RESULT(x) ns_file_convert_result((PRInt32)x) #define NS_FILE_FAILURE NS_FILE_RESULT(-1) @@ -261,17 +262,21 @@ nsStringInputStream::IsNonBlocking(PRBool *aNonBlocking) ///////// // nsISeekableStream implementation ///////// -NS_IMETHODIMP nsStringInputStream::Seek(PRInt32 whence, PRInt32 offset) +NS_IMETHODIMP nsStringInputStream::Seek(PRInt32 whence, PRInt64 offset) { mLastResult = NS_OK; // reset on a seek. + const nsInt64 maxUint32 = PR_UINT32_MAX; + nsInt64 offset64(offset); + PRInt32 offset32 = offset; + NS_ASSERTION(maxUint32 > offset64, "string streams only support 32 bit offsets"); mEOF = PR_FALSE; // reset on a seek. PRInt32 fileSize = LengthRemaining(); PRInt32 newPosition=-1; switch (whence) { - case NS_SEEK_CUR: newPosition = mOffset + offset; break; - case NS_SEEK_SET: newPosition = offset; break; - case NS_SEEK_END: newPosition = fileSize + offset; break; + case NS_SEEK_CUR: newPosition = mOffset + offset32; break; + case NS_SEEK_SET: newPosition = offset32; break; + case NS_SEEK_END: newPosition = fileSize + offset32; break; } if (newPosition < 0) { @@ -288,7 +293,7 @@ NS_IMETHODIMP nsStringInputStream::Seek(PRInt32 whence, PRInt32 offset) } -NS_IMETHODIMP nsStringInputStream::Tell(PRUint32* outWhere) +NS_IMETHODIMP nsStringInputStream::Tell(PRInt64* outWhere) { *outWhere = mOffset; return NS_OK; diff --git a/mozilla/xpcom/obsolete/nsFileStream.cpp b/mozilla/xpcom/obsolete/nsFileStream.cpp index 66923d5b9f2..5541ab755cf 100644 --- a/mozilla/xpcom/obsolete/nsFileStream.cpp +++ b/mozilla/xpcom/obsolete/nsFileStream.cpp @@ -43,7 +43,7 @@ #include "nsFileSpec.h" #include "nsIFileSpec.h" #include "nsIStringStream.h" - +#include "nsInt64.h" #include #include @@ -228,8 +228,9 @@ PRBool nsRandomAccessInputStream::readline(char* s, PRInt32 n) if (!s || !n) return PR_TRUE; - PRIntn position = tell(); - if (position < 0) + nsInt64 position = tell(); + const nsInt64 zero(0); + if (position < zero) return PR_FALSE; PRInt32 bytesRead = read(s, n - 1); if (failed()) diff --git a/mozilla/xpcom/obsolete/nsFileStream.h b/mozilla/xpcom/obsolete/nsFileStream.h index a976c50af36..81838006b81 100644 --- a/mozilla/xpcom/obsolete/nsFileStream.h +++ b/mozilla/xpcom/obsolete/nsFileStream.h @@ -387,22 +387,23 @@ public: } virtual ~nsRandomAccessStoreClient() {} - void seek(PRInt32 offset) + void seek(PRInt64 offset) { seek(PR_SEEK_SET, offset); } - void seek(PRSeekWhence whence, PRInt32 offset) + void seek(PRSeekWhence whence, PRInt64 offset) { set_at_eof(PR_FALSE); if (mStore) mResult = mStore->Seek(whence, offset); } - PRIntn tell() + PRInt64 tell() { - PRIntn result = -1; + PRInt64 result; + LL_I2L(result, -1); if (mStore) - mResult = mStore->Tell((PRUint32 *)&result); + mResult = mStore->Tell(&result); return result; } diff --git a/mozilla/xpcom/obsolete/nsIFileStream.cpp b/mozilla/xpcom/obsolete/nsIFileStream.cpp index 15690134958..eca96bb4211 100644 --- a/mozilla/xpcom/obsolete/nsIFileStream.cpp +++ b/mozilla/xpcom/obsolete/nsIFileStream.cpp @@ -43,6 +43,7 @@ #include "prerror.h" #include "nsSegmentedBuffer.h" +#include "nsInt64.h" #ifdef XP_MAC #include "pprio.h" // To get PR_ImportFile @@ -318,7 +319,7 @@ NS_IMETHODIMP FileImpl::GetIsOpen(PRBool* outOpen) } //---------------------------------------------------------------------------------------- -NS_IMETHODIMP FileImpl::Seek(PRInt32 whence, PRInt32 offset) +NS_IMETHODIMP FileImpl::Seek(PRInt32 whence, PRInt64 offset) //---------------------------------------------------------------------------------------- { if (mFileDesc==PR_STDIN || mFileDesc==PR_STDOUT || mFileDesc==PR_STDERR || !mFileDesc) @@ -329,17 +330,18 @@ NS_IMETHODIMP FileImpl::Seek(PRInt32 whence, PRInt32 offset) // To avoid corruption, we flush during a seek. see bug number 18949 InternalFlush(PR_FALSE); - PRInt32 position = PR_Seek(mFileDesc, 0, PR_SEEK_CUR); - PRInt32 available = PR_Available(mFileDesc); - PRInt32 fileSize = position + available; - PRInt32 newPosition = 0; + nsInt64 position = PR_Seek64(mFileDesc, 0, PR_SEEK_CUR); + nsInt64 available = PR_Available64(mFileDesc); + nsInt64 fileSize = position + available; + nsInt64 newPosition = offset; switch (whence) { - case NS_SEEK_CUR: newPosition = position + offset; break; - case NS_SEEK_SET: newPosition = offset; break; - case NS_SEEK_END: newPosition = fileSize + offset; break; + case NS_SEEK_CUR: newPosition += position; break; + case NS_SEEK_SET: ; break; + case NS_SEEK_END: newPosition += fileSize; break; } - if (newPosition < 0) + const nsInt64 zero = 0; + if (newPosition < zero) { newPosition = 0; mFailed = PR_TRUE; @@ -349,7 +351,7 @@ NS_IMETHODIMP FileImpl::Seek(PRInt32 whence, PRInt32 offset) newPosition = fileSize; mEOF = PR_TRUE; } - if (PR_Seek(mFileDesc, newPosition, PR_SEEK_SET) < 0) + if (PR_Seek64(mFileDesc, newPosition, PR_SEEK_SET) < 0) mFailed = PR_TRUE; return NS_OK; } // FileImpl::Seek @@ -492,12 +494,12 @@ FileImpl::IsNonBlocking(PRBool *aNonBlocking) } //---------------------------------------------------------------------------------------- -NS_IMETHODIMP FileImpl::Tell(PRUint32* outWhere) +NS_IMETHODIMP FileImpl::Tell(PRInt64* outWhere) //---------------------------------------------------------------------------------------- { if (mFileDesc==PR_STDIN || mFileDesc==PR_STDOUT || mFileDesc==PR_STDERR || !mFileDesc) return NS_FILE_RESULT(PR_BAD_DESCRIPTOR_ERROR); - *outWhere = PR_Seek(mFileDesc, 0, PR_SEEK_CUR); + *outWhere = PR_Seek64(mFileDesc, 0, PR_SEEK_CUR); return NS_OK; } // FileImpl::Tell