diff --git a/storm/Big.cpp b/storm/Big.cpp index 57ec5dc..5822bec 100644 --- a/storm/Big.cpp +++ b/storm/Big.cpp @@ -1,6 +1,6 @@ #include "storm/Big.hpp" #include "storm/big/Ops.hpp" -#include "storm/Memory.hpp" +#include #include void SBigAdd(BigData* a, BigData* b, BigData* c) { diff --git a/storm/Command.cpp b/storm/Command.cpp index 11585cf..a836f3e 100644 --- a/storm/Command.cpp +++ b/storm/Command.cpp @@ -1,8 +1,10 @@ #include "storm/Command.hpp" +#include "bc/os/file/Types.hpp" #include "storm/Error.hpp" #include "storm/String.hpp" -#include "storm/Memory.hpp" +#include +#include "storm/error/Defines.hpp" #include #include @@ -32,7 +34,7 @@ static void GenerateError(CMDERRORCALLBACK errorcallback, uint32_t errorcode, co case STORM_COMMAND_ERROR_NOT_ENOUGH_ARGUMENTS: strid = 1; break; - case STORM_COMMAND_ERROR_OPEN_FAILED: + case ERROR_OPEN_FAILED: strid = 2; break; default: @@ -325,7 +327,7 @@ static int32_t ProcessToken(const char* string, int32_t quoted, PROCESSING* proc } if (errorcallback) { - GenerateError(errorcallback, STORM_COMMAND_ERROR_OPEN_FAILED, string); + GenerateError(errorcallback, ERROR_OPEN_FAILED, string); } } @@ -354,10 +356,9 @@ static int32_t ProcessString(const char** stringptr, PROCESSING* processing, CMD static int32_t ProcessFile(const char* filename, PROCESSING* processing, CMDDEF** nextarg, CMDEXTRACALLBACK extracallback, CMDERRORCALLBACK errorcallback) { // TODO auto file = OsCreateFile(filename, OS_GENERIC_READ, OS_FILE_SHARE_READ, OS_OPEN_EXISTING, OS_FILE_FLAG_SEQUENTIAL_SCAN, 0); - - if (!file) { + if (file == HOSFILE_INVALID) { if (errorcallback) { - GenerateError(errorcallback, STORM_COMMAND_ERROR_OPEN_FAILED, filename); + GenerateError(errorcallback, ERROR_OPEN_FAILED, filename); } return false; } @@ -383,11 +384,13 @@ int32_t SCmdRegisterArgument(uint32_t flags, uint32_t id, const char* name, void auto namelength = SStrLen(name); - STORM_VALIDATE(namelength < 16, ERROR_INVALID_PARAMETER, 0); - STORM_VALIDATE((!variablebytes) || variableptr, ERROR_INVALID_PARAMETER, 0); - STORM_VALIDATE(((STORM_COMMAND_GET_ARG(flags) != STORM_COMMAND_ARG_REQUIRED) || !s_addedoptional), ERROR_INVALID_PARAMETER, 0); - STORM_VALIDATE((STORM_COMMAND_GET_ARG(flags) != STORM_COMMAND_ARG_FLAGGED) || (namelength > 0), ERROR_INVALID_PARAMETER, 0); - STORM_VALIDATE((STORM_COMMAND_GET_TYPE(flags) != STORM_COMMAND_TYPE_BOOL) || (!variableptr) || (variablebytes == sizeof(uint32_t)), ERROR_INVALID_PARAMETER, 0); + STORM_VALIDATE_BEGIN; + STORM_VALIDATE(namelength < 16); + STORM_VALIDATE((!variablebytes) || variableptr); + STORM_VALIDATE((STORM_COMMAND_GET_ARG(flags) != STORM_COMMAND_ARG_REQUIRED) || !s_addedoptional); + STORM_VALIDATE((STORM_COMMAND_GET_ARG(flags) != STORM_COMMAND_ARG_FLAGGED) || (namelength > 0)); + STORM_VALIDATE((STORM_COMMAND_GET_TYPE(flags) != STORM_COMMAND_TYPE_BOOL) || (!variableptr) || (variablebytes == sizeof(uint32_t))); + STORM_VALIDATE_END; // If argument is flagged, it goes in the flag list auto listptr = &s_arglist; @@ -419,7 +422,9 @@ int32_t SCmdRegisterArgument(uint32_t flags, uint32_t id, const char* name, void } int32_t SCmdRegisterArgList(ARGLIST* listptr, uint32_t numargs) { - STORM_VALIDATE(listptr, ERROR_INVALID_PARAMETER, 0); + STORM_VALIDATE_BEGIN; + STORM_VALIDATE(listptr); + STORM_VALIDATE_END; for (int32_t i = 0; i < numargs; i++) { if (!SCmdRegisterArgument(listptr->flags, listptr->id, listptr->name, 0, 0, 1, 0xFFFFFFFF, listptr->callback)) { @@ -433,7 +438,9 @@ int32_t SCmdRegisterArgList(ARGLIST* listptr, uint32_t numargs) { } int32_t SCmdProcess(const char* cmdline, int32_t skipprogname, CMDEXTRACALLBACK extracallback, CMDERRORCALLBACK errorcallback) { - STORM_VALIDATE(cmdline, ERROR_INVALID_PARAMETER, 0); + STORM_VALIDATE_BEGIN; + STORM_VALIDATE(cmdline); + STORM_VALIDATE_END; if (skipprogname) { SStrTokenize(&cmdline, nullptr, 0, STORM_COMMAND_WHITESPACE_CHARS, nullptr); @@ -490,12 +497,12 @@ int32_t SCmdGetBool(uint32_t id) { } int32_t SCmdGetString(uint32_t id, char* buffer, uint32_t bufferchars) { - if (buffer) { - *buffer = '\0'; - } + STORM_VALIDATE_BEGIN; + STORM_VALIDATE(buffer); + STORM_VALIDATE(bufferchars); + STORM_VALIDATE_END; - STORM_VALIDATE(buffer, ERROR_INVALID_PARAMETER, 0); - STORM_VALIDATE(bufferchars, ERROR_INVALID_PARAMETER, 0); + *buffer = '\0'; for (int32_t flaglist = 0; flaglist <= 1; flaglist++) { auto& list = flaglist ? s_flaglist : s_arglist; diff --git a/storm/Log.cpp b/storm/Log.cpp index cacb21a..6d7b82a 100644 --- a/storm/Log.cpp +++ b/storm/Log.cpp @@ -1,7 +1,7 @@ #include "storm/Log.hpp" #include "storm/Thread.hpp" #include "storm/Error.hpp" -#include "storm/Memory.hpp" +#include #include #include #include diff --git a/storm/Memory.hpp b/storm/Memory.hpp deleted file mode 100644 index 07c8186..0000000 --- a/storm/Memory.hpp +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef STORM_MEMORY_HPP -#define STORM_MEMORY_HPP - -#include -#include - -void* SMemAlloc(size_t bytes, const char* filename, int32_t linenumber, uint32_t flags); - -void SMemFree(void* ptr); - -void SMemFree(void* ptr, const char* filename, int32_t linenumber, uint32_t flags); - -void* SMemReAlloc(void* ptr, size_t bytes, const char* filename, int32_t linenumber, uint32_t flags); - -#endif diff --git a/storm/String.cpp b/storm/String.cpp index d9f21b9..f93c1dd 100644 --- a/storm/String.cpp +++ b/storm/String.cpp @@ -1,12 +1,13 @@ #include "storm/String.hpp" #include "storm/Error.hpp" -#include "storm/Memory.hpp" +#include #include "storm/string/bjhash.hpp" #include #include #include #include #include +#include #if defined(WHOA_SYSTEM_WIN) #include @@ -207,8 +208,9 @@ void SStrInitialize() { } char* SStrChr(char* string, char search) { - STORM_ASSERT(string); - STORM_VALIDATE(string, ERROR_INVALID_PARAMETER, nullptr); + STORM_VALIDATE_BEGIN; + STORM_VALIDATE(string); + STORM_VALIDATE_END; if (!*string) { return nullptr; @@ -226,8 +228,9 @@ char* SStrChr(char* string, char search) { } const char* SStrChr(const char* string, char search) { - STORM_ASSERT(string); - STORM_VALIDATE(string, ERROR_INVALID_PARAMETER, nullptr); + STORM_VALIDATE_BEGIN; + STORM_VALIDATE(string); + STORM_VALIDATE_END; if (!*string) { return nullptr; @@ -245,8 +248,9 @@ const char* SStrChr(const char* string, char search) { } char* SStrChrR(char* string, char search) { - STORM_ASSERT(string); - STORM_VALIDATE(string, ERROR_INVALID_PARAMETER, nullptr); + STORM_VALIDATE_BEGIN; + STORM_VALIDATE(string); + STORM_VALIDATE_END; char* result; @@ -260,8 +264,9 @@ char* SStrChrR(char* string, char search) { } const char* SStrChrR(const char* string, char search) { - STORM_ASSERT(string); - STORM_VALIDATE(string, ERROR_INVALID_PARAMETER, nullptr); + STORM_VALIDATE_BEGIN; + STORM_VALIDATE(string); + STORM_VALIDATE_END; const char* result; @@ -289,9 +294,10 @@ int32_t SStrCmpI(const char* string1, const char* string2, size_t maxchars) { } size_t SStrCopy(char* dest, const char* source, size_t destsize) { - STORM_ASSERT(dest); - STORM_ASSERT(source); - STORM_VALIDATE(dest && source, ERROR_INVALID_PARAMETER, 0); + STORM_VALIDATE_BEGIN; + STORM_VALIDATE(dest); + STORM_VALIDATE(source); + STORM_VALIDATE_END; char* destbuf = dest; @@ -322,6 +328,21 @@ size_t SStrCopy(char* dest, const char* source, size_t destsize) { return static_cast(destbuf - dest); } +size_t SStrNCopy(char* dest, const char* source, size_t maxchars, size_t destsize) { + STORM_VALIDATE_BEGIN; + STORM_VALIDATE(dest); + STORM_VALIDATE(source); + STORM_VALIDATE_END; + + auto length = strnlen(source, maxchars); + if (destsize) { + auto count = std::min(length, destsize - 1); + memcpy(dest, source, count); + dest[count] = '\0'; + } + return length; +} + char* SStrDupA(const char* string, const char* filename, uint32_t linenumber) { size_t len = SStrLen(string) + 1; char* dup = static_cast(SMemAlloc(len, filename, linenumber, 0x0)); @@ -362,7 +383,9 @@ uint32_t SStrHashHT(const char* string) { } size_t SStrLen(const char* string) { - STORM_ASSERT(string); + STORM_VALIDATE_BEGIN; + STORM_VALIDATE(string); + STORM_VALIDATE_END; auto stringEnd = string; while (*stringEnd) { @@ -460,14 +483,13 @@ const char* SStrStr(const char* string, const char* search) { } void SStrTokenize(const char** string, char* buffer, size_t bufferchars, const char* whitespace, int32_t* quoted) { - STORM_ASSERT(string); - STORM_VALIDATE(string, ERROR_INVALID_PARAMETER); - STORM_ASSERT(*string); - STORM_VALIDATE(*string, ERROR_INVALID_PARAMETER); - STORM_ASSERT(buffer || !bufferchars); - STORM_VALIDATE(buffer || !bufferchars, ERROR_INVALID_PARAMETER); - STORM_ASSERT(whitespace); - STORM_VALIDATE(whitespace, ERROR_INVALID_PARAMETER); + STORM_VALIDATE_BEGIN; + STORM_VALIDATE(string); + STORM_VALIDATE(*string); + STORM_VALIDATE(buffer || !bufferchars); + STORM_VALIDATE(whitespace); + STORM_VALIDATE_END; + int32_t inquotes = 0; int32_t usedquotes = 0; @@ -551,7 +573,9 @@ LABEL_35: } float SStrToFloat(const char* string) { - STORM_ASSERT(string); + STORM_VALIDATE_BEGIN; + STORM_VALIDATE(string); + STORM_VALIDATE_END; SStrInitialize(); @@ -646,7 +670,9 @@ float SStrToFloat(const char* string) { } int32_t SStrToInt(const char* string) { - STORM_ASSERT(string); + STORM_VALIDATE_BEGIN; + STORM_VALIDATE(string); + STORM_VALIDATE_END; int32_t result = 0; bool negative = false; @@ -670,7 +696,9 @@ int32_t SStrToInt(const char* string) { } uint32_t SStrToUnsigned(const char* string) { - STORM_ASSERT(string); + STORM_VALIDATE_BEGIN; + STORM_VALIDATE(string); + STORM_VALIDATE_END; uint32_t result = 0; diff --git a/storm/array/TSFixedArray.hpp b/storm/array/TSFixedArray.hpp index 37b8a7d..e212a03 100644 --- a/storm/array/TSFixedArray.hpp +++ b/storm/array/TSFixedArray.hpp @@ -1,9 +1,9 @@ #ifndef STORM_ARRAY_TS_FIXED_ARRAY_HPP #define STORM_ARRAY_TS_FIXED_ARRAY_HPP -#include "storm/Memory.hpp" -#include "storm/array/TSBaseArray.hpp" +#include #include +#include "storm/array/TSBaseArray.hpp" template class TSFixedArray : public TSBaseArray { diff --git a/storm/array/TSGrowableArray.hpp b/storm/array/TSGrowableArray.hpp index a091103..867f6f6 100644 --- a/storm/array/TSGrowableArray.hpp +++ b/storm/array/TSGrowableArray.hpp @@ -2,10 +2,10 @@ #define STORM_ARRAY_TS_GROWABLE_ARRAY_HPP #include "storm/array/TSFixedArray.hpp" +#include #include #include #include -#include template class TSGrowableArray : public TSFixedArray { diff --git a/storm/hash/Hashkey.cpp b/storm/hash/Hashkey.cpp index d715370..7bae99a 100644 --- a/storm/hash/Hashkey.cpp +++ b/storm/hash/Hashkey.cpp @@ -1,5 +1,6 @@ + +#include #include "storm/hash/Hashkey.hpp" -#include "storm/Memory.hpp" #include "storm/String.hpp" bool HASHKEY_NONE::operator==(const HASHKEY_NONE& key) { diff --git a/storm/list/TSList.hpp b/storm/list/TSList.hpp index 0dcd40b..4147911 100644 --- a/storm/list/TSList.hpp +++ b/storm/list/TSList.hpp @@ -1,7 +1,7 @@ #ifndef STORM_LIST_TS_LIST_HPP #define STORM_LIST_TS_LIST_HPP -#include "storm/Memory.hpp" +#include #include "storm/list/TSGetLink.hpp" #include "storm/list/TSLink.hpp" #include diff --git a/storm/thread/linux/S_Thread.cpp b/storm/thread/linux/S_Thread.cpp index f4943f3..d8a3735 100644 --- a/storm/thread/linux/S_Thread.cpp +++ b/storm/thread/linux/S_Thread.cpp @@ -1,5 +1,5 @@ #include "storm/thread/S_Thread.hpp" -#include "storm/Memory.hpp" +#include void* S_Thread::s_SLaunchThread(void* threadParam) { // TODO diff --git a/storm/thread/linux/Thread.cpp b/storm/thread/linux/Thread.cpp index f25ae2d..58f92bb 100644 --- a/storm/thread/linux/Thread.cpp +++ b/storm/thread/linux/Thread.cpp @@ -1,5 +1,5 @@ #include "storm/Thread.hpp" -#include "storm/Memory.hpp" +#include #include "storm/String.hpp" #include "storm/thread/S_Thread.hpp" #include diff --git a/storm/thread/mac/S_Thread.mm b/storm/thread/mac/S_Thread.mm index 1adf9e0..5926f42 100644 --- a/storm/thread/mac/S_Thread.mm +++ b/storm/thread/mac/S_Thread.mm @@ -1,5 +1,5 @@ #include "storm/thread/S_Thread.hpp" -#include "storm/Memory.hpp" +#include uint32_t S_Thread::s_SLaunchThread(void* threadParam) { // TODO diff --git a/storm/thread/mac/Thread.mm b/storm/thread/mac/Thread.mm index 24732bb..d722bb8 100644 --- a/storm/thread/mac/Thread.mm +++ b/storm/thread/mac/Thread.mm @@ -1,5 +1,5 @@ #include "storm/Thread.hpp" -#include "storm/Memory.hpp" +#include #include "storm/String.hpp" #include "storm/thread/S_Thread.hpp" #include "storm/thread/mac/SThreadRunner.h" diff --git a/storm/thread/win/S_Thread.cpp b/storm/thread/win/S_Thread.cpp index 0059b67..b12a064 100644 --- a/storm/thread/win/S_Thread.cpp +++ b/storm/thread/win/S_Thread.cpp @@ -1,5 +1,5 @@ #include "storm/thread/S_Thread.hpp" -#include "storm/Memory.hpp" +#include DWORD WINAPI S_Thread::s_SLaunchThread(void* threadParam) { auto params = static_cast(threadParam); diff --git a/storm/thread/win/Thread.cpp b/storm/thread/win/Thread.cpp index 7b6e1da..c0b70bb 100644 --- a/storm/thread/win/Thread.cpp +++ b/storm/thread/win/Thread.cpp @@ -1,5 +1,5 @@ #include "storm/Thread.hpp" -#include "storm/Memory.hpp" +#include #include "storm/String.hpp" #include "storm/thread/S_Thread.hpp" #include diff --git a/test/Memory.cpp b/test/Memory.cpp index b30b865..abe38de 100644 --- a/test/Memory.cpp +++ b/test/Memory.cpp @@ -1,4 +1,4 @@ -#include "storm/Memory.hpp" +#include #include "test/Test.hpp" TEST_CASE("SMemAlloc", "[memory]") { diff --git a/test/String.cpp b/test/String.cpp index 470ccdb..a88e66e 100644 --- a/test/String.cpp +++ b/test/String.cpp @@ -1,5 +1,5 @@ #include "storm/String.hpp" -#include "storm/Memory.hpp" +#include #include "test/Test.hpp" TEST_CASE("SStrChr", "[string]") { diff --git a/test/Thread.cpp b/test/Thread.cpp index 37b46cc..b127bee 100644 --- a/test/Thread.cpp +++ b/test/Thread.cpp @@ -1,5 +1,5 @@ #include "storm/Thread.hpp" -#include "storm/Memory.hpp" +#include #include "test/Test.hpp" uint32_t threadProc(void* param) {