diff options
| author | Clement Sibille <clements+github@lisible.xyz> | 2024-06-09 01:05:57 +0900 |
|---|---|---|
| committer | Clement Sibille <clements+github@lisible.xyz> | 2024-06-09 01:05:57 +0900 |
| commit | 6c8d0db34bd485084ffb2108620b396c8056251e (patch) | |
| tree | 71c37a768a8f5c174778f2a3fbc3149be5ba473f /src/lisiblestd | |
| parent | ff2cfc706efd88c2e30fdb4c27ddad3263227367 (diff) | |
Fix Playdate support
Diffstat (limited to 'src/lisiblestd')
| -rw-r--r-- | src/lisiblestd/assert.h | 8 | ||||
| -rw-r--r-- | src/lisiblestd/log.h | 14 | ||||
| -rw-r--r-- | src/lisiblestd/memory.c | 2 | ||||
| -rw-r--r-- | src/lisiblestd/string.c | 2 |
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}; |
