mirror of
https://github.com/thunderbrewhq/squall.git
synced 2025-12-12 02:22:30 +00:00
refactor(memory): make memory allocation the exclusive responsibility of bc from now on
This commit is contained in:
parent
92fcb3266f
commit
09e7076a9b
18 changed files with 94 additions and 73 deletions
|
|
@ -1,12 +1,13 @@
|
|||
#include "storm/String.hpp"
|
||||
#include "storm/Error.hpp"
|
||||
#include "storm/Memory.hpp"
|
||||
#include <bc/Memory.hpp>
|
||||
#include "storm/string/bjhash.hpp"
|
||||
#include <cctype>
|
||||
#include <cmath>
|
||||
#include <cstdarg>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
|
||||
#if defined(WHOA_SYSTEM_WIN)
|
||||
#include <string.h>
|
||||
|
|
@ -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<size_t>(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<char*>(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;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue