Skip to content

Support freethreading Python #16

Description

@hroncok

Activity

  1. hroncok commented on Nov 3, 2025

    @hroncok
    MemberAuthor

    I talked about this with @encukou. Assuming the crypt_r call itself is thread safe1, the only potentially problematic part of the code is Py_TYPE(args[1])->tp_name:

    crypt_r/src/_crypt_r.c

    Lines 37 to 40 in a52c167

    PyErr_Format(
    PyExc_TypeError, "crypt argument 1 (word) must be string, not %s",
    Py_TYPE(args[0])->tp_name
    );

    1. an argument is passed of type X
    2. we call Py_TYPE on it, and get X which does not increment the refcount
    3. the type of the argument is changed by another thread (e.g. by assigning to __class__)
    4. all other instances of this type are gone, garbage collected, the type is deallocated
    5. we call ->tp_name on garbage

    This is technically almost impossible to happen but it might :D

    A solution is to use the %T format here instead, which likely has the same problem, but the implementation is in Python and is no longer "our problem". %T was added in Python 3.13.

    Footnotes

    1. Where the r stands for re-entrant, so we assume it is. ↩

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions