Skip to content

Commit

Permalink
Replace some unsized unsigneds
Browse files Browse the repository at this point in the history
Contributes to #535 and #531
  • Loading branch information
blairmcg committed Mar 3, 2020
1 parent 8c9f47a commit 721e6ca
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 36 deletions.
12 changes: 6 additions & 6 deletions Core/DolphinVM/ExternalBuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ struct StoreSigned64
///////////////////////////////////////////////////////////////////////////////
// Primitive templates

template <typename T, typename P> static Oop* __fastcall Interpreter::primitiveIndirectIntegerAtOffset(Oop* const sp, unsigned)
template <typename T, typename P> static Oop* __fastcall Interpreter::primitiveIndirectIntegerAtOffset(Oop* const sp, primargcount_t)
{
Oop oopOffset = *sp;
if (ObjectMemoryIsIntegerObject(oopOffset))
Expand All @@ -90,7 +90,7 @@ template <typename T, typename P> static Oop* __fastcall Interpreter::primitiveI
}
}

template <typename T, typename Store> Oop* __fastcall Interpreter::primitiveIntegerAtOffset(Oop* const sp, unsigned)
template <typename T, typename Store> Oop* __fastcall Interpreter::primitiveIntegerAtOffset(Oop* const sp, primargcount_t)
{
Oop oopOffset = *sp;
if (ObjectMemoryIsIntegerObject(oopOffset))
Expand Down Expand Up @@ -118,7 +118,7 @@ template <typename T, typename Store> Oop* __fastcall Interpreter::primitiveInte
return primitiveFailure(_PrimitiveFailureCode::InvalidParameter1);
}
}
template <typename T, SmallInteger MinVal, SmallInteger MaxVal> Oop* __fastcall Interpreter::primitiveAtOffsetPutInteger(Oop* const sp, unsigned)
template <typename T, SmallInteger MinVal, SmallInteger MaxVal> Oop* __fastcall Interpreter::primitiveAtOffsetPutInteger(Oop* const sp, primargcount_t)
{
BytesOTE* oteReceiver = reinterpret_cast<BytesOTE*>(*(sp - 2));
Oop oopOffset = *(sp - 1);
Expand Down Expand Up @@ -165,7 +165,7 @@ template <typename T, SmallInteger MinVal, SmallInteger MaxVal> Oop* __fastcall
}
}

template <typename T, SmallInteger MinVal, SmallInteger MaxVal> Oop* __fastcall Interpreter::primitiveIndirectAtOffsetPutInteger(Oop* const sp, unsigned)
template <typename T, SmallInteger MinVal, SmallInteger MaxVal> Oop* __fastcall Interpreter::primitiveIndirectAtOffsetPutInteger(Oop* const sp, primargcount_t)
{
AddressOTE* oteReceiver = reinterpret_cast<AddressOTE*>(*(sp - 2));
Oop oopOffset = *(sp - 1);
Expand Down Expand Up @@ -219,7 +219,7 @@ template <typename T, SmallInteger MinVal, SmallInteger MaxVal> Oop* __fastcall
// (e.g. ExternalAddress).
//

template <typename T> Oop* __fastcall Interpreter::primitiveFloatAtOffsetPut(Oop* const sp, unsigned)
template <typename T> Oop* __fastcall Interpreter::primitiveFloatAtOffsetPut(Oop* const sp, primargcount_t)
{
Oop integerPointer = *(sp - 1);
if (ObjectMemoryIsIntegerObject(integerPointer))
Expand Down Expand Up @@ -281,7 +281,7 @@ template <typename T> Oop* __fastcall Interpreter::primitiveFloatAtOffsetPut(Oop
}
}

template <typename T> Oop* __fastcall Interpreter::primitiveFloatAtOffset(Oop* const sp, unsigned)
template <typename T> Oop* __fastcall Interpreter::primitiveFloatAtOffset(Oop* const sp, primargcount_t)
{
Oop integerPointer = *sp;
if (ObjectMemoryIsIntegerObject(integerPointer))
Expand Down
18 changes: 9 additions & 9 deletions Core/DolphinVM/GC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ void ObjectMemory::reclaimInaccessibleObjects(uintptr_t gcFlags)

// Now locate all the unmarked objects, and visit any object referenced from finalizable
// unmarked objects. Also nil the corpses of any weak objects, and queue them for finalization
unsigned nMaxUnmarked = 0, nUnmarked = 0;
size_t nMaxUnmarked = 0, nUnmarked = 0;
OTE** pUnmarked = 0;

const OTE* pEnd = m_pOT+m_nOTSize; // Loop invariant
Expand Down Expand Up @@ -292,8 +292,8 @@ void ObjectMemory::reclaimInaccessibleObjects(uintptr_t gcFlags)
// unmarked
unsigned deletions=0;
unsigned queuedForFinalize=0;
const unsigned loopEnd = nUnmarked;
for (unsigned i=0;i<loopEnd;i++)
const size_t loopEnd = nUnmarked;
for (size_t i=0;i<loopEnd;i++)
{
OTE* ote = pUnmarked[i];
const uint8_t oteFlags = ote->m_ubFlags;
Expand Down Expand Up @@ -435,8 +435,8 @@ void ObjectMemory::addVMRefs()

void ObjectMemory::checkPools()
{
const unsigned loopEnd = m_nOTSize;
for (unsigned i=OTBase;i<loopEnd;i++)
const size_t loopEnd = m_nOTSize;
for (size_t i=OTBase;i<loopEnd;i++)
{
OTE& ote = m_pOT[i];
if (!ote.isFree())
Expand Down Expand Up @@ -541,8 +541,8 @@ void ObjectMemory::addVMRefs()
int errors=0;
uint8_t* currentRefs = new uint8_t[m_nOTSize];
{
const unsigned loopEnd = m_nOTSize;
for (unsigned i=OTBase; i < loopEnd; i++)
const size_t loopEnd = m_nOTSize;
for (size_t i=OTBase; i < loopEnd; i++)
{
// Count and free bit should both be zero, or both non-zero
/*if (m_pOT[i].m_flags.m_free ^ (m_pOT[i].m_flags.m_count == 0))
Expand Down Expand Up @@ -586,8 +586,8 @@ void ObjectMemory::addVMRefs()
Interpreter::ReincrementVMReferences();

int refCountTooSmall = 0;
const unsigned loopEnd = m_nOTSize;
for (unsigned i=OTBase; i < loopEnd; i++)
const size_t loopEnd = m_nOTSize;
for (size_t i=OTBase; i < loopEnd; i++)
{
OTE* ote = &m_pOT[i];
if (currentRefs[i] < OTE::MAXCOUNT)
Expand Down
2 changes: 1 addition & 1 deletion Core/DolphinVM/Interprt.h
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ class Interpreter
static Oop* __fastcall primitiveSize(Oop* const sp, primargcount_t argCount);

// Object Indexing Primitives
static Oop* __fastcall primitiveBasicAt(Oop* const sp, const unsigned argCount);
static Oop* __fastcall primitiveBasicAt(Oop* const sp, const primargcount_t argCount);
static Oop* __fastcall primitiveBasicAtPut(Oop* const sp, primargcount_t argCount);
static Oop* __fastcall primitiveInstVarAt(Oop* const sp, primargcount_t argCount);
static Oop* __fastcall primitiveInstVarAtPut(Oop* const sp, primargcount_t argCount);
Expand Down
1 change: 1 addition & 0 deletions Core/DolphinVM/VMLib/VMLib.vcxitems
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
<ClInclude Include="$(MSBuildThisFileDirectory)..\DolphinSmalltalk.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\DolphinX.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\environ.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\ExternalBuf.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\FloatPrim.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\ImageFileResource.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\InterpRegisters.h" />
Expand Down
3 changes: 3 additions & 0 deletions Core/DolphinVM/VMLib/VMLib.vcxitems.filters
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,9 @@
<Filter>Primitives</Filter>
</ClInclude>
<ClInclude Include="$(MSBuildThisFileDirectory)ExternalBuf.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\ExternalBuf.h">
<Filter>FFI</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)..\Interprt.inl">
Expand Down
12 changes: 6 additions & 6 deletions Core/DolphinVM/alloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
ObjectMemory::FixedSizePool ObjectMemory::m_pools[MaxPools];
ObjectMemory::FixedSizePool::Link* ObjectMemory::FixedSizePool::m_pFreePages;
void** ObjectMemory::FixedSizePool::m_pAllocations;
unsigned ObjectMemory::FixedSizePool::m_nAllocations;
size_t ObjectMemory::FixedSizePool::m_nAllocations;

///////////////////////////////////////////////////////////////////////////////
// Public object allocation routines
Expand Down Expand Up @@ -746,8 +746,8 @@ VirtualOTE* ObjectMemory::newVirtualObject(BehaviorOTE* classPointer, MWORD init

// Fill space with nils for initial values
const Oop nil = Oop(Pointers.Nil);
const unsigned loopEnd = initialSize;
for (unsigned i = 0; i < loopEnd; i++)
const size_t loopEnd = initialSize;
for (size_t i = 0; i < loopEnd; i++)
pLocation->m_fields[i] = nil;

OTE* ote = ObjectMemory::allocateOop(static_cast<POBJECT>(pLocation));
Expand Down Expand Up @@ -859,7 +859,7 @@ void ObjectMemory::FixedSizePool::moreChunks()
memset(static_cast<uint8_t*>(pLast), 0xCD, m_nChunkSize);
#endif

const unsigned chunkSize = m_nChunkSize; // Loop invariant
const size_t chunkSize = m_nChunkSize; // Loop invariant
for (uint8_t* p = pStart; p < pLast; p += chunkSize)
reinterpret_cast<Link*>(p)->next = reinterpret_cast<Link*>(p + chunkSize);

Expand Down Expand Up @@ -1030,8 +1030,8 @@ inline POBJECT ObjectMemory::reallocChunk(POBJECT pChunk, MWORD newChunkSize)

bool ObjectMemory::FixedSizePool::isMyChunk(void* pChunk)
{
const unsigned loopEnd = m_nPages;
for (unsigned i=0;i<loopEnd;i++)
const size_t loopEnd = m_nPages;
for (size_t i=0;i<loopEnd;i++)
{
void* pPage = m_pages[i];
if (pChunk >= pPage && static_cast<uint8_t*>(pChunk) <= (static_cast<uint8_t*>(pPage)+dwPageSize))
Expand Down
16 changes: 8 additions & 8 deletions Core/DolphinVM/objmem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ extern "C" { HANDLE _crtheap; }

uint32_t ObjectMemory::m_nNextIdHash;

unsigned ObjectMemory::m_nOTSize;
unsigned ObjectMemory::m_nOTMax;
size_t ObjectMemory::m_nOTSize;
size_t ObjectMemory::m_nOTMax;

OTE* ObjectMemory::m_pOT; // The Object Table itself
OTE* ObjectMemory::m_pFreePointerList; // Head of list of free Object Table Entries
Expand Down Expand Up @@ -561,15 +561,15 @@ HRESULT ObjectMemory::allocateOT(unsigned reserve, unsigned commit)
ASSERT(sizeof(OTE) == 16);

m_nOTMax = _ROUND2(reserve, dwAllocationGranularity);
const unsigned reserveBytes = m_nOTMax * sizeof(OTE);
const size_t reserveBytes = m_nOTMax * sizeof(OTE);

OTE* pOTReserve = reinterpret_cast<OTE*>(::VirtualAlloc(NULL, reserveBytes, MEM_RESERVE, PAGE_NOACCESS));
if (!pOTReserve)
return ReportError(IDP_OTRESERVEFAIL, m_nOTMax);

// Can use _ROUND2 if dwPageSize is a power of 2
m_nOTSize = _ROUND2(commit, dwAllocationGranularity);
const unsigned commitBytes = m_nOTSize*sizeof(OTE);
const size_t commitBytes = m_nOTSize*sizeof(OTE);

OTE* pNewOT = reinterpret_cast<OTE*>(::VirtualAlloc(pOTReserve, commitBytes, MEM_COMMIT, PAGE_READWRITE));
if (!pNewOT)
Expand Down Expand Up @@ -626,8 +626,8 @@ void ObjectMemory::HeapCompact()

void ObjectMemory::FixedSizePool::Terminate()
{
const unsigned loopEnd = m_nAllocations;
for (unsigned i=0;i<loopEnd;i++)
const size_t loopEnd = m_nAllocations;
for (size_t i=0;i<loopEnd;i++)
VERIFY(::VirtualFree(m_pAllocations[i], 0, MEM_RELEASE));

free(m_pAllocations);
Expand Down Expand Up @@ -790,8 +790,8 @@ int ObjectMemory::gpFaultExceptionFilter(LPEXCEPTION_POINTERS pExInfo)
m_nSmallAllocated, m_nSmallFreed, m_nLargeAllocated, m_nLargeFreed);
m_nLargeAllocated = m_nLargeFreed = m_nSmallAllocated = m_nSmallFreed = 0;
#endif
const unsigned extraBytes = OTPagesAllocatedPerOverflow*dwPageSize;
const unsigned extraOTEs = extraBytes/sizeof(OTE);
const size_t extraBytes = OTPagesAllocatedPerOverflow*dwPageSize;
const size_t extraOTEs = extraBytes/sizeof(OTE);
// Note we can't allocate right up to the end, as we need at least one guard page, hence < rather than <=
if ((m_nOTSize + extraOTEs) < m_nOTMax)
{
Expand Down
8 changes: 4 additions & 4 deletions Core/DolphinVM/objmem.h
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ class ObjectMemory
int getPages() { return m_nPages; }
int getFree();
void** m_pages;
unsigned m_nPages;
size_t m_nPages;
#endif

int getSize() { return m_nChunkSize; }
Expand All @@ -367,15 +367,15 @@ class ObjectMemory
private:

Link* m_pFreeChunks;
unsigned m_nChunkSize;
size_t m_nChunkSize;

static Link* m_pFreePages;
static void** m_pAllocations;
public:
static unsigned m_nAllocations;
static size_t m_nAllocations;
};

static HRESULT __stdcall allocateOT(unsigned reserve, unsigned commit);
static HRESULT __stdcall allocateOT(size_t reserve, size_t commit);

// Answer the index of the last occuppied OT entry
static unsigned __stdcall lastOTEntry();
Expand Down
2 changes: 1 addition & 1 deletion Core/DolphinVM/primitiv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ Oop* __fastcall Interpreter::primitiveReplacePointers(Oop* const sp, primargcoun
return sp-4;
}

Oop* __fastcall Interpreter::primitiveBasicAt(Oop* const sp, const unsigned argCount)
Oop* __fastcall Interpreter::primitiveBasicAt(Oop* const sp, const primargcount_t argCount)
{
Oop* newSp = sp - argCount;
OTE* oteReceiver = reinterpret_cast<OTE*>(*newSp);
Expand Down
2 changes: 1 addition & 1 deletion Core/DolphinVM/strgprim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ Oop* __fastcall Interpreter::primitiveStringNextIndexOfFromTo(Oop* const sp, pri
}
}

Oop* __fastcall Interpreter::primitiveStringAt(Oop* const sp, const unsigned argCount)
Oop* __fastcall Interpreter::primitiveStringAt(Oop* const sp, const primargcount_t argCount)
{
Oop* newSp = sp - argCount;
SmallInteger oopIndex = *(newSp + 1);
Expand Down

0 comments on commit 721e6ca

Please sign in to comment.