diff options
author | Tom Sepez <tsepez@chromium.org> | 2015-04-14 12:54:38 -0700 |
---|---|---|
committer | Tom Sepez <tsepez@chromium.org> | 2015-04-14 12:54:38 -0700 |
commit | 4926900ab54a493d236291b5a24dfa4476792182 (patch) | |
tree | e53800a0569300516c934bfccbb036ce39d98cb3 /core/include/fxcrt | |
parent | eddab4425614e49146f904f00da4a664ba4b581b (diff) | |
download | pdfium-4926900ab54a493d236291b5a24dfa4476792182.tar.xz |
Kill CFX_Object.
CFX_Object is a type that implements its own new operators that return
NULL on error. There's no need for this given the |new (std::nothrow)|
syntax; in fact, the current code can only work if there is no activity
in the constructors. This may explain the pervasive lack of
constructors and reliance on Init() methods throughout the codebase.
The activity takes place in fx_memory.h, where FX_NEW is mapped onto
the std::nothrow syntax. The rest is just cleanup.
Down the road, we will simply throw and remove all the error-checking
paths for new objects. Landing this patch first will at least show a
simple path back to the old behaviour without having to re-introduce
CFX_Object should someone want to do so in their own fork.
R=thestig@chromium.org
Review URL: https://codereview.chromium.org/1088733002
Diffstat (limited to 'core/include/fxcrt')
-rw-r--r-- | core/include/fxcrt/fx_basic.h | 38 | ||||
-rw-r--r-- | core/include/fxcrt/fx_coordinates.h | 8 | ||||
-rw-r--r-- | core/include/fxcrt/fx_memory.h | 71 | ||||
-rw-r--r-- | core/include/fxcrt/fx_string.h | 10 | ||||
-rw-r--r-- | core/include/fxcrt/fx_xml.h | 8 |
5 files changed, 39 insertions, 96 deletions
diff --git a/core/include/fxcrt/fx_basic.h b/core/include/fxcrt/fx_basic.h index 45a5a6e23c..7b700d36a8 100644 --- a/core/include/fxcrt/fx_basic.h +++ b/core/include/fxcrt/fx_basic.h @@ -27,7 +27,7 @@ template <typename T, size_t N> char (&ArraySizeHelper(T (&array)[N]))[N]; -class CFX_BinaryBuf : public CFX_Object +class CFX_BinaryBuf { public: CFX_BinaryBuf(); @@ -155,7 +155,7 @@ public: CFX_WideStringC GetWideString() const; }; -class CFX_ArchiveSaver : public CFX_Object +class CFX_ArchiveSaver { public: CFX_ArchiveSaver() : m_pStream(NULL) {} @@ -198,7 +198,7 @@ protected: IFX_FileStream* m_pStream; }; -class CFX_ArchiveLoader : public CFX_Object +class CFX_ArchiveLoader { public: @@ -260,7 +260,7 @@ protected: FX_STRSIZE m_Length; }; -class CFX_FileBufferArchive : public IFX_BufferArchive, public CFX_Object +class CFX_FileBufferArchive : public IFX_BufferArchive { public: CFX_FileBufferArchive(FX_STRSIZE size = 32768); @@ -352,7 +352,7 @@ CFX_ByteString FX_UrlEncode(const CFX_WideString& wsUrl); CFX_WideString FX_UrlDecode(const CFX_ByteString& bsUrl); CFX_ByteString FX_EncodeURI(const CFX_WideString& wsURI); CFX_WideString FX_DecodeURI(const CFX_ByteString& bsURI); -class CFX_BasicArray : public CFX_Object +class CFX_BasicArray { protected: CFX_BasicArray(int unit_size); @@ -665,7 +665,7 @@ public: }; typedef CFX_ObjectArray<CFX_ByteString> CFX_ByteStringArray; typedef CFX_ObjectArray<CFX_WideString> CFX_WideStringArray; -class CFX_BaseSegmentedArray : public CFX_Object +class CFX_BaseSegmentedArray { public: CFX_BaseSegmentedArray(int unit_size = 1, int segment_units = 512, int index_size = 8); @@ -734,7 +734,7 @@ public: } }; template <class DataType, int FixedSize> -class CFX_FixedBufGrow : public CFX_Object +class CFX_FixedBufGrow { public: CFX_FixedBufGrow() : m_pData(NULL) @@ -799,7 +799,7 @@ public: private: DataType* m_pData; }; -class CFX_MapPtrToPtr : public CFX_Object +class CFX_MapPtrToPtr { protected: @@ -916,7 +916,7 @@ public: rValue = (ValueType)(FX_UINTPTR)pValue; } }; -class CFX_CMapDWordToDWord : public CFX_Object +class CFX_CMapDWordToDWord { public: @@ -933,7 +933,7 @@ protected: CFX_BinaryBuf m_Buffer; }; -class CFX_MapByteStringToPtr : public CFX_Object +class CFX_MapByteStringToPtr { protected: @@ -1013,7 +1013,7 @@ public: ~CFX_MapByteStringToPtr(); }; -class CFX_CMapByteStringToPtr : public CFX_Object +class CFX_CMapByteStringToPtr { public: CFX_CMapByteStringToPtr(); @@ -1041,7 +1041,7 @@ private: CFX_BaseSegmentedArray m_Buffer; }; -class CFX_PtrList : public CFX_Object +class CFX_PtrList { protected: @@ -1190,7 +1190,7 @@ protected: void AddData(FX_LPVOID module_id, FX_LPVOID pData, PD_CALLBACK_FREEDATA callback, FX_BOOL bSelfDestruct); }; -class CFX_BitStream : public CFX_Object +class CFX_BitStream { public: @@ -1223,7 +1223,7 @@ protected: FX_LPCBYTE m_pData; }; -template <class ObjClass> class CFX_CountRef : public CFX_Object +template <class ObjClass> class CFX_CountRef { public: @@ -1373,7 +1373,7 @@ public: virtual ~IFX_Pause() { } virtual FX_BOOL NeedToPauseNow() = 0; }; -class CFX_DataFilter : public CFX_Object +class CFX_DataFilter { public: @@ -1448,7 +1448,7 @@ protected: }; #define FX_DATALIST_LENGTH 1024 template<size_t unit> -class CFX_SortListArray : public CFX_Object +class CFX_SortListArray { protected: @@ -1562,7 +1562,7 @@ protected: CFX_ArrayTemplate<DataList> m_DataLists; }; template<typename T1, typename T2> -class CFX_ListArrayTemplate : public CFX_Object +class CFX_ListArrayTemplate { public: @@ -1603,7 +1603,7 @@ typedef enum { #define ProgressiveStatus FX_ProgressiveStatus #define FX_NAMESPACE_DECLARE(namespace, type) namespace::type -class CFX_Vector_3by1 : public CFX_Object +class CFX_Vector_3by1 { public: @@ -1619,7 +1619,7 @@ public: FX_FLOAT b; FX_FLOAT c; }; -class CFX_Matrix_3by3 : public CFX_Object +class CFX_Matrix_3by3 { public: diff --git a/core/include/fxcrt/fx_coordinates.h b/core/include/fxcrt/fx_coordinates.h index 0b4b920195..758d33762e 100644 --- a/core/include/fxcrt/fx_coordinates.h +++ b/core/include/fxcrt/fx_coordinates.h @@ -18,7 +18,7 @@ template<class baseType> class CFX_ATemplate; template<class baseType> class CFX_RRTemplate; class CFX_Matrix; template<class baseType> -class CFX_PSVTemplate : public CFX_Object +class CFX_PSVTemplate { public: typedef CFX_PSVTemplate<baseType> FXT_PSV; @@ -230,7 +230,7 @@ public: typedef CFX_VTemplate<FX_INT32> CFX_Vector; typedef CFX_VTemplate<FX_FLOAT> CFX_VectorF; template<class baseType> -class CFX_RTemplate: public CFX_Object +class CFX_RTemplate { public: typedef CFX_PSVTemplate<baseType> FXT_POINT; @@ -610,7 +610,7 @@ struct FX_SMALL_RECT { FX_SHORT Bottom; }; -class CFX_FloatRect : public CFX_Object +class CFX_FloatRect { public: @@ -749,7 +749,7 @@ public: FX_FLOAT top; }; -class CFX_Matrix : public CFX_Object +class CFX_Matrix { public: diff --git a/core/include/fxcrt/fx_memory.h b/core/include/fxcrt/fx_memory.h index 15dc7da8cf..7884d6b11d 100644 --- a/core/include/fxcrt/fx_memory.h +++ b/core/include/fxcrt/fx_memory.h @@ -10,6 +10,7 @@ #include "fx_system.h" #ifdef __cplusplus +#include <new> extern "C" { #endif #define FX_Alloc(type, size) (type*)calloc(size, sizeof(type)) @@ -22,76 +23,18 @@ void* FXMEM_DefaultRealloc(void* pointer, size_t new_size, int flags); void FXMEM_DefaultFree(void* pointer, int flags); #ifdef __cplusplus } -#endif -#ifdef __cplusplus -class CFX_Object -{ -public: - void* operator new (size_t size, FX_LPCSTR file, int line) - { - return malloc(size); - } - void operator delete (void* p, FX_LPCSTR file, int line) - { - free(p); - } - void* operator new (size_t size) - { - return malloc(size); - } - void operator delete (void* p) - { - free(p); - } - void* operator new[] (size_t size, FX_LPCSTR file, int line) - { - return malloc(size); - } - void operator delete[] (void* p, FX_LPCSTR file, int line) - { - free(p); - } - void* operator new[] (size_t size) - { - return malloc(size); - } - void operator delete[] (void* p) - { - free(p); - } - void* operator new (size_t, void* buf) - { - return buf; - } - void operator delete (void*, void*) {} -}; -#endif -#ifdef __cplusplus -#if defined(_DEBUG) -#define FX_NEW new(__FILE__, __LINE__) -#else -#define FX_NEW new -#endif -#define FX_NEW_VECTOR(Pointer, Class, Count) \ - { \ - Pointer = FX_Alloc(Class, Count); \ - if (Pointer) { \ - for (int i = 0; i < (Count); i ++) new (Pointer + i) Class; \ - } \ - } -#define FX_DELETE_VECTOR(Pointer, Class, Count) \ - { \ - for (int i = 0; i < (Count); i ++) Pointer[i].~Class(); \ - FX_Free(Pointer); \ - } -class CFX_DestructObject : public CFX_Object +#define FX_NEW new(std::nothrow) +#define FX_NEW_VECTOR(Pointer, Class, Count) (Pointer = FX_NEW Class[Count]) +#define FX_DELETE_VECTOR(Pointer, Class, Count) delete[] Pointer + +class CFX_DestructObject { public: virtual ~CFX_DestructObject() {} }; -class CFX_GrowOnlyPool : public CFX_Object +class CFX_GrowOnlyPool { public: diff --git a/core/include/fxcrt/fx_string.h b/core/include/fxcrt/fx_string.h index ad1d083323..df7dd0c762 100644 --- a/core/include/fxcrt/fx_string.h +++ b/core/include/fxcrt/fx_string.h @@ -21,7 +21,7 @@ class CFX_WideStringL; // An immutable string with caller-provided storage which must outlive the // string itself. -class CFX_ByteStringC : public CFX_Object +class CFX_ByteStringC { public: typedef FX_CHAR value_type; @@ -171,7 +171,7 @@ struct CFX_StringData { FX_CHAR m_String[1]; }; -class CFX_ByteString : public CFX_Object +class CFX_ByteString { public: typedef FX_CHAR value_type; @@ -428,7 +428,7 @@ inline CFX_ByteString operator + (FX_BSTR str1, const CFX_ByteString& str2) { return CFX_ByteString(str1, str2); } -class CFX_StringBufBase : public CFX_Object +class CFX_StringBufBase { public: @@ -484,7 +484,7 @@ public: FX_CHAR m_Buffer[limit]; }; typedef CFX_StringBufTemplate<256> CFX_StringBuf256; -class CFX_WideStringC : public CFX_Object +class CFX_WideStringC { public: typedef FX_WCHAR value_type; @@ -630,7 +630,7 @@ struct CFX_StringDataW { FX_WCHAR m_String[1]; }; -class CFX_WideString : public CFX_Object +class CFX_WideString { public: typedef FX_WCHAR value_type; diff --git a/core/include/fxcrt/fx_xml.h b/core/include/fxcrt/fx_xml.h index 8fb00158a7..7f3dbcc205 100644 --- a/core/include/fxcrt/fx_xml.h +++ b/core/include/fxcrt/fx_xml.h @@ -9,14 +9,14 @@ #include "fx_basic.h" -class CXML_AttrItem : public CFX_Object +class CXML_AttrItem { public: CFX_ByteString m_QSpaceName; CFX_ByteString m_AttrName; CFX_WideString m_Value; }; -class CXML_AttrMap : public CFX_Object +class CXML_AttrMap { public: CXML_AttrMap() @@ -35,7 +35,7 @@ public: CXML_AttrItem& GetAt(int index) const; CFX_ObjectArray<CXML_AttrItem>* m_pMap; }; -class CXML_Content : public CFX_Object +class CXML_Content { public: CXML_Content() : m_bCDATA(FALSE), m_Content() {} @@ -47,7 +47,7 @@ public: FX_BOOL m_bCDATA; CFX_WideString m_Content; }; -class CXML_Element : public CFX_Object +class CXML_Element { public: static CXML_Element* Parse(const void* pBuffer, size_t size, FX_BOOL bSaveSpaceChars = FALSE, FX_FILESIZE* pParsedSize = NULL); |