Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Unified Diff: Source/wtf/FastMalloc.h

Issue 22038002: Get rid of the tryFast*alloc API. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Review item. Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/wtf/FastAllocBase.h ('k') | Source/wtf/FastMalloc.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/wtf/FastMalloc.h
diff --git a/Source/wtf/FastMalloc.h b/Source/wtf/FastMalloc.h
index c03e05e5e91753595160d81ff8adceeeed27ae2d..1e05db286730fc68afcde6c9679c1872317f96e4 100644
--- a/Source/wtf/FastMalloc.h
+++ b/Source/wtf/FastMalloc.h
@@ -21,16 +21,12 @@
#ifndef WTF_FastMalloc_h
#define WTF_FastMalloc_h
-#include <new>
-#include <stdlib.h>
-
-#include "wtf/Platform.h"
-#include "wtf/PossiblyNull.h"
#include "wtf/WTFExport.h"
+#include <cstddef>
namespace WTF {
- // These functions call CRASH() if an allocation fails.
+ // These functions crash safely if an allocation fails.
WTF_EXPORT void* fastMalloc(size_t);
WTF_EXPORT void* fastZeroedMalloc(size_t);
WTF_EXPORT void* fastCalloc(size_t numElements, size_t elementSize);
@@ -38,43 +34,6 @@ namespace WTF {
WTF_EXPORT char* fastStrDup(const char*);
WTF_EXPORT size_t fastMallocGoodSize(size_t);
- struct TryMallocReturnValue {
- TryMallocReturnValue(void* data)
- : m_data(data)
- {
- }
- TryMallocReturnValue(const TryMallocReturnValue& source)
- : m_data(source.m_data)
- {
- source.m_data = 0;
- }
- ~TryMallocReturnValue() { ASSERT(!m_data); }
- template <typename T> bool getValue(T& data) WARN_UNUSED_RETURN;
- template <typename T> operator PossiblyNull<T>()
- {
- T value;
- getValue(value);
- return PossiblyNull<T>(value);
- }
- private:
- mutable void* m_data;
- };
-
- template <typename T> bool TryMallocReturnValue::getValue(T& data)
- {
- union u { void* data; T target; } res;
- res.data = m_data;
- data = res.target;
- bool returnValue = !!m_data;
- m_data = 0;
- return returnValue;
- }
-
- WTF_EXPORT TryMallocReturnValue tryFastMalloc(size_t n);
- WTF_EXPORT TryMallocReturnValue tryFastZeroedMalloc(size_t n);
- WTF_EXPORT TryMallocReturnValue tryFastCalloc(size_t n_elements, size_t element_size);
- WTF_EXPORT TryMallocReturnValue tryFastRealloc(void* p, size_t n);
-
WTF_EXPORT void fastFree(void*);
#ifndef NDEBUG
@@ -95,131 +54,6 @@ namespace WTF {
// size as the minimally aligned memory allocation.
typedef unsigned long long AllocAlignmentInteger;
- namespace Internal {
- enum AllocType { // Start with an unusual number instead of zero, because zero is common.
- AllocTypeMalloc = 0x375d6750, // Encompasses fastMalloc, fastZeroedMalloc, fastCalloc, fastRealloc.
- AllocTypeClassNew, // Encompasses class operator new from FastAllocBase.
- AllocTypeClassNewArray, // Encompasses class operator new[] from FastAllocBase.
- AllocTypeFastNew, // Encompasses fastNew.
- AllocTypeFastNewArray, // Encompasses fastNewArray.
- AllocTypeNew, // Encompasses global operator new.
- AllocTypeNewArray // Encompasses global operator new[].
- };
-
- enum {
- ValidationPrefix = 0xf00df00d,
- ValidationSuffix = 0x0badf00d
- };
-
- typedef unsigned ValidationTag;
-
- struct ValidationHeader {
- AllocType m_type;
- unsigned m_size;
- ValidationTag m_prefix;
- unsigned m_alignment;
- };
-
- static const int ValidationBufferSize = sizeof(ValidationHeader) + sizeof(ValidationTag);
- }
-
-#if ENABLE(WTF_MALLOC_VALIDATION)
-
- // Malloc validation is a scheme whereby a tag is attached to an
- // allocation which identifies how it was originally allocated.
- // This allows us to verify that the freeing operation matches the
- // allocation operation. If memory is allocated with operator new[]
- // but freed with free or delete, this system would detect that.
- // In the implementation here, the tag is an integer prepended to
- // the allocation memory which is assigned one of the AllocType
- // enumeration values. An alternative implementation of this
- // scheme could store the tag somewhere else or ignore it.
- // Users of FastMalloc don't need to know or care how this tagging
- // is implemented.
-
- namespace Internal {
-
- // Handle a detected alloc/free mismatch. By default this calls CRASH().
- void fastMallocMatchFailed(void* p);
-
- inline ValidationHeader* fastMallocValidationHeader(void* p)
- {
- return reinterpret_cast<ValidationHeader*>(static_cast<char*>(p) - sizeof(ValidationHeader));
- }
-
- inline ValidationTag* fastMallocValidationSuffix(void* p)
- {
- ValidationHeader* header = fastMallocValidationHeader(p);
- if (header->m_prefix != static_cast<unsigned>(ValidationPrefix))
- fastMallocMatchFailed(p);
-
- return reinterpret_cast<ValidationTag*>(static_cast<char*>(p) + header->m_size);
- }
-
- // Return the AllocType tag associated with the allocated block p.
- inline AllocType fastMallocMatchValidationType(void* p)
- {
- return fastMallocValidationHeader(p)->m_type;
- }
-
- // Set the AllocType tag to be associaged with the allocated block p.
- inline void setFastMallocMatchValidationType(void* p, AllocType allocType)
- {
- fastMallocValidationHeader(p)->m_type = allocType;
- }
-
- } // namespace Internal
-
- // This is a higher level function which is used by FastMalloc-using code.
- inline void fastMallocMatchValidateMalloc(void* p, Internal::AllocType allocType)
- {
- if (!p)
- return;
-
- Internal::setFastMallocMatchValidationType(p, allocType);
- }
-
- // This is a higher level function which is used by FastMalloc-using code.
- inline void fastMallocMatchValidateFree(void* p, Internal::AllocType)
- {
- if (!p)
- return;
-
- Internal::ValidationHeader* header = Internal::fastMallocValidationHeader(p);
- if (header->m_prefix != static_cast<unsigned>(Internal::ValidationPrefix))
- Internal::fastMallocMatchFailed(p);
-
- if (*Internal::fastMallocValidationSuffix(p) != Internal::ValidationSuffix)
- Internal::fastMallocMatchFailed(p);
-
- Internal::setFastMallocMatchValidationType(p, Internal::AllocTypeMalloc); // Set it to this so that fastFree thinks it's OK.
- }
-
- inline void fastMallocValidate(void* p)
- {
- if (!p)
- return;
-
- Internal::ValidationHeader* header = Internal::fastMallocValidationHeader(p);
- if (header->m_prefix != static_cast<unsigned>(Internal::ValidationPrefix))
- Internal::fastMallocMatchFailed(p);
-
- if (*Internal::fastMallocValidationSuffix(p) != Internal::ValidationSuffix)
- Internal::fastMallocMatchFailed(p);
- }
-
-#else
-
- inline void fastMallocMatchValidateMalloc(void*, Internal::AllocType)
- {
- }
-
- inline void fastMallocMatchValidateFree(void*, Internal::AllocType)
- {
- }
-
-#endif
-
} // namespace WTF
using WTF::fastCalloc;
@@ -229,10 +63,6 @@ using WTF::fastMallocGoodSize;
using WTF::fastRealloc;
using WTF::fastStrDup;
using WTF::fastZeroedMalloc;
-using WTF::tryFastCalloc;
-using WTF::tryFastMalloc;
-using WTF::tryFastRealloc;
-using WTF::tryFastZeroedMalloc;
#ifndef NDEBUG
using WTF::fastMallocForbid;
« no previous file with comments | « Source/wtf/FastAllocBase.h ('k') | Source/wtf/FastMalloc.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698