2001-09-25 01:25:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.1 (the "License"); you may not use this file except in
|
|
|
|
* compliance with the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/NPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
1999-11-06 03:43:54 +00:00
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2001-09-25 01:25:13 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1999
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the NPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the NPL, the GPL or the LGPL.
|
1999-11-06 03:43:54 +00:00
|
|
|
*
|
2001-09-25 01:25:13 +00:00
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-03-12 07:39:27 +00:00
|
|
|
|
|
|
|
#ifndef _MDB_
|
|
|
|
#include "mdb.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _MORK_
|
|
|
|
#include "mork.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _MORKNODE_
|
|
|
|
#include "morkNode.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _MORKENV_
|
|
|
|
#include "morkEnv.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _MORKPOOL_
|
|
|
|
#include "morkPool.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _MORKATOM_
|
|
|
|
#include "morkAtom.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _MORKHANDLE_
|
|
|
|
#include "morkHandle.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _MORKCELL_
|
|
|
|
#include "morkCell.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _MORKROW_
|
|
|
|
#include "morkRow.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _MORKBLOB_
|
|
|
|
#include "morkBlob.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _MORKDEQUE_
|
|
|
|
#include "morkDeque.h"
|
|
|
|
#endif
|
|
|
|
|
1999-09-22 05:35:28 +00:00
|
|
|
#ifndef _MORKZONE_
|
|
|
|
#include "morkZone.h"
|
|
|
|
#endif
|
|
|
|
|
1999-03-12 07:39:27 +00:00
|
|
|
//3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
|
|
|
|
|
|
|
|
// ````` ````` ````` ````` `````
|
|
|
|
// { ===== begin morkNode interface =====
|
|
|
|
|
|
|
|
/*public virtual*/ void
|
|
|
|
morkPool::CloseMorkNode(morkEnv* ev) // ClosePool() only if open
|
|
|
|
{
|
|
|
|
if ( this->IsOpenNode() )
|
|
|
|
{
|
|
|
|
this->MarkClosing();
|
|
|
|
this->ClosePool(ev);
|
|
|
|
this->MarkShut();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*public virtual*/
|
|
|
|
morkPool::~morkPool() // assert ClosePool() executed earlier
|
|
|
|
{
|
|
|
|
MORK_ASSERT(this->IsShutNode());
|
|
|
|
}
|
|
|
|
|
|
|
|
/*public non-poly*/
|
|
|
|
morkPool::morkPool(const morkUsage& inUsage, nsIMdbHeap* ioHeap,
|
|
|
|
nsIMdbHeap* ioSlotHeap)
|
|
|
|
: morkNode(inUsage, ioHeap)
|
|
|
|
, mPool_Heap( ioSlotHeap )
|
1999-09-22 05:35:28 +00:00
|
|
|
, mPool_UsedFramesCount( 0 )
|
|
|
|
, mPool_FreeFramesCount( 0 )
|
1999-03-12 07:39:27 +00:00
|
|
|
{
|
|
|
|
// mPool_Heap is NOT refcounted
|
|
|
|
MORK_ASSERT(ioSlotHeap);
|
|
|
|
if ( ioSlotHeap )
|
|
|
|
mNode_Derived = morkDerived_kPool;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*public non-poly*/
|
|
|
|
morkPool::morkPool(morkEnv* ev,
|
|
|
|
const morkUsage& inUsage, nsIMdbHeap* ioHeap, nsIMdbHeap* ioSlotHeap)
|
|
|
|
: morkNode(ev, inUsage, ioHeap)
|
|
|
|
, mPool_Heap( ioSlotHeap )
|
1999-09-22 05:35:28 +00:00
|
|
|
, mPool_UsedFramesCount( 0 )
|
|
|
|
, mPool_FreeFramesCount( 0 )
|
1999-03-12 07:39:27 +00:00
|
|
|
{
|
|
|
|
if ( ioSlotHeap )
|
|
|
|
{
|
|
|
|
// mPool_Heap is NOT refcounted:
|
|
|
|
// nsIMdbHeap_SlotStrongHeap(ioSlotHeap, ev, &mPool_Heap);
|
|
|
|
if ( ev->Good() )
|
|
|
|
mNode_Derived = morkDerived_kPool;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ev->NilPointerError();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*public non-poly*/ void
|
|
|
|
morkPool::ClosePool(morkEnv* ev) // called by CloseMorkNode();
|
|
|
|
{
|
|
|
|
if ( this )
|
|
|
|
{
|
|
|
|
if ( this->IsNode() )
|
|
|
|
{
|
1999-09-22 05:35:28 +00:00
|
|
|
#ifdef morkZone_CONFIG_ARENA
|
|
|
|
#else /*morkZone_CONFIG_ARENA*/
|
|
|
|
//MORK_USED_1(ioZone);
|
|
|
|
#endif /*morkZone_CONFIG_ARENA*/
|
|
|
|
|
|
|
|
nsIMdbHeap* heap = mPool_Heap;
|
|
|
|
nsIMdbEnv* mev = ev->AsMdbEnv();
|
1999-11-10 23:58:39 +00:00
|
|
|
morkLink* aLink;
|
1999-09-22 05:35:28 +00:00
|
|
|
morkDeque* d = &mPool_FreeHandleFrames;
|
1999-11-10 23:58:39 +00:00
|
|
|
while ( (aLink = d->RemoveFirst()) != 0 )
|
|
|
|
heap->Free(mev, aLink);
|
1999-09-22 05:35:28 +00:00
|
|
|
|
2001-10-06 01:16:24 +00:00
|
|
|
// if the pool's closed, get rid of the frames in use too.
|
|
|
|
d = &mPool_UsedHandleFrames;
|
|
|
|
while ( (aLink = d->RemoveFirst()) != 0 )
|
|
|
|
heap->Free(mev, aLink);
|
|
|
|
|
1999-03-12 07:39:27 +00:00
|
|
|
this->MarkShut();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
this->NonNodeError(ev);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ev->NilPointerError();
|
|
|
|
}
|
|
|
|
|
|
|
|
// } ===== end morkNode methods =====
|
|
|
|
// ````` ````` ````` ````` `````
|
|
|
|
|
|
|
|
|
|
|
|
// alloc and free individual instances of handles (inside hand frames):
|
|
|
|
morkHandleFace*
|
1999-09-22 05:35:28 +00:00
|
|
|
morkPool::NewHandle(morkEnv* ev, mork_size inSize, morkZone* ioZone)
|
1999-03-12 07:39:27 +00:00
|
|
|
{
|
|
|
|
void* newBlock = 0;
|
1999-09-22 05:35:28 +00:00
|
|
|
if ( inSize <= sizeof(morkHandleFrame) )
|
|
|
|
{
|
1999-11-10 23:58:39 +00:00
|
|
|
morkLink* firstLink = mPool_FreeHandleFrames.RemoveFirst();
|
|
|
|
if ( firstLink )
|
1999-09-22 05:35:28 +00:00
|
|
|
{
|
1999-11-10 23:58:39 +00:00
|
|
|
newBlock = firstLink;
|
1999-09-22 05:35:28 +00:00
|
|
|
if ( mPool_FreeFramesCount )
|
|
|
|
--mPool_FreeFramesCount;
|
|
|
|
else
|
|
|
|
ev->NewWarning("mPool_FreeFramesCount underflow");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
mPool_Heap->Alloc(ev->AsMdbEnv(), sizeof(morkHandleFrame),
|
|
|
|
(void**) &newBlock);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ev->NewWarning("inSize > sizeof(morkHandleFrame)");
|
|
|
|
mPool_Heap->Alloc(ev->AsMdbEnv(), inSize, (void**) &newBlock);
|
|
|
|
}
|
|
|
|
#ifdef morkZone_CONFIG_ARENA
|
|
|
|
#else /*morkZone_CONFIG_ARENA*/
|
|
|
|
MORK_USED_1(ioZone);
|
|
|
|
#endif /*morkZone_CONFIG_ARENA*/
|
|
|
|
|
1999-03-12 07:39:27 +00:00
|
|
|
return (morkHandleFace*) newBlock;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
morkPool::ZapHandle(morkEnv* ev, morkHandleFace* ioHandle)
|
|
|
|
{
|
|
|
|
if ( ioHandle )
|
1999-09-22 05:35:28 +00:00
|
|
|
{
|
1999-11-10 23:58:39 +00:00
|
|
|
morkLink* handleLink = (morkLink*) ioHandle;
|
|
|
|
mPool_FreeHandleFrames.AddLast(handleLink);
|
1999-09-22 05:35:28 +00:00
|
|
|
++mPool_FreeFramesCount;
|
2001-10-06 01:16:24 +00:00
|
|
|
// lets free all handles to track down leaks
|
|
|
|
// - uncomment out next 3 lines, comment out above 2
|
|
|
|
// nsIMdbHeap* heap = mPool_Heap;
|
|
|
|
// nsIMdbEnv* mev = ev->AsMdbEnv();
|
|
|
|
// heap->Free(mev, handleLink);
|
|
|
|
|
1999-09-22 05:35:28 +00:00
|
|
|
}
|
1999-03-12 07:39:27 +00:00
|
|
|
}
|
|
|
|
|
1999-09-22 05:35:28 +00:00
|
|
|
|
1999-03-12 07:39:27 +00:00
|
|
|
// alloc and free individual instances of rows:
|
|
|
|
morkRow*
|
1999-09-22 05:35:28 +00:00
|
|
|
morkPool::NewRow(morkEnv* ev, morkZone* ioZone) // allocate a new row instance
|
1999-03-12 07:39:27 +00:00
|
|
|
{
|
|
|
|
morkRow* newRow = 0;
|
1999-09-22 05:35:28 +00:00
|
|
|
|
|
|
|
#ifdef morkZone_CONFIG_ARENA
|
|
|
|
// a zone 'chip' remembers no size, and so cannot be deallocated:
|
|
|
|
newRow = (morkRow*) ioZone->ZoneNewChip(ev, sizeof(morkRow));
|
|
|
|
#else /*morkZone_CONFIG_ARENA*/
|
|
|
|
MORK_USED_1(ioZone);
|
1999-03-12 07:39:27 +00:00
|
|
|
mPool_Heap->Alloc(ev->AsMdbEnv(), sizeof(morkRow), (void**) &newRow);
|
1999-09-22 05:35:28 +00:00
|
|
|
#endif /*morkZone_CONFIG_ARENA*/
|
|
|
|
|
1999-03-12 07:39:27 +00:00
|
|
|
if ( newRow )
|
|
|
|
MORK_MEMSET(newRow, 0, sizeof(morkRow));
|
|
|
|
|
|
|
|
return newRow;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-09-22 05:35:28 +00:00
|
|
|
morkPool::ZapRow(morkEnv* ev, morkRow* ioRow,
|
|
|
|
morkZone* ioZone) // free old row instance
|
1999-03-12 07:39:27 +00:00
|
|
|
{
|
1999-09-22 05:35:28 +00:00
|
|
|
#ifdef morkZone_CONFIG_ARENA
|
|
|
|
if ( !ioRow )
|
|
|
|
ev->NilPointerWarning(); // a zone 'chip' cannot be freed
|
|
|
|
#else /*morkZone_CONFIG_ARENA*/
|
|
|
|
MORK_USED_1(ioZone);
|
1999-03-12 07:39:27 +00:00
|
|
|
if ( ioRow )
|
|
|
|
mPool_Heap->Free(ev->AsMdbEnv(), ioRow);
|
1999-09-22 05:35:28 +00:00
|
|
|
#endif /*morkZone_CONFIG_ARENA*/
|
1999-03-12 07:39:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// alloc and free entire vectors of cells (not just one cell at a time)
|
|
|
|
morkCell*
|
1999-09-22 05:35:28 +00:00
|
|
|
morkPool::NewCells(morkEnv* ev, mork_size inSize,
|
|
|
|
morkZone* ioZone)
|
1999-03-12 07:39:27 +00:00
|
|
|
{
|
|
|
|
morkCell* newCells = 0;
|
1999-09-22 05:35:28 +00:00
|
|
|
|
1999-03-12 07:39:27 +00:00
|
|
|
mork_size size = inSize * sizeof(morkCell);
|
|
|
|
if ( size )
|
1999-09-22 05:35:28 +00:00
|
|
|
{
|
|
|
|
#ifdef morkZone_CONFIG_ARENA
|
|
|
|
// a zone 'run' knows its size, and can indeed be deallocated:
|
|
|
|
newCells = (morkCell*) ioZone->ZoneNewRun(ev, size);
|
|
|
|
#else /*morkZone_CONFIG_ARENA*/
|
|
|
|
MORK_USED_1(ioZone);
|
1999-03-12 07:39:27 +00:00
|
|
|
mPool_Heap->Alloc(ev->AsMdbEnv(), size, (void**) &newCells);
|
1999-09-22 05:35:28 +00:00
|
|
|
#endif /*morkZone_CONFIG_ARENA*/
|
|
|
|
}
|
1999-03-12 07:39:27 +00:00
|
|
|
|
|
|
|
// note morkAtom depends on having nil stored in all new mCell_Atom slots:
|
|
|
|
if ( newCells )
|
|
|
|
MORK_MEMSET(newCells, 0, size);
|
|
|
|
return newCells;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-09-22 05:35:28 +00:00
|
|
|
morkPool::ZapCells(morkEnv* ev, morkCell* ioVector, mork_size inSize,
|
|
|
|
morkZone* ioZone)
|
1999-03-12 07:39:27 +00:00
|
|
|
{
|
1999-05-04 02:55:30 +00:00
|
|
|
MORK_USED_1(inSize);
|
1999-09-22 05:35:28 +00:00
|
|
|
|
1999-03-12 07:39:27 +00:00
|
|
|
if ( ioVector )
|
1999-09-22 05:35:28 +00:00
|
|
|
{
|
|
|
|
#ifdef morkZone_CONFIG_ARENA
|
|
|
|
// a zone 'run' knows its size, and can indeed be deallocated:
|
|
|
|
ioZone->ZoneZapRun(ev, ioVector);
|
|
|
|
#else /*morkZone_CONFIG_ARENA*/
|
|
|
|
MORK_USED_1(ioZone);
|
1999-03-12 07:39:27 +00:00
|
|
|
mPool_Heap->Free(ev->AsMdbEnv(), ioVector);
|
1999-09-22 05:35:28 +00:00
|
|
|
#endif /*morkZone_CONFIG_ARENA*/
|
|
|
|
}
|
1999-03-12 07:39:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// resize (grow or trim) cell vectors inside a containing row instance
|
|
|
|
mork_bool
|
1999-09-22 05:35:28 +00:00
|
|
|
morkPool::AddRowCells(morkEnv* ev, morkRow* ioRow, mork_size inNewSize,
|
|
|
|
morkZone* ioZone)
|
1999-03-12 07:39:27 +00:00
|
|
|
{
|
|
|
|
// note strong implementation similarity to morkArray::Grow()
|
|
|
|
|
1999-09-22 05:35:28 +00:00
|
|
|
MORK_USED_1(ioZone);
|
|
|
|
#ifdef morkZone_CONFIG_ARENA
|
|
|
|
#else /*morkZone_CONFIG_ARENA*/
|
|
|
|
#endif /*morkZone_CONFIG_ARENA*/
|
|
|
|
|
1999-03-12 07:39:27 +00:00
|
|
|
mork_fill fill = ioRow->mRow_Length;
|
|
|
|
if ( ev->Good() && fill < inNewSize ) // need more cells?
|
|
|
|
{
|
1999-09-22 05:35:28 +00:00
|
|
|
morkCell* newCells = this->NewCells(ev, inNewSize, ioZone);
|
1999-03-12 07:39:27 +00:00
|
|
|
if ( newCells )
|
|
|
|
{
|
|
|
|
morkCell* c = newCells; // for iterating during copy
|
|
|
|
morkCell* oldCells = ioRow->mRow_Cells;
|
|
|
|
morkCell* end = oldCells + fill; // copy all the old cells
|
|
|
|
while ( oldCells < end )
|
|
|
|
{
|
|
|
|
*c++ = *oldCells++; // bitwise copy each old cell struct
|
|
|
|
}
|
|
|
|
oldCells = ioRow->mRow_Cells;
|
|
|
|
ioRow->mRow_Cells = newCells;
|
1999-05-04 02:55:30 +00:00
|
|
|
ioRow->mRow_Length = (mork_u2) inNewSize;
|
1999-03-12 07:39:27 +00:00
|
|
|
++ioRow->mRow_Seed;
|
|
|
|
|
1999-03-30 05:43:09 +00:00
|
|
|
if ( oldCells )
|
1999-09-22 05:35:28 +00:00
|
|
|
this->ZapCells(ev, oldCells, fill, ioZone);
|
1999-03-12 07:39:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ( ev->Good() && ioRow->mRow_Length >= inNewSize );
|
|
|
|
}
|
|
|
|
|
|
|
|
mork_bool
|
|
|
|
morkPool::CutRowCells(morkEnv* ev, morkRow* ioRow,
|
1999-09-22 05:35:28 +00:00
|
|
|
mork_size inNewSize,
|
|
|
|
morkZone* ioZone)
|
1999-03-12 07:39:27 +00:00
|
|
|
{
|
1999-09-22 05:35:28 +00:00
|
|
|
MORK_USED_1(ioZone);
|
|
|
|
#ifdef morkZone_CONFIG_ARENA
|
|
|
|
#else /*morkZone_CONFIG_ARENA*/
|
|
|
|
#endif /*morkZone_CONFIG_ARENA*/
|
|
|
|
|
1999-03-12 07:39:27 +00:00
|
|
|
mork_fill fill = ioRow->mRow_Length;
|
|
|
|
if ( ev->Good() && fill > inNewSize ) // need fewer cells?
|
|
|
|
{
|
1999-03-30 05:43:09 +00:00
|
|
|
if ( inNewSize ) // want any row cells at all?
|
1999-03-12 07:39:27 +00:00
|
|
|
{
|
1999-09-22 05:35:28 +00:00
|
|
|
morkCell* newCells = this->NewCells(ev, inNewSize, ioZone);
|
1999-03-30 05:43:09 +00:00
|
|
|
if ( newCells )
|
1999-03-12 07:39:27 +00:00
|
|
|
{
|
2000-04-18 06:19:09 +00:00
|
|
|
morkCell* saveNewCells = newCells; // Keep newcell pos
|
1999-03-30 05:43:09 +00:00
|
|
|
morkCell* oldCells = ioRow->mRow_Cells;
|
|
|
|
morkCell* oldEnd = oldCells + fill; // one past all old cells
|
|
|
|
morkCell* newEnd = oldCells + inNewSize; // copy only kept old cells
|
|
|
|
while ( oldCells < newEnd )
|
|
|
|
{
|
|
|
|
*newCells++ = *oldCells++; // bitwise copy each old cell struct
|
|
|
|
}
|
|
|
|
while ( oldCells < oldEnd )
|
|
|
|
{
|
|
|
|
if ( oldCells->mCell_Atom ) // need to unref old cell atom?
|
|
|
|
oldCells->SetAtom(ev, (morkAtom*) 0, this); // unref cell atom
|
|
|
|
++oldCells;
|
|
|
|
}
|
|
|
|
oldCells = ioRow->mRow_Cells;
|
2000-04-18 06:19:09 +00:00
|
|
|
ioRow->mRow_Cells = saveNewCells;
|
1999-05-04 02:55:30 +00:00
|
|
|
ioRow->mRow_Length = (mork_u2) inNewSize;
|
1999-03-30 05:43:09 +00:00
|
|
|
++ioRow->mRow_Seed;
|
|
|
|
|
|
|
|
if ( oldCells )
|
1999-09-22 05:35:28 +00:00
|
|
|
this->ZapCells(ev, oldCells, fill, ioZone);
|
1999-03-12 07:39:27 +00:00
|
|
|
}
|
1999-03-30 05:43:09 +00:00
|
|
|
}
|
|
|
|
else // get rid of all row cells
|
|
|
|
{
|
|
|
|
morkCell* oldCells = ioRow->mRow_Cells;
|
|
|
|
ioRow->mRow_Cells = 0;
|
|
|
|
ioRow->mRow_Length = 0;
|
1999-03-12 07:39:27 +00:00
|
|
|
++ioRow->mRow_Seed;
|
|
|
|
|
1999-03-30 05:43:09 +00:00
|
|
|
if ( oldCells )
|
1999-09-22 05:35:28 +00:00
|
|
|
this->ZapCells(ev, oldCells, fill, ioZone);
|
1999-03-12 07:39:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ( ev->Good() && ioRow->mRow_Length <= inNewSize );
|
|
|
|
}
|
|
|
|
|
|
|
|
// alloc & free individual instances of atoms (lots of atom subclasses):
|
|
|
|
void
|
1999-09-22 05:35:28 +00:00
|
|
|
morkPool::ZapAtom(morkEnv* ev, morkAtom* ioAtom,
|
|
|
|
morkZone* ioZone) // any subclass (by kind)
|
1999-03-12 07:39:27 +00:00
|
|
|
{
|
1999-09-22 05:35:28 +00:00
|
|
|
#ifdef morkZone_CONFIG_ARENA
|
|
|
|
if ( !ioAtom )
|
|
|
|
ev->NilPointerWarning(); // a zone 'chip' cannot be freed
|
|
|
|
#else /*morkZone_CONFIG_ARENA*/
|
|
|
|
MORK_USED_1(ioZone);
|
1999-03-12 07:39:27 +00:00
|
|
|
if ( ioAtom )
|
|
|
|
mPool_Heap->Free(ev->AsMdbEnv(), ioAtom);
|
1999-09-22 05:35:28 +00:00
|
|
|
#endif /*morkZone_CONFIG_ARENA*/
|
1999-03-12 07:39:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
morkOidAtom*
|
1999-09-22 05:35:28 +00:00
|
|
|
morkPool::NewRowOidAtom(morkEnv* ev, const mdbOid& inOid,
|
|
|
|
morkZone* ioZone)
|
1999-03-12 07:39:27 +00:00
|
|
|
{
|
|
|
|
morkOidAtom* newAtom = 0;
|
1999-09-22 05:35:28 +00:00
|
|
|
|
|
|
|
#ifdef morkZone_CONFIG_ARENA
|
|
|
|
// a zone 'chip' remembers no size, and so cannot be deallocated:
|
|
|
|
newAtom = (morkOidAtom*) ioZone->ZoneNewChip(ev, sizeof(morkOidAtom));
|
|
|
|
#else /*morkZone_CONFIG_ARENA*/
|
|
|
|
MORK_USED_1(ioZone);
|
1999-03-12 07:39:27 +00:00
|
|
|
mPool_Heap->Alloc(ev->AsMdbEnv(), sizeof(morkOidAtom),(void**) &newAtom);
|
1999-09-22 05:35:28 +00:00
|
|
|
#endif /*morkZone_CONFIG_ARENA*/
|
|
|
|
|
1999-03-12 07:39:27 +00:00
|
|
|
if ( newAtom )
|
|
|
|
newAtom->InitRowOidAtom(ev, inOid);
|
|
|
|
return newAtom;
|
|
|
|
}
|
|
|
|
|
|
|
|
morkOidAtom*
|
1999-09-22 05:35:28 +00:00
|
|
|
morkPool::NewTableOidAtom(morkEnv* ev, const mdbOid& inOid,
|
|
|
|
morkZone* ioZone)
|
1999-03-12 07:39:27 +00:00
|
|
|
{
|
|
|
|
morkOidAtom* newAtom = 0;
|
1999-09-22 05:35:28 +00:00
|
|
|
|
|
|
|
#ifdef morkZone_CONFIG_ARENA
|
|
|
|
// a zone 'chip' remembers no size, and so cannot be deallocated:
|
|
|
|
newAtom = (morkOidAtom*) ioZone->ZoneNewChip(ev, sizeof(morkOidAtom));
|
|
|
|
#else /*morkZone_CONFIG_ARENA*/
|
|
|
|
MORK_USED_1(ioZone);
|
1999-03-12 07:39:27 +00:00
|
|
|
mPool_Heap->Alloc(ev->AsMdbEnv(), sizeof(morkOidAtom), (void**) &newAtom);
|
1999-09-22 05:35:28 +00:00
|
|
|
#endif /*morkZone_CONFIG_ARENA*/
|
1999-03-12 07:39:27 +00:00
|
|
|
if ( newAtom )
|
|
|
|
newAtom->InitTableOidAtom(ev, inOid);
|
|
|
|
return newAtom;
|
|
|
|
}
|
|
|
|
|
|
|
|
morkAtom*
|
|
|
|
morkPool::NewAnonAtom(morkEnv* ev, const morkBuf& inBuf,
|
1999-09-22 05:35:28 +00:00
|
|
|
mork_cscode inForm,
|
|
|
|
morkZone* ioZone)
|
1999-03-12 07:39:27 +00:00
|
|
|
// if inForm is zero, and inBuf.mBuf_Fill is less than 256, then a 'wee'
|
|
|
|
// anon atom will be created, and otherwise a 'big' anon atom.
|
|
|
|
{
|
|
|
|
morkAtom* newAtom = 0;
|
1999-09-22 05:35:28 +00:00
|
|
|
|
1999-03-12 07:39:27 +00:00
|
|
|
mork_bool needBig = ( inForm || inBuf.mBuf_Fill > 255 );
|
|
|
|
mork_size size = ( needBig )?
|
|
|
|
morkBigAnonAtom::SizeForFill(inBuf.mBuf_Fill) :
|
|
|
|
morkWeeAnonAtom::SizeForFill(inBuf.mBuf_Fill);
|
|
|
|
|
1999-09-22 05:35:28 +00:00
|
|
|
#ifdef morkZone_CONFIG_ARENA
|
|
|
|
// a zone 'chip' remembers no size, and so cannot be deallocated:
|
|
|
|
newAtom = (morkAtom*) ioZone->ZoneNewChip(ev, size);
|
|
|
|
#else /*morkZone_CONFIG_ARENA*/
|
|
|
|
MORK_USED_1(ioZone);
|
1999-03-12 07:39:27 +00:00
|
|
|
mPool_Heap->Alloc(ev->AsMdbEnv(), size, (void**) &newAtom);
|
1999-09-22 05:35:28 +00:00
|
|
|
#endif /*morkZone_CONFIG_ARENA*/
|
1999-03-12 07:39:27 +00:00
|
|
|
if ( newAtom )
|
|
|
|
{
|
|
|
|
if ( needBig )
|
|
|
|
((morkBigAnonAtom*) newAtom)->InitBigAnonAtom(ev, inBuf, inForm);
|
|
|
|
else
|
|
|
|
((morkWeeAnonAtom*) newAtom)->InitWeeAnonAtom(ev, inBuf);
|
|
|
|
}
|
|
|
|
return newAtom;
|
|
|
|
}
|
|
|
|
|
|
|
|
morkBookAtom*
|
|
|
|
morkPool::NewBookAtom(morkEnv* ev, const morkBuf& inBuf,
|
1999-09-22 05:35:28 +00:00
|
|
|
mork_cscode inForm, morkAtomSpace* ioSpace, mork_aid inAid,
|
|
|
|
morkZone* ioZone)
|
1999-03-12 07:39:27 +00:00
|
|
|
// if inForm is zero, and inBuf.mBuf_Fill is less than 256, then a 'wee'
|
|
|
|
// book atom will be created, and otherwise a 'big' book atom.
|
|
|
|
{
|
|
|
|
morkBookAtom* newAtom = 0;
|
1999-09-22 05:35:28 +00:00
|
|
|
|
1999-03-12 07:39:27 +00:00
|
|
|
mork_bool needBig = ( inForm || inBuf.mBuf_Fill > 255 );
|
|
|
|
mork_size size = ( needBig )?
|
|
|
|
morkBigBookAtom::SizeForFill(inBuf.mBuf_Fill) :
|
|
|
|
morkWeeBookAtom::SizeForFill(inBuf.mBuf_Fill);
|
|
|
|
|
1999-09-22 05:35:28 +00:00
|
|
|
#ifdef morkZone_CONFIG_ARENA
|
|
|
|
// a zone 'chip' remembers no size, and so cannot be deallocated:
|
|
|
|
newAtom = (morkBookAtom*) ioZone->ZoneNewChip(ev, size);
|
|
|
|
#else /*morkZone_CONFIG_ARENA*/
|
|
|
|
MORK_USED_1(ioZone);
|
1999-03-12 07:39:27 +00:00
|
|
|
mPool_Heap->Alloc(ev->AsMdbEnv(), size, (void**) &newAtom);
|
1999-09-22 05:35:28 +00:00
|
|
|
#endif /*morkZone_CONFIG_ARENA*/
|
1999-03-12 07:39:27 +00:00
|
|
|
if ( newAtom )
|
|
|
|
{
|
|
|
|
if ( needBig )
|
|
|
|
((morkBigBookAtom*) newAtom)->InitBigBookAtom(ev,
|
|
|
|
inBuf, inForm, ioSpace, inAid);
|
|
|
|
else
|
|
|
|
((morkWeeBookAtom*) newAtom)->InitWeeBookAtom(ev,
|
|
|
|
inBuf, ioSpace, inAid);
|
|
|
|
}
|
|
|
|
return newAtom;
|
|
|
|
}
|
|
|
|
|
|
|
|
morkBookAtom*
|
1999-09-22 05:35:28 +00:00
|
|
|
morkPool::NewBookAtomCopy(morkEnv* ev, const morkBigBookAtom& inAtom,
|
|
|
|
morkZone* ioZone)
|
1999-03-12 07:39:27 +00:00
|
|
|
// make the smallest kind of book atom that can hold content in inAtom.
|
|
|
|
// The inAtom parameter is often expected to be a staged book atom in
|
|
|
|
// the store, which was used to search an atom space for existing atoms.
|
|
|
|
{
|
|
|
|
morkBookAtom* newAtom = 0;
|
1999-09-22 05:35:28 +00:00
|
|
|
|
1999-03-12 07:39:27 +00:00
|
|
|
mork_cscode form = inAtom.mBigBookAtom_Form;
|
|
|
|
mork_fill fill = inAtom.mBigBookAtom_Size;
|
|
|
|
mork_bool needBig = ( form || fill > 255 );
|
|
|
|
mork_size size = ( needBig )?
|
|
|
|
morkBigBookAtom::SizeForFill(fill) :
|
|
|
|
morkWeeBookAtom::SizeForFill(fill);
|
|
|
|
|
1999-09-22 05:35:28 +00:00
|
|
|
#ifdef morkZone_CONFIG_ARENA
|
|
|
|
// a zone 'chip' remembers no size, and so cannot be deallocated:
|
|
|
|
newAtom = (morkBookAtom*) ioZone->ZoneNewChip(ev, size);
|
|
|
|
#else /*morkZone_CONFIG_ARENA*/
|
|
|
|
MORK_USED_1(ioZone);
|
1999-03-12 07:39:27 +00:00
|
|
|
mPool_Heap->Alloc(ev->AsMdbEnv(), size, (void**) &newAtom);
|
1999-09-22 05:35:28 +00:00
|
|
|
#endif /*morkZone_CONFIG_ARENA*/
|
1999-03-12 07:39:27 +00:00
|
|
|
if ( newAtom )
|
|
|
|
{
|
|
|
|
morkBuf buf(inAtom.mBigBookAtom_Body, fill);
|
|
|
|
if ( needBig )
|
|
|
|
((morkBigBookAtom*) newAtom)->InitBigBookAtom(ev,
|
|
|
|
buf, form, inAtom.mBookAtom_Space, inAtom.mBookAtom_Id);
|
|
|
|
else
|
|
|
|
((morkWeeBookAtom*) newAtom)->InitWeeBookAtom(ev,
|
|
|
|
buf, inAtom.mBookAtom_Space, inAtom.mBookAtom_Id);
|
|
|
|
}
|
|
|
|
return newAtom;
|
|
|
|
}
|
|
|
|
|
2000-04-01 17:07:38 +00:00
|
|
|
morkBookAtom*
|
|
|
|
morkPool::NewFarBookAtomCopy(morkEnv* ev, const morkFarBookAtom& inAtom,
|
|
|
|
morkZone* ioZone)
|
|
|
|
// make the smallest kind of book atom that can hold content in inAtom.
|
|
|
|
// The inAtom parameter is often expected to be a staged book atom in
|
|
|
|
// the store, which was used to search an atom space for existing atoms.
|
|
|
|
{
|
|
|
|
morkBookAtom* newAtom = 0;
|
|
|
|
|
|
|
|
mork_cscode form = inAtom.mFarBookAtom_Form;
|
|
|
|
mork_fill fill = inAtom.mFarBookAtom_Size;
|
|
|
|
mork_bool needBig = ( form || fill > 255 );
|
|
|
|
mork_size size = ( needBig )?
|
|
|
|
morkBigBookAtom::SizeForFill(fill) :
|
|
|
|
morkWeeBookAtom::SizeForFill(fill);
|
|
|
|
|
|
|
|
#ifdef morkZone_CONFIG_ARENA
|
|
|
|
// a zone 'chip' remembers no size, and so cannot be deallocated:
|
|
|
|
newAtom = (morkBookAtom*) ioZone->ZoneNewChip(ev, size);
|
|
|
|
#else /*morkZone_CONFIG_ARENA*/
|
|
|
|
MORK_USED_1(ioZone);
|
|
|
|
mPool_Heap->Alloc(ev->AsMdbEnv(), size, (void**) &newAtom);
|
|
|
|
#endif /*morkZone_CONFIG_ARENA*/
|
|
|
|
if ( newAtom )
|
|
|
|
{
|
|
|
|
morkBuf buf(inAtom.mFarBookAtom_Body, fill);
|
|
|
|
if ( needBig )
|
|
|
|
((morkBigBookAtom*) newAtom)->InitBigBookAtom(ev,
|
|
|
|
buf, form, inAtom.mBookAtom_Space, inAtom.mBookAtom_Id);
|
|
|
|
else
|
|
|
|
((morkWeeBookAtom*) newAtom)->InitWeeBookAtom(ev,
|
|
|
|
buf, inAtom.mBookAtom_Space, inAtom.mBookAtom_Id);
|
|
|
|
}
|
|
|
|
return newAtom;
|
|
|
|
}
|
|
|
|
|
1999-03-12 07:39:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
//3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
|
2000-04-01 17:07:38 +00:00
|
|
|
|