bricks: fix mp_hal_stdout_tx_strn() signature mismatch#2
bricks: fix mp_hal_stdout_tx_strn() signature mismatch#2morita5840 merged 4 commits intospike-rtfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR aligns multiple Pybricks “bricks” ports with the expected mp_hal_stdout_tx_strn() function signature by updating it to return a byte count (mp_uint_t) and standardizing the length parameter to size_t.
Changes:
- Update
mp_hal_stdout_tx_strn()signatures fromvoidtomp_uint_tand adjust parameter types tosize_tacross affected ports. - Return the number of bytes written (or written-so-far on error) instead of returning nothing / always returning 0.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| bricks/primehub_spike-rt/mphalport.c | Update stdout TX API to return bytes written for both debug and Bluetooth paths. |
| bricks/nxt/mphalport.c | Update stdout TX signature and return value (0 when disconnected/empty; otherwise full length). |
| bricks/ev3rt/mphalport.c | Update stdout TX signature and return bytes written when Bluetooth is connected. |
| bricks/ev3dev/ev3dev_mphal.c | Update stdout TX signature and now returns write() result (but needs type/robustness fix). |
| bricks/_common_stm32/mphalport.c | Update stdout TX signature and return values for UART and Bluetooth paths. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
bricks/ev3dev/ev3dev_mphal.c
Outdated
| mp_uint_t mp_hal_stdout_tx_strn(const char *str, size_t len) { | ||
| MP_THREAD_GIL_EXIT(); | ||
| int ret = write(STDOUT_FILENO, str, len); | ||
| MP_THREAD_GIL_ENTER(); | ||
| (void)ret; // to suppress compiler warning | ||
| return ret < 0 ? 0 : ret; |
There was a problem hiding this comment.
write() returns ssize_t, but the result is stored in an int and then returned as mp_uint_t. On 64-bit systems this can truncate successful writes (and makes it impossible to correctly represent large counts). Use ssize_t for ret and return a properly converted byte count (and ideally loop to handle partial writes/EINTR so stdout output isn’t silently dropped).
|
@morita5840 I've opened a new pull request, #3, to work on those changes. Once the pull request is ready, I'll request review from you. |
|
@morita5840 I've opened a new pull request, #4, to work on those changes. Once the pull request is ready, I'll request review from you. |
…ndle EINTR Co-authored-by: morita5840 <27051616+morita5840@users.noreply.github.com> Agent-Logs-Url: https://github.com/ETrobocon/pybricks-micropython/sessions/47be6172-8e95-4d8b-bd62-96efebdf1c34
Fix mp_hal_stdout_tx_strn(): use ssize_t, loop for partial writes, handle EINTR
No description provided.