summaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
Diffstat (limited to 'core/src')
-rw-r--r--core/src/fpdfapi/fpdf_edit/fpdf_edit_doc.cpp3
-rw-r--r--core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp4
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp1
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page_func.cpp1
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp2
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp1
-rw-r--r--core/src/fpdfapi/fpdf_render/fpdf_render_text.cpp2
-rw-r--r--core/src/fpdfdoc/doc_metadata.cpp1
-rw-r--r--core/src/fxcodec/codec/fx_codec.cpp6
-rw-r--r--core/src/fxcodec/codec/fx_codec_fax.cpp39
-rw-r--r--core/src/fxcodec/codec/fx_codec_flate.cpp1
-rw-r--r--core/src/fxcodec/codec/fx_codec_jpeg.cpp1
-rw-r--r--core/src/fxcodec/fx_libopenjpeg/libopenjpeg20/dwt.c13
-rw-r--r--core/src/fxcodec/fx_libopenjpeg/libopenjpeg20/j2k.c40
-rw-r--r--core/src/fxcodec/fx_libopenjpeg/libopenjpeg20/opj_malloc.h12
-rw-r--r--core/src/fxcodec/lcms2/lcms2-2.6/src/cmserr.c8
-rw-r--r--core/src/fxcrt/extension.h49
-rw-r--r--core/src/fxcrt/fx_basic_array.cpp56
-rw-r--r--core/src/fxcrt/fx_basic_bstring.cpp34
-rw-r--r--core/src/fxcrt/fx_basic_buffer.cpp43
-rw-r--r--core/src/fxcrt/fx_basic_list.cpp11
-rw-r--r--core/src/fxcrt/fx_basic_maps.cpp67
-rw-r--r--core/src/fxcrt/fx_basic_memmgr.cpp294
-rw-r--r--core/src/fxcrt/fx_basic_memmgr_mini.cpp822
-rw-r--r--core/src/fxcrt/fx_basic_plex.cpp12
-rw-r--r--core/src/fxcrt/fx_basic_utf.cpp14
-rw-r--r--core/src/fxcrt/fx_basic_wstring.cpp54
-rw-r--r--core/src/fxcrt/fx_extension.cpp74
-rw-r--r--core/src/fxcrt/fx_xml_composer.cpp12
-rw-r--r--core/src/fxcrt/fx_xml_parser.cpp267
-rw-r--r--core/src/fxcrt/fxcrt_platforms.cpp16
-rw-r--r--core/src/fxcrt/fxcrt_platforms.h2
-rw-r--r--core/src/fxcrt/fxcrt_posix.cpp16
-rw-r--r--core/src/fxcrt/fxcrt_posix.h2
-rw-r--r--core/src/fxcrt/fxcrt_windows.cpp18
-rw-r--r--core/src/fxcrt/fxcrt_windows.h4
-rw-r--r--core/src/fxcrt/mem_int.h232
-rw-r--r--core/src/fxcrt/plex.h6
-rw-r--r--core/src/fxcrt/xml_int.h38
-rw-r--r--core/src/fxge/dib/fx_dib_convert.cpp4
-rw-r--r--core/src/fxge/dib/fx_dib_engine.cpp2
-rw-r--r--core/src/fxge/dib/fx_dib_main.cpp1
-rw-r--r--core/src/fxge/win32/fx_win32_dib.cpp1
-rw-r--r--core/src/fxge/win32/fx_win32_gdipext.cpp1
44 files changed, 286 insertions, 2001 deletions
diff --git a/core/src/fpdfapi/fpdf_edit/fpdf_edit_doc.cpp b/core/src/fpdfapi/fpdf_edit/fpdf_edit_doc.cpp
index 2672116e4f..9985f06dc6 100644
--- a/core/src/fpdfapi/fpdf_edit/fpdf_edit_doc.cpp
+++ b/core/src/fpdfapi/fpdf_edit/fpdf_edit_doc.cpp
@@ -543,8 +543,7 @@ static void _CFString2CFXByteString(CFStringRef src, CFX_ByteString &dest)
SInt32 len = CFStringGetLength(src);
CFRange range = CFRangeMake(0, len);
CFIndex used = 0;
- UInt8* pBuffer = (UInt8*)malloc(sizeof(UInt8) * (len + 1));
- FXSYS_memset32(pBuffer, 0, sizeof(UInt8) * (len + 1));
+ UInt8* pBuffer = (UInt8*)calloc(len+1, sizeof(UInt8));
CFStringGetBytes(src, range, kCFStringEncodingASCII, 0, false, pBuffer, len, &used);
dest = (FX_LPSTR)pBuffer;
free(pBuffer);
diff --git a/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp b/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp
index 23bbc4aab9..bd1187645c 100644
--- a/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp
+++ b/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp
@@ -411,7 +411,6 @@ FX_BOOL CPDF_CMap::LoadPredefined(CPDF_CMapManager* pMgr, FX_LPCSTR pName, FX_BO
m_CodingScheme = map.m_CodingScheme;
if (m_CodingScheme == MixedTwoBytes) {
m_pLeadingBytes = FX_Alloc(FX_BYTE, 256);
- FXSYS_memset32(m_pLeadingBytes, 0, 256);
for (FX_DWORD i = 0; i < map.m_LeadingSegCount; i ++) {
for (int b = map.m_LeadingSegs[i * 2]; b <= map.m_LeadingSegs[i * 2 + 1]; b ++) {
m_pLeadingBytes[b] = 1;
@@ -431,7 +430,6 @@ FX_BOOL CPDF_CMap::LoadPredefined(CPDF_CMapManager* pMgr, FX_LPCSTR pName, FX_BO
return FALSE;
}
m_pMapping = FX_Alloc(FX_WORD, 65536);
- FXSYS_memset32(m_pMapping, 0, 65536 * sizeof(FX_WORD));
FX_DWORD dwRecodeEndPos = 0;
if (pBuffer[5] == 0) {
FX_DWORD dwStartIndex = *(FX_DWORD*)(pBuffer + 8);
@@ -480,7 +478,6 @@ extern "C" {
FX_BOOL CPDF_CMap::LoadEmbedded(FX_LPCBYTE pData, FX_DWORD size)
{
m_pMapping = FX_Alloc(FX_WORD, 65536);
- FXSYS_memset32(m_pMapping, 0, 65536 * sizeof(FX_WORD));
CPDF_CMapParser parser;
parser.Initialize(this);
CPDF_SimpleParser syntax(pData, size);
@@ -1528,7 +1525,6 @@ FX_BOOL CPDF_CIDFont::LoadGB2312()
CheckFontMetrics();
m_DefaultWidth = 1000;
m_pAnsiWidths = FX_Alloc(FX_WORD, 128);
- FXSYS_memset32(m_pAnsiWidths, 0, 128 * sizeof(FX_WORD));
for (int i = 32; i < 127; i ++) {
m_pAnsiWidths[i] = 500;
}
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp
index 867b245a50..b661bbefba 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp
@@ -1163,7 +1163,6 @@ FX_FLOAT* CPDF_ColorSpace::CreateBuf()
{
int size = GetBufSize();
FX_BYTE* pBuf = FX_Alloc(FX_BYTE, size);
- FXSYS_memset32(pBuf, 0, size);
return (FX_FLOAT*)pBuf;
}
FX_BOOL CPDF_ColorSpace::sRGB() const
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_func.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_func.cpp
index af22c5649e..649bd54a33 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page_func.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page_func.cpp
@@ -721,7 +721,6 @@ FX_BOOL CPDF_StitchFunc::v_Init(CPDF_Object* pObj)
return FALSE;
}
m_pSubFunctions = FX_Alloc(CPDF_Function*, m_nSubs);
- FXSYS_memset32(m_pSubFunctions, 0, sizeof(CPDF_Function*)*m_nSubs);
m_nOutputs = 0;
int i;
for (i = 0; i < m_nSubs; i ++) {
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp
index 628fb3da99..8053718c19 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp
@@ -71,7 +71,6 @@ CPDF_ClipPathData::CPDF_ClipPathData(const CPDF_ClipPathData& src)
m_TextCount = src.m_TextCount;
if (m_TextCount) {
m_pTextList = FX_Alloc(CPDF_TextObject*, m_TextCount);
- FXSYS_memset32(m_pTextList, 0, sizeof(CPDF_TextObject*) * m_TextCount);
for (int i = 0; i < m_TextCount; i ++) {
if (src.m_pTextList[i]) {
m_pTextList[i] = FX_NEW CPDF_TextObject;
@@ -96,7 +95,6 @@ void CPDF_ClipPathData::SetCount(int path_count, int text_count)
if (text_count) {
m_TextCount = text_count;
m_pTextList = FX_Alloc(CPDF_TextObject*, text_count);
- FXSYS_memset32(m_pTextList, 0, sizeof(void*) * text_count);
}
}
CPDF_Rect CPDF_ClipPath::GetClipBox() const
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp
index fe5e59c698..85cf034c1f 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp
@@ -962,7 +962,6 @@ void CPDF_ContentParser::Start(CPDF_Page* pPage, CPDF_ParseOptions* pOptions)
return;
}
m_pStreamArray = FX_Alloc(CPDF_StreamAcc*, m_nStreams);
- FXSYS_memset32(m_pStreamArray, 0, sizeof(CPDF_StreamAcc*) * m_nStreams);
} else {
m_Status = Done;
return;
diff --git a/core/src/fpdfapi/fpdf_render/fpdf_render_text.cpp b/core/src/fpdfapi/fpdf_render/fpdf_render_text.cpp
index a26d619565..fcb422b6c4 100644
--- a/core/src/fpdfapi/fpdf_render/fpdf_render_text.cpp
+++ b/core/src/fpdfapi/fpdf_render/fpdf_render_text.cpp
@@ -390,7 +390,6 @@ FX_BOOL CPDF_RenderStatus::ProcessType3Text(const CPDF_TextObject* textobj, cons
FXTEXT_GLYPHPOS* pGlyphAndPos = NULL;
if (device_class == FXDC_DISPLAY) {
pGlyphAndPos = FX_Alloc(FXTEXT_GLYPHPOS, textobj->m_nChars);
- FXSYS_memset32(pGlyphAndPos, 0, sizeof(FXTEXT_GLYPHPOS) * textobj->m_nChars);
} else if (fill_alpha < 255) {
return FALSE;
}
@@ -540,7 +539,6 @@ void CPDF_CharPosList::Load(int nChars, FX_DWORD* pCharCodes, FX_FLOAT* pCharPos
FX_FLOAT FontSize)
{
m_pCharPos = FX_Alloc(FXTEXT_CHARPOS, nChars);
- FXSYS_memset32(m_pCharPos, 0, sizeof(FXTEXT_CHARPOS) * nChars);
m_nChars = 0;
CPDF_CIDFont* pCIDFont = pFont->GetCIDFont();
FX_BOOL bVertWriting = pCIDFont && pCIDFont->IsVertWriting();
diff --git a/core/src/fpdfdoc/doc_metadata.cpp b/core/src/fpdfdoc/doc_metadata.cpp
index 8c00157990..bf55527d62 100644
--- a/core/src/fpdfdoc/doc_metadata.cpp
+++ b/core/src/fpdfdoc/doc_metadata.cpp
@@ -27,7 +27,6 @@ const FX_LPCSTR gs_FPDFDOC_Metadata_Titles[] = {
CPDF_Metadata::CPDF_Metadata()
{
m_pData = FX_Alloc(PDFDOC_METADATA, 1);
- FXSYS_memset32(m_pData, 0, sizeof(PDFDOC_METADATA));
CFX_CMapByteStringToPtr *&pStringMap = ((PDFDOC_LPMETADATA)m_pData)->m_pStringMap;
pStringMap = FX_NEW(CFX_CMapByteStringToPtr);
if (pStringMap != NULL) {
diff --git a/core/src/fxcodec/codec/fx_codec.cpp b/core/src/fxcodec/codec/fx_codec.cpp
index c6b3ccee43..456ec40fea 100644
--- a/core/src/fxcodec/codec/fx_codec.cpp
+++ b/core/src/fxcodec/codec/fx_codec.cpp
@@ -1,7 +1,7 @@
// Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-
+
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#include "../../../include/fxcodec/fx_codec.h"
@@ -119,8 +119,7 @@ void CCodec_ScanlineDecoder::DownScale(int dest_width, int dest_height)
FX_Free(m_pDataCache);
m_pDataCache = NULL;
}
- m_pDataCache = (CCodec_ImageDataCache*)FXMEM_DefaultAlloc(
- sizeof(CCodec_ImageDataCache) + m_Pitch * m_OutputHeight, FXMEM_NONLEAVE);
+ m_pDataCache = (CCodec_ImageDataCache*)FX_AllocNL(FX_BYTE, sizeof(CCodec_ImageDataCache) + m_Pitch * m_OutputHeight);
if (m_pDataCache == NULL) {
return;
}
@@ -337,7 +336,6 @@ FX_BOOL CCodec_RLScanlineDecoder::Create(FX_LPCBYTE src_buf, FX_DWORD src_size,
if (m_pScanline == NULL) {
return FALSE;
}
- FXSYS_memset32(m_pScanline, 0, m_Pitch);
return CheckDestSize();
}
FX_BOOL CCodec_RLScanlineDecoder::v_Rewind()
diff --git a/core/src/fxcodec/codec/fx_codec_fax.cpp b/core/src/fxcodec/codec/fx_codec_fax.cpp
index 979df38197..c6c13f98bb 100644
--- a/core/src/fxcodec/codec/fx_codec_fax.cpp
+++ b/core/src/fxcodec/codec/fx_codec_fax.cpp
@@ -6,8 +6,43 @@
#include "../../../include/fxcodec/fx_codec.h"
#include "codec_int.h"
-extern const FX_BYTE OneLeadPos[256];
-extern const FX_BYTE ZeroLeadPos[256];
+const FX_BYTE OneLeadPos[256] = {
+ 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4,
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+};
+const FX_BYTE ZeroLeadPos[256] = {
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+ 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 7, 8,
+};
+
int _FindBit(const FX_BYTE* data_buf, int max_pos, int start_pos, int bit)
{
if (start_pos >= max_pos) {
diff --git a/core/src/fxcodec/codec/fx_codec_flate.cpp b/core/src/fxcodec/codec/fx_codec_flate.cpp
index 4724593a94..c02f0977cf 100644
--- a/core/src/fxcodec/codec/fx_codec_flate.cpp
+++ b/core/src/fxcodec/codec/fx_codec_flate.cpp
@@ -654,7 +654,6 @@ FX_BOOL CCodec_FlateScanlineDecoder::Create(FX_LPCBYTE src_buf, FX_DWORD src_siz
if (m_pLastLine == NULL) {
return FALSE;
}
- FXSYS_memset32(m_pLastLine, 0, m_PredictPitch);
m_pPredictRaw = FX_Alloc(FX_BYTE, m_PredictPitch + 1);
if (m_pPredictRaw == NULL) {
return FALSE;
diff --git a/core/src/fxcodec/codec/fx_codec_jpeg.cpp b/core/src/fxcodec/codec/fx_codec_jpeg.cpp
index aae3e24c05..37399f8eb8 100644
--- a/core/src/fxcodec/codec/fx_codec_jpeg.cpp
+++ b/core/src/fxcodec/codec/fx_codec_jpeg.cpp
@@ -196,7 +196,6 @@ static void _JpegEncode(const CFX_DIBSource* pSource, FX_LPBYTE& dest_buf, FX_ST
dest_buf_length >>= 1;
dest_buf = FX_Alloc(FX_BYTE, dest_buf_length);
}
- FXSYS_memset32(dest_buf, 0, dest_buf_length);
struct jpeg_destination_mgr dest;
dest.init_destination = _dest_do_nothing;
dest.term_destination = _dest_do_nothing;
diff --git a/core/src/fxcodec/fx_libopenjpeg/libopenjpeg20/dwt.c b/core/src/fxcodec/fx_libopenjpeg/libopenjpeg20/dwt.c
index 5f710e87b2..60698e3ffe 100644
--- a/core/src/fxcodec/fx_libopenjpeg/libopenjpeg20/dwt.c
+++ b/core/src/fxcodec/fx_libopenjpeg/libopenjpeg20/dwt.c
@@ -140,9 +140,7 @@ static void opj_v4dwt_interleave_h(opj_v4dwt_t* restrict w, OPJ_FLOAT32* restric
static void opj_v4dwt_interleave_v(opj_v4dwt_t* restrict v , OPJ_FLOAT32* restrict a , OPJ_INT32 x, OPJ_INT32 nb_elts_read);
-//#ifdef __SSE__
-// Disable __SSE__ due to bug http://crbug.com/373619. Should enable this after adding aligned malloc in memory manager
-#if 0
+#ifdef __SSE__
static void opj_v4dwt_decode_step1_sse(opj_v4_t* w, OPJ_INT32 count, const __m128 c);
static void opj_v4dwt_decode_step2_sse(opj_v4_t* l, opj_v4_t* w, OPJ_INT32 k, OPJ_INT32 m, __m128 c);
@@ -673,9 +671,8 @@ void opj_v4dwt_interleave_v(opj_v4dwt_t* restrict v , OPJ_FLOAT32* restrict a ,
}
}
-//#ifdef __SSE__
-// Disable __SSE__ due to bug http://crbug.com/373619. Should enable this after adding aligned malloc in memory manager
-#if 0
+#ifdef __SSE__
+
void opj_v4dwt_decode_step1_sse(opj_v4_t* w, OPJ_INT32 count, const __m128 c){
__m128* restrict vw = (__m128*) w;
OPJ_INT32 i;
@@ -812,9 +809,7 @@ void opj_v4dwt_decode(opj_v4dwt_t* restrict dwt)
b = 0;
}
-//#ifdef __SSE__
-// Disable __SSE__ due to bug http://crbug.com/373619. Should enable this after adding aligned malloc in memory manager
-#if 0
+#ifdef __SSE__
opj_v4dwt_decode_step1_sse(dwt->wavelet+a, dwt->sn, _mm_set1_ps(opj_K));
opj_v4dwt_decode_step1_sse(dwt->wavelet+b, dwt->dn, _mm_set1_ps(opj_c13318));
opj_v4dwt_decode_step2_sse(dwt->wavelet+b, dwt->wavelet+a+1, dwt->sn, opj_int_min(dwt->sn, dwt->dn-a), _mm_set1_ps(opj_dwt_delta));
diff --git a/core/src/fxcodec/fx_libopenjpeg/libopenjpeg20/j2k.c b/core/src/fxcodec/fx_libopenjpeg/libopenjpeg20/j2k.c
index 77a864ebb9..bf411efca5 100644
--- a/core/src/fxcodec/fx_libopenjpeg/libopenjpeg20/j2k.c
+++ b/core/src/fxcodec/fx_libopenjpeg/libopenjpeg20/j2k.c
@@ -10253,43 +10253,3 @@ OPJ_BOOL opj_j2k_write_tile (opj_j2k_t * p_j2k,
return OPJ_TRUE;
}
-
-#ifdef _FOXIT_MEM_MANAGER_
-/** Allocate number of bytes */
-void* FXMEM_DefaultAlloc(int byte_size, int flags);
-void* FXMEM_DefaultRealloc(void* pointer, int new_size, int flags);
-void FXMEM_DefaultFree(void* pointer, int flags);
-
-void* opj_malloc(size_t size)
-{
- if (size >= (size_t)-0x100 || (int)size < 0) return NULL;
-
- return FXMEM_DefaultAlloc(size, 0);
-}
-
-void* opj_calloc(size_t _NumOfElements, size_t _SizeOfElements)
-{
- void* buffer = NULL;
-
- if (_NumOfElements != 0 && _NumOfElements >= (size_t)-0x100 / _SizeOfElements) return NULL;
- if ((int)_NumOfElements < 0 || (int)_SizeOfElements < 0) return NULL;
-
- buffer = FXMEM_DefaultAlloc(_NumOfElements * _SizeOfElements, 0);
- if (!buffer) return 0;
-
- memset(buffer, 0, _NumOfElements * _SizeOfElements);
- return buffer;
-}
-
-void* opj_realloc(void * m, size_t s)
-{
- if (s >= (size_t)-0x100 || (int)s < 0) return NULL;
- return FXMEM_DefaultRealloc(m, s, 0);
-}
-
-void opj_free(void * m)
-{
- FXMEM_DefaultFree(m, 0);
-}
-
-#endif
diff --git a/core/src/fxcodec/fx_libopenjpeg/libopenjpeg20/opj_malloc.h b/core/src/fxcodec/fx_libopenjpeg/libopenjpeg20/opj_malloc.h
index ed1dfaf983..f2fe82f1a3 100644
--- a/core/src/fxcodec/fx_libopenjpeg/libopenjpeg20/opj_malloc.h
+++ b/core/src/fxcodec/fx_libopenjpeg/libopenjpeg20/opj_malloc.h
@@ -50,16 +50,7 @@ Allocate an uninitialized memory block
@param size Bytes to allocate
@return Returns a void pointer to the allocated space, or NULL if there is insufficient memory available
*/
-#define _FOXIT_MEM_MANAGER_
-#ifdef _FOXIT_MEM_MANAGER_
-void* opj_malloc(size_t size);
-void* opj_calloc(size_t _NumOfElements, size_t _SizeOfElements);
-void* opj_realloc(void * m, size_t s);
-void opj_free(void * m);
-
-#define opj_aligned_malloc(size) opj_malloc(size)
-#define opj_aligned_free(m) opj_free(m)
-#else
+
#ifdef ALLOC_PERF_OPT
void * OPJ_CALLCONV opj_malloc(size_t size);
#else
@@ -170,7 +161,6 @@ void * OPJ_CALLCONV opj_realloc(void * m, size_t s);
#else
#define opj_realloc(m, s) realloc(m, s)
#endif
-#endif
/**
Deallocates or frees a memory block.
diff --git a/core/src/fxcodec/lcms2/lcms2-2.6/src/cmserr.c b/core/src/fxcodec/lcms2/lcms2-2.6/src/cmserr.c
index 87c6320cff..964182ae38 100644
--- a/core/src/fxcodec/lcms2/lcms2-2.6/src/cmserr.c
+++ b/core/src/fxcodec/lcms2/lcms2-2.6/src/cmserr.c
@@ -262,13 +262,13 @@ cmsBool _cmsRegisterMemHandlerPlugin(cmsContext ContextID, cmsPluginBase* Plugi
// Generic allocate
void* CMSEXPORT _cmsMalloc(cmsContext ContextID, cmsUInt32Number size)
{
- return FXMEM_DefaultAlloc(size, FXMEM_NONLEAVE);
+ return FXMEM_DefaultAlloc(size, 1);
}
// Generic allocate & zero
void* CMSEXPORT _cmsMallocZero(cmsContext ContextID, cmsUInt32Number size)
{
- void* p = FXMEM_DefaultAlloc(size, FXMEM_NONLEAVE);
+ void* p = FXMEM_DefaultAlloc(size, 1);
if (p) FXSYS_memset32(p, 0, size);
return p;
}
@@ -286,7 +286,7 @@ void* CMSEXPORT _cmsCalloc(cmsContext ContextID, cmsUInt32Number num, cmsUInt32N
// Generic reallocate
void* CMSEXPORT _cmsRealloc(cmsContext ContextID, void* Ptr, cmsUInt32Number size)
{
- return FXMEM_DefaultRealloc(Ptr, size, FXMEM_NONLEAVE);
+ return FXMEM_DefaultRealloc(Ptr, size, 1);
}
// Generic free memory
@@ -298,7 +298,7 @@ void CMSEXPORT _cmsFree(cmsContext ContextID, void* Ptr)
// Generic block duplication
void* CMSEXPORT _cmsDupMem(cmsContext ContextID, const void* Org, cmsUInt32Number size)
{
- void* p = FXMEM_DefaultAlloc(size, FXMEM_NONLEAVE);
+ void* p = FXMEM_DefaultAlloc(size, 1);
FXSYS_memmove32(p, Org, size);
return p;
}
diff --git a/core/src/fxcrt/extension.h b/core/src/fxcrt/extension.h
index 8d9597bfd1..db35387908 100644
--- a/core/src/fxcrt/extension.h
+++ b/core/src/fxcrt/extension.h
@@ -1,7 +1,7 @@
// Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-
+
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#ifndef _FXCRT_EXTENSION_IMP_
@@ -13,7 +13,7 @@ public:
virtual FX_BOOL Open(FX_BSTR fileName, FX_DWORD dwMode) = 0;
virtual FX_BOOL Open(FX_WSTR fileName, FX_DWORD dwMode) = 0;
virtual void Close() = 0;
- virtual void Release(IFX_Allocator* pAllocator = NULL) = 0;
+ virtual void Release() = 0;
virtual FX_FILESIZE GetSize() const = 0;
virtual FX_FILESIZE GetPosition() const = 0;
virtual FX_FILESIZE SetPosition(FX_FILESIZE pos) = 0;
@@ -24,15 +24,15 @@ public:
virtual FX_BOOL Flush() = 0;
virtual FX_BOOL Truncate(FX_FILESIZE szFile) = 0;
};
-IFXCRT_FileAccess* FXCRT_FileAccess_Create(IFX_Allocator* pAllocator = NULL);
+IFXCRT_FileAccess* FXCRT_FileAccess_Create();
class CFX_CRTFileStream : public IFX_FileStream, public CFX_Object
{
public:
- CFX_CRTFileStream(IFXCRT_FileAccess* pFA, IFX_Allocator* pAllocator) : m_pAllocator(pAllocator), m_pFile(pFA), m_dwCount(1), m_bUseRange(FALSE), m_nOffset(0), m_nSize(0) {}
+ CFX_CRTFileStream(IFXCRT_FileAccess* pFA) : m_pFile(pFA), m_dwCount(1), m_bUseRange(FALSE), m_nOffset(0), m_nSize(0) {}
~CFX_CRTFileStream()
{
if (m_pFile) {
- m_pFile->Release(m_pAllocator);
+ m_pFile->Release();
}
}
virtual IFX_FileStream* Retain()
@@ -44,11 +44,7 @@ public:
{
FX_DWORD nCount = -- m_dwCount;
if (!nCount) {
- if (m_pAllocator) {
- FX_DeleteAtAllocator(this, m_pAllocator, CFX_CRTFileStream);
- } else {
- delete this;
- }
+ delete this;
}
}
virtual FX_FILESIZE GetSize()
@@ -112,7 +108,6 @@ public:
{
return m_pFile->Flush();
}
- IFX_Allocator* m_pAllocator;
IFXCRT_FileAccess* m_pFile;
FX_DWORD m_dwCount;
FX_BOOL m_bUseRange;
@@ -125,9 +120,8 @@ public:
class CFX_MemoryStream : public IFX_MemoryStream, public CFX_Object
{
public:
- CFX_MemoryStream(FX_BOOL bConsecutive, IFX_Allocator* pAllocator)
- : m_Blocks(pAllocator)
- , m_dwCount(1)
+ CFX_MemoryStream(FX_BOOL bConsecutive)
+ : m_dwCount(1)
, m_nTotalSize(0)
, m_nCurSize(0)
, m_nCurPos(0)
@@ -136,9 +130,8 @@ public:
{
m_dwFlags = FX_MEMSTREAM_TakeOver | (bConsecutive ? FX_MEMSTREAM_Consecutive : 0);
}
- CFX_MemoryStream(FX_LPBYTE pBuffer, size_t nSize, FX_BOOL bTakeOver, IFX_Allocator* pAllocator)
- : m_Blocks(pAllocator)
- , m_dwCount(1)
+ CFX_MemoryStream(FX_LPBYTE pBuffer, size_t nSize, FX_BOOL bTakeOver)
+ : m_dwCount(1)
, m_nTotalSize(nSize)
, m_nCurSize(nSize)
, m_nCurPos(0)
@@ -150,10 +143,9 @@ public:
}
~CFX_MemoryStream()
{
- IFX_Allocator* pAllocator = m_Blocks.m_pAllocator;
if (m_dwFlags & FX_MEMSTREAM_TakeOver) {
- for (FX_INT32 i = 0; i < m_Blocks.GetSize(); i ++) {
- FX_Allocator_Free(pAllocator, (FX_LPBYTE)m_Blocks[i]);
+ for (FX_INT32 i = 0; i < m_Blocks.GetSize(); i++) {
+ FX_Free((FX_LPBYTE)m_Blocks[i]);
}
}
m_Blocks.RemoveAll();
@@ -169,12 +161,7 @@ public:
if (nCount) {
return;
}
- IFX_Allocator* pAllocator = m_Blocks.m_pAllocator;
- if (pAllocator) {
- FX_DeleteAtAllocator(this, pAllocator, CFX_MemoryStream);
- } else {
- delete this;
- }
+ delete this;
}
virtual FX_FILESIZE GetSize()
{
@@ -265,13 +252,12 @@ public:
if (m_dwFlags & FX_MEMSTREAM_Consecutive) {
m_nCurPos = (size_t)offset + size;
if (m_nCurPos > m_nTotalSize) {
- IFX_Allocator* pAllocator = m_Blocks.m_pAllocator;
m_nTotalSize = (m_nCurPos + m_nGrowSize - 1) / m_nGrowSize * m_nGrowSize;
if (m_Blocks.GetSize() < 1) {
- void* block = FX_Allocator_Alloc(pAllocator, FX_BYTE, m_nTotalSize);
+ void* block = FX_Alloc(FX_BYTE, m_nTotalSize);
m_Blocks.Add(block);
} else {
- m_Blocks[0] = FX_Allocator_Realloc(pAllocator, FX_BYTE, m_Blocks[0], m_nTotalSize);
+ m_Blocks[0] = FX_Realloc(FX_BYTE, m_Blocks[0], m_nTotalSize);
}
if (!m_Blocks[0]) {
m_Blocks.RemoveAll();
@@ -315,7 +301,7 @@ public:
{
if (m_dwFlags & FX_MEMSTREAM_Consecutive) {
if (m_Blocks.GetSize() < 1) {
- FX_LPBYTE pBlock = FX_Allocator_Alloc(m_Blocks.m_pAllocator, FX_BYTE, FX_MAX(nInitSize, 4096));
+ FX_LPBYTE pBlock = FX_Alloc(FX_BYTE, FX_MAX(nInitSize, 4096));
if (pBlock) {
m_Blocks.Add(pBlock);
}
@@ -373,9 +359,8 @@ protected:
FX_INT32 iCount = m_Blocks.GetSize();
size = (size - m_nTotalSize + m_nGrowSize - 1) / m_nGrowSize;
m_Blocks.SetSize(m_Blocks.GetSize() + (FX_INT32)size, -1);
- IFX_Allocator* pAllocator = m_Blocks.m_pAllocator;
while (size --) {
- FX_LPBYTE pBlock = FX_Allocator_Alloc(pAllocator, FX_BYTE, m_nGrowSize);
+ FX_LPBYTE pBlock = FX_Alloc(FX_BYTE, m_nGrowSize);
if (!pBlock) {
return FALSE;
}
diff --git a/core/src/fxcrt/fx_basic_array.cpp b/core/src/fxcrt/fx_basic_array.cpp
index aae3a1fa1c..55d27b0a4a 100644
--- a/core/src/fxcrt/fx_basic_array.cpp
+++ b/core/src/fxcrt/fx_basic_array.cpp
@@ -5,9 +5,8 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#include "../../include/fxcrt/fx_basic.h"
-CFX_BasicArray::CFX_BasicArray(int unit_size, IFX_Allocator* pAllocator)
- : m_pAllocator(pAllocator)
- , m_pData(NULL)
+CFX_BasicArray::CFX_BasicArray(int unit_size)
+ : m_pData(NULL)
, m_nSize(0)
, m_nMaxSize(0)
, m_nGrowBy(0)
@@ -20,15 +19,15 @@ CFX_BasicArray::CFX_BasicArray(int unit_size, IFX_Allocator* pAllocator)
}
CFX_BasicArray::~CFX_BasicArray()
{
- FX_Allocator_Free(m_pAllocator, m_pData);
+ FX_Free(m_pData);
}
FX_BOOL CFX_BasicArray::SetSize(int nNewSize, int nGrowBy)
{
if (nNewSize < 0 || nNewSize > (1 << 28) / m_nUnitSize) {
if (m_pData != NULL) {
- FX_Allocator_Free(m_pAllocator, m_pData);
+ FX_Free(m_pData);
m_pData = NULL;
- }
+ }
m_nSize = m_nMaxSize = 0;
return FALSE;
}
@@ -37,17 +36,16 @@ FX_BOOL CFX_BasicArray::SetSize(int nNewSize, int nGrowBy)
}
if (nNewSize == 0) {
if (m_pData != NULL) {
- FX_Allocator_Free(m_pAllocator, m_pData);
+ FX_Free(m_pData);
m_pData = NULL;
}
m_nSize = m_nMaxSize = 0;
} else if (m_pData == NULL) {
- m_pData = FX_Allocator_Alloc(m_pAllocator, FX_BYTE, nNewSize * m_nUnitSize);
+ m_pData = FX_Alloc(FX_BYTE, nNewSize * m_nUnitSize);
if (!m_pData) {
m_nSize = m_nMaxSize = 0;
return FALSE;
}
- FXSYS_memset32(m_pData, 0, nNewSize * m_nUnitSize);
m_nSize = m_nMaxSize = nNewSize;
} else if (nNewSize <= m_nMaxSize) {
if (nNewSize > m_nSize) {
@@ -66,7 +64,7 @@ FX_BOOL CFX_BasicArray::SetSize(int nNewSize, int nGrowBy)
} else {
nNewMax = nNewSize;
}
- FX_LPBYTE pNewData = FX_Allocator_Realloc(m_pAllocator, FX_BYTE, m_pData, nNewMax * m_nUnitSize);
+ FX_LPBYTE pNewData = FX_Realloc(FX_BYTE, m_pData, nNewMax * m_nUnitSize);
if (pNewData == NULL) {
return FALSE;
}
@@ -147,9 +145,8 @@ const void* CFX_BasicArray::GetDataPtr(int index) const
}
return m_pData + index * m_nUnitSize;
}
-CFX_BaseSegmentedArray::CFX_BaseSegmentedArray(int unit_size, int segment_units, int index_size, IFX_Allocator* pAllocator)
- : m_pAllocator(pAllocator)
- , m_UnitSize(unit_size)
+CFX_BaseSegmentedArray::CFX_BaseSegmentedArray(int unit_size, int segment_units, int index_size)
+ : m_UnitSize(unit_size)
, m_SegmentSize(segment_units)
, m_IndexSize(index_size)
, m_IndexDepth(0)
@@ -168,26 +165,26 @@ CFX_BaseSegmentedArray::~CFX_BaseSegmentedArray()
{
RemoveAll();
}
-static void _ClearIndex(IFX_Allocator* pAllcator, int level, int size, void** pIndex)
+static void _ClearIndex(int level, int size, void** pIndex)
{
if (level == 0) {
- FX_Allocator_Free(pAllcator, pIndex);
+ FX_Free(pIndex);
return;
}
- for (int i = 0; i < size; i ++) {
+ for (int i = 0; i < size; i++) {
if (pIndex[i] == NULL) {
continue;
}
- _ClearIndex(pAllcator, level - 1, size, (void**)pIndex[i]);
+ _ClearIndex(level - 1, size, (void**)pIndex[i]);
}
- FX_Allocator_Free(pAllcator, pIndex);
+ FX_Free(pIndex);
}
void CFX_BaseSegmentedArray::RemoveAll()
{
if (m_pIndex == NULL) {
return;
}
- _ClearIndex(m_pAllocator, m_IndexDepth, m_IndexSize, (void**)m_pIndex);
+ _ClearIndex(m_IndexDepth, m_IndexSize, (void**)m_pIndex);
m_pIndex = NULL;
m_IndexDepth = 0;
m_DataSize = 0;
@@ -197,7 +194,7 @@ void* CFX_BaseSegmentedArray::Add()
if (m_DataSize % m_SegmentSize) {
return GetAt(m_DataSize ++);
}
- void* pSegment = FX_Allocator_Alloc(m_pAllocator, FX_BYTE, m_UnitSize * m_SegmentSize);
+ void* pSegment = FX_Alloc(FX_BYTE, m_UnitSize * m_SegmentSize);
if (!pSegment) {
return NULL;
}
@@ -207,12 +204,11 @@ void* CFX_BaseSegmentedArray::Add()
return pSegment;
}
if (m_IndexDepth == 0) {
- void** pIndex = (void**)FX_Allocator_Alloc(m_pAllocator, void*, m_IndexSize);
+ void** pIndex = (void**)FX_Alloc(void*, m_IndexSize);
if (pIndex == NULL) {
- FX_Allocator_Free(m_pAllocator, pSegment);
+ FX_Free(pSegment);
return NULL;
}
- FXSYS_memset32(pIndex, 0, sizeof(void*) * m_IndexSize);
pIndex[0] = m_pIndex;
pIndex[1] = pSegment;
m_pIndex = pIndex;
@@ -233,12 +229,11 @@ void* CFX_BaseSegmentedArray::Add()
tree_size *= m_IndexSize;
}
if (m_DataSize == tree_size * m_SegmentSize) {
- void** pIndex = (void**)FX_Allocator_Alloc(m_pAllocator, void*, m_IndexSize);
+ void** pIndex = (void**)FX_Alloc(void*, m_IndexSize);
if (pIndex == NULL) {
- FX_Allocator_Free(m_pAllocator, pSegment);
+ FX_Free(pSegment);
return NULL;
}
- FXSYS_memset32(pIndex, 0, sizeof(void*) * m_IndexSize);
pIndex[0] = m_pIndex;
m_pIndex = pIndex;
m_IndexDepth ++;
@@ -248,18 +243,17 @@ void* CFX_BaseSegmentedArray::Add()
void** pSpot = (void**)m_pIndex;
for (i = 1; i < m_IndexDepth; i ++) {
if (pSpot[seg_index / tree_size] == NULL) {
- pSpot[seg_index / tree_size] = (void*)FX_Allocator_Alloc(m_pAllocator, void*, m_IndexSize);
+ pSpot[seg_index / tree_size] = (void*)FX_Alloc(void*, m_IndexSize);
if (pSpot[seg_index / tree_size] == NULL) {
break;
}
- FXSYS_memset32(pSpot[seg_index / tree_size], 0, sizeof(void*) * m_IndexSize);
}
pSpot = (void**)pSpot[seg_index / tree_size];
seg_index = seg_index % tree_size;
tree_size /= m_IndexSize;
}
if (i < m_IndexDepth) {
- FX_Allocator_Free(m_pAllocator, pSegment);
+ FX_Free(pSegment);
RemoveAll();
return NULL;
}
@@ -356,11 +350,11 @@ void CFX_BaseSegmentedArray::Delete(int index, int count)
if(m_IndexDepth) {
for (i = new_segs; i < old_segs; i ++) {
void** pIndex = GetIndex(i);
- FX_Allocator_Free(m_pAllocator, pIndex[i % m_IndexSize]);
+ FX_Free(pIndex[i % m_IndexSize]);
pIndex[i % m_IndexSize] = NULL;
}
} else {
- FX_Allocator_Free(m_pAllocator, m_pIndex);
+ FX_Free(m_pIndex);
m_pIndex = NULL;
}
}
diff --git a/core/src/fxcrt/fx_basic_bstring.cpp b/core/src/fxcrt/fx_basic_bstring.cpp
index 435f5a5e5c..f14ff2ba5d 100644
--- a/core/src/fxcrt/fx_basic_bstring.cpp
+++ b/core/src/fxcrt/fx_basic_bstring.cpp
@@ -1,7 +1,7 @@
// Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-
+
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#include "../../include/fxcrt/fx_basic.h"
@@ -1176,35 +1176,3 @@ void CFX_StringBufBase::Append(int i, FX_DWORD flags)
int len = _Buffer_itoa(buf, i, flags);
Append(CFX_ByteStringC(buf, len));
}
-void CFX_ByteStringL::Empty(IFX_Allocator* pAllocator)
-{
- if (m_Ptr) {
- FX_Allocator_Free(pAllocator, (FX_LPVOID)m_Ptr);
- }
- m_Ptr = NULL, m_Length = 0;
-}
-FX_LPSTR CFX_ByteStringL::AllocBuffer(FX_STRSIZE length, IFX_Allocator* pAllocator)
-{
- Empty(pAllocator);
- FX_LPSTR str = FX_Allocator_Alloc(pAllocator, FX_CHAR, length + 1);
- if (!str) {
- return NULL;
- }
- *(FX_LPSTR*)(&m_Ptr) = str;
- m_Length = length;
- return str;
-}
-void CFX_ByteStringL::Set(FX_BSTR src, IFX_Allocator* pAllocator)
-{
- Empty(pAllocator);
- if (src.GetCStr() != NULL && src.GetLength() > 0) {
- FX_LPSTR str = FX_Allocator_Alloc(pAllocator, FX_CHAR, src.GetLength() + 1);
- if (!str) {
- return;
- }
- FXSYS_memcpy32(str, src, src.GetLength());
- str[src.GetLength()] = '\0';
- *(FX_LPSTR*)(&m_Ptr) = str;
- m_Length = src.GetLength();
- }
-}
diff --git a/core/src/fxcrt/fx_basic_buffer.cpp b/core/src/fxcrt/fx_basic_buffer.cpp
index 4427857b27..1734423253 100644
--- a/core/src/fxcrt/fx_basic_buffer.cpp
+++ b/core/src/fxcrt/fx_basic_buffer.cpp
@@ -1,31 +1,29 @@
// Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-
+
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#include "../../include/fxcrt/fx_basic.h"
FX_STRSIZE FX_ftoa(FX_FLOAT f, FX_LPSTR buf);
-CFX_BinaryBuf::CFX_BinaryBuf(IFX_Allocator* pAllocator)
- : m_pAllocator(pAllocator)
- , m_AllocStep(0)
+CFX_BinaryBuf::CFX_BinaryBuf()
+ : m_AllocStep(0)
, m_pBuffer(NULL)
, m_DataSize(0)
, m_AllocSize(0)
{
}
-CFX_BinaryBuf::CFX_BinaryBuf(FX_STRSIZE size, IFX_Allocator* pAllocator)
- : m_pAllocator(pAllocator)
- , m_AllocStep(0)
+CFX_BinaryBuf::CFX_BinaryBuf(FX_STRSIZE size)
+ : m_AllocStep(0)
, m_DataSize(size)
, m_AllocSize(size)
{
- m_pBuffer = FX_Allocator_Alloc(m_pAllocator, FX_BYTE, size);
+ m_pBuffer = FX_Alloc(FX_BYTE, size);
}
CFX_BinaryBuf::~CFX_BinaryBuf()
{
if (m_pBuffer) {
- FX_Allocator_Free(m_pAllocator, m_pBuffer);
+ FX_Free(m_pBuffer);
}
}
void CFX_BinaryBuf::Delete(int start_index, int count)
@@ -49,7 +47,7 @@ void CFX_BinaryBuf::DetachBuffer()
void CFX_BinaryBuf::AttachData(void* buffer, FX_STRSIZE size)
{
if (m_pBuffer) {
- FX_Allocator_Free(m_pAllocator, m_pBuffer);
+ FX_Free(m_pBuffer);
}
m_DataSize = size;
m_pBuffer = (FX_LPBYTE)buffer;
@@ -86,9 +84,9 @@ void CFX_BinaryBuf::ExpandBuf(FX_STRSIZE add_size)
new_size = (new_size + alloc_step - 1) / alloc_step * alloc_step;
FX_LPBYTE pNewBuffer = m_pBuffer;
if (pNewBuffer) {
- pNewBuffer = FX_Allocator_Realloc(m_pAllocator, FX_BYTE, m_pBuffer, new_size);
+ pNewBuffer = FX_Realloc(FX_BYTE, m_pBuffer, new_size);
} else {
- pNewBuffer = FX_Allocator_Alloc(m_pAllocator, FX_BYTE, new_size);
+ pNewBuffer = FX_Alloc(FX_BYTE, new_size);
}
if (pNewBuffer) {
m_pBuffer = pNewBuffer;
@@ -143,10 +141,6 @@ CFX_ByteStringC CFX_BinaryBuf::GetByteString() const
{
return CFX_ByteStringC(m_pBuffer, m_DataSize);
}
-void CFX_BinaryBuf::GetByteStringL(CFX_ByteStringL &str) const
-{
- str.Set(CFX_ByteStringC(m_pBuffer, m_DataSize), m_pAllocator);
-}
CFX_ByteTextBuf& CFX_ByteTextBuf::operator << (FX_BSTR lpsz)
{
AppendBlock((FX_LPCBYTE)lpsz, lpsz.GetLength());
@@ -250,10 +244,6 @@ CFX_WideStringC CFX_WideTextBuf::GetWideString() const
{
return CFX_WideStringC((FX_LPCWSTR)m_pBuffer, m_DataSize / sizeof(FX_WCHAR));
}
-void CFX_WideTextBuf::GetWideStringL(CFX_WideStringL& wideText) const
-{
- wideText.Set(CFX_WideStringC((FX_LPCWSTR)m_pBuffer, m_DataSize / sizeof(FX_WCHAR)), m_pAllocator);
-}
CFX_ArchiveSaver& CFX_ArchiveSaver::operator << (FX_BYTE i)
{
if (m_pStream) {
@@ -439,9 +429,8 @@ FX_DWORD CFX_BitStream::GetBits(FX_DWORD nBits)
m_BitPos += nBits;
return result;
}
-IFX_BufferArchive::IFX_BufferArchive(FX_STRSIZE size, IFX_Allocator* pAllocator)
- : m_pAllocator(pAllocator)
- , m_BufSize(size)
+IFX_BufferArchive::IFX_BufferArchive(FX_STRSIZE size)
+ : m_BufSize(size)
, m_pBuffer(NULL)
, m_Length(0)
{
@@ -450,7 +439,7 @@ void IFX_BufferArchive::Clear()
{
m_Length = 0;
if (m_pBuffer) {
- FX_Allocator_Free(m_pAllocator, m_pBuffer);
+ FX_Free(m_pBuffer);
m_pBuffer = NULL;
}
}
@@ -466,7 +455,7 @@ FX_INT32 IFX_BufferArchive::AppendBlock(const void* pBuf, size_t size)
return 0;
}
if (!m_pBuffer) {
- m_pBuffer = FX_Allocator_Alloc(m_pAllocator, FX_BYTE, m_BufSize);
+ m_pBuffer = FX_Alloc(FX_BYTE, m_BufSize);
if (!m_pBuffer) {
return -1;
}
@@ -501,8 +490,8 @@ FX_INT32 IFX_BufferArchive::AppendString(FX_BSTR lpsz)
{
return AppendBlock((FX_LPCBYTE)lpsz, lpsz.GetLength());
}
-CFX_FileBufferArchive::CFX_FileBufferArchive(FX_STRSIZE size, IFX_Allocator* pAllocator)
- : IFX_BufferArchive(size, pAllocator)
+CFX_FileBufferArchive::CFX_FileBufferArchive(FX_STRSIZE size)
+ : IFX_BufferArchive(size)
, m_pFile(NULL)
, m_bTakeover(FALSE)
{
diff --git a/core/src/fxcrt/fx_basic_list.cpp b/core/src/fxcrt/fx_basic_list.cpp
index bf7091268b..c9619f99b7 100644
--- a/core/src/fxcrt/fx_basic_list.cpp
+++ b/core/src/fxcrt/fx_basic_list.cpp
@@ -1,14 +1,13 @@
// Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-
+
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#include "../../include/fxcrt/fx_basic.h"
#include "plex.h"
-CFX_PtrList::CFX_PtrList(int nBlockSize, IFX_Allocator* pAllocator)
- : m_pAllocator(pAllocator)
- , m_pNodeHead(NULL)
+CFX_PtrList::CFX_PtrList(int nBlockSize)
+ : m_pNodeHead(NULL)
, m_pNodeTail(NULL)
, m_nCount(0)
, m_pNodeFree(NULL)
@@ -84,14 +83,14 @@ void CFX_PtrList::RemoveAll()
{
m_nCount = 0;
m_pNodeHead = m_pNodeTail = m_pNodeFree = NULL;
- m_pBlocks->FreeDataChain(m_pAllocator);
+ m_pBlocks->FreeDataChain();
m_pBlocks = NULL;
}
CFX_PtrList::CNode*
CFX_PtrList::NewNode(CFX_PtrList::CNode* pPrev, CFX_PtrList::CNode* pNext)
{
if (m_pNodeFree == NULL) {
- CFX_Plex* pNewBlock = CFX_Plex::Create(m_pAllocator, m_pBlocks, m_nBlockSize, sizeof(CNode));
+ CFX_Plex* pNewBlock = CFX_Plex::Create(m_pBlocks, m_nBlockSize, sizeof(CNode));
CNode* pNode = (CNode*)pNewBlock->data();
pNode += m_nBlockSize - 1;
for (int i = m_nBlockSize - 1; i >= 0; i--, pNode--) {
diff --git a/core/src/fxcrt/fx_basic_maps.cpp b/core/src/fxcrt/fx_basic_maps.cpp
index a0b1788a82..e85d35e4ac 100644
--- a/core/src/fxcrt/fx_basic_maps.cpp
+++ b/core/src/fxcrt/fx_basic_maps.cpp
@@ -1,7 +1,7 @@
// Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-
+
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#include "../../include/fxcrt/fx_ext.h"
@@ -14,9 +14,8 @@ static void DestructElement(CFX_ByteString* pOldData)
{
pOldData->~CFX_ByteString();
}
-CFX_MapPtrToPtr::CFX_MapPtrToPtr(int nBlockSize, IFX_Allocator* pAllocator)
- : m_pAllocator(pAllocator)
- , m_pHashTable(NULL)
+CFX_MapPtrToPtr::CFX_MapPtrToPtr(int nBlockSize)
+ : m_pHashTable(NULL)
, m_nHashTableSize(17)
, m_nCount(0)
, m_pFreeList(NULL)
@@ -28,12 +27,12 @@ CFX_MapPtrToPtr::CFX_MapPtrToPtr(int nBlockSize, IFX_Allocator* pAllocator)
void CFX_MapPtrToPtr::RemoveAll()
{
if (m_pHashTable) {
- FX_Allocator_Free(m_pAllocator, m_pHashTable);
+ FX_Free(m_pHashTable);
m_pHashTable = NULL;
}
m_nCount = 0;
m_pFreeList = NULL;
- m_pBlocks->FreeDataChain(m_pAllocator);
+ m_pBlocks->FreeDataChain();
m_pBlocks = NULL;
}
CFX_MapPtrToPtr::~CFX_MapPtrToPtr()
@@ -122,7 +121,7 @@ CFX_MapPtrToPtr::CAssoc*
CFX_MapPtrToPtr::NewAssoc()
{
if (m_pFreeList == NULL) {
- CFX_Plex* newBlock = CFX_Plex::Create(m_pAllocator, m_pBlocks, m_nBlockSize, sizeof(CFX_MapPtrToPtr::CAssoc));
+ CFX_Plex* newBlock = CFX_Plex::Create(m_pBlocks, m_nBlockSize, sizeof(CFX_MapPtrToPtr::CAssoc));
CFX_MapPtrToPtr::CAssoc* pAssoc = (CFX_MapPtrToPtr::CAssoc*)newBlock->data();
pAssoc += m_nBlockSize - 1;
for (int i = m_nBlockSize - 1; i >= 0; i--, pAssoc--) {
@@ -145,14 +144,11 @@ void CFX_MapPtrToPtr::InitHashTable(
ASSERT(m_nCount == 0);
ASSERT(nHashSize > 0);
if (m_pHashTable != NULL) {
- FX_Allocator_Free(m_pAllocator, m_pHashTable);
+ FX_Free(m_pHashTable);
m_pHashTable = NULL;
}
if (bAllocNow) {
- m_pHashTable = FX_Allocator_Alloc(m_pAllocator, CAssoc*, nHashSize);
- if (m_pHashTable) {
- FXSYS_memset32(m_pHashTable, 0, sizeof(CAssoc*) * nHashSize);
- }
+ m_pHashTable = FX_Alloc(CAssoc*, nHashSize);
}
m_nHashTableSize = nHashSize;
}
@@ -184,9 +180,8 @@ void CFX_MapPtrToPtr::FreeAssoc(CFX_MapPtrToPtr::CAssoc* pAssoc)
RemoveAll();
}
}
-CFX_MapByteStringToPtr::CFX_MapByteStringToPtr(int nBlockSize, IFX_Allocator* pAllocator)
- : m_pAllocator(pAllocator)
- , m_pHashTable(NULL)
+CFX_MapByteStringToPtr::CFX_MapByteStringToPtr(int nBlockSize)
+ : m_pHashTable(NULL)
, m_nHashTableSize(17)
, m_nCount(0)
, m_pFreeList(NULL)
@@ -205,12 +200,12 @@ void CFX_MapByteStringToPtr::RemoveAll()
DestructElement(&pAssoc->key);
}
}
- FX_Allocator_Free(m_pAllocator, m_pHashTable);
+ FX_Free(m_pHashTable);
m_pHashTable = NULL;
}
m_nCount = 0;
m_pFreeList = NULL;
- m_pBlocks->FreeDataChain(m_pAllocator);
+ m_pBlocks->FreeDataChain();
m_pBlocks = NULL;
}
CFX_MapByteStringToPtr::~CFX_MapByteStringToPtr()
@@ -286,7 +281,7 @@ CFX_MapByteStringToPtr::CAssoc*
CFX_MapByteStringToPtr::NewAssoc()
{
if (m_pFreeList == NULL) {
- CFX_Plex* newBlock = CFX_Plex::Create(m_pAllocator, m_pBlocks, m_nBlockSize, sizeof(CFX_MapByteStringToPtr::CAssoc));
+ CFX_Plex* newBlock = CFX_Plex::Create(m_pBlocks, m_nBlockSize, sizeof(CFX_MapByteStringToPtr::CAssoc));
CFX_MapByteStringToPtr::CAssoc* pAssoc = (CFX_MapByteStringToPtr::CAssoc*)newBlock->data();
pAssoc += m_nBlockSize - 1;
for (int i = m_nBlockSize - 1; i >= 0; i--, pAssoc--) {
@@ -345,14 +340,11 @@ void CFX_MapByteStringToPtr::InitHashTable(
ASSERT(m_nCount == 0);
ASSERT(nHashSize > 0);
if (m_pHashTable != NULL) {
- FX_Allocator_Free(m_pAllocator, m_pHashTable);
+ FX_Free(m_pHashTable);
m_pHashTable = NULL;
}
if (bAllocNow) {
- m_pHashTable = FX_Allocator_Alloc(m_pAllocator, CAssoc*, nHashSize);
- if (m_pHashTable) {
- FXSYS_memset32(m_pHashTable, 0, sizeof(CAssoc*) * nHashSize);
- }
+ m_pHashTable = FX_Alloc(CAssoc*, nHashSize);
}
m_nHashTableSize = nHashSize;
}
@@ -391,10 +383,10 @@ struct _CompactString {
FX_BYTE m_Unused;
FX_LPBYTE m_pBuffer;
};
-static void _CompactStringRelease(IFX_Allocator* pAllocator, _CompactString* pCompact)
+static void _CompactStringRelease(_CompactString* pCompact)
{
if (pCompact->m_CompactLen == 0xff) {
- FX_Allocator_Free(pAllocator, pCompact->m_pBuffer);
+ FX_Free(pCompact->m_pBuffer);
}
}
static FX_BOOL _CompactStringSame(_CompactString* pCompact, FX_LPCBYTE pStr, int len)
@@ -410,7 +402,7 @@ static FX_BOOL _CompactStringSame(_CompactString* pCompact, FX_LPCBYTE pStr, int
}
return FXSYS_memcmp32(pCompact->m_pBuffer, pStr, len) == 0;
}
-static void _CompactStringStore(IFX_Allocator* pAllocator, _CompactString* pCompact, FX_LPCBYTE pStr, int len)
+static void _CompactStringStore(_CompactString* pCompact, FX_LPCBYTE pStr, int len)
{
if (len < (int)sizeof(_CompactString)) {
pCompact->m_CompactLen = (FX_BYTE)len;
@@ -420,7 +412,7 @@ static void _CompactStringStore(IFX_Allocator* pAllocator, _CompactString* pComp
pCompact->m_CompactLen = 0xff;
pCompact->m_LenHigh = len / 256;
pCompact->m_LenLow = len % 256;
- pCompact->m_pBuffer = FX_Allocator_Alloc(pAllocator, FX_BYTE, len);
+ pCompact->m_pBuffer = FX_Alloc(FX_BYTE, len);
if (pCompact->m_pBuffer) {
FXSYS_memcpy32(pCompact->m_pBuffer, pStr, len);
}
@@ -437,8 +429,8 @@ static CFX_ByteStringC _CompactStringGet(_CompactString* pCompact)
}
#define CMAP_ALLOC_STEP 8
#define CMAP_INDEX_SIZE 8
-CFX_CMapByteStringToPtr::CFX_CMapByteStringToPtr(IFX_Allocator* pAllocator)
- : m_Buffer(sizeof(_CompactString) + sizeof(void*), CMAP_ALLOC_STEP, CMAP_INDEX_SIZE, pAllocator)
+CFX_CMapByteStringToPtr::CFX_CMapByteStringToPtr()
+ : m_Buffer(sizeof(_CompactString) + sizeof(void*), CMAP_ALLOC_STEP, CMAP_INDEX_SIZE)
{
}
CFX_CMapByteStringToPtr::~CFX_CMapByteStringToPtr()
@@ -447,10 +439,9 @@ CFX_CMapByteStringToPtr::~CFX_CMapByteStringToPtr()
}
void CFX_CMapByteStringToPtr::RemoveAll()
{
- IFX_Allocator* pAllocator = m_Buffer.m_pAllocator;
int size = m_Buffer.GetSize();
- for (int i = 0; i < size; i ++) {
- _CompactStringRelease(pAllocator, (_CompactString*)m_Buffer.GetAt(i));
+ for (int i = 0; i < size; i++) {
+ _CompactStringRelease((_CompactString*)m_Buffer.GetAt(i));
}
m_Buffer.RemoveAll();
}
@@ -533,38 +524,36 @@ void CFX_CMapByteStringToPtr::SetAt(FX_BSTR key, void* value)
*(void**)(pKey + 1) = value;
return;
}
- IFX_Allocator* pAllocator = m_Buffer.m_pAllocator;
for (index = 0; index < size; index ++) {
_CompactString* pKey = (_CompactString*)m_Buffer.GetAt(index);
if (pKey->m_CompactLen) {
continue;
}
- _CompactStringStore(pAllocator, pKey, (FX_LPCBYTE)key, key_len);
+ _CompactStringStore(pKey, (FX_LPCBYTE)key, key_len);
*(void**)(pKey + 1) = value;
return;
}
_CompactString* pKey = (_CompactString*)m_Buffer.Add();
- _CompactStringStore(pAllocator, pKey, (FX_LPCBYTE)key, key_len);
+ _CompactStringStore(pKey, (FX_LPCBYTE)key, key_len);
*(void**)(pKey + 1) = value;
}
void CFX_CMapByteStringToPtr::AddValue(FX_BSTR key, void* value)
{
ASSERT(value != NULL);
_CompactString* pKey = (_CompactString*)m_Buffer.Add();
- _CompactStringStore(m_Buffer.m_pAllocator, pKey, (FX_LPCBYTE)key, key.GetLength());
+ _CompactStringStore(pKey, (FX_LPCBYTE)key, key.GetLength());
*(void**)(pKey + 1) = value;
}
void CFX_CMapByteStringToPtr::RemoveKey(FX_BSTR key)
{
int key_len = key.GetLength();
- IFX_Allocator* pAllocator = m_Buffer.m_pAllocator;
int size = m_Buffer.GetSize();
- for (int index = 0; index < size; index ++) {
+ for (int index = 0; index < size; index++) {
_CompactString* pKey = (_CompactString*)m_Buffer.GetAt(index);
if (!_CompactStringSame(pKey, (FX_LPCBYTE)key, key_len)) {
continue;
}
- _CompactStringRelease(pAllocator, pKey);
+ _CompactStringRelease(pKey);
pKey->m_CompactLen = 0xfe;
return;
}
diff --git a/core/src/fxcrt/fx_basic_memmgr.cpp b/core/src/fxcrt/fx_basic_memmgr.cpp
index 1021ab7adf..3b3211c20f 100644
--- a/core/src/fxcrt/fx_basic_memmgr.cpp
+++ b/core/src/fxcrt/fx_basic_memmgr.cpp
@@ -1,307 +1,37 @@
// Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-
+
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#include "../../include/fxcrt/fx_basic.h"
-#include "mem_int.h"
-
-void FXMEM_DestroyFoxitMgr(FXMEM_FoxitMgr* pFoxitMgr)
-{
- if (pFoxitMgr == NULL) {
- return;
- }
- CFX_MemoryMgr* p = (CFX_MemoryMgr*)pFoxitMgr;
- if (p->m_pSystemMgr->CollectAll) {
- p->m_pSystemMgr->CollectAll(p->m_pSystemMgr);
- }
- if (p->m_bReleaseMgr) {
- p->m_pSystemMgr->Free(p->m_pSystemMgr, p, 0);
- }
- if (p->m_pExternalMemory) {
- free(p->m_pExternalMemory);
- }
-}
#ifdef __cplusplus
extern "C" {
#endif
-static void* _DefAllocDebug(IFX_Allocator* pAllocator, size_t num, size_t size, FX_LPCSTR filename, int line)
-{
- if (size == 0 || num > SIZE_MAX/size)
- return NULL;
-
- size = size * num;
- return ((FX_DefAllocator*)pAllocator)->m_pFoxitMgr->AllocDebug(size, 0, filename, line);
-}
-static void* _DefAlloc(IFX_Allocator* pAllocator, size_t num, size_t size)
-{
- if (size == 0 || num > SIZE_MAX/size)
- return NULL;
-
- size = size * num;
- return ((FX_DefAllocator*)pAllocator)->m_pFoxitMgr->Alloc(size, 0);
-}
-static void* _DefReallocDebug(IFX_Allocator* pAllocator, void* p, size_t new_num, size_t size, FX_LPCSTR filename, int line)
+void* FXMEM_DefaultAlloc(size_t byte_size, int flags)
{
- if (size == 0 || new_num > SIZE_MAX/size)
- return NULL;
-
- size = size * new_num;
- return ((FX_DefAllocator*)pAllocator)->m_pFoxitMgr->ReallocDebug(p, size, 0, filename, line);
+ return (void*)malloc(byte_size);
}
-static void* _DefRealloc(IFX_Allocator* pAllocator, void* p, size_t new_num, size_t size)
+void* FXMEM_DefaultRealloc(void* pointer, size_t new_size, int flags)
{
- if (size == 0 || new_num > SIZE_MAX/size)
- return NULL;
-
- size = size * new_num;
- return ((FX_DefAllocator*)pAllocator)->m_pFoxitMgr->Realloc(p, size, 0);
+ return realloc(pointer, new_size);
}
-static void _DefFree(IFX_Allocator* pAllocator, void* p)
+void FXMEM_DefaultFree(void* pointer, int flags)
{
- ((FX_DefAllocator*)pAllocator)->m_pFoxitMgr->Free(p, 0);
+ free(pointer);
}
#ifdef __cplusplus
}
#endif
-void CFX_MemoryMgr::Init(FXMEM_SystemMgr* pSystemMgr)
-{
- m_pSystemMgr = pSystemMgr;
- IFX_Allocator &ac = m_DefAllocator.m_Allocator;
- ac.m_Alloc = _DefAlloc;
- ac.m_AllocDebug = _DefAllocDebug;
- ac.m_Realloc = _DefRealloc;
- ac.m_ReallocDebug = _DefReallocDebug;
- ac.m_Free = _DefFree;
- m_DefAllocator.m_pFoxitMgr = this;
- m_pExternalMemory = NULL;
- m_bReleaseMgr = TRUE;
-}
-void CFX_MemoryMgr::PurgeMgr()
-{
- if (m_pSystemMgr->Purge) {
- m_pSystemMgr->Purge(m_pSystemMgr);
- }
-}
-void* CFX_MemoryMgr::Alloc(size_t size, int flags)
-{
- void* p = m_pSystemMgr->Alloc(m_pSystemMgr, size, flags);
- if (p == NULL) {
- return NULL;
- }
- return p;
-}
-void* CFX_MemoryMgr::AllocDebug(size_t size, int flags, FX_LPCSTR file, int line)
-{
- void* p = m_pSystemMgr->AllocDebug(m_pSystemMgr, size, flags, file, line);
- if (p == NULL) {
- return NULL;
- }
- return p;
-}
-void* CFX_MemoryMgr::Realloc(void* p, size_t size, int flags)
-{
- void* p1 = m_pSystemMgr->Realloc(m_pSystemMgr, p, size, flags);
- if (p1 == NULL) {
- return NULL;
- }
- return p1;
-}
-void* CFX_MemoryMgr::ReallocDebug(void* p, size_t size, int flags, FX_LPCSTR file, int line)
-{
- void* p1 = m_pSystemMgr->ReallocDebug(m_pSystemMgr, p, size, flags, file, line);
- if (p1 == NULL) {
- return NULL;
- }
- return p1;
-}
-void CFX_MemoryMgr::Free(void* p, int flags)
-{
- if (p == NULL) {
- return;
- }
- m_pSystemMgr->Free(m_pSystemMgr, p, flags);
-}
-CFX_MemoryMgr* g_pDefFoxitMgr = NULL;
-void* FXMEM_DefaultAlloc(size_t size, int flags)
-{
- return g_pDefFoxitMgr->Alloc(size, flags);
-}
-void* FXMEM_DefaultAlloc2(size_t size, size_t unit, int flags)
-{
- return g_pDefFoxitMgr->Alloc(size * unit, flags);
-}
-void* FXMEM_DefaultRealloc(void* p, size_t size, int flags)
-{
- if (p == NULL) {
- return FXMEM_DefaultAlloc(size, flags);
- }
- return g_pDefFoxitMgr->Realloc(p, size, flags);
-}
-void* FXMEM_DefaultRealloc2(void* p, size_t size, size_t unit, int flags)
-{
- if (p == NULL) {
- return FXMEM_DefaultAlloc2(size, unit, flags);
- }
- return g_pDefFoxitMgr->Realloc(p, size * unit, flags);
-}
-void* FXMEM_DefaultAllocDebug(size_t size, int flags, FX_LPCSTR file, int line)
-{
- return g_pDefFoxitMgr->AllocDebug(size, flags, file, line);
-}
-void* FXMEM_DefaultAllocDebug2(size_t size, size_t unit, int flags, FX_LPCSTR file, int line)
-{
- return g_pDefFoxitMgr->AllocDebug(size * unit, flags, file, line);
-}
-void* FXMEM_DefaultReallocDebug(void* p, size_t size, int flags, FX_LPCSTR file, int line)
-{
- if (p == NULL) {
- return FXMEM_DefaultAllocDebug(size, flags, file, line);
- }
- return g_pDefFoxitMgr->ReallocDebug(p, size, flags, file, line);
-}
-void* FXMEM_DefaultReallocDebug2(void* p, size_t size, size_t unit, int flags, FX_LPCSTR file, int line)
-{
- if (p == NULL) {
- return FXMEM_DefaultAllocDebug2(size, unit, flags, file, line);
- }
- return g_pDefFoxitMgr->ReallocDebug(p, size * unit, flags, file, line);
-}
-void FXMEM_DefaultFree(void* p, int flags)
-{
- g_pDefFoxitMgr->Free(p, flags);
-}
-IFX_Allocator* FXMEM_GetDefAllocator()
-{
- return &g_pDefFoxitMgr->m_DefAllocator.m_Allocator;
-}
-void* CFX_Object::operator new(size_t size)
-{
- return g_pDefFoxitMgr->Alloc(size, 0);
-}
-void* CFX_Object::operator new[](size_t size)
-{
- return g_pDefFoxitMgr->Alloc(size, 0);
-}
-void* CFX_Object::operator new[](size_t size, FX_LPCSTR file, int line)
-{
- return g_pDefFoxitMgr->AllocDebug(size, 0, file, line);
-}
-void* CFX_Object::operator new(size_t size, FX_LPCSTR file, int line)
-{
- return g_pDefFoxitMgr->AllocDebug(size, 0, file, line);
-}
-void CFX_Object::operator delete(void* p)
-{
- g_pDefFoxitMgr->Free(p, 0);
-}
-void CFX_Object::operator delete[](void* p)
-{
- g_pDefFoxitMgr->Free(p, 0);
-}
-void CFX_Object::operator delete(void* p, FX_LPCSTR file, int line)
-{
- g_pDefFoxitMgr->Free(p, 0);
-}
-void CFX_Object::operator delete[](void* p, FX_LPCSTR file, int line)
-{
- g_pDefFoxitMgr->Free(p, 0);
-}
-void* CFX_AllocObject::operator new(size_t size, IFX_Allocator* pAllocator, FX_LPCSTR filename, int line)
-{
- void* p = pAllocator ? pAllocator->m_AllocDebug(pAllocator, size, 1, filename, line) :
- g_pDefFoxitMgr->AllocDebug(size, 0, filename, line);
- ((CFX_AllocObject*)p)->m_pAllocator = pAllocator;
- return p;
-}
-void CFX_AllocObject::operator delete (void* p, IFX_Allocator* pAllocator, FX_LPCSTR filename, int line)
-{
- if (pAllocator) {
- pAllocator->m_Free(pAllocator, p);
- } else {
- g_pDefFoxitMgr->Free(p, 0);
- }
-}
-void* CFX_AllocObject::operator new(size_t size, IFX_Allocator* pAllocator)
-{
- void* p = pAllocator ? pAllocator->m_Alloc(pAllocator, size, 1) : g_pDefFoxitMgr->Alloc(size, 0);
- ((CFX_AllocObject*)p)->m_pAllocator = pAllocator;
- return p;
-}
-void CFX_AllocObject::operator delete(void* p)
-{
- if (((CFX_AllocObject*)p)->m_pAllocator) {
- (((CFX_AllocObject*)p)->m_pAllocator)->m_Free(((CFX_AllocObject*)p)->m_pAllocator, p);
- } else {
- g_pDefFoxitMgr->Free(p, 0);
- }
-}
-void CFX_AllocObject::operator delete(void* p, IFX_Allocator* pAllocator)
-{
- if (pAllocator) {
- pAllocator->m_Free(pAllocator, p);
- } else {
- g_pDefFoxitMgr->Free(p, 0);
- }
-}
-extern "C" {
- static void* _GOPAllocDebug(IFX_Allocator* pAllocator, size_t num, size_t size, FX_LPCSTR file, int line)
- {
- if (size == 0 || num > SIZE_MAX/size)
- return NULL;
-
- size = size * num;
- return ((CFX_GrowOnlyPool*)pAllocator)->Alloc(size);
- }
- static void* _GOPAlloc(IFX_Allocator* pAllocator, size_t num, size_t size)
- {
- if (size == 0 || num > SIZE_MAX/size)
- return NULL;
-
- size = size * num;
- return ((CFX_GrowOnlyPool*)pAllocator)->Alloc(size);
- }
- static void* _GOPReallocDebug(IFX_Allocator* pAllocator, void* p, size_t new_num, size_t size, FX_LPCSTR file, int line)
- {
- if (size == 0 || new_num > SIZE_MAX/size)
- return NULL;
-
- size = size * new_num;
- return ((CFX_GrowOnlyPool*)pAllocator)->Realloc(p, size);
- }
- static void* _GOPRealloc(IFX_Allocator* pAllocator, void* p, size_t new_num, size_t size)
- {
- if (size == 0 || new_num > SIZE_MAX/size)
- return NULL;
-
- size = size * new_num;
- return ((CFX_GrowOnlyPool*)pAllocator)->Realloc(p, size);
- }
- static void _GOPFree(IFX_Allocator* pAllocator, void* p)
- {
- }
-};
-CFX_GrowOnlyPool::CFX_GrowOnlyPool(IFX_Allocator* pAllocator, size_t trunk_size)
+CFX_GrowOnlyPool::CFX_GrowOnlyPool(size_t trunk_size)
{
m_TrunkSize = trunk_size;
m_pFirstTrunk = NULL;
- m_pAllocator = pAllocator ? pAllocator : &g_pDefFoxitMgr->m_DefAllocator.m_Allocator;
- m_AllocDebug = _GOPAllocDebug;
- m_Alloc = _GOPAlloc;
- m_ReallocDebug = _GOPReallocDebug;
- m_Realloc = _GOPRealloc;
- m_Free = _GOPFree;
}
CFX_GrowOnlyPool::~CFX_GrowOnlyPool()
{
FreeAll();
}
-void CFX_GrowOnlyPool::SetAllocator(IFX_Allocator* pAllocator)
-{
- ASSERT(m_pFirstTrunk == NULL);
- m_pAllocator = pAllocator ? pAllocator : &g_pDefFoxitMgr->m_DefAllocator.m_Allocator;
-}
struct _FX_GrowOnlyTrunk {
size_t m_Size;
size_t m_Allocated;
@@ -312,7 +42,7 @@ void CFX_GrowOnlyPool::FreeAll()
_FX_GrowOnlyTrunk* pTrunk = (_FX_GrowOnlyTrunk*)m_pFirstTrunk;
while (pTrunk) {
_FX_GrowOnlyTrunk* pNext = pTrunk->m_pNext;
- m_pAllocator->m_Free(m_pAllocator, pTrunk);
+ FX_Free(pTrunk);
pTrunk = pNext;
}
m_pFirstTrunk = NULL;
@@ -330,11 +60,7 @@ void* CFX_GrowOnlyPool::Alloc(size_t size)
pTrunk = pTrunk->m_pNext;
}
size_t alloc_size = size > m_TrunkSize ? size : m_TrunkSize;
-
- if (alloc_size > SIZE_MAX - sizeof(_FX_GrowOnlyTrunk) )
- return NULL;
-
- pTrunk = (_FX_GrowOnlyTrunk*)m_pAllocator->m_Alloc(m_pAllocator, sizeof(_FX_GrowOnlyTrunk) + alloc_size, 1);
+ pTrunk = (_FX_GrowOnlyTrunk*)FX_Alloc(FX_BYTE, sizeof(_FX_GrowOnlyTrunk) + alloc_size);
pTrunk->m_Size = alloc_size;
pTrunk->m_Allocated = size;
pTrunk->m_pNext = (_FX_GrowOnlyTrunk*)m_pFirstTrunk;
diff --git a/core/src/fxcrt/fx_basic_memmgr_mini.cpp b/core/src/fxcrt/fx_basic_memmgr_mini.cpp
deleted file mode 100644
index 8d48bab935..0000000000
--- a/core/src/fxcrt/fx_basic_memmgr_mini.cpp
+++ /dev/null
@@ -1,822 +0,0 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/fxcrt/fx_ext.h"
-#include "mem_int.h"
-#ifdef _FPDFAPI_MINI_
-static FX_MEMCONFIG g_MemConfig = {
- 1,
- 5,
- 8,
- 4,
- 12,
- 8,
- 2,
- 4,
- 32,
- 64,
-};
-#else
-static FX_MEMCONFIG g_MemConfig = {
- 1,
- 8,
- 24,
- 8,
- 32,
- 16,
- 4,
- 8,
- 128,
- 64,
-};
-#endif
-void FXMEM_SetConfig(const FX_MEMCONFIG* memConfig)
-{
- g_MemConfig = *memConfig;
-}
-#ifdef __cplusplus
-extern "C" {
-#endif
-static void* FixedAlloc(FXMEM_SystemMgr* pMgr, size_t size, int flags)
-{
- return ((CFXMEM_FixedMgr*)pMgr->user)->Alloc(size);
-}
-static void* FixedAllocDebug(FXMEM_SystemMgr* pMgr, size_t size, int flags, FX_LPCSTR file, int line)
-{
- return ((CFXMEM_FixedMgr*)pMgr->user)->Alloc(size);
-}
-static void* FixedRealloc(FXMEM_SystemMgr* pMgr, void* pointer, size_t size, int flags)
-{
- return ((CFXMEM_FixedMgr*)pMgr->user)->Realloc(pointer, size);
-}
-static void* FixedReallocDebug(FXMEM_SystemMgr* pMgr, void* pointer, size_t size, int flags, FX_LPCSTR file, int line)
-{
- return ((CFXMEM_FixedMgr*)pMgr->user)->Realloc(pointer, size);
-}
-static void FixedFree(FXMEM_SystemMgr* pMgr, void* pointer, int flags)
-{
- ((CFXMEM_FixedMgr*)pMgr->user)->Free(pointer);
-}
-static void FixedPurge(FXMEM_SystemMgr* pMgr)
-{
- ((CFXMEM_FixedMgr*)pMgr->user)->Purge();
-}
-static void FixedCollectAll(FXMEM_SystemMgr* pMgr)
-{
- ((CFXMEM_FixedMgr*)pMgr->user)->FreeAll();
-}
-#define FIXEDMEM_MINIMUMSIZE (1024 * 1024 * 8)
-FXMEM_FoxitMgr* FXMEM_CreateMemoryMgr(size_t size, FX_BOOL extensible)
-{
- if (size < FIXEDMEM_MINIMUMSIZE) {
- size = FIXEDMEM_MINIMUMSIZE;
- }
- FX_LPVOID pMemory = malloc(size);
- if (!pMemory) {
- return NULL;
- }
- CFixedMgr_Proxy* pProxy = (CFixedMgr_Proxy*)pMemory;
- size_t offsetSize = (sizeof(CFixedMgr_Proxy) + 15) / 16 * 16;
- FXMEM_FoxitMgr* pFoxitMgr = pProxy->Initialize((FX_LPBYTE)pProxy + offsetSize, size - offsetSize, extensible);
- if (!pFoxitMgr) {
- free(pMemory);
- return NULL;
- }
- g_pDefFoxitMgr = (CFX_MemoryMgr*)pFoxitMgr;
- g_pDefFoxitMgr->m_pExternalMemory = pMemory;
- return pFoxitMgr;
-}
-FXMEM_FoxitMgr* FXMEM_CreateFixedMgr(void* pMemory, size_t size, FXMEM_SystemMgr2* pSystemMgr)
-{
- if (pMemory == NULL || size < FX_FIXEDMEM_PAGESIZE) {
- return NULL;
- }
- if (!pSystemMgr && size >= FIXEDMEM_PROXYSIZE_1) {
- CFixedMgr_Proxy* pProxy = (CFixedMgr_Proxy*)pMemory;
- size_t offsetSize = (sizeof(CFixedMgr_Proxy) + 15) / 16 * 16;
- return pProxy->Initialize((FX_LPBYTE)pProxy + offsetSize, size - offsetSize, FALSE);
- }
- CFXMEM_FixedMgr* pHeader = (CFXMEM_FixedMgr*)pMemory;
- pHeader->Initialize(size);
- pHeader->m_pExtender = pSystemMgr;
- CFX_MemoryMgr* p = (CFX_MemoryMgr*)pHeader->Alloc(sizeof(CFX_MemoryMgr));
- if (p == NULL) {
- return NULL;
- }
- p->Init(&pHeader->m_SystemMgr);
- return (FXMEM_FoxitMgr*)p;
-}
-size_t FXMEM_GetBlockSizeInFixedMgr(FXMEM_FoxitMgr* pFoxitMgr, void* ptr)
-{
- return pFoxitMgr ? ((CFXMEM_FixedMgr*)((CFX_MemoryMgr*)pFoxitMgr)->m_pSystemMgr->user)->GetSize(ptr) : 0;
-}
-#ifdef __cplusplus
-}
-#endif
-const FX_MEMCONFIG g_ProxyMgr_MemConfigs[6] = {
- {1, 2, 4, 0, 2, 2, 2, 0, 0, 0},
- {1, 4, 8, 0, 2, 2, 2, 0, 0, 0},
- {1, 4, 16, 4, 8, 8, 2, 1, 16, 16},
- {1, 8, 24, 4, 12, 12, 4, 2, 32, 16},
- {1, 8, 24, 8, 16, 16, 4, 2, 64, 32},
- {1, 8, 24, 8, 24, 32, 4, 2, 128, 64},
-};
-const FX_MEMCONFIG* FixedMgr_GetConfig(size_t nSize)
-{
- int index = 5;
- if (nSize <= FIXEDMEM_PROXYSIZE_0) {
- index = 0;
- } else if (nSize <= FIXEDMEM_PROXYSIZE_1) {
- index = 1;
- } else if (nSize <= FIXEDMEM_PROXYSIZE_2) {
- index = 2;
- } else if (nSize <= FIXEDMEM_PROXYSIZE_3) {
- index = 3;
- } else if (nSize <= FIXEDMEM_PROXYSIZE_4) {
- index = 4;
- }
- return &g_ProxyMgr_MemConfigs[index];
-}
-FXMEM_FoxitMgr* CFixedMgr_Proxy::Initialize(FX_LPVOID pBuffer, size_t nSize, FX_BOOL bExtensible)
-{
- FXSYS_assert(pBuffer != NULL && nSize >= FIXEDMEM_PROXYSIZE_1 - sizeof(CFixedMgr_Proxy));
- FXMEM_SetConfig(FixedMgr_GetConfig(nSize));
- m_SystemMgr.More = &CFixedMgr_Proxy::Common_More;
- m_SystemMgr.Free = &CFixedMgr_Proxy::Common_Free;
- m_pFixedPage = (CFXMEM_Page*)((FX_LPBYTE)pBuffer + FIXEDMEM_PROXYSIZE_0);
- m_pFixedPage->Initialize(nSize - FIXEDMEM_PROXYSIZE_0);
- m_pBuffer = pBuffer;
- m_nSize = nSize;
- m_bExtensible = bExtensible;
- return FXMEM_CreateFixedMgr(pBuffer, FIXEDMEM_PROXYSIZE_0, &m_SystemMgr);
-}
-FX_BOOL CFixedMgr_Proxy::Common_More(FXMEM_SystemMgr2* pMgr, size_t alloc_size, void** new_memory, size_t* new_size)
-{
- CFixedMgr_Proxy* pProxyMgr = (CFixedMgr_Proxy*)pMgr;
- FXSYS_assert(pProxyMgr != NULL && pProxyMgr->m_pFixedPage != NULL);
- *new_size = alloc_size;
- *new_memory = pProxyMgr->m_pFixedPage->Alloc(alloc_size);
- if (*new_memory == NULL && pProxyMgr->m_bExtensible) {
- *new_memory = malloc(alloc_size);
- }
- return *new_memory != NULL;
-}
-void CFixedMgr_Proxy::Common_Free(FXMEM_SystemMgr2* pMgr, void* memory)
-{
- CFixedMgr_Proxy* pProxyMgr = (CFixedMgr_Proxy*)pMgr;
- FXSYS_assert(pProxyMgr != NULL && pProxyMgr->m_pFixedPage != NULL);
- if (memory > pProxyMgr->m_pBuffer && memory < (FX_LPBYTE)pProxyMgr->m_pBuffer + pProxyMgr->m_nSize) {
- pProxyMgr->m_pFixedPage->Free(memory);
- } else if (pProxyMgr->m_bExtensible) {
- free(memory);
- }
-}
-void CFXMEM_Page::Initialize(size_t size)
-{
- CFXMEM_Block *pFirstBlock = (CFXMEM_Block*)(this + 1);
- m_nAvailSize = size - sizeof(CFXMEM_Page) - sizeof(CFXMEM_Block);
- pFirstBlock->m_nBlockSize = m_nAvailSize;
- pFirstBlock->m_pNextBlock = NULL;
- m_AvailHead.m_nBlockSize = m_nAvailSize;
- m_AvailHead.m_pNextBlock = pFirstBlock;
- m_pLimitPos = (CFXMEM_Block*)((FX_LPBYTE)this + size);
-}
-FX_LPVOID CFXMEM_Page::Alloc(CFXMEM_Block* pPrevBlock, CFXMEM_Block* pNextBlock, size_t size, size_t oldsize)
-{
- size_t gap = pNextBlock->m_nBlockSize - size;
- if (gap <= 64 + sizeof(CFXMEM_Block)) {
- pPrevBlock->m_pNextBlock = pNextBlock->m_pNextBlock;
- m_nAvailSize -= pNextBlock->m_nBlockSize;
- } else {
- m_nAvailSize -= size + sizeof(CFXMEM_Block);
- pNextBlock->m_nBlockSize = size;
- CFXMEM_Block *pNewBlock = (CFXMEM_Block*)((FX_LPBYTE)(pNextBlock + 1) + size);
- pNewBlock->m_nBlockSize = gap - sizeof(CFXMEM_Block);
- pNewBlock->m_pNextBlock = pNextBlock->m_pNextBlock;
- pPrevBlock->m_pNextBlock = pNewBlock;
- }
- return (FX_LPVOID)(pNextBlock + 1);
-}
-FX_LPVOID CFXMEM_Page::Alloc(size_t size)
-{
- size_t oldsize = size;
-#if _FX_WORDSIZE_ == _FX_W64_
- size = (size + 31) / 32 * 32;
-#else
- size = (size + 7) / 8 * 8;
-#endif
- if (m_nAvailSize < size) {
- return NULL;
- }
- CFXMEM_Block *pNextBlock;
- CFXMEM_Block *pPrevBlock = &m_AvailHead;
- while (TRUE) {
- pNextBlock = pPrevBlock->m_pNextBlock;
- if (!pNextBlock) {
- return NULL;
- }
- if (pNextBlock->m_nBlockSize >= size) {
- break;
- }
- pPrevBlock = pNextBlock;
- }
- return Alloc(pPrevBlock, pNextBlock, size, oldsize);
-}
-FX_LPVOID CFXMEM_Page::Realloc(FX_LPVOID p, size_t oldSize, size_t newSize)
-{
- FXSYS_assert(p > (FX_LPVOID)this && p < (FX_LPVOID)m_pLimitPos);
- size_t oldnewSize = newSize;
-#if _FX_WORDSIZE_ == _FX_W64_
- newSize = (newSize + 31) / 32 * 32;
-#else
- newSize = (newSize + 7) / 8 * 8;
-#endif
- CFXMEM_Block *pPrevBlock = &m_AvailHead;
- CFXMEM_Block *pNextBlock, *pPrevPrev;
- CFXMEM_Block *pBlock = (CFXMEM_Block*)p - 1;
- pPrevPrev = NULL;
- while (TRUE) {
- pNextBlock = pPrevBlock->m_pNextBlock;
- if (pNextBlock == NULL || pNextBlock > pBlock) {
- break;
- }
- if (pPrevBlock != &m_AvailHead && (FX_LPBYTE)pNextBlock == (FX_LPBYTE)(pPrevBlock + 1) + pPrevBlock->m_nBlockSize) {
- m_nAvailSize += sizeof(CFXMEM_Block);
- pPrevBlock->m_nBlockSize += pNextBlock->m_nBlockSize + sizeof(CFXMEM_Block);
- pPrevBlock->m_pNextBlock = pNextBlock->m_pNextBlock;
- } else {
- pPrevPrev = pPrevBlock;
- pPrevBlock = pNextBlock;
- }
- }
- if (pNextBlock) {
- CFXMEM_Block* pCurBlock = pNextBlock->m_pNextBlock;
- while ((FX_LPBYTE)pCurBlock == (FX_LPBYTE)(pNextBlock + 1) + pNextBlock->m_nBlockSize) {
- m_nAvailSize += sizeof(CFXMEM_Block);
- pNextBlock->m_nBlockSize += pCurBlock->m_nBlockSize + sizeof(CFXMEM_Block);
- pCurBlock = pCurBlock->m_pNextBlock;
- pNextBlock->m_pNextBlock = pCurBlock;
- }
- }
- size_t size = 0;
- FX_DWORD dwFlags = 0;
- if (pPrevBlock != &m_AvailHead && (FX_LPBYTE)pBlock == (FX_LPBYTE)(pPrevBlock + 1) + pPrevBlock->m_nBlockSize) {
- size += pPrevBlock->m_nBlockSize + oldSize + sizeof(CFXMEM_Block);
- dwFlags |= 0x10;
- }
- if (pNextBlock && (FX_LPBYTE)pNextBlock == (FX_LPBYTE)p + oldSize) {
- size += pNextBlock->m_nBlockSize + sizeof(CFXMEM_Block);
- dwFlags |= 0x01;
- }
- if (size >= newSize) {
- m_nAvailSize += pBlock->m_nBlockSize;
- CFXMEM_Block* pCurBlock = pBlock;
- if (dwFlags & 0x10) {
- pCurBlock = pPrevBlock;
- m_nAvailSize += sizeof(CFXMEM_Block);
- pCurBlock->m_nBlockSize += pBlock->m_nBlockSize + sizeof(CFXMEM_Block);
- pPrevBlock = pPrevPrev;
- }
- if (dwFlags & 0x01) {
- m_nAvailSize += sizeof(CFXMEM_Block);
- pCurBlock->m_nBlockSize += pNextBlock->m_nBlockSize + sizeof(CFXMEM_Block);
- pCurBlock->m_pNextBlock = pNextBlock->m_pNextBlock;
- }
- if (pCurBlock != pBlock) {
- FXSYS_memmove32((FX_LPVOID)(pCurBlock + 1), p, oldSize);
- }
- return Alloc(pPrevBlock, pCurBlock, newSize, oldnewSize);
- }
- return NULL;
-}
-void CFXMEM_Page::Free(FX_LPVOID p)
-{
- FXSYS_assert(p > (FX_LPVOID)this && p < (FX_LPVOID)m_pLimitPos);
- CFXMEM_Block *pPrevBlock = &m_AvailHead;
- CFXMEM_Block *pNextBlock;
- CFXMEM_Block *pBlock = (CFXMEM_Block*)p - 1;
- m_nAvailSize += pBlock->m_nBlockSize;
- while (TRUE) {
- pNextBlock = pPrevBlock->m_pNextBlock;
- if (pNextBlock == NULL || pNextBlock > pBlock) {
- break;
- }
- if (pPrevBlock != &m_AvailHead && (FX_LPBYTE)pNextBlock == (FX_LPBYTE)(pPrevBlock + 1) + pPrevBlock->m_nBlockSize) {
- m_nAvailSize += sizeof(CFXMEM_Block);
- pPrevBlock->m_nBlockSize += pNextBlock->m_nBlockSize + sizeof(CFXMEM_Block);
- pPrevBlock->m_pNextBlock = pNextBlock->m_pNextBlock;
- } else {
- pPrevBlock = pNextBlock;
- }
- }
- while ((FX_LPBYTE)pNextBlock == (FX_LPBYTE)(pBlock + 1) + pBlock->m_nBlockSize) {
- m_nAvailSize += sizeof(CFXMEM_Block);
- pBlock->m_nBlockSize += pNextBlock->m_nBlockSize + sizeof(CFXMEM_Block);
- pNextBlock = pNextBlock->m_pNextBlock;
- }
- pBlock->m_pNextBlock = pNextBlock;
- if (pPrevBlock != &m_AvailHead && (FX_LPBYTE)pBlock == (FX_LPBYTE)(pPrevBlock + 1) + pPrevBlock->m_nBlockSize) {
- m_nAvailSize += sizeof(CFXMEM_Block);
- pPrevBlock->m_nBlockSize += pBlock->m_nBlockSize + sizeof(CFXMEM_Block);
- pPrevBlock->m_pNextBlock = pBlock->m_pNextBlock;
- } else {
- FXSYS_assert(pPrevBlock != pBlock);
- pPrevBlock->m_pNextBlock = pBlock;
- }
-}
-void CFXMEM_Pages::Initialize(FX_LPBYTE pStart, size_t pageSize, size_t pages)
-{
- m_pStartPage = m_pCurPage = (CFXMEM_Page*)pStart;
- m_nPageSize = pageSize;
- for (size_t n = 0; n < pages; n++) {
- ((CFXMEM_Page*)pStart)->Initialize(pageSize);
- pStart += pageSize;
- }
- m_pLimitPos = (CFXMEM_Page*)pStart;
-}
-FX_BOOL CFXMEM_Pages::IsEmpty() const
-{
- if (m_pStartPage >= m_pLimitPos) {
- return TRUE;
- }
- FX_LPBYTE pPage = (FX_LPBYTE)m_pStartPage;
- while (pPage < (FX_LPBYTE)m_pLimitPos) {
- if (!((CFXMEM_Page*)pPage)->IsEmpty()) {
- return FALSE;
- }
- pPage += m_nPageSize;
- }
- return TRUE;
-}
-FX_LPVOID CFXMEM_Pages::Alloc(size_t size)
-{
- CFXMEM_Page *pCurPage = m_pCurPage;
- do {
- FX_LPVOID p = m_pCurPage->Alloc(size);
- if (p) {
- return p;
- }
- m_pCurPage = (CFXMEM_Page*)((FX_LPBYTE)m_pCurPage + m_nPageSize);
- if (m_pCurPage == m_pLimitPos) {
- m_pCurPage = m_pStartPage;
- }
- } while (m_pCurPage != pCurPage);
- return NULL;
-}
-FX_LPVOID CFXMEM_Pages::Realloc(FX_LPVOID p, size_t oldSize, size_t newSize)
-{
- FXSYS_assert (p > (FX_LPVOID)m_pStartPage && p < (FX_LPVOID)m_pLimitPos);
- CFXMEM_Page* pPage = (CFXMEM_Page*)((FX_LPBYTE)m_pStartPage + ((FX_LPBYTE)p - (FX_LPBYTE)m_pStartPage) / m_nPageSize * m_nPageSize);
- return pPage->Realloc(p, oldSize, newSize);
-}
-void CFXMEM_Pages::Free(FX_LPVOID p)
-{
- FXSYS_assert (p > (FX_LPVOID)m_pStartPage && p < (FX_LPVOID)m_pLimitPos);
- CFXMEM_Page* pPage = (CFXMEM_Page*)((FX_LPBYTE)m_pStartPage + ((FX_LPBYTE)p - (FX_LPBYTE)m_pStartPage) / m_nPageSize * m_nPageSize);
- pPage->Free(p);
-}
-void CFXMEM_Pool::Initialize(const FX_MEMCONFIG* pMemConfig, size_t size, size_t pageNum8Bytes, size_t pageNum16Bytes, size_t pageNum32Bytes, size_t pageNumMid)
-{
- m_pPrevPool = NULL;
- m_pNextPool = NULL;
- m_bAlone = FALSE;
- FX_LPBYTE pPage = (FX_LPBYTE)this + sizeof(CFXMEM_Pool);
- size -= sizeof(CFXMEM_Pool);
- m_8BytesPages.Initialize(pPage, pageNum8Bytes);
- pPage += pageNum8Bytes * FX_FIXEDMEM_PAGESIZE;
- size -= pageNum8Bytes * FX_FIXEDMEM_PAGESIZE;
- m_16BytesPages.Initialize(pPage, pageNum16Bytes);
- pPage += pageNum16Bytes * FX_FIXEDMEM_PAGESIZE;
- size -= pageNum16Bytes * FX_FIXEDMEM_PAGESIZE;
- m_32BytesPages.Initialize(pPage, pageNum32Bytes);
- pPage += pageNum32Bytes * FX_FIXEDMEM_PAGESIZE;
- size -= pageNum32Bytes * FX_FIXEDMEM_PAGESIZE;
- m_MidPages.Initialize(pPage, pMemConfig->nPageSize_Mid * FX_FIXEDMEM_PAGESIZE, pageNumMid);
- pPage += pageNumMid * pMemConfig->nPageSize_Mid * FX_FIXEDMEM_PAGESIZE;
- size -= pageNumMid * pMemConfig->nPageSize_Mid * FX_FIXEDMEM_PAGESIZE;
- if (size < FX_FIXEDMEM_MIDBLOCKSIZE) {
- m_pLargePage = NULL;
- } else {
- m_pLargePage = (CFXMEM_Page*)pPage;
- m_pLargePage->Initialize(size);
- }
- m_pLimitPos = pPage + size;
-}
-FX_BOOL CFXMEM_Pool::IsEmpty() const
-{
- if (!m_8BytesPages.IsEmpty()) {
- return FALSE;
- }
- if (!m_16BytesPages.IsEmpty()) {
- return FALSE;
- }
- if (!m_32BytesPages.IsEmpty()) {
- return FALSE;
- }
- if (!m_MidPages.IsEmpty()) {
- return FALSE;
- }
- return !m_pLargePage || m_pLargePage->IsEmpty();
-}
-size_t CFXMEM_Pool::GetSize(FX_LPVOID p) const
-{
- FXSYS_assert(p > (FX_LPVOID)this && p < (FX_LPVOID)m_pLimitPos);
- if (p < (FX_LPVOID)m_8BytesPages.m_pLimitPos) {
- return 8;
- }
- if (p < (FX_LPVOID)m_16BytesPages.m_pLimitPos) {
- return 16;
- }
- if (p < (FX_LPVOID)m_32BytesPages.m_pLimitPos) {
- return 32;
- }
- return ((CFXMEM_Block*)p - 1)->m_nBlockSize;
-}
-FX_LPVOID CFXMEM_Pool::Realloc(FX_LPVOID p, size_t oldSize, size_t newSize)
-{
- FXSYS_assert(p > (FX_LPVOID)this && p < (FX_LPVOID)m_pLimitPos);
- if (p > (FX_LPVOID)m_32BytesPages.m_pLimitPos) {
- if (p < (FX_LPVOID)m_MidPages.m_pLimitPos) {
- return m_MidPages.Realloc(p, oldSize, newSize);
- } else if (m_pLargePage) {
- return m_pLargePage->Realloc(p, oldSize, newSize);
- }
- }
- return NULL;
-}
-void CFXMEM_Pool::Free(FX_LPVOID p)
-{
- FXSYS_assert(p > (FX_LPVOID)this && p < (FX_LPVOID)m_pLimitPos);
- if (p < (FX_LPVOID)m_32BytesPages.m_pLimitPos) {
- if (p < (FX_LPVOID)m_8BytesPages.m_pLimitPos) {
- m_8BytesPages.Free(p);
- } else if (p < (FX_LPVOID)m_16BytesPages.m_pLimitPos) {
- m_16BytesPages.Free(p);
- } else {
- m_32BytesPages.Free(p);
- }
- return;
- } else if (p < (FX_LPVOID)m_MidPages.m_pLimitPos) {
- m_MidPages.Free(p);
- } else {
- m_pLargePage->Free(p);
- }
-}
-void CFXMEM_FixedMgr::Initialize(size_t size)
-{
- m_MemConfig = g_MemConfig;
- FXSYS_memset32(&m_SystemMgr, 0, sizeof m_SystemMgr);
- m_SystemMgr.Alloc = FixedAlloc;
- m_SystemMgr.AllocDebug = FixedAllocDebug;
- m_SystemMgr.Free = FixedFree;
- m_SystemMgr.Realloc = FixedRealloc;
- m_SystemMgr.ReallocDebug = FixedReallocDebug;
- m_SystemMgr.CollectAll = FixedCollectAll;
- m_SystemMgr.Purge = FixedPurge;
- m_SystemMgr.user = this;
- size -= sizeof(CFXMEM_FixedMgr);
- size_t nMidPages = 0;
- if (m_MemConfig.nPageSize_Mid) {
- nMidPages = (size - (m_MemConfig.nPageNum_Init8 + m_MemConfig.nPageNum_Init16 + m_MemConfig.nPageNum_Init32) * FX_FIXEDMEM_PAGESIZE) / (m_MemConfig.nPageSize_Mid * FX_FIXEDMEM_PAGESIZE);
- if (nMidPages > m_MemConfig.nPageNum_InitMid) {
- nMidPages = m_MemConfig.nPageNum_InitMid;
- }
- }
- m_FirstPool.Initialize(&m_MemConfig, size, m_MemConfig.nPageNum_Init8, m_MemConfig.nPageNum_Init16, m_MemConfig.nPageNum_Init32, nMidPages);
-}
-FX_LPVOID CFXMEM_FixedMgr::Alloc16(CFXMEM_Pool **pp32Pool, size_t size)
-{
- CFXMEM_Pool *pPool = &m_FirstPool;
- do {
- CFXMEM_16BytesPages &pages = pPool->m_16BytesPages;
- if (pages.HasFreeBlock()) {
- return pages.Alloc(size);
- }
- if (pp32Pool && pPool->m_32BytesPages.HasFreeBlock()) {
- *pp32Pool = pPool;
- }
- pPool = pPool->m_pNextPool;
- } while(pPool);
- return NULL;
-}
-FX_LPVOID CFXMEM_FixedMgr::Alloc32(size_t size)
-{
- if (size <= 8) {
- CFXMEM_8BytesPages &pages = m_FirstPool.m_8BytesPages;
- if (pages.HasFreeBlock()) {
- return pages.Alloc(size);
- }
- }
- CFXMEM_Pool *p32BytesPool;
- if (size <= 16) {
- p32BytesPool = NULL;
- FX_LPVOID p = Alloc16(&p32BytesPool, size);
- if (p) {
- return p;
- }
- } else {
- p32BytesPool = &m_FirstPool;
- }
- while (p32BytesPool) {
- CFXMEM_32BytesPages &pages = p32BytesPool->m_32BytesPages;
- if (pages.HasFreeBlock()) {
- return pages.Alloc(size);
- }
- p32BytesPool = p32BytesPool->m_pNextPool;
- }
- return NULL;
-}
-FX_LPVOID CFXMEM_FixedMgr::AllocSmall(size_t size)
-{
- FX_LPVOID p = Alloc32(size);
- if (p) {
- return p;
- }
- if (!m_pExtender) {
- return NULL;
- }
- size_t requiredSize = (m_MemConfig.nPageNum_More16 + m_MemConfig.nPageNum_More32) * FX_FIXEDMEM_PAGESIZE;
- if (!requiredSize) {
- return NULL;
- }
- CFXMEM_Pool *pNewPool = NULL;
- requiredSize += sizeof(CFXMEM_Pool);
- size_t newSize = requiredSize;
- if (!m_pExtender->More(m_pExtender, newSize, (void**)&pNewPool, &newSize)) {
- return NULL;
- }
- size_t nMidPages = 0;
- if (m_MemConfig.nPageSize_Mid) {
- nMidPages = (newSize - requiredSize) / (m_MemConfig.nPageSize_Mid * FX_FIXEDMEM_PAGESIZE);
- if (nMidPages > m_MemConfig.nPageNum_MoreMid) {
- nMidPages = m_MemConfig.nPageNum_MoreMid;
- }
- }
- pNewPool->Initialize(&m_MemConfig, newSize, 0, m_MemConfig.nPageNum_More16, m_MemConfig.nPageNum_More32, nMidPages);
- pNewPool->m_pPrevPool = &m_FirstPool;
- CFXMEM_Pool *pPool = m_FirstPool.m_pNextPool;
- pNewPool->m_pNextPool = pPool;
- if (pPool) {
- pPool->m_pPrevPool = pNewPool;
- }
- m_FirstPool.m_pNextPool = pNewPool;
- return Alloc32(size);
-}
-FX_LPVOID CFXMEM_FixedMgr::AllocMid(size_t size)
-{
- CFXMEM_Pool *pPool = &m_FirstPool;
- do {
- CFXMEM_Pages &pages = pPool->m_MidPages;
- if (pages.m_pLimitPos > pages.m_pStartPage) {
- FX_LPVOID p = pages.Alloc(size);
- if (p) {
- return p;
- }
- }
- pPool = pPool->m_pNextPool;
- } while(pPool);
- if (!m_pExtender) {
- return NULL;
- }
- size_t newSize = m_MemConfig.nPageSize_Mid * FX_FIXEDMEM_PAGESIZE * m_MemConfig.nPageNum_MoreMid;
- if (!newSize) {
- return NULL;
- }
- CFXMEM_Pool *pNewPool = NULL;
- newSize += sizeof(CFXMEM_Pool);
- if (!m_pExtender->More(m_pExtender, newSize, (void**)&pNewPool, &newSize)) {
- return NULL;
- }
- size_t nMidPages = (newSize - sizeof(CFXMEM_Pool)) / (m_MemConfig.nPageSize_Mid * FX_FIXEDMEM_PAGESIZE);
- if (nMidPages > m_MemConfig.nPageNum_MoreMid) {
- nMidPages = m_MemConfig.nPageNum_MoreMid;
- }
- pNewPool->Initialize(&m_MemConfig, newSize, 0, 0, 0, nMidPages);
- pNewPool->m_pPrevPool = &m_FirstPool;
- pPool = m_FirstPool.m_pNextPool;
- pNewPool->m_pNextPool = pPool;
- if (pPool) {
- pPool->m_pPrevPool = pNewPool;
- }
- m_FirstPool.m_pNextPool = pNewPool;
- return pNewPool->m_MidPages.Alloc(size);
-}
-FX_LPVOID CFXMEM_FixedMgr::AllocLarge(size_t size)
-{
- CFXMEM_Pool *pPool = &m_FirstPool;
- do {
- if (!pPool->m_bAlone && pPool->m_pLargePage) {
- FX_LPVOID p = pPool->m_pLargePage->Alloc(size);
- if (p) {
- return p;
- }
- }
- pPool = pPool->m_pNextPool;
- } while(pPool);
- if (!m_pExtender || !m_MemConfig.nPageSize_Large) {
- return NULL;
- }
- CFXMEM_Pool *pNewPool = NULL;
-#if _FX_WORDSIZE_ == _FX_W64_
- size_t newSize = ((size + 31) / 32 * 32 + sizeof(CFXMEM_Pool) + sizeof(CFXMEM_Page) + sizeof(CFXMEM_Block) + 4095) / 4096 * 4096;
-#else
- size_t newSize = (size + 7) / 8 * 8 + sizeof(CFXMEM_Pool) + sizeof(CFXMEM_Page) + sizeof(CFXMEM_Block);
-#endif
- if (newSize < m_MemConfig.nPageSize_Large * FX_FIXEDMEM_PAGESIZE) {
- newSize = m_MemConfig.nPageSize_Large * FX_FIXEDMEM_PAGESIZE;
- }
- if (!m_pExtender->More(m_pExtender, newSize, (void**)&pNewPool, &newSize)) {
- return NULL;
- }
- pNewPool->Initialize(&m_MemConfig, newSize, 0, 0, 0, 0);
- pNewPool->m_bAlone = size >= m_MemConfig.nPageSize_Alone * FX_FIXEDMEM_PAGESIZE;
- pNewPool->m_pPrevPool = &m_FirstPool;
- pPool = m_FirstPool.m_pNextPool;
- pNewPool->m_pNextPool = pPool;
- if (pPool) {
- pPool->m_pPrevPool = pNewPool;
- }
- m_FirstPool.m_pNextPool = pNewPool;
- return pNewPool->m_pLargePage->Alloc(size);
-}
-size_t CFXMEM_FixedMgr::GetSize(FX_LPVOID p) const
-{
- const CFXMEM_Pool *pFind = &m_FirstPool;
- do {
- if (p > (FX_LPVOID)pFind && p < pFind->m_pLimitPos) {
- return pFind->GetSize(p);
- }
- pFind = pFind->m_pNextPool;
- } while (pFind);
- return 0;
-}
-FX_LPVOID CFXMEM_FixedMgr::Alloc(size_t size)
-{
- FX_LPVOID p;
- if (size <= 32) {
- p = AllocSmall(size);
- if (p) {
- return p;
- }
- }
- if (size <= FX_FIXEDMEM_MIDBLOCKSIZE) {
- p = AllocMid(size);
- if (p) {
- return p;
- }
- }
- p = AllocLarge(size);
- return p;
-}
-FX_LPVOID CFXMEM_FixedMgr::ReallocSmall(CFXMEM_Pool* pPool, FX_LPVOID p, size_t oldSize, size_t newSize)
-{
- FX_LPVOID np = AllocSmall(newSize);
- if (!np) {
- return NULL;
- }
- FXSYS_memcpy32(np, p, oldSize);
- pPool->Free(p);
- return np;
-}
-FX_LPVOID CFXMEM_FixedMgr::Realloc(FX_LPVOID p, size_t newSize)
-{
- if (!p) {
- return Alloc(newSize);
- }
- size_t oldSize = 0;
- CFXMEM_Pool *pFind = &m_FirstPool;
- do {
- if (p > (FX_LPVOID)pFind && p < pFind->m_pLimitPos) {
- oldSize = pFind->GetSize(p);
- if (oldSize >= newSize) {
- return p;
- }
- break;
- }
- pFind = pFind->m_pNextPool;
- } while (pFind);
- if (!oldSize || !pFind) {
- return Alloc(newSize);
- }
- FX_LPVOID np = NULL;
- if (newSize <= 32) {
- np = ReallocSmall(pFind, p, oldSize, newSize);
- if (np) {
- return np;
- }
- }
- if (newSize <= FX_FIXEDMEM_MIDBLOCKSIZE) {
- np = pFind->Realloc(p, oldSize, newSize);
- if (np) {
- return np;
- }
- }
- np = Alloc(newSize);
- if (np) {
- FXSYS_memcpy32(np, p, oldSize);
- pFind->Free(p);
- }
- if (pFind->m_bAlone && pFind->IsEmpty()) {
- FreePool(pFind);
- }
- return np;
-}
-void CFXMEM_FixedMgr::Free(FX_LPVOID p)
-{
- CFXMEM_Pool *pFind = &m_FirstPool;
- do {
- if (p > (FX_LPVOID)pFind && p < pFind->m_pLimitPos) {
- pFind->Free(p);
- if (pFind->m_bAlone && pFind->IsEmpty()) {
- FreePool(pFind);
- }
- return;
- }
- pFind = pFind->m_pNextPool;
- } while (pFind);
-}
-void CFXMEM_FixedMgr::FreePool(CFXMEM_Pool* pPool)
-{
- FXSYS_assert(pPool->m_bAlone && pPool->IsEmpty());
- FXSYS_assert(m_pExtender != NULL);
- CFXMEM_Pool* pPrevPool = pPool->m_pPrevPool;
- CFXMEM_Pool* pNextPool = pPool->m_pNextPool;
- if (pPrevPool) {
- pPrevPool->m_pNextPool = pNextPool;
- }
- if (pNextPool) {
- pNextPool->m_pPrevPool = pPrevPool;
- }
- m_pExtender->Free(m_pExtender, pPool);
-}
-void CFXMEM_FixedMgr::FreeAll()
-{
- if (!m_pExtender) {
- return;
- }
- CFXMEM_Pool* pPool = m_FirstPool.m_pNextPool;
- while (pPool) {
- CFXMEM_Pool* pPrevPool = pPool;
- pPool = pPool->m_pNextPool;
- m_pExtender->Free(m_pExtender, pPrevPool);
- }
- m_FirstPool.m_pNextPool = NULL;
-}
-void CFXMEM_FixedMgr::Purge()
-{
- if (!m_pExtender) {
- return;
- }
- CFXMEM_Pool* pPool = m_FirstPool.m_pNextPool;
- while (pPool) {
- CFXMEM_Pool* pNextPool = pPool->m_pNextPool;
- if (pPool->IsEmpty()) {
- CFXMEM_Pool* pPrevPool = pPool->m_pPrevPool;
- pPrevPool->m_pNextPool = pNextPool;
- if (pNextPool) {
- pNextPool->m_pPrevPool = pPrevPool;
- }
- m_pExtender->Free(m_pExtender, pPool);
- }
- pPool = pNextPool;
- }
-}
-extern const FX_BYTE OneLeadPos[256] = {
- 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4,
- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-};
-extern const FX_BYTE ZeroLeadPos[256] = {
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
- 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 7, 8,
-};
diff --git a/core/src/fxcrt/fx_basic_plex.cpp b/core/src/fxcrt/fx_basic_plex.cpp
index 80c014a2b3..bff55461f4 100644
--- a/core/src/fxcrt/fx_basic_plex.cpp
+++ b/core/src/fxcrt/fx_basic_plex.cpp
@@ -1,14 +1,14 @@
// Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-
+
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#include "../../include/fxcrt/fx_basic.h"
#include "plex.h"
-CFX_Plex* CFX_Plex::Create(IFX_Allocator* pAllocator, CFX_Plex*& pHead, FX_DWORD nMax, FX_DWORD cbElement)
+CFX_Plex* CFX_Plex::Create(CFX_Plex*& pHead, FX_DWORD nMax, FX_DWORD cbElement)
{
- CFX_Plex* p = (CFX_Plex*)FX_Allocator_Alloc(pAllocator, FX_BYTE, sizeof(CFX_Plex) + nMax * cbElement);
+ CFX_Plex* p = (CFX_Plex*)FX_Alloc(FX_BYTE, sizeof(CFX_Plex) + nMax * cbElement);
if (!p) {
return NULL;
}
@@ -16,13 +16,13 @@ CFX_Plex* CFX_Plex::Create(IFX_Allocator* pAllocator, CFX_Plex*& pHead, FX_DWORD
pHead = p;
return p;
}
-void CFX_Plex::FreeDataChain(IFX_Allocator* pAllocator)
+void CFX_Plex::FreeDataChain()
{
CFX_Plex* p = this;
while (p != NULL) {
- FX_BYTE* bytes = (FX_BYTE*) p;
+ FX_BYTE* bytes = (FX_BYTE*)p;
CFX_Plex* pNext = p->pNext;
- FX_Allocator_Free(pAllocator, bytes);
+ FX_Free(bytes);
p = pNext;
}
}
diff --git a/core/src/fxcrt/fx_basic_utf.cpp b/core/src/fxcrt/fx_basic_utf.cpp
index c5aa360e6c..02c7d98a1b 100644
--- a/core/src/fxcrt/fx_basic_utf.cpp
+++ b/core/src/fxcrt/fx_basic_utf.cpp
@@ -1,7 +1,7 @@
// Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-
+
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#include "../../include/fxcrt/fx_basic.h"
@@ -88,15 +88,3 @@ CFX_ByteString FX_UTF8Encode(FX_LPCWSTR pwsStr, FX_STRSIZE len)
}
return encoder.GetResult();
}
-void FX_UTF8Encode(FX_LPCWSTR pwsStr, FX_STRSIZE len, CFX_ByteStringL &utf8Str, IFX_Allocator* pAllocator)
-{
- FXSYS_assert(pwsStr != NULL);
- if (len < 0) {
- len = (FX_STRSIZE)FXSYS_wcslen(pwsStr);
- }
- CFX_UTF8Encoder encoder(pAllocator);
- while (len -- > 0) {
- encoder.Input(*pwsStr ++);
- }
- encoder.GetResult(utf8Str);
-}
diff --git a/core/src/fxcrt/fx_basic_wstring.cpp b/core/src/fxcrt/fx_basic_wstring.cpp
index 68a65d5b6b..192579fe54 100644
--- a/core/src/fxcrt/fx_basic_wstring.cpp
+++ b/core/src/fxcrt/fx_basic_wstring.cpp
@@ -1,7 +1,7 @@
// Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-
+
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#include "../../include/fxcrt/fx_basic.h"
@@ -1062,58 +1062,6 @@ FX_FLOAT CFX_WideString::GetFloat() const
}
return FX_wtof(m_pData->m_String, m_pData->m_nDataLength);
}
-void CFX_WideStringL::Empty(IFX_Allocator* pAllocator)
-{
- if (m_Ptr) {
- FX_Allocator_Free(pAllocator, (FX_LPVOID)m_Ptr);
- }
- m_Ptr = NULL, m_Length = 0;
-}
-void CFX_WideStringL::Set(FX_WSTR src, IFX_Allocator* pAllocator)
-{
- Empty(pAllocator);
- if (src.GetPtr() != NULL && src.GetLength() > 0) {
- FX_LPWSTR str = FX_Allocator_Alloc(pAllocator, FX_WCHAR, src.GetLength() + 1);
- if (!str) {
- return;
- }
- FXSYS_memcpy32(str, src.GetPtr(), src.GetLength()*sizeof(FX_WCHAR));
- str[src.GetLength()] = '\0';
- *(FX_LPWSTR*)(&m_Ptr) = str;
- m_Length = src.GetLength();
- }
-}
-int CFX_WideStringL::GetInteger() const
-{
- if (!m_Ptr) {
- return 0;
- }
- return FXSYS_wtoi(m_Ptr);
-}
-FX_FLOAT CFX_WideStringL::GetFloat() const
-{
- if (!m_Ptr) {
- return 0.0f;
- }
- return FX_wtof(m_Ptr, m_Length);
-}
-void CFX_WideStringL::TrimRight(FX_LPCWSTR lpszTargets)
-{
- if (!lpszTargets || *lpszTargets == 0 || !m_Ptr || m_Length < 1) {
- return;
- }
- FX_STRSIZE pos = m_Length;
- while (pos) {
- if (FXSYS_wcschr(lpszTargets, m_Ptr[pos - 1]) == NULL) {
- break;
- }
- pos --;
- }
- if (pos < m_Length) {
- (*(FX_LPWSTR*)(&m_Ptr))[pos] = 0;
- m_Length = pos;
- }
-}
static CFX_ByteString _DefMap_GetByteString(CFX_CharMap* pCharMap, const CFX_WideString& widestr)
{
int src_len = widestr.GetLength();
diff --git a/core/src/fxcrt/fx_extension.cpp b/core/src/fxcrt/fx_extension.cpp
index e7272cff0b..7ff6b062b4 100644
--- a/core/src/fxcrt/fx_extension.cpp
+++ b/core/src/fxcrt/fx_extension.cpp
@@ -1,7 +1,7 @@
// Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-
+
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#include "../../include/fxcrt/fx_ext.h"
@@ -11,29 +11,29 @@
#else
#include <ctime>
#endif
-FX_HFILE FX_File_Open(FX_BSTR fileName, FX_DWORD dwMode, IFX_Allocator* pAllocator)
+FX_HFILE FX_File_Open(FX_BSTR fileName, FX_DWORD dwMode)
{
- IFXCRT_FileAccess* pFA = FXCRT_FileAccess_Create(pAllocator);
+ IFXCRT_FileAccess* pFA = FXCRT_FileAccess_Create();
if (pFA && !pFA->Open(fileName, dwMode)) {
- pFA->Release(pAllocator);
+ pFA->Release();
return NULL;
}
return (FX_HFILE)pFA;
}
-FX_HFILE FX_File_Open(FX_WSTR fileName, FX_DWORD dwMode, IFX_Allocator* pAllocator)
+FX_HFILE FX_File_Open(FX_WSTR fileName, FX_DWORD dwMode)
{
- IFXCRT_FileAccess* pFA = FXCRT_FileAccess_Create(pAllocator);
+ IFXCRT_FileAccess* pFA = FXCRT_FileAccess_Create();
if (pFA && !pFA->Open(fileName, dwMode)) {
- pFA->Release(pAllocator);
+ pFA->Release();
return NULL;
}
return (FX_HFILE)pFA;
}
-void FX_File_Close(FX_HFILE hFile, IFX_Allocator* pAllocator)
+void FX_File_Close(FX_HFILE hFile)
{
FXSYS_assert(hFile != NULL);
((IFXCRT_FileAccess*)hFile)->Close();
- ((IFXCRT_FileAccess*)hFile)->Release(pAllocator);
+ ((IFXCRT_FileAccess*)hFile)->Release();
}
FX_FILESIZE FX_File_GetSize(FX_HFILE hFile)
{
@@ -80,69 +80,53 @@ FX_BOOL FX_File_Truncate(FX_HFILE hFile, FX_FILESIZE szFile)
FXSYS_assert(hFile != NULL);
return ((IFXCRT_FileAccess*)hFile)->Truncate(szFile);
}
-IFX_FileStream* FX_CreateFileStream(FX_LPCSTR filename, FX_DWORD dwModes, IFX_Allocator* pAllocator)
+IFX_FileStream* FX_CreateFileStream(FX_LPCSTR filename, FX_DWORD dwModes)
{
- IFXCRT_FileAccess* pFA = FXCRT_FileAccess_Create(pAllocator);
+ IFXCRT_FileAccess* pFA = FXCRT_FileAccess_Create();
if (!pFA) {
return NULL;
}
if (!pFA->Open(filename, dwModes)) {
- pFA->Release(pAllocator);
+ pFA->Release();
return NULL;
}
- if (pAllocator) {
- return FX_NewAtAllocator(pAllocator) CFX_CRTFileStream(pFA, pAllocator);
- } else {
- return FX_NEW CFX_CRTFileStream(pFA, pAllocator);
- }
+ return FX_NEW CFX_CRTFileStream(pFA);
}
-IFX_FileStream* FX_CreateFileStream(FX_LPCWSTR filename, FX_DWORD dwModes, IFX_Allocator* pAllocator)
+IFX_FileStream* FX_CreateFileStream(FX_LPCWSTR filename, FX_DWORD dwModes)
{
- IFXCRT_FileAccess* pFA = FXCRT_FileAccess_Create(pAllocator);
+ IFXCRT_FileAccess* pFA = FXCRT_FileAccess_Create();
if (!pFA) {
return NULL;
}
if (!pFA->Open(filename, dwModes)) {
- pFA->Release(pAllocator);
+ pFA->Release();
return NULL;
}
- if (pAllocator) {
- return FX_NewAtAllocator(pAllocator) CFX_CRTFileStream(pFA, pAllocator);
- } else {
- return FX_NEW CFX_CRTFileStream(pFA, pAllocator);
- }
+ return FX_NEW CFX_CRTFileStream(pFA);
}
-IFX_FileWrite* FX_CreateFileWrite(FX_LPCSTR filename, IFX_Allocator* pAllocator)
+IFX_FileWrite* FX_CreateFileWrite(FX_LPCSTR filename)
{
- return FX_CreateFileStream(filename, FX_FILEMODE_Truncate, pAllocator);
+ return FX_CreateFileStream(filename, FX_FILEMODE_Truncate);
}
-IFX_FileWrite* FX_CreateFileWrite(FX_LPCWSTR filename, IFX_Allocator* pAllocator)
+IFX_FileWrite* FX_CreateFileWrite(FX_LPCWSTR filename)
{
- return FX_CreateFileStream(filename, FX_FILEMODE_Truncate, pAllocator);
+ return FX_CreateFileStream(filename, FX_FILEMODE_Truncate);
}
-IFX_FileRead* FX_CreateFileRead(FX_LPCSTR filename, IFX_Allocator* pAllocator)
+IFX_FileRead* FX_CreateFileRead(FX_LPCSTR filename)
{
- return FX_CreateFileStream(filename, FX_FILEMODE_ReadOnly, pAllocator);
+ return FX_CreateFileStream(filename, FX_FILEMODE_ReadOnly);
}
-IFX_FileRead* FX_CreateFileRead(FX_LPCWSTR filename, IFX_Allocator* pAllocator)
+IFX_FileRead* FX_CreateFileRead(FX_LPCWSTR filename)
{
- return FX_CreateFileStream(filename, FX_FILEMODE_ReadOnly, pAllocator);
+ return FX_CreateFileStream(filename, FX_FILEMODE_ReadOnly);
}
-IFX_MemoryStream* FX_CreateMemoryStream(FX_LPBYTE pBuffer, size_t dwSize, FX_BOOL bTakeOver, IFX_Allocator* pAllocator)
+IFX_MemoryStream* FX_CreateMemoryStream(FX_LPBYTE pBuffer, size_t dwSize, FX_BOOL bTakeOver)
{
- if (pAllocator) {
- return FX_NewAtAllocator(pAllocator)CFX_MemoryStream(pBuffer, dwSize, bTakeOver, pAllocator);
- } else {
- return FX_NEW CFX_MemoryStream(pBuffer, dwSize, bTakeOver, NULL);
- }
+ return FX_NEW CFX_MemoryStream(pBuffer, dwSize, bTakeOver);
}
-IFX_MemoryStream* FX_CreateMemoryStream(FX_BOOL bConsecutive, IFX_Allocator* pAllocator)
+IFX_MemoryStream* FX_CreateMemoryStream(FX_BOOL bConsecutive)
{
- if (pAllocator) {
- return FX_NewAtAllocator(pAllocator)CFX_MemoryStream(bConsecutive, pAllocator);
- } else {
- return FX_NEW CFX_MemoryStream(bConsecutive, NULL);
- }
+ return FX_NEW CFX_MemoryStream(bConsecutive);
}
#ifdef __cplusplus
extern "C" {
diff --git a/core/src/fxcrt/fx_xml_composer.cpp b/core/src/fxcrt/fx_xml_composer.cpp
index 1fce9009db..97c5dfd130 100644
--- a/core/src/fxcrt/fx_xml_composer.cpp
+++ b/core/src/fxcrt/fx_xml_composer.cpp
@@ -1,7 +1,7 @@
// Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-
+
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#include "../../include/fxcrt/fx_xml.h"
@@ -27,16 +27,14 @@ void FX_XML_SplitQualifiedName(FX_BSTR bsFullName, CFX_ByteStringC &bsSpace, CFX
}
void CXML_Element::SetTag(FX_BSTR qSpace, FX_BSTR tagname)
{
- IFX_Allocator* pAllocator = m_Children.m_pAllocator;
- m_QSpaceName.Set(qSpace, pAllocator);
- m_TagName.Set(tagname, pAllocator);
+ m_QSpaceName = qSpace;
+ m_TagName = tagname;
}
void CXML_Element::SetTag(FX_BSTR qTagName)
{
ASSERT(!qTagName.IsEmpty());
- IFX_Allocator* pAllocator = m_Children.m_pAllocator;
CFX_ByteStringC bsSpace, bsName;
FX_XML_SplitQualifiedName(qTagName, bsSpace, bsName);
- m_QSpaceName.Set(bsSpace, pAllocator);
- m_TagName.Set(bsName, pAllocator);
+ m_QSpaceName = bsSpace;
+ m_TagName = bsName;
}
diff --git a/core/src/fxcrt/fx_xml_parser.cpp b/core/src/fxcrt/fx_xml_parser.cpp
index b7e58a04e1..d41880a6c4 100644
--- a/core/src/fxcrt/fx_xml_parser.cpp
+++ b/core/src/fxcrt/fx_xml_parser.cpp
@@ -1,24 +1,20 @@
// Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-
+
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#include "../../include/fxcrt/fx_xml.h"
#include "xml_int.h"
CXML_Parser::~CXML_Parser()
{
- if (m_bOwnedStream && m_pDataAcc) {
+ if (m_bOwnedStream) {
m_pDataAcc->Release();
}
}
FX_BOOL CXML_Parser::Init(FX_LPBYTE pBuffer, size_t size)
{
- if (m_pAllocator) {
- m_pDataAcc = FX_NewAtAllocator(m_pAllocator)CXML_DataBufAcc(pBuffer, size, m_pAllocator);
- } else {
- m_pDataAcc = FX_NEW CXML_DataBufAcc(pBuffer, size, NULL);
- }
+ m_pDataAcc = FX_NEW CXML_DataBufAcc(pBuffer, size);
if (!m_pDataAcc) {
return FALSE;
}
@@ -26,11 +22,7 @@ FX_BOOL CXML_Parser::Init(FX_LPBYTE pBuffer, size_t size)
}
FX_BOOL CXML_Parser::Init(IFX_FileRead *pFileRead)
{
- if (m_pAllocator) {
- m_pDataAcc = FX_NewAtAllocator(m_pAllocator)CXML_DataStmAcc(pFileRead, m_pAllocator);
- } else {
- m_pDataAcc = FX_NEW CXML_DataStmAcc(pFileRead, NULL);
- }
+ m_pDataAcc = FX_NEW CXML_DataStmAcc(pFileRead);
if (!m_pDataAcc) {
return FALSE;
}
@@ -136,19 +128,19 @@ void CXML_Parser::SkipWhiteSpaces()
}
} while (ReadNextBlock());
}
-void CXML_Parser::GetName(CFX_ByteStringL &space, CFX_ByteStringL &name)
+void CXML_Parser::GetName(CFX_ByteString &space, CFX_ByteString &name)
{
m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex;
if (IsEOF()) {
return;
}
- CFX_ByteTextBuf buf(m_pAllocator);
+ CFX_ByteTextBuf buf;
FX_BYTE ch;
do {
while (m_dwIndex < m_dwBufferSize) {
ch = m_pBuffer[m_dwIndex];
if (ch == ':') {
- buf.GetByteStringL(space);
+ space = buf.GetByteString();
buf.Clear();
} else if (g_FXCRT_XML_IsNameChar(ch)) {
buf.AppendChar(ch);
@@ -162,7 +154,7 @@ void CXML_Parser::GetName(CFX_ByteStringL &space, CFX_ByteStringL &name)
break;
}
} while (ReadNextBlock());
- buf.GetByteStringL(name);
+ name = buf.GetByteString();
}
void CXML_Parser::SkipLiterals(FX_BSTR str)
{
@@ -204,7 +196,7 @@ FX_DWORD CXML_Parser::GetCharRef()
}
FX_BYTE ch;
FX_INT32 iState = 0;
- CFX_ByteTextBuf buf(m_pAllocator);
+ CFX_ByteTextBuf buf;
FX_DWORD code = 0;
do {
while (m_dwIndex < m_dwBufferSize) {
@@ -283,13 +275,13 @@ FX_DWORD CXML_Parser::GetCharRef()
} while (ReadNextBlock());
return code;
}
-void CXML_Parser::GetAttrValue(CFX_WideStringL &value)
+void CXML_Parser::GetAttrValue(CFX_WideString &value)
{
m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex;
if (IsEOF()) {
return;
}
- CFX_UTF8Decoder decoder(m_pAllocator);
+ CFX_UTF8Decoder decoder;
FX_BYTE mark = 0, ch;
do {
while (m_dwIndex < m_dwBufferSize) {
@@ -310,7 +302,7 @@ void CXML_Parser::GetAttrValue(CFX_WideStringL &value)
if (ch == '&') {
decoder.AppendChar(GetCharRef());
if (IsEOF()) {
- decoder.GetResult(value);
+ value = decoder.GetResult();
return;
}
} else {
@@ -322,9 +314,9 @@ void CXML_Parser::GetAttrValue(CFX_WideStringL &value)
break;
}
} while (ReadNextBlock());
- decoder.GetResult(value);
+ value = decoder.GetResult();
}
-void CXML_Parser::GetTagName(CFX_ByteStringL &space, CFX_ByteStringL &name, FX_BOOL &bEndTag, FX_BOOL bStartTag)
+void CXML_Parser::GetTagName(CFX_ByteString &space, CFX_ByteString &name, FX_BOOL &bEndTag, FX_BOOL bStartTag)
{
m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex;
if (IsEOF()) {
@@ -379,30 +371,23 @@ CXML_Element* CXML_Parser::ParseElement(CXML_Element* pParent, FX_BOOL bStartTag
if (IsEOF()) {
return NULL;
}
- CFX_ByteStringL tag_name, tag_space;
+ CFX_ByteString tag_name, tag_space;
FX_BOOL bEndTag;
GetTagName(tag_space, tag_name, bEndTag, bStartTag);
if (tag_name.IsEmpty() || bEndTag) {
- tag_space.Empty(m_pAllocator);
return NULL;
}
CXML_Element* pElement;
- if (m_pAllocator) {
- pElement = FX_NewAtAllocator(m_pAllocator)CXML_Element(m_pAllocator);
- } else {
- pElement = FX_NEW CXML_Element;
- }
+ pElement = FX_NEW CXML_Element;
if (pElement) {
pElement->m_pParent = pParent;
pElement->SetTag(tag_space, tag_name);
}
- tag_space.Empty(m_pAllocator);
- tag_name.Empty(m_pAllocator);
if (!pElement) {
return NULL;
}
do {
- CFX_ByteStringL attr_space, attr_name;
+ CFX_ByteString attr_space, attr_name;
while (m_dwIndex < m_dwBufferSize) {
SkipWhiteSpaces();
if (IsEOF()) {
@@ -411,8 +396,6 @@ CXML_Element* CXML_Parser::ParseElement(CXML_Element* pParent, FX_BOOL bStartTag
if (!g_FXCRT_XML_IsNameIntro(m_pBuffer[m_dwIndex])) {
break;
}
- attr_space.Empty(m_pAllocator);
- attr_name.Empty(m_pAllocator);
GetName(attr_space, attr_name);
SkipWhiteSpaces();
if (IsEOF()) {
@@ -426,13 +409,10 @@ CXML_Element* CXML_Parser::ParseElement(CXML_Element* pParent, FX_BOOL bStartTag
if (IsEOF()) {
break;
}
- CFX_WideStringL attr_value;
+ CFX_WideString attr_value;
GetAttrValue(attr_value);
- pElement->m_AttrMap.SetAt(attr_space, attr_name, attr_value, m_pAllocator);
- attr_value.Empty(m_pAllocator);
+ pElement->m_AttrMap.SetAt(attr_space, attr_name, attr_value);
}
- attr_space.Empty(m_pAllocator);
- attr_name.Empty(m_pAllocator);
m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex;
if (m_dwIndex < m_dwBufferSize || IsEOF()) {
break;
@@ -450,19 +430,15 @@ CXML_Element* CXML_Parser::ParseElement(CXML_Element* pParent, FX_BOOL bStartTag
}
if (ch != '>') {
m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex;
- if (m_pAllocator) {
- FX_DeleteAtAllocator(pElement, m_pAllocator, CXML_Element);
- } else {
- delete pElement;
- }
+ delete pElement;
return NULL;
}
SkipWhiteSpaces();
if (IsEOF()) {
return pElement;
}
- CFX_UTF8Decoder decoder(m_pAllocator);
- CFX_WideTextBuf content(m_pAllocator);
+ CFX_UTF8Decoder decoder;
+ CFX_WideTextBuf content;
FX_BOOL bCDATA = FALSE;
FX_INT32 iState = 0;
do {
@@ -487,22 +463,18 @@ CXML_Element* CXML_Parser::ParseElement(CXML_Element* pParent, FX_BOOL bStartTag
SkipWhiteSpaces();
iState = 0;
} else if (ch == '/') {
- CFX_ByteStringL space, name;
+ CFX_ByteString space, name;
GetName(space, name);
- space.Empty(m_pAllocator);
- name.Empty(m_pAllocator);
SkipWhiteSpaces();
m_dwIndex ++;
iState = 10;
} else {
content << decoder.GetResult();
- CFX_WideStringL dataStr;
- content.GetWideStringL(dataStr);
+ CFX_WideString dataStr = content.GetWideString();
if (!bCDATA && !m_bSaveSpaceChars) {
dataStr.TrimRight((FX_LPCWSTR)L" \t\r\n");
}
InsertContentSegment(bCDATA, dataStr, pElement);
- dataStr.Empty(m_pAllocator);
content.Clear();
decoder.Clear();
bCDATA = FALSE;
@@ -542,13 +514,11 @@ CXML_Element* CXML_Parser::ParseElement(CXML_Element* pParent, FX_BOOL bStartTag
}
} while (ReadNextBlock());
content << decoder.GetResult();
- CFX_WideStringL dataStr;
- content.GetWideStringL(dataStr);
+ CFX_WideString dataStr = content.GetWideString();
if (!m_bSaveSpaceChars) {
dataStr.TrimRight((FX_LPCWSTR)L" \t\r\n");
}
InsertContentSegment(bCDATA, dataStr, pElement);
- dataStr.Empty(m_pAllocator);
content.Clear();
decoder.Clear();
bCDATA = FALSE;
@@ -560,15 +530,11 @@ void CXML_Parser::InsertContentSegment(FX_BOOL bCDATA, FX_WSTR content, CXML_Ele
return;
}
CXML_Content* pContent;
- if (m_pAllocator) {
- pContent = FX_NewAtAllocator(m_pAllocator)CXML_Content;
- } else {
- pContent = FX_NEW CXML_Content;
- }
+ pContent = FX_NEW CXML_Content;
if (!pContent) {
return;
}
- pContent->Set(bCDATA, content, m_pAllocator);
+ pContent->Set(bCDATA, content);
pElement->m_Children.Add((FX_LPVOID)CXML_Element::Content);
pElement->m_Children.Add(pContent);
}
@@ -581,54 +547,49 @@ static CXML_Element* XML_ContinueParse(CXML_Parser &parser, FX_BOOL bSaveSpaceCh
}
return pElement;
}
-CXML_Element* CXML_Element::Parse(const void* pBuffer, size_t size, FX_BOOL bSaveSpaceChars, FX_FILESIZE* pParsedSize, IFX_Allocator* pAllocator)
+CXML_Element* CXML_Element::Parse(const void* pBuffer, size_t size, FX_BOOL bSaveSpaceChars, FX_FILESIZE* pParsedSize)
{
- CXML_Parser parser(pAllocator);
+ CXML_Parser parser;
if (!parser.Init((FX_LPBYTE)pBuffer, size)) {
return NULL;
}
return XML_ContinueParse(parser, bSaveSpaceChars, pParsedSize);
}
-CXML_Element* CXML_Element::Parse(IFX_FileRead *pFile, FX_BOOL bSaveSpaceChars, FX_FILESIZE* pParsedSize, IFX_Allocator* pAllocator)
+CXML_Element* CXML_Element::Parse(IFX_FileRead *pFile, FX_BOOL bSaveSpaceChars, FX_FILESIZE* pParsedSize)
{
- CXML_Parser parser(pAllocator);
+ CXML_Parser parser;
if (!parser.Init(pFile)) {
return NULL;
}
return XML_ContinueParse(parser, bSaveSpaceChars, pParsedSize);
}
-CXML_Element* CXML_Element::Parse(IFX_BufferRead *pBuffer, FX_BOOL bSaveSpaceChars, FX_FILESIZE* pParsedSize, IFX_Allocator* pAllocator)
+CXML_Element* CXML_Element::Parse(IFX_BufferRead *pBuffer, FX_BOOL bSaveSpaceChars, FX_FILESIZE* pParsedSize)
{
- CXML_Parser parser(pAllocator);
+ CXML_Parser parser;
if (!parser.Init(pBuffer)) {
return NULL;
}
return XML_ContinueParse(parser, bSaveSpaceChars, pParsedSize);
}
-CXML_Element::CXML_Element(IFX_Allocator* pAllocator)
- : m_pParent(NULL)
- , m_QSpaceName()
+CXML_Element::CXML_Element()
+ : m_QSpaceName()
, m_TagName()
, m_AttrMap()
- , m_Children(pAllocator)
{
}
-CXML_Element::CXML_Element(FX_BSTR qSpace, FX_BSTR tagName, IFX_Allocator* pAllocator)
- : m_pParent(NULL)
- , m_QSpaceName()
+CXML_Element::CXML_Element(FX_BSTR qSpace, FX_BSTR tagName)
+ : m_QSpaceName()
, m_TagName()
, m_AttrMap()
- , m_Children(pAllocator)
{
- m_QSpaceName.Set(qSpace, pAllocator);
- m_TagName.Set(tagName, pAllocator);
+ m_QSpaceName = qSpace;
+ m_TagName = tagName;
}
-CXML_Element::CXML_Element(FX_BSTR qTagName, IFX_Allocator* pAllocator)
+CXML_Element::CXML_Element(FX_BSTR qTagName)
: m_pParent(NULL)
, m_QSpaceName()
, m_TagName()
, m_AttrMap()
- , m_Children(pAllocator)
{
SetTag(qTagName);
}
@@ -638,32 +599,19 @@ CXML_Element::~CXML_Element()
}
void CXML_Element::Empty()
{
- IFX_Allocator* pAllocator = m_Children.m_pAllocator;
- m_QSpaceName.Empty(pAllocator);
- m_TagName.Empty(pAllocator);
- m_AttrMap.RemoveAll(pAllocator);
RemoveChildren();
}
void CXML_Element::RemoveChildren()
{
- IFX_Allocator* pAllocator = m_Children.m_pAllocator;
for (int i = 0; i < m_Children.GetSize(); i += 2) {
ChildType type = (ChildType)(FX_UINTPTR)m_Children.GetAt(i);
if (type == Content) {
CXML_Content* content = (CXML_Content*)m_Children.GetAt(i + 1);
- if (pAllocator) {
- FX_DeleteAtAllocator(content, pAllocator, CXML_Content);
- } else {
- delete content;
- }
+ delete content;
} else if (type == Element) {
CXML_Element* child = (CXML_Element*)m_Children.GetAt(i + 1);
child->RemoveChildren();
- if (pAllocator) {
- FX_DeleteAtAllocator(child, pAllocator, CXML_Element);
- } else {
- delete child;
- }
+ delete child;
}
}
m_Children.RemoveAll();
@@ -678,25 +626,6 @@ CFX_ByteString CXML_Element::GetTagName(FX_BOOL bQualified) const
bsTag += m_TagName;
return bsTag;
}
-void CXML_Element::GetTagName(CFX_ByteStringL &tagName, FX_BOOL bQualified) const
-{
- IFX_Allocator* pAllocator = m_Children.m_pAllocator;
- if (!bQualified || m_QSpaceName.IsEmpty()) {
- tagName.Set(m_TagName, pAllocator);
- return;
- }
- FX_LPSTR str = tagName.AllocBuffer(m_QSpaceName.GetLength() + m_TagName.GetLength() + 2, pAllocator);
- if (!str) {
- return;
- }
- FXSYS_memcpy32(str, m_QSpaceName.GetCStr(), m_QSpaceName.GetLength());
- str += m_QSpaceName.GetLength();
- *str = ':';
- str ++;
- FXSYS_memcpy32(str, m_TagName.GetCStr(), m_TagName.GetLength());
- str += m_TagName.GetLength();
- *str = '\0';
-}
CFX_ByteString CXML_Element::GetNamespace(FX_BOOL bQualified) const
{
if (bQualified) {
@@ -704,18 +633,9 @@ CFX_ByteString CXML_Element::GetNamespace(FX_BOOL bQualified) const
}
return GetNamespaceURI(m_QSpaceName);
}
-void CXML_Element::GetNamespace(CFX_ByteStringL &nameSpace, FX_BOOL bQualified) const
-{
- IFX_Allocator* pAllocator = m_Children.m_pAllocator;
- if (bQualified) {
- nameSpace.Set(m_QSpaceName, pAllocator);
- return;
- }
- GetNamespaceURI(m_QSpaceName, nameSpace);
-}
CFX_ByteString CXML_Element::GetNamespaceURI(FX_BSTR qName) const
{
- const CFX_WideStringL* pwsSpace;
+ const CFX_WideString* pwsSpace;
const CXML_Element *pElement = this;
do {
if (qName.IsEmpty()) {
@@ -730,26 +650,6 @@ CFX_ByteString CXML_Element::GetNamespaceURI(FX_BSTR qName) const
} while(pElement);
return pwsSpace ? FX_UTF8Encode(*pwsSpace) : CFX_ByteString();
}
-void CXML_Element::GetNamespaceURI(FX_BSTR qName, CFX_ByteStringL &uri) const
-{
- IFX_Allocator* pAllocator = m_Children.m_pAllocator;
- const CFX_WideStringL* pwsSpace;
- const CXML_Element *pElement = this;
- do {
- if (qName.IsEmpty()) {
- pwsSpace = pElement->m_AttrMap.Lookup(FX_BSTRC(""), FX_BSTRC("xmlns"));
- } else {
- pwsSpace = pElement->m_AttrMap.Lookup(FX_BSTRC("xmlns"), qName);
- }
- if (pwsSpace) {
- break;
- }
- pElement = pElement->GetParent();
- } while(pElement);
- if (pwsSpace) {
- FX_UTF8Encode(pwsSpace->GetPtr(), pwsSpace->GetLength(), uri, pAllocator);
- }
-}
void CXML_Element::GetAttrByIndex(int index, CFX_ByteString& space, CFX_ByteString& name, CFX_WideString& value) const
{
if (index < 0 || index >= m_AttrMap.GetSize()) {
@@ -760,17 +660,6 @@ void CXML_Element::GetAttrByIndex(int index, CFX_ByteString& space, CFX_ByteStri
name = item.m_AttrName;
value = item.m_Value;
}
-void CXML_Element::GetAttrByIndex(int index, CFX_ByteStringL &space, CFX_ByteStringL &name, CFX_WideStringL &value) const
-{
- if (index < 0 || index >= m_AttrMap.GetSize()) {
- return;
- }
- IFX_Allocator* pAllocator = m_Children.m_pAllocator;
- CXML_AttrItem& item = m_AttrMap.GetAt(index);
- space.Set(item.m_QSpaceName, pAllocator);
- name.Set(item.m_AttrName, pAllocator);
- value.Set(item.m_Value, pAllocator);
-}
FX_BOOL CXML_Element::HasAttr(FX_BSTR name) const
{
CFX_ByteStringC bsSpace, bsName;
@@ -781,37 +670,27 @@ FX_BOOL CXML_Element::GetAttrValue(FX_BSTR name, CFX_WideString& attribute) cons
{
CFX_ByteStringC bsSpace, bsName;
FX_XML_SplitQualifiedName(name, bsSpace, bsName);
- const CFX_WideStringL* pValue = m_AttrMap.Lookup(bsSpace, bsName);
+ const CFX_WideString* pValue = m_AttrMap.Lookup(bsSpace, bsName);
if (pValue) {
- attribute = CFX_WideString(pValue->GetPtr(), pValue->GetLength());
+ attribute = CFX_WideString((FX_LPCWSTR)pValue, pValue->GetLength());
return TRUE;
}
return FALSE;
}
-const CFX_WideStringL* CXML_Element::GetAttrValuePtr(FX_BSTR name) const
-{
- CFX_ByteStringC bsSpace, bsName;
- FX_XML_SplitQualifiedName(name, bsSpace, bsName);
- return m_AttrMap.Lookup(bsSpace, bsName);
-}
FX_BOOL CXML_Element::GetAttrValue(FX_BSTR space, FX_BSTR name, CFX_WideString& attribute) const
{
- const CFX_WideStringL* pValue = m_AttrMap.Lookup(space, name);
+ const CFX_WideString* pValue = m_AttrMap.Lookup(space, name);
if (pValue) {
- attribute = CFX_WideString(pValue->GetPtr(), pValue->GetLength());
+ attribute = CFX_WideString((FX_LPCWSTR)pValue, pValue->GetLength());
return TRUE;
}
return FALSE;
}
-const CFX_WideStringL* CXML_Element::GetAttrValuePtr(FX_BSTR space, FX_BSTR name) const
-{
- return m_AttrMap.Lookup(space, name);
-}
FX_BOOL CXML_Element::GetAttrInteger(FX_BSTR name, int& attribute) const
{
CFX_ByteStringC bsSpace, bsName;
FX_XML_SplitQualifiedName(name, bsSpace, bsName);
- const CFX_WideStringL* pwsValue = m_AttrMap.Lookup(bsSpace, bsName);
+ const CFX_WideString* pwsValue = m_AttrMap.Lookup(bsSpace, bsName);
if (pwsValue) {
attribute = pwsValue->GetInteger();
return TRUE;
@@ -820,7 +699,7 @@ FX_BOOL CXML_Element::GetAttrInteger(FX_BSTR name, int& attribute) const
}
FX_BOOL CXML_Element::GetAttrInteger(FX_BSTR space, FX_BSTR name, int& attribute) const
{
- const CFX_WideStringL* pwsValue = m_AttrMap.Lookup(space, name);
+ const CFX_WideString* pwsValue = m_AttrMap.Lookup(space, name);
if (pwsValue) {
attribute = pwsValue->GetInteger();
return TRUE;
@@ -835,8 +714,7 @@ FX_BOOL CXML_Element::GetAttrFloat(FX_BSTR name, FX_FLOAT& attribute) const
}
FX_BOOL CXML_Element::GetAttrFloat(FX_BSTR space, FX_BSTR name, FX_FLOAT& attribute) const
{
- CFX_WideString value;
- const CFX_WideStringL* pValue = m_AttrMap.Lookup(space, name);
+ const CFX_WideString* pValue = m_AttrMap.Lookup(space, name);
if (pValue) {
attribute = pValue->GetFloat();
return TRUE;
@@ -868,19 +746,6 @@ CFX_WideString CXML_Element::GetContent(FX_DWORD index) const
}
return CFX_WideString();
}
-const CFX_WideStringL* CXML_Element::GetContentPtr(FX_DWORD index) const
-{
- index <<= 1;
- if (index >= (FX_DWORD)m_Children.GetSize() ||
- (ChildType)(FX_UINTPTR)m_Children.GetAt(index) != Content) {
- return NULL;
- }
- CXML_Content* pContent = (CXML_Content*)m_Children.GetAt(index + 1);
- if (pContent) {
- return &pContent->m_Content;
- }
- return NULL;
-}
CXML_Element* CXML_Element::GetElement(FX_DWORD index) const
{
index <<= 1;
@@ -935,7 +800,7 @@ FX_DWORD CXML_Element::FindElement(CXML_Element *pChild) const
}
return (FX_DWORD) - 1;
}
-const CFX_WideStringL* CXML_AttrMap::Lookup(FX_BSTR space, FX_BSTR name) const
+const CFX_WideString* CXML_AttrMap::Lookup(FX_BSTR space, FX_BSTR name) const
{
if (m_pMap == NULL) {
return NULL;
@@ -948,21 +813,17 @@ const CFX_WideStringL* CXML_AttrMap::Lookup(FX_BSTR space, FX_BSTR name) const
}
return NULL;
}
-void CXML_AttrMap::SetAt(FX_BSTR space, FX_BSTR name, FX_WSTR value, IFX_Allocator* pAllocator)
+void CXML_AttrMap::SetAt(FX_BSTR space, FX_BSTR name, FX_WSTR value)
{
- for (int i = 0; i < GetSize(); i ++) {
+ for (int i = 0; i < GetSize(); i++) {
CXML_AttrItem& item = GetAt(i);
if ((space.IsEmpty() || item.m_QSpaceName == space) && item.m_AttrName == name) {
- item.m_Value.Set(value, pAllocator);
+ item.m_Value = value;
return;
}
}
if (!m_pMap) {
- if (pAllocator) {
- m_pMap = FX_NewAtAllocator(pAllocator)CFX_ObjectArray<CXML_AttrItem>(pAllocator);
- } else {
- m_pMap = FX_NEW CFX_ObjectArray<CXML_AttrItem>;
- }
+ m_pMap = FX_NEW CFX_ObjectArray < CXML_AttrItem > ;
}
if (!m_pMap) {
return;
@@ -971,11 +832,11 @@ void CXML_AttrMap::SetAt(FX_BSTR space, FX_BSTR name, FX_WSTR value, IFX_Allocat
if (!pItem) {
return;
}
- pItem->m_QSpaceName.Set(space, pAllocator);
- pItem->m_AttrName.Set(name, pAllocator);
- pItem->m_Value.Set(value, pAllocator);
+ pItem->m_QSpaceName = space;
+ pItem->m_AttrName = name;
+ pItem->m_Value = value;
}
-void CXML_AttrMap::RemoveAt(FX_BSTR space, FX_BSTR name, IFX_Allocator* pAllocator)
+void CXML_AttrMap::RemoveAt(FX_BSTR space, FX_BSTR name)
{
if (m_pMap == NULL) {
return;
@@ -983,7 +844,6 @@ void CXML_AttrMap::RemoveAt(FX_BSTR space, FX_BSTR name, IFX_Allocator* pAllocat
for (int i = 0; i < m_pMap->GetSize(); i ++) {
CXML_AttrItem& item = GetAt(i);
if ((space.IsEmpty() || item.m_QSpaceName == space) && item.m_AttrName == name) {
- item.Empty(pAllocator);
m_pMap->RemoveAt(i);
return;
}
@@ -998,20 +858,15 @@ CXML_AttrItem& CXML_AttrMap::GetAt(int index) const
ASSERT(m_pMap != NULL);
return (*m_pMap)[index];
}
-void CXML_AttrMap::RemoveAll(IFX_Allocator* pAllocator)
+void CXML_AttrMap::RemoveAll()
{
if (!m_pMap) {
return;
}
for (int i = 0; i < m_pMap->GetSize(); i ++) {
CXML_AttrItem& item = (*m_pMap)[i];
- item.Empty(pAllocator);
}
m_pMap->RemoveAll();
- if (pAllocator) {
- FX_DeleteAtAllocator(m_pMap, pAllocator, CFX_ObjectArray<CXML_AttrItem>);
- } else {
- delete m_pMap;
- }
+ delete m_pMap;
m_pMap = NULL;
}
diff --git a/core/src/fxcrt/fxcrt_platforms.cpp b/core/src/fxcrt/fxcrt_platforms.cpp
index 7fb3adae40..e14e362079 100644
--- a/core/src/fxcrt/fxcrt_platforms.cpp
+++ b/core/src/fxcrt/fxcrt_platforms.cpp
@@ -7,13 +7,9 @@
#include "../../include/fxcrt/fx_ext.h"
#include "fxcrt_platforms.h"
#if (_FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ && _FXM_PLATFORM_ != _FXM_PLATFORM_LINUX_ && _FXM_PLATFORM_ != _FXM_PLATFORM_APPLE_ && _FXM_PLATFORM_ != _FXM_PLATFORM_ANDROID_)
-IFXCRT_FileAccess* FXCRT_FileAccess_Create(IFX_Allocator* pAllocator)
+IFXCRT_FileAccess* FXCRT_FileAccess_Create()
{
- if (pAllocator) {
- return FX_NewAtAllocator(pAllocator) CFXCRT_FileAccess_CRT;
- } else {
- return FX_NEW CFXCRT_FileAccess_CRT;
- }
+ return FX_NEW CFXCRT_FileAccess_CRT;
}
void FXCRT_GetFileModeString(FX_DWORD dwModes, CFX_ByteString &bsMode)
{
@@ -71,13 +67,9 @@ void CFXCRT_FileAccess_CRT::Close()
FXSYS_fclose(m_hFile);
m_hFile = NULL;
}
-void CFXCRT_FileAccess_CRT::Release(IFX_Allocator* pAllocator)
+void CFXCRT_FileAccess_CRT::Release()
{
- if (pAllocator) {
- FX_DeleteAtAllocator(this, pAllocator, CFXCRT_FileAccess_CRT);
- } else {
- delete this;
- }
+ delete this;
}
FX_FILESIZE CFXCRT_FileAccess_CRT::GetSize() const
{
diff --git a/core/src/fxcrt/fxcrt_platforms.h b/core/src/fxcrt/fxcrt_platforms.h
index 4cb839961d..dbdff6aba0 100644
--- a/core/src/fxcrt/fxcrt_platforms.h
+++ b/core/src/fxcrt/fxcrt_platforms.h
@@ -18,7 +18,7 @@ public:
virtual FX_BOOL Open(FX_BSTR fileName, FX_DWORD dwMode);
virtual FX_BOOL Open(FX_WSTR fileName, FX_DWORD dwMode);
virtual void Close();
- virtual void Release(IFX_Allocator* pAllocator = NULL);
+ virtual void Release();
virtual FX_FILESIZE GetSize() const;
virtual FX_FILESIZE GetPosition() const;
virtual FX_FILESIZE SetPosition(FX_FILESIZE pos);
diff --git a/core/src/fxcrt/fxcrt_posix.cpp b/core/src/fxcrt/fxcrt_posix.cpp
index 558f33466b..98f9a71c6c 100644
--- a/core/src/fxcrt/fxcrt_posix.cpp
+++ b/core/src/fxcrt/fxcrt_posix.cpp
@@ -7,13 +7,9 @@
#include "../../include/fxcrt/fx_ext.h"
#include "fxcrt_posix.h"
#if _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_ || _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ || _FXM_PLATFORM_ == _FXM_PLATFORM_ANDROID_
-IFXCRT_FileAccess* FXCRT_FileAccess_Create(IFX_Allocator* pAllocator)
+IFXCRT_FileAccess* FXCRT_FileAccess_Create()
{
- if (pAllocator) {
- return FX_NewAtAllocator(pAllocator) CFXCRT_FileAccess_Posix();
- } else {
- return FX_NEW CFXCRT_FileAccess_Posix;
- }
+ return FX_NEW CFXCRT_FileAccess_Posix;
}
void FXCRT_Posix_GetFileMode(FX_DWORD dwModes, FX_INT32 &nFlags, FX_INT32 &nMasks)
{
@@ -59,13 +55,9 @@ void CFXCRT_FileAccess_Posix::Close()
close(m_nFD);
m_nFD = -1;
}
-void CFXCRT_FileAccess_Posix::Release(IFX_Allocator* pAllocator)
+void CFXCRT_FileAccess_Posix::Release()
{
- if (pAllocator) {
- FX_DeleteAtAllocator(this, pAllocator, CFXCRT_FileAccess_Posix);
- } else {
- delete this;
- }
+ delete this;
}
FX_FILESIZE CFXCRT_FileAccess_Posix::GetSize() const
{
diff --git a/core/src/fxcrt/fxcrt_posix.h b/core/src/fxcrt/fxcrt_posix.h
index f76e35cdd1..db4377f5f2 100644
--- a/core/src/fxcrt/fxcrt_posix.h
+++ b/core/src/fxcrt/fxcrt_posix.h
@@ -16,7 +16,7 @@ public:
virtual FX_BOOL Open(FX_BSTR fileName, FX_DWORD dwMode);
virtual FX_BOOL Open(FX_WSTR fileName, FX_DWORD dwMode);
virtual void Close();
- virtual void Release(IFX_Allocator* pAllocator = NULL);
+ virtual void Release();
virtual FX_FILESIZE GetSize() const;
virtual FX_FILESIZE GetPosition() const;
virtual FX_FILESIZE SetPosition(FX_FILESIZE pos);
diff --git a/core/src/fxcrt/fxcrt_windows.cpp b/core/src/fxcrt/fxcrt_windows.cpp
index 9b77b33ca2..6b0f0f290d 100644
--- a/core/src/fxcrt/fxcrt_windows.cpp
+++ b/core/src/fxcrt/fxcrt_windows.cpp
@@ -1,7 +1,7 @@
// Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-
+
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#include "../../include/fxcrt/fx_ext.h"
@@ -23,13 +23,9 @@ FX_BOOL FX_File_Exist(FX_WSTR fileName)
}
return (dwAttri & FILE_ATTRIBUTE_DIRECTORY) == 0;
}
-IFXCRT_FileAccess* FXCRT_FileAccess_Create(IFX_Allocator* pAllocator)
+IFXCRT_FileAccess* FXCRT_FileAccess_Create()
{
- if (pAllocator) {
- return FX_NewAtAllocator(pAllocator) CFXCRT_FileAccess_Win64;
- } else {
- return FX_NEW CFXCRT_FileAccess_Win64;
- }
+ return FX_NEW CFXCRT_FileAccess_Win64;
}
void FXCRT_Windows_GetFileMode(FX_DWORD dwMode, FX_DWORD &dwAccess, FX_DWORD &dwShare, FX_DWORD &dwCreation)
{
@@ -92,13 +88,9 @@ void CFXCRT_FileAccess_Win64::Close()
::CloseHandle(m_hFile);
m_hFile = NULL;
}
-void CFXCRT_FileAccess_Win64::Release(IFX_Allocator* pAllocator)
+void CFXCRT_FileAccess_Win64::Release()
{
- if (pAllocator) {
- FX_DeleteAtAllocator(this, pAllocator, CFXCRT_FileAccess_Win64);
- } else {
- delete this;
- }
+ delete this;
}
FX_FILESIZE CFXCRT_FileAccess_Win64::GetSize() const
{
diff --git a/core/src/fxcrt/fxcrt_windows.h b/core/src/fxcrt/fxcrt_windows.h
index 9c2e428782..39d72554da 100644
--- a/core/src/fxcrt/fxcrt_windows.h
+++ b/core/src/fxcrt/fxcrt_windows.h
@@ -1,7 +1,7 @@
// Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-
+
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#ifndef _FXCRT_WINDOWS_
@@ -16,7 +16,7 @@ public:
virtual FX_BOOL Open(FX_BSTR fileName, FX_DWORD dwMode);
virtual FX_BOOL Open(FX_WSTR fileName, FX_DWORD dwMode);
virtual void Close();
- virtual void Release(IFX_Allocator* pAllocator = NULL);
+ virtual void Release();
virtual FX_FILESIZE GetSize() const;
virtual FX_FILESIZE GetPosition() const;
virtual FX_FILESIZE SetPosition(FX_FILESIZE pos);
diff --git a/core/src/fxcrt/mem_int.h b/core/src/fxcrt/mem_int.h
deleted file mode 100644
index 3e3d25a7ec..0000000000
--- a/core/src/fxcrt/mem_int.h
+++ /dev/null
@@ -1,232 +0,0 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#ifndef _FXM_MEM_INT_H_
-#define _FXM_MEM_INT_H_
-struct FX_DefAllocator {
- IFX_Allocator m_Allocator;
- struct CFX_MemoryMgr* m_pFoxitMgr;
-};
-struct CFX_MemoryMgr {
-public:
- FXMEM_SystemMgr* m_pSystemMgr;
- FX_DefAllocator m_DefAllocator;
- FX_LPVOID m_pExternalMemory;
- FX_BOOL m_bReleaseMgr;
- void Init(FXMEM_SystemMgr* pSystemMgr);
- void* Alloc(size_t size, int flags);
- void* AllocDebug(size_t size, int flags, FX_LPCSTR file, int line);
- void* Realloc(void* p, size_t size, int flags);
- void* ReallocDebug(void* p, size_t size, int flags, FX_LPCSTR file, int line);
- void Free(void* p, int flags);
- void PurgeMgr();
-};
-extern CFX_MemoryMgr* g_pDefFoxitMgr;
-#define FIXEDMEM_PAGE_EXTRASPACE sizeof(size_t)
-#define FIXEDMEM_BLOCKNUM(bs) (8 * (FX_FIXEDMEM_PAGESIZE - FIXEDMEM_PAGE_EXTRASPACE) / (8 * bs + 1))
-#define FIXEDMEM_8BYTES_BLOCKNUM FIXEDMEM_BLOCKNUM(8)
-#define FIXEDMEM_16BYTES_BLOCKNUM FIXEDMEM_BLOCKNUM(16)
-#define FIXEDMEM_32BYTES_BLOCKNUM FIXEDMEM_BLOCKNUM(32)
-extern const FX_BYTE ZeroLeadPos[256];
-extern const FX_BYTE OneLeadPos[256];
-template <size_t blockNum, size_t blockSize>
-class CFXMEM_FixedPage
-{
-public:
- void Initialize()
- {
- m_nAvailCount = blockNum;
- FXSYS_memset32(m_BusyMap, 0, (blockNum + 7) / 8);
- }
- FX_BOOL HasFreeBlock() const
- {
- return (FX_BOOL)m_nAvailCount;
- }
- FX_LPVOID Alloc(size_t size)
- {
- FXSYS_assert(m_nAvailCount);
- FX_LPDWORD pFind = (FX_LPDWORD)m_BusyMap;
- size_t i = 0;
- while (i < (blockNum + 7) / 8 / 4 && pFind[i] == 0xFFFFFFFF) {
- i ++;
- }
- i *= 4;
- while (m_BusyMap[i] == 0xFF) {
- i ++;
- }
- size_t pos = ZeroLeadPos[m_BusyMap[i]];
- m_BusyMap[i] |= 1 << (7 - pos);
- m_nAvailCount --;
- return (FX_LPBYTE)(this + 1) + (i * 8 + pos) * blockSize;
- }
- void Free(FX_LPVOID p)
- {
- FXSYS_assert(p > (FX_LPVOID)this && p < (FX_LPVOID)((FX_LPBYTE)this + FX_FIXEDMEM_PAGESIZE));
- size_t pos = ((FX_LPBYTE)p - (FX_LPBYTE)(this + 1)) / blockSize;
- m_BusyMap[pos / 8] &= ~(1 << (7 - (pos % 8)));
- m_nAvailCount ++;
- }
- volatile size_t m_nAvailCount;
- FX_BYTE m_BusyMap[(blockNum + 7) / 8];
-};
-typedef CFXMEM_FixedPage<FIXEDMEM_8BYTES_BLOCKNUM, 8> CFXMEM_8BytesPage;
-typedef CFXMEM_FixedPage<FIXEDMEM_16BYTES_BLOCKNUM, 16> CFXMEM_16BytesPage;
-typedef CFXMEM_FixedPage<FIXEDMEM_32BYTES_BLOCKNUM, 32> CFXMEM_32BytesPage;
-template <size_t blockNum, size_t blockSize>
-class CFXMEM_FixedPages
-{
-public:
- typedef CFXMEM_FixedPage<blockNum, blockSize> T;
- FX_LPBYTE m_pStartPage;
- FX_LPBYTE m_pLimitPos;
- FX_LPBYTE m_pCurPage;
- volatile size_t m_nAvailBlocks;
- void Initialize(FX_LPBYTE pStart, size_t pages)
- {
- m_pStartPage = m_pCurPage = pStart;
- m_nAvailBlocks = pages * blockNum;
- for (size_t n = 0; n < pages; n ++) {
- ((T*)pStart)->Initialize();
- pStart += FX_FIXEDMEM_PAGESIZE;
- }
- m_pLimitPos = pStart;
- }
- FX_BOOL IsEmpty() const
- {
- return m_nAvailBlocks == (m_pLimitPos - m_pStartPage) / FX_FIXEDMEM_PAGESIZE * blockNum;
- }
- FX_BOOL HasFreeBlock() const
- {
- return (FX_BOOL)m_nAvailBlocks;
- }
- FX_LPVOID Alloc(size_t size)
- {
- FXSYS_assert(m_nAvailBlocks);
- do {
- if (((T*)m_pCurPage)->HasFreeBlock()) {
- m_nAvailBlocks --;
- return ((T*)m_pCurPage)->Alloc(size);
- }
- m_pCurPage += FX_FIXEDMEM_PAGESIZE;
- if (m_pCurPage == m_pLimitPos) {
- m_pCurPage = m_pStartPage;
- }
- } while (TRUE);
- return NULL;
- }
- void Free(FX_LPVOID p)
- {
- FXSYS_assert(p > (FX_LPVOID)m_pStartPage && p < (FX_LPVOID)m_pLimitPos);
- ((T*)(m_pStartPage + ((FX_LPBYTE)p - m_pStartPage) / FX_FIXEDMEM_PAGESIZE * FX_FIXEDMEM_PAGESIZE))->Free(p);
- m_nAvailBlocks ++;
- }
-};
-typedef CFXMEM_FixedPages<FIXEDMEM_8BYTES_BLOCKNUM, 8> CFXMEM_8BytesPages;
-typedef CFXMEM_FixedPages<FIXEDMEM_16BYTES_BLOCKNUM, 16> CFXMEM_16BytesPages;
-typedef CFXMEM_FixedPages<FIXEDMEM_32BYTES_BLOCKNUM, 32> CFXMEM_32BytesPages;
-class CFXMEM_Block
-{
-public:
- size_t m_nBlockSize;
- CFXMEM_Block* m_pNextBlock;
-};
-class CFXMEM_Page
-{
-public:
- size_t m_nAvailSize;
- CFXMEM_Block* m_pLimitPos;
- CFXMEM_Block m_AvailHead;
- void Initialize(size_t size);
- FX_BOOL IsEmpty() const
- {
- return m_AvailHead.m_pNextBlock && m_AvailHead.m_nBlockSize == m_AvailHead.m_pNextBlock->m_nBlockSize;
- }
- FX_LPVOID Alloc(size_t size);
- FX_LPVOID Realloc(FX_LPVOID p, size_t oldSize, size_t newSize);
- void Free(FX_LPVOID p);
-protected:
- FX_LPVOID Alloc(CFXMEM_Block* pPrevBlock, CFXMEM_Block* pNextBlock, size_t size, size_t oldsize);
-};
-class CFXMEM_Pages
-{
-public:
- CFXMEM_Page* m_pStartPage;
- CFXMEM_Page* m_pLimitPos;
- CFXMEM_Page* m_pCurPage;
- size_t m_nPageSize;
- void Initialize(FX_LPBYTE pStart, size_t pageSize, size_t pages);
- FX_BOOL IsEmpty() const;
- FX_LPVOID Alloc(size_t size);
- FX_LPVOID Realloc(FX_LPVOID p, size_t oldSize, size_t newSize);
- void Free(FX_LPVOID p);
-};
-class CFXMEM_Pool
-{
-public:
- CFXMEM_Pool* m_pPrevPool;
- CFXMEM_Pool* m_pNextPool;
- CFXMEM_8BytesPages m_8BytesPages;
- CFXMEM_16BytesPages m_16BytesPages;
- CFXMEM_32BytesPages m_32BytesPages;
- CFXMEM_Pages m_MidPages;
- FX_BOOL m_bAlone;
- FX_DWORD m_dwReserved[3];
- FX_LPVOID m_pLimitPos;
- CFXMEM_Page* m_pLargePage;
- void Initialize(const FX_MEMCONFIG* pMemConfig, size_t size, size_t pageNum8Bytes, size_t pageNum16Bytes, size_t pageNum32Bytes, size_t pageNumMid);
- FX_BOOL IsEmpty() const;
- size_t GetSize(FX_LPVOID p) const;
- FX_LPVOID Realloc(FX_LPVOID p, size_t oldSize, size_t newSize);
- void Free(FX_LPVOID p);
-};
-class CFXMEM_FixedMgr
-{
-public:
- void Initialize(size_t size);
- FX_LPVOID Alloc(size_t size);
- FX_LPVOID Realloc(FX_LPVOID p, size_t newSize);
- void Free(FX_LPVOID p);
- void FreeAll();
- void Purge();
- CFXMEM_Pool* GetFirstPool()
- {
- return &m_FirstPool;
- }
- size_t GetSize(FX_LPVOID p) const;
- FXMEM_SystemMgr m_SystemMgr;
- FXMEM_SystemMgr2* m_pExtender;
- FX_LPVOID m_pReserved;
- FX_MEMCONFIG m_MemConfig;
-protected:
- FX_LPVOID Alloc16(CFXMEM_Pool **pp32Pool = NULL, size_t size = 0);
- FX_LPVOID Alloc32(size_t size);
- FX_LPVOID AllocSmall(size_t size);
- FX_LPVOID AllocMid(size_t size);
- FX_LPVOID AllocLarge(size_t size);
- FX_LPVOID ReallocSmall(CFXMEM_Pool* pPool, FX_LPVOID p, size_t oldSize, size_t newSize);
- void FreePool(CFXMEM_Pool* pPool);
- CFXMEM_Pool m_FirstPool;
-};
-#define FIXEDMEM_PROXYSIZE_0 (1024 * 1024 * 8)
-#define FIXEDMEM_PROXYSIZE_1 (1024 * 1024 * 16)
-#define FIXEDMEM_PROXYSIZE_2 (1024 * 1024 * 32)
-#define FIXEDMEM_PROXYSIZE_3 (1024 * 1024 * 64)
-#define FIXEDMEM_PROXYSIZE_4 (1024 * 1024 * 128)
-#define FIXEDMEM_PROXYSIZE_5 (1024 * 1024 * 256)
-const FX_MEMCONFIG* FixedMgr_GetConfig(size_t nSize);
-class CFixedMgr_Proxy
-{
-public:
- FXMEM_FoxitMgr* Initialize(FX_LPVOID pBuffer, size_t nSize, FX_BOOL bExtensible);
- static FX_BOOL Common_More(FXMEM_SystemMgr2* pMgr, size_t alloc_size, void** new_memory, size_t* new_size);
- static void Common_Free(FXMEM_SystemMgr2* pMgr, void* memory);
- FXMEM_SystemMgr2 m_SystemMgr;
- CFXMEM_Page* m_pFixedPage;
- FX_LPVOID m_pBuffer;
- size_t m_nSize;
- FX_BOOL m_bExtensible;
-};
-#endif
diff --git a/core/src/fxcrt/plex.h b/core/src/fxcrt/plex.h
index e982fd67a4..f8f01948e5 100644
--- a/core/src/fxcrt/plex.h
+++ b/core/src/fxcrt/plex.h
@@ -1,7 +1,7 @@
// Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-
+
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
struct CFX_Plex {
@@ -10,6 +10,6 @@ struct CFX_Plex {
{
return this + 1;
}
- static CFX_Plex* Create(IFX_Allocator* pAllocator, CFX_Plex*& head, FX_DWORD nMax, FX_DWORD cbElement);
- void FreeDataChain(IFX_Allocator* pAllocator);
+ static CFX_Plex* Create(CFX_Plex*& head, FX_DWORD nMax, FX_DWORD cbElement);
+ void FreeDataChain();
};
diff --git a/core/src/fxcrt/xml_int.h b/core/src/fxcrt/xml_int.h
index 09737893af..1f75928e51 100644
--- a/core/src/fxcrt/xml_int.h
+++ b/core/src/fxcrt/xml_int.h
@@ -1,7 +1,7 @@
// Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-
+
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#ifndef _FXCRT_XML_INT_
@@ -9,9 +9,8 @@
class CXML_DataBufAcc : public IFX_BufferRead, public CFX_Object
{
public:
- CXML_DataBufAcc(FX_LPCBYTE pBuffer, size_t size, IFX_Allocator* pAllocator = NULL)
- : m_pAllocator(pAllocator)
- , m_pBuffer(pBuffer)
+ CXML_DataBufAcc(FX_LPCBYTE pBuffer, size_t size)
+ : m_pBuffer(pBuffer)
, m_dwSize(size)
, m_dwCurPos(0)
{
@@ -19,11 +18,7 @@ public:
virtual ~CXML_DataBufAcc() {}
virtual void Release()
{
- if (m_pAllocator) {
- FX_DeleteAtAllocator(this, m_pAllocator, CXML_DataBufAcc);
- } else {
- delete this;
- }
+ delete this;
}
virtual FX_BOOL IsEOF()
{
@@ -61,7 +56,6 @@ public:
return 0;
}
protected:
- IFX_Allocator* m_pAllocator;
FX_LPCBYTE m_pBuffer;
size_t m_dwSize;
size_t m_dwCurPos;
@@ -70,9 +64,8 @@ protected:
class CXML_DataStmAcc : public IFX_BufferRead, public CFX_Object
{
public:
- CXML_DataStmAcc(IFX_FileRead *pFileRead, IFX_Allocator* pAllocator = NULL)
- : m_pAllocator(pAllocator)
- , m_pFileRead(pFileRead)
+ CXML_DataStmAcc(IFX_FileRead *pFileRead)
+ : m_pFileRead(pFileRead)
, m_pBuffer(NULL)
, m_nStart(0)
, m_dwSize(0)
@@ -82,16 +75,12 @@ public:
virtual ~CXML_DataStmAcc()
{
if (m_pBuffer) {
- FX_Allocator_Free(m_pAllocator, m_pBuffer);
+ FX_Free(m_pBuffer);
}
}
virtual void Release()
{
- if (m_pAllocator) {
- FX_DeleteAtAllocator(this, m_pAllocator, CXML_DataStmAcc);
- } else {
- delete this;
- }
+ delete this;
}
virtual FX_BOOL IsEOF()
{
@@ -117,7 +106,7 @@ public:
}
m_dwSize = (size_t)FX_MIN(FX_XMLDATASTREAM_BufferSize, nLength - m_nStart);
if (!m_pBuffer) {
- m_pBuffer = FX_Allocator_Alloc(m_pAllocator, FX_BYTE, m_dwSize);
+ m_pBuffer = FX_Alloc(FX_BYTE, m_dwSize);
if (!m_pBuffer) {
return FALSE;
}
@@ -137,7 +126,6 @@ public:
return m_nStart;
}
protected:
- IFX_Allocator* m_pAllocator;
IFX_FileRead *m_pFileRead;
FX_LPBYTE m_pBuffer;
FX_FILESIZE m_nStart;
@@ -146,9 +134,7 @@ protected:
class CXML_Parser
{
public:
- CXML_Parser(IFX_Allocator* pAllocator = NULL) : m_pAllocator(pAllocator) {}
~CXML_Parser();
- IFX_Allocator* m_pAllocator;
IFX_BufferRead* m_pDataAcc;
FX_BOOL m_bOwnedStream;
FX_FILESIZE m_nOffset;
@@ -165,10 +151,10 @@ public:
FX_BOOL IsEOF();
FX_BOOL HaveAvailData();
void SkipWhiteSpaces();
- void GetName(CFX_ByteStringL &space, CFX_ByteStringL &name);
- void GetAttrValue(CFX_WideStringL &value);
+ void GetName(CFX_ByteString& space, CFX_ByteString& name);
+ void GetAttrValue(CFX_WideString &value);
FX_DWORD GetCharRef();
- void GetTagName(CFX_ByteStringL &space, CFX_ByteStringL &name, FX_BOOL &bEndTag, FX_BOOL bStartTag = FALSE);
+ void GetTagName(CFX_ByteString &space, CFX_ByteString &name, FX_BOOL &bEndTag, FX_BOOL bStartTag = FALSE);
void SkipLiterals(FX_BSTR str);
CXML_Element* ParseElement(CXML_Element* pParent, FX_BOOL bStartTag = FALSE);
void InsertContentSegment(FX_BOOL bCDATA, FX_WSTR content, CXML_Element* pElement);
diff --git a/core/src/fxge/dib/fx_dib_convert.cpp b/core/src/fxge/dib/fx_dib_convert.cpp
index 2a74452626..ddc24cc4ad 100644
--- a/core/src/fxge/dib/fx_dib_convert.cpp
+++ b/core/src/fxge/dib/fx_dib_convert.cpp
@@ -239,7 +239,6 @@ FX_BOOL CFX_Palette::BuildPalette(const CFX_DIBSource* pBitmap, int pal_type)
if (!m_pPalette) {
return FALSE;
}
- FXSYS_memset32(m_pPalette, 0, sizeof(FX_DWORD) * 256);
int bpp = pBitmap->GetBPP() / 8;
int width = pBitmap->GetWidth();
int height = pBitmap->GetHeight();
@@ -259,8 +258,6 @@ FX_BOOL CFX_Palette::BuildPalette(const CFX_DIBSource* pBitmap, int pal_type)
if (!m_aLut) {
return FALSE;
}
- FXSYS_memset32(m_aLut, 0, sizeof(FX_DWORD) * 4096);
- FXSYS_memset32(m_cLut, 0, sizeof(FX_DWORD) * 4096);
int row, col;
m_lut = 0;
for (row = 0; row < height; row++) {
@@ -878,7 +875,6 @@ FX_BOOL ConvertBuffer(FXDIB_Format dest_format, FX_LPBYTE dest_buf, int dest_pit
if (!d_pal) {
return FALSE;
}
- FXSYS_memset32(d_pal, 0, sizeof(FX_DWORD) * 256);
if (((src_format & 0xff) == 1 || (src_format & 0xff) == 8) && pSrcBitmap->GetPalette()) {
return _ConvertBuffer_Plt2PltRgb8(dest_buf, dest_pitch, width, height, pSrcBitmap, src_left, src_top, d_pal, pIccTransform);
} else if ((src_format & 0xff) >= 24) {
diff --git a/core/src/fxge/dib/fx_dib_engine.cpp b/core/src/fxge/dib/fx_dib_engine.cpp
index a51038628e..803d906ff9 100644
--- a/core/src/fxge/dib/fx_dib_engine.cpp
+++ b/core/src/fxge/dib/fx_dib_engine.cpp
@@ -32,7 +32,6 @@ void CWeightTable::Calc(int dest_len, int dest_min, int dest_max, int src_len, i
if (m_pWeightTables == NULL) {
return;
}
- FXSYS_memset32(m_pWeightTables, 0, sizeof(FX_BYTE) * ((dest_max - dest_min)*m_ItemSize + 4));
if ((flags & FXDIB_NOSMOOTH) != 0 || FXSYS_fabs((FX_FLOAT)scale) < 1.0f) {
for (int dest_pixel = dest_min; dest_pixel < dest_max; dest_pixel ++) {
PixelWeight& pixel_weights = *GetPixelWeight(dest_pixel);
@@ -207,7 +206,6 @@ CStretchEngine::CStretchEngine(IFX_ScanlineComposer* pDestBitmap, FXDIB_Format d
if (m_pDestScanline == NULL) {
return;
}
- FXSYS_memset32(m_pDestScanline, 0, sizeof(FX_BYTE) * size);
if (dest_format == FXDIB_Rgb32) {
FXSYS_memset8(m_pDestScanline, 255, size);
}
diff --git a/core/src/fxge/dib/fx_dib_main.cpp b/core/src/fxge/dib/fx_dib_main.cpp
index 7644e39f02..3e1e8cf91b 100644
--- a/core/src/fxge/dib/fx_dib_main.cpp
+++ b/core/src/fxge/dib/fx_dib_main.cpp
@@ -91,7 +91,6 @@ FX_BOOL CFX_DIBitmap::Create(int width, int height, FXDIB_Format format, FX_LPBY
if (m_pBuffer == NULL) {
return FALSE;
}
- FXSYS_memset32(m_pBuffer, 0, sizeof (FX_BYTE) * size);
}
m_Width = width;
m_Height = height;
diff --git a/core/src/fxge/win32/fx_win32_dib.cpp b/core/src/fxge/win32/fx_win32_dib.cpp
index 0093d5e41b..e369073cc2 100644
--- a/core/src/fxge/win32/fx_win32_dib.cpp
+++ b/core/src/fxge/win32/fx_win32_dib.cpp
@@ -224,7 +224,6 @@ CFX_DIBitmap* CFX_WindowsDIB::LoadFromDDB(HDC hDC, HBITMAP hBitmap, FX_DWORD* pP
}
return NULL;
}
- FXSYS_memset32(pbmih, 0, sizeof (BITMAPINFOHEADER));
pbmih->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
pbmih->bmiHeader.biBitCount = bmih.biBitCount;
pbmih->bmiHeader.biCompression = BI_RGB;
diff --git a/core/src/fxge/win32/fx_win32_gdipext.cpp b/core/src/fxge/win32/fx_win32_gdipext.cpp
index 7b586ea32a..1aada3a1f3 100644
--- a/core/src/fxge/win32/fx_win32_gdipext.cpp
+++ b/core/src/fxge/win32/fx_win32_gdipext.cpp
@@ -1200,7 +1200,6 @@ static PREVIEW3_DIBITMAP* LoadDIBitmap(WINDIB_Open_Args_ args)
return NULL;
}
BITMAPINFOHEADER* pbmih = (BITMAPINFOHEADER*)buf;
- FXSYS_memset32(buf, 0, info_size);
pbmih->biBitCount = bpp;
pbmih->biCompression = BI_RGB;
pbmih->biHeight = -(int)height;