Bug 1037100 - Remove all use of ScopedDeleteArray from mozglue/. r=glandium

--HG--
extra : rebase_source : dbc49be874fd57130f33584892589c180c7d1128
This commit is contained in:
Jeff Walden 2014-07-21 18:14:11 -04:00
Родитель cb5758222b
Коммит ec20cc707d
2 изменённых файлов: 24 добавлений и 26 удалений

Просмотреть файл

@ -23,6 +23,9 @@
#include "SeekableZStream.h"
#include "Logging.h"
using mozilla::MakeUnique;
using mozilla::UniquePtr;
Mappable *
MappableFile::Create(const char *path)
{
@ -67,8 +70,8 @@ MappableExtractFile::Create(const char *name, Zip *zip, Zip::Stream *stream)
"not extracting");
return nullptr;
}
mozilla::UniquePtr<char[]> path;
path.reset(new char[strlen(cachePath) + strlen(name) + 2]);
UniquePtr<char[]> path =
MakeUnique<char[]>(strlen(cachePath) + strlen(name) + 2);
sprintf(path.get(), "%s/%s", cachePath, name);
struct stat cacheStat;
if (stat(path.get(), &cacheStat) == 0) {
@ -87,8 +90,7 @@ MappableExtractFile::Create(const char *name, Zip *zip, Zip::Stream *stream)
ERROR("Couldn't open %s to decompress library", path.get());
return nullptr;
}
AutoUnlinkFile file;
file = path.release();
AutoUnlinkFile file(path.release());
if (stream->GetType() == Zip::Stream::DEFLATE) {
if (ftruncate(fd, stream->GetUncompressedSize()) == -1) {
ERROR("Couldn't ftruncate %s to decompress library", file.get());
@ -147,7 +149,7 @@ MappableExtractFile::Create(const char *name, Zip *zip, Zip::Stream *stream)
return nullptr;
}
return new MappableExtractFile(fd.forget(), file.forget());
return new MappableExtractFile(fd.forget(), Move(file));
}
MappableExtractFile::~MappableExtractFile()
@ -157,7 +159,7 @@ MappableExtractFile::~MappableExtractFile()
* doesn't really matter, it helps e.g. valgrind that the file is there.
* The string still needs to be delete[]d, though */
if (pid != getpid())
delete [] path.forget();
delete [] path.release();
}
/**
@ -389,13 +391,12 @@ MappableSeekableZStream::Create(const char *name, Zip *zip,
if (!mappable->zStream.Init(stream->GetBuffer(), stream->GetSize()))
return nullptr;
mappable->buffer = _MappableBuffer::Create(name,
mappable->zStream.GetUncompressedSize());
mappable->buffer.reset(_MappableBuffer::Create(name,
mappable->zStream.GetUncompressedSize()));
if (!mappable->buffer)
return nullptr;
mappable->chunkAvail = new unsigned char[mappable->zStream.GetChunksNum()];
memset(mappable->chunkAvail, 0, mappable->zStream.GetChunksNum());
mappable->chunkAvail = MakeUnique<unsigned char[]>(mappable->zStream.GetChunksNum());
return mappable.forget();
}
@ -579,7 +580,7 @@ MappableSeekableZStream::stats(const char *when, const char *name) const
name, when, static_cast<size_t>(chunkAvailNum), nEntries);
size_t len = 64;
mozilla::UniquePtr<char[]> map(new char[len + 3]);
UniquePtr<char[]> map = MakeUnique<char[]>(len + 3);
map[0] = '[';
for (size_t i = 0, j = 1; i < nEntries; i++, j++) {

Просмотреть файл

@ -10,7 +10,7 @@
#include "Zip.h"
#include "SeekableZStream.h"
#include "mozilla/RefPtr.h"
#include "mozilla/Scoped.h"
#include "mozilla/UniquePtr.h"
#include "zlib.h"
/**
@ -123,24 +123,21 @@ public:
virtual Kind GetKind() const { return MAPPABLE_EXTRACT_FILE; };
private:
MappableExtractFile(int fd, char *path)
: MappableFile(fd), path(path), pid(getpid()) { }
/**
* AutoUnlinkFile keeps track or a file name and removes (unlinks) the file
* AutoUnlinkFile keeps track of a file name and removes (unlinks) the file
* when the instance is destroyed.
*/
struct AutoUnlinkFileTraits: public mozilla::ScopedDeleteArrayTraits<char>
struct UnlinkFile
{
static void release(char *value)
{
if (!value)
return;
void operator()(char *value) {
unlink(value);
mozilla::ScopedDeleteArrayTraits<char>::release(value);
delete [] value;
}
};
typedef mozilla::Scoped<AutoUnlinkFileTraits> AutoUnlinkFile;
typedef mozilla::UniquePtr<char[], UnlinkFile> AutoUnlinkFile;
MappableExtractFile(int fd, AutoUnlinkFile path)
: MappableFile(fd), path(Move(path)), pid(getpid()) { }
/* Extracted file */
AutoUnlinkFile path;
@ -180,7 +177,7 @@ private:
mozilla::RefPtr<Zip> zip;
/* Decompression buffer */
mozilla::ScopedDeletePtr<_MappableBuffer> buffer;
mozilla::UniquePtr<_MappableBuffer> buffer;
/* Zlib data */
z_stream zStream;
@ -220,7 +217,7 @@ private:
mozilla::RefPtr<Zip> zip;
/* Decompression buffer */
mozilla::ScopedDeletePtr<_MappableBuffer> buffer;
mozilla::UniquePtr<_MappableBuffer> buffer;
/* Seekable ZStream */
SeekableZStream zStream;
@ -263,7 +260,7 @@ private:
/* Array keeping track of which chunks have already been decompressed.
* Each value is the number of pages decompressed for the given chunk. */
mozilla::ScopedDeleteArray<unsigned char> chunkAvail;
mozilla::UniquePtr<unsigned char[]> chunkAvail;
/* Number of chunks that have already been decompressed. */
mozilla::Atomic<size_t> chunkAvailNum;