Backout f3b6bc4b2590 (Bug 827749) for test failures.
authorBen Turner <bent.mozilla@gmail.com>
Thu, 10 Jan 2013 13:54:27 +0100
changeset 118380 e06f05ff1edc89552802f997c30075a3c088d4c2
parent 118379 9a93bc7b059bf7f97ccb412cea5f04e5c8415f1d
child 118381 da9cd7ac8713d0f2d0560a90de8691420f3313b1
push id24166
push userMs2ger@gmail.com
push dateFri, 11 Jan 2013 13:57:41 +0000
treeherdermozilla-central@63c4b0f66a0c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs827749
milestone21.0a1
backs outf3b6bc4b25904d62588fd33ba347741872b7fc2d
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
Backout f3b6bc4b2590 (Bug 827749) for test failures.
ipc/glue/FileDescriptor.cpp
ipc/glue/FileDescriptor.h
--- a/ipc/glue/FileDescriptor.cpp
+++ b/ipc/glue/FileDescriptor.cpp
@@ -3,103 +3,60 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "FileDescriptor.h"
 
 #include "mozilla/Assertions.h"
 #include "nsDebug.h"
 
 #ifdef XP_WIN
-
 #include <windows.h>
 #define INVALID_HANDLE INVALID_HANDLE_VALUE
-
-#else // XP_WIN
-
+#else
 #include <unistd.h>
-
-#ifndef OS_POSIX
-#define OS_POSIX
+#define INVALID_HANDLE -1
 #endif
 
-#include "base/eintr_wrapper.h"
-#define INVALID_HANDLE -1
-
-#endif // XP_WIN
-
 using mozilla::ipc::FileDescriptor;
 
 FileDescriptor::FileDescriptor()
-: mHandle(INVALID_HANDLE), mMustCloseHandle(false)
+: mHandle(INVALID_HANDLE)
 { }
 
-FileDescriptor::FileDescriptor(PlatformHandleType aHandle)
-: mHandle(INVALID_HANDLE), mMustCloseHandle(false)
-{
-  DuplicateInCurrentProcess(aHandle);
-}
-
-FileDescriptor::~FileDescriptor()
-{
-  if (mMustCloseHandle) {
-    MOZ_ASSERT(mHandle != INVALID_HANDLE);
-#ifdef XP_WIN
-    if (!CloseHandle(mHandle)) {
-      NS_WARNING("Failed to close file handle!");
-    }
-#else // XP_WIN
-    HANDLE_EINTR(close(mHandle));
-#endif
-  }
-}
-
-void
-FileDescriptor::DuplicateInCurrentProcess(PlatformHandleType aHandle)
-{
-  if (aHandle != INVALID_HANDLE) {
-    PlatformHandleType newHandle;
-#ifdef XP_WIN
-    if (DuplicateHandle(GetCurrentProcess(), aHandle, GetCurrentProcess(),
-                        &newHandle, 0, FALSE, DUPLICATE_SAME_ACCESS)) {
-#else // XP_WIN
-    if ((newHandle = dup(aHandle)) != INVALID_HANDLE) {
-#endif
-      mHandle = newHandle;
-      mMustCloseHandle = true;
-      return;
-    }
-    NS_WARNING("Failed to duplicate file descriptor!");
-  }
-
-  mHandle = INVALID_HANDLE;
-  mMustCloseHandle = false;
-}
-
 FileDescriptor::PickleType
 FileDescriptor::ShareTo(const FileDescriptor::IPDLPrivate&,
                         FileDescriptor::ProcessHandle aOtherProcess) const
 {
+#ifdef XP_WIN
+  if (mHandle == INVALID_HANDLE) {
+    return INVALID_HANDLE;
+  }
+
   PlatformHandleType newHandle;
-#ifdef XP_WIN
-  if (mHandle != INVALID_HANDLE) {
-    if (DuplicateHandle(GetCurrentProcess(), mHandle, aOtherProcess,
-                        &newHandle, 0, FALSE, DUPLICATE_SAME_ACCESS)) {
-      // mHandle must still be closed here (since it is an in-process handle
-      // that we duplicated) so leave mMustCloseHandle unchanged.
-      return newHandle;
-    }
+  if (!DuplicateHandle(GetCurrentProcess(), mHandle, aOtherProcess, &newHandle,
+                       0, FALSE, DUPLICATE_SAME_ACCESS)) {
     NS_WARNING("Failed to duplicate file handle!");
+    return INVALID_HANDLE;
   }
-  return INVALID_HANDLE;
+
+  return newHandle;
 #else // XP_WIN
-  if (mHandle != INVALID_HANDLE) {
-    newHandle = dup(mHandle);
-    return base::FileDescriptor(newHandle, /* auto_close */ true);
+  if (mHandle == INVALID_HANDLE) {
+    return base::FileDescriptor();
   }
-  return base::FileDescriptor();
+
+  PlatformHandleType newHandle = dup(mHandle);
+  if (newHandle < 0) {
+    NS_WARNING("Failed to duplicate file descriptor!");
+    return base::FileDescriptor();
+  }
+
+  // This file descriptor must be closed once the caller is done using it, so
+  // pass true here for the 'auto_close' argument.
+  return base::FileDescriptor(newHandle, true);
 #endif
 
   MOZ_NOT_REACHED("Must not get here!");
   return PickleType();
 }
 
 bool
 FileDescriptor::IsValid() const
--- a/ipc/glue/FileDescriptor.h
+++ b/ipc/glue/FileDescriptor.h
@@ -45,40 +45,28 @@ public:
 #endif
 
   // This should only ever be created by IPDL.
   struct IPDLPrivate
   {};
 
   FileDescriptor();
 
-  FileDescriptor(const FileDescriptor& aOther)
-  {
-    *this = aOther;
-  }
-
-  FileDescriptor(PlatformHandleType aHandle);
+  FileDescriptor(PlatformHandleType aHandle)
+  : mHandle(aHandle)
+  { }
 
   FileDescriptor(const IPDLPrivate&, const PickleType& aPickle)
 #ifdef XP_WIN
-  : mHandle(aPickle), mMustCloseHandle(false)
+  : mHandle(aPickle)
 #else
-  : mHandle(aPickle.fd), mMustCloseHandle(false)
+  : mHandle(aPickle.fd)
 #endif
   { }
 
-  ~FileDescriptor();
-
-  FileDescriptor&
-  operator=(const FileDescriptor& aOther)
-  {
-    DuplicateInCurrentProcess(aOther.mHandle);
-    return *this;
-  }
-
   // Performs platform-specific actions to duplicate mHandle in the other
   // process (e.g. dup() on POSIX, DuplicateHandle() on Windows). Returns a
   // pickled value that can be passed to the other process via IPC.
   PickleType
   ShareTo(const IPDLPrivate&, ProcessHandle aOtherProcess) const;
 
   // Tests mHandle against a well-known invalid platform-specific file handle
   // (e.g. -1 on POSIX, INVALID_HANDLE_VALUE on Windows).
@@ -93,19 +81,15 @@ public:
 
   bool
   operator==(const FileDescriptor& aOther) const
   {
     return mHandle == aOther.mHandle;
   }
 
 private:
-  void
-  DuplicateInCurrentProcess(PlatformHandleType aHandle);
-
   PlatformHandleType mHandle;
-  bool mMustCloseHandle;
 };
 
 } // namespace ipc
 } // namespace mozilla
 
 #endif // mozilla_ipc_FileDescriptor_h