1ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov// Copyright 2014 PDFium Authors. All rights reserved.
2ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov// Use of this source code is governed by a BSD-style license that can be
3ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov// found in the LICENSE file.
4ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
5ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
7ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#include "../../include/fxcrt/fx_basic.h"
8ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#include "plex.h"
9ee451cb395940862dad63c85adfe8f2fd55e864cSvet GanovCFX_Plex* CFX_Plex::Create(IFX_Allocator* pAllocator, CFX_Plex*& pHead, FX_DWORD nMax, FX_DWORD cbElement)
10ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
11ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_Plex* p = (CFX_Plex*)FX_Allocator_Alloc(pAllocator, FX_BYTE, sizeof(CFX_Plex) + nMax * cbElement);
12ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (!p) {
13ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return NULL;
14ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
15ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    p->pNext = pHead;
16ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    pHead = p;
17ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    return p;
18ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
19ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CFX_Plex::FreeDataChain(IFX_Allocator* pAllocator)
20ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
21ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_Plex* p = this;
22ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    while (p != NULL) {
23ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        FX_BYTE* bytes = (FX_BYTE*) p;
24ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        CFX_Plex* pNext = p->pNext;
25ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        FX_Allocator_Free(pAllocator, bytes);
26ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        p = pNext;
27ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
28ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
29