Bug 695843 part 3 - Use mozilla::AutoFDClose instead of ad hoc AutoCloseFD classes. r=bsmedberg
authorMike Hommey <mh+mozilla@glandium.org>
Thu, 08 Dec 2011 11:03:36 +0100
changeset 82245 3032fd2bd96a5afe71c8e73b627c6bc97465bc9d
parent 82244 8e345e9d93e9b2cd2d3cce19f76e33ca38dbcff8
child 82246 692b6b2207b47648b1b4690c2c7134e3c7590632
push id21587
push userbmo@edmorley.co.uk
push dateThu, 08 Dec 2011 15:13:43 +0000
treeherdermozilla-central@98db2311a44c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmedberg
bugs695843
milestone11.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 695843 part 3 - Use mozilla::AutoFDClose instead of ad hoc AutoCloseFD classes. r=bsmedberg
xpcom/components/nsComponentManager.cpp
xpcom/reflect/xptinfo/src/xptiInterfaceInfoManager.cpp
--- a/xpcom/components/nsComponentManager.cpp
+++ b/xpcom/components/nsComponentManager.cpp
@@ -93,16 +93,17 @@
 #include "ManifestParser.h"
 #include "mozilla/Services.h"
 
 #include "nsManifestLineReader.h"
 #include "mozilla/GenericFactory.h"
 #include "nsSupportsPrimitives.h"
 #include "nsArrayEnumerator.h"
 #include "nsStringEnumerator.h"
+#include "mozilla/FileUtils.h"
 
 #include NEW_H     // for placement new
 
 #include "mozilla/Omnijar.h"
 #include "nsJAR.h"
 static NS_DEFINE_CID(kZipReaderCID, NS_ZIPREADER_CID);
 
 #include "prlog.h"
@@ -568,48 +569,24 @@ nsComponentManagerImpl::RegisterJarManif
     }
 
     whole[flen] = '\0';
 
     ParseManifest(aType, aReader, aPath,
                   whole, aChromeOnly);
 }
 
-namespace {
-struct AutoCloseFD
-{
-    AutoCloseFD()
-        : mFD(NULL)
-    { }
-    ~AutoCloseFD() {
-        if (mFD)
-            PR_Close(mFD);
-    }
-    operator PRFileDesc*() {
-        return mFD;
-    }
-
-    PRFileDesc** operator&() {
-        NS_ASSERTION(!mFD, "Re-opening a file");
-        return &mFD;
-    }
-
-    PRFileDesc* mFD;
-};
-
-} // anonymous namespace
-
 void
 nsComponentManagerImpl::RegisterManifestFile(NSLocationType aType,
                                              nsILocalFile* aFile,
                                              bool aChromeOnly)
 {
     nsresult rv;
 
-    AutoCloseFD fd;
+    mozilla::AutoFDClose fd;
     rv = aFile->OpenNSPRFileDesc(PR_RDONLY, 0444, &fd);
     if (NS_FAILED(rv)) {
         nsCAutoString path;
         aFile->GetNativePath(path);
         if (NS_BOOTSTRAPPED_LOCATION != aType)
             LogMessage("Could not read chrome manifest file '%s'.", path.get());
         return;
     }
--- a/xpcom/reflect/xptinfo/src/xptiInterfaceInfoManager.cpp
+++ b/xpcom/reflect/xptinfo/src/xptiInterfaceInfoManager.cpp
@@ -41,16 +41,17 @@
 
 #include "xptiprivate.h"
 #include "nsDependentString.h"
 #include "nsString.h"
 #include "nsISupportsArray.h"
 #include "nsArrayEnumerator.h"
 #include "mozilla/FunctionTimer.h"
 #include "nsDirectoryService.h"
+#include "mozilla/FileUtils.h"
 
 using namespace mozilla;
 
 NS_IMPL_THREADSAFE_ISUPPORTS2(xptiInterfaceInfoManager, 
                               nsIInterfaceInfoManager,
                               nsIInterfaceInfoSuperManager)
 
 static xptiInterfaceInfoManager* gInterfaceInfoManager = nsnull;
@@ -91,45 +92,20 @@ xptiInterfaceInfoManager::~xptiInterface
     mWorkingSet.InvalidateInterfaceInfos();
 
     gInterfaceInfoManager = nsnull;
 #ifdef DEBUG
     gCallCount = 0;
 #endif
 }
 
-namespace {
-
-struct AutoCloseFD
-{
-    AutoCloseFD()
-        : mFD(NULL)
-    { }
-    ~AutoCloseFD() {
-        if (mFD)
-            PR_Close(mFD);
-    }
-    operator PRFileDesc*() {
-        return mFD;
-    }
-
-    PRFileDesc** operator&() {
-        NS_ASSERTION(!mFD, "Re-opening a file");
-        return &mFD;
-    }
-
-    PRFileDesc* mFD;
-};
-
-} // anonymous namespace
-
 XPTHeader* 
 xptiInterfaceInfoManager::ReadXPTFile(nsILocalFile* aFile)
 {
-    AutoCloseFD fd;
+    mozilla::AutoFDClose fd;
     if (NS_FAILED(aFile->OpenNSPRFileDesc(PR_RDONLY, 0444, &fd)) || !fd)
         return NULL;
 
     PRFileInfo64 fileInfo;
     if (PR_SUCCESS != PR_GetOpenFileInfo64(fd, &fileInfo))
         return NULL;
 
     if (fileInfo.size > PRInt64(PR_INT32_MAX))