arm64 : fix intptr_t size

This commit is contained in:
hymei
2022-06-05 01:12:32 +03:00
committed by nillerusr
parent 2690e6c85a
commit 4e4039d756
143 changed files with 1015 additions and 674 deletions
+4 -4
View File
@@ -28,7 +28,7 @@ class CUtlBuffer;
//-----------------------------------------------------------------------------
// Invalid command handle
//-----------------------------------------------------------------------------
typedef int CommandHandle_t;
typedef intp CommandHandle_t;
enum
{
COMMAND_BUFFER_INVALID_COMMAND_HANDLE = 0
@@ -100,11 +100,11 @@ private:
};
// Insert a command into the command queue at the appropriate time
void InsertCommandAtAppropriateTime( int hCommand );
void InsertCommandAtAppropriateTime( CommandHandle_t hCommand );
// Insert a command into the command queue
// Only happens if it's inserted while processing other commands
void InsertImmediateCommand( int hCommand );
void InsertImmediateCommand( CommandHandle_t hCommand );
// Insert a command into the command queue
bool InsertCommand( const char *pArgS, int nCommandSize, int nTick );
@@ -125,7 +125,7 @@ private:
int m_nCurrentTick;
int m_nLastTickToProcess;
int m_nWaitDelayTicks;
int m_hNextCommand;
CommandHandle_t m_hNextCommand;
int m_nMaxArgSBufferLength;
bool m_bIsProcessingCommands;
bool m_bWaitEnabled;
+11 -11
View File
@@ -115,7 +115,7 @@ public:
void SetName( const char *setName);
// gets the name as a unique int
int GetNameSymbol() const { return m_iKeyName; }
intp GetNameSymbol() const { return m_iKeyName; }
// File access. Set UsesEscapeSequences true, if resource file/buffer uses Escape Sequences (eg \n, \t)
void UsesEscapeSequences(bool state); // default false
@@ -132,7 +132,7 @@ public:
// Find a keyValue, create it if it is not found.
// Set bCreate to true to create the key if it doesn't already exist (which ensures a valid pointer will be returned)
KeyValues *FindKey(const char *keyName, bool bCreate = false);
KeyValues *FindKey(int keySymbol) const;
KeyValues *FindKey(intp keySymbol) const;
KeyValues *CreateNewKey(); // creates a new key, with an autogenerated name. name is guaranteed to be an integer, of value 1 higher than the highest other integer key name
void AddSubKey( KeyValues *pSubkey ); // Adds a subkey. Make sure the subkey isn't a child of some other keyvalues
void RemoveSubKey(KeyValues *subKey); // removes a subkey from the list, DOES NOT DELETE IT
@@ -311,7 +311,7 @@ private:
void FreeAllocatedValue();
void AllocateValueBlock(int size);
int m_iKeyName; // keyname is a symbol defined in KeyValuesSystem
intp m_iKeyName; // keyname is a symbol defined in KeyValuesSystem
// These are needed out of the union because the API returns string pointers
char *m_sValue;
@@ -338,22 +338,22 @@ private:
private:
// Statics to implement the optional growable string table
// Function pointers that will determine which mode we are in
static int (*s_pfGetSymbolForString)( const char *name, bool bCreate );
static const char *(*s_pfGetStringForSymbol)( int symbol );
static intp (*s_pfGetSymbolForString)( const char *name, bool bCreate );
static const char *(*s_pfGetStringForSymbol)( intp symbol );
static CKeyValuesGrowableStringTable *s_pGrowableStringTable;
public:
// Functions that invoke the default behavior
static int GetSymbolForStringClassic( const char *name, bool bCreate = true );
static const char *GetStringForSymbolClassic( int symbol );
static intp GetSymbolForStringClassic( const char *name, bool bCreate = true );
static const char *GetStringForSymbolClassic( intp symbol );
// Functions that use the growable string table
static int GetSymbolForStringGrowable( const char *name, bool bCreate = true );
static const char *GetStringForSymbolGrowable( int symbol );
static intp GetSymbolForStringGrowable( const char *name, bool bCreate = true );
static const char *GetStringForSymbolGrowable( intp symbol );
// Functions to get external access to whichever of the above functions we're going to call.
static int CallGetSymbolForString( const char *name, bool bCreate = true ) { return s_pfGetSymbolForString( name, bCreate ); }
static const char *CallGetStringForSymbol( int symbol ) { return s_pfGetStringForSymbol( symbol ); }
static intp CallGetSymbolForString( const char *name, bool bCreate = true ) { return s_pfGetSymbolForString( name, bCreate ); }
static const char *CallGetStringForSymbol( intp symbol ) { return s_pfGetStringForSymbol( symbol ); }
};
typedef KeyValues::AutoDelete KeyValuesAD;
+15 -15
View File
@@ -225,7 +225,7 @@ public:
void WriteByte(int val);
void WriteShort(int val);
void WriteWord(int val);
void WriteLong(long val);
void WriteLong(int32 val);
void WriteLongLong(int64 val);
void WriteFloat(float val);
bool WriteBytes( const void *pBuf, int nBytes );
@@ -255,7 +255,7 @@ public:
public:
// The current buffer.
unsigned long* RESTRICT m_pData;
uint32* RESTRICT m_pData;
int m_nDataBytes;
int m_nDataBits;
@@ -342,7 +342,7 @@ BITBUF_INLINE void bf_write::WriteOneBitNoCheck(int nValue)
else
m_pData[m_iCurBit >> 5] &= ~(1u << (m_iCurBit & 31));
#else
extern unsigned long g_LittleBits[32];
extern uint32 g_LittleBits[32];
if(nValue)
m_pData[m_iCurBit >> 5] |= g_LittleBits[m_iCurBit & 31];
else
@@ -379,7 +379,7 @@ inline void bf_write::WriteOneBitAt( int iBit, int nValue )
else
m_pData[iBit >> 5] &= ~(1u << (iBit & 31));
#else
extern unsigned long g_LittleBits[32];
extern uint32 g_LittleBits[32];
if(nValue)
m_pData[iBit >> 5] |= g_LittleBits[iBit & 31];
else
@@ -393,7 +393,7 @@ BITBUF_INLINE void bf_write::WriteUBitLong( unsigned int curData, int numbits, b
// Make sure it doesn't overflow.
if ( bCheckRange && numbits < 32 )
{
if ( curData >= (unsigned long)(1 << numbits) )
if ( curData >= (uint32)(1 << numbits) )
{
CallErrorHandler( BITBUFERROR_VALUE_OUT_OF_RANGE, GetDebugName() );
}
@@ -414,8 +414,8 @@ BITBUF_INLINE void bf_write::WriteUBitLong( unsigned int curData, int numbits, b
m_iCurBit += numbits;
// Mask in a dword.
Assert( (iDWord*4 + sizeof(long)) <= (unsigned int)m_nDataBytes );
unsigned long * RESTRICT pOut = &m_pData[iDWord];
Assert( (iDWord*4 + sizeof(int32)) <= (unsigned int)m_nDataBytes );
uint32 * RESTRICT pOut = &m_pData[iDWord];
// Rotate data into dword alignment
curData = (curData << iCurBitMasked) | (curData >> (32 - iCurBitMasked));
@@ -427,8 +427,8 @@ BITBUF_INLINE void bf_write::WriteUBitLong( unsigned int curData, int numbits, b
// Only look beyond current word if necessary (avoid access violation)
int i = mask2 & 1;
unsigned long dword1 = LoadLittleDWord( pOut, 0 );
unsigned long dword2 = LoadLittleDWord( pOut, i );
uint32 dword1 = LoadLittleDWord( pOut, 0 );
uint32 dword2 = LoadLittleDWord( pOut, i );
// Drop bits into place
dword1 ^= ( mask1 & ( curData ^ dword1 ) );
@@ -467,7 +467,7 @@ BITBUF_INLINE void bf_write::WriteBitFloat(float val)
{
int32 intVal;
Assert(sizeof(long) == sizeof(float));
Assert(sizeof(int32) == sizeof(float));
Assert(sizeof(float) == 4);
Q_memcpy( &intVal, &val, sizeof(intVal));
@@ -603,7 +603,7 @@ public:
BITBUF_INLINE int ReadByte() { return ReadUBitLong(8); }
BITBUF_INLINE int ReadShort() { return (short)ReadUBitLong(16); }
BITBUF_INLINE int ReadWord() { return ReadUBitLong(16); }
BITBUF_INLINE long ReadLong() { return ReadUBitLong(32); }
BITBUF_INLINE int32 ReadLong() { return ReadUBitLong(32); }
int64 ReadLongLong();
float ReadFloat();
bool ReadBytes(void *pOut, int nBytes);
@@ -728,7 +728,7 @@ inline bool bf_read::CheckForOverflow(int nBits)
inline int bf_read::ReadOneBitNoCheck()
{
#if VALVE_LITTLE_ENDIAN
unsigned int value = ((unsigned long * RESTRICT)m_pData)[m_iCurBit >> 5] >> (m_iCurBit & 31);
unsigned int value = ((uint32 * RESTRICT)m_pData)[m_iCurBit >> 5] >> (m_iCurBit & 31);
#else
unsigned char value = m_pData[m_iCurBit >> 3] >> (m_iCurBit & 7);
#endif
@@ -787,12 +787,12 @@ BITBUF_INLINE unsigned int bf_read::ReadUBitLong( int numbits ) RESTRICT
#if __i386__
unsigned int bitmask = (2 << (numbits-1)) - 1;
#else
extern unsigned long g_ExtraMasks[33];
extern uint32 g_ExtraMasks[33];
unsigned int bitmask = g_ExtraMasks[numbits];
#endif
unsigned int dw1 = LoadLittleDWord( (unsigned long* RESTRICT)m_pData, iWordOffset1 ) >> iStartBit;
unsigned int dw2 = LoadLittleDWord( (unsigned long* RESTRICT)m_pData, iWordOffset2 ) << (32 - iStartBit);
unsigned int dw1 = LoadLittleDWord( (uint32* RESTRICT)m_pData, iWordOffset1 ) >> iStartBit;
unsigned int dw2 = LoadLittleDWord( (uint32* RESTRICT)m_pData, iWordOffset2 ) << (32 - iStartBit);
return (dw1 | dw2) & bitmask;
}
+1 -1
View File
@@ -251,7 +251,7 @@ private:
inline unsigned short CDataManagerBase::FromHandle( memhandle_t handle )
{
unsigned int fullWord = (unsigned int)handle;
uintp fullWord = (uintp)handle;
unsigned short serial = fullWord>>16;
unsigned short index = fullWord & 0xFFFF;
index--;
+2 -2
View File
@@ -193,8 +193,8 @@ public:
class CRefMT
{
public:
static int Increment( int *p) { return ThreadInterlockedIncrement( (long *)p ); }
static int Decrement( int *p) { return ThreadInterlockedDecrement( (long *)p ); }
static int Increment( int *p) { return ThreadInterlockedIncrement( (int32 *)p ); }
static int Decrement( int *p) { return ThreadInterlockedDecrement( (int32 *)p ); }
};
class CRefST
+27
View File
@@ -189,6 +189,7 @@ public:
unsigned int GetUnsignedInt( );
float GetFloat( );
double GetDouble( );
void * GetPtr();
template <size_t maxLenInChars> void GetString( char( &pString )[maxLenInChars] )
{
GetStringInternal( pString, maxLenInChars );
@@ -278,6 +279,7 @@ public:
void PutUnsignedInt( unsigned int u );
void PutFloat( float f );
void PutDouble( double d );
void PutPtr( void * ); // Writes the pointer, not the pointed to
void PutString( const char* pString );
void Put( const void* pMem, int size );
@@ -757,6 +759,18 @@ inline float CUtlBuffer::GetFloat( )
return f;
}
inline void *CUtlBuffer::GetPtr( )
{
void *p;
// LEGACY WARNING: in text mode, PutPtr writes 32 bit pointers in hex, while GetPtr reads 32 or 64 bit pointers in decimal
#ifndef PLATFORM_64BITS
p = ( void* )GetUnsignedInt();
#else
p = ( void* )GetInt64();
#endif
return p;
}
inline double CUtlBuffer::GetDouble( )
{
double d;
@@ -986,6 +1000,19 @@ inline void CUtlBuffer::PutDouble( double d )
PutType( d, "%f" );
}
inline void CUtlBuffer::PutPtr( void *p )
{
// LEGACY WARNING: in text mode, PutPtr writes 32 bit pointers in hex, while GetPtr reads 32 or 64 bit pointers in decimal
if (!IsText())
{
PutTypeBin( p );
}
else
{
Printf( "0x%p", p );
}
}
//-----------------------------------------------------------------------------
// Am I a text buffer?
+21 -7
View File
@@ -59,13 +59,21 @@ public:
private:
struct HandleType_t
{
// MoeMod : use union to fix strict alias bug
HandleType_t( unsigned int i, unsigned int s ) : nIndex( i ), nSerial( s )
{
Assert( i < ( 1 << HandleBits ) );
Assert( s < ( 1 << ( 31 - HandleBits ) ) );
}
unsigned int nIndex : HandleBits;
unsigned int nSerial : 31 - HandleBits;
HandleType_t( UtlHandle_t handle ) : handle(handle) {}
union {
UtlHandle_t handle;
struct {
unsigned int nIndex : HandleBits;
unsigned int nSerial : 31 - HandleBits;
};
};
};
struct EntryType_t
@@ -186,7 +194,7 @@ bool CUtlHandleTable<T, HandleBits>::IsHandleValid( UtlHandle_t handle ) const
return false;
unsigned int nIndex = GetListIndex( handle );
AssertOnce( nIndex < ( unsigned int )m_list.Count() );
//AssertOnce( nIndex < ( unsigned int )m_list.Count() );
if ( nIndex >= ( unsigned int )m_list.Count() )
return false;
@@ -241,20 +249,26 @@ int CUtlHandleTable<T, HandleBits>::GetIndexFromHandle( UtlHandle_t h ) const
template< class T, int HandleBits >
unsigned int CUtlHandleTable<T, HandleBits>::GetSerialNumber( UtlHandle_t handle )
{
return ( ( HandleType_t* )&handle )->nSerial;
//return ( ( HandleType_t* )&handle )->nSerial;
//return (handle >> HandleBits) & ((1 << (32 - HandleBits)) - 1);
return HandleType_t(handle).nSerial;
}
template< class T, int HandleBits >
unsigned int CUtlHandleTable<T, HandleBits>::GetListIndex( UtlHandle_t handle )
{
return ( ( HandleType_t* )&handle )->nIndex;
//return ( ( HandleType_t* )&handle )->nIndex;
//return handle & ((1 << HandleBits) - 1);
return HandleType_t(handle).nIndex;
}
template< class T, int HandleBits >
UtlHandle_t CUtlHandleTable<T, HandleBits>::CreateHandle( unsigned int nSerial, unsigned int nIndex )
{
HandleType_t h( nIndex, nSerial );
return *( UtlHandle_t* )&h;
//return *( UtlHandle_t* )&h;
//return (nIndex & ((1 << HandleBits) - 1)) | (nSerial << HandleBits);
return h.handle;
}
@@ -268,7 +282,7 @@ const typename CUtlHandleTable<T, HandleBits>::EntryType_t *CUtlHandleTable<T, H
return NULL;
unsigned int nIndex = GetListIndex( handle );
Assert( nIndex < ( unsigned int )m_list.Count() );
//Assert( nIndex < ( unsigned int )m_list.Count() );
if ( nIndex >= ( unsigned int )m_list.Count() )
return NULL;
+7 -7
View File
@@ -461,7 +461,7 @@ inline void CUtlHash<Data, C, K>::Log( const char *filename )
// Number of buckets must be a power of 2.
// Key must be 32-bits (unsigned int).
//
typedef int UtlHashFastHandle_t;
typedef intp UtlHashFastHandle_t;
#define UTLHASH_POOL_SCALAR 2
@@ -617,7 +617,7 @@ template<class Data, class HashFuncs> inline UtlHashFastHandle_t CUtlHashFast<Da
template<class Data, class HashFuncs> inline UtlHashFastHandle_t CUtlHashFast<Data,HashFuncs>::FastInsert( unsigned int uiKey, const Data &data )
{
// Get a new element from the pool.
int iHashData = m_aDataPool.Alloc( true );
intp iHashData = m_aDataPool.Alloc( true );
HashFastData_t *pHashData = &m_aDataPool[iHashData];
if ( !pHashData )
return InvalidHandle();
@@ -671,7 +671,7 @@ template<class Data, class HashFuncs> inline UtlHashFastHandle_t CUtlHashFast<Da
// hash the "key" - get the correct hash table "bucket"
int iBucket = HashFuncs::Hash( uiKey, m_uiBucketMask );
for ( int iElement = m_aBuckets[iBucket]; iElement != m_aDataPool.InvalidIndex(); iElement = m_aDataPool.Next( iElement ) )
for ( intp iElement = m_aBuckets[iBucket]; iElement != m_aDataPool.InvalidIndex(); iElement = m_aDataPool.Next( iElement ) )
{
if ( m_aDataPool[iElement].m_uiKey == uiKey )
return iElement;
@@ -719,7 +719,7 @@ template<class Data, class HashFuncs> inline Data const &CUtlHashFast<Data,HashF
// Number of buckets must be a power of 2.
// Key must be 32-bits (unsigned int).
//
typedef int UtlHashFixedHandle_t;
typedef intp UtlHashFixedHandle_t;
template <int NUM_BUCKETS>
class CUtlHashFixedGenericHash
@@ -753,7 +753,7 @@ public:
void Purge( void );
// Invalid handle.
static UtlHashFixedHandle_t InvalidHandle( void ) { return ( UtlHashFixedHandle_t )~0; }
static UtlHashFixedHandle_t InvalidHandle( void ) { return ( UtlHashFixedHandle_t )-1; }
// Size.
int Count( void );
@@ -858,7 +858,7 @@ template<class Data, int NUM_BUCKETS, class HashFuncs> inline UtlHashFixedHandle
pHashData->m_Data = data;
m_nElements++;
return (UtlHashFixedHandle_t)pHashData;
return (UtlHashFixedHandle_t)(intp)pHashData;
}
//-----------------------------------------------------------------------------
@@ -895,7 +895,7 @@ template<class Data, int NUM_BUCKETS, class HashFuncs> inline UtlHashFixedHandle
for ( UtlPtrLinkedListIndex_t iElement = bucket.Head(); iElement != bucket.InvalidIndex(); iElement = bucket.Next( iElement ) )
{
if ( bucket[iElement].m_uiKey == uiKey )
return (UtlHashFixedHandle_t)iElement;
return (UtlHashFixedHandle_t)(intp)iElement;
}
return InvalidHandle();
+8 -7
View File
@@ -389,15 +389,16 @@ private:
// this is kind of ugly, but until C++ gets templatized typedefs in C++0x, it's our only choice
// MoeMod : CUtlFixedMemory uses intp as index type
template < class T >
class CUtlFixedLinkedList : public CUtlLinkedList< T, int, true, int, CUtlFixedMemory< UtlLinkedListElem_t< T, int > > >
class CUtlFixedLinkedList : public CUtlLinkedList< T, intp, true, intp, CUtlFixedMemory< UtlLinkedListElem_t< T, intp > > >
{
public:
CUtlFixedLinkedList( int growSize = 0, int initSize = 0 )
: CUtlLinkedList< T, int, true, int, CUtlFixedMemory< UtlLinkedListElem_t< T, int > > >( growSize, initSize ) {}
: CUtlLinkedList< T, intp, true, intp, CUtlFixedMemory< UtlLinkedListElem_t< T, intp > > >( growSize, initSize ) {}
typedef CUtlLinkedList< T, int, true, int, CUtlFixedMemory< UtlLinkedListElem_t< T, int > > > BaseClass;
bool IsValidIndex( int i ) const
typedef CUtlLinkedList< T, intp, true, intp, CUtlFixedMemory< UtlLinkedListElem_t< T, intp > > > BaseClass;
bool IsValidIndex( intp i ) const
{
if ( !BaseClass::Memory().IsIdxValid( i ) )
return false;
@@ -414,7 +415,7 @@ public:
}
private:
int MaxElementIndex() const { Assert( 0 ); return BaseClass::InvalidIndex(); } // fixedmemory containers don't support iteration from 0..maxelements-1
intp MaxElementIndex() const { Assert( 0 ); return BaseClass::InvalidIndex(); } // fixedmemory containers don't support iteration from 0..maxelements-1
void ResetDbgInfo() {}
};
@@ -439,7 +440,7 @@ CUtlLinkedList<T,S,ML,I,M>::CUtlLinkedList( int growSize, int initSize ) :
m_Memory( growSize, initSize ), m_LastAlloc( m_Memory.InvalidIterator() )
{
// Prevent signed non-int datatypes
COMPILE_TIME_ASSERT( sizeof(S) == 4 || ( ( (S)-1 ) > 0 ) );
COMPILE_TIME_ASSERT( sizeof(S) == sizeof(M::InvalidIndex()) || ( ( (S)-1 ) > 0 ) );
ConstructList();
ResetDbgInfo();
}
@@ -797,7 +798,7 @@ inline I CUtlLinkedList<T,S,ML,I,M>::AddToHead( )
template <class T, class S, bool ML, class I, class M>
inline I CUtlLinkedList<T,S,ML,I,M>::AddToTail( )
{
return InsertBefore( InvalidIndex() );
return InsertBefore( InvalidIndex() );
}