1
0
forked from 0ad/0ad

aio: check for NULL aiocb* params; made aio_h get/set static; various small improvements

mem: explicit mem_shutdown call - try to avoid exit order problems

unifont: remove logger calls (dependency on ps/)

This was SVN commit r1657.
This commit is contained in:
janwas 2005-01-07 01:13:48 +00:00
parent 577c23d936
commit e6a12f76e2
5 changed files with 54 additions and 32 deletions

View File

@ -57,8 +57,6 @@ static PtrToH& get_ptr_to_h()
// crash + burn
_ptr_to_h = new PtrToH;
atexit2(ptr_to_h_shutdown);
}
return *_ptr_to_h;
}
@ -381,6 +379,8 @@ void* mem_alloc(size_t size, const size_t align, uint flags, Handle* phm)
void* mem_get_ptr(Handle hm, size_t* user_size /* = 0 */)
{
h_add_ref(hm);
Mem* m = H_USER_DATA(hm, Mem);
if(!m)
{
@ -405,3 +405,9 @@ ssize_t mem_size(void* p)
return (ssize_t)m->size;
}
*/
void mem_shutdown()
{
ptr_to_h_shutdown();
}

View File

@ -29,6 +29,8 @@ extern int mem_free_h(Handle& hm);
extern void* mem_get_ptr(Handle h, size_t* size = 0);
extern void mem_shutdown();
#ifdef __cplusplus
}
#endif

View File

@ -21,8 +21,8 @@ Unicode OpenGL texture font
#include <stdio.h>
#include <assert.h>
#include <ps/CLogger.h>
#define LOG_CATEGORY "graphics"
/*/*#include <ps/CLogger.h>
#define LOG_CATEGORY "graphics"*/
// This isn't particularly efficient - it can be improved if we
// (a) care enough, and (b) know about fixed ranges of characters
@ -79,20 +79,20 @@ static int UniFont_reload(UniFont* f, const char* fn, Handle UNUSEDPARAM(h))
// // if (! vfs_exists(fnt_fn))
// // return ERR_FILE_NOT_FOUND;
Handle fh = vfs_load(fnt_fn, RawFNT, FNTSize);
CHECK_ERR(fh);
Handle hm = vfs_load(fnt_fn, RawFNT, FNTSize);
CHECK_ERR(hm);
// Get the data in a nicer object
std::istringstream FNTStream (std::string((char*)RawFNT, (int)FNTSize));
std::istringstream FNTStream (std::string((const char*)RawFNT, (int)FNTSize));
// Unload the file
mem_free(RawFNT);
mem_free_h(hm);
int Version;
FNTStream >> Version;
if (Version != 100) // Make sure this is from a recent version of the font builder
{
LOG(ERROR, LOG_CATEGORY, "Invalid .fnt version number");
// LOG(ERROR, LOG_CATEGORY, "Invalid .fnt version number");
return -1;
}
@ -112,7 +112,7 @@ static int UniFont_reload(UniFont* f, const char* fn, Handle UNUSEDPARAM(h))
f->ListBase = glGenLists(NumGlyphs);
if (f->ListBase == 0) // My Voodoo2 drivers didn't support display lists (although I'd be surprised if they got this far)
{
LOG(ERROR, LOG_CATEGORY, "Display list creation failed");
// LOG(ERROR, LOG_CATEGORY, "Display list creation failed");
return -1;
}

View File

@ -52,7 +52,7 @@ __asm
fstp [r]
}
UNUSED(f)
UNUSED(f);
return r;
}
@ -94,8 +94,8 @@ __asm
pop eax
}
UNUSED(new_cw)
UNUSED(mask)
UNUSED(new_cw);
UNUSED(mask);
return 0;
}

View File

@ -93,7 +93,7 @@ static bool is_valid_file_handle(const HANDLE h)
// return async-capable handle associated with file <fd>
HANDLE aio_h_get(const int fd)
static HANDLE aio_h_get(const int fd)
{
HANDLE h = INVALID_HANDLE_VALUE;
@ -118,7 +118,7 @@ HANDLE aio_h_get(const int fd)
// associate h (an async-capable file handle) with fd;
// returned by subsequent aio_h_get(fd) calls.
// setting h = INVALID_HANDLE_VALUE removes the association.
int aio_h_set(const int fd, const HANDLE h)
static int aio_h_set(const int fd, const HANDLE h)
{
lock();
@ -214,16 +214,17 @@ int aio_close(int fd)
{
HANDLE h = aio_h_get(fd);
if(h == INVALID_HANDLE_VALUE) // out of bounds or already closed
{
debug_warn("aio_close failed");
return -1;
}
goto fail;
if(!CloseHandle(h))
debug_warn("aio_close: CloseHandle failed");
aio_h_set(fd, INVALID_HANDLE_VALUE);
goto fail;
CHECK_ERR(aio_h_set(fd, INVALID_HANDLE_VALUE));
return 0;
fail:
debug_warn("aio_close failed");
return -1;
}
@ -500,6 +501,13 @@ fail:
// return status of transfer
int aio_error(const struct aiocb* cb)
{
// must not pass 0 to req_find - we'd look for a free cb!
if(!cb)
{
debug_warn("aio_error: invalid cb");
return -1;
}
Req* r = req_find(cb);
if(!r)
return -1;
@ -519,6 +527,13 @@ int aio_error(const struct aiocb* cb)
// get bytes transferred. call exactly once for each op.
ssize_t aio_return(struct aiocb* cb)
{
// must not pass 0 to req_find - we'd look for a free cb!
if(!cb)
{
debug_warn("aio_return: invalid cb");
return -1;
}
Req* r = req_find(cb);
if(!r)
{
@ -600,14 +615,14 @@ int aio_suspend(const struct aiocb* const cbs[], int n, const struct timespec* t
int aio_cancel(int fd, struct aiocb* cb)
{
UNUSED(cb)
// Win32 limitation: can't cancel single transfers -
// all pending reads on this file are cancelled.
UNUSED(cb);
const HANDLE h = aio_h_get(fd);
if(h == INVALID_HANDLE_VALUE)
return -1;
// Win32 limitation: can't cancel single transfers -
// all pending reads on this file are cancelled.
CancelIo(h);
return AIO_CANCELED;
}
@ -618,33 +633,32 @@ int aio_cancel(int fd, struct aiocb* cb)
int aio_read(struct aiocb* cb)
{
cb->aio_lio_opcode = LIO_READ;
return aio_rw(cb);
return aio_rw(cb); // checks for cb == 0
}
int aio_write(struct aiocb* cb)
{
cb->aio_lio_opcode = LIO_WRITE;
return aio_rw(cb);
return aio_rw(cb); // checks for cb == 0
}
int lio_listio(int mode, struct aiocb* const cbs[], int n, struct sigevent* se)
{
UNUSED(se)
UNUSED(se);
int err = 0;
int err = 0;
for(int i = 0; i < n; i++)
{
int ret = aio_rw(cbs[i]); // aio_rw checks for 0 param
int ret = aio_rw(cbs[i]); // checks for cbs[i] == 0
// don't CHECK_ERR - want to try to issue each one
if(ret < 0)
if(ret < 0 && !err)
err = ret;
}
if(err < 0)
return err;
CHECK_ERR(err);
if(mode == LIO_WAIT)
return aio_suspend(cbs, n, 0);