Skip to content

strxfrm fails on macOS 15 with OSError: [Errno 22] Invalid argument #130567

Closed

Description

@nijel

Bug report

Bug description:

It appears that macOS 15 broke locale.strxfrm for letters outside the latin-1 set:

import locale
locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
locale.strxfrm('Français') # works
locale.strxfrm('zkouška') # crashes with OSError
locale.strxfrm('中文') # crashes with OSError

This works on Linux and macOS 14 and crashes on macOS 15, tested with Python 3.9–3.14: https://github.com/nijel/python-strxfrm/actions/runs/13541306384/job/37842825809

There are several projects which run into this already:

In most cases, this is being addressed by completely removing locale-aware sorting.

CPython versions tested on:

3.14

Operating systems tested on:

macOS

Linked PRs

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    on Feb 26, 2025
  2. nijel commented on Feb 26, 2025

    @nijel
    ContributorAuthor

    Looking more into that I've found https://swi-prolog.discourse.group/t/compiling-swi-prolog-from-git-source-on-next-macos-15-beta/7590/1. They figured out that wcsxfrm does not actually return desired string size in case of the failure, so they ended up allocating double space in that case, see SWI-Prolog/swipl-devel@f0bbfb0.

    The following code would have to be changed:

    wchar_t * new_buf = PyMem_Realloc(buf, (n2+1)*sizeof(wchar_t));

  3. added a commit that references this issue on Feb 27, 2025
  4. nijel commented on Feb 27, 2025

    @nijel
    ContributorAuthor

    I've tried to address this #130619.

  5. added 5 commits that reference this issue on Feb 27, 2025
  6. serhiy-storchaka commented on Feb 28, 2025

    @serhiy-storchaka
    Member

    What error do you get? What code?

  7. added a commit that references this issue on Feb 28, 2025
  8. serhiy-storchaka commented on Feb 28, 2025

    @serhiy-storchaka
    Member

    Other reports show "[Errno 22] Invalid argument". This is EINVAL. But the re-allocation code is only executed if errno is 0 or ERANGE (34), so your fix cannot change the outcome.

  9. 32 remaining items

  10. added 2 commits that reference this issue on Sep 23, 2025
  11. added 2 commits that reference this issue on Sep 24, 2025
  12. added 2 commits that reference this issue on Sep 29, 2025
  13. added a commit that references this issue on Sep 30, 2025
  14. added 2 commits that reference this issue on Oct 7, 2025
  15. added a commit that references this issue on Oct 16, 2025
  16. added a commit that references this issue on Dec 6, 2025
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

    OS-macextension-modulesC modules in the Modules dirtype-bugAn unexpected behavior, bug, or error

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions