minor error path improvements+comments; add WARN_IF_FALSE et al.
This was SVN commit r2693.
This commit is contained in:
parent
3c9ad073bc
commit
189786928e
@ -170,6 +170,34 @@ STMT(\
|
||||
|
||||
|
||||
|
||||
// if ok evaluates to false or FALSE, warn user and return -1.
|
||||
#define WARN_RETURN_IF_FALSE(ok)\
|
||||
STMT(\
|
||||
if(!(ok))\
|
||||
{\
|
||||
debug_warn("FYI: WARN_RETURN_IF_FALSE reports that a function failed."\
|
||||
"feel free to ignore or suppress this warning.");\
|
||||
return -1;\
|
||||
}\
|
||||
)
|
||||
|
||||
// if ok evaluates to false or FALSE, return -1.
|
||||
#define RETURN_IF_FALSE(ok)\
|
||||
STMT(\
|
||||
if(!(ok))\
|
||||
return -1;\
|
||||
)
|
||||
|
||||
// if ok evaluates to false or FALSE, warn user.
|
||||
#define WARN_IF_FALSE(ok)\
|
||||
STMT(\
|
||||
if(!(ok))\
|
||||
debug_warn("FYI: WARN_IF_FALSE reports that a function failed."\
|
||||
"feel free to ignore or suppress this warning.");\
|
||||
)
|
||||
|
||||
|
||||
|
||||
// useful because VC6 may return 0 on failure, instead of throwing.
|
||||
// this wraps the exception handling, and creates a NULL pointer on failure.
|
||||
#define SAFE_NEW(type, ptr)\
|
||||
@ -183,7 +211,8 @@ STMT(\
|
||||
ptr = 0;\
|
||||
}
|
||||
|
||||
#define SAFE_DELETE(p) STMT(\
|
||||
#define SAFE_DELETE(p)\
|
||||
STMT(\
|
||||
if((p))\
|
||||
{\
|
||||
delete (p);\
|
||||
|
@ -385,28 +385,28 @@ typedef std::set<std::string> StringSet;
|
||||
// note: we need the full DLL path for dll_list_add but DirEnt only gives us
|
||||
// the name. for efficiency, we append this in a PathPackage allocated by
|
||||
// add_oal_dlls_in_dir.
|
||||
static void add_if_oal_dll(const DirEnt* ent, PathPackage* pp, StringSet* dlls)
|
||||
static int add_if_oal_dll(const DirEnt* ent, PathPackage* pp, StringSet* dlls)
|
||||
{
|
||||
const char* fn = ent->name;
|
||||
|
||||
// skip non-files.
|
||||
if(!DIRENT_IS_DIR(ent))
|
||||
return;
|
||||
return 0;
|
||||
|
||||
// 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 openal = strstr(fn, "OpenAL") != 0;
|
||||
if(!oal && !openal)
|
||||
return;
|
||||
return 0;
|
||||
|
||||
// skip if already in StringSet (i.e. has already been dll_list_add-ed)
|
||||
std::pair<StringSet::iterator, bool> ret = dlls->insert(fn);
|
||||
if(!ret.second) // insert failed - element already there
|
||||
return;
|
||||
return 0;
|
||||
|
||||
WARN_ERR_RETURN(pp_append_file(pp, fn)); // todo4
|
||||
(void)dll_list_add(pp->path);
|
||||
RETURN_ERR(pp_append_file(pp, fn));
|
||||
return dll_list_add(pp->path);
|
||||
}
|
||||
|
||||
|
||||
@ -416,26 +416,25 @@ static void add_if_oal_dll(const DirEnt* ent, PathPackage* pp, StringSet* dlls)
|
||||
// same name in the system directory.
|
||||
//
|
||||
// <dir>: no trailing.
|
||||
static void add_oal_dlls_in_dir(const char* dir, StringSet* dlls)
|
||||
static int add_oal_dlls_in_dir(const char* dir, StringSet* dlls)
|
||||
{
|
||||
int err;
|
||||
|
||||
PathPackage pp;
|
||||
(void)pp_set_dir(&pp, dir);
|
||||
RETURN_ERR(pp_set_dir(&pp, dir));
|
||||
|
||||
DirIterator d;
|
||||
WARN_ERR_RETURN(dir_open(dir, &d)); // TODO4
|
||||
RETURN_ERR(dir_open(dir, &d));
|
||||
|
||||
DirEnt ent;
|
||||
for(;;) // instead of while to avoid warning
|
||||
{
|
||||
err = dir_next_ent(&d, &ent);
|
||||
if(err == ERR_DIR_END)
|
||||
int err = dir_next_ent(&d, &ent);
|
||||
if(err != 0)
|
||||
break;
|
||||
add_if_oal_dll(&ent, &pp, dlls);
|
||||
(void)add_if_oal_dll(&ent, &pp, dlls);
|
||||
}
|
||||
|
||||
(void)dir_close(&d);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -481,9 +480,9 @@ int win_get_snd_info()
|
||||
// find all DLLs related to OpenAL, retrieve their versions,
|
||||
// and store in snd_drv_ver string.
|
||||
dll_list_init(snd_drv_ver, SND_DRV_VER_LEN);
|
||||
dll_list_add(ds_drv_path);
|
||||
(void)dll_list_add(ds_drv_path);
|
||||
StringSet dlls; // ensures uniqueness
|
||||
add_oal_dlls_in_dir(win_exe_dir, &dlls);
|
||||
add_oal_dlls_in_dir(win_sys_dir, &dlls);
|
||||
(void)add_oal_dlls_in_dir(win_exe_dir, &dlls);
|
||||
(void)add_oal_dlls_in_dir(win_sys_dir, &dlls);
|
||||
return 0;
|
||||
}
|
||||
|
@ -225,7 +225,7 @@ static void detect_filesystem()
|
||||
|
||||
|
||||
// from wtime
|
||||
extern time_t local_filetime_to_time_t(FILETIME* ft);
|
||||
extern time_t time_t_from_local_filetime(FILETIME* ft);
|
||||
extern time_t utc_filetime_to_time_t(FILETIME* ft);
|
||||
|
||||
// convert Windows FILETIME to POSIX time_t (seconds-since-1970 UTC);
|
||||
@ -246,7 +246,7 @@ static time_t filetime_to_time_t(FILETIME* ft)
|
||||
{
|
||||
FILETIME local_ft;
|
||||
FileTimeToLocalFileTime(ft, &local_ft);
|
||||
return local_filetime_to_time_t(&local_ft);
|
||||
return time_t_from_local_filetime(&local_ft);
|
||||
}
|
||||
|
||||
return utc_filetime_to_time_t(ft);
|
||||
@ -615,11 +615,7 @@ int mprotect(void* addr, size_t len, int prot)
|
||||
const DWORD flNewProtect = win32_prot(prot);
|
||||
DWORD flOldProtect; // required by VirtualProtect
|
||||
BOOL ok = VirtualProtect(addr, len, flNewProtect, &flOldProtect);
|
||||
if(!ok)
|
||||
{
|
||||
debug_warn("mprotect failed"); // todo4
|
||||
return -1;
|
||||
}
|
||||
WARN_RETURN_IF_FALSE(ok);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -776,12 +772,7 @@ int munmap(void* start, size_t UNUSED(len))
|
||||
// VirtualFree requires dwSize to be 0 (entire region is released).
|
||||
ok = VirtualFree(start, 0, MEM_RELEASE);
|
||||
|
||||
// both failed
|
||||
if(!ok)
|
||||
{
|
||||
debug_warn("munmap failed"); // todo4
|
||||
return -1;
|
||||
}
|
||||
WARN_RETURN_IF_FALSE(ok); // both failed
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -804,9 +795,8 @@ static void* void_from_HMODULE(HMODULE hModule)
|
||||
int dlclose(void* handle)
|
||||
{
|
||||
BOOL ok = FreeLibrary(HMODULE_from_void(handle));
|
||||
if(!ok)
|
||||
debug_warn("dlclose failed");
|
||||
return ok? 0 : -1;
|
||||
WARN_RETURN_IF_FALSE(ok);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -185,8 +185,7 @@ static int choose_impl()
|
||||
// this happens on notebooks now, but eventually desktop systems
|
||||
// will do this as well (if not to save power, for heat reasons).
|
||||
// frequency changes are too often and drastic to correct,
|
||||
// and we don't want to mess with the system power settings.
|
||||
// => unsafe.
|
||||
// and we don't want to mess with the system power settings => unsafe.
|
||||
if(cpu_freq > 0.0 && ia32_cap(TSC))
|
||||
{
|
||||
safe = (cpu_smp == 0 && cpu_speedstep == 0);
|
||||
@ -294,13 +293,13 @@ static i64 ticks_lk()
|
||||
{
|
||||
switch(hrt_impl)
|
||||
{
|
||||
// TSC
|
||||
// TSC
|
||||
#if CPU_IA32 && !defined(NO_TSC)
|
||||
case HRT_TSC:
|
||||
return (i64)rdtsc();
|
||||
#endif
|
||||
|
||||
// QPC
|
||||
// QPC
|
||||
#if OS_WIN && !defined(NO_QPC)
|
||||
case HRT_QPC:
|
||||
{
|
||||
@ -311,7 +310,7 @@ static i64 ticks_lk()
|
||||
}
|
||||
#endif
|
||||
|
||||
// TGT
|
||||
// TGT
|
||||
#if OS_WIN
|
||||
case HRT_GTC:
|
||||
return (i64)GetTickCount();
|
||||
@ -681,7 +680,7 @@ time_t utc_filetime_to_time_t(FILETIME* ft)
|
||||
// and ourselves adding the appropriate bias.
|
||||
//
|
||||
// called for FAT file times; see wposix filetime_to_time_t.
|
||||
time_t local_filetime_to_time_t(FILETIME* ft)
|
||||
time_t time_t_from_local_filetime(FILETIME* ft)
|
||||
{
|
||||
SYSTEMTIME st;
|
||||
FileTimeToSystemTime(ft, &st);
|
||||
@ -752,12 +751,6 @@ static int wtime_shutdown()
|
||||
return hrt_shutdown();
|
||||
}
|
||||
|
||||
// Called by the crash code to kill the thread,
|
||||
// because it disrupts debugging.
|
||||
void abort_timer()
|
||||
{
|
||||
wtime_shutdown();
|
||||
}
|
||||
|
||||
void wtime_reset_impl()
|
||||
{
|
||||
@ -828,14 +821,14 @@ int gettimeofday(struct timeval* tv, void* UNUSED(tzp))
|
||||
|
||||
uint sleep(uint sec)
|
||||
{
|
||||
Sleep(sec * 1000);
|
||||
Sleep(sec * 1000); // don't bother checking for overflow (user's fault)
|
||||
return sec;
|
||||
}
|
||||
|
||||
|
||||
int usleep(useconds_t us)
|
||||
{
|
||||
// can't overflow, because us < 1e6
|
||||
sleep_ns(us * 1000);
|
||||
debug_assert(us < _1e6);
|
||||
sleep_ns(us * 1000); // can't overflow due to <us> limit
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user