8000 Merge remote-tracking branch 'upstream/main' into stackref_all · python/cpython@ec70b3b · GitHub
[go: up one dir, main page]

Skip to content

Commit ec70b3b

Browse files
Merge remote-tracking branch 'upstream/main' into stackref_all
2 parents dcc55b0 + b034f14 commit ec70b3b

File tree

251 files changed

+7457
-2595
lines changed
  • cpython
  • internal
  • Lib
  • Mac/BuildScript
  • Misc
  • Modules
  • Objects
  • PC
  • PCbuild
  • Parser
  • Python
  • Tools
  • Some content is hidden

    Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

    251 files changed

    +7457
    -2595
    lines changed

    .github/workflows/jit.yml

    Lines changed: 5 additions & 8 deletions
    Original file line numberDiff line numberDiff line change
    @@ -75,14 +75,10 @@ jobs:
    7575
    architecture: aarch64
    7676
    runner: ubuntu-latest
    7777
    compiler: gcc
    78-
    # These fail because of emulation, not because of the JIT:
    79-
    exclude: test_pathlib test_posixpath test_unix_events test_init test_process_pool test_shutdown test_multiprocessing_fork test_cmd_line test_faulthandler test_os test_perf_profiler test_posix test_signal test_socket test_subprocess test_threading test_venv test_external_inspection
    8078
    - target: aarch64-unknown-linux-gnu/clang
    8179
    architecture: aarch64
    8280
    runner: ubuntu-latest
    8381
    compiler: clang
    84-
    # These fail because of emulation, not because of the JIT:
    85-
    exclude: test_pathlib test_posixpath test_unix_events test_init test_process_pool test_shutdown test_multiprocessing_fork test_cmd_line test_faulthandler test_os test_perf_profiler test_posix test_signal test_socket test_subprocess test_threading test_venv test_external_inspection
    8682
    env:
    8783
    CC: ${{ matrix.compiler }}
    8884
    steps:
    @@ -97,7 +93,7 @@ jobs:
    9793
    choco upgrade llvm -y
    9894
    choco install llvm --allow-downgrade --no-progress --version ${{ matrix.llvm }}
    9995
    ./PCbuild/build.bat --experimental-jit ${{ matrix.debug && '-d' || '--pgo' }} -p ${{ matrix.architecture }}
    100-
    ./PCbuild/rt.bat ${{ matrix.debug && '-d' }} -p ${{ matrix.architecture }} -q --exclude ${{ matrix.exclude }} --multiprocess 0 --timeout 4500 --verbose2 --verbose3
    96+
    ./PCbuild/rt.bat ${{ matrix.debug && '-d' || '' }} -p ${{ matrix.architecture }} -q --multiprocess 0 --timeout 4500 --verbose2 --verbose3
    10197
    10298
    # No PGO or tests (yet):
    10399
    - name: Emulated Windows
    @@ -115,7 +111,7 @@ jobs:
    115111
    SDKROOT="$(xcrun --show-sdk-path)" \
    116112
    ./configure --enable-experimental-jit ${{ matrix.debug && '--with-pydebug' || '--enable-optimizations --with-lto' }}
    117113
    make all --jobs 4
    118-
    ./python.exe -m test --exclude ${{ matrix.exclude }} --multiprocess 0 --timeout 4500 --verbose2 --verbose3
    114+
    ./python.exe -m test --multiprocess 0 --timeout 4500 --verbose2 --verbose3
    119115
    120116
    # --with-lto has been removed temporarily as a result of an open issue in LLVM 18 (see https://github.com/llvm/llvm-project/issues/87553)
    121117
    - name: Native Linux
    @@ -125,11 +121,12 @@ jobs:
    125121
    export PATH="$(llvm-config-${{ matrix.llvm }} --bindir):$PATH"
    126122
    ./configure --enable-experimental-jit ${{ matrix.debug && '--with-pydebug' || '--enable-optimizations' }}
    127123
    make all --jobs 4
    128-
    ./python -m test --exclude ${{ matrix.exclude }} --multiprocess 0 --timeout 4500 --verbose2 --verbose3
    124+
    ./python -m test --multiprocess 0 --timeout 4500 --verbose2 --verbose3
    129125
    130126
    # --with-lto has been removed temporarily as a result of an open issue in LLVM 18 (see https://github.com/llvm/llvm-project/issues/87553)
    131127
    - name: Emulated Linux
    132128
    if: runner.os == 'Linux' && matrix.architecture != 'x86_64'
    129+
    # The --ignorefile on ./python -m test is used to exclude tests known to fail when running on an emulated Linux.
    133130
    run: |
    134131
    sudo bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)" ./llvm.sh ${{ matrix.llvm }}
    135132
    export PATH="$(llvm-config-${{ matrix.llvm }} --bindir):$PATH"
    @@ -146,4 +143,4 @@ jobs:
    146143
    HOSTRUNNER=qemu-${{ matrix.architecture }} \
    147144
    ./configure --enable-experimental-jit ${{ matrix.debug && '--with-pydebug' || '--enable-optimizations ' }} --build=x86_64-linux-gnu --host="$HOST" --with-build-python=../build/bin/python3 --with-pkg-config=no ac_cv_buggy_getaddrinfo=no ac_cv_file__dev_ptc=no ac_cv_file__dev_ptmx=yes
    148145
    make all --jobs 4
    149-
    ./python -m test --exclude ${{ matrix.exclude }} --multiprocess 0 --timeout 4500 --verbose2 --verbose3
    146+
    ./python -m test --ignorefile=Tools/jit/ignore-tests-emulated-linux.txt --multiprocess 0 --timeout 4500 --verbose2 --verbose3

    .pre-commit-config.yaml

    Lines changed: 8 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -11,6 +11,14 @@ repos:
    1111
    args: [--exit-non-zero-on-fix, --config=Tools/clinic/.ruff.toml]
    1212
    files: ^Tools/clinic/|Lib/test/test_clinic.py
    1313

    14+
    - repo: https://github.com/psf/black-pre-commit-mirror
    15+
    rev: 24.4.2
    16+
    hooks:
    17+
    - id: black
    18+
    name: Run Black on Tools/jit/
    19+
    files: ^Tools/jit/
    20+
    language_version: python3.12
    21+
    1422
    - repo: https://github.com/pre-commit/pre-commit-hooks
    1523
    rev: v4.5.0
    1624
    hooks:

    Doc/c-api/index.rst

    Lines changed: 1 addition & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -25,3 +25,4 @@ document the API functions in detail.
    2525
    memory.rst
    2626
    objimpl.rst
    2727
    apiabiversion.rst
    28+
    monitoring.rst

    Doc/c-api/module.rst

    Lines changed: 38 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -411,6 +411,31 @@ The available slot types are:
    411411
    412412
    .. versionadded:: 3.12
    413413
    414+
    .. c:macro:: Py_mod_gil
    415+
    416+
    Specifies one of the following values:
    417+
    418+
    .. c:macro:: Py_MOD_GIL_USED
    419+
    420+
    The module depends on the presence of the global interpreter lock (GIL),
    421+
    and may access global state without synchronization.
    422+
    423+
    .. c:macro:: Py_MOD_GIL_NOT_USED
    424+
    425+
    The module is safe to run without an active GIL.
    426+
    427+
    This slot is ignored by Python builds not configured with
    428+
    :option:`--disable-gil`. Otherwise, it determines whether or not importing
    429+
    this module will cause the GIL to be automatically enabled. See
    430+
    :envvar:`PYTHON_GIL` and :option:`-X gil <-X>` for more detail.
    431+
    432+
    Multiple ``Py_mod_gil`` slots may not be specified in one module definition.
    433+
    434+
    If ``Py_mod_gil`` is not specified, the import machinery defaults to
    435+
    ``Py_MOD_GIL_USED``.
    436+
    437+
    .. versionadded: 3.13
    438+
    414439
    See :PEP:`489` for more details on multi-phase initialization.
    415440
    416441
    Low-level module creation functions
    @@ -609,6 +634,19 @@ state:
    609634
    610635
    .. versionadded:: 3.9
    611636
    637+
    .. c:function:: int PyModule_ExperimentalSetGIL(PyObject *module, void *gil)
    638+
    639+
    Indicate that *module* does or does not support running without the global
    640+
    interpreter lock (GIL), using one of the values from
    641+
    :c:macro:`Py_mod_gil`. It must be called during *module*'s initialization
    642+
    function. If this function is not called during module initialization, the
    643+
    import machinery assumes the module does not support running without the
    644+
    GIL. This function is only available in Python builds configured with
    645+
    :option:`--disable-gil`.
    646+
    Return ``-1`` on error, ``0`` on success.
    647+
    648+
    .. versionadded:: 3.13
    649+
    612650
    613651
    Module lookup
    614652
    ^^^^^^^^^^^^^

    Doc/c-api/monitoring.rst

    Lines changed: 164 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -0,0 +1,164 @@
    1+
    .. highlight:: c
    2+
    3+
    .. _monitoring:
    4+
    5+
    Monitorong C API
    6+
    ================
    7+
    8+
    Added in version 3.13.
    9+
    10+
    An extension may need to interact with the event monitoring system. Subscribing
    11+
    to events and registering callbacks can be done via the Python API exposed in
    12+
    :mod:`sys.monitoring`.
    13+
    14+
    Generating Execution Events
    15+
    ===========================
    16+
    17+
    The functions below make it possible for an extension to fire monitoring
    18+
    events as it emulates the execution of Python code. Each of these functions
    19+
    accepts a ``PyMonitoringState`` struct which contains concise information
    20+
    about the activation state of events, as well as the event arguments, which
    21+
    include a ``PyObject*`` representing the code object, the instruction offset
    22+
    and sometimes additional, event-specific arguments (see :mod:`sys.monitoring`
    23+
    for details about the signatures of the different event callbacks).
    24+
    The ``codelike`` argument should be an instance of :class:`types.CodeType`
    25+
    or of a type that emulates it.
    26+
    27+
    The VM disables tracing when firing an event, so there is no need for user
    28+
    code to do that.
    29+
    30+
    Monitoring functions should not be called with an exception set,
    31+
    except those listed below as working with the current exception.
    32+
    33+
    .. c:type:: PyMonitoringState
    34+
    35+
    Representation of the state of an event type. It is allocated by the user
    36+
    while its contents are maintained by the monitoring API functions described below.
    37+
    38+
    39+
    All of the functions below return 0 on success and -1 (with an exception set) on error.
    40+
    41+
    See :mod:`sys.monitoring` for descriptions of the events.
    42+
    43+
    .. c:function:: int PyMonitoring_FirePyStartEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset)
    44+
    45+
    Fire a ``PY_START`` event.
    46+
    47+
    48+
    .. c:function:: int PyMonitoring_FirePyResumeEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset)
    49+
    50+
    Fire a ``PY_RESUME`` event.
    51+
    52+
    53+
    .. c:function:: int PyMonitoring_FirePyReturnEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset, PyObject* retval)
    54+
    55+
    Fire a ``PY_RETURN`` event.
    56+
    57+
    58+
    .. c:function:: int PyMonitoring_FirePyYieldEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset, PyObject* retval)
    59+
    60+
    Fire a ``PY_YIELD`` event.
    61+
    62+
    63+
    .. c:function:: int PyMonitoring_FireCallEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset, PyObject* callable, PyObject *arg0)
    64+
    65+
    Fire a ``CALL`` event.
    66+
    67+
    68+
    .. c:function:: int PyMonitoring_FireLineEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset, int lineno)
    69+
    70+
    Fire a ``LINE`` event.
    71+
    72+
    73+
    .. c:function:: int PyMonitoring_FireJumpEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset, PyObject *target_offset)
    74+
    75+
    Fire a ``JUMP`` event.
    76+
    77+
    78+
    .. c:function:: int PyMonitoring_FireBranchEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset, PyObject *target_offset)
    79+
    80+
    Fire a ``BRANCH`` event.
    81+
    82+
    83+
    .. c:function:: int PyMonitoring_FireCReturnEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset, PyObject *retval)
    84+
    85+
    Fire a ``C_RETURN`` event.
    86+
    87+
    88+
    .. c:function:: int PyMonitoring_FirePyThrowEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset)
    89+
    90+
    Fire a ``PY_THROW`` event with the current exception (as returned by
    91+
    :c:func:`PyErr_GetRaisedException`).
    92+
    93+
    94+
    .. c:function:: int PyMonitoring_FireRaiseEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset)
    95+
    96+
    Fire a ``RAISE`` event with the current exception (as returned by
    97+
    :c:func:`PyErr_GetRaisedException`).
    98+
    99+
    100+
    .. c:function:: int PyMonitoring_FireCRaiseEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset)
    101+
    102+
    Fire a ``C_RAISE`` event with the current exception (as returned by
    103+
    :c:func:`PyErr_GetRaisedException`).
    104+
    105+
    106+
    .. c:function:: int PyMonitoring_FireReraiseEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset)
    107+
    108+
    Fire a ``RERAISE`` event with the current exception (as returned by
    109+
    :c:func:`PyErr_GetRaisedException`).
    110+
    111+
    112+
    .. c:function:: int PyMonitoring_FireExceptionHandledEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset)
    113+
    114+
    Fire an ``EXCEPTION_HANDLED`` event with the current exception (as returned by
    115+
    :c:func:`PyErr_GetRaisedException`).
    116+
    117+
    118+
    .. c:function:: int PyMonitoring_FirePyUnwindEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset)
    119+
    120+
    Fire a ``PY_UNWIND`` event with the current exception (as returned by
    121+
    :c:func:`PyErr_GetRaisedException`).
    122+
    123+
    124+
    .. c:function:: int PyMonitoring_FireStopIterationEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset)
    125+
    126+
    Fire a ``STOP_ITERATION`` event with the current exception (as returned by
    127+
    :c:func:`PyErr_GetRaisedException`).
    128+
    129+
    130+
    Managing the Monitoring State
    131+
    -----------------------------
    132+
    133+
    Monitoring states can be managed with the help of monitoring scopes. A scope
    134+
    would typically correspond to a python function.
    135+
    136+
    .. :c:function:: int PyMonitoring_EnterScope(PyMonitoringState *state_array, uint64_t *version, const uint8_t *event_types, Py_ssize_t length)
    137+
    138+
    Enter a monitored scope. ``event_types`` is an array of the event IDs for
    139+
    events that may be fired from the scope. For example, the ID of a ``PY_START``
    140+
    event is the value ``PY_MONITORING_EVENT_PY_START``, which is numerically equal
    141+
    to the base-2 logarithm of ``sys.monitoring.events.PY_START``.
    142+
    ``state_array`` is an array with a monitoring state entry for each event in
    143+
    ``event_types``, it is allocated by the user but populated by
    144+
    ``PyMonitoring_EnterScope`` with information about the activation state of
    145+
    the event. The size of ``event_types`` (and hence also of ``state_array``)
    146+
    is given in ``length``.
    147+
    148+
    The ``version`` argument is a pointer to a value which should be allocated
    149+
    by the user together with ``state_array`` and initialized to 0,
    150+
    and then set only by ``PyMonitoring_EnterScope`` itelf. It allows this< EE3C /span>
    151+
    function to determine whether event states have changed since the previous call,
    152+
    and to return quickly if they have not.
    153+
    154+
    The scopes referred to here are lexical scopes: a function, class or method.
    155+
    ``PyMonitoring_EnterScope`` should be called whenever the lexical scope is
    156+
    entered. Scopes can be reentered, reusing the same *state_array* and *version*,
    157+
    in situations like when emulating a recursive Python function. When a code-like's
    158+
    execution is paused, such as when emulating a generator, the scope needs to
    159+
    be exited and re-entered.
    160+
    161+
    162+
    .. :c:function:: int PyMonitoring_ExitScope(void)
    163+
    164+
    Exit the last scope that was entered with ``PyMonitoring_EnterScope``.

    Doc/conf.py

    Lines changed: 1 addition & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -131,6 +131,7 @@
    131131
    ('c:func', 'vsnprintf'),
    132132
    # Standard C types
    133133
    ('c:type', 'FILE'),
    134+
    ('c:type', 'int32_t'),
    134135
    ('c:type', 'int64_t'),
    135136
    ('c:type', 'intmax_t'),
    136137
    ('c:type', 'off_t'),

    Doc/data/stable_abi.dat

    Lines changed: 3 additions & 0 deletions
    Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

    0 commit comments

    Comments
     (0)
    0