Skip to content

Py_C_STACK_SIZE causes test_max_level failure on musl/s390x #139467

Closed

Description

@lotheac

Bug report

Bug description:

Hello,

I am updating Python in Alpine to 3.14 and encountered the following test failure on s390x:

======================================================================
ERROR: test_max_level (test.test_grammar.TokenTests.test_max_level)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/builds/lotheac/aports/main/python3/src/Python-3.14.0rc3/Lib/test/test_grammar.py", line 257, in test_max_level
    result = eval("(" * MAXLEVEL + ")" * MAXLEVEL)
MemoryError: Parser stack overflowed - Python source too complex to parse

----------------------------------------------------------------------

the root cause seems to be the following define in Python/ceval.c, added in commit 0142236:

#if defined(__s390x__)
#  define Py_C_STACK_SIZE 320000

I was able to make the tests pass by removing this stack size limitation for s390x with the following patch, making it use the default size 4000000 as other architectures do:

diff --git a/Python/ceval.c b/Python/ceval.c
index e5b1b82e45e..fe8c4a7d092 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -352,7 +352,7 @@ _Py_EnterRecursiveCallUnchecked(PyThreadState *tstate)
     }
 }

-#if defined(__s390x__)
+#if 0
 #  define Py_C_STACK_SIZE 320000
 #elif defined(_WIN32)
    // Don't define Py_C_STACK_SIZE, ask the O/S

Because this dumb patch appears to work, I would like to ask you for some insight on why this Py_C_STACK_SIZE override on s390x exists. I'm not very familiar with s390x myself.

CPython versions tested on:

3.14

Operating systems tested on:

Linux

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    on Oct 1, 2025
  2. picnixz commented on Oct 2, 2025

    @picnixz
    Member

    cc @markshannon (this was #130396)

  3. added
    3.14bugs and security fixes
    3.15bugs and security fixes
    on Oct 2, 2025
  4. changed the title [-][3.14] s390x Py_C_STACK_SIZE causes test_max_level failure on musl[/-] [+][3.14] s390x Py_C_STACK_SIZE causes `test_max_level` failure on musl[/+] on Oct 2, 2025
  5. changed the title [-][3.14] s390x Py_C_STACK_SIZE causes `test_max_level` failure on musl[/-] [+]Py_C_STACK_SIZE causes `test_max_level` failure on musl/s390x[/+] on Oct 2, 2025
  6. vstinner commented on Jun 18, 2026

    @vstinner
    Member

    Hi. I modified Python build system to increase the default stack size from 128 kiB to 1 MiB and update Py_C_STACK_SIZE. Can you please check if you can still reproduce the issue on s390x?

  7. lotheac commented on Jun 18, 2026

    @lotheac
    Author

    Hi. I modified Python build system to increase the default stack size from 128 kiB to 1 MiB and update Py_C_STACK_SIZE. Can you please check if you can still reproduce the issue on s390x?

    could you tell me which commit you did it in? it would be easier for me to test that way.

  8. vstinner commented on Jun 19, 2026

    @vstinner
    Member

    The latest musl fix is 9a61d1c.

  9. lotheac commented on Jun 19, 2026

    @lotheac
    Author

    @vstinner I applied df6c157 and 9a61d1c on top of 3.14.5, and can no longer reproduce the issue. Thanks!

  10. vstinner commented on Jun 19, 2026

    @vstinner
    Member

    That's great! Thanks for testing.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.14bugs and security fixes3.15bugs and security fixesOS-unsupportedinterpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions