Compare commits

..

No commits in common. "59765aa3344d4005147088e6c4767ee19fbba6a7" and "345e13965e226825603740facf23e1aeceaf0aec" have entirely different histories.

14 changed files with 16 additions and 37 deletions

View File

@ -6,9 +6,9 @@
#include "memory/MemoryManager.h" #include "memory/MemoryManager.h"
#include "thread/Scheduler.h" #include "thread/Scheduler.h"
#include <cpuid.h> #include <cpuid.h>
#include <luna/CString.h>
#include <luna/Check.h> #include <luna/Check.h>
#include <luna/Result.h> #include <luna/Result.h>
#include <luna/String.h>
#include <luna/SystemError.h> #include <luna/SystemError.h>
#include <luna/Types.h> #include <luna/Types.h>

View File

@ -1,7 +1,7 @@
#include "arch/MMU.h" #include "arch/MMU.h"
#include "memory/MemoryManager.h" #include "memory/MemoryManager.h"
#include <luna/CString.h>
#include <luna/Result.h> #include <luna/Result.h>
#include <luna/String.h>
#include <luna/SystemError.h> #include <luna/SystemError.h>
#pragma GCC push_options #pragma GCC push_options

View File

@ -1,5 +1,5 @@
#include "thread/Thread.h" #include "thread/Thread.h"
#include <luna/CString.h> #include <luna/String.h>
bool is_in_kernel(Registers* regs) bool is_in_kernel(Registers* regs)
{ {

View File

@ -4,8 +4,8 @@
#include "boot/bootboot.h" #include "boot/bootboot.h"
#include "memory/MemoryManager.h" #include "memory/MemoryManager.h"
#include "video/Framebuffer.h" #include "video/Framebuffer.h"
#include <luna/CString.h>
#include <luna/Result.h> #include <luna/Result.h>
#include <luna/String.h>
extern const BOOTBOOT bootboot; extern const BOOTBOOT bootboot;

View File

@ -6,10 +6,10 @@
#include "memory/MemoryManager.h" #include "memory/MemoryManager.h"
#include <luna/Alignment.h> #include <luna/Alignment.h>
#include <luna/Alloc.h> #include <luna/Alloc.h>
#include <luna/CString.h>
#include <luna/LinkedList.h> #include <luna/LinkedList.h>
#include <luna/SafeArithmetic.h> #include <luna/SafeArithmetic.h>
#include <luna/ScopeGuard.h> #include <luna/ScopeGuard.h>
#include <luna/String.h>
#include <luna/SystemError.h> #include <luna/SystemError.h>
namespace std namespace std

View File

@ -6,8 +6,8 @@
#include "memory/MemoryMap.h" #include "memory/MemoryMap.h"
#include <luna/Alignment.h> #include <luna/Alignment.h>
#include <luna/Bitmap.h> #include <luna/Bitmap.h>
#include <luna/CString.h>
#include <luna/ScopeGuard.h> #include <luna/ScopeGuard.h>
#include <luna/String.h>
#include <luna/SystemError.h> #include <luna/SystemError.h>
#include <luna/Types.h> #include <luna/Types.h>

View File

@ -1,9 +1,9 @@
#include "video/TextConsole.h" #include "video/TextConsole.h"
#include "boot/bootboot.h" #include "boot/bootboot.h"
#include "video/Framebuffer.h" #include "video/Framebuffer.h"
#include <luna/CString.h>
#include <luna/Format.h> #include <luna/Format.h>
#include <luna/Result.h> #include <luna/Result.h>
#include <luna/String.h>
#include <stdarg.h> #include <stdarg.h>
extern const BOOTBOOT bootboot; extern const BOOTBOOT bootboot;

View File

@ -3,7 +3,7 @@
set(FREESTANDING_SOURCES set(FREESTANDING_SOURCES
src/Format.cpp src/Format.cpp
src/NumberParsing.cpp src/NumberParsing.cpp
src/CString.cpp src/String.cpp
src/Units.cpp src/Units.cpp
src/SystemError.cpp src/SystemError.cpp
src/Bitmap.cpp src/Bitmap.cpp

View File

@ -22,12 +22,6 @@ class OwnedStringView
return m_length; return m_length;
} }
const char& operator[](usize index) const
{
expect(index < m_length, "OwnedStringView: index out of range");
return m_string[index];
}
private: private:
char* m_string{nullptr}; char* m_string{nullptr};
usize m_length{0}; usize m_length{0};

View File

@ -8,6 +8,4 @@ extern "C"
int memcmp(const void* a, const void* b, usize n); int memcmp(const void* a, const void* b, usize n);
void* memmove(void* dest, const void* src, usize n); void* memmove(void* dest, const void* src, usize n);
usize strlen(const char* str); usize strlen(const char* str);
char* strdup(const char* str);
} }

View File

@ -7,7 +7,7 @@
[[nodiscard]] void* raw_malloc(usize size) [[nodiscard]] void* raw_malloc(usize size)
{ {
#ifdef USE_FREESTANDING #ifdef USE_FREESTANDING
char* const rc = new (std::nothrow) char[size]; char* const rc = new char[size];
return (void*)rc; return (void*)rc;
#else #else
return malloc(size); return malloc(size);

View File

@ -1,6 +1,6 @@
#include <luna/Bitmap.h> #include <luna/Bitmap.h>
#include <luna/CString.h>
#include <luna/Check.h> #include <luna/Check.h>
#include <luna/String.h>
Bitmap::Bitmap() Bitmap::Bitmap()
{ {

View File

@ -1,6 +1,6 @@
#include <luna/Alloc.h> #include <luna/Alloc.h>
#include <luna/CString.h>
#include <luna/OwnedStringView.h> #include <luna/OwnedStringView.h>
#include <luna/String.h>
OwnedStringView::OwnedStringView() OwnedStringView::OwnedStringView()
{ {
@ -23,14 +23,14 @@ OwnedStringView::OwnedStringView(char* c_str)
OwnedStringView::~OwnedStringView() OwnedStringView::~OwnedStringView()
{ {
if (m_string) raw_free(m_string); if (m_string) destroy_array(m_string);
} }
Result<OwnedStringView> OwnedStringView::clone() const Result<OwnedStringView> OwnedStringView::clone() const
{ {
char* const c_str = strdup(m_string); char* buf = TRY(make_array<char>(m_length + 1));
if (!c_str) return err(ENOMEM); memcpy(buf, m_string, m_length + 1);
return OwnedStringView{c_str}; return OwnedStringView{buf};
} }

View File

@ -1,5 +1,4 @@
#include <luna/Alloc.h> #include <luna/String.h>
#include <luna/CString.h>
extern "C" extern "C"
{ {
@ -45,16 +44,4 @@ extern "C"
; ;
return (usize)(i - str); return (usize)(i - str);
} }
char* strdup(const char* str)
{
const usize len = strlen(str);
char* dest = (char*)raw_malloc(len + 1);
if (!dest) return nullptr;
memcpy(dest, str, len + 1);
return dest;
}
} }