Skip to content

pbio/main: Fix return type of pbio_main_start_application_resources. - #507

Open
CrispStrobe wants to merge 1 commit into
pybricks:masterfrom
CrispStrobe:fix-start-app-resources-void
Open

CrispStrobe wants to merge 1 commit into
pybricks:masterfrom
CrispStrobe:fix-start-app-resources-void

Conversation

@CrispStrobe

Copy link
Copy Markdown

lib/pbio/include/pbio/main.h declares

pbio_error_t pbio_main_start_application_resources(void);

but lib/pbio/src/main.c defines it as void, and the only caller
(lib/pbio/sys/main.c) ignores the result. src/main.c does not include
pbio/main.h, so the compiler never compares the two. This is still true on
master (8aa9986).

With the ARM calling convention this happens to work, but it is undefined
behaviour. On targets that check function signatures it fails: an emscripten
build links with

wasm-ld: warning: function signature mismatch: pbio_main_start_application_resources
>>> defined as () -> i32 in lib/pbio/sys/main.o
>>> defined as () -> void in lib/pbio/src/main.o

and the call traps at run time.

The fix makes the declaration void and includes pbio/main.h in
src/main.c, so any future mismatch is a compile error. Without the header
change, the added include produces:

lib/pbio/src/main.c:70:6: error: conflicting types for 'pbio_main_start_application_resources'; have 'void(void)'

Both files compile cleanly with the fix (virtualhub flags, -Wall -Werror).

🤖 Generated with Claude Code

The header declared it as returning pbio_error_t, but it is defined as
returning void and the only caller ignores the result. src/main.c did not
include pbio/main.h, so the compiler never compared the two.

With C calling conventions on ARM this happens to work, but it is undefined
behavior, and on targets that check function signatures at link or call
time it does not work: a WebAssembly build links with "function signature
mismatch: pbio_main_start_application_resources" and the call traps.

Make the declaration void, and include pbio/main.h in src/main.c so that a
future mismatch is a compile error.

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant