From 6064fa6fed5a56740ec97ee5a0cea09df3fe9d84 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 21 Mar 2026 10:54:49 +0000 Subject: [PATCH 1/2] Initial plan From 2395918b5220d4678758f672bd7c7fedd7fc5af4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 21 Mar 2026 10:57:37 +0000 Subject: [PATCH 2/2] Fix mp_hal_stdout_tx_strn(): use ssize_t, loop for partial writes, handle 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 --- bricks/ev3dev/ev3dev_mphal.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/bricks/ev3dev/ev3dev_mphal.c b/bricks/ev3dev/ev3dev_mphal.c index c3fa7b5e5..e4ac74983 100644 --- a/bricks/ev3dev/ev3dev_mphal.c +++ b/bricks/ev3dev/ev3dev_mphal.c @@ -110,10 +110,25 @@ int mp_hal_stdin_rx_chr(void) { } 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(); - return ret < 0 ? 0 : ret; + size_t remaining = len; + while (remaining > 0) { + MP_THREAD_GIL_EXIT(); + ssize_t ret = write(STDOUT_FILENO, str, remaining); + MP_THREAD_GIL_ENTER(); + if (ret < 0) { + if (errno == EINTR) { + continue; + } + return len - remaining; + } + /* Defensive check: POSIX guarantees ret <= remaining, but guard against non-compliant implementations. */ + if ((size_t)ret > remaining) { + return len; + } + str += ret; + remaining -= (size_t)ret; + } + return len; } // cooked is same as uncooked because the terminal does some postprocessing