stuff
This commit is contained in:
+1
-1
@@ -16,7 +16,7 @@ struct Array_List {
|
||||
|
||||
void dealloc() {
|
||||
free(data);
|
||||
data = 0;
|
||||
data = nullptr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -75,10 +75,10 @@ struct Hook : Array_List<Lambda<void()>> {
|
||||
}
|
||||
};
|
||||
|
||||
// struct __System_Shutdown_Hook : Hook {
|
||||
// void operator()() = delete;
|
||||
// ~__System_Shutdown_Hook() {
|
||||
// Hook::operator()();
|
||||
// dealloc();
|
||||
// }
|
||||
// } system_shutdown_hook;
|
||||
struct __System_Shutdown_Hook : Hook {
|
||||
void operator()() = delete;
|
||||
~__System_Shutdown_Hook() {
|
||||
Hook::operator()();
|
||||
dealloc();
|
||||
}
|
||||
} system_shutdown_hook;
|
||||
|
||||
+9
-4
@@ -52,14 +52,19 @@ expands to:
|
||||
};
|
||||
*/
|
||||
|
||||
#if defined(unix) || defined(__unix__) || defined(__unix)
|
||||
#define NULL_HANDLE "/dev/null"
|
||||
#else
|
||||
#define NULL_HANDLE "nul"
|
||||
#endif
|
||||
#define ignore_stdout \
|
||||
if (0) \
|
||||
label(finished,__LINE__): ; \
|
||||
else \
|
||||
for (FILE* tmp = ftb_stdout;;) \
|
||||
for (defer{ fclose(ftb_stdout); ftb_stdout= tmp; } ;;) \
|
||||
for (FILE* label(fluid_let_, __LINE__) = ftb_stdout;;) \
|
||||
for (defer{ fclose(ftb_stdout); ftb_stdout=label(fluid_let_, __LINE__) ; } ;;) \
|
||||
if (1) { \
|
||||
ftb_stdout = fopen("nul", "w"); \
|
||||
ftb_stdout = fopen(NULL_HANDLE, "w"); \
|
||||
goto label(body,__LINE__); \
|
||||
} \
|
||||
else \
|
||||
@@ -70,7 +75,6 @@ expands to:
|
||||
else label(body,__LINE__):
|
||||
|
||||
|
||||
|
||||
/*****************
|
||||
* fluid-let *
|
||||
*****************/
|
||||
@@ -91,6 +95,7 @@ expands to:
|
||||
goto TOKENPASTE2(finished, __LINE__); \
|
||||
} \
|
||||
else TOKENPASTE2(body,__LINE__):
|
||||
;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
+3
-3
@@ -1,9 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#pragma message("Compiling for Windows")
|
||||
// #pragma message ("Compiling for Windows")
|
||||
#define FTB_WINDOWS
|
||||
#elseif
|
||||
#pragma message("Compiling for Linux")
|
||||
#else
|
||||
// #pragma message ("Compiling for Linux")
|
||||
#define FTB_LINUX
|
||||
#endif
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "hashmap.hpp"
|
||||
#include "hooks.hpp"
|
||||
|
||||
FILE* ftb_stdout = stdout;
|
||||
|
||||
@@ -443,16 +444,17 @@ auto print_str_line(FILE* f, char* str) -> s32 {
|
||||
return print_to_file(f, "%.*s", length, str);
|
||||
}
|
||||
|
||||
void deinit_printer() {
|
||||
printer_map.dealloc();
|
||||
type_map.dealloc();
|
||||
}
|
||||
|
||||
void init_printer() {
|
||||
color_stack.alloc();
|
||||
printer_map.alloc();
|
||||
type_map.alloc();
|
||||
|
||||
system_shutdown_hook << [](){
|
||||
color_stack.dealloc();
|
||||
printer_map.dealloc();
|
||||
type_map.dealloc();
|
||||
};
|
||||
|
||||
register_printer("u32", print_u32, Printer_Function_Type::_32b);
|
||||
register_printer("u64", print_u64, Printer_Function_Type::_64b);
|
||||
register_printer("bool", print_bool, Printer_Function_Type::_32b);
|
||||
|
||||
+8
-4
@@ -19,10 +19,14 @@ typedef s32 testresult;
|
||||
__FILE__, __LINE__, (type)(value), (type)(variable))
|
||||
|
||||
#define assert_equal_string(variable, value) \
|
||||
if (!string_equal(variable, value)) { \
|
||||
print_assert_equal_fail(&(variable), &(value), String*, "%{->Str}"); \
|
||||
do { \
|
||||
auto v1{variable}; \
|
||||
auto v2{value}; \
|
||||
if (!string_equal(v1, v2)) { \
|
||||
print_assert_equal_fail(&(v1), &(v2), String*, "%{->Str}"); \
|
||||
return fail; \
|
||||
}
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define assert_equal_int(variable, value) \
|
||||
if (variable != value) { \
|
||||
@@ -86,4 +90,4 @@ typedef s32 testresult;
|
||||
free(error); \
|
||||
error = nullptr; \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
@@ -23,11 +23,17 @@ typedef wchar_t path_char;
|
||||
typedef char path_char;
|
||||
#endif
|
||||
|
||||
struct String {
|
||||
struct StringSlice {
|
||||
const char* data;
|
||||
u64 length;
|
||||
char* data;
|
||||
};
|
||||
|
||||
struct String {
|
||||
char* data;
|
||||
u64 length;
|
||||
};
|
||||
|
||||
|
||||
inline auto heap_copy_c_string(const char* str) -> char* {
|
||||
#ifdef FTB_WINDOWS
|
||||
return _strdup(str);
|
||||
@@ -43,9 +49,32 @@ inline auto make_heap_string(const char* str) -> String {
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline const String make_static_string(char* str) {
|
||||
String ret;
|
||||
inline auto make_static_string(const char* str) -> const StringSlice {
|
||||
StringSlice ret;
|
||||
ret.length = strlen(str);
|
||||
ret.data = str;
|
||||
return ret;
|
||||
}
|
||||
|
||||
auto inline string_equal(const char* input, const char* check) -> bool {
|
||||
return strcmp(input, check) == 0;
|
||||
}
|
||||
|
||||
auto inline string_equal(StringSlice str, const char* check) -> bool {
|
||||
if (str.length != strlen(check))
|
||||
return false;
|
||||
return strncmp(str.data, check, str.length) == 0;
|
||||
}
|
||||
|
||||
auto inline string_equal(const char* check, StringSlice str) -> bool {
|
||||
if (str.length != strlen(check))
|
||||
return false;
|
||||
return strncmp(str.data, check, str.length) == 0;
|
||||
}
|
||||
|
||||
auto inline string_equal(StringSlice str1, StringSlice str2) -> bool {
|
||||
if (str1.length != str2.length)
|
||||
return false;
|
||||
|
||||
return strncmp(str1.data, str2.data, str2.length) == 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user