allocators: fix OverrunProtector - avoid crash at exit if the object was never actually used
lib: add display_msgw which is a wrapper around the sys_display_msgw impl and takes care of translating text lib_errors: codes are now an enum (this will allow a special return type and make documentation much more clear); codes are defined in the header, not from lib.h wsdl: resolve todo comment This was SVN commit r3217.
This commit is contained in:
parent
724477a0d9
commit
7e6d38314d
@ -223,11 +223,7 @@ public:
|
||||
|
||||
~OverrunProtector()
|
||||
{
|
||||
initialized = 2;
|
||||
unlock();
|
||||
cached_ptr->~T(); // call dtor (since we used placement new)
|
||||
cached_ptr = 0;
|
||||
(void)da_free(&da);
|
||||
shutdown();
|
||||
}
|
||||
|
||||
void lock()
|
||||
@ -264,9 +260,22 @@ fail:
|
||||
debug_warn("OverrunProtector mem alloc failed");
|
||||
}
|
||||
|
||||
void shutdown()
|
||||
{
|
||||
if(!CAS(&initialized, 1, 2))
|
||||
return; // never initialized or already shut down - abort
|
||||
unlock();
|
||||
cached_ptr->~T(); // call dtor (since we used placement new)
|
||||
cached_ptr = 0;
|
||||
(void)da_free(&da);
|
||||
}
|
||||
|
||||
public:
|
||||
T* get()
|
||||
{
|
||||
// this could theoretically be done in the ctor, but we try to
|
||||
// minimize non-trivial code at NLSO ctor time
|
||||
// (avoids init order problems).
|
||||
if(CAS(&initialized, 0, 1))
|
||||
init();
|
||||
debug_assert(initialized != 2 && "OverrunProtector: used after dtor called:");
|
||||
|
@ -22,6 +22,7 @@
|
||||
|
||||
#include "lib/types.h"
|
||||
#include "lib.h"
|
||||
#include "lib/app_hooks.h"
|
||||
|
||||
#include "sysdep/sysdep.h"
|
||||
|
||||
@ -30,6 +31,14 @@
|
||||
#endif
|
||||
|
||||
|
||||
// translates the given strings and passes them on to sys_display_msgw
|
||||
// (see documentation there).
|
||||
void display_msgw(const wchar_t* caption, const wchar_t* msg)
|
||||
{
|
||||
sys_display_msgw(ah_translate(caption), ah_translate(msg));
|
||||
}
|
||||
|
||||
|
||||
// FNV1-A hash - good for strings.
|
||||
// if len = 0 (default), treat buf as a C-string;
|
||||
// otherwise, hash <len> bytes of buf.
|
||||
|
@ -59,8 +59,6 @@ scope
|
||||
#include "config.h"
|
||||
#include "lib/types.h"
|
||||
|
||||
// define error codes
|
||||
#define ERR(err, id, str) const int id = err;
|
||||
#include "lib/lib_errors.h"
|
||||
|
||||
#include "sysdep/sysdep.h"
|
||||
@ -313,6 +311,12 @@ const size_t GiB = 1ul << 30;
|
||||
#endif
|
||||
|
||||
|
||||
// translates the given strings and passes them on to sys_display_msgw
|
||||
// (see documentation there).
|
||||
extern void display_msgw(const wchar_t* caption, const wchar_t* msg);
|
||||
|
||||
|
||||
|
||||
#define BIT(n) (1ul << (n))
|
||||
|
||||
|
||||
|
@ -1,11 +1,46 @@
|
||||
// note: this is called lib_errors.h because we have another
|
||||
// errors.cpp; the MS linker isn't smart enough to deal with
|
||||
// object files of the same name but in different paths.
|
||||
// notes:
|
||||
// - file is called lib_errors.h because 0ad has another errors.cpp and
|
||||
// the MS linker isn't smart enough to deal with object files
|
||||
// of the same name but in different paths.
|
||||
// - the first part of this file is a normal header; the second contains
|
||||
// X macros and is only active if ERR is defined (i.e. someone is
|
||||
// including this header for the purpose of using them).
|
||||
|
||||
#ifndef ERRORS_H__
|
||||
#define ERRORS_H__
|
||||
|
||||
// limits on the errors defined above (used by error_description_r)
|
||||
#define ERR_MIN 100000
|
||||
#define ERR_MAX 110000
|
||||
|
||||
// define error codes.
|
||||
enum LibError {
|
||||
#define ERR(err, id, str) id = err,
|
||||
#include "lib_errors.h"
|
||||
// necessary because the enum would otherwise end with a comma
|
||||
// (which is often tolerated but not standards compliant).
|
||||
// note: we cannot rely on this being the last value (in case the
|
||||
// ERR x-macros aren't arranged in order), so don't use as such.
|
||||
LIB_ERROR_DUMMY
|
||||
};
|
||||
|
||||
|
||||
// generate textual description of an error code.
|
||||
// stores up to <max_chars> in the given buffer.
|
||||
// <err> can be one of the above error codes, POSIX ENOENT etc., or
|
||||
// an OS-specific errors. if unknown, the string will be something like
|
||||
// "Unknown error (65536, 0x10000)".
|
||||
extern void error_description_r(int err, char* buf, size_t max_chars);
|
||||
|
||||
#endif // #ifndef ERRORS_H__
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifdef ERR
|
||||
|
||||
// X macros: error code, symbolic name in code, user-visible string.
|
||||
// error code is usually negative; positive denotes warnings.
|
||||
// its absolute value must be within [ERR_MIN, ERR_MAX).
|
||||
#ifdef ERR
|
||||
|
||||
// function arguments
|
||||
ERR(-100000, ERR_INVALID_PARAM, "Invalid function argument")
|
||||
@ -58,22 +93,3 @@ ERR(-100704, ERR_SHDR_NO_PROGRAM, "Invalid shader program reference")
|
||||
|
||||
#undef ERR
|
||||
#endif // #ifdef ERR
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef ERRORS_H__
|
||||
#define ERRORS_H__
|
||||
|
||||
// limits on the errors defined above (used by error_description_r)
|
||||
#define ERR_MIN 100000
|
||||
#define ERR_MAX 110000
|
||||
|
||||
// generate textual description of an error code.
|
||||
// stores up to <max_chars> in the given buffer.
|
||||
// <err> can be one of the above error codes, POSIX ENOENT etc., or
|
||||
// an OS-specific errors. if unknown, the string will be something like
|
||||
// "Unknown error (65536, 0x10000)".
|
||||
extern void error_description_r(int err, char* buf, size_t max_chars);
|
||||
|
||||
#endif // #ifndef ERRORS_H__
|
@ -127,6 +127,8 @@ extern void* alloca(size_t size);
|
||||
// output
|
||||
//
|
||||
|
||||
// raise a message box with the given text or (depending on platform)
|
||||
// otherwise inform the user.
|
||||
extern void sys_display_msg(const char* caption, const char* msg);
|
||||
extern void sys_display_msgw(const wchar_t* caption, const wchar_t* msg);
|
||||
|
||||
|
@ -1128,7 +1128,8 @@ void SDL_WM_SetCaption(const char* title, const char* icon)
|
||||
{
|
||||
WARN_IF_FALSE(SetWindowText(hWnd, title));
|
||||
|
||||
UNUSED2(icon); // TODO: implement
|
||||
// real SDL ignores this parameter, so we will follow suit.
|
||||
UNUSED2(icon);
|
||||
}
|
||||
|
||||
|
||||
|
@ -333,8 +333,7 @@ ErrorReaction sys_display_error(const wchar_t* text, int flags)
|
||||
// failed; warn user and make sure we return an ErrorReaction.
|
||||
if(ret == 0 || ret == -1)
|
||||
{
|
||||
sys_display_msgw(L"Error", L"Unable to display detailed error dialog.");
|
||||
// TODO: i18n
|
||||
display_msgw(L"Error", L"Unable to display detailed error dialog.");
|
||||
return ER_CONTINUE;
|
||||
}
|
||||
return (ErrorReaction)ret;
|
||||
|
Loading…
Reference in New Issue
Block a user