Bug 1423107 - Replace uses of moz_posix_memalign with posix_memalign. r?njn draft
authorMike Hommey <mh+mozilla@glandium.org>
Tue, 05 Dec 2017 16:46:17 +0900
changeset 707448 b79c229c7303defdfffa44f2637913beca2dc7a6
parent 707235 e19b017880c8d71385aed453bacbe2b473757e90
child 707449 d05b814789dd8ca69d902b55d86935a3a0895e17
push id92107
push userbmo:mh+mozilla@glandium.org
push dateTue, 05 Dec 2017 07:55:10 +0000
reviewersnjn
bugs1423107, 414946
milestone59.0a1
Bug 1423107 - Replace uses of moz_posix_memalign with posix_memalign. r?njn moz_posix_memalign is a wrapper for posix_memalign that only exists if posix_memalign exists. On OSX, it has a fallback for an under-specified bug where it purportedly returns a pointer that doesn't have the requested alignment. That fallback was added in bug 414946, over 6 years ago, before jemalloc was even enabled on OSX. Considering posix_memalign is used directly in many other places in Gecko, that we almost always use mozjemalloc, which doesn't have these problems, and that in all likeliness, the bug was in some old version of OSX that is not supported anymore, the fallback does not seem all that useful. So, just use posix_memalign directly.
gfx/thebes/gfxImageSurface.cpp
memory/volatile/VolatileBufferFallback.cpp
memory/volatile/VolatileBufferOSX.cpp
--- a/gfx/thebes/gfxImageSurface.cpp
+++ b/gfx/thebes/gfxImageSurface.cpp
@@ -91,19 +91,19 @@ gfxImageSurface::InitWithData(unsigned c
 static void*
 TryAllocAlignedBytes(size_t aSize)
 {
     // Use fallible allocators here
 #if defined(HAVE_POSIX_MEMALIGN)
     void* ptr;
     // Try to align for fast alpha recovery.  This should only help
     // cairo too, can't hurt.
-    return moz_posix_memalign(&ptr,
-                              1 << gfxAlphaRecovery::GoodAlignmentLog2(),
-                              aSize) ?
+    return posix_memalign(&ptr,
+                          1 << gfxAlphaRecovery::GoodAlignmentLog2(),
+                          aSize) ?
              nullptr : ptr;
 #else
     // Oh well, hope that luck is with us in the allocator
     return malloc(aSize);
 #endif
 }
 
 gfxImageSurface::gfxImageSurface(const IntSize& size, gfxImageFormat format, bool aClear)
--- a/memory/volatile/VolatileBufferFallback.cpp
+++ b/memory/volatile/VolatileBufferFallback.cpp
@@ -22,24 +22,20 @@ VolatileBuffer::VolatileBuffer()
 
 bool VolatileBuffer::Init(size_t aSize, size_t aAlignment)
 {
   MOZ_ASSERT(!mSize && !mBuf, "Init called twice");
   MOZ_ASSERT(!(aAlignment % sizeof(void *)),
              "Alignment must be multiple of pointer size");
 
   mSize = aSize;
-#if defined(MOZ_MEMORY)
+#if defined(MOZ_MEMORY) || defined(HAVE_POSIX_MEMALIGN)
   if (posix_memalign(&mBuf, aAlignment, aSize) != 0) {
     return false;
   }
-#elif defined(HAVE_POSIX_MEMALIGN)
-  if (moz_posix_memalign(&mBuf, aAlignment, aSize) != 0) {
-    return false;
-  }
 #else
 #error "No memalign implementation found"
 #endif
   return !!mBuf;
 }
 
 VolatileBuffer::~VolatileBuffer()
 {
--- a/memory/volatile/VolatileBufferOSX.cpp
+++ b/memory/volatile/VolatileBufferOSX.cpp
@@ -42,17 +42,17 @@ VolatileBuffer::Init(size_t aSize, size_
                     (vm_address_t*)&mBuf,
                     mSize,
                     VM_FLAGS_PURGABLE | VM_FLAGS_ANYWHERE);
   if (ret == KERN_SUCCESS) {
     return true;
   }
 
 heap_alloc:
-  (void)moz_posix_memalign(&mBuf, aAlignment, aSize);
+  (void)posix_memalign(&mBuf, aAlignment, aSize);
   mHeap = true;
   return !!mBuf;
 }
 
 VolatileBuffer::~VolatileBuffer()
 {
   MOZ_ASSERT(mLockCount == 0, "Being destroyed with non-zero lock count?");