64 bit compatibility effort, 1/nn: type correctness work in common.c,

common.h, gl_vidsdl.c, mathlib.h, zone.c, zone.h. added Z_Realloc as a
new function (will be used later.) next step will be type correctness
work in opengl stuff.


git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@33 af15c1b1-3010-417e-b628-4374ebc0bcbd
This commit is contained in:
Ozkan Sezer 2010-02-16 21:22:20 +00:00
parent c04d5309f9
commit 9e861e3102
6 changed files with 72 additions and 46 deletions

View File

@ -150,11 +150,11 @@ void InsertLinkAfter (link_t *l, link_t *after)
============================================================================ ============================================================================
*/ */
void Q_memset (void *dest, int fill, int count) void Q_memset (void *dest, int fill, size_t count)
{ {
int i; size_t i;
if ( (((long)dest | count) & 3) == 0) if ( (((size_t)dest | count) & 3) == 0)
{ {
count >>= 2; count >>= 2;
fill = fill | (fill<<8) | (fill<<16) | (fill<<24); fill = fill | (fill<<8) | (fill<<16) | (fill<<24);
@ -166,11 +166,11 @@ void Q_memset (void *dest, int fill, int count)
((byte *)dest)[i] = fill; ((byte *)dest)[i] = fill;
} }
void Q_memcpy (void *dest, const void *src, int count) void Q_memcpy (void *dest, const void *src, size_t count)
{ {
int i; size_t i;
if (( ( (long)dest | (long)src | count) & 3) == 0 ) if (( ( (size_t)dest | (size_t)src | count) & 3) == 0 )
{ {
count>>=2; count>>=2;
for (i=0 ; i<count ; i++) for (i=0 ; i<count ; i++)
@ -181,7 +181,7 @@ void Q_memcpy (void *dest, const void *src, int count)
((byte *)dest)[i] = ((byte *)src)[i]; ((byte *)dest)[i] = ((byte *)src)[i];
} }
int Q_memcmp (const void *m1, const void *m2, int count) int Q_memcmp (const void *m1, const void *m2, size_t count)
{ {
while(count) while(count)
{ {

View File

@ -124,9 +124,9 @@ float MSG_ReadAngle16 (void); //johnfitz
//============================================================================ //============================================================================
void Q_memset (void *dest, int fill, int count); void Q_memset (void *dest, int fill, size_t count);
void Q_memcpy (void *dest, const void *src, int count); void Q_memcpy (void *dest, const void *src, size_t count);
int Q_memcmp (const void *m1, const void *m2, int count); int Q_memcmp (const void *m1, const void *m2, size_t count);
void Q_strcpy (char *dest, const char *src); void Q_strcpy (char *dest, const char *src);
void Q_strncpy (char *dest, const char *src, int count); void Q_strncpy (char *dest, const char *src, int count);
int Q_strlen (const char *str); int Q_strlen (const char *str);

View File

@ -243,7 +243,7 @@ int VID_SetMode (int modenum)
{ {
int temp; int temp;
qboolean stat; qboolean stat;
long int flags = SDL_DEFAULT_FLAGS; Uint32 flags = SDL_DEFAULT_FLAGS;
char caption[50]; char caption[50];
//TODO: check if video mode is supported using SDL_VideoModeOk //TODO: check if video mode is supported using SDL_VideoModeOk
@ -1092,7 +1092,7 @@ void VID_InitFullDIB ()
{ {
SDL_PixelFormat format; SDL_PixelFormat format;
SDL_Rect **modes; SDL_Rect **modes;
long int flags; Uint32 flags;
int i, j, k, modenum, originalnummodes, existingmode; int i, j, k, modenum, originalnummodes, existingmode;
int bpps[3] = {16, 24, 32}; // enumerate >8 bpp modes int bpps[3] = {16, 24, 32}; // enumerate >8 bpp modes

View File

@ -58,7 +58,7 @@ extern int nanmask;
_number = DotProduct(_v, _v);\ _number = DotProduct(_v, _v);\
if (_number != 0.0)\ if (_number != 0.0)\
{\ {\
*((long *)&_y) = 0x5f3759df - ((* (long *) &_number) >> 1);\ *((int *)&_y) = 0x5f3759df - ((* (int *) &_number) >> 1);\
_y = _y * (1.5f - (_number * 0.5f * _y * _y));\ _y = _y * (1.5f - (_number * 0.5f * _y * _y));\
VectorScale(_v, _y, _v);\ VectorScale(_v, _y, _v);\
}\ }\

View File

@ -64,33 +64,6 @@ all big things are allocated on the hunk.
memzone_t *mainzone; memzone_t *mainzone;
void Z_ClearZone (memzone_t *zone, int size);
/*
========================
Z_ClearZone
========================
*/
void Z_ClearZone (memzone_t *zone, int size)
{
memblock_t *block;
// set the entire zone to one free block
zone->blocklist.next = zone->blocklist.prev = block =
(memblock_t *)( (byte *)zone + sizeof(memzone_t) );
zone->blocklist.tag = 1; // in use block
zone->blocklist.id = 0;
zone->blocklist.size = 0;
zone->rover = block;
block->prev = block->next = &zone->blocklist;
block->tag = 0; // free block
block->id = ZONEID;
block->size = size - sizeof(memzone_t);
}
/* /*
======================== ========================
@ -153,6 +126,41 @@ Z_CheckHeap (); // DEBUG
return buf; return buf;
} }
/*
========================
Z_Realloc
========================
*/
void *Z_Realloc(void *ptr, int size)
{
int old_size;
void *old_ptr;
memblock_t *block;
if (!ptr)
return Z_Malloc (size);
block = (memblock_t *) ((byte *) ptr - sizeof (memblock_t));
if (block->id != ZONEID)
Sys_Error ("Z_Realloc: realloced a pointer without ZONEID");
if (block->tag == 0)
Sys_Error ("Z_Realloc: realloced a freed pointer");
old_size = block->size;
old_ptr = ptr;
Z_Free (ptr);
ptr = Z_TagMalloc (size, 1);
if (!ptr)
Sys_Error ("Z_Realloc: failed on allocation of %i bytes", size);
if (ptr != old_ptr)
memmove (ptr, old_ptr, min (old_size, size));
return ptr;
}
void *Z_TagMalloc (int size, int tag) void *Z_TagMalloc (int size, int tag)
{ {
int extra; int extra;
@ -299,7 +307,7 @@ void Hunk_Check (void)
{ {
if (h->sentinal != HUNK_SENTINAL) if (h->sentinal != HUNK_SENTINAL)
Sys_Error ("Hunk_Check: trahsed sentinal"); Sys_Error ("Hunk_Check: trahsed sentinal");
if (h->size < 16 || h->size + (byte *)h - hunk_base > hunk_size) if (h->size < sizeof(hunk_t) || h->size + (byte *)h - hunk_base > hunk_size)
Sys_Error ("Hunk_Check: bad size"); Sys_Error ("Hunk_Check: bad size");
h = (hunk_t *)((byte *)h+h->size); h = (hunk_t *)((byte *)h+h->size);
} }
@ -357,7 +365,7 @@ void Hunk_Print (qboolean all)
// //
if (h->sentinal != HUNK_SENTINAL) if (h->sentinal != HUNK_SENTINAL)
Sys_Error ("Hunk_Check: trahsed sentinal"); Sys_Error ("Hunk_Check: trahsed sentinal");
if (h->size < 16 || h->size + (byte *)h - hunk_base > hunk_size) if (h->size < sizeof(hunk_t) || h->size + (byte *)h - hunk_base > hunk_size)
Sys_Error ("Hunk_Check: bad size"); Sys_Error ("Hunk_Check: bad size");
next = (hunk_t *)((byte *)h+h->size); next = (hunk_t *)((byte *)h+h->size);
@ -922,6 +930,25 @@ void *Cache_Alloc (cache_user_t *c, int size, char *name)
//============================================================================ //============================================================================
static void Memory_InitZone (memzone_t *zone, int size)
{
memblock_t *block;
// set the entire zone to one free block
zone->blocklist.next = zone->blocklist.prev = block =
(memblock_t *)( (byte *)zone + sizeof(memzone_t) );
zone->blocklist.tag = 1; // in use block
zone->blocklist.id = 0;
zone->blocklist.size = 0;
zone->rover = block;
block->prev = block->next = &zone->blocklist;
block->tag = 0; // free block
block->id = ZONEID;
block->size = size - sizeof(memzone_t);
}
/* /*
======================== ========================
Memory_Init Memory_Init
@ -947,7 +974,7 @@ void Memory_Init (void *buf, int size)
Sys_Error ("Memory_Init: you must specify a size in KB after -zone"); Sys_Error ("Memory_Init: you must specify a size in KB after -zone");
} }
mainzone = Hunk_AllocName (zonesize, "zone" ); mainzone = Hunk_AllocName (zonesize, "zone" );
Z_ClearZone (mainzone, zonesize); Memory_InitZone (mainzone, zonesize);
Cmd_AddCommand ("hunk_print", Hunk_Print_f); //johnfitz Cmd_AddCommand ("hunk_print", Hunk_Print_f); //johnfitz
} }

View File

@ -88,11 +88,10 @@ void Memory_Init (void *buf, int size);
void Z_Free (void *ptr); void Z_Free (void *ptr);
void *Z_Malloc (int size); // returns 0 filled memory void *Z_Malloc (int size); // returns 0 filled memory
void *Z_Realloc (void *ptr, int size);
void *Z_TagMalloc (int size, int tag); void *Z_TagMalloc (int size, int tag);
void Z_DumpHeap (void);
void Z_CheckHeap (void); void Z_CheckHeap (void);
int Z_FreeMemory (void);
void *Hunk_Alloc (int size); // returns 0 filled memory void *Hunk_Alloc (int size); // returns 0 filled memory
void *Hunk_AllocName (int size, char *name); void *Hunk_AllocName (int size, char *name);