Skip to content

unix/mpthreadport: Fix type / comparison of PTHREAD_STACK_MIN. #17440

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

andrewleech
Copy link
Contributor

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?

Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
@andrewleech andrewleech changed the title unix/mpthreadport: Ensure consistent type of PTHREAD_STACK_MIN. unix/mpthreadport: Fix type / comparison of PTHREAD_STACK_MIN. Jun 6, 2025
Copy link

codecov bot commented Jun 6, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.54%. Comparing base (5f058e9) to head (6473276).
Report is 35 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #17440   +/-   ##
=======================================
  Coverage   98.54%   98.54%           
=======================================
  Files         169      169           
  Lines       21943    21943           
=======================================
  Hits        21623    21623           
  Misses        320      320           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

github-actions bot commented Jun 6, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants