summaryrefslogtreecommitdiffstats
path: root/src/lisiblestd
diff options
context:
space:
mode:
Diffstat (limited to 'src/lisiblestd')
-rw-r--r--src/lisiblestd/assert.h8
-rw-r--r--src/lisiblestd/log.h14
-rw-r--r--src/lisiblestd/memory.c2
-rw-r--r--src/lisiblestd/string.c2
4 files changed, 20 insertions, 6 deletions
diff --git a/src/lisiblestd/assert.h b/src/lisiblestd/assert.h
index 15026f9..2babb6d 100644
--- a/src/lisiblestd/assert.h
+++ b/src/lisiblestd/assert.h
@@ -5,21 +5,19 @@
extern void exit(int);
-
-
#ifdef LSTD_PLATFORM_PLAYDATE
#include <pd_api.h>
-extern PlaydateAPI* pd;
+extern PlaydateAPI *pd;
#define LSTD_ASSERT(expr) \
do { \
if (!(expr)) { \
- pd->system->error("Assertion failed:\n\t%s", #expr); \
+ pd->system->error("Assertion failed: %s", #expr); \
} \
} while (0)
#define LSTD_UNIMPLEMENTED() \
do { \
- pd->system->error("Unimpemented code reached"); \
+ pd->system->error("Unimpemented code reached"); \
} while (0)
#else
#define LSTD_ASSERT(expr) \
diff --git a/src/lisiblestd/log.h b/src/lisiblestd/log.h
index f4b4d6f..1cc4dc5 100644
--- a/src/lisiblestd/log.h
+++ b/src/lisiblestd/log.h
@@ -15,6 +15,19 @@ typedef enum {
extern LogLevel lstd_log_level;
+#ifdef LSTD_PLATFORM_PLAYDATE
+#include <pd_api.h>
+extern PlaydateAPI *pd;
+#define LOG(log_level, ...) \
+ do { \
+ if (lstd_log_level <= log_level) { \
+ pd->system->logToConsole(LSTD_LOG_PREFIX, log_level_to_str(log_level), \
+ __FILE__, __LINE__); \
+ pd->system->logToConsole(__VA_ARGS__); \
+ pd->system->logToConsole("\n"); \
+ } \
+ } while (0)
+#else
#define LOG(log_level, ...) \
do { \
if (lstd_log_level <= log_level) { \
@@ -24,6 +37,7 @@ extern LogLevel lstd_log_level;
fprintf(stderr, "\n"); \
} \
} while (0)
+#endif
#define LOG_TRACE(...) LOG(LogLevel_Trace, __VA_ARGS__)
#define LOG_DEBUG(...) LOG(LogLevel_Debug, __VA_ARGS__)
#define LOG_WARN(...) LOG(LogLevel_Warn, __VA_ARGS__)
diff --git a/src/lisiblestd/memory.c b/src/lisiblestd/memory.c
index 1f6b3c9..c8498f8 100644
--- a/src/lisiblestd/memory.c
+++ b/src/lisiblestd/memory.c
@@ -68,6 +68,7 @@ void *arena_allocator_allocate_aligned(usize alignment, usize size, void *ctx) {
(void)alignment;
(void)size;
LSTD_UNIMPLEMENTED();
+ return NULL;
}
void *arena_allocator_allocate_array(usize count, usize item_size, void *ctx) {
LSTD_ASSERT(ctx != NULL);
@@ -80,6 +81,7 @@ void *arena_allocator_reallocate(void *ptr, usize old_size, usize new_size,
(void)new_size;
(void)ctx;
LSTD_UNIMPLEMENTED();
+ return NULL;
}
void arena_allocator_free(void *ptr, void *ctx) {
diff --git a/src/lisiblestd/string.c b/src/lisiblestd/string.c
index 2b191b2..e7ef28c 100644
--- a/src/lisiblestd/string.c
+++ b/src/lisiblestd/string.c
@@ -12,7 +12,7 @@ String String_new(Allocator *allocator, const char *str) {
char *value = Allocator_allocate(allocator, length + 1);
LSTD_ASSERT(value != NULL);
- strncpy(value, str, length);
+ strncpy(value, str, length + 1);
value[length] = '\0';
return (String){.value = value, .length = length};
Go back to lisible.xyz