зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1380410 - Add NeverAllocPolicy, r=erahm
MozReview-Commit-ID: 8U38Oj3vyaF
This commit is contained in:
Родитель
a5c3b22cad
Коммит
0969ebe118
|
@ -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 */
|
||||
|
|
Загрузка…
Ссылка в новой задаче