Browse Source

Issue #1258 - Part 1: Import mailnews, ldap, and mork from comm-esr52.9.1

pull/24/head
Matt A. Tobin 3 years ago committed by Roy Tam
parent
commit
e400f4130a
  1. 24
      db/mork/build/moz.build
  2. 30
      db/mork/build/nsIMdbFactoryFactory.h
  3. 21
      db/mork/build/nsMorkCID.h
  4. 56
      db/mork/build/nsMorkFactory.cpp
  5. 2520
      db/mork/public/mdb.h
  6. 9
      db/mork/public/moz.build
  7. 247
      db/mork/src/mork.h
  8. 297
      db/mork/src/morkArray.cpp
  9. 98
      db/mork/src/morkArray.h
  10. 528
      db/mork/src/morkAtom.cpp
  11. 365
      db/mork/src/morkAtom.h
  12. 427
      db/mork/src/morkAtomMap.cpp
  13. 365
      db/mork/src/morkAtomMap.h
  14. 270
      db/mork/src/morkAtomSpace.cpp
  15. 219
      db/mork/src/morkAtomSpace.h
  16. 425
      db/mork/src/morkBead.cpp
  17. 245
      db/mork/src/morkBead.h
  18. 110
      db/mork/src/morkBlob.cpp
  19. 141
      db/mork/src/morkBlob.h
  20. 1031
      db/mork/src/morkBuilder.cpp
  21. 303
      db/mork/src/morkBuilder.h
  22. 114
      db/mork/src/morkCell.cpp
  23. 89
      db/mork/src/morkCell.h
  24. 530
      db/mork/src/morkCellObject.cpp
  25. 173
      db/mork/src/morkCellObject.h
  26. 233
      db/mork/src/morkCh.cpp
  27. 126
      db/mork/src/morkCh.h
  28. 201
      db/mork/src/morkConfig.cpp
  29. 157
      db/mork/src/morkConfig.h
  30. 201
      db/mork/src/morkCursor.cpp
  31. 127
      db/mork/src/morkCursor.h
  32. 288
      db/mork/src/morkDeque.cpp
  33. 239
      db/mork/src/morkDeque.h
  34. 615
      db/mork/src/morkEnv.cpp
  35. 218
      db/mork/src/morkEnv.h
  36. 610
      db/mork/src/morkFactory.cpp
  37. 203
      db/mork/src/morkFactory.h
  38. 874
      db/mork/src/morkFile.cpp
  39. 355
      db/mork/src/morkFile.h
  40. 423
      db/mork/src/morkHandle.cpp
  41. 176
      db/mork/src/morkHandle.h
  42. 238
      db/mork/src/morkIntMap.cpp
  43. 145
      db/mork/src/morkIntMap.h
  44. 953
      db/mork/src/morkMap.cpp
  45. 394
      db/mork/src/morkMap.h
  46. 592
      db/mork/src/morkNode.cpp
  47. 292
      db/mork/src/morkNode.h
  48. 155
      db/mork/src/morkNodeMap.cpp
  49. 98
      db/mork/src/morkNodeMap.h
  50. 206
      db/mork/src/morkObject.cpp
  51. 143
      db/mork/src/morkObject.h
  52. 1568
      db/mork/src/morkParser.cpp
  53. 533
      db/mork/src/morkParser.h
  54. 552
      db/mork/src/morkPool.cpp
  55. 152
      db/mork/src/morkPool.h
  56. 430
      db/mork/src/morkPortTableCursor.cpp
  57. 141
      db/mork/src/morkPortTableCursor.h
  58. 1234
      db/mork/src/morkProbeMap.cpp
  59. 431
      db/mork/src/morkProbeMap.h
  60. 187
      db/mork/src/morkQuickSort.cpp
  61. 25
      db/mork/src/morkQuickSort.h
  62. 933
      db/mork/src/morkRow.cpp
  63. 226
      db/mork/src/morkRow.h
  64. 289
      db/mork/src/morkRowCellCursor.cpp
  65. 124
      db/mork/src/morkRowCellCursor.h
  66. 297
      db/mork/src/morkRowMap.cpp
  67. 211
      db/mork/src/morkRowMap.h
  68. 623
      db/mork/src/morkRowObject.cpp
  69. 200
      db/mork/src/morkRowObject.h
  70. 632
      db/mork/src/morkRowSpace.cpp
  71. 233
      db/mork/src/morkRowSpace.h
  72. 169
      db/mork/src/morkSearchRowCursor.cpp
  73. 105
      db/mork/src/morkSearchRowCursor.h
  74. 292
      db/mork/src/morkSink.cpp
  75. 161
      db/mork/src/morkSink.h
  76. 152
      db/mork/src/morkSpace.cpp
  77. 110
      db/mork/src/morkSpace.h
  78. 2290
      db/mork/src/morkStore.cpp
  79. 768
      db/mork/src/morkStore.h
  80. 859
      db/mork/src/morkStream.cpp
  81. 251
      db/mork/src/morkStream.h
  82. 1610
      db/mork/src/morkTable.cpp
  83. 729
      db/mork/src/morkTable.h
  84. 493
      db/mork/src/morkTableRowCursor.cpp
  85. 146
      db/mork/src/morkTableRowCursor.h
  86. 523
      db/mork/src/morkThumb.cpp
  87. 180
      db/mork/src/morkThumb.h
  88. 94
      db/mork/src/morkUniqRowCursor.h
  89. 2206
      db/mork/src/morkWriter.cpp
  90. 343
      db/mork/src/morkWriter.h
  91. 75
      db/mork/src/morkYarn.cpp
  92. 75
      db/mork/src/morkYarn.h
  93. 527
      db/mork/src/morkZone.cpp
  94. 321
      db/mork/src/morkZone.h
  95. 55
      db/mork/src/moz.build
  96. 84
      db/mork/src/orkinHeap.cpp
  97. 52
      db/mork/src/orkinHeap.h
  98. 11
      db/moz.build
  99. 379
      ldap/c-sdk/include/disptmpl.h
  100. 72
      ldap/c-sdk/include/iutil.h
  101. Some files were not shown because too many files have changed in this diff Show More

24
db/mork/build/moz.build

@ -0,0 +1,24 @@
# vim: set filetype=python:
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
EXPORTS += [
'nsIMdbFactoryFactory.h',
'nsMorkCID.h',
]
SOURCES += [
'nsMorkFactory.cpp',
]
if CONFIG['MOZ_INCOMPLETE_EXTERNAL_LINKAGE']:
XPCOMBinaryComponent('mork')
USE_LIBS += [
'nspr',
'xpcomglue_s',
'xul',
]
else:
Library('mork')
FINAL_LIBRARY = 'xul'

30
db/mork/build/nsIMdbFactoryFactory.h

@ -0,0 +1,30 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef nsIMdbFactoryFactory_h__
#define nsIMdbFactoryFactory_h__
#include "nsISupports.h"
#include "nsIFactory.h"
#include "nsIComponentManager.h"
class nsIMdbFactory;
// 2794D0B7-E740-47a4-91C0-3E4FCB95B806
#define NS_IMDBFACTORYFACTORY_IID \
{ 0x2794d0b7, 0xe740, 0x47a4, { 0x91, 0xc0, 0x3e, 0x4f, 0xcb, 0x95, 0xb8, 0x6 } }
// because Mork doesn't support XPCOM, we have to wrap the mdb factory interface
// with an interface that gives you an mdb factory.
class nsIMdbFactoryService : public nsISupports
{
public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_IMDBFACTORYFACTORY_IID)
NS_IMETHOD GetMdbFactory(nsIMdbFactory **aFactory) = 0;
};
NS_DEFINE_STATIC_IID_ACCESSOR(nsIMdbFactoryService, NS_IMDBFACTORYFACTORY_IID)
#endif

21
db/mork/build/nsMorkCID.h

@ -0,0 +1,21 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef nsMorkCID_h__
#define nsMorkCID_h__
#include "nsISupports.h"
#include "nsIFactory.h"
#include "nsIComponentManager.h"
#define NS_MORK_CONTRACTID \
"@mozilla.org/db/mork;1"
// 36d90300-27f5-11d3-8d74-00805f8a6617
#define NS_MORK_CID \
{ 0x36d90300, 0x27f5, 0x11d3, \
{ 0x8d, 0x74, 0x00, 0x80, 0x5f, 0x8a, 0x66, 0x17 } }
#endif

56
db/mork/build/nsMorkFactory.cpp

@ -0,0 +1,56 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/ModuleUtils.h"
#include "nsCOMPtr.h"
#include "nsMorkCID.h"
#include "nsIMdbFactoryFactory.h"
#include "mdb.h"
class nsMorkFactoryService final : public nsIMdbFactoryService
{
public:
nsMorkFactoryService() {};
// nsISupports methods
NS_DECL_ISUPPORTS
NS_IMETHOD GetMdbFactory(nsIMdbFactory **aFactory) override;
protected:
~nsMorkFactoryService() {}
nsCOMPtr<nsIMdbFactory> mMdbFactory;
};
NS_GENERIC_FACTORY_CONSTRUCTOR(nsMorkFactoryService)
NS_DEFINE_NAMED_CID(NS_MORK_CID);
const mozilla::Module::CIDEntry kMorkCIDs[] = {
{ &kNS_MORK_CID, false, NULL, nsMorkFactoryServiceConstructor },
{ NULL }
};
const mozilla::Module::ContractIDEntry kMorkContracts[] = {
{ NS_MORK_CONTRACTID, &kNS_MORK_CID },
{ NULL }
};
static const mozilla::Module kMorkModule = {
mozilla::Module::kVersion,
kMorkCIDs,
kMorkContracts
};
NSMODULE_DEFN(nsMorkModule) = &kMorkModule;
NS_IMPL_ISUPPORTS(nsMorkFactoryService, nsIMdbFactoryService)
NS_IMETHODIMP nsMorkFactoryService::GetMdbFactory(nsIMdbFactory **aFactory)
{
if (!mMdbFactory)
mMdbFactory = MakeMdbFactory();
NS_IF_ADDREF(*aFactory = mMdbFactory);
return *aFactory ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}

2520
db/mork/public/mdb.h

File diff suppressed because it is too large Load Diff

9
db/mork/public/moz.build

@ -0,0 +1,9 @@
# vim: set filetype=python:
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
EXPORTS += [
'mdb.h',
]

247
db/mork/src/mork.h

@ -0,0 +1,247 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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.
*
* The Original Code is mozilla.org code.
*
* 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 of 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 MPL, 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 MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef _MORK_
#define _MORK_ 1
#ifndef _MDB_
#include "mdb.h"
#endif
#include "nscore.h"
//3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
// { %%%%% begin disable unused param warnings %%%%%
#define MORK_USED_1(x) (void)(&x)
#define MORK_USED_2(x,y) (void)(&x);(void)(&y);
#define MORK_USED_3(x,y,z) (void)(&x);(void)(&y);(void)(&z);
#define MORK_USED_4(w,x,y,z) (void)(&w);(void)(&x);(void)(&y);(void)(&z);
// } %%%%% end disable unused param warnings %%%%%
// { %%%%% begin macro for finding class member offset %%%%%
/*| OffsetOf: the unsigned integer offset of a class or struct
**| field from the beginning of that class or struct. This is
**| the same as the similarly named public domain IronDoc macro,
**| and is also the same as another macro appearing in stdlib.h.
**| We want these offsets so we can correctly convert pointers
**| to member slots back into pointers to enclosing objects, and
**| have this exactly match what the compiler thinks is true.
**|
**|| Bascially we are asking the compiler to determine the offset at
**| compile time, and we use the definition of address artithmetic
**| to do this. By casting integer zero to a pointer of type obj*,
**| we can reference the address of a slot in such an object that
**| is hypothetically physically placed at address zero, but without
**| actually dereferencing a memory location. The absolute address
**| of slot is the same as offset of that slot, when the object is
**| placed at address zero.
|*/
#define mork_OffsetOf(obj,slot) ((unsigned int)&((obj*) 0)->slot)
// } %%%%% end macro for finding class member offset %%%%%
// { %%%%% begin specific-size integer scalar typedefs %%%%%
typedef unsigned char mork_u1; // make sure this is one byte
typedef unsigned short mork_u2; // make sure this is two bytes
typedef short mork_i2; // make sure this is two bytes
typedef uint32_t mork_u4; // make sure this is four bytes
typedef int32_t mork_i4; // make sure this is four bytes
typedef PRWord mork_ip; // make sure sizeof(mork_ip) == sizeof(void*)
typedef mork_u1 mork_ch; // small byte-sized character (never wide)
typedef mork_u1 mork_flags; // one byte's worth of predicate bit flags
typedef mork_u2 mork_base; // 2-byte magic class signature slot in object
typedef mork_u2 mork_derived; // 2-byte magic class signature slot in object
typedef mork_u4 mork_token; // unsigned token for atomized string
typedef mork_token mork_scope; // token used to id scope for rows
typedef mork_token mork_kind; // token used to id kind for tables
typedef mork_token mork_cscode; // token used to id charset names
typedef mork_token mork_aid; // token used to id atomize cell values
typedef mork_token mork_column; // token used to id columns for rows
typedef mork_column mork_delta; // mork_column plus mork_change
typedef mork_token mork_color; // bead ID
#define morkColor_kNone ((mork_color) 0)
typedef mork_u4 mork_magic; // unsigned magic signature
typedef mork_u4 mork_seed; // unsigned collection change counter
typedef mork_u4 mork_count; // unsigned collection member count
typedef mork_count mork_num; // synonym for count
typedef mork_u4 mork_size; // unsigned physical media size
typedef mork_u4 mork_fill; // unsigned logical content size
typedef mork_u4 mork_more; // more available bytes for larger buffer
typedef mdb_u4 mork_percent; // 0..100, with values >100 same as 100
typedef mork_i4 mork_pos; // negative means "before first" (at zero pos)
typedef mork_i4 mork_line; // negative means "before first line in file"
typedef mork_u1 mork_usage; // 1-byte magic usage signature slot in object
typedef mork_u1 mork_access; // 1-byte magic access signature slot in object
typedef mork_u1 mork_change; // add, cut, put, set, nil
typedef mork_u1 mork_priority; // 0..9, for a total of ten different values
typedef mork_u1 mork_able; // on, off, asleep (clone IronDoc's fe_able)
typedef mork_u1 mork_load; // dirty or clean (clone IronDoc's fe_load)
// } %%%%% end specific-size integer scalar typedefs %%%%%
// 'test' is a public domain Mithril for key equality tests in probe maps
typedef mork_i2 mork_test; /* neg=>kVoid, zero=>kHit, pos=>kMiss */
#define morkTest_kVoid ((mork_test) -1) /* -1: nil key slot, no key order */
#define morkTest_kHit ((mork_test) 0) /* 0: keys are equal, a map hit */
#define morkTest_kMiss ((mork_test) 1) /* 1: keys not equal, a map miss */
// { %%%%% begin constants for Mork scalar types %%%%%
#define morkPriority_kHi ((mork_priority) 0) /* best priority */
#define morkPriority_kMin ((mork_priority) 0) /* best priority is smallest */
#define morkPriority_kLo ((mork_priority) 9) /* worst priority */
#define morkPriority_kMax ((mork_priority) 9) /* worst priority is biggest */
#define morkPriority_kCount 10 /* number of distinct priority values */
#define morkAble_kEnabled ((mork_able) 0x55) /* same as IronDoc constant */
#define morkAble_kDisabled ((mork_able) 0xAA) /* same as IronDoc constant */
#define morkAble_kAsleep ((mork_able) 0x5A) /* same as IronDoc constant */
#define morkChange_kAdd 'a' /* add member */
#define morkChange_kCut 'c' /* cut member */
#define morkChange_kPut 'p' /* put member */
#define morkChange_kSet 's' /* set all members */
#define morkChange_kNil 0 /* no change in this member */
#define morkChange_kDup 'd' /* duplicate changes have no effect */
// kDup is intended to replace another change constant in an object as a
// conclusion about change feasibility while staging intended alterations.
#define morkLoad_kDirty ((mork_load) 0xDD) /* same as IronDoc constant */
#define morkLoad_kClean ((mork_load) 0x22) /* same as IronDoc constant */
#define morkAccess_kOpen 'o'
#define morkAccess_kClosing 'c'
#define morkAccess_kShut 's'
#define morkAccess_kDead 'd'
// } %%%%% end constants for Mork scalar types %%%%%
// { %%%%% begin non-specific-size integer scalar typedefs %%%%%
typedef int mork_char; // nominal type for ints used to hold input byte
#define morkChar_IsWhite(c) \
((c) == 0xA || (c) == 0x9 || (c) == 0xD || (c) == ' ')
// } %%%%% end non-specific-size integer scalar typedefs %%%%%
// { %%%%% begin mdb-driven scalar typedefs %%%%%
// easier to define bool exactly the same as mdb:
typedef mdb_bool mork_bool; // unsigned byte with zero=false, nonzero=true
/* canonical boolean constants provided only for code clarity: */
#define morkBool_kTrue ((mork_bool) 1) /* actually any nonzero means true */
#define morkBool_kFalse ((mork_bool) 0) /* only zero means false */
// mdb clients can assign these, so we cannot pick maximum size:
typedef mdb_id mork_id; // unsigned object identity in a scope
typedef mork_id mork_rid; // unsigned row identity inside scope
typedef mork_id mork_tid; // unsigned table identity inside scope
typedef mork_id mork_gid; // unsigned group identity without any scope
// we only care about neg, zero, pos -- so we don't care about size:
typedef mdb_order mork_order; // neg:lessthan, zero:equalto, pos:greaterthan
// } %%%%% end mdb-driven scalar typedefs %%%%%
#define morkId_kMinusOne ((mdb_id) -1)
// { %%%%% begin class forward defines %%%%%
// try to put these in alphabetical order for easier examination:
class morkMid;
class morkAtom;
class morkAtomSpace;
class morkBookAtom;
class morkBuf;
class morkBuilder;
class morkCell;
class morkCellObject;
class morkCursor;
class morkEnv;
class morkFactory;
class morkFile;
class morkHandle;
class morkHandleFace; // just an opaque cookie type
class morkHandleFrame;
class morkHashArrays;
class morkMap;
class morkNode;
class morkObject;
class morkOidAtom;
class morkParser;
class morkPool;
class morkPlace;
class morkPort;
class morkPortTableCursor;
class morkProbeMap;
class morkRow;
class morkRowCellCursor;
class morkRowObject;
class morkRowSpace;
class morkSorting;
class morkSortingRowCursor;
class morkSpace;
class morkSpan;
class morkStore;
class morkStream;
class morkTable;
class morkTableChange;
class morkTableRowCursor;
class morkThumb;
class morkWriter;
class morkZone;
// } %%%%% end class forward defines %%%%%
// include this config file last for platform & environment specific stuff:
#ifndef _MORKCONFIG_
#include "morkConfig.h"
#endif
//3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
#endif /* _MORK_ */

297
db/mork/src/morkArray.cpp

@ -0,0 +1,297 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nscore.h"
#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 _MORKARRAY_
#include "morkArray.h"
#endif
//3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
// ````` ````` ````` ````` `````
// { ===== begin morkNode interface =====
/*public virtual*/ void
morkArray::CloseMorkNode(morkEnv* ev) // CloseTable() only if open
{
if ( this->IsOpenNode() )
{
this->MarkClosing();
this->CloseArray(ev);
this->MarkShut();
}
}
/*public virtual*/
morkArray::~morkArray() // assert CloseTable() executed earlier
{
MORK_ASSERT(this->IsShutNode());
MORK_ASSERT(mArray_Slots==0);
}
/*public non-poly*/
morkArray::morkArray(morkEnv* ev, const morkUsage& inUsage,
nsIMdbHeap* ioHeap, mork_size inSize, nsIMdbHeap* ioSlotHeap)
: morkNode(ev, inUsage, ioHeap)
, mArray_Slots( 0 )
, mArray_Heap( 0 )
, mArray_Fill( 0 )
, mArray_Size( 0 )
, mArray_Seed( (mork_u4)NS_PTR_TO_INT32(this) ) // "random" integer assignment
{
if ( ev->Good() )
{
if ( ioSlotHeap )
{
nsIMdbHeap_SlotStrongHeap(ioSlotHeap, ev, &mArray_Heap);
if ( ev->Good() )
{
if ( inSize < 3 )
inSize = 3;
mdb_size byteSize = inSize * sizeof(void*);
void** block = 0;
ioSlotHeap->Alloc(ev->AsMdbEnv(), byteSize, (void**) &block);
if ( block && ev->Good() )
{
mArray_Slots = block;
mArray_Size = inSize;
MORK_MEMSET(mArray_Slots, 0, byteSize);
if ( ev->Good() )
mNode_Derived = morkDerived_kArray;
}
}
}
else
ev->NilPointerError();
}
}
/*public non-poly*/ void
morkArray::CloseArray(morkEnv* ev) // called by CloseMorkNode();
{
if ( this->IsNode() )
{
if ( mArray_Heap && mArray_Slots )
mArray_Heap->Free(ev->AsMdbEnv(), mArray_Slots);
mArray_Slots = 0;
mArray_Size = 0;
mArray_Fill = 0;
++mArray_Seed;
nsIMdbHeap_SlotStrongHeap((nsIMdbHeap*) 0, ev, &mArray_Heap);
this->MarkShut();
}
else
this->NonNodeError(ev);
}
// } ===== end morkNode methods =====
// ````` ````` ````` ````` `````
/*static*/ void
morkArray::NonArrayTypeError(morkEnv* ev)
{
ev->NewError("non morkArray");
}
/*static*/ void
morkArray::IndexBeyondEndError(morkEnv* ev)
{
ev->NewError("array index beyond end");
}
/*static*/ void
morkArray::NilSlotsAddressError(morkEnv* ev)
{
ev->NewError("nil mArray_Slots");
}
/*static*/ void
morkArray::FillBeyondSizeError(morkEnv* ev)
{
ev->NewError("mArray_Fill > mArray_Size");
}
mork_bool
morkArray::Grow(morkEnv* ev, mork_size inNewSize)
// Grow() returns true if capacity becomes >= inNewSize and ev->Good()
{
if ( ev->Good() && inNewSize > mArray_Size ) // make array larger?
{
if ( mArray_Fill <= mArray_Size ) // fill and size fit the invariant?
{
if (mArray_Size <= 3)
inNewSize = mArray_Size + 3;
else
inNewSize = mArray_Size * 2;// + 3; // try doubling size here - used to grow by 3
mdb_size newByteSize = inNewSize * sizeof(void*);
void** newBlock = 0;
mArray_Heap->Alloc(ev->AsMdbEnv(), newByteSize, (void**) &newBlock);
if ( newBlock && ev->Good() ) // okay new block?
{
void** oldSlots = mArray_Slots;
void** oldEnd = oldSlots + mArray_Fill;
void** newSlots = newBlock;
void** newEnd = newBlock + inNewSize;
while ( oldSlots < oldEnd )
*newSlots++ = *oldSlots++;
while ( newSlots < newEnd )
*newSlots++ = (void*) 0;
oldSlots = mArray_Slots;
mArray_Size = inNewSize;
mArray_Slots = newBlock;
mArray_Heap->Free(ev->AsMdbEnv(), oldSlots);
}
}
else
this->FillBeyondSizeError(ev);
}
++mArray_Seed; // always modify seed, since caller intends to add slots
return ( ev->Good() && mArray_Size >= inNewSize );
}
void*
morkArray::SafeAt(morkEnv* ev, mork_pos inPos)
{
if ( mArray_Slots )
{
if ( inPos >= 0 && inPos < (mork_pos) mArray_Fill )
return mArray_Slots[ inPos ];
else
this->IndexBeyondEndError(ev);
}
else
this->NilSlotsAddressError(ev);
return (void*) 0;
}
void
morkArray::SafeAtPut(morkEnv* ev, mork_pos inPos, void* ioSlot)
{
if ( mArray_Slots )
{
if ( inPos >= 0 && inPos < (mork_pos) mArray_Fill )
{
mArray_Slots[ inPos ] = ioSlot;
++mArray_Seed;
}
else
this->IndexBeyondEndError(ev);
}
else
this->NilSlotsAddressError(ev);
}
mork_pos
morkArray::AppendSlot(morkEnv* ev, void* ioSlot)
{
mork_pos outPos = -1;
if ( mArray_Slots )
{
mork_fill fill = mArray_Fill;
if ( this->Grow(ev, fill+1) )
{
outPos = (mork_pos) fill;
mArray_Slots[ fill ] = ioSlot;
mArray_Fill = fill + 1;
// note Grow() increments mArray_Seed
}
}
else
this->NilSlotsAddressError(ev);
return outPos;
}
void
morkArray::AddSlot(morkEnv* ev, mork_pos inPos, void* ioSlot)
{
if ( mArray_Slots )
{
mork_fill fill = mArray_Fill;
if ( this->Grow(ev, fill+1) )
{
void** slot = mArray_Slots; // the slot vector
void** end = slot + fill; // one past the last used array slot
slot += inPos; // the slot to be added
while ( --end >= slot ) // another slot to move upward?
end[ 1 ] = *end;
*slot = ioSlot;
mArray_Fill = fill + 1;
// note Grow() increments mArray_Seed
}
}
else
this->NilSlotsAddressError(ev);
}
void
morkArray::CutSlot(morkEnv* ev, mork_pos inPos)
{
MORK_USED_1(ev);
mork_fill fill = mArray_Fill;
if ( inPos >= 0 && inPos < (mork_pos) fill ) // cutting slot in used array portion?
{
void** slot = mArray_Slots; // the slot vector
void** end = slot + fill; // one past the last used array slot
slot += inPos; // the slot to be cut
while ( ++slot < end ) // another slot to move downward?
slot[ -1 ] = *slot;
slot[ -1 ] = 0; // clear the last used slot which is now unused
// note inPos<fill implies fill>0, so fill-1 must be nonnegative:
mArray_Fill = fill - 1;
++mArray_Seed;
}
}
void
morkArray::CutAllSlots(morkEnv* ev)
{
if ( mArray_Slots )
{
if ( mArray_Fill <= mArray_Size )
{
mdb_size oldByteSize = mArray_Fill * sizeof(void*);
MORK_MEMSET(mArray_Slots, 0, oldByteSize);
}
else
this->FillBeyondSizeError(ev);
}
else
this->NilSlotsAddressError(ev);
++mArray_Seed;
mArray_Fill = 0;
}
//3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789

98
db/mork/src/morkArray.h

@ -0,0 +1,98 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef _MORKARRAY_
#define _MORKARRAY_ 1
#ifndef _MORK_
#include "mork.h"
#endif
#ifndef _MORKNODE_
#include "morkNode.h"
#endif
//3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
#define morkDerived_kArray /*i*/ 0x4179 /* ascii 'Ay' */
class morkArray : public morkNode { // row iterator
// public: // slots inherited from morkObject (meant to inform only)
// nsIMdbHeap* mNode_Heap;
// mork_able mNode_Mutable; // can this node be modified?
// mork_load mNode_Load; // is this node clean or dirty?
// mork_base mNode_Base; // must equal morkBase_kNode
// mork_derived mNode_Derived; // depends on specific node subclass
// mork_access mNode_Access; // kOpen, kClosing, kShut, or kDead
// mork_usage mNode_Usage; // kHeap, kStack, kMember, kGlobal, kNone
// mork_uses mNode_Uses; // refcount for strong refs
// mork_refs mNode_Refs; // refcount for strong refs + weak refs
public: // state is public because the entire Mork system is private
void** mArray_Slots; // array of pointers
nsIMdbHeap* mArray_Heap; // required heap for allocating mArray_Slots
mork_fill mArray_Fill; // logical count of used slots in mArray_Slots
mork_size mArray_Size; // physical count of mArray_Slots ( >= Fill)
mork_seed mArray_Seed; // change counter for syncing with iterators
// { ===== begin morkNode interface =====
public: // morkNode virtual methods
virtual void CloseMorkNode(morkEnv* ev) override; // CloseArray()
virtual ~morkArray(); // assert that close executed earlier
public: // morkArray construction & destruction
morkArray(morkEnv* ev, const morkUsage& inUsage,
nsIMdbHeap* ioHeap, mork_size inSize, nsIMdbHeap* ioSlotHeap);
void CloseArray(morkEnv* ev); // called by CloseMorkNode();
private: // copying is not allowed
morkArray(const morkArray& other);
morkArray& operator=(const morkArray& other);
public: // dynamic type identification
mork_bool IsArray() const
{ return IsNode() && mNode_Derived == morkDerived_kArray; }
// } ===== end morkNode methods =====
public: // typing & errors
static void NonArrayTypeError(morkEnv* ev);
static void IndexBeyondEndError(morkEnv* ev);
static void NilSlotsAddressError(morkEnv* ev);
static void FillBeyondSizeError(morkEnv* ev);
public: // other table row cursor methods
mork_fill Length() const { return mArray_Fill; }
mork_size Capacity() const { return mArray_Size; }
mork_bool Grow(morkEnv* ev, mork_size inNewSize);
// Grow() returns true if capacity becomes >= inNewSize and ev->Good()
void* At(mork_pos inPos) const { return mArray_Slots[ inPos ]; }
void AtPut(mork_pos inPos, void* ioSlot)
{ mArray_Slots[ inPos ] = ioSlot; }
void* SafeAt(morkEnv* ev, mork_pos inPos);
void SafeAtPut(morkEnv* ev, mork_pos inPos, void* ioSlot);
mork_pos AppendSlot(morkEnv* ev, void* ioSlot);
void AddSlot(morkEnv* ev, mork_pos inPos, void* ioSlot);
void CutSlot(morkEnv* ev, mork_pos inPos);
void CutAllSlots(morkEnv* ev);
public: // typesafe refcounting inlines calling inherited morkNode methods
static void SlotWeakArray(morkArray* me,
morkEnv* ev, morkArray** ioSlot)
{ morkNode::SlotWeakNode((morkNode*) me, ev, (morkNode**) ioSlot); }
static void SlotStrongArray(morkArray* me,
morkEnv* ev, morkArray** ioSlot)
{ morkNode::SlotStrongNode((morkNode*) me, ev, (morkNode**) ioSlot); }
};
//3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
#endif /* _MORKTABLEROWCURSOR_ */

528
db/mork/src/morkAtom.cpp

@ -0,0 +1,528 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef _MDB_
#include "mdb.h"
#endif
#ifndef _MORK_
#include "mork.h"
#endif
#ifndef _MORKBLOB_
#include "morkBlob.h"
#endif
#ifndef _MORKATOM_
#include "morkAtom.h"
#endif
#ifndef _MORKENV_
#include "morkEnv.h"
#endif
#ifndef _MORKATOMSPACE_
#include "morkAtomSpace.h"
#endif
//3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
mork_bool
morkAtom::GetYarn(mdbYarn* outYarn) const
{
const void* source = 0;
mdb_fill fill = 0;
mdb_cscode form = 0;
outYarn->mYarn_More = 0;
if ( this->IsWeeBook() )
{
morkWeeBookAtom* weeBook = (morkWeeBookAtom*) this;
source = weeBook->mWeeBookAtom_Body;
fill = weeBook->mAtom_Size;
}
else if ( this->IsBigBook() )
{
morkBigBookAtom* bigBook = (morkBigBookAtom*) this;
source = bigBook->mBigBookAtom_Body;
fill = bigBook->mBigBookAtom_Size;
form = bigBook->mBigBookAtom_Form;
}
else if ( this->IsWeeAnon() )
{
morkWeeAnonAtom* weeAnon = (morkWeeAnonAtom*) this;
source = weeAnon->mWeeAnonAtom_Body;
fill = weeAnon->mAtom_Size;
}
else if ( this->IsBigAnon() )
{
morkBigAnonAtom* bigAnon = (morkBigAnonAtom*) this;
source = bigAnon->mBigAnonAtom_Body;
fill = bigAnon->mBigAnonAtom_Size;
form = bigAnon->mBigAnonAtom_Form;
}
if ( source && fill ) // have an atom with nonempty content?
{
// if we have too many bytes, and yarn seems growable:
if ( fill > outYarn->mYarn_Size && outYarn->mYarn_Grow ) // try grow?
(*outYarn->mYarn_Grow)(outYarn, (mdb_size) fill); // request bigger
mdb_size size = outYarn->mYarn_Size; // max dest size
if ( fill > size ) // too much atom content?
{
outYarn->mYarn_More = fill - size; // extra atom bytes omitted
fill = size; // copy no more bytes than size of yarn buffer
}
void* dest = outYarn->mYarn_Buf; // where bytes are going
if ( !dest ) // nil destination address buffer?
fill = 0; // we can't write any content at all
if ( fill ) // anything to copy?
MORK_MEMCPY(dest, source, fill); // copy fill bytes to yarn
outYarn->mYarn_Fill = fill; // tell yarn size of copied content
}
else // no content to put into the yarn
{
outYarn->mYarn_Fill = 0; // tell yarn that atom has no bytes
}
outYarn->mYarn_Form = form; // always update the form slot
return ( source != 0 );
}
/* static */
mork_bool
morkAtom::AliasYarn(const morkAtom* atom, mdbYarn* outYarn)
{
outYarn->mYarn_More = 0;
outYarn->mYarn_Form = 0;
if ( atom )
{
if ( atom->IsWeeBook() )
{
morkWeeBookAtom* weeBook = (morkWeeBookAtom*) atom;
outYarn->mYarn_Buf = weeBook->mWeeBookAtom_Body;
outYarn->mYarn_Fill = weeBook->mAtom_Size;
outYarn->mYarn_Size = weeBook->mAtom_Size;
}
else if ( atom->IsBigBook() )
{
morkBigBookAtom* bigBook = (morkBigBookAtom*) atom;
outYarn->mYarn_Buf = bigBook->mBigBookAtom_Body;
outYarn->mYarn_Fill = bigBook->mBigBookAtom_Size;
outYarn->mYarn_Size = bigBook->mBigBookAtom_Size;
outYarn->mYarn_Form = bigBook->mBigBookAtom_Form;
}
else if ( atom->IsWeeAnon() )
{
morkWeeAnonAtom* weeAnon = (morkWeeAnonAtom*) atom;
outYarn->mYarn_Buf = weeAnon->mWeeAnonAtom_Body;
outYarn->mYarn_Fill = weeAnon->mAtom_Size;
outYarn->mYarn_Size = weeAnon->mAtom_Size;
}
else if ( atom->IsBigAnon() )
{
morkBigAnonAtom* bigAnon = (morkBigAnonAtom*) atom;
outYarn->mYarn_Buf = bigAnon->mBigAnonAtom_Body;
outYarn->mYarn_Fill = bigAnon->mBigAnonAtom_Size;
outYarn->mYarn_Size = bigAnon->mBigAnonAtom_Size;
outYarn->mYarn_Form = bigAnon->mBigAnonAtom_Form;
}
else
atom = 0; // show desire to put empty content in yarn
}
if ( !atom ) // empty content for yarn?
{
outYarn->mYarn_Buf = 0;
outYarn->mYarn_Fill = 0;
outYarn->mYarn_Size = 0;
// outYarn->mYarn_Grow = 0; // please don't modify the Grow slot
}
return ( atom != 0 );
}
mork_aid
morkAtom::GetBookAtomAid() const // zero or book atom's ID
{
return ( this->IsBook() )? ((morkBookAtom*) this)->mBookAtom_Id : 0;
}
mork_scope
morkAtom::GetBookAtomSpaceScope(morkEnv* ev) const // zero or book's space's scope
{
mork_scope outScope = 0;
if ( this->IsBook() )
{
const morkBookAtom* bookAtom = (const morkBookAtom*) this;
morkAtomSpace* space = bookAtom->mBookAtom_Space;
if ( space->IsAtomSpace() )
outScope = space->SpaceScope();
else
space->NonAtomSpaceTypeError(ev);
}
return outScope;
}
void
morkAtom::MakeCellUseForever(morkEnv* ev)
{
MORK_USED_1(ev);
mAtom_CellUses = morkAtom_kForeverCellUses;
}
mork_u1
morkAtom::AddCellUse(morkEnv* ev)
{
MORK_USED_1(ev);
if ( mAtom_CellUses < morkAtom_kMaxCellUses ) // not already maxed out?
++mAtom_CellUses;
return mAtom_CellUses;
}
mork_u1
morkAtom::CutCellUse(morkEnv* ev)
{
if ( mAtom_CellUses ) // any outstanding uses to cut?
{
if ( mAtom_CellUses < morkAtom_kMaxCellUses ) // not frozen at max?
--mAtom_CellUses;
}
else
this->CellUsesUnderflowWarning(ev);
return mAtom_CellUses;
}
/*static*/ void
morkAtom::CellUsesUnderflowWarning(morkEnv* ev)
{
ev->NewWarning("mAtom_CellUses underflow");
}
/*static*/ void
morkAtom::BadAtomKindError(morkEnv* ev)
{
ev->NewError("bad mAtom_Kind");
}
/*static*/ void
morkAtom::ZeroAidError(morkEnv* ev)
{
ev->NewError("zero atom ID");
}
/*static*/ void
morkAtom::AtomSizeOverflowError(morkEnv* ev)
{
ev->NewError("atom mAtom_Size overflow");
}
void
morkOidAtom::InitRowOidAtom(morkEnv* ev, const mdbOid& inOid)
{
MORK_USED_1(ev);
mAtom_CellUses = 0;
mAtom_Kind = morkAtom_kKindRowOid;
mAtom_Change = morkChange_kNil;
mAtom_Size = 0;
mOidAtom_Oid = inOid; // bitwise copy
}
void
morkOidAtom::InitTableOidAtom(morkEnv* ev, const mdbOid& inOid)
{
MORK_USED_1(ev);
mAtom_CellUses = 0;
mAtom_Kind = morkAtom_kKindTableOid;
mAtom_Change = morkChange_kNil;
mAtom_Size = 0;
mOidAtom_Oid = inOid; // bitwise copy
}
void
morkWeeAnonAtom::InitWeeAnonAtom(morkEnv* ev, const morkBuf& inBuf)
{
mAtom_Kind = 0;
mAtom_Change = morkChange_kNil;
if ( inBuf.mBuf_Fill <= morkAtom_kMaxByteSize )
{
mAtom_CellUses = 0;
mAtom_Kind = morkAtom_kKindWeeAnon;
mork_size size = inBuf.mBuf_Fill;
mAtom_Size = (mork_u1) size;
if ( size && inBuf.mBuf_Body )
MORK_MEMCPY(mWeeAnonAtom_Body, inBuf.mBuf_Body, size);
mWeeAnonAtom_Body[ size ] = 0;
}
else
this->AtomSizeOverflowError(ev);
}
void
morkBigAnonAtom::InitBigAnonAtom(morkEnv* ev, const morkBuf& inBuf,
mork_cscode inForm)
{
MORK_USED_1(ev);
mAtom_CellUses = 0;
mAtom_Kind = morkAtom_kKindBigAnon;
mAtom_Change = morkChange_kNil;
mAtom_Size = 0;
mBigAnonAtom_Form = inForm;
mork_size size = inBuf.mBuf_Fill;
mBigAnonAtom_Size = size;
if ( size && inBuf.mBuf_Body )
MORK_MEMCPY(mBigAnonAtom_Body, inBuf.mBuf_Body, size);
mBigAnonAtom_Body[ size ] = 0;
}
/*static*/ void
morkBookAtom::NonBookAtomTypeError(morkEnv* ev)
{
ev->NewError("non morkBookAtom");
}
mork_u4
morkBookAtom::HashFormAndBody(morkEnv* ev) const
{
// This hash is obviously a variation of the dragon book string hash.
// (I won't bother to explain or rationalize this usage for you.)
mork_u4 outHash = 0; // hash value returned
unsigned char c; // next character
const mork_u1* body; // body of bytes to hash
mork_size size = 0; // the number of bytes to hash
if ( this->IsWeeBook() )
{
size = mAtom_Size;
body = ((const morkWeeBookAtom*) this)->mWeeBookAtom_Body;
}
else if ( this->IsBigBook() )
{
size = ((const morkBigBookAtom*) this)->mBigBookAtom_Size;
body = ((const morkBigBookAtom*) this)->mBigBookAtom_Body;
}
else if ( this->IsFarBook() )
{
size = ((const morkFarBookAtom*) this)->mFarBookAtom_Size;
body = ((const morkFarBookAtom*) this)->mFarBookAtom_Body;
}
else
{
this->NonBookAtomTypeError(ev);
return 0;
}
const mork_u1* end = body + size;
while ( body < end )
{
c = *body++;
outHash <<= 4;
outHash += c;
mork_u4 top = outHash & 0xF0000000L; // top four bits
if ( top ) // any of high four bits equal to one?
{
outHash ^= (top >> 24); // fold down high bits
outHash ^= top; // zero top four bits
}
}
return outHash;
}
mork_bool
morkBookAtom::EqualFormAndBody(morkEnv* ev, const morkBookAtom* inAtom) const
{
mork_bool outEqual = morkBool_kFalse;
const mork_u1* body = 0; // body of inAtom bytes to compare
mork_size size; // the number of inAtom bytes to compare
mork_cscode form; // nominal charset for ioAtom
if ( inAtom->IsWeeBook() )
{
size = inAtom->mAtom_Size;
body = ((const morkWeeBookAtom*) inAtom)->mWeeBookAtom_Body;
form = 0;
}
else if ( inAtom->IsBigBook() )
{
size = ((const morkBigBookAtom*) inAtom)->mBigBookAtom_Size;
body = ((const morkBigBookAtom*) inAtom)->mBigBookAtom_Body;
form = ((const morkBigBookAtom*) inAtom)->mBigBookAtom_Form;
}
else if ( inAtom->IsFarBook() )
{
size = ((const morkFarBookAtom*) inAtom)->mFarBookAtom_Size;
body = ((const morkFarBookAtom*) inAtom)->mFarBookAtom_Body;
form = ((const morkFarBookAtom*) inAtom)->mFarBookAtom_Form;
}
else
{
inAtom->NonBookAtomTypeError(ev);
return morkBool_kFalse;
}
const mork_u1* thisBody = 0; // body of bytes in this to compare
mork_size thisSize; // the number of bytes in this to compare
mork_cscode thisForm; // nominal charset for this atom
if ( this->IsWeeBook() )
{
thisSize = mAtom_Size;
thisBody = ((const morkWeeBookAtom*) this)->mWeeBookAtom_Body;
thisForm = 0;
}
else if ( this->IsBigBook() )
{
thisSize = ((const morkBigBookAtom*) this)->mBigBookAtom_Size;
thisBody = ((const morkBigBookAtom*) this)->mBigBookAtom_Body;
thisForm = ((const morkBigBookAtom*) this)->mBigBookAtom_Form;
}
else if ( this->IsFarBook() )
{
thisSize = ((const morkFarBookAtom*) this)->mFarBookAtom_Size;
thisBody = ((const morkFarBookAtom*) this)->mFarBookAtom_Body;
thisForm = ((const morkFarBookAtom*) this)->mFarBookAtom_Form;
}
else
{
this->NonBookAtomTypeError(ev);
return morkBool_kFalse;
}
// if atoms are empty, form is irrelevant
if ( body && thisBody && size == thisSize && (!size || form == thisForm ))
outEqual = (MORK_MEMCMP(body, thisBody, size) == 0);
return outEqual;
}
void
morkBookAtom::CutBookAtomFromSpace(morkEnv* ev)
{
morkAtomSpace* space = mBookAtom_Space;
if ( space )
{
mBookAtom_Space = 0;
space->mAtomSpace_AtomBodies.CutAtom(ev, this);
space->mAtomSpace_AtomAids.CutAtom(ev, this);
}
else
ev->NilPointerError();
}
morkWeeBookAtom::morkWeeBookAtom(mork_aid inAid)
{
mAtom_Kind = morkAtom_kKindWeeBook;
mAtom_CellUses = 0;
mAtom_Change = morkChange_kNil;
mAtom_Size = 0;
mBookAtom_Space = 0;
mBookAtom_Id = inAid;
mWeeBookAtom_Body[ 0 ] = 0;
}
void
morkWeeBookAtom::InitWeeBookAtom(morkEnv* ev, const morkBuf& inBuf,
morkAtomSpace* ioSpace, mork_aid inAid)
{
mAtom_Kind = 0;
mAtom_Change = morkChange_kNil;
if ( ioSpace )
{
if ( inAid )
{
if ( inBuf.mBuf_Fill <= morkAtom_kMaxByteSize )
{
mAtom_CellUses = 0;
mAtom_Kind = morkAtom_kKindWeeBook;
mBookAtom_Space = ioSpace;
mBookAtom_Id = inAid;
mork_size size = inBuf.mBuf_Fill;
mAtom_Size = (mork_u1) size;
if ( size && inBuf.mBuf_Body )
MORK_MEMCPY(mWeeBookAtom_Body, inBuf.mBuf_Body, size);
mWeeBookAtom_Body[ size ] = 0;
}
else
this->AtomSizeOverflowError(ev);
}
else
this->ZeroAidError(ev);
}
else
ev->NilPointerError();
}
void
morkBigBookAtom::InitBigBookAtom(morkEnv* ev, const morkBuf& inBuf,
mork_cscode inForm, morkAtomSpace* ioSpace, mork_aid inAid)
{
mAtom_Kind = 0;
mAtom_Change = morkChange_kNil;
if ( ioSpace )
{
if ( inAid )
{
mAtom_CellUses = 0;
mAtom_Kind = morkAtom_kKindBigBook;
mAtom_Size = 0;
mBookAtom_Space = ioSpace;
mBookAtom_Id = inAid;
mBigBookAtom_Form = inForm;
mork_size size = inBuf.mBuf_Fill;
mBigBookAtom_Size = size;
if ( size && inBuf.mBuf_Body )
MORK_MEMCPY(mBigBookAtom_Body, inBuf.mBuf_Body, size);
mBigBookAtom_Body[ size ] = 0;
}
else
this->ZeroAidError(ev);
}
else
ev->NilPointerError();
}
void morkFarBookAtom::InitFarBookAtom(morkEnv* ev, const morkBuf& inBuf,
mork_cscode inForm, morkAtomSpace* ioSpace, mork_aid inAid)
{
mAtom_Kind = 0;
mAtom_Change = morkChange_kNil;
if ( ioSpace )
{
if ( inAid )
{
mAtom_CellUses = 0;
mAtom_Kind = morkAtom_kKindFarBook;
mAtom_Size = 0;
mBookAtom_Space = ioSpace;
mBookAtom_Id = inAid;
mFarBookAtom_Form = inForm;
mFarBookAtom_Size = inBuf.mBuf_Fill;
mFarBookAtom_Body = (mork_u1*) inBuf.mBuf_Body;
}
else
this->ZeroAidError(ev);
}
else
ev->NilPointerError();
}
//3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789

365
db/mork/src/morkAtom.h

@ -0,0 +1,365 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef _MORKATOM_
#define _MORKATOM_ 1
#ifndef _MORK_
#include "mork.h"
#endif
//3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
#define morkAtom_kMaxByteSize 255 /* max for 8-bit integer */
#define morkAtom_kForeverCellUses 0x0FF /* max for 8-bit integer */
#define morkAtom_kMaxCellUses 0x07F /* max for 7-bit integer */
#define morkAtom_kKindWeeAnon 'a' /* means morkWeeAnonAtom subclass */
#define morkAtom_kKindBigAnon 'A' /* means morkBigAnonAtom subclass */
#define morkAtom_kKindWeeBook 'b' /* means morkWeeBookAtom subclass */
#define morkAtom_kKindBigBook 'B' /* means morkBigBookAtom subclass */
#define morkAtom_kKindFarBook 'f' /* means morkFarBookAtom subclass */
#define morkAtom_kKindRowOid 'r' /* means morkOidAtom subclass */
#define morkAtom_kKindTableOid 't' /* means morkOidAtom subclass */
/*| Atom: .
|*/
class morkAtom { //
public:
mork_u1 mAtom_Kind; // identifies a specific atom subclass
mork_u1 mAtom_CellUses; // number of persistent uses in a cell
mork_change mAtom_Change; // how has this atom been changed?
mork_u1 mAtom_Size; // only for atoms smaller than 256 bytes
public:
morkAtom(mork_aid inAid, mork_u1 inKind);
mork_bool IsWeeAnon() const { return mAtom_Kind == morkAtom_kKindWeeAnon; }
mork_bool IsBigAnon() const { return mAtom_Kind == morkAtom_kKindBigAnon; }
mork_bool IsWeeBook() const { return mAtom_Kind == morkAtom_kKindWeeBook; }
mork_bool IsBigBook() const { return mAtom_Kind == morkAtom_kKindBigBook; }
mork_bool IsFarBook() const { return mAtom_Kind == morkAtom_kKindFarBook; }
mork_bool IsRowOid() const { return mAtom_Kind == morkAtom_kKindRowOid; }
mork_bool IsTableOid() const { return mAtom_Kind == morkAtom_kKindTableOid; }
mork_bool IsBook() const { return this->IsWeeBook() || this->IsBigBook(); }
public: // clean vs dirty
void SetAtomClean() { mAtom_Change = morkChange_kNil; }
void SetAtomDirty() { mAtom_Change = morkChange_kAdd; }
mork_bool IsAtomClean() const { return mAtom_Change == morkChange_kNil; }
mork_bool IsAtomDirty() const { return mAtom_Change == morkChange_kAdd; }
public: // atom space scope if IsBook() is true, or else zero:
mork_scope GetBookAtomSpaceScope(morkEnv* ev) const;
// zero or book's space's scope
mork_aid GetBookAtomAid() const;
// zero or book atom's ID
public: // empty construction does nothing
morkAtom() { }
public: // one-byte refcounting, freezing at maximum