Bug 699731 - Remove PR_INT64_MAX / PR_UINT64_MAX from non-nsprpub source; r=ted

This commit is contained in:
Ms2ger 2012-01-11 09:23:07 +01:00
parent 7cf1cd311b
commit 1a688061bd
11 changed files with 49 additions and 59 deletions

View File

@ -58,10 +58,7 @@
#include "mozilla/dom/indexedDB/IndexedDatabaseManager.h"
#include "mozilla/GuardObjects.h"
#ifndef PR_UINT64_MAX
#define PR_UINT64_MAX (~(PRUint64)(0))
#endif
#include "mozilla/StdInt.h"
class nsIFile;
class nsIInputStream;
@ -99,7 +96,7 @@ public:
: mIsFile(false), mImmutable(false), mContentType(aContentType),
mStart(aStart), mLength(aLength)
{
NS_ASSERTION(aLength != PR_UINT64_MAX,
NS_ASSERTION(aLength != UINT64_MAX,
"Must know length when creating slice");
// Ensure non-null mContentType by default
mContentType.SetIsVoid(false);
@ -120,7 +117,7 @@ public:
protected:
bool IsSizeUnknown()
{
return mLength == PR_UINT64_MAX;
return mLength == UINT64_MAX;
}
virtual bool IsStoredFile()
@ -152,7 +149,7 @@ class nsDOMFileFile : public nsDOMFileBase,
public:
// Create as a file
nsDOMFileFile(nsIFile *aFile)
: nsDOMFileBase(EmptyString(), EmptyString(), PR_UINT64_MAX),
: nsDOMFileBase(EmptyString(), EmptyString(), UINT64_MAX),
mFile(aFile), mWholeFile(true), mStoredFile(false)
{
NS_ASSERTION(mFile, "must have file");
@ -164,7 +161,7 @@ public:
// Create as a blob
nsDOMFileFile(nsIFile *aFile, const nsAString& aContentType,
nsISupports *aCacheToken = nsnull)
: nsDOMFileBase(aContentType, PR_UINT64_MAX),
: nsDOMFileBase(aContentType, UINT64_MAX),
mFile(aFile), mWholeFile(true), mStoredFile(false),
mCacheToken(aCacheToken)
{
@ -194,7 +191,7 @@ public:
// Create as a file to be later initialized
nsDOMFileFile()
: nsDOMFileBase(EmptyString(), EmptyString(), PR_UINT64_MAX),
: nsDOMFileBase(EmptyString(), EmptyString(), UINT64_MAX),
mWholeFile(true), mStoredFile(false)
{
// Lazily get the content type and size

View File

@ -46,9 +46,7 @@
#include "nsContentUtils.h"
#include "CheckedInt.h"
// XXXkhuey shamelessly stolen from VideoUtils.h. We should patch NSPR.
#define PR_INT64_MAX (~((PRInt64)(1) << 63))
#define PR_INT64_MIN (-PR_INT64_MAX - 1)
#include "mozilla/StdInt.h"
using namespace mozilla;
@ -59,7 +57,7 @@ public:
nsDOMMultipartFile(nsTArray<nsCOMPtr<nsIDOMBlob> > aBlobs,
const nsAString& aName,
const nsAString& aContentType)
: nsDOMFileBase(aName, aContentType, PR_UINT64_MAX),
: nsDOMFileBase(aName, aContentType, UINT64_MAX),
mBlobs(aBlobs)
{
}
@ -67,7 +65,7 @@ public:
// Create as a blob
nsDOMMultipartFile(nsTArray<nsCOMPtr<nsIDOMBlob> > aBlobs,
const nsAString& aContentType)
: nsDOMFileBase(aContentType, PR_UINT64_MAX),
: nsDOMFileBase(aContentType, UINT64_MAX),
mBlobs(aBlobs)
{
}
@ -85,7 +83,7 @@ protected:
NS_IMETHODIMP
nsDOMMultipartFile::GetSize(PRUint64* aLength)
{
if (mLength == PR_UINT64_MAX) {
if (mLength == UINT64_MAX) {
CheckedUint64 length = 0;
PRUint32 i;

View File

@ -39,6 +39,8 @@
#include "nsMathUtils.h"
#include "prtypes.h"
#include "mozilla/StdInt.h"
// Adds two 32bit unsigned numbers, retuns true if addition succeeded,
// or false the if addition would result in an overflow.
bool AddOverflow32(PRUint32 a, PRUint32 b, PRUint32& aResult) {
@ -68,11 +70,11 @@ bool MulOverflow32(PRUint32 a, PRUint32 b, PRUint32& aResult)
// if addition would result in an overflow.
bool AddOverflow(PRInt64 a, PRInt64 b, PRInt64& aResult) {
if (b < 1) {
if (PR_INT64_MIN - b <= a) {
if (INT64_MIN - b <= a) {
aResult = a + b;
return true;
}
} else if (PR_INT64_MAX - b >= a) {
} else if (INT64_MAX - b >= a) {
aResult = a + b;
return true;
}
@ -99,7 +101,7 @@ bool MulOverflow(PRInt64 a, PRInt64 b, PRInt64& aResult) {
// So to check if a*b overflows, we must check each sub part of the above
// sum.
//
// Note: -1 * PR_INT64_MIN == PR_INT64_MIN ; we can't negate PR_INT64_MIN!
// Note: -1 * INT64_MIN == INT64_MIN ; we can't negate INT64_MIN!
// Note: Shift of negative numbers is undefined.
//
// Figure out the sign after multiplication. Then we can just work with
@ -110,7 +112,7 @@ bool MulOverflow(PRInt64 a, PRInt64 b, PRInt64& aResult) {
PRInt64 abs_b = (b < 0) ? -b : b;
if (abs_a < 0) {
NS_ASSERTION(a == PR_INT64_MIN, "How else can this happen?");
NS_ASSERTION(a == INT64_MIN, "How else can this happen?");
if (b == 0 || b == 1) {
aResult = a * b;
return true;
@ -120,7 +122,7 @@ bool MulOverflow(PRInt64 a, PRInt64 b, PRInt64& aResult) {
}
if (abs_b < 0) {
NS_ASSERTION(b == PR_INT64_MIN, "How else can this happen?");
NS_ASSERTION(b == INT64_MIN, "How else can this happen?");
if (a == 0 || a == 1) {
aResult = a * b;
return true;
@ -162,7 +164,7 @@ bool MulOverflow(PRInt64 a, PRInt64 b, PRInt64& aResult) {
// Both a_lo and b_lo are less than INT32_MAX, so can't overflow.
PRUint64 lo = a_lo * b_lo;
if (lo > PR_INT64_MAX) {
if (lo > INT64_MAX) {
return false;
}

View File

@ -49,19 +49,6 @@
// remove this file in the near future.
// This belongs in prtypes.h
/************************************************************************
* MACROS: PR_INT64_MAX
* PR_INT64_MIN
* PR_UINT64_MAX
* DESCRIPTION:
* The maximum and minimum values of a PRInt64 or PRUint64.
************************************************************************/
#define PR_INT64_MAX (~((PRInt64)(1) << 63))
#define PR_INT64_MIN (-PR_INT64_MAX - 1)
#define PR_UINT64_MAX (~(PRUint64)(0))
// This belongs in xpcom/monitor/Monitor.h, once we've made
// mozilla::Monitor non-reentrant.
namespace mozilla {

View File

@ -43,9 +43,11 @@
#include "nsBuiltinDecoder.h"
#include "nsBuiltinDecoderReader.h"
#include "nsBuiltinDecoderStateMachine.h"
#include "mozilla/mozalloc.h"
#include "VideoUtils.h"
#include "mozilla/mozalloc.h"
#include "mozilla/StdInt.h"
using namespace mozilla;
using mozilla::layers::ImageContainer;
using mozilla::layers::PlanarYCbCrImage;
@ -216,8 +218,8 @@ VideoData* nsBuiltinDecoderReader::FindStartTime(PRInt64& aOutStartTime)
// Extract the start times of the bitstreams in order to calculate
// the duration.
PRInt64 videoStartTime = PR_INT64_MAX;
PRInt64 audioStartTime = PR_INT64_MAX;
PRInt64 videoStartTime = INT64_MAX;
PRInt64 audioStartTime = INT64_MAX;
VideoData* videoData = nsnull;
if (HasVideo()) {
@ -236,7 +238,7 @@ VideoData* nsBuiltinDecoderReader::FindStartTime(PRInt64& aOutStartTime)
}
PRInt64 startTime = NS_MIN(videoStartTime, audioStartTime);
if (startTime != PR_INT64_MAX) {
if (startTime != INT64_MAX) {
aOutStartTime = startTime;
}

View File

@ -45,7 +45,9 @@
#include "mozilla/mozalloc.h"
#include "VideoUtils.h"
#include "nsTimeRanges.h"
#include "mozilla/Preferences.h"
#include "mozilla/StdInt.h"
using namespace mozilla;
using namespace mozilla::layers;
@ -1162,7 +1164,7 @@ void nsBuiltinDecoderStateMachine::Seek(double aTime)
NS_ASSERTION(mState >= DECODER_STATE_DECODING,
"We should have loaded metadata");
double t = aTime * static_cast<double>(USECS_PER_S);
if (t > PR_INT64_MAX) {
if (t > INT64_MAX) {
// Prevent integer overflow.
return;
}

View File

@ -44,6 +44,8 @@
#include "VideoUtils.h"
#include "nsBuiltinDecoderReader.h"
#include "mozilla/StdInt.h"
#ifdef PR_LOGGING
extern PRLogModuleInfo* gBuiltinDecoderLog;
#define LOG(type, msg) PR_LOG(gBuiltinDecoderLog, type, msg)
@ -1045,8 +1047,8 @@ nsresult nsSkeletonState::GetDuration(const nsTArray<PRUint32>& aTracks,
{
return NS_ERROR_FAILURE;
}
PRInt64 endTime = PR_INT64_MIN;
PRInt64 startTime = PR_INT64_MAX;
PRInt64 endTime = INT64_MIN;
PRInt64 startTime = INT64_MAX;
for (PRUint32 i=0; i<aTracks.Length(); i++) {
nsKeyFrameIndex* index = nsnull;
mIndex.Get(aTracks[i], &index);

View File

@ -51,6 +51,8 @@
#include <nsClassHashtable.h>
#include "VideoUtils.h"
#include "mozilla/StdInt.h"
// Uncomment the following to validate that we're predicting the number
// of Vorbis samples in each packet correctly.
#define VALIDATE_VORBIS_SAMPLE_CALCULATION
@ -340,8 +342,8 @@ public:
class nsKeyPoint {
public:
nsKeyPoint()
: mOffset(PR_INT64_MAX),
mTime(PR_INT64_MAX) {}
: mOffset(INT64_MAX),
mTime(INT64_MAX) {}
nsKeyPoint(PRInt64 aOffset, PRInt64 aTime)
: mOffset(aOffset),
@ -354,8 +356,8 @@ public:
PRInt64 mTime;
bool IsNull() {
return mOffset == PR_INT64_MAX &&
mTime == PR_INT64_MAX;
return mOffset == INT64_MAX &&
mTime == INT64_MAX;
}
};

View File

@ -43,6 +43,8 @@
#include "nsTimeRanges.h"
#include "VideoUtils.h"
#include "mozilla/StdInt.h"
using namespace mozilla;
// Un-comment to enable logging of seek bisections.
@ -225,8 +227,8 @@ bool nsWaveReader::DecodeAudioData()
double posTime = BytesToTime(pos);
double readSizeTime = BytesToTime(readSize);
NS_ASSERTION(posTime <= PR_INT64_MAX / USECS_PER_S, "posTime overflow");
NS_ASSERTION(readSizeTime <= PR_INT64_MAX / USECS_PER_S, "readSizeTime overflow");
NS_ASSERTION(posTime <= INT64_MAX / USECS_PER_S, "posTime overflow");
NS_ASSERTION(readSizeTime <= INT64_MAX / USECS_PER_S, "readSizeTime overflow");
NS_ASSERTION(frames < PR_INT32_MAX, "frames overflow");
mAudioQueue.Push(new AudioData(pos,
@ -255,11 +257,11 @@ nsresult nsWaveReader::Seek(PRInt64 aTarget, PRInt64 aStartTime, PRInt64 aEndTim
return NS_ERROR_FAILURE;
}
double d = BytesToTime(GetDataLength());
NS_ASSERTION(d < PR_INT64_MAX / USECS_PER_S, "Duration overflow");
NS_ASSERTION(d < INT64_MAX / USECS_PER_S, "Duration overflow");
PRInt64 duration = static_cast<PRInt64>(d * USECS_PER_S);
double seekTime = NS_MIN(aTarget, duration) / static_cast<double>(USECS_PER_S);
PRInt64 position = RoundDownToFrame(static_cast<PRInt64>(TimeToBytes(seekTime)));
NS_ASSERTION(PR_INT64_MAX - mWavePCMOffset > position, "Integer overflow during wave seek");
NS_ASSERTION(INT64_MAX - mWavePCMOffset > position, "Integer overflow during wave seek");
position += mWavePCMOffset;
return mDecoder->GetStream()->Seek(nsISeekableStream::NS_SEEK_SET, position);
}

View File

@ -56,9 +56,6 @@
#include "prmem.h"
#include "prenv.h"
#include "ImageLogging.h"
#include "mozilla/TimeStamp.h"
#include "mozilla/Telemetry.h"
#include "mozilla/Preferences.h"
#include "ImageLayers.h"
#include "nsPNGDecoder.h"
@ -70,6 +67,11 @@
#include "gfxContext.h"
#include "mozilla/Preferences.h"
#include "mozilla/StdInt.h"
#include "mozilla/Telemetry.h"
#include "mozilla/TimeStamp.h"
using namespace mozilla;
using namespace mozilla::imagelib;
using namespace mozilla::layers;
@ -677,7 +679,7 @@ RasterImage::GetCurrentImgFrameEndTime() const
// doesn't work correctly if we have a negative timeout value. The reason
// this positive infinity was chosen was because it works with the loop in
// RequestRefresh() above.
return TimeStamp() + TimeDuration::FromMilliseconds(UINT64_MAX_VAL);
return TimeStamp() + TimeDuration::FromMilliseconds(UINT64_MAX);
}
TimeDuration durationOfTimeout = TimeDuration::FromMilliseconds(timeout);

View File

@ -82,12 +82,6 @@ class nsIInputStream;
{0xb1, 0x43, 0x33, 0x40, 0xc0, 0x01, 0x12, 0xf7} \
}
/**
* It would be nice if we had a macro for this in prtypes.h.
* TODO: Place this macro in prtypes.h as PR_UINT64_MAX.
*/
#define UINT64_MAX_VAL PRUint64(-1)
/**
* Handles static and animated image containers.
*