Applying formatting and moving libraries into specific folders

This commit is contained in:
GearsProgress
2026-10-18 11:07:35 -04:00
parent 1e90aa40ce
commit f1e2b62e4a
74 changed files with 6147 additions and 5199 deletions

View File

@@ -8,34 +8,37 @@
#define NANOPRINTF_USE_WRITEBACK_FORMAT_SPECIFIERS 0
#include "libstd_replacements.h"
#include "custom_malloc.h"
#include "libraries/nanoprintf/nanoprintf.h"
#include <cstdlib>
#include <stdarg.h>
#include <ctype.h>
#include "custom_malloc.h"
#include <stdarg.h>
// recommended for a 32 bit system to have at least 33 bytes available
// source: https://cplusplus.com/reference/cstdlib/itoa/
// unfortunately itoa is not standardized, so we'll have to make do with snprintf
// unfortunately itoa is not standardized, so we'll have to make do with
// snprintf
static char conversion_buffer[33];
const char* ptgb::to_string(int intVal)
const char *ptgb::to_string(int intVal)
{
npf_snprintf(conversion_buffer, sizeof(conversion_buffer), "%d", intVal);
return conversion_buffer;
}
const char* ptgb::to_string(unsigned int wordVal)
const char *ptgb::to_string(unsigned int wordVal)
{
npf_snprintf(conversion_buffer, sizeof(conversion_buffer), "%u", wordVal);
return conversion_buffer;
}
// when compiling with -nostdlib++, we need to provide our own operator new and delete implementations
// Regular operator new
void* operator new(std::size_t size) {
void* ptr = malloc(size);
if (!ptr) {
// when compiling with -nostdlib++, we need to provide our own operator new and
// delete implementations Regular operator new
void *operator new(std::size_t size)
{
void *ptr = malloc(size);
if (!ptr)
{
// mimic standard behavior: throw std::bad_alloc
// but we can't use std::bad_alloc without libstdc++
// so instead we can abort or return nullptr
@@ -46,52 +49,53 @@ void* operator new(std::size_t size) {
}
// nothrow version
void* operator new(std::size_t size, const std::nothrow_t&) noexcept {
void *operator new(std::size_t size, const std::nothrow_t &) noexcept
{
return malloc(size);
}
// regular array operator new
void* operator new[](std::size_t size) {
void* ptr = malloc(size);
if (!ptr) {
void *operator new[](std::size_t size)
{
void *ptr = malloc(size);
if (!ptr)
{
return NULL;
}
return ptr;
}
// nothrow array operator new
void* operator new[](std::size_t size, const std::nothrow_t&) noexcept {
void *operator new[](std::size_t size, const std::nothrow_t &) noexcept
{
return malloc(size);
}
// operator delete
void operator delete(void* ptr) noexcept {
free(ptr);
}
void operator delete(void *ptr) noexcept { free(ptr); }
// array operator delete
void operator delete[](void* ptr) noexcept {
free(ptr);
}
void operator delete[](void *ptr) noexcept { free(ptr); }
// nothrow delete
void operator delete(void* ptr, const std::nothrow_t&) noexcept {
free(ptr);
}
void operator delete(void *ptr, const std::nothrow_t &) noexcept { free(ptr); }
// nothrow array delete
void operator delete[](void* ptr, const std::nothrow_t&) noexcept {
void operator delete[](void *ptr, const std::nothrow_t &) noexcept
{
free(ptr);
}
// sized delete
void operator delete(void* ptr, std::size_t size) noexcept {
void operator delete(void *ptr, std::size_t size) noexcept
{
(void)size;
free(ptr);
}
// sized array delete
void operator delete[](void* ptr, std::size_t size) noexcept {
void operator delete[](void *ptr, std::size_t size) noexcept
{
(void)size;
free(ptr);
}