1
0

Added additional macros to support the MSVC size_t format and changed all formats to use the macros

This commit is contained in:
Tycho 2014-03-12 10:34:50 -07:00
parent d904e89712
commit 862e219443
13 changed files with 33 additions and 29 deletions

View File

@ -340,7 +340,7 @@ void cCraftingRecipes::LoadRecipes(void)
} }
AddRecipeLine(LineNum, Recipe); AddRecipeLine(LineNum, Recipe);
} // for itr - Split[] } // for itr - Split[]
LOG("Loaded %zu crafting recipes", m_Recipes.size()); LOG("Loaded " SIZE_T_FMT " crafting recipes", m_Recipes.size());
} }

View File

@ -175,7 +175,7 @@ void cFurnaceRecipe::ReloadRecipes(void)
{ {
LOGERROR("ERROR: FurnaceRecipe, syntax error" ); LOGERROR("ERROR: FurnaceRecipe, syntax error" );
} }
LOG("Loaded %zu furnace recipes and %zu fuels", m_pState->Recipes.size(), m_pState->Fuel.size()); LOG("Loaded " SIZE_T_FMT " furnace recipes and " SIZE_T_FMT " fuels", m_pState->Recipes.size(), m_pState->Fuel.size());
} }

View File

@ -116,7 +116,7 @@ void cChunkGenerator::QueueGenerateChunk(int a_ChunkX, int a_ChunkY, int a_Chunk
// Add to queue, issue a warning if too many: // Add to queue, issue a warning if too many:
if (m_Queue.size() >= QUEUE_WARNING_LIMIT) if (m_Queue.size() >= QUEUE_WARNING_LIMIT)
{ {
LOGWARN("WARNING: Adding chunk [%i, %i] to generation queue; Queue is too big! (%zu)", a_ChunkX, a_ChunkZ, m_Queue.size()); LOGWARN("WARNING: Adding chunk [%i, %i] to generation queue; Queue is too big! (" SIZE_T_FMT ")", a_ChunkX, a_ChunkZ, m_Queue.size());
} }
m_Queue.push_back(cChunkCoords(a_ChunkX, a_ChunkY, a_ChunkZ)); m_Queue.push_back(cChunkCoords(a_ChunkX, a_ChunkY, a_ChunkZ));
} }

View File

@ -43,6 +43,8 @@
// MSVC has its own custom version of zu format // MSVC has its own custom version of zu format
#define SIZE_T_FMT "%Iu" #define SIZE_T_FMT "%Iu"
#define SIZE_T_FMT_PRECISION(x) "%" #x "Iu"
#define SIZE_T_FMT_HEX "%Ix"
#elif defined(__GNUC__) #elif defined(__GNUC__)
@ -65,6 +67,8 @@
#define FORMATSTRING(formatIndex,va_argsIndex) __attribute__((format (printf, formatIndex, va_argsIndex))) #define FORMATSTRING(formatIndex,va_argsIndex) __attribute__((format (printf, formatIndex, va_argsIndex)))
#define SIZE_T_FMT "%zu" #define SIZE_T_FMT "%zu"
#define SIZE_T_FMT_PRECISION(x) "%" #x "zu"
#define SIZE_T_FMT_HEX "%zx"
#else #else

View File

@ -216,7 +216,7 @@ cItem * cItems::Get(int a_Idx)
{ {
if ((a_Idx < 0) || (a_Idx >= (int)size())) if ((a_Idx < 0) || (a_Idx >= (int)size()))
{ {
LOGWARNING("cItems: Attempt to get an out-of-bounds item at index %d; there are currently %zu items. Returning a nil.", a_Idx, size()); LOGWARNING("cItems: Attempt to get an out-of-bounds item at index %d; there are currently " SIZE_T_FMT " items. Returning a nil.", a_Idx, size());
return NULL; return NULL;
} }
return &at(a_Idx); return &at(a_Idx);
@ -230,7 +230,7 @@ void cItems::Set(int a_Idx, const cItem & a_Item)
{ {
if ((a_Idx < 0) || (a_Idx >= (int)size())) if ((a_Idx < 0) || (a_Idx >= (int)size()))
{ {
LOGWARNING("cItems: Attempt to set an item at an out-of-bounds index %d; there are currently %zu items. Not setting.", a_Idx, size()); LOGWARNING("cItems: Attempt to set an item at an out-of-bounds index %d; there are currently " SIZE_T_FMT " items. Not setting.", a_Idx, size());
return; return;
} }
at(a_Idx) = a_Item; at(a_Idx) = a_Item;
@ -244,7 +244,7 @@ void cItems::Delete(int a_Idx)
{ {
if ((a_Idx < 0) || (a_Idx >= (int)size())) if ((a_Idx < 0) || (a_Idx >= (int)size()))
{ {
LOGWARNING("cItems: Attempt to delete an item at an out-of-bounds index %d; there are currently %zu items. Ignoring.", a_Idx, size()); LOGWARNING("cItems: Attempt to delete an item at an out-of-bounds index %d; there are currently " SIZE_T_FMT " items. Ignoring.", a_Idx, size());
return; return;
} }
erase(begin() + a_Idx); erase(begin() + a_Idx);
@ -258,7 +258,7 @@ void cItems::Set(int a_Idx, short a_ItemType, char a_ItemCount, short a_ItemDama
{ {
if ((a_Idx < 0) || (a_Idx >= (int)size())) if ((a_Idx < 0) || (a_Idx >= (int)size()))
{ {
LOGWARNING("cItems: Attempt to set an item at an out-of-bounds index %d; there are currently %zu items. Not setting.", a_Idx, size()); LOGWARNING("cItems: Attempt to set an item at an out-of-bounds index %d; there are currently " SIZE_T_FMT " items. Not setting.", a_Idx, size());
return; return;
} }
at(a_Idx) = cItem(a_ItemType, a_ItemCount, a_ItemDamage); at(a_Idx) = cItem(a_ItemType, a_ItemCount, a_ItemDamage);

View File

@ -118,7 +118,7 @@ void cLog::Log(const char * a_Format, va_list argList)
AString Line; AString Line;
#ifdef _DEBUG #ifdef _DEBUG
Printf(Line, "[%04zu|%02d:%02d:%02d] %s", cIsThread::GetCurrentID(), timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, Message.c_str()); Printf(Line, "[" SIZE_T_FMT_PRECISION(04) "|%02d:%02d:%02d] %s", cIsThread::GetCurrentID(), timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, Message.c_str());
#else #else
Printf(Line, "[%02d:%02d:%02d] %s", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, Message.c_str()); Printf(Line, "[%02d:%02d:%02d] %s", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, Message.c_str());
#endif #endif

View File

@ -54,7 +54,7 @@ bool cSocketThreads::AddClient(const cSocket & a_Socket, cCallback * a_Client)
} }
// No thread has free space, create a new one: // No thread has free space, create a new one:
LOGD("Creating a new cSocketThread (currently have %zu)", m_Threads.size()); LOGD("Creating a new cSocketThread (currently have " SIZE_T_FMT ")", m_Threads.size());
cSocketThread * Thread = new cSocketThread(this); cSocketThread * Thread = new cSocketThread(this);
if (!Thread->Start()) if (!Thread->Start())
{ {

View File

@ -100,7 +100,7 @@ cProtocol132::~cProtocol132()
{ {
if (!m_DataToSend.empty()) if (!m_DataToSend.empty())
{ {
LOGD("There are %zu unsent bytes while deleting cProtocol132", m_DataToSend.size()); LOGD("There are " SIZE_T_FMT " unsent bytes while deleting cProtocol132", m_DataToSend.size());
} }
} }

View File

@ -1251,7 +1251,7 @@ void cProtocol172::AddReceivedData(const char * a_Data, int a_Size)
ASSERT(m_ReceivedData.GetReadableSpace() == OldReadableSpace); ASSERT(m_ReceivedData.GetReadableSpace() == OldReadableSpace);
AString Hex; AString Hex;
CreateHexDump(Hex, AllData.data(), AllData.size(), 16); CreateHexDump(Hex, AllData.data(), AllData.size(), 16);
m_CommLogFile.Printf("Incoming data, %zu (0x%zx) unparsed bytes already present in buffer:\n%s\n", m_CommLogFile.Printf("Incoming data, " SIZE_T_FMT " (0x" SIZE_T_FMT_HEX ") unparsed bytes already present in buffer:\n%s\n",
AllData.size(), AllData.size(), Hex.c_str() AllData.size(), AllData.size(), Hex.c_str()
); );
} }
@ -1344,14 +1344,14 @@ void cProtocol172::AddReceivedData(const char * a_Data, int a_Size)
if (bb.GetReadableSpace() != 1) if (bb.GetReadableSpace() != 1)
{ {
// Read more or less than packet length, report as error // Read more or less than packet length, report as error
LOGWARNING("Protocol 1.7: Wrong number of bytes read for packet 0x%x, state %d. Read %zu bytes, packet contained %u bytes", LOGWARNING("Protocol 1.7: Wrong number of bytes read for packet 0x%x, state %d. Read " SIZE_T_FMT " bytes, packet contained %u bytes",
PacketType, m_State, bb.GetUsedSpace() - bb.GetReadableSpace(), PacketLen PacketType, m_State, bb.GetUsedSpace() - bb.GetReadableSpace(), PacketLen
); );
// Put a message in the comm log: // Put a message in the comm log:
if (g_ShouldLogCommIn) if (g_ShouldLogCommIn)
{ {
m_CommLogFile.Printf("^^^^^^ Wrong number of bytes read for this packet (exp %d left, got %zu left) ^^^^^^\n\n\n", m_CommLogFile.Printf("^^^^^^ Wrong number of bytes read for this packet (exp %d left, got " SIZE_T_FMT " left) ^^^^^^\n\n\n",
1, bb.GetReadableSpace() 1, bb.GetReadableSpace()
); );
m_CommLogFile.Flush(); m_CommLogFile.Flush();
@ -1373,7 +1373,7 @@ void cProtocol172::AddReceivedData(const char * a_Data, int a_Size)
ASSERT(m_ReceivedData.GetReadableSpace() == OldReadableSpace); ASSERT(m_ReceivedData.GetReadableSpace() == OldReadableSpace);
AString Hex; AString Hex;
CreateHexDump(Hex, AllData.data(), AllData.size(), 16); CreateHexDump(Hex, AllData.data(), AllData.size(), 16);
m_CommLogFile.Printf("There are %zu (0x%zx) bytes of non-parse-able data left in the buffer:\n%s", m_CommLogFile.Printf("There are " SIZE_T_FMT " (0x" SIZE_T_FMT_HEX ") bytes of non-parse-able data left in the buffer:\n%s",
m_ReceivedData.GetReadableSpace(), m_ReceivedData.GetReadableSpace(), Hex.c_str() m_ReceivedData.GetReadableSpace(), m_ReceivedData.GetReadableSpace(), Hex.c_str()
); );
m_CommLogFile.Flush(); m_CommLogFile.Flush();
@ -2062,7 +2062,7 @@ void cProtocol172::ParseItemMetadata(cItem & a_Item, const AString & a_Metadata)
{ {
AString HexDump; AString HexDump;
CreateHexDump(HexDump, a_Metadata.data(), a_Metadata.size(), 16); CreateHexDump(HexDump, a_Metadata.data(), a_Metadata.size(), 16);
LOGWARNING("Cannot unGZIP item metadata (%zu bytes):\n%s", a_Metadata.size(), HexDump.c_str()); LOGWARNING("Cannot unGZIP item metadata (" SIZE_T_FMT " bytes):\n%s", a_Metadata.size(), HexDump.c_str());
return; return;
} }
@ -2072,7 +2072,7 @@ void cProtocol172::ParseItemMetadata(cItem & a_Item, const AString & a_Metadata)
{ {
AString HexDump; AString HexDump;
CreateHexDump(HexDump, Uncompressed.data(), Uncompressed.size(), 16); CreateHexDump(HexDump, Uncompressed.data(), Uncompressed.size(), 16);
LOGWARNING("Cannot parse NBT item metadata: (%zu bytes)\n%s", Uncompressed.size(), HexDump.c_str()); LOGWARNING("Cannot parse NBT item metadata: (" SIZE_T_FMT " bytes)\n%s", Uncompressed.size(), HexDump.c_str());
return; return;
} }

View File

@ -778,11 +778,11 @@ void cRoot::LogChunkStats(cCommandOutputCallback & a_Output)
int Mem = NumValid * sizeof(cChunk); int Mem = NumValid * sizeof(cChunk);
a_Output.Out(" Memory used by chunks: %d KiB (%d MiB)", (Mem + 1023) / 1024, (Mem + 1024 * 1024 - 1) / (1024 * 1024)); a_Output.Out(" Memory used by chunks: %d KiB (%d MiB)", (Mem + 1023) / 1024, (Mem + 1024 * 1024 - 1) / (1024 * 1024));
a_Output.Out(" Per-chunk memory size breakdown:"); a_Output.Out(" Per-chunk memory size breakdown:");
a_Output.Out(" block types: %6zu bytes (%3zu KiB)", sizeof(cChunkDef::BlockTypes), (sizeof(cChunkDef::BlockTypes) + 1023) / 1024); a_Output.Out(" block types: " SIZE_T_FMT_PRECISION(6) " bytes (" SIZE_T_FMT_PRECISION(3) " KiB)", sizeof(cChunkDef::BlockTypes), (sizeof(cChunkDef::BlockTypes) + 1023) / 1024);
a_Output.Out(" block metadata: %6zu bytes (%3zu KiB)", sizeof(cChunkDef::BlockNibbles), (sizeof(cChunkDef::BlockNibbles) + 1023) / 1024); a_Output.Out(" block metadata: " SIZE_T_FMT_PRECISION(6) " bytes (" SIZE_T_FMT_PRECISION(3) " KiB)", sizeof(cChunkDef::BlockNibbles), (sizeof(cChunkDef::BlockNibbles) + 1023) / 1024);
a_Output.Out(" block lighting: %6zu bytes (%3zu KiB)", 2 * sizeof(cChunkDef::BlockNibbles), (2 * sizeof(cChunkDef::BlockNibbles) + 1023) / 1024); a_Output.Out(" block lighting: " SIZE_T_FMT_PRECISION(6) " bytes (" SIZE_T_FMT_PRECISION(3) " KiB)", 2 * sizeof(cChunkDef::BlockNibbles), (2 * sizeof(cChunkDef::BlockNibbles) + 1023) / 1024);
a_Output.Out(" heightmap: %6zu bytes (%3zu KiB)", sizeof(cChunkDef::HeightMap), (sizeof(cChunkDef::HeightMap) + 1023) / 1024); a_Output.Out(" heightmap: " SIZE_T_FMT_PRECISION(6) " bytes (" SIZE_T_FMT_PRECISION(3) " KiB)", sizeof(cChunkDef::HeightMap), (sizeof(cChunkDef::HeightMap) + 1023) / 1024);
a_Output.Out(" biomemap: %6zu bytes (%3zu KiB)", sizeof(cChunkDef::BiomeMap), (sizeof(cChunkDef::BiomeMap) + 1023) / 1024); a_Output.Out(" biomemap: " SIZE_T_FMT_PRECISION(6) " bytes (" SIZE_T_FMT_PRECISION(3) " KiB)", sizeof(cChunkDef::BiomeMap), (sizeof(cChunkDef::BiomeMap) + 1023) / 1024);
int Rest = sizeof(cChunk) - sizeof(cChunkDef::BlockTypes) - 3 * sizeof(cChunkDef::BlockNibbles) - sizeof(cChunkDef::HeightMap) - sizeof(cChunkDef::BiomeMap); int Rest = sizeof(cChunk) - sizeof(cChunkDef::BlockTypes) - 3 * sizeof(cChunkDef::BlockNibbles) - sizeof(cChunkDef::HeightMap) - sizeof(cChunkDef::BiomeMap);
a_Output.Out(" other: %6d bytes (%3d KiB)", Rest, (Rest + 1023) / 1024); a_Output.Out(" other: %6d bytes (%3d KiB)", Rest, (Rest + 1023) / 1024);
SumNumValid += NumValid; SumNumValid += NumValid;

View File

@ -637,7 +637,7 @@ int cWindow::DistributeItemToSlots(cPlayer & a_Player, const cItem & a_Item, int
{ {
if ((size_t)(a_Item.m_ItemCount) < a_SlotNums.size()) if ((size_t)(a_Item.m_ItemCount) < a_SlotNums.size())
{ {
LOGWARNING("%s: Distributing less items (%d) than slots (%zu)", __FUNCTION__, (int)a_Item.m_ItemCount, a_SlotNums.size()); LOGWARNING("%s: Distributing less items (%d) than slots (" SIZE_T_FMT ")", __FUNCTION__, (int)a_Item.m_ItemCount, a_SlotNums.size());
// This doesn't seem to happen with the 1.5.1 client, so we don't worry about it for now // This doesn't seem to happen with the 1.5.1 client, so we don't worry about it for now
return 0; return 0;
} }

View File

@ -102,7 +102,7 @@ protected:
{ {
for (;;) for (;;)
{ {
LOG("%zu chunks to load, %d chunks to generate", LOG("" SIZE_T_FMT " chunks to load, %d chunks to generate",
m_World->GetStorage().GetLoadQueueLength(), m_World->GetStorage().GetLoadQueueLength(),
m_World->GetGenerator().GetQueueLength() m_World->GetGenerator().GetQueueLength()
); );
@ -154,7 +154,7 @@ protected:
{ {
for (;;) for (;;)
{ {
LOG("%zu chunks remaining to light", m_Lighting->GetQueueLength() LOG("" SIZE_T_FMT " chunks remaining to light", m_Lighting->GetQueueLength()
); );
// Wait for 2 sec, but be "reasonably wakeable" when the thread is to finish // Wait for 2 sec, but be "reasonably wakeable" when the thread is to finish

View File

@ -569,7 +569,7 @@ void cWSSCompact::cPAKFile::UpdateChunk1To2()
if( ChunksConverted % 32 == 0 ) if( ChunksConverted % 32 == 0 )
{ {
LOGINFO("Updating \"%s\" version 1 to version 2: %zu %%", m_FileName.c_str(), (ChunksConverted * 100) / m_ChunkHeaders.size() ); LOGINFO("Updating \"%s\" version 1 to version 2: " SIZE_T_FMT " %%", m_FileName.c_str(), (ChunksConverted * 100) / m_ChunkHeaders.size() );
} }
ChunksConverted++; ChunksConverted++;
@ -607,7 +607,7 @@ void cWSSCompact::cPAKFile::UpdateChunk1To2()
if (UncompressedSize != (int)UncompressedData.size()) if (UncompressedSize != (int)UncompressedData.size())
{ {
LOGWARNING("Uncompressed data size differs (exp %d bytes, got %zu) for chunk [%d, %d]", LOGWARNING("Uncompressed data size differs (exp %d bytes, got " SIZE_T_FMT ") for chunk [%d, %d]",
UncompressedSize, UncompressedData.size(), UncompressedSize, UncompressedData.size(),
Header->m_ChunkX, Header->m_ChunkZ Header->m_ChunkX, Header->m_ChunkZ
); );
@ -713,7 +713,7 @@ void cWSSCompact::cPAKFile::UpdateChunk2To3()
if( ChunksConverted % 32 == 0 ) if( ChunksConverted % 32 == 0 )
{ {
LOGINFO("Updating \"%s\" version 2 to version 3: %zu %%", m_FileName.c_str(), (ChunksConverted * 100) / m_ChunkHeaders.size() ); LOGINFO("Updating \"%s\" version 2 to version 3: " SIZE_T_FMT " %%", m_FileName.c_str(), (ChunksConverted * 100) / m_ChunkHeaders.size() );
} }
ChunksConverted++; ChunksConverted++;
@ -751,7 +751,7 @@ void cWSSCompact::cPAKFile::UpdateChunk2To3()
if (UncompressedSize != (int)UncompressedData.size()) if (UncompressedSize != (int)UncompressedData.size())
{ {
LOGWARNING("Uncompressed data size differs (exp %d bytes, got %zu) for chunk [%d, %d]", LOGWARNING("Uncompressed data size differs (exp %d bytes, got " SIZE_T_FMT ") for chunk [%d, %d]",
UncompressedSize, UncompressedData.size(), UncompressedSize, UncompressedData.size(),
Header->m_ChunkX, Header->m_ChunkZ Header->m_ChunkX, Header->m_ChunkZ
); );
@ -866,7 +866,7 @@ bool cWSSCompact::LoadChunkFromData(const cChunkCoords & a_Chunk, int & a_Uncomp
if (a_UncompressedSize != (int)UncompressedData.size()) if (a_UncompressedSize != (int)UncompressedData.size())
{ {
LOGWARNING("Uncompressed data size differs (exp %d bytes, got %zu) for chunk [%d, %d]", LOGWARNING("Uncompressed data size differs (exp %d bytes, got " SIZE_T_FMT ") for chunk [%d, %d]",
a_UncompressedSize, UncompressedData.size(), a_UncompressedSize, UncompressedData.size(),
a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ
); );