Skip to content

Commit

Permalink
Replace the MWORD type with appropriate sized int type (#871)
Browse files Browse the repository at this point in the history
Also replace most uses of unsigned and int with sized types.

Contributes to #535 and #531
  • Loading branch information
blairmcg committed Mar 16, 2020
1 parent 0b733d8 commit 7f1da4a
Show file tree
Hide file tree
Showing 65 changed files with 901 additions and 931 deletions.
20 changes: 10 additions & 10 deletions Core/DolphinVM/CrashDump.cpp
Expand Up @@ -13,9 +13,9 @@
#include "VMExcept.h"
#include "RegKey.h"

static const size_t DefaultStackDepth = 300;
static const size_t DefaultWalkbackDepth = static_cast<size_t>(-1);
static const int MAXDUMPPARMCHARS = 40;
constexpr size_t DefaultStackDepth = 300;
constexpr size_t DefaultWalkbackDepth = static_cast<size_t>(-1);
constexpr int MAXDUMPPARMCHARS = 40;
extern wchar_t achImagePath[];

// Warning about SEH and destructable objects
Expand Down Expand Up @@ -58,17 +58,17 @@ void CrashDump(EXCEPTION_POINTERS *pExceptionInfo, wostream* pStream, size_t nSt
pStream = &TRACESTREAM;

*pStream << std::endl;
for (int i=0;i<80;i++)
for (auto i=0;i<80;i++)
*pStream << L'*';

EXCEPTION_RECORD* pExRec = pExceptionInfo->ExceptionRecord;
DWORD exceptionCode = pExRec->ExceptionCode;

*pStream << std::endl;
for (int i=0;i<26;i++)
for (auto i=0;i<26;i++)
*pStream << L'*';
*pStream<< L" Dolphin Crash Dump Report ";
for (int i=0;i<27;i++)
for (auto i=0;i<27;i++)
*pStream << L'*';

wchar_t szModule[_MAX_PATH+1];
Expand Down Expand Up @@ -101,7 +101,7 @@ void CrashDump(EXCEPTION_POINTERS *pExceptionInfo, wostream* pStream, size_t nSt
wostream::char_type cFill = pStream->fill(L'0');
pStream->setf(ios::uppercase);
*pStream << std::hex;
for (unsigned i=0;i<NumParms;i++)
for (auto i=0u;i<NumParms;i++)
{
uintptr_t parm = pExRec->ExceptionInformation[i];
*pStream << setw(sizeof(uintptr_t)<<1) << parm<< L" ";
Expand Down Expand Up @@ -228,7 +228,7 @@ void CrashDump(EXCEPTION_POINTERS *pExceptionInfo, const wchar_t* achImagePath)
{
wchar_t achLogPath[_MAX_PATH+1];
achLogPath[0] = 0;
unsigned long size = _MAX_PATH;
ULONG size = _MAX_PATH;
rkDump.QueryStringValue(L"", achLogPath, &size);
pStream = OpenLogStream(achLogPath, achImagePath, fStream);

Expand Down Expand Up @@ -266,10 +266,10 @@ void __stdcall Dump2(const wchar_t* szMsg, wostream* pStream, int nStackDepth, i
pStream = &TRACESTREAM;

*pStream << std::endl;
for (int i=0;i<26;i++)
for (auto i=0;i<26;i++)
*pStream << L'*';
*pStream<< L" Dolphin Virtual Machine Dump Report ";
for (int i=0;i<27;i++)
for (auto i=0;i<27;i++)
*pStream << L'*';

// Dump the time and message
Expand Down
18 changes: 9 additions & 9 deletions Core/DolphinVM/ExternalBuf.cpp
Expand Up @@ -23,7 +23,7 @@ Oop * __fastcall Interpreter::primitiveAddressOf(Oop * const sp, primargcount_t
Oop * __fastcall Interpreter::primitiveBytesIsNull(Oop * const sp, primargcount_t argCount)
{
AddressOTE* oteBytes = reinterpret_cast<AddressOTE*>(*sp);
MWORD size = oteBytes->bytesSize();
size_t size = oteBytes->bytesSize();
if (size == sizeof(uintptr_t))
{
*sp = reinterpret_cast<Oop>(oteBytes->m_location->m_pointer == nullptr ? Pointers.True : Pointers.False);
Expand Down Expand Up @@ -87,9 +87,9 @@ Oop * __fastcall Interpreter::primitiveUint32AtPut(Oop * const sp, primargcount_

if (ObjectMemoryIsIntegerObject(oopOffset))
{
const int size = oteReceiver->bytesSizeForUpdate();
const ptrdiff_t size = oteReceiver->bytesSizeForUpdate();
SmallInteger offset = ObjectMemoryIntegerValueOf(oopOffset);
if (offset >= 0 && static_cast<int>(offset + sizeof(uint32_t)) <= size)
if (offset >= 0 && static_cast<ptrdiff_t>(offset + sizeof(uint32_t)) <= size)
{
// Store into byte object
Oop oopValue = *sp;
Expand All @@ -109,7 +109,7 @@ Oop * __fastcall Interpreter::primitiveUint32AtPut(Oop * const sp, primargcount_
uint32_t* valueFields = oteValue->m_location->m_fields;
if (oteValue->isBytes())
{
MWORD argSize = oteValue->bytesSize();
size_t argSize = oteValue->bytesSize();

// The primitive has traditionally been lenient and accepts any 4 byte object, or any 8 byte object
// where the top 32-bits are zero. This is to allow positive argeIntegers in the interval [0x7FFFFFFF, 0xFFFFFFFF]
Expand Down Expand Up @@ -167,7 +167,7 @@ Oop * __fastcall Interpreter::primitiveIndirectUint32AtPut(Oop * const sp, prima
uint32_t* valueFields = oteValue->m_location->m_fields;
if (oteValue->isBytes())
{
MWORD argSize = oteValue->bytesSize();
size_t argSize = oteValue->bytesSize();

// The primitive has traditionally been lenient and accepts any 4 byte object, or any 8 byte object
// where the top 32-bits are zero. This is to allow positive argeIntegers in the interval [0x7FFFFFFF, 0xFFFFFFFF]
Expand Down Expand Up @@ -197,9 +197,9 @@ Oop * __fastcall Interpreter::primitiveInt32AtPut(Oop * const sp, primargcount_t

if (ObjectMemoryIsIntegerObject(oopOffset))
{
const int size = oteReceiver->bytesSizeForUpdate();
const ptrdiff_t size = oteReceiver->bytesSizeForUpdate();
SmallInteger offset = ObjectMemoryIntegerValueOf(oopOffset);
if (offset >= 0 && static_cast<int>(offset + sizeof(int32_t)) <= size)
if (offset >= 0 && static_cast<ptrdiff_t>(offset + sizeof(int32_t)) <= size)
{
// Store into byte object
Oop oopValue = *sp;
Expand All @@ -219,7 +219,7 @@ Oop * __fastcall Interpreter::primitiveInt32AtPut(Oop * const sp, primargcount_t
int32_t* pValue = reinterpret_cast<int32_t*>(oteValue->m_location->m_fields);
if (oteValue->isBytes())
{
MWORD argSize = oteValue->bytesSize();
size_t argSize = oteValue->bytesSize();

// The primitive has traditionally been lenient and accepts any 4 byte object
if (argSize == sizeof(int32_t))
Expand Down Expand Up @@ -275,7 +275,7 @@ Oop * __fastcall Interpreter::primitiveIndirectInt32AtPut(Oop * const sp, primar
int32_t* pValue = reinterpret_cast<int32_t*>(oteValue->m_location->m_fields);
if (oteValue->isBytes())
{
MWORD argSize = oteValue->bytesSize();
size_t argSize = oteValue->bytesSize();

// The primitive has traditionally been lenient and accepts any 4 byte object
if (argSize == sizeof(int32_t))
Expand Down
18 changes: 9 additions & 9 deletions Core/DolphinVM/ExternalBuf.h
Expand Up @@ -98,9 +98,9 @@ template <typename T, typename Store> Oop* __fastcall Interpreter::primitiveInte
SmallInteger offset = ObjectMemoryIntegerValueOf(oopOffset);

BytesOTE* oteReceiver = reinterpret_cast<BytesOTE*>(*(sp - 1));
const int size = oteReceiver->bytesSize();
const size_t size = oteReceiver->bytesSize();

if (offset >= 0 && static_cast<int>(offset + sizeof(T)) <= size)
if (offset >= 0 && static_cast<size_t>(offset) + sizeof(T) <= size)
{
T value = *reinterpret_cast<T*>(oteReceiver->m_location->m_fields + offset);
Store()(sp - 1, value);
Expand All @@ -125,9 +125,9 @@ template <typename T, SmallInteger MinVal, SmallInteger MaxVal> Oop* __fastcall

if (ObjectMemoryIsIntegerObject(oopOffset))
{
const int size = oteReceiver->bytesSizeForUpdate();
const ptrdiff_t size = oteReceiver->bytesSizeForUpdate();
SmallInteger offset = ObjectMemoryIntegerValueOf(oopOffset);
if (offset >= 0 && static_cast<int>(offset + sizeof(T)) <= size)
if (offset >= 0 && offset + static_cast<ptrdiff_t>(sizeof(T)) <= size)
{
// Store into byte object
Oop oopValue = *sp;
Expand Down Expand Up @@ -172,7 +172,7 @@ template <typename T, SmallInteger MinVal, SmallInteger MaxVal> Oop* __fastcall

if (ObjectMemoryIsIntegerObject(oopOffset))
{
const int size = oteReceiver->bytesSizeForUpdate();
const ptrdiff_t size = oteReceiver->bytesSizeForUpdate();
SmallInteger offset = ObjectMemoryIntegerValueOf(oopOffset);
// Store into byte object
Oop oopValue = *sp;
Expand Down Expand Up @@ -240,7 +240,7 @@ template <typename T> Oop* __fastcall Interpreter::primitiveFloatAtOffsetPut(Oop
fValue = oteValue->m_location->m_fValue;
}

SmallUinteger offset = ObjectMemoryIntegerValueOf(integerPointer);
SmallInteger offset = ObjectMemoryIntegerValueOf(integerPointer);

OTE* receiver = reinterpret_cast<OTE*>(*(sp - 2));
ASSERT(!ObjectMemoryIsIntegerObject(receiver));
Expand All @@ -261,8 +261,8 @@ template <typename T> Oop* __fastcall Interpreter::primitiveFloatAtOffsetPut(Oop
BytesOTE* oteBytes = reinterpret_cast<BytesOTE*>(receiver);

// We can check that the offset is in bounds
int size = oteBytes->bytesSizeForUpdate();
if (static_cast<int>(offset) >= 0 && static_cast<int>(offset + sizeof(T)) <= size)
ptrdiff_t size = oteBytes->bytesSizeForUpdate();
if (offset >= 0 && offset + static_cast<ptrdiff_t>(sizeof(T)) <= size)
{
T* pBuf = reinterpret_cast<T*>(oteBytes->m_location->m_fields + offset);
*pBuf = static_cast<T>(fValue);
Expand Down Expand Up @@ -303,7 +303,7 @@ template <typename T> Oop* __fastcall Interpreter::primitiveFloatAtOffset(Oop* c
BytesOTE* oteBytes = reinterpret_cast<BytesOTE*>(receiver);

// We can check that the offset is in bounds
if (offset >= 0 && offset + sizeof(T) <= oteBytes->bytesSize())
if (offset >= 0 && static_cast<size_t>(offset) + sizeof(T) <= oteBytes->bytesSize())
{
pValue = reinterpret_cast<T*>(oteBytes->m_location->m_fields + offset);
}
Expand Down
2 changes: 1 addition & 1 deletion Core/DolphinVM/ExternalCall.asm
Expand Up @@ -48,7 +48,7 @@ extern NewUnsigned64:near32
REQUESTCOMPLETION EQU ?OnCallReturned@OverlappedCall@@AAEXXZ
extern REQUESTCOMPLETION:near32

CharacterGetCodePoint EQU ?getCodePoint@Character@ST@@QBEIXZ
CharacterGetCodePoint EQU ?getCodePoint@Character@ST@@QBE_UXZ
extern CharacterGetCodePoint:near32

; We need to test the structure type specially
Expand Down
2 changes: 1 addition & 1 deletion Core/DolphinVM/FloatPrim.h
Expand Up @@ -24,7 +24,7 @@ template <typename Op> static Oop* __fastcall Interpreter::primitiveFloatTruncat
}
else
{
int intVal = static_cast<int>(fValue);
auto intVal = static_cast<SmallInteger>(fValue);
*sp = ObjectMemoryIntegerObjectOf(intVal);
return sp;
}
Expand Down
58 changes: 29 additions & 29 deletions Core/DolphinVM/GC.cpp
Expand Up @@ -82,9 +82,9 @@ void ObjectMemory::markObjectsAccessibleFrom(OTE* ote)
if ((oteClass->m_ubFlags ^ curMark) & OTEFlags::MarkMask) // Already accessible from roots of world?
markObjectsAccessibleFrom(reinterpret_cast<POTE>(oteClass));

const MWORD lastPointer = lastStrongPointerOf(ote);
const size_t lastPointer = lastStrongPointerOf(ote);
Oop* pFields = reinterpret_cast<Oop*>(ote->m_location);
for (MWORD i = ObjectHeaderSize; i < lastPointer; i++)
for (auto i = ObjectHeaderSize; i < lastPointer; i++)
{
// This will get nicely optimised by the Compiler
Oop fieldPointer = pFields[i];
Expand All @@ -107,7 +107,7 @@ OTEFlags ObjectMemory::nextMark()
OTEFlags oldMark = m_spaceOTEBits[OTEFlags::NormalSpace];
// Toggle the "visited" mark - all objects will then have previous mark
BOOL newMark = oldMark.m_mark ? FALSE : TRUE;
for (unsigned i=0;i<OTEFlags::NumSpaces;i++)
for (auto i=0u;i<OTEFlags::NumSpaces;i++)
m_spaceOTEBits[i].m_mark = newMark;
return oldMark;
}
Expand Down Expand Up @@ -209,7 +209,7 @@ void ObjectMemory::reclaimInaccessibleObjects(uintptr_t gcFlags)
// Another scan to nil out weak references. This has to be a separate scan from the finalization
// candidate scan so that we don't end up nilling out weak references to objects that are accessible
// from finalizable objects
unsigned queuedForBereavement=0;
size_t queuedForBereavement=0;
if (WeaknessMask != 0)
{
for (OTE* ote = m_pOT + OTBase; ote < pEnd; ote++)
Expand All @@ -222,11 +222,11 @@ void ObjectMemory::reclaimInaccessibleObjects(uintptr_t gcFlags)
{
SmallInteger losses = 0;
PointersOTE* otePointers = reinterpret_cast<PointersOTE*>(ote);
const MWORD size = otePointers->pointersSize();
const size_t size = otePointers->pointersSize();
VariantObject* weakObj = otePointers->m_location;
const Behavior* weakObjClass = ote->m_oteClass->m_location;
const MWORD fixedFields = weakObjClass->fixedFields();
for (MWORD j = fixedFields; j < size; j++)
const auto fixedFields = weakObjClass->fixedFields();
for (size_t j = fixedFields; j < size; j++)
{
Oop fieldPointer = weakObj->m_fields[j];
if (!ObjectMemoryIsIntegerObject(fieldPointer))
Expand Down Expand Up @@ -290,10 +290,10 @@ void ObjectMemory::reclaimInaccessibleObjects(uintptr_t gcFlags)

// Now sweep through the unmarked objects, and finalize/deallocate any objects which are STILL
// unmarked
unsigned deletions=0;
unsigned queuedForFinalize=0;
const size_t loopEnd = nUnmarked;
for (size_t i=0;i<loopEnd;i++)
size_t deletions=0;
size_t queuedForFinalize=0;
const auto loopEnd = nUnmarked;
for (auto i=0u;i<loopEnd;i++)
{
OTE* ote = pUnmarked[i];
const uint8_t oteFlags = ote->m_ubFlags;
Expand Down Expand Up @@ -340,9 +340,9 @@ void ObjectMemory::reclaimInaccessibleObjects(uintptr_t gcFlags)
if (ote->isPointers())
{
PointersOTE* otePointers = reinterpret_cast<PointersOTE*>(ote);
const MWORD lastPointer = otePointers->pointersSize();
const size_t lastPointer = otePointers->pointersSize();
VariantObject* varObj = otePointers->m_location;
for (unsigned f = 0; f < lastPointer; f++)
for (auto f = 0u; f < lastPointer; f++)
{
Oop fieldPointer = varObj->m_fields[f];
if (!isIntegerObject(fieldPointer))
Expand Down Expand Up @@ -422,8 +422,8 @@ void ObjectMemory::addVMRefs()
// Deliberately max out ref. counts of VM ref'd objects so that ref. counting ops
// not needed
Array* globalPointers = (Array*)&_Pointers;
const unsigned loopEnd = NumPointers;
for (unsigned i=0;i<loopEnd;i++)
const auto loopEnd = NumPointers;
for (auto i=0u;i<loopEnd;i++)
{
Oop obj = globalPointers->m_elements[i];
if (!isIntegerObject(obj))
Expand All @@ -444,7 +444,7 @@ void ObjectMemory::addVMRefs()
OTEFlags::Spaces space = ote.heapSpace();
if (space == OTEFlags::PoolSpace)
{
unsigned size = ote.sizeOf();
size_t size = ote.sizeOf();
if (size > MaxSizeOfPoolObject)
{
if (size <= MaxSmallObjectSize)
Expand All @@ -463,14 +463,14 @@ void ObjectMemory::addVMRefs()
}
}
}
for (int j=0;j<NumPools;j++)
for (auto j=0;j<NumPools;j++)
HARDASSERT(m_pools[j].isValid());
}

int ObjectMemory::CountFreeOTEs()
size_t ObjectMemory::CountFreeOTEs()
{
OTE* p = m_pFreePointerList;
int count = 0;
size_t count = 0;
OTE* offEnd= m_pOT + m_nOTSize;
while (p < offEnd)
{
Expand All @@ -482,7 +482,7 @@ void ObjectMemory::addVMRefs()

void ObjectMemory::checkStackRefs(Oop* const sp)
{
int zeroCountNotInZct = 0;
size_t zeroCountNotInZct = 0;
Process* pProcess = Interpreter::m_registers.m_pActiveProcess;
for (Oop* pOop = pProcess->m_stack;pOop <= sp;pOop++)
{
Expand Down Expand Up @@ -538,7 +538,7 @@ void ObjectMemory::addVMRefs()
Interpreter::IncStackRefs(sp);
}

int errors=0;
auto errors=0;
uint8_t* currentRefs = new uint8_t[m_nOTSize];
{
const size_t loopEnd = m_nOTSize;
Expand All @@ -564,7 +564,7 @@ void ObjectMemory::addVMRefs()

// Recalc the references
const OTE* pEnd = m_pOT+m_nOTSize;
int nFree = 0;
size_t nFree = 0;
for (OTE* ote=m_pOT; ote < pEnd; ote++)
{
if (!ote->isFree())
Expand All @@ -574,7 +574,7 @@ void ObjectMemory::addVMRefs()
}

POTE poteFree = m_pFreePointerList;
int cFreeList = 0;
size_t cFreeList = 0;
while (poteFree < pEnd)
{
++cFreeList;
Expand All @@ -585,7 +585,7 @@ void ObjectMemory::addVMRefs()

Interpreter::ReincrementVMReferences();

int refCountTooSmall = 0;
auto refCountTooSmall = 0;
const size_t loopEnd = m_nOTSize;
for (size_t i=OTBase; i < loopEnd; i++)
{
Expand Down Expand Up @@ -617,7 +617,7 @@ void ObjectMemory::addVMRefs()
TRACESTREAM<< L" Referenced From:" << std::endl;
ArrayOTE* oteRefs = ObjectMemory::referencesTo(reinterpret_cast<Oop>(ote), true);
Array* refs = oteRefs->m_location;
for (unsigned i=0;i<oteRefs->pointersSize();i++)
for (auto i=0u;i<oteRefs->pointersSize();i++)
TRACESTREAM<< L" " << reinterpret_cast<OTE*>(refs->m_elements[i]) << std::endl;
deallocate(reinterpret_cast<OTE*>(oteRefs));
}
Expand Down Expand Up @@ -653,8 +653,8 @@ void ObjectMemory::addVMRefs()
if (ote->isPointers())
{
VariantObject* obj = reinterpret_cast<PointersOTE*>(ote)->m_location;
int size = ote->pointersSize();
for (int i = 0; i < size; i++)
size_t size = ote->pointersSize();
for (size_t i = 0; i < size; i++)
{
HARDASSERT(isValidOop(obj->m_fields[i]));
}
Expand Down Expand Up @@ -697,8 +697,8 @@ void ObjectMemory::addVMRefs()
{
PointersOTE* otePointers = reinterpret_cast<PointersOTE*>(ote);
VariantObject* varObj = otePointers->m_location;
const MWORD lastPointer = otePointers->pointersSize();
for (MWORD i = 0; i < lastPointer; i++)
const size_t lastPointer = otePointers->pointersSize();
for (size_t i = 0; i < lastPointer; i++)
{
Oop fieldPointer = varObj->m_fields[i];
// The reason we don't use an ASSERT here is that, ASSERT throws
Expand Down

0 comments on commit 7f1da4a

Please sign in to comment.