示例#1
0
/*public virtual*/
morkTable::~morkTable() /*i*/ // assert CloseTable() executed earlier
{
  CloseMorkNode(mMorkEnv);
  MORK_ASSERT(this->IsShutNode());
  MORK_ASSERT(mTable_Store==0);
  MORK_ASSERT(mTable_RowSpace==0);
}
示例#2
0
/*public virtual*/
morkFile::~morkFile() // assert CloseFile() executed earlier
{
  MORK_ASSERT(mFile_Frozen==0);
  MORK_ASSERT(mFile_DoTrace==0);
  MORK_ASSERT(mFile_IoOpen==0);
  MORK_ASSERT(mFile_Active==0);
}
/*public virtual*/
morkHandle::~morkHandle()  // assert CloseHandle() executed earlier
{
  MORK_ASSERT(mHandle_Env == 0);
  MORK_ASSERT(mHandle_Face == 0);
  MORK_ASSERT(mHandle_Object == 0);
  MORK_ASSERT(mHandle_Magic == 0);
  MORK_ASSERT(mHandle_Tag == morkHandle_kTag);  // should still have correct tag
}
morkObject* morkHandle::GetGoodHandleObject(morkEnv* ev, mork_bool inMutable,
                                            mork_magic inMagicType,
                                            mork_bool inClosedOkay) const {
  morkObject* outObject = 0;
  if (this->IsHandle() && this->GoodHandleTag() &&
      (inClosedOkay || this->IsOpenNode())) {
    if (!inMagicType || mHandle_Magic == inMagicType) {
      morkObject* obj = this->mHandle_Object;
      if (obj) {
        if (obj->IsNode()) {
          if (inClosedOkay || obj->IsOpenNode()) {
            if (this->IsMutable() || !inMutable)
              outObject = obj;
            else
              this->NonMutableNodeError(ev);
          } else
            this->NonOpenObjectError(ev);
        } else
          this->NonNodeObjectError(ev);
      } else if (!inClosedOkay)
        this->NilHandleObjectError(ev);
    } else
      this->NewBadMagicHandleError(ev, inMagicType);
  } else
    this->NewDownHandleError(ev);

  MORK_ASSERT(outObject || inClosedOkay);
  return outObject;
}
/*public virtual*/
morkEnv::~morkEnv() /*i*/ // assert CloseEnv() executed earlier
{
  CloseMorkNode(mMorkEnv);
  if (mEnv_Heap)
  {
    mork_bool ownsHeap = mEnv_OwnsHeap;
    nsIMdbHeap*saveHeap = mEnv_Heap;

    if (ownsHeap)
    {
#ifdef MORK_DEBUG_HEAP_STATS
      printf("%d blocks remaining \n", ((orkinHeap *) saveHeap)->HeapBlockCount());
      mork_u4* array = (mork_u4*) this;
      array -= 3;
      // null out heap ptr in mem block so we won't crash trying to use it to
      // delete the env.
      *array = nullptr;
#endif // MORK_DEBUG_HEAP_STATS
      // whoops, this is our heap - hmm. Can't delete it, or not allocate env's from
      // an orkinHeap.
      delete saveHeap;
    }

  }
//  MORK_ASSERT(mEnv_SelfAsMdbEnv==0);
  MORK_ASSERT(mEnv_ErrorHook==0);
}
示例#6
0
void morkParser::ReadCellForm(morkEnv *ev, int c)
{
  MORK_ASSERT (c == morkStore_kFormColumn);
  int nextChar;
  nextChar = this->NextChar(ev);
  int cellForm;

  if (nextChar == '=')
  {
    cellForm = this->NextChar(ev);
    nextChar = this->NextChar(ev);
  }
  else if (nextChar == '^')
  {
    cellForm = this->ReadHex(ev, &nextChar);
  }
  else
  {
    ev->NewWarning("unexpected byte in cell form");
    return;
  }
  // ### not sure about this. Which form should we set?
  //    mBuilder_CellForm = mBuilder_RowForm = cellForm;
  if (nextChar == ')')
  {
    OnCellForm(ev, cellForm);
    return;
  }
  ev->NewWarning("unexpected byte in cell form");
}
示例#7
0
morkRow*
morkRowSpace::NewRowWithOid(morkEnv* ev, const mdbOid* inOid)
{
  morkRow* outRow = mRowSpace_Rows.GetOid(ev, inOid);
  MORK_ASSERT(outRow==0);
  if ( !outRow && ev->Good() )
  {
    morkStore* store = mSpace_Store;
    if ( store )
    {
      morkPool* pool = this->GetSpaceStorePool();
      morkRow* row = pool->NewRow(ev, &store->mStore_Zone);
      if ( row )
      {
        row->InitRow(ev, inOid, this, /*length*/ 0, pool);
        
        if ( ev->Good() && mRowSpace_Rows.AddRow(ev, row) )
        {
          outRow = row;
          mork_rid rid = inOid->mOid_Id;
          if ( mRowSpace_NextRowId <= rid )
            mRowSpace_NextRowId = rid + 1;
        }
        else
          pool->ZapRow(ev, row, &store->mStore_Zone);

        if ( this->IsRowSpaceClean() && store->mStore_CanDirty )
          this->MaybeDirtyStoreAndSpace(); // InitRow() does already
      }
    }
    else
      this->NilSpaceStoreError(ev);
  }
  return outRow;
}
/*virtual*/ nsresult morkHandle::Handle_IsOpenMdbObject(nsIMdbEnv* mev,
                                                        mdb_bool* outOpen) {
  MORK_USED_1(mev);
  nsresult outErr = NS_OK;

  MORK_ASSERT(outOpen);
  if (outOpen) *outOpen = this->IsOpenNode();

  return outErr;
}
/*public non-poly*/
morkPool::morkPool(const morkUsage& inUsage, nsIMdbHeap* ioHeap,
                   nsIMdbHeap* ioSlotHeap)
    : morkNode(inUsage, ioHeap),
      mPool_Heap(ioSlotHeap),
      mPool_UsedFramesCount(0),
      mPool_FreeFramesCount(0) {
  // mPool_Heap is NOT refcounted
  MORK_ASSERT(ioSlotHeap);
  if (ioSlotHeap) mNode_Derived = morkDerived_kPool;
}
// { ----- begin heap methods -----
NS_IMETHODIMP
morkFactory::MakeHeap(nsIMdbEnv* mev, nsIMdbHeap** acqHeap) {
  nsresult outErr = NS_OK;
  nsIMdbHeap* outHeap = 0;
  morkEnv* ev = morkEnv::FromMdbEnv(mev);
  if (ev) {
    outHeap = new orkinHeap();
    if (!outHeap) ev->OutOfMemoryError();
  }
  MORK_ASSERT(acqHeap);
  if (acqHeap) *acqHeap = outHeap;
  return outErr;
}
示例#11
0
void morkRow::CutColumn(morkEnv* ev, mdb_column inColumn)
{
  mork_pos pos = -1;
  morkCell* cell = this->GetCell(ev, inColumn, &pos);
  if ( cell ) 
  {
    morkStore* store = this->GetRowSpaceStore(ev);
    if ( store )
    {
      if ( this->MaybeDirtySpaceStoreAndRow() && !this->IsRowRewrite() )
        this->NoteRowCutCol(ev, inColumn);
        
      morkRowSpace* rowSpace = mRow_Space;
      morkAtomRowMap* map = ( rowSpace->mRowSpace_IndexCount )?
        rowSpace->FindMap(ev, inColumn) : (morkAtomRowMap*) 0;
      if ( map ) // this row attribute is indexed by row space?
      {
        morkAtom* oldAtom = cell->mCell_Atom;
        if ( oldAtom ) // need to cut an entry from the index?
        {
          mork_aid oldAid = oldAtom->GetBookAtomAid();
          if ( oldAid ) // cut old row attribute from row index in space?
            map->CutAid(ev, oldAid);
        }
      }
      
      morkPool* pool = store->StorePool();
      cell->SetAtom(ev, (morkAtom*) 0, pool);
      
      mork_fill fill = mRow_Length; // should not be zero
      MORK_ASSERT(fill);
      if ( fill ) // index < fill for last cell exists?
      {
        mork_fill last = fill - 1; // index of last cell in row
        
        if ( pos < (mork_pos)last ) // need to move cells following cut cell?
        {
          morkCell* lastCell = mRow_Cells + last;
          mork_count after = last - pos; // cell count after cut cell
          morkCell* next = cell + 1; // next cell after cut cell
          MORK_MEMMOVE(cell, next, after * sizeof(morkCell));
          lastCell->SetColumnAndChange(0, 0);
          lastCell->mCell_Atom = 0;
        }
        
        if ( ev->Good() )
          pool->CutRowCells(ev, this, fill - 1, &store->mStore_Zone);
      }
    }
  }
}
示例#12
0
/*public non-poly*/
morkEnv::morkEnv(const morkUsage& inUsage, nsIMdbHeap* ioHeap,
  morkFactory* ioFactory, nsIMdbHeap* ioSlotHeap)
: morkObject(inUsage, ioHeap, morkColor_kNone)
, mEnv_Factory( ioFactory )
, mEnv_Heap( ioSlotHeap )

, mEnv_SelfAsMdbEnv( 0 )
, mEnv_ErrorHook( 0 )
, mEnv_HandlePool( 0 )
  
, mEnv_ErrorCount( 0 ) 
, mEnv_WarningCount( 0 ) 

, mEnv_ErrorCode(NS_OK)

, mEnv_DoTrace( morkBool_kFalse )
, mEnv_AutoClear( morkAble_kDisabled )
, mEnv_ShouldAbort( morkBool_kFalse )
, mEnv_BeVerbose( morkEnv_kBeVerbose )
, mEnv_OwnsHeap ( morkBool_kFalse )
{
  MORK_ASSERT(ioSlotHeap && ioFactory );
  if ( ioSlotHeap )
  {
    // mEnv_Heap is NOT refcounted:
    // nsIMdbHeap_SlotStrongHeap(ioSlotHeap, this, &mEnv_Heap);
    
    mEnv_HandlePool = new morkPool(morkUsage::kGlobal,
      (nsIMdbHeap*) 0, ioSlotHeap);
      
    MORK_ASSERT(mEnv_HandlePool);
    if ( mEnv_HandlePool && this->Good() )
    {
      mNode_Derived = morkDerived_kEnv;
      mNode_Refs += morkEnv_kWeakRefCountEnvBonus;
    }
  }
}
示例#13
0
/*public non-poly*/
morkNode::morkNode(const morkUsage& inUsage, nsIMdbHeap* ioHeap)
: mNode_Heap( ioHeap )
, mNode_Base( morkBase_kNode )
, mNode_Derived ( 0 ) // until subclass sets appropriately
, mNode_Access( morkAccess_kOpen )
, mNode_Usage( inUsage.Code() )
, mNode_Mutable( morkAble_kEnabled )
, mNode_Load( morkLoad_kClean )
, mNode_Uses( 1 )
, mNode_Refs( 1 )
{
  if ( !ioHeap && mNode_Usage == morkUsage_kHeap )
    MORK_ASSERT(ioHeap);
}
示例#14
0
// { ===== begin nsIMdbHeap methods =====
/*virtual*/ mdb_err
orkinHeap::Alloc(nsIMdbEnv* mev, // allocate a piece of memory
  mdb_size inSize,   // requested size of new memory block 
  void** outBlock)  // memory block of inSize bytes, or nil
{
#ifdef MORK_DEBUG_HEAP_STATS
  mdb_size realSize = inSize;
  inSize += 12; // sizeof(mork_u4) * 3
  ++sHeap_AllocCount;
#endif /*MORK_DEBUG_HEAP_STATS*/

  MORK_USED_1(mev);
  mdb_err outErr = 0;
  void* block = malloc(inSize);
  if ( !block )
    outErr = morkEnv_kOutOfMemoryError;
#ifdef MORK_DEBUG_HEAP_STATS
  else
  {
    printf("%lx allocating %d\n", this, realSize);
    mork_u4* array = (mork_u4*) block;
    *array++ = (mork_u4) this;
    *array++ = realSize;
    *array++ = orkinHeap_kTag;
    block = array;
    ++sHeap_BlockCount;
    mork_num blockVol = sHeap_BlockVolume + realSize;
    sHeap_BlockVolume = blockVol;
    if ( blockVol > sHeap_HighWaterVolume )
    {
      sHeap_HighWaterVolume = blockVol;
      
      mork_num tenKiloVol = blockVol / (10 * 1024);
      if ( tenKiloVol > sHeap_HighWaterTenKilo )
      {
        sHeap_HighWaterTenKilo = tenKiloVol;
      
        mork_num hundredKiloVol = blockVol / (100 * 1024);
        if ( hundredKiloVol > sHeap_HighWaterHundredKilo )
          sHeap_HighWaterHundredKilo = hundredKiloVol;
      }
    }
  }
#endif /*MORK_DEBUG_HEAP_STATS*/
    
  MORK_ASSERT(outBlock);
  if ( outBlock )
    *outBlock = block;
  return outErr;
}
示例#15
0
/*public virtual*/
morkMap::~morkMap() // assert CloseMap() executed earlier
{
  MORK_ASSERT(mMap_FreeList==0);
  MORK_ASSERT(mMap_Buckets==0);
  MORK_ASSERT(mMap_Keys==0);
  MORK_ASSERT(mMap_Vals==0);
  MORK_ASSERT(mMap_Changes==0);
  MORK_ASSERT(mMap_Assocs==0);
}
/*public virtual*/
morkBuilder::~morkBuilder() // assert CloseBuilder() executed earlier
{
  MORK_ASSERT(mBuilder_Store==0);
  MORK_ASSERT(mBuilder_Row==0);
  MORK_ASSERT(mBuilder_Table==0);
  MORK_ASSERT(mBuilder_Cell==0);
  MORK_ASSERT(mBuilder_RowSpace==0);
  MORK_ASSERT(mBuilder_AtomSpace==0);
}
morkEnv* morkHandle::CanUseHandle(nsIMdbEnv* mev, mork_bool inMutable,
                                  mork_bool inClosedOkay,
                                  nsresult* outErr) const {
  morkEnv* outEnv = 0;
  morkEnv* ev = morkEnv::FromMdbEnv(mev);
  if (ev) {
    morkObject* obj = this->GetGoodHandleObject(ev, inMutable,
                                                /*magic*/ 0, inClosedOkay);
    if (obj) {
      outEnv = ev;
    }
    *outErr = ev->AsErr();
  }
  MORK_ASSERT(outEnv || inClosedOkay);
  return outEnv;
}
morkEnv*
morkPortTableCursor::CanUsePortTableCursor(nsIMdbEnv* mev, mork_bool inMutable,
                                           nsresult* outErr) const
{
  morkEnv* outEnv = 0;
  morkEnv* ev = morkEnv::FromMdbEnv(mev);
  if ( ev )
  {
    if ( IsPortTableCursor() )
      outEnv = ev;
    else
      NonPortTableCursorTypeError(ev);
    *outErr = ev->AsErr();
  }
  MORK_ASSERT(outEnv);
  return outEnv;
}
示例#19
0
mork_pos
morkTable::ArrayHasOid(morkEnv* ev, const mdbOid* inOid)
{
  MORK_USED_1(ev); 
  mork_count count = mTable_RowArray.mArray_Fill;
  mork_pos pos = -1;
  while ( ++pos < (mork_pos)count )
  {
    morkRow* row = (morkRow*) mTable_RowArray.At(pos);
    MORK_ASSERT(row);
    if ( row && row->EqualOid(inOid) )
    {
      return pos;
    }
  }
  return -1;
}
// { ----- begin attribute methods -----
/*virtual*/ nsresult morkHandle::Handle_IsFrozenMdbObject(
    nsIMdbEnv* mev, mdb_bool* outIsReadonly) {
  nsresult outErr = NS_OK;
  mdb_bool readOnly = mdbBool_kTrue;

  morkEnv* ev = CanUseHandle(mev, /*inMutable*/ morkBool_kFalse,
                             /*inClosedOkay*/ morkBool_kTrue, &outErr);
  if (ev) {
    readOnly = mHandle_Object->IsFrozen();

    outErr = ev->AsErr();
  }
  MORK_ASSERT(outIsReadonly);
  if (outIsReadonly) *outIsReadonly = readOnly;

  return outErr;
}
示例#21
0
/*protected non-poly*/ void
morkParser::ParseChunk(morkEnv* ev)
{
  mParser_Change = morkChange_kNil;
  mParser_DoMore = morkBool_kTrue;
            
  switch ( mParser_State )
  {
    case morkParser_kCellState: // 0
      this->OnCellState(ev); break;
      
    case morkParser_kMetaState: // 1
      this->OnMetaState(ev); break;
      
    case morkParser_kRowState: // 2
      this->OnRowState(ev); break;
      
    case morkParser_kTableState: // 3
      this->OnTableState(ev); break;
      
    case morkParser_kDictState: // 4
      this->OnDictState(ev); break;
      
    case morkParser_kPortState: // 5
      this->OnPortState(ev); break;
      
    case morkParser_kStartState: // 6
      this->OnStartState(ev); break;
     
    case morkParser_kDoneState: // 7
      mParser_DoMore = morkBool_kFalse;
      mParser_IsDone = morkBool_kTrue;
      this->StopParse(ev);
      break;
    case morkParser_kBrokenState: // 8
      mParser_DoMore = morkBool_kFalse;
      mParser_IsBroken = morkBool_kTrue;
      this->StopParse(ev);
      break;
    default: // ?
      MORK_ASSERT(morkBool_kFalse);
      mParser_State = morkParser_kBrokenState;
      break;
  }
}
/*virtual*/ nsresult morkHandle::Handle_GetStrongRefCount(
    nsIMdbEnv* mev,  // strong refs
    mdb_count* outCount) {
  nsresult outErr = NS_OK;
  mdb_count count = 0;

  morkEnv* ev = CanUseHandle(mev, /*inMutable*/ morkBool_kFalse,
                             /*inClosedOkay*/ morkBool_kTrue, &outErr);
  if (ev) {
    count = this->StrongRefsOnly();

    outErr = ev->AsErr();
  }
  MORK_ASSERT(outCount);
  if (outCount) *outCount = count;

  return outErr;
}
示例#23
0
FILE* mork_fileopen(const char* name, const char* mode)
{
    int access = O_RDWR;
    int descriptor;
    int pmode = 0;

    /* Only possible options are wb+ and rb+ */
    MORK_ASSERT((mode[0] == 'w' || mode[0] == 'r') && (mode[1] == 'b') && (mode[2] == '+'));
    if (mode[0] == 'w') {
        access |= (O_TRUNC | O_CREAT);
        pmode = S_IREAD | S_IWRITE;
    }

    descriptor = sopen(name, access, SH_DENYNO, pmode);
    if (descriptor != -1) {
        return fdopen(descriptor, mode);
    }
    return NULL;
}
示例#24
0
/*virtual*/ mdb_err
orkinHeap::Free(nsIMdbEnv* mev, // free block allocated earlier by Alloc()
  void* inBlock)
{
#ifdef MORK_DEBUG_HEAP_STATS
  ++sHeap_FreeCount;
#endif /*MORK_DEBUG_HEAP_STATS*/

  MORK_USED_1(mev);
  MORK_ASSERT(inBlock);
  if ( inBlock )
  {
#ifdef MORK_DEBUG_HEAP_STATS
    morkEnv* ev = 0; //morkEnv::FromMdbEnv(mev);
    mork_u4* array = (mork_u4*) inBlock;
    if ( *--array != orkinHeap_kTag )
    {
      if ( ev )
        ev->NewWarning("heap block tag not hEaP");
    }
    mork_u4 realSize = *--array;
    inBlock = --array; // skip over heap ptr too.
    
    printf("%lx freeing %d\n", this, realSize);
    if ( sHeap_BlockCount )
      --sHeap_BlockCount;
    else if ( ev ) 
      ev->NewWarning("sHeap_BlockCount underflow");
    
    if ( sHeap_BlockVolume >= realSize )
      sHeap_BlockVolume -= realSize;
    else if ( ev )
    {
      sHeap_BlockVolume = 0;
      ev->NewWarning("sHeap_BlockVolume underflow");
    }
#endif /*MORK_DEBUG_HEAP_STATS*/
    
    free(inBlock);
  }
  return 0;
}
示例#25
0
/*public non-poly*/
morkEnv::morkEnv(morkEnv* ev, /*i*/
  const morkUsage& inUsage, nsIMdbHeap* ioHeap, nsIMdbEnv* inSelfAsMdbEnv,
  morkFactory* ioFactory, nsIMdbHeap* ioSlotHeap)
: morkObject(ev, inUsage, ioHeap, morkColor_kNone, (morkHandle*) 0)
, mEnv_Factory( ioFactory )
, mEnv_Heap( ioSlotHeap )

, mEnv_SelfAsMdbEnv( inSelfAsMdbEnv )
, mEnv_ErrorHook( 0 )
, mEnv_HandlePool( 0 )
  
, mEnv_ErrorCount( 0 ) 
, mEnv_WarningCount( 0 ) 

, mEnv_ErrorCode(NS_OK)

, mEnv_DoTrace( morkBool_kFalse )
, mEnv_AutoClear( morkAble_kDisabled )
, mEnv_ShouldAbort( morkBool_kFalse )
, mEnv_BeVerbose( morkEnv_kBeVerbose )
, mEnv_OwnsHeap ( morkBool_kFalse )
{
  // $$$ do we need to refcount the inSelfAsMdbEnv nsIMdbEnv??
  
  if ( ioFactory && inSelfAsMdbEnv && ioSlotHeap)
  {
    // mEnv_Heap is NOT refcounted:
    // nsIMdbHeap_SlotStrongHeap(ioSlotHeap, ev, &mEnv_Heap);

    mEnv_HandlePool = new(*ioSlotHeap, ev) morkPool(ev, 
      morkUsage::kHeap, ioSlotHeap, ioSlotHeap);
      
    MORK_ASSERT(mEnv_HandlePool);
    if ( mEnv_HandlePool && ev->Good() )
    {
      mNode_Derived = morkDerived_kEnv;
      mNode_Refs += morkEnv_kWeakRefCountEnvBonus;
    }
  }
  else
    ev->NilPointerError();
}
示例#26
0
mork_tid
morkRowSpace::MakeNewTableId(morkEnv* ev)
{
  mork_tid outTid = 0;
  mork_tid id = mRowSpace_NextTableId;
  mork_num count = 9; // try up to eight times
  
  while ( !outTid && --count ) // still trying to find an unused table ID?
  {
    if ( !mRowSpace_Tables.GetTable(ev, id) )
      outTid = id;
    else
    {
      MORK_ASSERT(morkBool_kFalse); // alert developer about ID problems
      ++id;
    }
  }
  
  mRowSpace_NextTableId = id + 1;
  return outTid;
}
// { ----- begin factory methods -----
/*virtual*/ nsresult morkHandle::Handle_GetMdbFactory(
    nsIMdbEnv* mev, nsIMdbFactory** acqFactory) {
  nsresult outErr = NS_OK;
  nsIMdbFactory* handle = 0;

  morkEnv* ev = CanUseHandle(mev, /*inMutable*/ morkBool_kFalse,
                             /*inClosedOkay*/ morkBool_kTrue, &outErr);
  if (ev) {
    morkFactory* factory = ev->mEnv_Factory;
    if (factory) {
      handle = factory;
      NS_ADDREF(handle);
    } else
      this->NilFactoryError(ev);

    outErr = ev->AsErr();
  }

  MORK_ASSERT(acqFactory);
  if (acqFactory) *acqFactory = handle;

  return outErr;
}
示例#28
0
mork_rid
morkRowSpace::MakeNewRowId(morkEnv* ev)
{
  mork_rid outRid = 0;
  mork_rid id = mRowSpace_NextRowId;
  mork_num count = 9; // try up to eight times
  mdbOid oid;
  oid.mOid_Scope = this->SpaceScope();
  
  while ( !outRid && --count ) // still trying to find an unused row ID?
  {
    oid.mOid_Id = id;
    if ( !mRowSpace_Rows.GetOid(ev, &oid) )
      outRid = id;
    else
    {
      MORK_ASSERT(morkBool_kFalse); // alert developer about ID problems
      ++id;
    }
  }
  
  mRowSpace_NextRowId = id + 1;
  return outRid;
}
/*public virtual*/
morkSearchRowCursor::~morkSearchRowCursor() // CloseSearchRowCursor() executed earlier
{
  MORK_ASSERT(this->IsShutNode());
}
示例#30
0
/*public virtual*/
morkParser::~morkParser() // assert CloseParser() executed earlier
{
  MORK_ASSERT(mParser_Heap==0);
  MORK_ASSERT(mParser_Stream==0);
}