From df1b502bbd5f1f60540efe67c78e84ffa9968ac2 Mon Sep 17 00:00:00 2001 From: olsner Date: Wed, 22 Sep 2004 15:20:58 +0000 Subject: [PATCH] Linux Compat and some updated PARANOIA code This was SVN commit r1189. --- source/gui/GUItext.h | 1 + source/lib/res/file.cpp | 22 +++++++++++-- source/lib/res/snd.cpp | 19 ++++++++---- source/lib/res/vfs.cpp | 50 +++++++++++++++++------------- source/lib/res/zip.cpp | 6 ++-- source/lib/sysdep/sysdep.cpp | 2 +- source/scripting/ScriptGlue.cpp | 2 +- source/scripting/ScriptingHost.cpp | 4 ++- 8 files changed, 70 insertions(+), 36 deletions(-) diff --git a/source/gui/GUItext.h b/source/gui/GUItext.h index 6c1a58a8c3..d395f41594 100755 --- a/source/gui/GUItext.h +++ b/source/gui/GUItext.h @@ -21,6 +21,7 @@ gee@pyro.nu //-------------------------------------------------------- // Includes / Compiler directives //-------------------------------------------------------- +#include //-------------------------------------------------------- // Declarations diff --git a/source/lib/res/file.cpp b/source/lib/res/file.cpp index 13a73a7b4b..2200d10c07 100755 --- a/source/lib/res/file.cpp +++ b/source/lib/res/file.cpp @@ -546,7 +546,7 @@ int file_start_io(File* const f, const off_t ofs, size_t size, void* const p, Fi memset(io, 0, sizeof(FileIO)); #ifdef PARANOIA - debug_out("file_start_io ofs=%d size=%d\n", ofs, size); + debug_out("file_start_io: ofs=%d size=%d\n", ofs, size); #endif @@ -584,6 +584,7 @@ int file_start_io(File* const f, const off_t ofs, size_t size, void* const p, Fi // pointer to a struct containing the aiocb*. aiocb* cb = (aiocb*)malloc(sizeof(aiocb)); + memset(cb, 0, sizeof(aiocb)); if(!cb) return ERR_NO_MEM; io->cb = cb; @@ -594,9 +595,15 @@ int file_start_io(File* const f, const off_t ofs, size_t size, void* const p, Fi cb->aio_fildes = f->fd; cb->aio_offset = ofs; cb->aio_nbytes = size; +#ifdef PARANOIA + debug_out("file_start_io: io=%p nbytes=%d\n", io, cb->aio_nbytes); +#endif int err = lio_listio(LIO_NOWAIT, &cb, 1, (struct sigevent*)0); if(err < 0) { +#ifdef PARANOIA + debug_out("file_start_io: lio_listio: %d, %d[%s]\n", err, errno, strerror(errno)); +#endif file_discard_io(io); return err; } @@ -624,7 +631,7 @@ int file_io_complete(FileIO* io) int file_wait_io(FileIO* io, void*& p, size_t& size) { #ifdef PARANOIA -debug_out("file_wait_io: hio=%I64x\n", hio); +debug_out("file_wait_io: hio=%p\n", io); #endif // zero output params in case something (e.g. H_DEREF) fails. @@ -640,6 +647,10 @@ debug_out("file_wait_io: hio=%I64x\n", hio); // query number of bytes transferred (-1 if the transfer failed) const ssize_t bytes_transferred = aio_return(cb); +#ifdef PARANOIA + debug_out("file_wait_io: bytes_transferred=%d aio_nbytes=%d\n", + bytes_transferred, cb->aio_nbytes); +#endif if(bytes_transferred < (ssize_t)cb->aio_nbytes) return -1; @@ -942,6 +953,9 @@ debug_out("file_io fd=%d size=%d ofs=%d\n", f->fd, data_size, data_ofs); void* buf = (temp)? 0 : (char*)actual_buf + issue_cnt; ssize_t issued = block_issue(f, slot, issue_ofs, buf); +#ifdef PARANOIA + debug_out("file_io: block_issue: %d\n", issued); +#endif if(issued < 0) err = issued; // transfer failed - loop will now terminate after @@ -1031,6 +1045,10 @@ if(from_cache && !temp) break; } +#ifdef PARANOIA + debug_out("file_io: err=%d, actual_transferred_cnt=%d\n", err, actual_transferred_cnt); +#endif + // failed (0 means callback reports it's finished) if(err < 0) return err; diff --git a/source/lib/res/snd.cpp b/source/lib/res/snd.cpp index 966bbf9bd8..b9353bdc23 100755 --- a/source/lib/res/snd.cpp +++ b/source/lib/res/snd.cpp @@ -10,13 +10,16 @@ # include #endif +// Linux OpenAL puts the Ogg Vorbis extension enums in alexttypes.h +#ifdef OS_LINUX +# include +#endif + #ifdef _MSC_VER #pragma comment(lib, "openal32.lib") #pragma comment(lib, "alut.lib") #endif - - // called as late as possible, i.e. the first time sound/music is played // (either from module init there, or from the play routine itself). // this delays library load, leading to faster perceived app startup. @@ -319,7 +322,11 @@ static int ALBuffer_reload(ALBuffer* b, const char* fn, Handle) // freed in bailout ladder Handle hf = 0; + ssize_t file_size = 0; void* file = 0; + + ssize_t bytes_read=0; + void *dst=0; { @@ -372,13 +379,13 @@ static int ALBuffer_reload(ALBuffer* b, const char* fn, Handle) // note: freed after openal latches its contents in al_create_buffer. // we don't know how much has already been read by wav_detect_format; // allocate enough for the entire file. - ssize_t file_size = vfs_size(hf); + file_size = vfs_size(hf); if(file_size < 0) { ret = file_size; goto fail; } - void* file = mem_alloc(file_size, 65536); // freed soon after + file = mem_alloc(file_size, 65536); // freed soon after if(!file) { ret = ERR_NO_MEM; @@ -389,8 +396,8 @@ memset(file, 0xe2, file_size); // read from file. note: don't use vfs_load - detect_audio_fmt // has seeked to the actual audio data in the file. - void* dst = file; // for vfs_io - ssize_t bytes_read = vfs_io(hf, file_size, &dst); + dst = file; // for vfs_io + bytes_read = vfs_io(hf, file_size, &dst); if(bytes_read < 0) { ret = bytes_read; diff --git a/source/lib/res/vfs.cpp b/source/lib/res/vfs.cpp index 0af2b48b5d..45607e3628 100755 --- a/source/lib/res/vfs.cpp +++ b/source/lib/res/vfs.cpp @@ -1317,7 +1317,7 @@ Handle vfs_open(const char* v_fn, uint file_flags /* = 0 */) // pass file flags to init #ifdef PARANOIA -debug_out("vfs_open fn=%s %I64x\n", v_fn, h); +debug_out("vfs_open fn=%s %llx\n", v_fn, h); #endif return h; @@ -1325,10 +1325,10 @@ debug_out("vfs_open fn=%s %I64x\n", v_fn, h); // close the handle to a file. -inline int vfs_close(Handle& h) +int vfs_close(Handle& h) { #ifdef PARANOIA -debug_out("vfs_close %I64x\n", h); +debug_out("vfs_close %llx\n", h); #endif return h_free(h, H_VFile); @@ -1426,7 +1426,7 @@ static ssize_t vfs_timed_io(const Handle hf, const size_t size, void** p, FileIO Handle vfs_load(const char* const v_fn, void*& p, size_t& size, uint flags /* default 0 */) { #ifdef PARANOIA -debug_out("vfs_load fn=%s\n", fn); +debug_out("vfs_load v_fn=%s\n", v_fn); #endif p = 0; size = 0; // zeroed in case vfs_open or H_DEREF fails @@ -1457,24 +1457,27 @@ debug_out("vfs_load fn=%s\n", fn); // (padding), but it greatly simplifies returning the Handle // (if we allow File to alloc, have to make sure the Handle references // the actual data address, not that of the padding). - const size_t BLOCK_SIZE = 64*KB; - p = mem_alloc(size, BLOCK_SIZE, 0, &hm); - if(!p) - goto ret; - - ssize_t nread = vfs_timed_io(hf, size, &p); - // failed - if(nread < 0) { - mem_free_h(hm); - hm = nread; // error code - } - else - { - if(flags & FILE_CACHE) - vf->hm = hm; + const size_t BLOCK_SIZE = 64*KB; + p = mem_alloc(size, BLOCK_SIZE, 0, &hm); + if(!p) + goto ret; } + { + ssize_t nread = vfs_timed_io(hf, size, &p); + // failed + if(nread < 0) + { + mem_free_h(hm); + hm = nread; // error code + } + else + { + if(flags & FILE_CACHE) + vf->hm = hm; + } + } ret: vfs_close(hf); @@ -1485,6 +1488,9 @@ ret: if(hm <= 0) p = 0, size = 0; + if (hm == 0) + debug_out("hm == 0!!\n"); + return hm; } @@ -1573,7 +1579,7 @@ Handle vfs_start_io(Handle hf, off_t ofs, size_t size, void* buf) // indicates if the IO referenced by has completed. // return value: 0 if pending, 1 if complete, < 0 on error. -inline int vfs_io_complete(Handle hio) +int vfs_io_complete(Handle hio) { H_DEREF(hio, IO, io); if(io->is_zip) @@ -1585,7 +1591,7 @@ inline int vfs_io_complete(Handle hio) // wait until the transfer completes, and return its buffer. // output parameters are zeroed on error. -inline int vfs_wait_io(Handle hio, void*& p, size_t& size) +int vfs_wait_io(Handle hio, void*& p, size_t& size) { H_DEREF(hio, IO, io); if(io->is_zip) @@ -1596,7 +1602,7 @@ inline int vfs_wait_io(Handle hio, void*& p, size_t& size) // finished with transfer - free its buffer (returned by vfs_wait_io) -inline int vfs_discard_io(Handle& hio) +int vfs_discard_io(Handle& hio) { return h_free(hio, H_IO); } diff --git a/source/lib/res/zip.cpp b/source/lib/res/zip.cpp index 5f81cf8af8..1dfcc7041d 100755 --- a/source/lib/res/zip.cpp +++ b/source/lib/res/zip.cpp @@ -1068,7 +1068,7 @@ int zip_start_io(ZFile* const zf, off_t user_ofs, size_t max_output_size, void* // indicates if the IO referenced by has completed. // return value: 0 if pending, 1 if complete, < 0 on error. -inline int zip_io_complete(ZipIO* io) +int zip_io_complete(ZipIO* io) { if(io->already_inflated) return 1; @@ -1078,7 +1078,7 @@ inline int zip_io_complete(ZipIO* io) // wait until the transfer completes, and return its buffer. // output parameters are zeroed on error. -inline int zip_wait_io(ZipIO* io, void*& buf, size_t& size) +int zip_wait_io(ZipIO* io, void*& buf, size_t& size) { buf = io->user_buf; size = io->max_output_size; @@ -1107,7 +1107,7 @@ inline int zip_wait_io(ZipIO* io, void*& buf, size_t& size) // finished with transfer - free its buffer (returned by zip_wait_io) -inline int zip_discard_io(ZipIO* io) +int zip_discard_io(ZipIO* io) { if(io->already_inflated) return 0; diff --git a/source/lib/sysdep/sysdep.cpp b/source/lib/sysdep/sysdep.cpp index 443ffadbdd..57f4ec070d 100755 --- a/source/lib/sysdep/sysdep.cpp +++ b/source/lib/sysdep/sysdep.cpp @@ -36,7 +36,7 @@ void debug_out(const char* fmt, ...) } -inline void debug_check_heap() +void debug_check_heap() { } diff --git a/source/scripting/ScriptGlue.cpp b/source/scripting/ScriptGlue.cpp index ddc9333ca6..2ca7469435 100755 --- a/source/scripting/ScriptGlue.cpp +++ b/source/scripting/ScriptGlue.cpp @@ -397,7 +397,7 @@ JSBool getLanguageID(JSContext* cx, JSObject* UNUSEDPARAM(globalObject), unsigne return JS_TRUE; } -extern "C" extern int fps; +extern "C" int fps; JSBool getFPS(JSContext* UNUSEDPARAM(cx), JSObject* UNUSEDPARAM(globalObject), unsigned int UNUSEDPARAM(argc), jsval* UNUSEDPARAM(argv), jsval* rval) { *rval = INT_TO_JSVAL(fps); diff --git a/source/scripting/ScriptingHost.cpp b/source/scripting/ScriptingHost.cpp index 869fd3ecf4..d518c02487 100755 --- a/source/scripting/ScriptingHost.cpp +++ b/source/scripting/ScriptingHost.cpp @@ -322,7 +322,9 @@ CStrW ScriptingHost::ValueToUCString( const jsval value ) if (string == NULL) throw PSERROR_Scripting_ConversionFailed(); - return CStrW(JS_GetStringChars(string), JS_GetStringLength(string)); + jschar *strptr=JS_GetStringChars(string); + uint length=JS_GetStringLength(string); + return CStrW(std::wstring(strptr, strptr+length)); } jsval ScriptingHost::UCStringToValue(const utf16string &str)