diff --git a/source/gui/CGUI.cpp b/source/gui/CGUI.cpp index 5d872fac48..22cea66d17 100644 --- a/source/gui/CGUI.cpp +++ b/source/gui/CGUI.cpp @@ -1022,7 +1022,7 @@ void CGUI::ReportParseError(const char *str, ...) memset(buffer,0,sizeof(buffer)); va_start(argp, str); - vsnprintf2(buffer, sizeof(buffer), str, argp); + sys_vsnprintf(buffer, sizeof(buffer), str, argp); va_end(argp); // Print header diff --git a/source/lib/lib.h b/source/lib/lib.h index d2531f8696..35791957db 100644 --- a/source/lib/lib.h +++ b/source/lib/lib.h @@ -8,7 +8,7 @@ * ========================================================================= */ -/*b +/* * Copyright (c) 2003-2005 Jan Wassenberg * * Redistribution and/or modification are also permitted under the diff --git a/source/lib/posix/posix.cpp b/source/lib/posix/posix.cpp index 800b2e4314..fe7780aae8 100644 --- a/source/lib/posix/posix.cpp +++ b/source/lib/posix/posix.cpp @@ -2,7 +2,7 @@ #include "posix.h" #if CPU_IA32 -# include "lib/sysdep/ia32/ia32.h" +# include "lib/sysdep/ia32/ia32_asm.h" #endif @@ -48,17 +48,26 @@ float fmaxf(float a, float b) uint fpclassifyd(double d) { +#if CPU_IA32 + return ia32_asm_fpclassifyd(d); +#else // really sucky stub implementation; doesn't attempt to cover all cases. if(d != d) return FP_NAN; else return FP_NORMAL; +#endif } uint fpclassifyf(float f) { - return fpclassify((double)f); +#if CPU_IA32 + return ia32_asm_fpclassifyf(f); +#else + const double d = (double)f; + return fpclassifyd(d); +#endif } #endif // #if !HAVE_C99_MATH diff --git a/source/lib/posix/posix.h b/source/lib/posix/posix.h index 61da410f76..c56abd1321 100644 --- a/source/lib/posix/posix.h +++ b/source/lib/posix/posix.h @@ -75,6 +75,10 @@ need only be renamed (e.g. _open, _stat). #include "posix_utsname.h" +// note: the following need only be #defined (instead of defining a +// trampoline function) because the redefined functions are already +// declared by standard headers. + // provide C99 *snprintf functions if compiler doesn't already // (MinGW does, VC7.1 doesn't). #if MSC_VERSION @@ -84,6 +88,12 @@ need only be renamed (e.g. _open, _stat). # define vswprintf _vsnwprintf #endif +// VC doesn't define str[n]casecmp +#if MSC_VERSION +#define strcasecmp stricmp +#define strncasecmp strnicmp +#endif + #if !HAVE_STRDUP extern char* strdup(const char* str); diff --git a/source/lib/res/file/archive_builder.cpp b/source/lib/res/file/archive_builder.cpp index cabd5fe317..5635bb2929 100644 --- a/source/lib/res/file/archive_builder.cpp +++ b/source/lib/res/file/archive_builder.cpp @@ -50,7 +50,7 @@ static inline bool file_type_is_uncompressible(const char* fn) for(uint i = 0; i < ARRAY_SIZE(uncompressible_exts); i++) { - if(!stricmp(ext+1, uncompressible_exts[i])) + if(!strcasecmp(ext+1, uncompressible_exts[i])) return true; } diff --git a/source/lib/res/file/vfs.cpp b/source/lib/res/file/vfs.cpp index 84a2eb7867..28949a1606 100644 --- a/source/lib/res/file/vfs.cpp +++ b/source/lib/res/file/vfs.cpp @@ -661,11 +661,11 @@ static bool can_ignore_reload(const char* V_path, PathList pending_reloads, uint return true; // .. compiled XML files the engine writes out by the hundreds; // skipping them is a big performance gain. - if(!stricmp(ext, "xmb")) + if(!strcasecmp(ext, "xmb")) return true; // .. temp files, usually created when an editor saves a file // (delete, create temp, rename temp); no need to reload those. - if(!stricmp(ext, "tmp")) + if(!strcasecmp(ext, "tmp")) return true; // .. more than one notification for a file; only reload once. // note: this doesn't suffer from the 'reloaded too early' diff --git a/source/lib/res/file/vfs_optimizer.cpp b/source/lib/res/file/vfs_optimizer.cpp index a8cf7f1672..f366e102f4 100644 --- a/source/lib/res/file/vfs_optimizer.cpp +++ b/source/lib/res/file/vfs_optimizer.cpp @@ -552,7 +552,7 @@ public: // remove if not same extension const char* ext = path_extension(ent.name); - if(stricmp(archive_ext, ext) != 0) + if(strcasecmp(archive_ext, ext) != 0) return true; // keep diff --git a/source/lib/res/file/vfs_tree.cpp b/source/lib/res/file/vfs_tree.cpp index 4a7337bf84..6a63734986 100644 --- a/source/lib/res/file/vfs_tree.cpp +++ b/source/lib/res/file/vfs_tree.cpp @@ -174,7 +174,7 @@ public: // possibly OS are case-sensitive) and wastes memory here. // what we'll do is warn and treat as separate filename // (least surprise). -// if(!stricmp(k1, k2)) +// if(!strcasecmp(k1, k2)) // debug_warn("filenames differ only in case: bug?"); #endif return false; diff --git a/source/lib/res/graphics/ogl_shader.cpp b/source/lib/res/graphics/ogl_shader.cpp index 966eecd4b0..801eea4ad1 100644 --- a/source/lib/res/graphics/ogl_shader.cpp +++ b/source/lib/res/graphics/ogl_shader.cpp @@ -53,9 +53,9 @@ static const char* shader_type_to_string(GLenum type, char* buf, size_t buflen) // or 0 if the shader type is not known. static GLenum string_to_shader_type(const char* name) { - if (!stricmp(name, "VERTEX_SHADER")) + if (!strcasecmp(name, "VERTEX_SHADER")) return GL_VERTEX_SHADER_ARB; - if (!stricmp(name, "FRAGMENT_SHADER")) + if (!strcasecmp(name, "FRAGMENT_SHADER")) return GL_FRAGMENT_SHADER_ARB; return 0; } diff --git a/source/lib/res/graphics/tex_bmp.cpp b/source/lib/res/graphics/tex_bmp.cpp index e5e7ef154c..e78d3d5c3e 100644 --- a/source/lib/res/graphics/tex_bmp.cpp +++ b/source/lib/res/graphics/tex_bmp.cpp @@ -72,7 +72,7 @@ static bool bmp_is_hdr(const u8* file) static bool bmp_is_ext(const char* ext) { - return !stricmp(ext, "bmp"); + return !strcasecmp(ext, "bmp"); } diff --git a/source/lib/res/graphics/tex_dds.cpp b/source/lib/res/graphics/tex_dds.cpp index 13f152f9a3..920c693804 100644 --- a/source/lib/res/graphics/tex_dds.cpp +++ b/source/lib/res/graphics/tex_dds.cpp @@ -605,7 +605,7 @@ static bool dds_is_hdr(const u8* file) static bool dds_is_ext(const char* ext) { - return !stricmp(ext, "dds"); + return !strcasecmp(ext, "dds"); } diff --git a/source/lib/res/graphics/tex_jpg.cpp b/source/lib/res/graphics/tex_jpg.cpp index 8e1f781a80..58d9a6744f 100644 --- a/source/lib/res/graphics/tex_jpg.cpp +++ b/source/lib/res/graphics/tex_jpg.cpp @@ -579,7 +579,7 @@ static bool jpg_is_hdr(const u8* file) static bool jpg_is_ext(const char* ext) { - return !stricmp(ext, "jpg") || !stricmp(ext, "jpeg"); + return !strcasecmp(ext, "jpg") || !strcasecmp(ext, "jpeg"); } diff --git a/source/lib/res/graphics/tex_png.cpp b/source/lib/res/graphics/tex_png.cpp index e07f68bf39..163d686839 100644 --- a/source/lib/res/graphics/tex_png.cpp +++ b/source/lib/res/graphics/tex_png.cpp @@ -204,7 +204,7 @@ static bool png_is_hdr(const u8* file) static bool png_is_ext(const char* ext) { - return !stricmp(ext, "png"); + return !strcasecmp(ext, "png"); } diff --git a/source/lib/res/graphics/tex_tga.cpp b/source/lib/res/graphics/tex_tga.cpp index ec1d1fd61b..4c75204a58 100644 --- a/source/lib/res/graphics/tex_tga.cpp +++ b/source/lib/res/graphics/tex_tga.cpp @@ -91,7 +91,7 @@ static bool tga_is_hdr(const u8* file) static bool tga_is_ext(const char* ext) { - return !stricmp(ext, "tga"); + return !strcasecmp(ext, "tga"); } diff --git a/source/lib/res/sound/snd_mgr.cpp b/source/lib/res/sound/snd_mgr.cpp index a60d569d7c..4ae9ec5a8a 100644 --- a/source/lib/res/sound/snd_mgr.cpp +++ b/source/lib/res/sound/snd_mgr.cpp @@ -1092,7 +1092,7 @@ static LibError SndData_reload(SndData * sd, const char * fn, Handle hsd) const char * ext = path_extension(fn); // .. OGG (data will be passed directly to OpenAL) - if(!stricmp(ext, "ogg")) + if(!strcasecmp(ext, "ogg")) { #ifdef OGG_HACK #else @@ -1626,7 +1626,7 @@ static LibError VSrc_reload(VSrc * vs, const char * fn, Handle hvs) // declare here so that it doesn't go out of scope below. const char * ext = path_extension(fn); - if(!stricmp(ext, "txt")) + if(!strcasecmp(ext, "txt")) { FileIOBuf buf; size_t size; RETURN_ERR(vfs_load(fn, buf, size)); diff --git a/source/lib/sysdep/cpu.h b/source/lib/sysdep/cpu.h index d652c95a77..252c3c9698 100644 --- a/source/lib/sysdep/cpu.h +++ b/source/lib/sysdep/cpu.h @@ -81,6 +81,10 @@ extern bool cpu_CAS(uintptr_t* location, uintptr_t expected, uintptr_t new_value // similar mishaps, the implementation verifies is a valid pointer. #define CAS(l,o,n) cpu_CAS((uintptr_t*)l, (uintptr_t)o, (uintptr_t)n) +/** + * add a signed value to a variable without the possibility of interference + * from other threads/CPUs. + **/ extern void cpu_atomic_add(intptr_t* location, intptr_t increment); // enforce strong memory ordering. diff --git a/source/lib/sysdep/ia32/ia32.h b/source/lib/sysdep/ia32/ia32.h index f0b26a090f..469f638f57 100644 --- a/source/lib/sysdep/ia32/ia32.h +++ b/source/lib/sysdep/ia32/ia32.h @@ -9,7 +9,7 @@ */ /* - * Copyright (c) 2003-2005 Jan Wassenberg + * Copyright (c) 2003-2007 Jan Wassenberg * * Redistribution and/or modification are also permitted under the * terms of the GNU General Public License as published by the @@ -20,8 +20,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ -#ifndef IA32_H -#define IA32_H +#ifndef INCLUDED_IA32 +#define INCLUDED_IA32 #if !CPU_IA32 #error "including ia32.h without CPU_IA32=1" @@ -30,19 +30,19 @@ #include "ia32_asm.h" #include "ia32_memcpy.h" - -// call before any of the following functions +/** + * must be called exactly once before any of the following functions. + **/ extern void ia32_init(); - -// fpclassify return values +/// fpclassify return values #define IA32_FP_NAN 0x0100 #define IA32_FP_NORMAL 0x0400 #define IA32_FP_INFINITE (IA32_FP_NAN | IA32_FP_NORMAL) #define IA32_FP_ZERO 0x4000 #define IA32_FP_SUBNORMAL (IA32_FP_NORMAL | IA32_FP_ZERO) -// FPU control word +// FPU control word (for ia32_asm_control87) // .. Precision Control: #define IA32_MCW_PC 0x0300 #define IA32_PC_24 0x0000 @@ -61,24 +61,9 @@ extern void ia32_init(); #define IA32_EM_UNDERFLOW BIT(4) #define IA32_EM_INEXACT BIT(5) - - -extern void ia32_mfence(); -extern void ia32_serialize(); - - -extern u64 ia32_rdtsc_safe(void); -#if CONFIG_RETURN64_EDX_EAX -# define ia32_rdtsc ia32_asm_rdtsc_edx_eax -#else -# define ia32_rdtsc ia32_rdtsc_safe -#endif - -extern void ia32_debug_break(void); - - -// order in which registers are stored in CPUID regs array -// (do not change! brand string relies on this ordering) +/** + * order in which ia32_asm_cpuid stores register values + **/ enum IA32Regs { EAX, @@ -87,8 +72,10 @@ enum IA32Regs EDX }; -// CPU capability flags (128 bits) -// do not change the order! +/** + * bit indices of CPU capability flags (128 bits). + * values are defined by IA-32 CPUID feature flags - do not change! + **/ enum IA32Cap { // standard (ecx) - currently only defined by Intel @@ -113,25 +100,89 @@ enum IA32Cap IA32_CAP_AMD_3DNOW = 96+31 }; -// indicate if the CPU supports the indicated cap. +/** + * @return whether the CPU supports the indicated IA32Cap / feature flag. + **/ extern bool ia32_cap(IA32Cap cap); -// checks if there is an IA-32 CALL instruction right before ret_addr. -// returns INFO::OK if so and ERR::FAIL if not. -// also attempts to determine the call target. if that is possible -// (directly addressed relative or indirect jumps), it is stored in -// target, which is otherwise 0. -// -// this is useful for walking the stack manually. +/** + * check if there is an IA-32 CALL instruction right before ret_addr. + * @return INFO::OK if so and ERR::FAIL if not. + * + * also attempts to determine the call target. if that is possible + * (directly addressed relative or indirect jumps), it is stored in + * target, which is otherwise 0. + * + * this function is used for walking the call stack. + **/ extern LibError ia32_get_call_target(void* ret_addr, void** target); +/// safe but slow inline-asm version +extern u64 ia32_rdtsc_safe(void); + +/** + * @return the current value of the TimeStampCounter (a counter of + * CPU cycles since power-on, which is useful for high-resolution timing + * but potentially differs between multiple CPUs) + **/ +extern u64 ia32_rdtsc(); // only for CppDoc's benefit +#if CONFIG_RETURN64_EDX_EAX +# define ia32_rdtsc ia32_asm_rdtsc_edx_eax +#else +# define ia32_rdtsc ia32_rdtsc_safe +#endif + +/** + * trigger a breakpoint inside this function when it is called. + **/ +extern void ia32_debug_break(void); + + +// CPU detection + +/** + * @return string identifying the CPU (usually a cleaned-up version of the + * brand string) + **/ extern const char* ia32_identifierString(); + +/** + * @return whether CPU frequency throttling is possible or + * may potentially happen (if so, using RDTSC is unsafe). + **/ extern int ia32_isThrottlingPossible(); + +/** + * @return the cached result of a precise measurement of the + * CPU frequency. + **/ extern double ia32_clockFrequency(); +/** + * @return number of *enabled* CPU packages / sockets. + **/ extern uint ia32_numPackages(); + +/** + * @return number of *enabled* CPU cores per package. + * (2 on dual-core systems) + **/ extern uint ia32_coresPerPackage(); + +/** + * @return number of *enabled* hyperthreading units per core. + * (2 on P4 EE) + **/ extern uint ia32_logicalPerCore(); -#endif // #ifndef IA32_H + +// implementations of the cpu.h interface + +/// see cpu_mfence +extern void ia32_mfence(); + +// see cpu_serialize +extern void ia32_serialize(); + +#endif // #ifndef INCLUDED_IA32 diff --git a/source/lib/sysdep/ia32/ia32_asm.asm b/source/lib/sysdep/ia32/ia32_asm.asm index e741b8e1d1..47898e478f 100644 --- a/source/lib/sysdep/ia32/ia32_asm.asm +++ b/source/lib/sysdep/ia32/ia32_asm.asm @@ -192,9 +192,9 @@ sym(ia32_asm_control87): ; possible IA-32 FPU control word flags after FXAM: NAN|NORMAL|ZERO FP_CLASSIFY_MASK equ 0x4500 -; extern "C" uint __cdecl ia32_asm_fpclassify(double d); -global sym(ia32_asm_fpclassify) -sym(ia32_asm_fpclassify): +; extern "C" uint __cdecl ia32_asm_fpclassifyd(double d); +global sym(ia32_asm_fpclassifyd) +sym(ia32_asm_fpclassifyd): fld qword [esp+4] fxam fnstsw ax diff --git a/source/lib/sysdep/ia32/ia32_asm.h b/source/lib/sysdep/ia32/ia32_asm.h index ca395071f7..92481343bb 100644 --- a/source/lib/sysdep/ia32/ia32_asm.h +++ b/source/lib/sysdep/ia32/ia32_asm.h @@ -5,37 +5,66 @@ extern "C" { #endif +/** + * prepare ia32_asm_cpuid for use (detects which CPUID functions are + * available). called by ia32_init. + **/ extern void ia32_asm_cpuid_init(); -// try to call the specified CPUID sub-function. returns true on success or -// false on failure (i.e. CPUID or the specific function not supported). -// returns eax, ebx, ecx, edx registers in above order. +/** + * try to call the specified CPUID sub-function. + * (note: ECX is set to 0 beforehand as required by sub-function 4) + * fills register array according to IA32Regs. + * @return true on success or false if the sub-function isn't supported. + **/ extern bool ia32_asm_cpuid(u32 func, u32* regs); -extern void ia32_asm_atomic_add(intptr_t* location, intptr_t increment); - - -extern bool ia32_asm_CAS(uintptr_t* location, uintptr_t expected, uintptr_t new_value); - +/** + * for all 1-bits in mask, update the corresponding FPU control word bits + * with the bit values in new_val. + * @return 0 to indicate success. + **/ extern uint ia32_asm_control87(uint new_val, uint mask); -extern uint ia32_asm_fpclassify(double d); +/** + * @return the current value of the TimeStampCounter in edx:eax + * (interpretable as a u64 when using the standard Win32 calling convention) + **/ +extern u64 ia32_asm_rdtsc_edx_eax(void); + +/** + * write the current execution state (e.g. all register values) into + * (Win32::CONTEXT*)pcontext (defined as void* to avoid dependency). + **/ +extern void ia32_asm_get_current_context(void* pcontext); + + +// implementations of the cpu.h interface + +/// see cpu_atomic_add +extern void ia32_asm_atomic_add(intptr_t* location, intptr_t increment); + +/// see cpu_CAS +extern bool ia32_asm_CAS(uintptr_t* location, uintptr_t expected, uintptr_t new_value); + +/// see cpu_i32_from_float +extern i32 ia32_asm_i32_from_float(float f); +extern i32 ia32_asm_i32_from_double(double d); +extern i64 ia32_asm_i64_from_double(double d); + + +// backends for POSIX/SUS functions + +/// see fpclassify +extern uint ia32_asm_fpclassifyd(double d); extern uint ia32_asm_fpclassifyf(float f); +/// see rintf extern float ia32_asm_rintf(float); extern double ia32_asm_rint(double); extern float ia32_asm_fminf(float, float); extern float ia32_asm_fmaxf(float, float); -extern i32 ia32_asm_i32_from_float(float f); -extern i32 ia32_asm_i32_from_double(double d); -extern i64 ia32_asm_i64_from_double(double d); - -extern u64 ia32_asm_rdtsc_edx_eax(void); - -// write the current execution state (e.g. all register values) into -// (Win32::CONTEXT*)pcontext (defined as void* to avoid dependency). -extern void ia32_asm_get_current_context(void* pcontext); #ifdef __cplusplus } diff --git a/source/lib/sysdep/sysdep.h b/source/lib/sysdep/sysdep.h index 20196e6774..31b6040a55 100644 --- a/source/lib/sysdep/sysdep.h +++ b/source/lib/sysdep/sysdep.h @@ -26,31 +26,9 @@ #include "lib/config.h" #include "lib/debug.h" // ErrorReaction -#include // needed for vsnprintf2 +#include // needed for sys_vsnprintf -//----------------------------------------------------------------------------- -// C99 / SUSv3 emulation where needed -//----------------------------------------------------------------------------- - -// vsnprintf2: doesn't quite follow the standard for vsnprintf, but works -// better across compilers: -// - handles positional parameters and %lld -// - always null-terminates the buffer -// - returns -1 on overflow (if the output string (including null) does not fit in the buffer) -extern int vsnprintf2(char* buffer, size_t count, const char* format, va_list argptr); - -#if !MSC_VERSION -#define stricmp strcasecmp -#define strnicmp strncasecmp -#endif - - - -//----------------------------------------------------------------------------- -// sysdep API -//----------------------------------------------------------------------------- - // // output // @@ -120,6 +98,14 @@ extern LibError sys_cursor_free(void* cursor); // misc // +// sys_vsnprintf: doesn't quite follow the standard for vsnprintf, but works +// better across compilers: +// - handles positional parameters and %lld +// - always null-terminates the buffer +// - returns -1 on overflow (if the output string (including null) does not fit in the buffer) +extern int sys_vsnprintf(char* buffer, size_t count, const char* format, va_list argptr); + + /** * allocate on stack, automatically free when current function returns. **/ diff --git a/source/lib/sysdep/tests/test_printf.h b/source/lib/sysdep/tests/test_printf.h index a20c33906a..1df12e7c29 100644 --- a/source/lib/sysdep/tests/test_printf.h +++ b/source/lib/sysdep/tests/test_printf.h @@ -6,7 +6,7 @@ class TestPrintf : public CxxTest::TestSuite { // Split some bits into separate functions, so we can get - // a legitimate va_list to pass to vsnprintf2: + // a legitimate va_list to pass to sys_vsnprintf: void _test_truncate(int buffer_size, char* expected_output, int expected_return, /* char* input_string */...) { @@ -15,7 +15,7 @@ class TestPrintf : public CxxTest::TestSuite va_list ap; va_start(ap, expected_return); - int ret = vsnprintf2(buf, buffer_size, "%s", ap); + int ret = sys_vsnprintf(buf, buffer_size, "%s", ap); TS_ASSERT_STR_EQUALS(buf, expected_output); TS_ASSERT_EQUALS(ret, expected_return); @@ -33,7 +33,7 @@ class TestPrintf : public CxxTest::TestSuite va_list ap; va_start(ap, format); - vsnprintf2(buf, sizeof(buf), format, ap); + sys_vsnprintf(buf, sizeof(buf), format, ap); TS_ASSERT_STR_EQUALS(buf, expected_output); va_end(ap); diff --git a/source/lib/sysdep/unix/printf.cpp b/source/lib/sysdep/unix/printf.cpp index 548b4ba109..f7b352c0b5 100644 --- a/source/lib/sysdep/unix/printf.cpp +++ b/source/lib/sysdep/unix/printf.cpp @@ -5,7 +5,7 @@ // See declaration in sysdep.h for explanation of need -int vsnprintf2(char* buffer, size_t count, const char* format, va_list argptr) +int sys_vsnprintf(char* buffer, size_t count, const char* format, va_list argptr) { int ret = vsnprintf(buffer, count, format, argptr); diff --git a/source/lib/sysdep/win/delay_load.cpp b/source/lib/sysdep/win/delay_load.cpp index 8c1e7b0667..2b817a8758 100644 --- a/source/lib/sysdep/win/delay_load.cpp +++ b/source/lib/sysdep/win/delay_load.cpp @@ -623,7 +623,7 @@ static FARPROC WINAPI notify_hook(unsigned dliNotify, PDelayLoadInfo pdli) return 0; for(DllLoadNotify* n = notify_list; n; n = n->next) - if(strnicmp(pdli->szDll, n->dll_name, strlen(n->dll_name)) == 0) + if(strncasecmp(pdli->szDll, n->dll_name, strlen(n->dll_name)) == 0) n->func(); return 0; diff --git a/source/lib/sysdep/win/printf.h b/source/lib/sysdep/win/printf.h deleted file mode 100644 index 647c6fc446..0000000000 --- a/source/lib/sysdep/win/printf.h +++ /dev/null @@ -1,2 +0,0 @@ -// Acts like vsnprintf, but handles positional parameters and %lld -int vsnprintf2(char* buffer, size_t count, const char* format, va_list argptr); diff --git a/source/lib/sysdep/win/printf.cpp b/source/lib/sysdep/win/wprintf.cpp similarity index 99% rename from source/lib/sysdep/win/printf.cpp rename to source/lib/sysdep/win/wprintf.cpp index 0ebf11e7b5..014c741048 100644 --- a/source/lib/sysdep/win/printf.cpp +++ b/source/lib/sysdep/win/wprintf.cpp @@ -175,7 +175,7 @@ int type_size(TCHAR type, int length) return 0; } -int vsnprintf2(TCHAR* buffer, size_t count, const TCHAR* format, va_list argptr) +int sys_vsnprintf(TCHAR* buffer, size_t count, const TCHAR* format, va_list argptr) { /* diff --git a/source/lib/sysdep/win/wsnd.cpp b/source/lib/sysdep/win/wsnd.cpp index ae9ab1c7ae..c21769200a 100644 --- a/source/lib/sysdep/win/wsnd.cpp +++ b/source/lib/sysdep/win/wsnd.cpp @@ -90,7 +90,7 @@ static LibError add_if_oal_dll(const DirEnt* ent, PathPackage* pp, StringSet* dl // skip if not an OpenAL DLL. const size_t len = strlen(fn); - const bool oal = len >= 7 && !stricmp(fn+len-7, "oal.dll"); + const bool oal = len >= 7 && !strcasecmp(fn+len-7, "oal.dll"); const bool openal = strstr(fn, "OpenAL") != 0; if(!oal && !openal) return INFO::OK; diff --git a/source/ps/CLogger.cpp b/source/ps/CLogger.cpp index cbd2d6a3ae..fa339db846 100644 --- a/source/ps/CLogger.cpp +++ b/source/ps/CLogger.cpp @@ -170,7 +170,7 @@ void CLogger::Log(ELogMethod method, const char* category, const char *fmt, ...) char buffer[512]; va_start(argp, fmt); - if (vsnprintf2(buffer, sizeof(buffer), fmt, argp) == -1) + if (sys_vsnprintf(buffer, sizeof(buffer), fmt, argp) == -1) { // Buffer too small - ensure the string is nicely terminated strcpy(buffer+sizeof(buffer)-4, "..."); // safe @@ -187,7 +187,7 @@ void CLogger::LogOnce(ELogMethod method, const char* category, const char *fmt, char buffer[512]; va_start(argp, fmt); - if (vsnprintf2(buffer, sizeof(buffer), fmt, argp) == -1) + if (sys_vsnprintf(buffer, sizeof(buffer), fmt, argp) == -1) { // Buffer too small - ensure the string is nicely terminated strcpy(buffer+sizeof(buffer)-4, "..."); // safe diff --git a/source/ps/FileUnpacker.cpp b/source/ps/FileUnpacker.cpp index 5b77693649..1537a8fd95 100644 --- a/source/ps/FileUnpacker.cpp +++ b/source/ps/FileUnpacker.cpp @@ -46,7 +46,7 @@ void CFileUnpacker::Read(const char* filename,const char magicstr[4]) // that the buffer will be kept in memory longer (avoids warning). uint flags = 0; const char* ext = path_extension(filename); - if(!stricmp(ext, "pmp")) + if(!strcasecmp(ext, "pmp")) flags |= FILE_LONG_LIVED; // load the whole thing into memory diff --git a/source/ps/Util.cpp b/source/ps/Util.cpp index 4b8ce7bc0a..9c78037bba 100644 --- a/source/ps/Util.cpp +++ b/source/ps/Util.cpp @@ -176,7 +176,7 @@ void WriteScreenshot(const char* extension) int flags = TEX_BOTTOM_UP; // we want writing BMP to be as fast as possible, // so read data from OpenGL in BMP format to obviate conversion. - if(!stricmp(extension, "bmp")) + if(!strcasecmp(extension, "bmp")) { fmt = GL_BGR; flags |= TEX_BGR; @@ -221,7 +221,7 @@ void WriteBigScreenshot(const char* extension, int tiles) int flags = TEX_BOTTOM_UP; // we want writing BMP to be as fast as possible, // so read data from OpenGL in BMP format to obviate conversion. - if(!stricmp(extension, "bmp")) + if(!strcasecmp(extension, "bmp")) { fmt = GL_BGR; flags |= TEX_BGR; diff --git a/source/ps/XML/XeroXMB.cpp b/source/ps/XML/XeroXMB.cpp index 91c4b05d7a..fd85c4a01e 100644 --- a/source/ps/XML/XeroXMB.cpp +++ b/source/ps/XML/XeroXMB.cpp @@ -89,7 +89,7 @@ int XMBFile::getElementID(const char* Name) const { // See if this could be the right string, checking its // length and then its contents - if (*(int*)Pos == len && strnicmp(Pos+4, Name, len) == 0) + if (*(int*)Pos == len && strncasecmp(Pos+4, Name, len) == 0) return i; // If not, jump to the next string Pos += 4 + *(int*)Pos; @@ -109,7 +109,7 @@ int XMBFile::getAttributeID(const char* Name) const { // See if this could be the right string, checking its // length and then its contents - if (*(int*)Pos == len && strnicmp(Pos+4, Name, len) == 0) + if (*(int*)Pos == len && strncasecmp(Pos+4, Name, len) == 0) return i; // If not, jump to the next string Pos += 4 + *(int*)Pos; diff --git a/source/scripting/ScriptGlue.cpp b/source/scripting/ScriptGlue.cpp index b890b6735e..60d74ae45f 100644 --- a/source/scripting/ScriptGlue.cpp +++ b/source/scripting/ScriptGlue.cpp @@ -1508,11 +1508,11 @@ JSFunctionSpec ScriptFunctionTable[] = JSBool GetEntitySet( JSContext* UNUSED(cx), JSObject* UNUSED(obj), jsval UNUSED(argv), jsval* vp ) { - std::auto_ptr > extant (g_EntityManager.getExtant()); + std::vector extant; + g_EntityManager.GetExtantAsHandles(extant); + *vp = OBJECT_TO_JSVAL(EntityCollection::Create(extant)); - *vp = OBJECT_TO_JSVAL( EntityCollection::Create( *extant ) ); - - return( JS_TRUE ); + return JS_TRUE; } diff --git a/source/simulation/EntityHandles.cpp b/source/simulation/EntityHandles.cpp index f017405230..e4ae07fefc 100644 --- a/source/simulation/EntityHandles.cpp +++ b/source/simulation/EntityHandles.cpp @@ -31,7 +31,7 @@ HEntity::HEntity() HEntity::~HEntity() { - if( CEntityManager::extant() ) + if( CEntityManager::IsExtant() ) decRef(); } diff --git a/source/simulation/EntityManager.cpp b/source/simulation/EntityManager.cpp index f08c3f743e..8b8be9d28f 100644 --- a/source/simulation/EntityManager.cpp +++ b/source/simulation/EntityManager.cpp @@ -184,13 +184,12 @@ std::vector* CEntityManager::matches( EntityPredicate predicate, void* return( matchlist ); } -std::vector* CEntityManager::getExtant() +void CEntityManager::GetExtantAsHandles( std::vector& results ) { - std::vector* activelist = new std::vector; + results.clear(); for( int i = 0; i < MAX_HANDLES; i++ ) if( isEntityRefd(i) ) - activelist->push_back( HEntity( i ) ); - return( activelist ); + results.push_back( HEntity( i ) ); } void CEntityManager::GetExtant( std::vector& results ) diff --git a/source/simulation/EntityManager.h b/source/simulation/EntityManager.h index 484c9c6011..dc2af02a42 100644 --- a/source/simulation/EntityManager.h +++ b/source/simulation/EntityManager.h @@ -11,7 +11,7 @@ // Perform updates on all world entities by g_EntityManager.updateAll( timestep ) // Dispatch an identical message to all world entities by g_EntityManager.dispatchAll( message_pointer ) // Get an STL vector container of all entities with a certain property with g_EntityManager.matches( predicate ) -// or just get all entities with g_EntityManager.getExtant(). +// or just get all entities with g_EntityManager.GetExtant(). // // Those last two functions - caller has responsibility for deleting the collection when you're done with it. @@ -113,9 +113,9 @@ public: { return( !operand( target, userdata ) ); } std::vector* matches( EntityPredicate predicate, void* userdata = NULL ); - std::vector* getExtant(); - void GetExtant( std::vector& results ); // TODO: Switch most/all uses of getExtant() to this. - static inline bool extant() // True if the singleton is actively maintaining handles. When false, system is shutting down, handles are quietly dumped. + void GetExtantAsHandles( std::vector& results ); + void GetExtant( std::vector& results ); + static inline bool IsExtant() // True if the singleton is actively maintaining handles. When false, system is shutting down, handles are quietly dumped. { return( m_extant ); } diff --git a/source/tools/pmdexp/ModelDef.cpp b/source/tools/pmdexp/ModelDef.cpp index 6abaaa6b21..200cbbe3d1 100644 --- a/source/tools/pmdexp/ModelDef.cpp +++ b/source/tools/pmdexp/ModelDef.cpp @@ -35,7 +35,7 @@ CModelDef::~CModelDef() SPropPoint* CModelDef::FindPropPoint(const char* name) const { for (uint i=0;i