unix/mpthreadport: Fix type / comparison of PTHREAD_STACK_MIN.
Summary
When compiling the unix port on my recently updated ubuntu machine I ran into this error:
mpthreadport.c: In function ‘mp_thread_create’:
mpthreadport.c:253:21: error: comparison of integer expressions of different signedness: ‘size_t’ {aka ‘long unsigned int’} and ‘long int’ [-Werror=sign-compare]
253 | if (*stack_size < PTHREAD_STACK_MIN) {
| ^
cc1: all warnings being treated as errors
See https://github.com/micropython/micropython/wiki/Build-Troubleshooting
make: *** [../../py/mkrules.mk:101: build-standard/mpthreadport.o] Error 1
make: *** Waiting for unfinished jobs....
make: Leaving directory '/home/corona/micropython/ports/unix'
It looks like my gcc was updated:
[corona@Telie micropython]$ gcc --version
gcc (GCC) 14.2.1 20250207
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
The variable PTHREAD_STACK_MIN is defined by the pthread libraries:
/usr/include/bits/pthread_stack_min.h
1:/* Definition of PTHREAD_STACK_MIN. Linux version.
20:#define PTHREAD_STACK_MIN 16384
It seems GCC 14 got stricter with warn/errs like -Wsign-compare and types a "bare number" as a long int that can't be compared to a (unsigned) size_t ?
Testing
With this change the unix port compiled again. The thread unit tests pass:
[corona@Telie tests]$ ./run-tests.py ./thread/thread*.py
platform=linux arch=x64
pass ./thread/thread_heap_lock.py
pass ./thread/thread_ident1.py
pass ./thread/thread_lock1.py
pass ./thread/thread_exc2.py
pass ./thread/thread_exit2.py
pass ./thread/thread_lock2.py
pass ./thread/thread_gc1.py
pass ./thread/thread_lock5.py
pass ./thread/thread_qstr1.py
pass ./thread/thread_shared1.py
pass ./thread/thread_shared2.py
pass ./thread/thread_sleep1.py
pass ./thread/thread_lock3.py
pass ./thread/thread_lock4.py
pass ./thread/thread_stacksize1.py
pass ./thread/thread_exit1.py
pass ./thread/thread_coop.py
pass ./thread/thread_exc1.py
pass ./thread/thread_sleep2.py
pass ./thread/thread_start1.py
pass ./thread/thread_start2.py
pass ./thread/thread_stdin.py
22 tests performed (127 individual testcases)
22 tests passed
Trade-offs and Alternatives
The function could accept a ssize_t instead but that's arguably a broader change.
Perhaps there's a compiler flag to work around this default signing of integers a different way?
Codecov Report
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 98.38%. Comparing base (
7729e80) to head (bc77b27).
Additional details and impacted files
@@ Coverage Diff @@
## master #17440 +/- ##
=======================================
Coverage 98.38% 98.38%
=======================================
Files 171 171
Lines 22238 22238
=======================================
Hits 21879 21879
Misses 359 359
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
Code size report:
bare-arm: +0 +0.000%
minimal x86: +0 +0.000%
unix x64: +0 +0.000% standard
stm32: +0 +0.000% PYBV10
mimxrt: +0 +0.000% TEENSY40
rp2: +0 +0.000% RPI_PICO_W
samd: +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS
qemu rv32: +0 +0.000% VIRT_RV32