summaryrefslogtreecommitdiffstats
path: root/js/src/ds/LifoAlloc.h
diff options
context:
space:
mode:
authorMoonchild <mcwerewolf@gmail.com>2018-09-10 23:42:44 +0200
committerGitHub <noreply@github.com>2018-09-10 23:42:44 +0200
commit7bf3d2440e8ff65763daedca51aad6d0288ef61d (patch)
tree2c2bd6aa515c5d6eb33cabb24cc9299584b6b93e /js/src/ds/LifoAlloc.h
parent2e9c525a91b66038dafcc2ef97dd436164ab65f6 (diff)
parent47c5bba17a1049ca69e01981aebe858fb50c8d69 (diff)
downloadUXP-7bf3d2440e8ff65763daedca51aad6d0288ef61d.tar
UXP-7bf3d2440e8ff65763daedca51aad6d0288ef61d.tar.gz
UXP-7bf3d2440e8ff65763daedca51aad6d0288ef61d.tar.lz
UXP-7bf3d2440e8ff65763daedca51aad6d0288ef61d.tar.xz
UXP-7bf3d2440e8ff65763daedca51aad6d0288ef61d.zip
Merge pull request #754 from trav90/class-memaccess-errors
Fix more -Wclass-memaccess warnings (GCC8)
Diffstat (limited to 'js/src/ds/LifoAlloc.h')
-rw-r--r--js/src/ds/LifoAlloc.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/js/src/ds/LifoAlloc.h b/js/src/ds/LifoAlloc.h
index f349cd476..b4e9c3418 100644
--- a/js/src/ds/LifoAlloc.h
+++ b/js/src/ds/LifoAlloc.h
@@ -15,6 +15,8 @@
#include "mozilla/TemplateLib.h"
#include "mozilla/TypeTraits.h"
+#include <new>
+
// This data structure supports stacky LIFO allocation (mark/release and
// LifoAllocScope). It does not maintain one contiguous segment; instead, it
// maintains a bunch of linked memory segments. In order to prevent malloc/free
@@ -285,6 +287,20 @@ class LifoAlloc
return allocImpl(n);
}
+ template<typename T, typename... Args>
+ MOZ_ALWAYS_INLINE T*
+ allocInSize(size_t n, Args&&... args)
+ {
+ MOZ_ASSERT(n >= sizeof(T), "must request enough space to store a T");
+ static_assert(alignof(T) <= detail::LIFO_ALLOC_ALIGN,
+ "LifoAlloc must provide enough alignment to store T");
+ void* ptr = alloc(n);
+ if (!ptr)
+ return nullptr;
+
+ return new (ptr) T(mozilla::Forward<Args>(args)...);
+ }
+
MOZ_ALWAYS_INLINE
void* allocInfallible(size_t n) {
AutoEnterOOMUnsafeRegion oomUnsafe;