Bug 1380410 - Add NeverAllocPolicy, r=erahm

MozReview-Commit-ID: 8U38Oj3vyaF
This commit is contained in:
Michael Layzell 2017-07-12 14:27:11 -04:00
Родитель a5c3b22cad
Коммит 0969ebe118
1 изменённых файлов: 62 добавлений и 0 удалений

Просмотреть файл

@ -13,6 +13,7 @@
#define mozilla_AllocPolicy_h
#include "mozilla/Attributes.h"
#include "mozilla/Assertions.h"
#include "mozilla/TemplateLib.h"
#include <stddef.h>
@ -128,6 +129,67 @@ public:
}
};
/*
* A policy which always fails to allocate memory, returning nullptr. Methods
* which expect an existing allocation assert.
*
* This type should be used in situations where you want to use a MFBT type with
* inline storage, and don't want to allow it to allocate on the heap.
*/
class NeverAllocPolicy
{
public:
template <typename T>
T* maybe_pod_malloc(size_t aNumElems)
{
return nullptr;
}
template <typename T>
T* maybe_pod_calloc(size_t aNumElems)
{
return nullptr;
}
template <typename T>
T* maybe_pod_realloc(T* aPtr, size_t aOldSize, size_t aNewSize)
{
MOZ_CRASH("NeverAllocPolicy::maybe_pod_realloc");
}
template <typename T>
T* pod_malloc(size_t aNumElems)
{
return nullptr;
}
template <typename T>
T* pod_calloc(size_t aNumElems)
{
return nullptr;
}
template <typename T>
T* pod_realloc(T* aPtr, size_t aOldSize, size_t aNewSize)
{
MOZ_CRASH("NeverAllocPolicy::pod_realloc");
}
void free_(void* aPtr)
{
MOZ_CRASH("NeverAllocPolicy::free_");
}
void reportAllocOverflow() const
{
}
MOZ_MUST_USE bool checkSimulatedOOM() const
{
return true;
}
};
} // namespace mozilla
#endif /* mozilla_AllocPolicy_h */