From c1b6200e80645634706fe6043554547bb8ca7294 Mon Sep 17 00:00:00 2001 From: Mike Hommey Date: Mon, 13 Feb 2012 15:49:45 +0100 Subject: [PATCH] Bug 725230 - Enable and fix assertions in linker code. r=tglek --- mozglue/android/APKOpen.cpp | 10 ++++------ mozglue/linker/ElfLoader.cpp | 1 - mozglue/linker/ElfLoader.h | 4 +--- mozglue/linker/Mappable.cpp | 12 ++++++------ mozglue/linker/Utils.h | 11 ++++++----- mozglue/linker/Zip.h | 2 -- 6 files changed, 17 insertions(+), 23 deletions(-) diff --git a/mozglue/android/APKOpen.cpp b/mozglue/android/APKOpen.cpp index 37a08bb0121..cd59d8809de 100644 --- a/mozglue/android/APKOpen.cpp +++ b/mozglue/android/APKOpen.cpp @@ -81,6 +81,8 @@ enum StartupEvent { #undef mozilla_StartupTimeline_Event }; +using namespace mozilla; + static uint64_t *sStartupTimeline; void StartupTimeline_Record(StartupEvent ev, struct timeval *tm) @@ -651,7 +653,7 @@ loadGeckoLibs(const char *apkName) struct rusage usage1; getrusage(RUSAGE_THREAD, &usage1); - Zip *zip = new Zip(apkName); + RefPtr zip = new Zip(apkName); #ifdef MOZ_CRASHREPORTER file_ids = (char *)extractBuf("lib.id", zip); @@ -682,8 +684,6 @@ loadGeckoLibs(const char *apkName) #undef MOZLOAD #endif - delete zip; - #ifdef MOZ_CRASHREPORTER free(file_ids); file_ids = NULL; @@ -749,7 +749,7 @@ static void loadSQLiteLibs(const char *apkName) apk_mtime = status.st_mtime; #endif - Zip *zip = new Zip(apkName); + RefPtr zip = new Zip(apkName); lib_mapping = (struct mapping_info *)calloc(MAX_MAPPING_INFO, sizeof(*lib_mapping)); #ifdef MOZ_CRASHREPORTER @@ -767,8 +767,6 @@ static void loadSQLiteLibs(const char *apkName) #undef MOZLOAD #endif - delete zip; - #ifdef MOZ_CRASHREPORTER free(file_ids); file_ids = NULL; diff --git a/mozglue/linker/ElfLoader.cpp b/mozglue/linker/ElfLoader.cpp index 78782af432a..c18fd7d478e 100644 --- a/mozglue/linker/ElfLoader.cpp +++ b/mozglue/linker/ElfLoader.cpp @@ -318,7 +318,6 @@ ElfLoader::~ElfLoader() debug("ElfLoader::~ElfLoader(): Remaining handle for \"%s\" " "[%d direct refs, %d refs total]", (*it)->GetPath(), (*it)->DirectRefCount(), (*it)->refCount()); - delete (*it); } else { debug("ElfLoader::~ElfLoader(): Unexpected remaining handle for \"%s\" " "[%d direct refs, %d refs total]", (*it)->GetPath(), diff --git a/mozglue/linker/ElfLoader.h b/mozglue/linker/ElfLoader.h index c234a42a715..d1e8c0d78cd 100644 --- a/mozglue/linker/ElfLoader.h +++ b/mozglue/linker/ElfLoader.h @@ -7,8 +7,6 @@ #include #include -/* Until RefPtr.h stops using JS_Assert */ -#undef DEBUG #include "mozilla/RefPtr.h" #include "Zip.h" @@ -98,7 +96,7 @@ public: { bool ret = false; if (directRefCnt) { - // ASSERT(directRefCnt >= mozilla::RefCounted::refCount()) + MOZ_ASSERT(directRefCnt <= mozilla::RefCounted::refCount()); if (--directRefCnt) ret = true; mozilla::RefCounted::Release(); diff --git a/mozglue/linker/Mappable.cpp b/mozglue/linker/Mappable.cpp index 39634293a11..9ea6b6af9cb 100644 --- a/mozglue/linker/Mappable.cpp +++ b/mozglue/linker/Mappable.cpp @@ -35,8 +35,8 @@ void * MappableFile::mmap(const void *addr, size_t length, int prot, int flags, off_t offset) { - // ASSERT(fd != -1) - // ASSERT(! flags & MAP_SHARED) + MOZ_ASSERT(fd != -1); + MOZ_ASSERT(!(flags & MAP_SHARED)); flags |= MAP_PRIVATE; void *mapped = ::mmap(const_cast(addr), length, prot, flags, @@ -191,7 +191,7 @@ public: void *mmap(const void *addr, size_t length, int prot, int flags, off_t offset) { - // ASSERT(fd != -1) + MOZ_ASSERT(fd != -1); #ifdef ANDROID /* Mapping ashmem MAP_PRIVATE is like mapping anonymous memory, even when * there is content in the ashmem */ @@ -222,7 +222,7 @@ private: MappableDeflate * MappableDeflate::Create(const char *name, Zip *zip, Zip::Stream *stream) { - // ASSERT(stream->GetType() == Zip::Stream::DEFLATE) + MOZ_ASSERT(stream->GetType() == Zip::Stream::DEFLATE); _MappableBuffer *buf = _MappableBuffer::Create(name, stream->GetUncompressedSize()); if (buf) return new MappableDeflate(buf, zip, stream); @@ -238,8 +238,8 @@ MappableDeflate::~MappableDeflate() { } void * MappableDeflate::mmap(const void *addr, size_t length, int prot, int flags, off_t offset) { - // ASSERT(buffer) - // ASSERT(! flags & MAP_SHARED) + MOZ_ASSERT(buffer); + MOZ_ASSERT(!(flags & MAP_SHARED)); flags |= MAP_PRIVATE; /* The deflate stream is uncompressed up to the required offset + length, if diff --git a/mozglue/linker/Utils.h b/mozglue/linker/Utils.h index 7d60f673df5..439843d19b8 100644 --- a/mozglue/linker/Utils.h +++ b/mozglue/linker/Utils.h @@ -9,6 +9,7 @@ #include #include #include +#include "mozilla/Assertions.h" /** * On architectures that are little endian and that support unaligned reads, @@ -280,7 +281,7 @@ public: void Init(const void *buf) { - // ASSERT(operator bool()) + MOZ_ASSERT(contents == NULL); contents = reinterpret_cast(buf); } @@ -289,7 +290,7 @@ public: */ const T &operator[](const idx_t index) const { - // ASSERT(operator bool()) + MOZ_ASSERT(contents); return contents[index]; } @@ -346,7 +347,7 @@ public: void Init(const idx_t len) { - // ASSERT(length != 0) + MOZ_ASSERT(length == 0); length = len; } @@ -372,8 +373,8 @@ public: */ const T &operator[](const idx_t index) const { - // ASSERT(index < length) - // ASSERT(operator bool()) + MOZ_ASSERT(index < length); + MOZ_ASSERT(operator bool()); return UnsizedArray::operator[](index); } diff --git a/mozglue/linker/Zip.h b/mozglue/linker/Zip.h index a9bb465b77f..f85fb7c83f4 100644 --- a/mozglue/linker/Zip.h +++ b/mozglue/linker/Zip.h @@ -10,8 +10,6 @@ #include #include #include "Utils.h" -/* Until RefPtr.h stops using JS_Assert */ -#undef DEBUG #include "mozilla/RefPtr.h" /**