mirror of
https://github.com/thunderbrewhq/squall.git
synced 2025-12-12 18:42:28 +00:00
refactor(error): make error variables properly static
This commit is contained in:
parent
57430d406f
commit
6cbf0d23bf
5 changed files with 74 additions and 74 deletions
|
|
@ -1,49 +0,0 @@
|
|||
#include "storm/Error.hpp"
|
||||
#include "storm/error/Error.hpp"
|
||||
|
||||
#include "storm/Thread.hpp"
|
||||
|
||||
#include <cstdarg>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
|
||||
[[noreturn]] void SErrDisplayAppFatal(const char* format, ...) {
|
||||
// Format arguments
|
||||
constexpr size_t size = 1024;
|
||||
char buffer[size] = {0};
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
vsnprintf(buffer, size, format, args);
|
||||
va_end(args);
|
||||
|
||||
SErrDisplayError(STORM_ERROR_APPLICATION_FATAL, s_appFatInfo.filename, s_appFatInfo.linenumber, buffer, 0, 1, 0);
|
||||
}
|
||||
|
||||
int32_t SErrDisplayErrorFmt(uint32_t errorcode, const char* filename, int32_t linenumber, int32_t recoverable, uint32_t exitcode, const char* format, ...) {
|
||||
char buffer[2048];
|
||||
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
vsnprintf(buffer, sizeof(buffer) - 1, format, args);
|
||||
buffer[sizeof(buffer) - 1] = '\0';
|
||||
va_end(args);
|
||||
|
||||
return SErrDisplayError(errorcode, filename, linenumber, buffer, recoverable, exitcode, 1);
|
||||
}
|
||||
|
||||
void SErrPrepareAppFatal(const char* filename, int32_t linenumber) {
|
||||
s_appFatInfo.filename = filename;
|
||||
s_appFatInfo.linenumber = linenumber;
|
||||
s_appFatInfo.threadId = SGetCurrentThreadId();
|
||||
}
|
||||
|
||||
void SErrSetLastError(uint32_t errorcode) {
|
||||
s_lasterror = errorcode;
|
||||
#if defined(WHOA_SYSTEM_WIN)
|
||||
SetLastError(errorcode);
|
||||
#endif
|
||||
}
|
||||
|
||||
uint32_t SErrGetLastError() {
|
||||
return s_lasterror;
|
||||
}
|
||||
|
|
@ -1,21 +1,6 @@
|
|||
#ifndef STORM_ERROR_HPP
|
||||
#define STORM_ERROR_HPP
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "storm/error/Macro.hpp"
|
||||
#include "storm/error/Codes.hpp"
|
||||
|
||||
[[noreturn]] void SErrDisplayAppFatal(const char* format, ...);
|
||||
|
||||
int32_t SErrDisplayError(uint32_t errorcode, const char* filename, int32_t linenumber, const char* description, int32_t recoverable, uint32_t exitcode, uint32_t a7);
|
||||
|
||||
int32_t SErrDisplayErrorFmt(uint32_t errorcode, const char* filename, int32_t linenumber, int32_t recoverable, uint32_t exitcode, const char* format, ...);
|
||||
|
||||
void SErrPrepareAppFatal(const char* filename, int32_t linenumber);
|
||||
|
||||
void SErrSetLastError(uint32_t errorcode);
|
||||
|
||||
uint32_t SErrGetLastError();
|
||||
#include "storm/error/Error.hpp"
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,6 +1,52 @@
|
|||
#include "storm/error/Error.hpp"
|
||||
#include "storm/error/Codes.hpp"
|
||||
#include "storm/error/Types.hpp"
|
||||
#include "storm/Thread.hpp"
|
||||
|
||||
uint32_t s_lasterror = ERROR_SUCCESS;
|
||||
APPFATINFO s_appFatInfo = {};
|
||||
#include <cstdarg>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
|
||||
static uint32_t s_lasterror = ERROR_SUCCESS;
|
||||
static APPFATINFO s_appFatInfo = {};
|
||||
|
||||
[[noreturn]] void SErrDisplayAppFatal(const char* format, ...) {
|
||||
// Format arguments
|
||||
constexpr size_t size = 1024;
|
||||
char buffer[size] = {0};
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
vsnprintf(buffer, size, format, args);
|
||||
va_end(args);
|
||||
|
||||
SErrDisplayError(STORM_ERROR_APPLICATION_FATAL, s_appFatInfo.filename, s_appFatInfo.linenumber, buffer, 0, 1, 0);
|
||||
}
|
||||
|
||||
int32_t SErrDisplayErrorFmt(uint32_t errorcode, const char* filename, int32_t linenumber, int32_t recoverable, uint32_t exitcode, const char* format, ...) {
|
||||
char buffer[2048];
|
||||
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
vsnprintf(buffer, sizeof(buffer) - 1, format, args);
|
||||
buffer[sizeof(buffer) - 1] = '\0';
|
||||
va_end(args);
|
||||
|
||||
return SErrDisplayError(errorcode, filename, linenumber, buffer, recoverable, exitcode, 1);
|
||||
}
|
||||
|
||||
void SErrPrepareAppFatal(const char* filename, int32_t linenumber) {
|
||||
s_appFatInfo.filename = filename;
|
||||
s_appFatInfo.linenumber = linenumber;
|
||||
s_appFatInfo.threadId = SGetCurrentThreadId();
|
||||
}
|
||||
|
||||
void SErrSetLastError(uint32_t errorcode) {
|
||||
s_lasterror = errorcode;
|
||||
#if defined(WHOA_SYSTEM_WIN)
|
||||
SetLastError(errorcode);
|
||||
#endif
|
||||
}
|
||||
|
||||
uint32_t SErrGetLastError() {
|
||||
return s_lasterror;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,13 +3,19 @@
|
|||
|
||||
#include <cstdint>
|
||||
|
||||
struct APPFATINFO {
|
||||
const char *filename;
|
||||
int32_t linenumber;
|
||||
uintptr_t threadId;
|
||||
};
|
||||
#include "storm/error/Macro.hpp"
|
||||
#include "storm/error/Codes.hpp"
|
||||
|
||||
extern uint32_t s_lasterror;
|
||||
extern APPFATINFO s_appFatInfo;
|
||||
[[noreturn]] void SErrDisplayAppFatal(const char* format, ...);
|
||||
|
||||
int32_t SErrDisplayError(uint32_t errorcode, const char* filename, int32_t linenumber, const char* description, int32_t recoverable, uint32_t exitcode, uint32_t a7);
|
||||
|
||||
int32_t SErrDisplayErrorFmt(uint32_t errorcode, const char* filename, int32_t linenumber, int32_t recoverable, uint32_t exitcode, const char* format, ...);
|
||||
|
||||
void SErrPrepareAppFatal(const char* filename, int32_t linenumber);
|
||||
|
||||
void SErrSetLastError(uint32_t errorcode);
|
||||
|
||||
uint32_t SErrGetLastError();
|
||||
|
||||
#endif
|
||||
|
|
|
|||
12
storm/error/Types.hpp
Normal file
12
storm/error/Types.hpp
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
#ifndef STORM_ERROR_TYPES_HPP
|
||||
#define STORM_ERROR_TYPES_HPP
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
struct APPFATINFO {
|
||||
const char* filename;
|
||||
int32_t linenumber;
|
||||
uintptr_t threadId;
|
||||
};
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue