aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Rodrigues Lordello <[email protected]>2026-10-10 20:25:21 +0200
committerNicholas Rodrigues Lordello <[email protected]>2026-10-10 20:25:21 +0200
commitbfcf30e800c68e0289f17b3967081280fca6592c (patch)
tree96e29101ab4cd85d144744307e82ae436e87726a
parent70d2db07ec4dd5034c6d888258a3fd945c67e4d4 (diff)
Fixed Minor Portability Issues
-rw-r--r--Makefile6
-rw-r--r--lib/wamr/custom/platform.c21
-rw-r--r--src/menu.c58
-rw-r--r--src/picow.c3
-rw-r--r--tools/generate-sysroot.c14
5 files changed, 52 insertions, 50 deletions
diff --git a/Makefile b/Makefile
index b00c8ad..217c59a 100644
--- a/Makefile
+++ b/Makefile
@@ -8,8 +8,8 @@ WAT2WASM ?= wat2wasm
ARCH ?= $(shell uname -m)
CFLAGS += -std=c99 -Wall -Wextra -O2 -MMD
-SDL3_CFLAGS ?= $(shell pkg-config SDL3 --cflags)
-SDL3_LIBS ?= $(shell pkg-config SDL3 --libs)
+SDL3_CFLAGS ?= $(shell pkg-config sdl3 --cflags)
+SDL3_LIBS ?= $(shell pkg-config sdl3 --libs)
TARGET := build/$(ARCH)
OUT := $(TARGET)/out
@@ -17,7 +17,7 @@ TOOLS := build/tools
SYSTEM := build/system
PICOW_CFLAGS := $(CFLAGS) $(SDL3_CFLAGS) -Ilib/
-PICOW_LDFLAGS := $(LDFLAGS) $(SDL3_LIBS) -L$(TARGET) -lwamr
+PICOW_LDFLAGS := $(LDFLAGS) $(SDL3_LIBS) -L$(TARGET) -lwamr -lm
PICOW_SRC := $(wildcard src/*.c) $(SYSTEM)/sysroot.c
PICOW_OBJ := $(patsubst %.c,$(OUT)/%.o,$(PICOW_SRC:build/%=%))
diff --git a/lib/wamr/custom/platform.c b/lib/wamr/custom/platform.c
index 387a040..eccd975 100644
--- a/lib/wamr/custom/platform.c
+++ b/lib/wamr/custom/platform.c
@@ -1,14 +1,17 @@
-#include "bh_assert.h"
-#include "platform_api_extension.h"
-#include "platform_api_vmcore.h"
-#include "platform_internal.h"
+#include "../core/config.h"
-#ifdef BH_DEBUG
+#if BH_DEBUG != 0
+#define _POSIX_C_SOURCE 200809L
#include <execinfo.h>
#include <time.h>
#endif
-#ifdef BH_DEBUG
+#include "bh_assert.h"
+#include "platform_api_extension.h"
+#include "platform_api_vmcore.h"
+#include "platform_internal.h"
+
+#if BH_DEBUG != 0
#define NOT_IMPLEMENTED() \
do { \
fprintf(stderr, "'%s' is not implemented\n", __FUNCTION__); \
@@ -43,15 +46,15 @@ int os_printf(const char *format, ...) {
}
int os_vprintf(const char *format, va_list ap) {
-#ifdef BH_DEBUG
+#if BH_DEBUG != 0
return vprintf(format, ap);
#else
- return 0
+ return 0;
#endif
}
uint64_t os_time_get_boot_us(void) {
-#ifdef BH_DEBUG
+#if BH_DEBUG != 0
struct timespec ts;
if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) {
return 0;
diff --git a/src/menu.c b/src/menu.c
index 441ebcf..c185cd9 100644
--- a/src/menu.c
+++ b/src/menu.c
@@ -59,23 +59,20 @@ void pw_menu_free(struct pw_menu *menu) {
SDL_free(menu);
}
-static size_t saturating_add(size_t a, ssize_t b) {
- // TODO: yuck...
- if (b < 0) {
- size_t c = (size_t)(-b);
- if (a < c) {
- return 0;
- } else {
- return a - c;
- }
- } else {
- size_t c = a + (size_t)(b);
- if (c < a) {
- return SIZE_MAX;
- } else {
- return c;
- }
+static size_t saturating_add(size_t a, size_t b) {
+ size_t r = a + b;
+ if (r < a) {
+ return SIZE_MAX;
+ }
+ return r;
+}
+
+static size_t saturating_sub(size_t a, size_t b) {
+ size_t r = a - b;
+ if (r > a) {
+ return 0;
}
+ return r;
}
bool pw_menu_event(struct pw_menu *menu, SDL_Event *event) {
@@ -92,22 +89,22 @@ bool pw_menu_event(struct pw_menu *menu, SDL_Event *event) {
return true;
}
- ssize_t delta = 0;
+ size_t next = menu->selection.next;
switch (event->type) {
case SDL_EVENT_GAMEPAD_AXIS_MOTION:
switch (event->gaxis.axis) {
case SDL_GAMEPAD_AXIS_LEFTX:
if (event->gaxis.value < -PW_AXIS_THRESHOLD) {
- delta -= 1;
+ next = saturating_sub(next, 1);
} else if (event->gaxis.value > PW_AXIS_THRESHOLD) {
- delta += 1;
+ next = saturating_add(next, 1);
}
break;
case SDL_GAMEPAD_AXIS_LEFTY:
if (event->gaxis.value < -PW_AXIS_THRESHOLD) {
- delta -= 10;
+ next = saturating_sub(next, 10);
} else if (event->gaxis.value > PW_AXIS_THRESHOLD) {
- delta += 10;
+ next = saturating_add(next, 10);
}
break;
}
@@ -123,16 +120,16 @@ bool pw_menu_event(struct pw_menu *menu, SDL_Event *event) {
menu->selection.selected = true;
break;
case SDL_GAMEPAD_BUTTON_DPAD_UP:
- delta -= 10;
+ next = saturating_sub(next, 10);
break;
case SDL_GAMEPAD_BUTTON_DPAD_DOWN:
- delta += 10;
+ next = saturating_add(next, 10);
break;
case SDL_GAMEPAD_BUTTON_DPAD_LEFT:
- delta -= 1;
+ next = saturating_sub(next, 1);
break;
case SDL_GAMEPAD_BUTTON_DPAD_RIGHT:
- delta += 1;
+ next = saturating_add(next, 1);
break;
}
break;
@@ -145,25 +142,24 @@ bool pw_menu_event(struct pw_menu *menu, SDL_Event *event) {
break;
case SDLK_UP:
case SDLK_K:
- delta -= 10;
+ next = saturating_sub(next, 10);
break;
case SDLK_DOWN:
case SDLK_J:
- delta += 10;
+ next = saturating_add(next, 10);
break;
case SDLK_LEFT:
case SDLK_H:
- delta -= 1;
+ next = saturating_sub(next, 1);
break;
case SDLK_RIGHT:
case SDLK_L:
- delta += 1;
+ next = saturating_add(next, 1);
break;
}
}
+ menu->selection.next = SDL_min(next, menu->carts->count - 1);
- menu->selection.next = SDL_min(saturating_add(menu->selection.next, delta),
- menu->carts->count - 1);
return true;
}
diff --git a/src/picow.c b/src/picow.c
index 0e6bdde..599fea2 100644
--- a/src/picow.c
+++ b/src/picow.c
@@ -1,3 +1,4 @@
+#include <stdio.h>
#include <unistd.h>
#define SDL_MAIN_USE_CALLBACKS
@@ -185,5 +186,5 @@ void SDL_AppQuit(void *appstate, SDL_AppResult result) {
SDL_DestroyWindow(state->window);
SDL_free(state);
- SDL_Log(0, "bye");
+ SDL_Log("bye");
}
diff --git a/tools/generate-sysroot.c b/tools/generate-sysroot.c
index 4400fcd..e6d93f8 100644
--- a/tools/generate-sysroot.c
+++ b/tools/generate-sysroot.c
@@ -1,10 +1,12 @@
-#include <limits.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
+#define PW_PATH_MAX 1024
+
static inline void check(bool cond, char const *msg) {
if (!cond) {
perror(msg);
@@ -22,10 +24,10 @@ static void fprintfx(FILE *f, char const *fmt, ...) {
static void fclosex(FILE *f) { check(!fclose(f), "fclose"); }
-static void joinpath(char buffer[static PATH_MAX], char const *dir,
+static void joinpath(char buffer[static PW_PATH_MAX], char const *dir,
char const *file) {
- size_t n = snprintf(buffer, PATH_MAX, "%s/%s", dir, file);
- check(n < PATH_MAX, "joinpath");
+ size_t n = snprintf(buffer, PW_PATH_MAX, "%s/%s", dir, file);
+ check(n < PW_PATH_MAX, "joinpath");
}
struct sysroot_output {
@@ -35,7 +37,7 @@ struct sysroot_output {
static void open_sysroot_output(struct sysroot_output *out,
char const *outdir) {
- char path[PATH_MAX];
+ char path[PW_PATH_MAX];
joinpath(path, outdir, "sysroot.h");
out->h = fopen(path, "w");
@@ -125,7 +127,7 @@ int main(int argc, char *argv[argc + 1]) {
{"unknown_p8_png", "unknown.p8.png"},
};
for (size_t i = 0; i < sizeof entries / sizeof entries[0]; i++) {
- char file[PATH_MAX];
+ char file[PW_PATH_MAX];
joinpath(file, sysroot, entries[i].file);
write_sysroot_data(&out, entries[i].name, file);
}