Skip to content

Commit 98a5070

Browse files
Merge remote-tracking branch 'upstream/main' into tail-call
2 parents db5114b + 25cf79a commit 98a5070

File tree

108 files changed

+2133
-1746
lines changed

Some content is hidden

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

108 files changed

+2133
-1746
lines changed

.github/workflows/build.yml

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -512,26 +512,20 @@ jobs:
512512
run: xvfb-run make ci
513513

514514
build_tsan:
515-
name: 'Thread sanitizer'
516-
needs: check_source
517-
if: needs.check_source.outputs.run_tests == 'true'
518-
uses: ./.github/workflows/reusable-tsan.yml
519-
with:
520-
config_hash: ${{ needs.check_source.outputs.config_hash }}
521-
options: ./configure --config-cache --with-thread-sanitizer --with-pydebug
522-
suppressions_path: Tools/tsan/supressions.txt
523-
tsan_logs_artifact_name: tsan-logs-default
524-
525-
build_tsan_free_threading:
526-
name: 'Thread sanitizer (free-threading)'
515+
name: >-
516+
Thread sanitizer
517+
${{ fromJSON(matrix.free-threading) && '(free-threading)' || '' }}
527518
needs: check_source
528519
if: needs.check_source.outputs.run_tests == 'true'
520+
strategy:
521+
matrix:
522+
free-threading:
523+
- false
524+
- true
529525
uses: ./.github/workflows/reusable-tsan.yml
530526
with:
531527
config_hash: ${{ needs.check_source.outputs.config_hash }}
532-
options: ./configure --config-cache --disable-gil --with-thread-sanitizer --with-pydebug
533-
suppressions_path: Tools/tsan/suppressions_free_threading.txt
534-
tsan_logs_artifact_name: tsan-logs-free-threading
528+
free-threading: ${{ matrix.free-threading }}
535529

536530
# CIFuzz job based on https://google.github.io/oss-fuzz/getting-started/continuous-integration/
537531
cifuzz:
@@ -591,7 +585,6 @@ jobs:
591585
- test_hypothesis
592586
- build_asan
593587
- build_tsan
594-
- build_tsan_free_threading
595588
- cifuzz
596589

597590
runs-on: ubuntu-latest
@@ -625,7 +618,6 @@ jobs:
625618
build_windows,
626619
build_asan,
627620
build_tsan,
628-
build_tsan_free_threading,
629621
'
630622
|| ''
631623
}}

.github/workflows/reusable-tsan.yml

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,11 @@ on:
66
config_hash:
77
required: true
88
type: string
9-
options:
10-
required: true
11-
type: string
12-
suppressions_path:
13-
description: 'A repo relative path to the suppressions file'
14-
required: true
15-
type: string
16-
tsan_logs_artifact_name:
17-
description: 'Name of the TSAN logs artifact. Must be unique for each job.'
18-
required: true
19-
type: string
9+
free-threading:
10+
description: Whether to use free-threaded mode
11+
required: false
12+
type: boolean
13+
default: false
2014

2115
env:
2216
FORCE_COLOR: 1
@@ -26,9 +20,6 @@ jobs:
2620
name: 'Thread sanitizer'
2721
runs-on: ubuntu-24.04
2822
timeout-minutes: 60
29-
env:
30-
OPTIONS: ${{ inputs.options }}
31-
SUPPRESSIONS_PATH: ${{ inputs.suppressions_path }}
3223
steps:
3324
- uses: actions/checkout@v4
3425
with:
@@ -55,7 +46,11 @@ jobs:
5546
sudo sysctl -w vm.mmap_rnd_bits=28
5647
- name: TSAN Option Setup
5748
run: |
58-
echo "TSAN_OPTIONS=log_path=${GITHUB_WORKSPACE}/tsan_log suppressions=${GITHUB_WORKSPACE}/${SUPPRESSIONS_PATH} handle_segv=0" >> "$GITHUB_ENV"
49+
echo "TSAN_OPTIONS=log_path=${GITHUB_WORKSPACE}/tsan_log suppressions=${GITHUB_WORKSPACE}/Tools/tsan/suppressions${{
50+
fromJSON(inputs.free-threading)
51+
&& '_free_threading'
52+
|| ''
53+
}}.txt handle_segv=0" >> "$GITHUB_ENV"
5954
echo "CC=clang" >> "$GITHUB_ENV"
6055
echo "CXX=clang++" >> "$GITHUB_ENV"
6156
- name: Add ccache to PATH
@@ -67,7 +62,12 @@ jobs:
6762
save: ${{ github.event_name == 'push' }}
6863
max-size: "200M"
6964
- name: Configure CPython
70-
run: "${OPTIONS}"
65+
run: >-
66+
./configure
67+
--config-cache
68+
--with-thread-sanitizer
69+
--with-pydebug
70+
${{ fromJSON(inputs.free-threading) && '--disable-gil' || '' }}
7171
- name: Build CPython
7272
run: make -j4
7373
- name: Display build info
@@ -81,6 +81,11 @@ jobs:
8181
if: always()
8282
uses: actions/upload-artifact@v4
8383
with:
84-
name: ${{ inputs.tsan_logs_artifact_name }}
84+
name: >-
85+
tsan-logs-${{
86+
fromJSON(inputs.free-threading)
87+
&& 'free-threading'
88+
|| 'default'
89+
}}
8590
path: tsan_log.*
8691
if-no-files-found: ignore

.github/workflows/reusable-windows.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ env:
2424
2525
jobs:
2626
build:
27-
name: 'build and test (${{ inputs.arch }})'
27+
name: ${{ inputs.arch == 'arm64' && 'build' || 'build and test' }} (${{ inputs.arch }})
2828
runs-on: ${{ inputs.os }}
2929
timeout-minutes: 60
3030
env:

Doc/c-api/long.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,6 @@ The :c:type:`PyLongWriter` API can be used to import an integer.
824824
825825
Discard a :c:type:`PyLongWriter` created by :c:func:`PyLongWriter_Create`.
826826
827-
*writer* must not be ``NULL``.
827+
If *writer* is ``NULL``, no operation is performed.
828828
829829
The writer instance and the *digits* array are invalid after the call.

Doc/c-api/object.rst

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,3 +613,95 @@ Object Protocol
613613
614614
.. versionadded:: 3.14
615615
616+
.. c:function:: int PyUnstable_IsImmortal(PyObject *obj)
617+
618+
This function returns non-zero if *obj* is :term:`immortal`, and zero
619+
otherwise. This function cannot fail.
620+
621+
.. note::
622+
623+
Objects that are immortal in one CPython version are not guaranteed to
624+
be immortal in another.
625+
626+
.. versionadded:: next
627+
628+
.. c:function:: int PyUnstable_TryIncRef(PyObject *obj)
629+
630+
Increments the reference count of *obj* if it is not zero. Returns ``1``
631+
if the object's reference count was successfully incremented. Otherwise,
632+
this function returns ``0``.
633+
634+
:c:func:`PyUnstable_EnableTryIncRef` must have been called
635+
earlier on *obj* or this function may spuriously return ``0`` in the
636+
:term:`free threading` build.
637+
638+
This function is logically equivalent to the following C code, except that
639+
it behaves atomically in the :term:`free threading` build::
640+
641+
if (Py_REFCNT(op) > 0) {
642+
Py_INCREF(op);
643+
return 1;
644+
}
645+
return 0;
646+
647+
This is intended as a building block for managing weak references
648+
without the overhead of a Python :ref:`weak reference object <weakrefobjects>`.
649+
650+
Typically, correct use of this function requires support from *obj*'s
651+
deallocator (:c:member:`~PyTypeObject.tp_dealloc`).
652+
For example, the following sketch could be adapted to implement a
653+
"weakmap" that works like a :py:class:`~weakref.WeakValueDictionary`
654+
for a specific type:
655+
656+
.. code-block:: c
657+
658+
PyMutex mutex;
659+
660+
PyObject *
661+
add_entry(weakmap_key_type *key, PyObject *value)
662+
{
663+
PyUnstable_EnableTryIncRef(value);
664+
weakmap_type weakmap = ...;
665+
PyMutex_Lock(&mutex);
666+
weakmap_add_entry(weakmap, key, value);
667+
PyMutex_Unlock(&mutex);
668+
Py_RETURN_NONE;
669+
}
670+
671+
PyObject *
672+
get_value(weakmap_key_type *key)
673+
{
674+
weakmap_type weakmap = ...;
675+
PyMutex_Lock(&mutex);
676+
PyObject *result = weakmap_find(weakmap, key);
677+
if (PyUnstable_TryIncRef(result)) {
678+
// `result` is safe to use
679+
PyMutex_Unlock(&mutex);
680+
return result;
681+
}
682+
// if we get here, `result` is starting to be garbage-collected,
683+
// but has not been removed from the weakmap yet
684+
PyMutex_Unlock(&mutex);
685+
return NULL;
686+
}
687+
688+
// tp_dealloc function for weakmap values
689+
void
690+
value_dealloc(PyObject *value)
691+
{
692+
weakmap_type weakmap = ...;
693+
PyMutex_Lock(&mutex);
694+
weakmap_remove_value(weakmap, value);
695+
696+
...
697+
PyMutex_Unlock(&mutex);
698+
}
699+
700+
.. versionadded:: 3.14
701+
702+
.. c:function:: void PyUnstable_EnableTryIncRef(PyObject *obj)
703+
704+
Enables subsequent uses of :c:func:`PyUnstable_TryIncRef` on *obj*. The
705+
caller must hold a :term:`strong reference` to *obj* when calling this.
706+
707+
.. versionadded:: 3.14

Doc/deprecations/c-api-pending-removal-in-future.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ although there is currently no date scheduled for their removal.
3434
Use :c:func:`!_PyErr_ChainExceptions1` instead.
3535
* :c:member:`!PyBytesObject.ob_shash` member:
3636
call :c:func:`PyObject_Hash` instead.
37-
* :c:member:`!PyDictObject.ma_version_tag` member.
3837
* Thread Local Storage (TLS) API:
3938

4039
* :c:func:`PyThread_create_key`:

0 commit comments

Comments
 (0)