Bug 953296 - Convert trivial ScopedDelete{Ptr,Array} uses to UniquePtr in mozglue/linker/. (More remain, but they're less trivial to change.) r=glandium

--HG--
extra : rebase_source : 7af7ff2daa70ff3aedaac91d3898bcd90a402162
This commit is contained in:
Jeff Walden 2013-12-30 13:34:54 -06:00
parent 6c2d127725
commit 03e36c69cd
2 changed files with 20 additions and 16 deletions

View File

@ -9,7 +9,11 @@
#include <cstring> #include <cstring>
#include <cstdlib> #include <cstdlib>
#include <cstdio> #include <cstdio>
#include "Mappable.h" #include "Mappable.h"
#include "mozilla/UniquePtr.h"
#ifdef ANDROID #ifdef ANDROID
#include <linux/ashmem.h> #include <linux/ashmem.h>
#endif #endif
@ -63,28 +67,28 @@ MappableExtractFile::Create(const char *name, Zip *zip, Zip::Stream *stream)
"not extracting"); "not extracting");
return nullptr; return nullptr;
} }
mozilla::ScopedDeleteArray<char> path; mozilla::UniquePtr<char[]> path;
path = new char[strlen(cachePath) + strlen(name) + 2]; path.reset(new char[strlen(cachePath) + strlen(name) + 2]);
sprintf(path, "%s/%s", cachePath, name); sprintf(path.get(), "%s/%s", cachePath, name);
struct stat cacheStat; struct stat cacheStat;
if (stat(path, &cacheStat) == 0) { if (stat(path.get(), &cacheStat) == 0) {
struct stat zipStat; struct stat zipStat;
stat(zip->GetName(), &zipStat); stat(zip->GetName(), &zipStat);
if (cacheStat.st_mtime > zipStat.st_mtime) { if (cacheStat.st_mtime > zipStat.st_mtime) {
DEBUG_LOG("Reusing %s", static_cast<char *>(path)); DEBUG_LOG("Reusing %s", static_cast<char *>(path.get()));
return MappableFile::Create(path); return MappableFile::Create(path.get());
} }
} }
DEBUG_LOG("Extracting to %s", static_cast<char *>(path)); DEBUG_LOG("Extracting to %s", static_cast<char *>(path.get()));
AutoCloseFD fd; AutoCloseFD fd;
fd = open(path, O_TRUNC | O_RDWR | O_CREAT | O_NOATIME, fd = open(path.get(), O_TRUNC | O_RDWR | O_CREAT | O_NOATIME,
S_IRUSR | S_IWUSR); S_IRUSR | S_IWUSR);
if (fd == -1) { if (fd == -1) {
ERROR("Couldn't open %s to decompress library", path.get()); ERROR("Couldn't open %s to decompress library", path.get());
return nullptr; return nullptr;
} }
AutoUnlinkFile file; AutoUnlinkFile file;
file = path.forget(); file = path.release();
if (stream->GetType() == Zip::Stream::DEFLATE) { if (stream->GetType() == Zip::Stream::DEFLATE) {
if (ftruncate(fd, stream->GetUncompressedSize()) == -1) { if (ftruncate(fd, stream->GetUncompressedSize()) == -1) {
ERROR("Couldn't ftruncate %s to decompress library", file.get()); ERROR("Couldn't ftruncate %s to decompress library", file.get());
@ -575,8 +579,7 @@ MappableSeekableZStream::stats(const char *when, const char *name) const
name, when, static_cast<size_t>(chunkAvailNum), nEntries); name, when, static_cast<size_t>(chunkAvailNum), nEntries);
size_t len = 64; size_t len = 64;
mozilla::ScopedDeleteArray<char> map; mozilla::UniquePtr<char[]> map(new char[len + 3]);
map = new char[len + 3];
map[0] = '['; map[0] = '[';
for (size_t i = 0, j = 1; i < nEntries; i++, j++) { for (size_t i = 0, j = 1; i < nEntries; i++, j++) {
@ -584,7 +587,7 @@ MappableSeekableZStream::stats(const char *when, const char *name) const
if ((j == len) || (i == nEntries - 1)) { if ((j == len) || (i == nEntries - 1)) {
map[j + 1] = ']'; map[j + 1] = ']';
map[j + 2] = '\0'; map[j + 2] = '\0';
DEBUG_LOG("%s", static_cast<char *>(map)); DEBUG_LOG("%s", static_cast<char *>(map.get()));
j = 0; j = 0;
} }
} }

View File

@ -14,6 +14,7 @@
#include <errno.h> #include <errno.h>
#include "mozilla/Assertions.h" #include "mozilla/Assertions.h"
#include "mozilla/Scoped.h" #include "mozilla/Scoped.h"
#include "mozilla/UniquePtr.h"
#include "SeekableZStream.h" #include "SeekableZStream.h"
#include "Utils.h" #include "Utils.h"
#include "Logging.h" #include "Logging.h"
@ -466,7 +467,7 @@ bool GetSize(const char *str, size_t *out)
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
mozilla::ScopedDeletePtr<SzipAction> action; mozilla::UniquePtr<SzipAction> action;
char **firstArg; char **firstArg;
bool compress = true; bool compress = true;
size_t chunkSize = 0; size_t chunkSize = 0;
@ -528,7 +529,7 @@ int main(int argc, char* argv[])
} }
if (compress) { if (compress) {
action = new SzipCompress(chunkSize, filter, dictSize); action.reset(new SzipCompress(chunkSize, filter, dictSize));
} else { } else {
if (chunkSize) { if (chunkSize) {
ERROR("-c is incompatible with -d"); ERROR("-c is incompatible with -d");
@ -538,7 +539,7 @@ int main(int argc, char* argv[])
ERROR("-D is incompatible with -d"); ERROR("-D is incompatible with -d");
return 1; return 1;
} }
action = new SzipDecompress(); action.reset(new SzipDecompress());
} }
std::stringstream tmpOutStream; std::stringstream tmpOutStream;