Update nedmalloc, fix loading tiles from .art files contained in a .zip, workaround GCC 4.4.x squarerotatetile() miscompilation issue

git-svn-id: https://svn.eduke32.com/eduke32@1586 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2010-01-16 20:17:33 +00:00
parent 00fcc1851d
commit 15b9665dc6
9 changed files with 221 additions and 183 deletions

View file

@ -9,6 +9,11 @@
extern "C" {
#endif
#define MAXGROUPFILES 8 //Warning: Fix groupfil if this is changed
#define MAXOPENFILES 64 //Warning: Fix filehan if this is changed
extern char filegrp[MAXOPENFILES];
void initcache(intptr_t dacachestart, int32_t dacachesize);
void allocache(intptr_t *newhandle, int32_t newbytes, char *newlockptr);
void suckcache(intptr_t *suckptr);

View file

@ -48,6 +48,10 @@ nedmalloc.dll.
USE_LOCKS can be 2 if you want to define your own MLOCK_T, INITIAL_LOCK,
ACQUIRE_LOCK, RELEASE_LOCK, TRY_LOCK, IS_LOCKED and NULL_LOCK_INITIALIZER.
NEDMALLOC_DEBUG can be defined to cause DEBUG to be set differently for nedmalloc
than for the rest of the build. Remember to set NDEBUG to disable all assertion
checking too.
USE_MAGIC_HEADERS causes nedalloc to allocate an extra three sizeof(size_t)
to each block. nedpfree() and nedprealloc() can then automagically know when
to free a system allocated block. Enabling this typically adds 20-50% to
@ -197,21 +201,21 @@ systems when passing non-nedmalloc blocks if you don't use USE_MAGIC_HEADERS.
*/
NEDMALLOCEXTSPEC NEDMALLOCNOALIASATTR size_t nedblksize(int *RESTRICT isforeign, void *RESTRICT mem) THROWSPEC;
NEDMALLOCEXTSPEC void nedsetvalue(void *v) THROWSPEC;
NEDMALLOCEXTSPEC NEDMALLOCNOALIASATTR void nedsetvalue(void *v) THROWSPEC;
NEDMALLOCEXTSPEC NEDMALLOCPTRATTR void * nedmalloc(size_t size) THROWSPEC;
NEDMALLOCEXTSPEC NEDMALLOCPTRATTR void * nedcalloc(size_t no, size_t size) THROWSPEC;
NEDMALLOCEXTSPEC NEDMALLOCPTRATTR void * nedrealloc(void *mem, size_t size) THROWSPEC;
NEDMALLOCEXTSPEC void nedfree(void *mem) THROWSPEC;
NEDMALLOCEXTSPEC NEDMALLOCPTRATTR void * nedmemalign(size_t alignment, size_t bytes) THROWSPEC;
NEDMALLOCEXTSPEC struct nedmallinfo nedmallinfo(void) THROWSPEC;
NEDMALLOCEXTSPEC int nedmallopt(int parno, int value) THROWSPEC;
NEDMALLOCEXTSPEC void* nedmalloc_internals(size_t *granularity, size_t *magic) THROWSPEC;
NEDMALLOCEXTSPEC int nedmalloc_trim(size_t pad) THROWSPEC;
NEDMALLOCEXTSPEC NEDMALLOCNOALIASATTR NEDMALLOCPTRATTR void * nedmalloc(size_t size) THROWSPEC;
NEDMALLOCEXTSPEC NEDMALLOCNOALIASATTR NEDMALLOCPTRATTR void * nedcalloc(size_t no, size_t size) THROWSPEC;
NEDMALLOCEXTSPEC NEDMALLOCNOALIASATTR NEDMALLOCPTRATTR void * nedrealloc(void *mem, size_t size) THROWSPEC;
NEDMALLOCEXTSPEC NEDMALLOCNOALIASATTR void nedfree(void *mem) THROWSPEC;
NEDMALLOCEXTSPEC NEDMALLOCNOALIASATTR NEDMALLOCPTRATTR void * nedmemalign(size_t alignment, size_t bytes) THROWSPEC;
NEDMALLOCEXTSPEC NEDMALLOCNOALIASATTR struct nedmallinfo nedmallinfo(void) THROWSPEC;
NEDMALLOCEXTSPEC NEDMALLOCNOALIASATTR int nedmallopt(int parno, int value) THROWSPEC;
NEDMALLOCEXTSPEC NEDMALLOCNOALIASATTR void* nedmalloc_internals(size_t *granularity, size_t *magic) THROWSPEC;
NEDMALLOCEXTSPEC NEDMALLOCNOALIASATTR int nedmalloc_trim(size_t pad) THROWSPEC;
NEDMALLOCEXTSPEC void nedmalloc_stats(void) THROWSPEC;
NEDMALLOCEXTSPEC size_t nedmalloc_footprint(void) THROWSPEC;
NEDMALLOCEXTSPEC NEDMALLOCPTRATTR void **nedindependent_calloc(size_t elemsno, size_t elemsize, void **chunks) THROWSPEC;
NEDMALLOCEXTSPEC NEDMALLOCPTRATTR void **nedindependent_comalloc(size_t elems, size_t *sizes, void **chunks) THROWSPEC;
NEDMALLOCEXTSPEC NEDMALLOCNOALIASATTR size_t nedmalloc_footprint(void) THROWSPEC;
NEDMALLOCEXTSPEC NEDMALLOCNOALIASATTR NEDMALLOCPTRATTR void **nedindependent_calloc(size_t elemsno, size_t elemsize, void **chunks) THROWSPEC;
NEDMALLOCEXTSPEC NEDMALLOCNOALIASATTR NEDMALLOCPTRATTR void **nedindependent_comalloc(size_t elems, size_t *sizes, void **chunks) THROWSPEC;
/* Destroys the system memory pool used by the functions above.
Useful for when you have nedmalloc in a DLL you're about to unload.

View file

@ -14,6 +14,7 @@ extern char cullmodel[MAXSPRITES];
extern int32_t cullcheckcnt;
#define PI 3.14159265358979323
extern char TEXCACHEFILE[BMAX_PATH];
typedef struct { char r, g, b, a; } coltype;

View file

@ -72,9 +72,6 @@ static int32_t lockrecip[200];
static char toupperlookup[256];
extern void *kmalloc(size_t);
extern void kfree(void *);
static void reportandexit(char *errormessage);
extern char pow2char[8];
@ -398,10 +395,6 @@ BFILE* fopenfrompath(const char *fn, const char *mode)
return h;
}
#define MAXGROUPFILES 8 //Warning: Fix groupfil if this is changed
#define MAXOPENFILES 64 //Warning: Fix filehan if this is changed
static char toupperlookup[256] =
{
0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,
@ -429,7 +422,7 @@ static int32_t groupfilpos[MAXGROUPFILES];
static char *gfilelist[MAXGROUPFILES];
static int32_t *gfileoffs[MAXGROUPFILES];
static char filegrp[MAXOPENFILES];
char filegrp[MAXOPENFILES];
static int32_t filepos[MAXOPENFILES];
static intptr_t filehan[MAXOPENFILES] =
{
@ -495,9 +488,9 @@ int32_t initgroupfile(char *filename)
}
gnumfiles[numgroupfiles] = B_LITTLE32(*((int32_t *)&buf[12]));
if ((gfilelist[numgroupfiles] = (char *)kmalloc(gnumfiles[numgroupfiles]<<4)) == 0)
if ((gfilelist[numgroupfiles] = (char *)Bmalloc(gnumfiles[numgroupfiles]<<4)) == 0)
{ Bprintf("Not enough memory for file grouping system\n"); exit(0); }
if ((gfileoffs[numgroupfiles] = (int32_t *)kmalloc((gnumfiles[numgroupfiles]+1)<<2)) == 0)
if ((gfileoffs[numgroupfiles] = (int32_t *)Bmalloc((gnumfiles[numgroupfiles]+1)<<2)) == 0)
{ Bprintf("Not enough memory for file grouping system\n"); exit(0); }
Bread(groupfil[numgroupfiles],gfilelist[numgroupfiles],gnumfiles[numgroupfiles]<<4);
@ -523,8 +516,8 @@ void uninitsinglegroupfile(int32_t grphandle)
for (i=numgroupfiles-1; i>=0; i--)
if (groupfil[i] != -1 && groupfil[i] == grphandle)
{
kfree(gfilelist[i]);
kfree(gfileoffs[i]);
Bfree(gfilelist[i]);
Bfree(gfileoffs[i]);
Bclose(groupfil[i]);
groupfil[i] = -1;
grpnum = i;
@ -567,8 +560,8 @@ void uninitgroupfile(void)
for (i=numgroupfiles-1; i>=0; i--)
if (groupfil[i] != -1)
{
kfree(gfilelist[i]);
kfree(gfileoffs[i]);
Bfree(gfilelist[i]);
Bfree(gfileoffs[i]);
Bclose(groupfil[i]);
groupfil[i] = -1;
}

View file

@ -15,6 +15,7 @@
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#define _WIN32_IE 0x0400
#define _WIN32_WINNT 0x0500
#include <windows.h>
#include <shlobj.h>
#include <direct.h>
@ -26,6 +27,7 @@
#include <fcntl.h>
#include <sys/types.h>
// #include <sys/stat.h>
#include <limits.h>
#ifdef __APPLE__
#if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_3
@ -41,7 +43,7 @@
#endif
#include "compat.h"
#include "baselayer.h"
#ifndef __compat_h_macrodef__
@ -774,35 +776,59 @@ char *Bstrupr(char *s)
//
// getsysmemsize() -- gets the amount of system memory in the machine
// Bgetsysmemsize() -- gets the amount of system memory in the machine
//
uint32_t Bgetsysmemsize(void)
{
#ifdef _WIN32
MEMORYSTATUS memst;
GlobalMemoryStatus(&memst);
return (uint32_t)memst.dwTotalPhys;
#elif (defined(_SC_PAGE_SIZE) || defined(_SC_PAGESIZE)) && defined(_SC_PHYS_PAGES)
uint32_t siz = 0x7fffffff;
int32_t scpagesiz, scphyspages;
#ifdef _SC_PAGE_SIZE
scpagesiz = sysconf(_SC_PAGE_SIZE);
#else
scpagesiz = sysconf(_SC_PAGESIZE);
#endif
scphyspages = sysconf(_SC_PHYS_PAGES);
if (scpagesiz >= 0 && scphyspages >= 0)
siz = (uint32_t)min(longlong(0x7fffffff), (int64_t)scpagesiz * (int64_t)scphyspages);
//initprintf("Bgetsysmemsize(): %d pages of %d bytes, %d bytes of system memory\n",
// scphyspages, scpagesiz, siz);
return siz;
#else
return 0x7fffffff;
#endif
}
uint32_t Bgetsysmemsize(void)
{
#ifdef _WIN32
uint32_t siz = UINT_MAX;
HMODULE lib = LoadLibrary("KERNEL32.DLL");
if (lib)
{
WINBASEAPI BOOL WINAPI (*aGlobalMemoryStatusEx)(LPMEMORYSTATUSEX) =
(void *)GetProcAddress(lib, "GlobalMemoryStatusEx");
if (aGlobalMemoryStatusEx)
{
//WinNT
MEMORYSTATUSEX memst;
memst.dwLength = sizeof(MEMORYSTATUSEX);
if (aGlobalMemoryStatusEx(&memst))
siz = (uint32_t)min(UINT_MAX, memst.ullTotalPhys);
}
else
{
// Yeah, there's enough Win9x hatred here that a perfectly good workaround
// has been replaced by an error message. Oh well, we don't support 9x anyway.
initprintf("Bgetsysmemsize(): error determining system memory size!\n");
}
FreeLibrary(lib);
}
return siz;
#elif (defined(_SC_PAGE_SIZE) || defined(_SC_PAGESIZE)) && defined(_SC_PHYS_PAGES)
uint32_t siz = UINT_MAX;
int64_t scpagesiz, scphyspages;
#ifdef _SC_PAGE_SIZE
scpagesiz = sysconf(_SC_PAGE_SIZE);
#else
scpagesiz = sysconf(_SC_PAGESIZE);
#endif
scphyspages = sysconf(_SC_PHYS_PAGES);
if (scpagesiz >= 0 && scphyspages >= 0)
siz = (uint32_t)min(UINT_MAX, (int64_t)scpagesiz * (int64_t)scphyspages);
//initprintf("Bgetsysmemsize(): %d pages of %d bytes, %d bytes of system memory\n",
// scphyspages, scpagesiz, siz);
return siz;
#else
return UINT_MAX;
#endif
}

View file

@ -42,12 +42,6 @@
#include "engine_priv.h"
void *kmalloc(bsize_t size) { return(Bmalloc(size)); }
#define kkmalloc kmalloc
void kfree(void *buffer) { Bfree(buffer); }
#define kkfree kfree
#ifdef SUPERBUILD
void loadvoxel(int32_t voxindex) { voxindex=0; }
int32_t tiletovox[MAXTILES];
@ -103,6 +97,10 @@ int32_t tilefileoffs[MAXTILES];
int32_t artsize = 0, cachesize = 0;
// unlikely to occur, but .art files with less than 256 tiles are certainly possible
// this would be 60 (MAXTILES/256) if we just assumed there were 256 tiles per .art as in Duke
char *artptrs[256];
static int16_t radarang2[MAXXDIM];
static uint16_t sqrtable[4096], shlookup[4096+256];
char pow2char[8] = {1,2,4,8,16,32,64,128};
@ -5127,9 +5125,9 @@ static void loadpalette(void)
kread(fil,palette,768);
kread(fil,&numpalookups,2); numpalookups = B_LITTLE16(numpalookups);
if ((palookup[0] = (char *)kkmalloc(numpalookups<<8)) == NULL)
if ((palookup[0] = (char *)Bmalloc(numpalookups<<8)) == NULL)
allocache((intptr_t*)&palookup[0],numpalookups<<8,&permanentlock);
if ((transluc = (char *)kkmalloc(65536L)) == NULL)
if ((transluc = (char *)Bmalloc(65536L)) == NULL)
allocache((intptr_t*)&transluc,65536,&permanentlock);
globalpalwritten = palookup[0]; globalpal = 0;
@ -5148,7 +5146,7 @@ static void loadpalette(void)
//
// getclosestcol (internal)
// getclosestcol
//
int32_t getclosestcol(int32_t r, int32_t g, int32_t b)
{
@ -5637,17 +5635,29 @@ void uninitengine(void)
uninitsystem();
if (artfil != -1) kclose(artfil);
if (transluc != NULL) { kkfree(transluc); transluc = NULL; }
if (pic != NULL) { kkfree(pic); pic = NULL; }
i=(sizeof(artptrs)/sizeof(intptr_t))-1;
// this leaves a bunch of invalid pointers in waloff... fixme?
for(; i>=0; i--)
{
if (artptrs[i])
{
Bfree(artptrs[i]);
artptrs[i] = NULL;
}
}
if (transluc != NULL) { Bfree(transluc); transluc = NULL; }
if (pic != NULL) { Bfree(pic); pic = NULL; }
if (lookups != NULL)
{
if (lookupsalloctype == 0) kkfree((void *)lookups);
if (lookupsalloctype == 0) Bfree((void *)lookups);
//if (lookupsalloctype == 1) suckcache(lookups); //Cache already gone
lookups = NULL;
}
for (i=0; i<MAXPALOOKUPS; i++)
if (palookup[i] != NULL) { kkfree(palookup[i]); palookup[i] = NULL; }
if (palookup[i] != NULL) { Bfree(palookup[i]); palookup[i] = NULL; }
#ifdef DYNALLOC_ARRAYS
if (sector != NULL)
@ -7714,12 +7724,12 @@ int32_t setgamemode(char davidoption, int32_t daxdim, int32_t daydim, int32_t da
if (lookups != NULL)
{
if (lookupsalloctype == 0) kkfree((void *)lookups);
if (lookupsalloctype == 0) Bfree((void *)lookups);
if (lookupsalloctype == 1) suckcache(lookups);
lookups = NULL;
}
lookupsalloctype = 0;
if ((lookups = (intptr_t *)kkmalloc(j<<1)) == NULL)
if ((lookups = (intptr_t *)Bmalloc(j<<1)) == NULL)
{
allocache((intptr_t *)&lookups,j<<1,&permanentlock);
lookupsalloctype = 1;
@ -7839,7 +7849,6 @@ void nextpage(void)
numframes++;
}
//
// loadpics
//
@ -7897,6 +7906,14 @@ int32_t loadpics(char *filename, int32_t askedsize)
offscount += dasiz;
artsize += ((dasiz+15)&0xfffffff0);
}
if (filegrp[fil] == 254) // from zip
{
i = kfilelength(fil);
artptrs[numtilefiles] = Brealloc(artptrs[numtilefiles], i);
klseek(fil, 0, BSEEK_SET);
kread(fil, artptrs[numtilefiles], i);
}
kclose(fil);
}
numtilefiles++;
@ -7912,7 +7929,7 @@ int32_t loadpics(char *filename, int32_t askedsize)
cachesize = (Bgetsysmemsize()/100)*60;
else
cachesize = askedsize;
while ((pic = kkmalloc(cachesize)) == NULL)
while ((pic = Bmalloc(cachesize)) == NULL)
{
cachesize -= 65536L;
if (cachesize < 65536) return(-1);
@ -7942,14 +7959,19 @@ int32_t loadpics(char *filename, int32_t askedsize)
//
void loadtile(int16_t tilenume)
{
char *ptr;
int32_t i, dasiz;
if ((unsigned)tilenume >= (unsigned)MAXTILES) return;
dasiz = tilesizx[tilenume]*tilesizy[tilenume];
if (dasiz <= 0) return;
if ((dasiz = tilesizx[tilenume]*tilesizy[tilenume]) <= 0) return;
if (artptrs[(i = tilefilenum[tilenume])]) // from zip
{
waloff[tilenume] = (intptr_t)(artptrs[i] + tilefileoffs[tilenume]);
faketimerhandler();
// OSD_Printf("loaded tile %d from zip\n", tilenume);
return;
}
i = tilefilenum[tilenume];
if (i != artfilnum)
{
if (artfil != -1) kclose(artfil);
@ -7965,29 +7987,37 @@ void loadtile(int16_t tilenume)
if (cachedebug) printOSD("Tile:%d\n",tilenume);
if (waloff[tilenume] == 0)
{
walock[tilenume] = 199;
allocache(&waloff[tilenume],dasiz,&walock[tilenume]);
}
// dummy tiles for highres replacements and tilefromtexture definitions
if (faketilesiz[tilenume])
{
if (faketilesiz[tilenume] == -1)
Bmemset((char *)waloff[tilenume],0,dasiz);
else if (faketiledata[tilenume] != NULL)
qlz_decompress(faketiledata[tilenume], (char *)waloff[tilenume], state_decompress);
{
walock[tilenume] = 255; // permanent tile
allocache(&waloff[tilenume],dasiz,&walock[tilenume]);
qlz_decompress(faketiledata[tilenume], (char *)waloff[tilenume], state_decompress);
Bfree(faketiledata[tilenume]);
faketiledata[tilenume] = NULL;
}
faketimerhandler();
return;
}
if (waloff[tilenume] == 0)
{
walock[tilenume] = 199;
allocache(&waloff[tilenume],dasiz,&walock[tilenume]);
}
if (artfilplc != tilefileoffs[tilenume])
{
klseek(artfil,tilefileoffs[tilenume]-artfilplc,BSEEK_CUR);
faketimerhandler();
}
ptr = (char *)waloff[tilenume];
kread(artfil,ptr,dasiz);
kread(artfil, (char *)waloff[tilenume], dasiz);
faketimerhandler();
artfilplc = tilefileoffs[tilenume]+dasiz;
}
@ -9819,7 +9849,7 @@ void makepalookup(int32_t palnum, char *remapbuf, int8_t r, int8_t g, int8_t b,
if (palookup[palnum] == NULL)
{
//Allocate palookup buffer
if ((palookup[palnum] = (char *)kkmalloc(numpalookups<<8)) == NULL)
if ((palookup[palnum] = (char *)Bmalloc(numpalookups<<8)) == NULL)
allocache((intptr_t*)&palookup[palnum],numpalookups<<8,&permanentlock);
}
@ -10187,26 +10217,36 @@ void setviewback(void)
//
// squarerotatetile
//
#ifdef __GNUC__
#define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
#if (GCC_VERSION >= 40400)
#pragma GCC optimize("0")
#endif
#endif
void squarerotatetile(int16_t tilenume)
{
int32_t i, j, k, xsiz, ysiz;
char *ptr1, *ptr2;
xsiz = tilesizx[tilenume]; ysiz = tilesizy[tilenume];
int32_t siz;
//supports square tiles only for rotation part
if (xsiz == ysiz)
if ((siz = tilesizx[tilenume]) == tilesizy[tilenume])
{
k = (xsiz<<1);
for (i=xsiz-1; i>=0; i--)
int32_t i = siz-1;
for (; i>=0; i--)
{
ptr1 = (char *)(waloff[tilenume]+i*(xsiz+1)); ptr2 = ptr1;
if ((i&1) != 0) { ptr1--; ptr2 -= xsiz; swapchar(ptr1,ptr2); }
for (j=(i>>1)-1; j>=0; j--)
{ ptr1 -= 2; ptr2 -= k; swapchar2(ptr1,ptr2,xsiz); }
int32_t j=(i>>1)-1;
char *ptr1 = (char *)(waloff[tilenume]+i*(siz+1)), *ptr2 = ptr1;
if (i&1) swapchar(--ptr1, (ptr2 -= siz));
for (; j>=0; j--) swapchar2((ptr1 -= 2), (ptr2 -= (siz<<1)), siz);
}
}
}
#ifdef __GNUC__
#if (GCC_VERSION >= 40400)
#pragma GCC reset_options
#endif
#undef GCC_VERSION
#endif
//
@ -11693,7 +11733,7 @@ int32_t screencapture_tga(char *filename, char inverseit)
// targa renders bottom to top, from left to right
if (inverseit && qsetmode != 200)
{
inversebuf = (char *)kmalloc(bytesperline);
inversebuf = (char *)Bmalloc(bytesperline);
if (inversebuf)
{
for (i=ydim-1; i>=0; i--)
@ -11702,7 +11742,7 @@ int32_t screencapture_tga(char *filename, char inverseit)
for (j=0; j < (bytesperline>>2); j++)((int32_t *)inversebuf)[j] ^= 0x0f0f0f0fL;
Bfwrite(inversebuf, xdim, 1, fil);
}
kfree(inversebuf);
Bfree(inversebuf);
}
}
else
@ -11712,7 +11752,7 @@ int32_t screencapture_tga(char *filename, char inverseit)
{
char c;
// 24bit
inversebuf = (char *)kmalloc(xdim*ydim*3);
inversebuf = (char *)Bmalloc(xdim*ydim*3);
if (inversebuf)
{
bglReadPixels(0,0,xdim,ydim,GL_RGB,GL_UNSIGNED_BYTE,inversebuf);
@ -11724,7 +11764,7 @@ int32_t screencapture_tga(char *filename, char inverseit)
inversebuf[i+2] = c;
}
Bfwrite(inversebuf, xdim*ydim, 3, fil);
kfree(inversebuf);
Bfree(inversebuf);
}
}
else
@ -11867,7 +11907,7 @@ int32_t screencapture_pcx(char *filename, char inverseit)
// targa renders bottom to top, from left to right
if (inverseit && qsetmode != 200)
{
inversebuf = (char *)kmalloc(bytesperline);
inversebuf = (char *)Bmalloc(bytesperline);
if (inversebuf)
{
for (i=0; i<ydim; i++)
@ -11876,7 +11916,7 @@ int32_t screencapture_pcx(char *filename, char inverseit)
for (j=0; j < (bytesperline>>2); j++)((int32_t *)inversebuf)[j] ^= 0x0f0f0f0fL;
writepcxline(inversebuf, xdim, 1, fil);
}
kfree(inversebuf);
Bfree(inversebuf);
}
}
else
@ -11885,7 +11925,7 @@ int32_t screencapture_pcx(char *filename, char inverseit)
if (rendmode >= 3 && qsetmode == 200)
{
// 24bit
inversebuf = (char *)kmalloc(xdim*ydim*3);
inversebuf = (char *)Bmalloc(xdim*ydim*3);
if (inversebuf)
{
bglReadPixels(0,0,xdim,ydim,GL_RGB,GL_UNSIGNED_BYTE,inversebuf);
@ -11895,7 +11935,7 @@ int32_t screencapture_pcx(char *filename, char inverseit)
writepcxline(inversebuf+i*xdim*3+1, xdim, 3, fil);
writepcxline(inversebuf+i*xdim*3+2, xdim, 3, fil);
}
kfree(inversebuf);
Bfree(inversebuf);
}
}
else

View file

@ -41,9 +41,11 @@ DEALINGS IN THE SOFTWARE.
#define FINEGRAINEDBINS 1
#define ENABLE_LARGE_PAGES 1
#define ENABLE_FAST_HEAP_DETECTION 1
#define NDEBUG 1
/*#define ENABLE_TOLERANT_NEDMALLOC 1*/
/*#define ENABLE_FAST_HEAP_DETECTION 1*/
/*#define NEDMALLOC_DEBUG 1*/
/*#define FULLSANITYCHECKS*/
/* If link time code generation is on, don't force or prevent inlining */
@ -66,19 +68,12 @@ DEALINGS IN THE SOFTWARE.
#define USE_LOCKS 1
#endif
#define FOOTERS 1 /* Need to enable footers so frees lock the right mspace */
#if defined(DEBUG) && !defined(_DEBUG)
#define _DEBUG
#elif !defined(NDEBUG) && !defined(DEBUG) && !defined(_DEBUG)
#define NDEBUG
#endif
#undef DEBUG /* dlmalloc wants DEBUG either 0 or 1 */
#ifdef _DEBUG
#define DEBUG 1
#else
#ifndef NEDMALLOC_DEBUG #if defined(DEBUG) || defined(_DEBUG) #define NEDMALLOC_DEBUG 1 #else #define NEDMALLOC_DEBUG 0 #endif #endif /* We need to consistently define DEBUG=0|1, _DEBUG and NDEBUG for dlmalloc */ #undef DEBUG #undef _DEBUG #if NEDMALLOC_DEBUG #define _DEBUG #else
#define DEBUG 0
#endif
#ifdef NDEBUG /* Disable assert checking on release builds */
#undef DEBUG
#undef _DEBUG
#endif
/* The default of 64Kb means we spend too much time kernel-side */
#ifndef DEFAULT_GRANULARITY
@ -89,17 +84,8 @@ DEALINGS IN THE SOFTWARE.
#endif
/*#define USE_SPIN_LOCKS 0*/
#include "malloc.c.h"
#ifdef NDEBUG /* Disable assert checking on release builds */
#undef DEBUG
#endif
#if defined(__GNUC__) && defined(DEBUG)
#warning DEBUG is defined so allocator will run with assert checking! Define NDEBUG to run at full speed.
#endif
/* The maximum concurrent threads in a pool possible */
#ifndef MAXTHREADSINPOOL
#include "malloc.c.h" #ifdef NDEBUG /* Disable assert checking on release builds */ #undef DEBUG #elif !NEDMALLOC_DEBUG #ifdef __GNUC__ #warning DEBUG is defined so allocator will run with assert checking! Define NDEBUG to run at full speed. #elif defined(_MSC_VER) #pragma message(__FILE__ ": WARNING: DEBUG is defined so allocator will run with assert checking! Define NDEBUG to run at full speed.") #endif #endif
/* The maximum concurrent threads in a pool possible */#ifndef MAXTHREADSINPOOL
#define MAXTHREADSINPOOL 16
#endif
/* The maximum number of threadcaches which can be allocated */
@ -169,20 +155,7 @@ static void *RESTRICT leastusedaddress;
static size_t largestusedblock;
#endif
static FORCEINLINE void *CallMalloc(void *RESTRICT mspace, size_t size, size_t alignment) THROWSPEC
{
void *RESTRICT ret=0;
#if USE_MAGIC_HEADERS
size_t *_ret=0;
size+=alignment+3*sizeof(size_t);
#endif
#if USE_ALLOCATOR==0
ret=malloc(size);
#elif USE_ALLOCATOR==1
ret=mspace_malloc((mstate) mspace, size);
#ifndef ENABLE_FAST_HEAP_DETECTION
if(ret)
{
static FORCEINLINE void *CallMalloc(void *RESTRICT mspace, size_t size, size_t alignment) THROWSPEC { void *RESTRICT ret=0; size_t _alignment=alignment; #if USE_MAGIC_HEADERS size_t *_ret=0; size+=alignment+3*sizeof(size_t); _alignment=0; #endif #if USE_ALLOCATOR==0 ret=_alignment ? #ifdef _MSC_VER /* This is the MSVCRT equivalent */ _aligned_malloc(size, _alignment) #elif defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__) /* This is the glibc/ptmalloc2/dlmalloc/BSD libc equivalent. */ memalign(_alignment, size) #else #error Cannot aligned allocate with the memory allocator of an unknown system! #endif : malloc(size); #elif USE_ALLOCATOR==1 ret=_alignment ? mspace_memalign((mstate) mspace, _alignment, size) : mspace_malloc((mstate) mspace, size); #ifndef ENABLE_FAST_HEAP_DETECTION if(ret) {
size_t truesize=chunksize(mem2chunk(ret));
if(!leastusedaddress || (void *)((mstate) mspace)->least_addr<leastusedaddress) leastusedaddress=(void *)((mstate) mspace)->least_addr;
if(!largestusedblock || truesize>largestusedblock) largestusedblock=(truesize+mparams.page_size) & ~(mparams.page_size-1);
@ -491,19 +464,19 @@ NEDMALLOCNOALIASATTR size_t nedblksize(int *RESTRICT isforeign, void *RESTRICT m
return 0;
}
void nedsetvalue(void *v) THROWSPEC { nedpsetvalue((nedpool *) 0, v); }
NEDMALLOCPTRATTR void * nedmalloc(size_t size) THROWSPEC { return nedpmalloc((nedpool *) 0, size); }
NEDMALLOCPTRATTR void * nedcalloc(size_t no, size_t size) THROWSPEC { return nedpcalloc((nedpool *) 0, no, size); }
NEDMALLOCPTRATTR void * nedrealloc(void *mem, size_t size) THROWSPEC { return nedprealloc((nedpool *) 0, mem, size); }
void nedfree(void *mem) THROWSPEC { nedpfree((nedpool *) 0, mem); }
NEDMALLOCPTRATTR void * nedmemalign(size_t alignment, size_t bytes) THROWSPEC { return nedpmemalign((nedpool *) 0, alignment, bytes); }
struct nedmallinfo nedmallinfo(void) THROWSPEC { return nedpmallinfo((nedpool *) 0); }
int nedmallopt(int parno, int value) THROWSPEC { return nedpmallopt((nedpool *) 0, parno, value); }
int nedmalloc_trim(size_t pad) THROWSPEC { return nedpmalloc_trim((nedpool *) 0, pad); }
NEDMALLOCNOALIASATTR void nedsetvalue(void *v) THROWSPEC { nedpsetvalue((nedpool *) 0, v); }
NEDMALLOCNOALIASATTR NEDMALLOCPTRATTR void * nedmalloc(size_t size) THROWSPEC { return nedpmalloc((nedpool *) 0, size); }
NEDMALLOCNOALIASATTR NEDMALLOCPTRATTR void * nedcalloc(size_t no, size_t size) THROWSPEC { return nedpcalloc((nedpool *) 0, no, size); }
NEDMALLOCNOALIASATTR NEDMALLOCPTRATTR void * nedrealloc(void *mem, size_t size) THROWSPEC { return nedprealloc((nedpool *) 0, mem, size); }
NEDMALLOCNOALIASATTR void nedfree(void *mem) THROWSPEC { nedpfree((nedpool *) 0, mem); }
NEDMALLOCNOALIASATTR NEDMALLOCPTRATTR void * nedmemalign(size_t alignment, size_t bytes) THROWSPEC { return nedpmemalign((nedpool *) 0, alignment, bytes); }
NEDMALLOCNOALIASATTR struct nedmallinfo nedmallinfo(void) THROWSPEC { return nedpmallinfo((nedpool *) 0); }
NEDMALLOCNOALIASATTR int nedmallopt(int parno, int value) THROWSPEC { return nedpmallopt((nedpool *) 0, parno, value); }
NEDMALLOCNOALIASATTR int nedmalloc_trim(size_t pad) THROWSPEC { return nedpmalloc_trim((nedpool *) 0, pad); }
void nedmalloc_stats() THROWSPEC { nedpmalloc_stats((nedpool *) 0); }
size_t nedmalloc_footprint() THROWSPEC { return nedpmalloc_footprint((nedpool *) 0); }
NEDMALLOCNOALIASATTR size_t nedmalloc_footprint() THROWSPEC { return nedpmalloc_footprint((nedpool *) 0); }
NEDMALLOCPTRATTR void **nedindependent_calloc(size_t elemsno, size_t elemsize, void **chunks) THROWSPEC { return nedpindependent_calloc((nedpool *) 0, elemsno, elemsize, chunks); }
// NEDMALLOCPTRATTR void **nedindependent_comalloc(size_t elems, size_t *sizes, void **chunks) THROWSPEC { return nedpindependent_comalloc((nedpool *) 0, elems, sizes, chunks); }
// NEDMALLOCNOALIASATTR NEDMALLOCPTRATTR void **nedindependent_comalloc(size_t elems, size_t *sizes, void **chunks) THROWSPEC { return nedpindependent_comalloc((nedpool *) 0, elems, sizes, chunks); }
struct threadcacheblk_t;
typedef struct threadcacheblk_t threadcacheblk;
@ -832,7 +805,7 @@ static void threadcache_free(nedpool *RESTRICT p, threadcache *RESTRICT tc, int
idx<<=1;
if(size>bestsize)
{
unsigned int biggerbestsize=bestsize+bestsize<<1;
unsigned int biggerbestsize=(bestsize+bestsize)<<1;
if(size>=biggerbestsize)
{
idx++;
@ -1356,7 +1329,7 @@ int nedpmallopt(nedpool *p, int parno, int value) THROWSPEC
return 0;
#endif
}
void* nedmalloc_internals(size_t *granularity, size_t *magic) THROWSPEC
NEDMALLOCNOALIASATTR void* nedmalloc_internals(size_t *granularity, size_t *magic) THROWSPEC
{
#if USE_ALLOCATOR==1
if(granularity) *granularity=mparams.granularity;
@ -1444,7 +1417,7 @@ NEDMALLOCPTRATTR void **nedpindependent_comalloc(nedpool *p, size_t elems, size_
// cheap replacement for strdup so we aren't feeding system allocated blocks into nedmalloc
NEDMALLOCPTRATTR char *nedstrdup(const char *str) THROWSPEC
NEDMALLOCNOALIASATTR NEDMALLOCPTRATTR char *nedstrdup(const char *str) THROWSPEC
{
int n = strlen(str) + 1;
char *dup = nedmalloc(n);

View file

@ -492,8 +492,7 @@ void uninitinput(void)
const char *getkeyname(int32_t num)
{
if ((unsigned)num >= 256) return NULL;
return key_names[num];
return ((unsigned)num >= 256) ? NULL : key_names[num];
}
const char *getjoyname(int32_t what, int32_t num)
@ -527,11 +526,14 @@ const char *getjoyname(int32_t what, int32_t num)
//
char bgetchar(void)
{
char c;
if (keyasciififoplc == keyasciififoend) return 0;
c = keyasciififo[keyasciififoplc];
keyasciififoplc = ((keyasciififoplc+1)&(KEYFIFOSIZ-1));
return c;
if (keyasciififoplc == keyasciififoend)
return 0;
{
char c = keyasciififo[keyasciififoplc];
keyasciififoplc = ((keyasciififoplc+1)&(KEYFIFOSIZ-1));
return c;
}
}
int32_t bkbhit(void)

View file

@ -277,9 +277,12 @@ int32_t WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, in
FILE *fp;
HDC hdc;
UNREFERENCED_PARAMETER(lpCmdLine);
UNREFERENCED_PARAMETER(nCmdShow);
hInstance = hInst;
if (CheckWinVersion() || hPrevInst)
if (!CheckWinVersion() || hPrevInst)
{
MessageBox(0, "This application requires Windows 2000 or better to run.",
apptitle, MB_OK|MB_ICONSTOP);
@ -313,9 +316,6 @@ int32_t WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, in
// atexit(neddestroysyspool);
UNREFERENCED_PARAMETER(lpCmdLine);
UNREFERENCED_PARAMETER(nCmdShow);
hdc = GetDC(NULL);
r = GetDeviceCaps(hdc, BITSPIXEL);
ReleaseDC(NULL, hdc);
@ -1609,8 +1609,7 @@ static void GetKeyNames(void)
const char *getkeyname(int32_t num)
{
if ((unsigned)num >= 256) return NULL;
return key_names[num];
return ((unsigned)num >= 256) ? NULL : key_names[num];
}
const char *getjoyname(int32_t what, int32_t num)
@ -1618,17 +1617,11 @@ const char *getjoyname(int32_t what, int32_t num)
switch (what)
{
case 0: // axis
if ((unsigned)num > (unsigned)joynumaxes) return NULL;
return (char *)axisdefs[num].name;
return ((unsigned)num > (unsigned)joynumaxes) ? NULL : (char *)axisdefs[num].name;
case 1: // button
if ((unsigned)num > (unsigned)joynumbuttons) return NULL;
return (char *)buttondefs[num].name;
return ((unsigned)num > (unsigned)joynumbuttons) ? NULL : (char *)buttondefs[num].name;
case 2: // hat
if ((unsigned)num > (unsigned)joynumhats) return NULL;
return (char *)hatdefs[num].name;
return ((unsigned)num > (unsigned)joynumhats) ? NULL : (char *)hatdefs[num].name;
default:
return NULL;
}
@ -4210,17 +4203,18 @@ static inline BOOL CheckWinVersion(void)
ZeroMemory(&osv, sizeof(osv));
osv.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
if (!GetVersionEx(&osv)) return TRUE;
// we don't like anything older than Windows 2000, but the BUILD_WIN9X
// variable allows attempting to run on 9x (for masochists and sodomites)
// we don't like anything older than Windows 2000
else if (osv.dwMajorVersion >= 5) return FALSE;
if (!GetVersionEx(&osv)) return FALSE;
// BUILD_WIN9X variable allows attempting to run on 9x, for masochists and sodomites
else if (Bgetenv("BUILD_WIN9X") != NULL && osv.dwMajorVersion == 4 &&
if (osv.dwMajorVersion >= 5) return TRUE;
if (Bgetenv("BUILD_WIN9X") != NULL && osv.dwMajorVersion == 4 &&
osv.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
return FALSE;
return TRUE;
else return TRUE;
return FALSE;
}