fix(kcp, IDT, Heap, kernel): Various fixes, scrap broken memory allocator
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* CString.cpp
|
||||
* C++ string tooling
|
||||
* Copyright (c) 2025 Daniel Hammer
|
||||
*/
|
||||
|
||||
#include "CString.hpp"
|
||||
#include "Stream.hpp"
|
||||
|
||||
#include <Libraries/Memory.hpp>
|
||||
#include <Memory/Heap.hpp>
|
||||
|
||||
namespace kcp {
|
||||
vector<const char*> splitstr(const char* str, char delimiter) {
|
||||
vector<const char*> result;
|
||||
cstringstream current_stream = cstringstream();
|
||||
|
||||
do {
|
||||
if (*str == delimiter || *str == '\0') {
|
||||
auto cstr = current_stream.cstr();
|
||||
auto cstr_len = Lib::strlen(cstr);
|
||||
|
||||
result.push_back((const char*)Memory::g_heap->Request(sizeof(char) * (cstr_len + 1)));
|
||||
|
||||
memcpy((void*)result.at(result.size() - 1), cstr, cstr_len + 1);
|
||||
|
||||
if (*str == '\0') {
|
||||
break;
|
||||
}
|
||||
|
||||
current_stream = cstringstream();
|
||||
str++;
|
||||
continue;
|
||||
}
|
||||
|
||||
current_stream << (char)*str;
|
||||
str++;
|
||||
} while (*str != '\0');
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
* CString.cpp
|
||||
* C++ string tooling
|
||||
* Copyright (c) 2025 Daniel Hammer
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <CppLib/Vector.hpp>
|
||||
|
||||
namespace kcp {
|
||||
vector<const char*> splitstr(const char* str, char delimiter);
|
||||
};
|
||||
@@ -6,8 +6,8 @@
|
||||
|
||||
#include "Stream.hpp"
|
||||
#include <Memory/Heap.hpp>
|
||||
#include <Terminal/terminal.hpp>
|
||||
#include <Libraries/string.hpp>
|
||||
#include <Terminal/Terminal.hpp>
|
||||
#include <Libraries/String.hpp>
|
||||
|
||||
kcp::cstringstream::cstringstream()
|
||||
{
|
||||
@@ -21,7 +21,7 @@ kcp::cstringstream::~cstringstream()
|
||||
}
|
||||
|
||||
kcp::cstringstream& kcp::cstringstream::operator<<(char c) {
|
||||
this->string = (const char *)Memory::g_heap->Realloc((void *)this->string, this->size + 1);
|
||||
this->string = (char *)Memory::g_heap->Realloc((void *)this->string, this->size + 2);
|
||||
|
||||
if (!this->string)
|
||||
{
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace kcp {
|
||||
};
|
||||
|
||||
class cstringstream {
|
||||
const char* string;
|
||||
char* string;
|
||||
std::size_t size;
|
||||
|
||||
base current_base = base::dec;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <Terminal/terminal.hpp>
|
||||
#include <Terminal/Terminal.hpp>
|
||||
#include <Memory/Heap.hpp>
|
||||
|
||||
namespace kcp
|
||||
@@ -24,11 +24,12 @@ namespace kcp
|
||||
array = nullptr;
|
||||
}
|
||||
|
||||
T operator[](std::size_t position)
|
||||
T& operator[](std::size_t position)
|
||||
{
|
||||
if (position > (sz - 1)) {
|
||||
kerr << "Vector out of bounds caught!" << Kt::newline;
|
||||
return T{};
|
||||
|
||||
return at(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -36,13 +37,17 @@ namespace kcp
|
||||
}
|
||||
}
|
||||
|
||||
T at(std::int64_t position) {
|
||||
T& at(std::int64_t position) {
|
||||
return this->operator[](position);
|
||||
}
|
||||
|
||||
void push_back(T value) {
|
||||
size_t push_back(T value) {
|
||||
size_t _sz = sz;
|
||||
|
||||
array = (T *)Memory::g_heap->Realloc(array, sizeof(T) * (sz + 1));
|
||||
array[sz++] = value;
|
||||
|
||||
return _sz;
|
||||
}
|
||||
|
||||
T* get_array()
|
||||
|
||||
Reference in New Issue
Block a user