From a0d5463b495fff2b81c8a2e82f26aa199a14ef30 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Wed, 14 May 2008 03:39:30 +0000 Subject: [PATCH] - Added the C99 printf size specifiers 't' (ptrdiff_t) and 'z' (size_t) to FString::Format() so that I can fix all the problem printf strings that a 64-bit GCC compile finds. SVN r968 (trunk) --- Makefile.linux | 14 +++++++++++++- docs/rh-log.txt | 11 ++++++++--- src/dobjgc.cpp | 4 ++-- src/f_finale.cpp | 2 +- src/g_shared/a_skies.cpp | 2 +- src/g_shared/a_weapons.cpp | 2 +- src/m_alloc.cpp | 8 ++++---- src/nodebuild.cpp | 4 ++-- src/p_maputl.cpp | 2 +- src/p_mobj.cpp | 4 ++-- src/p_setup.cpp | 2 +- src/p_udmf.cpp | 2 +- src/p_user.cpp | 8 ++++---- src/r_bsp.cpp | 2 +- src/r_segs.cpp | 4 ++-- src/r_things.cpp | 8 ++++---- src/sound/fmodsound.cpp | 6 +++--- src/stats.h | 6 +++--- src/timidity/common.cpp | 4 ++-- src/timidity/mix.cpp | 2 +- src/zstrformat.cpp | 26 +++++++++++++++++++++++++- src/zstring.h | 4 +++- 22 files changed, 85 insertions(+), 42 deletions(-) diff --git a/Makefile.linux b/Makefile.linux index 884a5467c..61c4031fb 100644 --- a/Makefile.linux +++ b/Makefile.linux @@ -5,6 +5,15 @@ CXX ?= g++ CC ?= gcc NASM ?= nasm CCDV = @./ccdv + +ifndef X64 + ifeq (x86_64,$(shell uname -m)) + X64=64 + else + X64= + endif +endif + ifdef DEBUG CFLAGS ?= -pipe -Wall -Wno-unused -fno-strict-aliasing else @@ -17,7 +26,7 @@ endif #endif CFLAGS += -MMD -DHAVE_FILELENGTH -D__forceinline=inline `sdl-config --cflags` `pkg-config gtk+-2.0 --cflags` CFLAGS += -Dstricmp=strcasecmp -Dstrnicmp=strncasecmp -DNEED_STRUPR -LDFLAGS += -lz -ljpeg `sdl-config --libs` `pkg-config gtk+-2.0 --libs` $(FMOD_PREFIX)/lib/libfmodex.so +LDFLAGS += -lz -ljpeg `sdl-config --libs` `pkg-config gtk+-2.0 --libs` $(FMOD_PREFIX)/lib/libfmodex${X64}.so NASMFLAGS += -f elf -DM_TARGET_LINUX SRCDIRS = src/ $(addprefix src/,g_doom/ g_heretic/ g_hexen/ g_raven/ g_shared/ g_strife/ oplsynth/ sound/ sdl/ textures/ thingdef/ xlat/ timidity/) @@ -31,6 +40,9 @@ DEBUGOBJ ?= debugobj CPPSRCS = $(wildcard $(addsuffix *.cpp,$(SRCDIRS))) CSRCS = $(filter-out src/xlat/xlat_parser.c, $(wildcard $(addsuffix *.c,$(SRCDIRS)))) +ifdef X64 + NOASM=1 +endif ifdef NOASM CFLAGS += -DNOASM else diff --git a/docs/rh-log.txt b/docs/rh-log.txt index b1b9c03f6..4deda5e7a 100644 --- a/docs/rh-log.txt +++ b/docs/rh-log.txt @@ -1,3 +1,8 @@ +May 13, 2008 +- Added the C99 printf size specifiers 't' (ptrdiff_t) and 'z' (size_t) to + FString::Format() so that I can fix all the problem printf strings that a + 64-bit GCC compile finds. + May 12, 2008 (Changes by Graf Zahl) - Added Skulltag's PUFFGETSOWNER flag. - Fixed: Parsing sector special bit masks must be done backwards so that later @@ -272,7 +277,7 @@ April 15, 2008 (Changes by Graf Zahl) check being done manually. April 14, 2008 (Changes by Graf Zahl) -- Added rotation 90° angles only) and mirroring to the Multipatch texture +- Added rotation 90� angles only) and mirroring to the Multipatch texture composition code. - Fixed: The game crashed when a level was ended while a player was morphed by a powerup. @@ -5476,7 +5481,7 @@ April 22, 2006 (Changes by Graf Zahl) - Fixed the issues with .96x's railgun code and added it to the current version. - Fixed: Setting of the friendly Minotaur's angle was inconsistent and - could cause it to move backwards in a féw situation. + could cause it to move backwards in a f�w situation. - Fixed: The minotaur did checks for type by checking for the MF_FRIENDLY flag, not by checking for the actor class. That made it impossible to spawn friendly 'normal' minotaurs. @@ -16442,7 +16447,7 @@ September 12, 1998 September 4, 1998 - Added weapnext and weapprev commands courtesy of - Papst Johannes Jörg IV. [which were later completely + Papst Johannes J�rg IV. [which were later completely rewritten by me] - Add support for suspending and resuming scripts (easy when you know you can only have one copy running at a time). diff --git a/src/dobjgc.cpp b/src/dobjgc.cpp index 25bbb1e44..f2877636d 100644 --- a/src/dobjgc.cpp +++ b/src/dobjgc.cpp @@ -644,7 +644,7 @@ ADD_STAT(gc) " Sweep ", "Finalize " }; FString out; - out.Format("[%s] Alloc:%6uK Thresh:%6uK Est:%6uK Steps: %d", + out.Format("[%s] Alloc:%6zuK Thresh:%6zuK Est:%6zuK Steps: %d", StateStrings[GC::State], (GC::AllocBytes + 1023) >> 10, (GC::Threshold + 1023) >> 10, @@ -652,7 +652,7 @@ ADD_STAT(gc) GC::StepCount); if (GC::State != GC::GCS_Pause) { - out.AppendFormat(" %uK", (GC::Dept + 1023) >> 10); + out.AppendFormat(" %zuK", (GC::Dept + 1023) >> 10); } return out; } diff --git a/src/f_finale.cpp b/src/f_finale.cpp index c91e94187..d70125fac 100644 --- a/src/f_finale.cpp +++ b/src/f_finale.cpp @@ -961,7 +961,7 @@ void F_BunnyScroll (void) laststage = stage; } - sprintf (name, "END%i", stage); + sprintf (name, "END%d", (int)stage); screen->DrawTexture (TexMan(name), (320-13*8)/2, (200-8*8)/2, DTA_320x200, true, TAG_DONE); } } diff --git a/src/g_shared/a_skies.cpp b/src/g_shared/a_skies.cpp index 4ec3a8ad7..f682f3558 100644 --- a/src/g_shared/a_skies.cpp +++ b/src/g_shared/a_skies.cpp @@ -128,7 +128,7 @@ void ASkyPicker::PostBeginPlay () if (box == NULL && args[0] != 0) { - Printf ("Can't find SkyViewpoint %d for sector %d\n", + Printf ("Can't find SkyViewpoint %d for sector %td\n", args[0], Sector - sectors); } else diff --git a/src/g_shared/a_weapons.cpp b/src/g_shared/a_weapons.cpp index f6e37b6a1..560dacd4d 100644 --- a/src/g_shared/a_weapons.cpp +++ b/src/g_shared/a_weapons.cpp @@ -851,7 +851,7 @@ CCMD (addslot) if (!LocalWeapons.Slots[slot].AddWeapon (argv[2])) { - Printf ("Could not add %s to slot %d\n", argv[2], slot); + Printf ("Could not add %s to slot %zu\n", argv[2], slot); } } diff --git a/src/m_alloc.cpp b/src/m_alloc.cpp index 4d9e0fbf3..23d0edc65 100644 --- a/src/m_alloc.cpp +++ b/src/m_alloc.cpp @@ -50,7 +50,7 @@ void *M_Malloc(size_t size) void *block = malloc(size); if (block == NULL) - I_FatalError("Could not malloc %u bytes", size); + I_FatalError("Could not malloc %zu bytes", size); GC::AllocBytes += _msize(block); return block; @@ -65,7 +65,7 @@ void *M_Realloc(void *memblock, size_t size) void *block = realloc(memblock, size); if (block == NULL) { - I_FatalError("Could not realloc %u bytes", size); + I_FatalError("Could not realloc %zu bytes", size); } GC::AllocBytes += _msize(block); return block; @@ -80,7 +80,7 @@ void *M_Malloc_Dbg(size_t size, const char *file, int lineno) void *block = _malloc_dbg(size, _NORMAL_BLOCK, file, lineno); if (block == NULL) - I_FatalError("Could not malloc %u bytes", size); + I_FatalError("Could not malloc %zu bytes", size); GC::AllocBytes += _msize(block); return block; @@ -95,7 +95,7 @@ void *M_Realloc_Dbg(void *memblock, size_t size, const char *file, int lineno) void *block = _realloc_dbg(memblock, size, _NORMAL_BLOCK, file, lineno); if (block == NULL) { - I_FatalError("Could not realloc %u bytes", size); + I_FatalError("Could not realloc %zu bytes", size); } GC::AllocBytes += _msize(block); return block; diff --git a/src/nodebuild.cpp b/src/nodebuild.cpp index d8f534255..37b45981d 100644 --- a/src/nodebuild.cpp +++ b/src/nodebuild.cpp @@ -751,7 +751,7 @@ void FNodeBuilder::SplitSegs (DWORD set, node_t &node, DWORD splitseg, DWORD &ou if (seg->loopnum) { - Printf (" Split seg %u (%d,%d)-(%d,%d) of sector %d in loop %d\n", + Printf (" Split seg %u (%d,%d)-(%d,%d) of sector %td in loop %d\n", set, Vertices[seg->v1].x>>16, Vertices[seg->v1].y>>16, Vertices[seg->v2].x>>16, Vertices[seg->v2].y>>16, @@ -991,7 +991,7 @@ void FNodeBuilder::PrintSet (int l, DWORD set) Printf ("set %d:\n", l); for (; set != DWORD_MAX; set = Segs[set].next) { - Printf ("\t%u(%d):%d(%d,%d)-%d(%d,%d) ", set, Segs[set].frontsector-sectors, + Printf ("\t%u(%td):%d(%d,%d)-%d(%d,%d) ", set, Segs[set].frontsector-sectors, Segs[set].v1, Vertices[Segs[set].v1].x>>16, Vertices[Segs[set].v1].y>>16, Segs[set].v2, diff --git a/src/p_maputl.cpp b/src/p_maputl.cpp index 48e40e6bb..5d86f9559 100644 --- a/src/p_maputl.cpp +++ b/src/p_maputl.cpp @@ -522,7 +522,7 @@ sector_t *AActor::LinkToWorldForMapThing () if (distance < radius) { - DPrintf ("%s at (%d,%d) lies on %s line %d, distance = %f\n", + DPrintf ("%s at (%d,%d) lies on %s line %td, distance = %f\n", this->GetClass()->TypeName.GetChars(), x>>FRACBITS, y>>FRACBITS, ldef->dx == 0? "vertical" : ldef->dy == 0? "horizontal" : "diagonal", ldef-lines, FIXED2FLOAT(distance)); diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp index fc1f292fe..906c0d088 100644 --- a/src/p_mobj.cpp +++ b/src/p_mobj.cpp @@ -499,7 +499,7 @@ int AActor::GetTics(FState * newstate) bool AActor::SetState (FState *newstate) { if (debugfile && player && (player->cheats & CF_PREDICTING)) - fprintf (debugfile, "for pl %d: SetState while predicting!\n", player-players); + fprintf (debugfile, "for pl %td: SetState while predicting!\n", player-players); do { if (newstate == NULL) @@ -3096,7 +3096,7 @@ bool AActor::UpdateWaterLevel (fixed_t oldz, bool dosplash) } - // some additional checks to make deep sectors à la Boom splash without setting + // some additional checks to make deep sectors � la Boom splash without setting // the water flags. if (boomwaterlevel == 0 && waterlevel != 0 && dosplash) P_HitWater(this, Sector, fh); boomwaterlevel=waterlevel; diff --git a/src/p_setup.cpp b/src/p_setup.cpp index 593c426a2..e24957e3e 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -1282,7 +1282,7 @@ void P_LoadNodes (MapData * map) } else if (child >= numnodes) { - Printf ("BSP node %d references invalid node %d.\n" + Printf ("BSP node %d references invalid node %td.\n" "The BSP will be rebuilt.\n", i, (node_t *)no->children[j] - nodes); ForceNodeBuild = true; delete[] nodes; diff --git a/src/p_udmf.cpp b/src/p_udmf.cpp index 943acc44c..2273d1e71 100644 --- a/src/p_udmf.cpp +++ b/src/p_udmf.cpp @@ -542,7 +542,7 @@ struct UDMFParser if (v1i >= numvertexes || v2i >= numvertexes || v1i < 0 || v2i < 0) { - I_Error ("Line %d has invalid vertices: %d and/or %d.\nThe map only contains %d vertices.", i+skipped, v1i, v2i, numvertexes); + I_Error ("Line %d has invalid vertices: %zd and/or %zd.\nThe map only contains %d vertices.", i+skipped, v1i, v2i, numvertexes); } else if (v1i == v2i || (vertexes[v1i].x == vertexes[v2i].x && vertexes[v1i].y == vertexes[v2i].y)) diff --git a/src/p_user.cpp b/src/p_user.cpp index 587a8681d..0bf4419d7 100644 --- a/src/p_user.cpp +++ b/src/p_user.cpp @@ -1639,13 +1639,13 @@ void P_MovePlayer (player_t *player) if (debugfile) { - fprintf (debugfile, "move player for pl %d%c: (%d,%d,%d) (%d,%d) %d %d w%d [", player-players, + fprintf (debugfile, "move player for pl %d%c: (%d,%d,%d) (%d,%d) %d %d w%d [", int(player-players), player->cheats&CF_PREDICTING?'p':' ', player->mo->x, player->mo->y, player->mo->z,forwardmove, sidemove, movefactor, friction, player->mo->waterlevel); msecnode_t *n = player->mo->touching_sectorlist; while (n != NULL) { - fprintf (debugfile, "%d ", n->m_sector-sectors); + fprintf (debugfile, "%td ", n->m_sector-sectors); n = n->m_tnext; } fprintf (debugfile, "]\n"); @@ -1918,12 +1918,12 @@ void P_PlayerThink (player_t *player) if (player->mo == NULL) { - I_Error ("No player %d start\n", player - players + 1); + I_Error ("No player %td start\n", player - players + 1); } if (debugfile && !(player->cheats & CF_PREDICTING)) { - fprintf (debugfile, "tic %d for pl %d: (%d, %d, %d, %u) b:%02x p:%d y:%d f:%d s:%d u:%d\n", + fprintf (debugfile, "tic %d for pl %td: (%d, %d, %d, %u) b:%02x p:%d y:%d f:%d s:%d u:%d\n", gametic, player-players, player->mo->x, player->mo->y, player->mo->z, player->mo->angle>>ANGLETOFINESHIFT, player->cmd.ucmd.buttons, player->cmd.ucmd.pitch, player->cmd.ucmd.yaw, player->cmd.ucmd.forwardmove, diff --git a/src/r_bsp.cpp b/src/r_bsp.cpp index 27248e608..99721019c 100644 --- a/src/r_bsp.cpp +++ b/src/r_bsp.cpp @@ -1048,7 +1048,7 @@ void R_Subsector (subsector_t *sub) #ifdef RANGECHECK if (sub - subsectors >= (ptrdiff_t)numsubsectors) - I_Error ("R_Subsector: ss %i with numss = %i", sub - subsectors, numsubsectors); + I_Error ("R_Subsector: ss %ti with numss = %i", sub - subsectors, numsubsectors); #endif frontsector = sub->sector; diff --git a/src/r_segs.cpp b/src/r_segs.cpp index 4c6031305..894efc9ea 100644 --- a/src/r_segs.cpp +++ b/src/r_segs.cpp @@ -1480,7 +1480,7 @@ void R_CheckDrawSegs () firstdrawseg = drawsegs + firstofs; ds_p = drawsegs + MaxDrawSegs; MaxDrawSegs = newdrawsegs; - DPrintf ("MaxDrawSegs increased to %d\n", MaxDrawSegs); + DPrintf ("MaxDrawSegs increased to %zu\n", MaxDrawSegs); } } @@ -1498,7 +1498,7 @@ void R_CheckOpenings (size_t need) maxopenings = maxopenings ? maxopenings*2 : 16384; while (need > maxopenings); openings = (short *)M_Realloc (openings, maxopenings * sizeof(*openings)); - DPrintf ("MaxOpenings increased to %u\n", maxopenings); + DPrintf ("MaxOpenings increased to %zu\n", maxopenings); } } diff --git a/src/r_things.cpp b/src/r_things.cpp index eb8e0e041..6685956ea 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -467,7 +467,7 @@ void R_InitSkins (void) strncpy (key, sc.String, sizeof(key)-1); if (!sc.GetString() || sc.String[0] != '=') { - Printf (PRINT_BOLD, "Bad format for skin %d: %s\n", i, key); + Printf (PRINT_BOLD, "Bad format for skin %d: %s\n", (int)i, key); break; } sc.GetString (); @@ -478,7 +478,7 @@ void R_InitSkins (void) { if (stricmp (skins[i].name, skins[j].name) == 0) { - sprintf (skins[i].name, "skin%d", i); + sprintf (skins[i].name, "skin%d", (int)i); Printf (PRINT_BOLD, "Skin %s duplicated as %s\n", skins[j].name, skins[i].name); break; @@ -659,7 +659,7 @@ void R_InitSkins (void) if (!remove) { if (skins[i].name[0] == 0) - sprintf (skins[i].name, "skin%d", i); + sprintf (skins[i].name, "skin%d", (int)i); // Now collect the sprite frames for this skin. If the sprite name was not // specified, use whatever immediately follows the specifier lump. @@ -710,7 +710,7 @@ void R_InitSkins (void) if (spr == 0 && maxframe <= 0) { - Printf (PRINT_BOLD, "Skin %s (#%d) has no frames. Removing.\n", skins[i].name, i); + Printf (PRINT_BOLD, "Skin %s (#%d) has no frames. Removing.\n", skins[i].name, (int)i); remove = true; break; } diff --git a/src/sound/fmodsound.cpp b/src/sound/fmodsound.cpp index da134a9f7..72787fe89 100644 --- a/src/sound/fmodsound.cpp +++ b/src/sound/fmodsound.cpp @@ -602,7 +602,7 @@ bool FMODSoundRenderer::Init() if (!ShowedBanner) { - Printf("FMOD Sound System, copyright © Firelight Technologies Pty, Ltd., 1994-2008.\n"); + Printf("FMOD Sound System, copyright � Firelight Technologies Pty, Ltd., 1994-2008.\n"); ShowedBanner = true; } #ifdef _WIN32 @@ -1597,7 +1597,7 @@ void FMODSoundRenderer::LoadSound(sfxinfo_t *sfx) { if (sfx->data == NULL) { - DPrintf("loading sound \"%s\" (%d)\n", sfx->name.GetChars(), sfx - &S_sfx[0]); + DPrintf("Loading sound \"%s\" (%td)\n", sfx->name.GetChars(), sfx - &S_sfx[0]); getsfx(sfx); } } @@ -1614,7 +1614,7 @@ void FMODSoundRenderer::UnloadSound(sfxinfo_t *sfx) { ((FMOD::Sound *)sfx->data)->release(); sfx->data = NULL; - DPrintf("Unloaded sound \"%s\" (%d)\n", sfx->name.GetChars(), sfx - &S_sfx[0]); + DPrintf("Unloaded sound \"%s\" (%td)\n", sfx->name.GetChars(), sfx - &S_sfx[0]); } } diff --git a/src/stats.h b/src/stats.h index a02e5a124..81066b3c0 100644 --- a/src/stats.h +++ b/src/stats.h @@ -58,9 +58,9 @@ inline cycle_t GetClockCycle () #endif } -#elif defined(__GNUG__) && defined(__i386__) +#elif defined(__GNUC__) && (defined(__i386__) || defined(__amd64__)) -typedef QWORD cycle_t; +typedef unsigned long long cycle_t; inline cycle_t GetClockCycle() { @@ -78,7 +78,7 @@ inline cycle_t GetClockCycle() #else -typedef DWORD cycle_t; +typedef QWORD cycle_t; inline cycle_t GetClockCycle () { diff --git a/src/timidity/common.cpp b/src/timidity/common.cpp index 8579780e3..83e334b53 100644 --- a/src/timidity/common.cpp +++ b/src/timidity/common.cpp @@ -120,7 +120,7 @@ void *safe_malloc(size_t count) void *p; if (count > (1 << 21)) { - I_Error("Timidity: Tried allocating %u bytes. This must be a bug.", count); + I_Error("Timidity: Tried allocating %zu bytes. This must be a bug.", count); } else if ((p = malloc(count))) { @@ -128,7 +128,7 @@ void *safe_malloc(size_t count) } else { - I_Error("Timidity: Couldn't malloc %u bytes.", count); + I_Error("Timidity: Couldn't malloc %zu bytes.", count); } return 0; // Unreachable. } diff --git a/src/timidity/mix.cpp b/src/timidity/mix.cpp index 46fccd97d..b4fc0f818 100644 --- a/src/timidity/mix.cpp +++ b/src/timidity/mix.cpp @@ -278,7 +278,7 @@ static bool check_release(double RateMul, double sec) bool SF2Envelope::Update(Voice *v) { double sec; - double newvolume; + double newvolume = 0; switch (stage) { diff --git a/src/zstrformat.cpp b/src/zstrformat.cpp index e783d3ccd..567ebbd88 100644 --- a/src/zstrformat.cpp +++ b/src/zstrformat.cpp @@ -218,6 +218,16 @@ namespace StringFormat flags |= F_BIGI; } } + else if (*c == 't') + { + flags |= F_PTRDIFF; + ++c; + } + else if (*c == 'z') + { + flags |= F_SIZE; + ++c; + } base = c+1; @@ -278,7 +288,11 @@ namespace StringFormat } else { - if (size == F_HALFHALF) + if (size == 0) + { + intarg = va_arg (arglist, int); + } + else if (size == F_HALFHALF) { intarg = va_arg (arglist, int); intarg = (signed char)intarg; @@ -302,6 +316,16 @@ namespace StringFormat { int64arg = va_arg (arglist, int64_t); } + else if (size == F_PTRDIFF) + { + if (sizeof(ptrdiff_t) == sizeof(int)) intarg = va_arg (arglist, int); + else { int64arg = va_arg (arglist, int64_t); size = F_LONGLONG; } + } + else if (size == F_SIZE) + { + if (sizeof(size_t) == sizeof(int)) intarg = va_arg (arglist, int); + else { int64arg = va_arg (arglist, int64_t); size = F_LONGLONG; } + } else { intarg = va_arg (arglist, int); diff --git a/src/zstring.h b/src/zstring.h index 749c51728..cfef8c2cc 100644 --- a/src/zstring.h +++ b/src/zstring.h @@ -284,7 +284,9 @@ namespace StringFormat F_HALF = 0x2000, // h F_LONG = 0x3000, // l F_LONGLONG = 0x4000, // ll or I64 - F_BIGI = 0x5000 // I + F_BIGI = 0x5000, // I + F_PTRDIFF = 0x6000, // t + F_SIZE = 0x7000, // z }; typedef int (*OutputFunc)(void *data, const char *str, int len);