fixed many warnings with vc, /Wp64, mostly pointer cast/truncation
This was SVN commit r61.
This commit is contained in:
parent
b60f1b3353
commit
a8783bb797
@ -231,5 +231,5 @@ void glprintf(const char* fmt, ...)
|
||||
vsnprintf(buf, sizeof(buf)-1, fmt, args);
|
||||
va_end(args);
|
||||
|
||||
glCallLists(strlen(buf), GL_UNSIGNED_BYTE, buf);
|
||||
glCallLists((GLsizei)strlen(buf), GL_UNSIGNED_BYTE, buf);
|
||||
}
|
||||
|
@ -22,7 +22,7 @@
|
||||
#include "res.h"
|
||||
|
||||
// load and return a handle to the font defined in <fn>
|
||||
extern u32 font_load(const char* fn);
|
||||
extern Handle font_load(const char* fn);
|
||||
|
||||
// use the font referenced by h for all subsequent glprintf() calls
|
||||
extern int font_bind(Handle h);
|
||||
|
@ -21,7 +21,7 @@ static void heap_free(MEM* m)
|
||||
static void* heap_alloc(const size_t size, const int align, MEM* mem)
|
||||
{
|
||||
u8* org_p = (u8*)malloc(size+align-1);
|
||||
u8* p = (u8*)round_up((long)org_p, align);
|
||||
u8* p = (u8*)round_up((uintptr_t)org_p, align);
|
||||
|
||||
mem->org_p = org_p;
|
||||
return p;
|
||||
@ -53,7 +53,7 @@ static void* pool_alloc(const size_t size, const uint align, MEM* mem)
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t ofs = round_up((long)pool+pool_pos, align) - (ulong)pool;
|
||||
ptrdiff_t ofs = (u8*)round_up((uintptr_t)pool+pool_pos, align) - pool;
|
||||
if(ofs+size > POOL_CAP)
|
||||
return 0;
|
||||
|
||||
@ -72,13 +72,13 @@ static void* pool_alloc(const size_t size, const uint align, MEM* mem)
|
||||
|
||||
static void mmap_free(MEM* m)
|
||||
{
|
||||
munmap(m->p, m->size);
|
||||
munmap(m->p, (uint)m->size);
|
||||
}
|
||||
|
||||
|
||||
static void* mmap_alloc(const size_t size, const int fd, MEM* mem)
|
||||
{
|
||||
mem->p = mmap(0, size, PROT_READ, MAP_PRIVATE, fd, 0);
|
||||
mem->p = mmap(0, (uint)size, PROT_READ, MAP_PRIVATE, fd, 0);
|
||||
mem->size = size;
|
||||
mem->fd = fd;
|
||||
|
||||
@ -108,7 +108,7 @@ int mem_free(void* p)
|
||||
if(!p)
|
||||
return 1;
|
||||
|
||||
Handle h = h_find((u32)p, H_MEM, 0);
|
||||
Handle h = h_find((uintptr_t)p, H_MEM, 0);
|
||||
if(h)
|
||||
return h_free(h, H_MEM);
|
||||
return -1;
|
||||
@ -149,7 +149,7 @@ void* mem_alloc(size_t size, const uint align, const MemType type, const int fd,
|
||||
return 0;
|
||||
|
||||
MEM* pmem;
|
||||
Handle h = h_alloc((u32)p, H_MEM, mem_dtor, (void**)&pmem);
|
||||
Handle h = h_alloc((uintptr_t)p, H_MEM, mem_dtor, (void**)&pmem);
|
||||
if(!h) // failed to allocate a handle
|
||||
{
|
||||
mem_dtor(&mem);
|
||||
|
@ -45,7 +45,7 @@ const int HDATA_USER_SIZE = 20;
|
||||
// 32 bytes
|
||||
struct HDATA
|
||||
{
|
||||
u32 key;
|
||||
uintptr_t key;
|
||||
u32 tag : HTAG_BITS;
|
||||
u32 type : HTYPE_BITS; // handle's type (e.g. texture, sound)
|
||||
u32 refs : HREF_BITS;
|
||||
@ -159,7 +159,7 @@ static void cleanup(void)
|
||||
}
|
||||
|
||||
|
||||
Handle h_find(const u32 key, uint type, void** puser)
|
||||
Handle h_find(const uintptr_t key, uint type, void** puser)
|
||||
{
|
||||
int idx;
|
||||
HDATA* hd;
|
||||
@ -198,7 +198,7 @@ found:
|
||||
}
|
||||
|
||||
|
||||
Handle h_alloc(const u32 key, const uint type, /*const size_t user_size,*/ H_DTOR dtor, void** puser)
|
||||
Handle h_alloc(const uintptr_t key, const uint type, /*const size_t user_size,*/ H_DTOR dtor, void** puser)
|
||||
{
|
||||
ONCE(atexit(cleanup))
|
||||
/*
|
||||
|
@ -65,12 +65,12 @@ typedef void(*H_DTOR)(void*);
|
||||
//// user_size is checked to make sure the user data fits in the handle data space.
|
||||
// dtor is associated with type and called when the object is freed.
|
||||
// handle data is initialized to 0; optionally, a pointer to it is returned.
|
||||
extern Handle h_alloc(u32 key, uint type,/* size_t user_size,*/ H_DTOR dtor = 0, void** puser = 0);
|
||||
extern Handle h_alloc(uintptr_t key, uint type,/* size_t user_size,*/ H_DTOR dtor = 0, void** puser = 0);
|
||||
extern int h_free(Handle& h, uint type);
|
||||
|
||||
// find and return a handle by type and key (typically filename hash)
|
||||
// currently O(n).
|
||||
extern Handle h_find(u32 key, uint type, void** puser = 0);
|
||||
extern Handle h_find(uintptr_t key, uint type, void** puser = 0);
|
||||
|
||||
// return a pointer to handle data
|
||||
extern void* h_user_data(Handle h, uint type);
|
||||
|
@ -1,18 +1,37 @@
|
||||
#ifndef __TYPES_H__
|
||||
#define __TYPES_H__
|
||||
|
||||
|
||||
// defines instead of typedefs so we can #undef conflicting decls
|
||||
|
||||
#define uint unsigned int
|
||||
|
||||
#define ulong unsigned long
|
||||
|
||||
#define uint unsigned int
|
||||
|
||||
#define int8 signed char
|
||||
#define int16 short
|
||||
#define int32 long
|
||||
|
||||
#define u8 unsigned char
|
||||
#define u16 unsigned short
|
||||
#define u32 unsigned long // compatibility with Win32 DWORD
|
||||
#define u32 unsigned long // long to match Win32 DWORD
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define u64 unsigned __int64
|
||||
#else
|
||||
#define u64 unsigned long long
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#include <stddef.h>
|
||||
#ifdef _MSC_VER
|
||||
#ifndef _UINTPTR_T_DEFINED
|
||||
#define _UINTPTR_T_DEFINED
|
||||
#define uintptr_t u32
|
||||
#endif // _UINTPTR_T_DEFINED
|
||||
#endif // _MSC_VER
|
||||
|
||||
|
||||
#endif // #ifndef __TYPES_H__
|
||||
|
@ -62,7 +62,7 @@ struct PATH
|
||||
char* dir; // relative to root dir;
|
||||
// points to space at end of this struct
|
||||
|
||||
int num_archives;
|
||||
size_t num_archives;
|
||||
Handle archives[1];
|
||||
|
||||
// space allocated here for archive Handles + dir string
|
||||
@ -129,11 +129,11 @@ int vfs_mount(const char* path)
|
||||
archives.push_back(ent->d_name);
|
||||
}
|
||||
closedir(dir);
|
||||
const int num_archives = archives.size();
|
||||
const size_t num_archives = archives.size();
|
||||
|
||||
// alloc search path entry (add to front)
|
||||
const int archives_size = num_archives*sizeof(Handle);
|
||||
const int entry_size = round_up(sizeof(PATH)+archives_size+path_len+1, 32);
|
||||
const size_t archives_size = num_archives*sizeof(Handle);
|
||||
const size_t entry_size = round_up((long)(sizeof(PATH)+archives_size+path_len+1), 32);
|
||||
PATH* entry = (PATH*)mem_alloc(entry_size, 32, MEM_HEAP);
|
||||
if(!entry)
|
||||
return -1;
|
||||
@ -146,7 +146,7 @@ int vfs_mount(const char* path)
|
||||
// add archives in alphabetical order
|
||||
std::sort(archives.begin(), archives.end());
|
||||
entry->num_archives = num_archives;
|
||||
for(int i = 0; i < num_archives; i++)
|
||||
for(size_t i = 0; i < num_archives; i++)
|
||||
entry->archives[i] = zip_open(archives[i].c_str());
|
||||
|
||||
return 0;
|
||||
@ -163,7 +163,7 @@ int vfs_umount(const char* path)
|
||||
if(!strcmp(entry->dir, path))
|
||||
{
|
||||
// close all archives
|
||||
for(int i = 0; i < entry->num_archives; i++)
|
||||
for(size_t i = 0; i < entry->num_archives; i++)
|
||||
h_free(entry->archives[i], H_ZARCHIVE);
|
||||
|
||||
// remove from list
|
||||
@ -204,7 +204,7 @@ static int vfs_foreach_path(int (*func)(const char* path, Handle ha, void* data)
|
||||
return err;
|
||||
|
||||
// archive
|
||||
for(int i = 0; i < entry->num_archives; i++)
|
||||
for(size_t i = 0; i < entry->num_archives; i++)
|
||||
{
|
||||
err = func(path, entry->archives[i], data);
|
||||
if(err <= 0)
|
||||
@ -358,9 +358,9 @@ u32 vfs_start_read(const Handle hf, size_t& ofs, void** buf)
|
||||
if(!vf)
|
||||
return 0;
|
||||
|
||||
ssize_t bytes_left = vf->size - ofs;
|
||||
if(bytes_left < 0)
|
||||
if(ofs >= vf->size)
|
||||
return 0;
|
||||
size_t bytes_left = vf->size - ofs;
|
||||
|
||||
// TODO: thread safety
|
||||
|
||||
@ -400,15 +400,17 @@ u32 vfs_start_read(const Handle hf, size_t& ofs, void** buf)
|
||||
}
|
||||
|
||||
// align to 64 KB for speed
|
||||
u32 rsize = min(64*KB - (ofs & 0xffff), bytes_left);
|
||||
size_t rsize = 64*KB - (ofs & 0xffff); // min(~, bytes_left) - avoid warning
|
||||
if(rsize > bytes_left)
|
||||
rsize = bytes_left;
|
||||
|
||||
cb->aio_offset = ofs;
|
||||
cb->aio_offset = (off_t)ofs;
|
||||
cb->aio_nbytes = rsize;
|
||||
aio_read(cb);
|
||||
|
||||
ofs += rsize;
|
||||
if(buf)
|
||||
(int&)*buf += rsize;
|
||||
(size_t&)*buf += rsize;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "mem.h"
|
||||
#include "vfs.h"
|
||||
|
||||
#include <zlib.h>
|
||||
#ifdef _MSC_VER
|
||||
#pragma comment(lib, "zlib.lib")
|
||||
#endif
|
||||
@ -47,7 +48,6 @@ struct ZARCHIVE
|
||||
ZFILE* files;
|
||||
};
|
||||
|
||||
#include <zlib.h>
|
||||
|
||||
static const char ecdr_id[] = "PK\5\6"; // End of Central Directory Header identifier
|
||||
static const char cdfh_id[] = "PK\1\2"; // Central File Header identifier
|
||||
@ -55,7 +55,6 @@ static const char lfh_id[] = "PK\3\4"; // Local File Header identifier
|
||||
|
||||
|
||||
|
||||
|
||||
static void zarchive_dtor(void* p)
|
||||
{
|
||||
ZARCHIVE* za = (ZARCHIVE*)p;
|
||||
@ -96,7 +95,9 @@ Handle zip_open(const char* const fn)
|
||||
// (zip comment <= 65535 bytes, sizeof(ECDR) = 22, add some for safety)
|
||||
// if the zip file is < 66000 bytes, scan the whole file
|
||||
|
||||
size_t bytes_left = min(size, 66000);
|
||||
size_t bytes_left = 66000; // min(66k, size) - avoid stupid warning
|
||||
if(bytes_left > size)
|
||||
bytes_left = size;
|
||||
ecdr = zfile + size - bytes_left;
|
||||
|
||||
while(bytes_left-3 > 0)
|
||||
@ -142,7 +143,7 @@ found_ecdr:
|
||||
const u8* cdfh = zfile+cd_ofs;
|
||||
u32* hs = za->fn_hashs;
|
||||
ZFILE* f = za->files;
|
||||
uint i;
|
||||
u16 i;
|
||||
for(i = 0; i < num_files; i++)
|
||||
{
|
||||
// read CDFH
|
||||
@ -173,7 +174,7 @@ found_ecdr:
|
||||
f->ucsize = ucsize;
|
||||
f++;
|
||||
|
||||
(int&)cdfh += 46 + fn_len + e_len + c_len;
|
||||
(uintptr_t&)cdfh += 46 + fn_len + e_len + c_len;
|
||||
}
|
||||
|
||||
za->num_files = i;
|
||||
@ -197,7 +198,7 @@ ZFILE* zip_lookup(Handle ha, const char* fn)
|
||||
|
||||
// find its File descriptor
|
||||
const u32 fn_hash = fnv_hash(fn, strlen(fn));
|
||||
uint i = za->last_file+1;
|
||||
u16 i = za->last_file+1;
|
||||
if(i >= za->num_files || za->fn_hashs[i] != fn_hash)
|
||||
{
|
||||
for(i = 0; i < za->num_files; i++)
|
||||
@ -219,7 +220,7 @@ int zip_stat(Handle ha, const char* fn, struct stat* s)
|
||||
if(!zf)
|
||||
return -1;
|
||||
|
||||
s->st_size = zf->ucsize;
|
||||
s->st_size = (off_t)zf->ucsize;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -249,7 +250,7 @@ void* zip_inflate_start(void* out, size_t out_size)
|
||||
// -MAX_WBITS indicates no zlib header present
|
||||
|
||||
stream->next_out = (Bytef*)out;
|
||||
stream->avail_out = out_size;
|
||||
stream->avail_out = (uInt)out_size;
|
||||
|
||||
return stream;
|
||||
}
|
||||
@ -260,7 +261,7 @@ int zip_inflate_process(void* ctx, void* p, size_t size)
|
||||
z_stream* stream = (z_stream*)ctx;
|
||||
|
||||
stream->next_in = (Bytef*)p;
|
||||
stream->avail_in = size;
|
||||
stream->avail_in = (uInt)size;
|
||||
return inflate(stream, 0);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user