refactor(error): make error variables properly static

This commit is contained in:
phaneron 2024-09-07 12:26:26 -04:00
parent 57430d406f
commit 6cbf0d23bf
5 changed files with 74 additions and 74 deletions

View file

@ -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;
}

View file

@ -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
View 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