Skip to content

Commit 13d6ac7

Browse files
committed
Merge remote-tracking branch 'upstream/main' into fix/await/anextawaitable-close-131666
2 parents f8bac51 + 69e94e0 commit 13d6ac7

File tree

15 files changed

+109
-90
lines changed

15 files changed

+109
-90
lines changed

Include/internal/pycore_interpframe.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,11 @@ _PyFrame_SetStackPointer(_PyInterpreterFrame *frame, _PyStackRef *stack_pointer)
189189
* Frames on the frame stack are incomplete until the
190190
* first RESUME instruction.
191191
* Frames owned by a generator are always complete.
192+
*
193+
* NOTE: We allow racy accesses to the instruction pointer
194+
* from other threads for sys._current_frames() and similar APIs.
192195
*/
193-
static inline bool
196+
static inline bool _Py_NO_SANITIZE_THREAD
194197
_PyFrame_IsIncomplete(_PyInterpreterFrame *frame)
195198
{
196199
if (frame->owner >= FRAME_OWNED_BY_INTERPRETER) {

Include/pyport.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,27 +565,45 @@ extern "C" {
565565
# if __has_feature(memory_sanitizer)
566566
# if !defined(_Py_MEMORY_SANITIZER)
567567
# define _Py_MEMORY_SANITIZER
568+
# define _Py_NO_SANITIZE_MEMORY __attribute__((no_sanitize_memory))
568569
# endif
569570
# endif
570571
# if __has_feature(address_sanitizer)
571572
# if !defined(_Py_ADDRESS_SANITIZER)
572573
# define _Py_ADDRESS_SANITIZER
574+
# define _Py_NO_SANITIZE_ADDRESS __attribute__((no_sanitize_address))
573575
# endif
574576
# endif
575577
# if __has_feature(thread_sanitizer)
576578
# if !defined(_Py_THREAD_SANITIZER)
577579
# define _Py_THREAD_SANITIZER
580+
# define _Py_NO_SANITIZE_THREAD __attribute__((no_sanitize_thread))
578581
# endif
579582
# endif
580583
#elif defined(__GNUC__)
581584
# if defined(__SANITIZE_ADDRESS__)
582585
# define _Py_ADDRESS_SANITIZER
586+
# define _Py_NO_SANITIZE_ADDRESS __attribute__((no_sanitize_address))
583587
# endif
584588
# if defined(__SANITIZE_THREAD__)
585589
# define _Py_THREAD_SANITIZER
590+
# define _Py_NO_SANITIZE_THREAD __attribute__((no_sanitize_thread))
591+
# elif __GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)
592+
// TSAN is supported since GCC 5.1, but __SANITIZE_THREAD__ macro
593+
// is provided only since GCC 7.
594+
# define _Py_NO_SANITIZE_THREAD __attribute__((no_sanitize_thread))
586595
# endif
587596
#endif
588597

598+
#ifndef _Py_NO_SANITIZE_ADDRESS
599+
# define _Py_NO_SANITIZE_ADDRESS
600+
#endif
601+
#ifndef _Py_NO_SANITIZE_THREAD
602+
# define _Py_NO_SANITIZE_THREAD
603+
#endif
604+
#ifndef _Py_NO_SANITIZE_MEMORY
605+
# define _Py_NO_SANITIZE_MEMORY
606+
#endif
589607

590608
/* AIX has __bool__ redefined in it's system header file. */
591609
#if defined(_AIX) && defined(__bool__)

Lib/test/mapping_tests.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,7 @@ def __repr__(self):
624624

625625
@support.skip_wasi_stack_overflow()
626626
@support.skip_emscripten_stack_overflow()
627+
@support.skip_if_sanitizer("requires deep stack", ub=True)
627628
def test_repr_deep(self):
628629
d = self._empty_mapping()
629630
for i in range(support.exceeds_recursion_limit()):

Lib/test/test_functools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2078,7 +2078,7 @@ def orig(a, /, b, c=True): ...
20782078

20792079
@support.skip_on_s390x
20802080
@unittest.skipIf(support.is_wasi, "WASI has limited C stack")
2081-
@support.skip_if_sanitizer("requires deep stack", thread=True)
2081+
@support.skip_if_sanitizer("requires deep stack", ub=True, thread=True)
20822082
@support.skip_emscripten_stack_overflow()
20832083
def test_lru_recursion(self):
20842084

Modules/_ctypes/_ctypes.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3805,8 +3805,9 @@ _validate_paramflags(ctypes_state *st, PyTypeObject *type, PyObject *paramflags)
38053805
}
38063806

38073807
static int
3808-
_get_name(PyObject *obj, const char **pname)
3808+
_get_name(PyObject *obj, void *arg)
38093809
{
3810+
const char **pname = (const char **)arg;
38103811
#ifdef MS_WIN32
38113812
if (PyLong_Check(obj)) {
38123813
/* We have to use MAKEINTRESOURCEA for Windows CE.

Modules/_ctypes/callproc.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,8 +1353,9 @@ PyObject *_ctypes_callproc(ctypes_state *st,
13531353
}
13541354

13551355
static int
1356-
_parse_voidp(PyObject *obj, void **address)
1356+
_parse_voidp(PyObject *obj, void *arg)
13571357
{
1358+
void **address = (void **)arg;
13581359
*address = PyLong_AsVoidPtr(obj);
13591360
if (*address == NULL)
13601361
return 0;
@@ -1846,8 +1847,9 @@ addressof(PyObject *self, PyObject *obj)
18461847
}
18471848

18481849
static int
1849-
converter(PyObject *obj, void **address)
1850+
converter(PyObject *obj, void *arg)
18501851
{
1852+
void **address = (void **)arg;
18511853
*address = PyLong_AsVoidPtr(obj);
18521854
return *address != NULL;
18531855
}

Modules/_ctypes/cfield.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ PyCField_set(PyObject *op, PyObject *inst, PyObject *value)
266266
}
267267

268268
static PyObject *
269-
PyCField_get(PyObject *op, PyObject *inst, PyTypeObject *type)
269+
PyCField_get(PyObject *op, PyObject *inst, PyObject *type)
270270
{
271271
CDataObject *src;
272272
CFieldObject *self = _CFieldObject_CAST(op);

Modules/_testcapi/heaptype.c

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -605,15 +605,17 @@ heapctype_init(PyObject *self, PyObject *args, PyObject *kwargs)
605605
}
606606

607607
static int
608-
heapgcctype_traverse(HeapCTypeObject *self, visitproc visit, void *arg)
608+
heapgcctype_traverse(PyObject *op, visitproc visit, void *arg)
609609
{
610+
HeapCTypeObject *self = (HeapCTypeObject*)op;
610611
Py_VISIT(Py_TYPE(self));
611612
return 0;
612613
}
613614

614615
static void
615-
heapgcctype_dealloc(HeapCTypeObject *self)
616+
heapgcctype_dealloc(PyObject *op)
616617
{
618+
HeapCTypeObject *self = (HeapCTypeObject*)op;
617619
PyTypeObject *tp = Py_TYPE(self);
618620
PyObject_GC_UnTrack(self);
619621
PyObject_GC_Del(self);
@@ -642,8 +644,9 @@ PyDoc_STRVAR(heapctype__doc__,
642644
"The 'value' attribute is set to 10 in __init__.");
643645

644646
static void
645-
heapctype_dealloc(HeapCTypeObject *self)
647+
heapctype_dealloc(PyObject *op)
646648
{
649+
HeapCTypeObject *self = (HeapCTypeObject*)op;
647650
PyTypeObject *tp = Py_TYPE(self);
648651
PyObject_Free(self);
649652
Py_DECREF(tp);
@@ -716,8 +719,9 @@ typedef struct {
716719
} HeapCTypeWithBufferObject;
717720

718721
static int
719-
heapctypewithbuffer_getbuffer(HeapCTypeWithBufferObject *self, Py_buffer *view, int flags)
722+
heapctypewithbuffer_getbuffer(PyObject *op, Py_buffer *view, int flags)
720723
{
724+
HeapCTypeWithBufferObject *self = (HeapCTypeWithBufferObject*)op;
721725
self->buffer[0] = '1';
722726
self->buffer[1] = '2';
723727
self->buffer[2] = '3';
@@ -727,8 +731,9 @@ heapctypewithbuffer_getbuffer(HeapCTypeWithBufferObject *self, Py_buffer *view,
727731
}
728732

729733
static void
730-
heapctypewithbuffer_releasebuffer(HeapCTypeWithBufferObject *self, Py_buffer *view)
734+
heapctypewithbuffer_releasebuffer(PyObject *op, Py_buffer *view)
731735
{
736+
HeapCTypeWithBufferObject *self = (HeapCTypeWithBufferObject*)op;
732737
assert(view->obj == (void*) self);
733738
}
734739

@@ -873,9 +878,9 @@ typedef struct {
873878
} HeapCTypeWithDictObject;
874879

875880
static void
876-
heapctypewithdict_dealloc(HeapCTypeWithDictObject* self)
881+
heapctypewithdict_dealloc(PyObject *op)
877882
{
878-
883+
HeapCTypeWithDictObject *self = (HeapCTypeWithDictObject*)op;
879884
PyTypeObject *tp = Py_TYPE(self);
880885
Py_XDECREF(self->dict);
881886
PyObject_Free(self);
@@ -917,22 +922,23 @@ static PyType_Spec HeapCTypeWithDict2_spec = {
917922
};
918923

919924
static int
920-
heapmanaged_traverse(HeapCTypeObject *self, visitproc visit, void *arg)
925+
heapmanaged_traverse(PyObject *self, visitproc visit, void *arg)
921926
{
922927
Py_VISIT(Py_TYPE(self));
923928
return PyObject_VisitManagedDict((PyObject *)self, visit, arg);
924929
}
925930

926931
static int
927-
heapmanaged_clear(HeapCTypeObject *self)
932+
heapmanaged_clear(PyObject *self)
928933
{
929-
PyObject_ClearManagedDict((PyObject *)self);
934+
PyObject_ClearManagedDict(self);
930935
return 0;
931936
}
932937

933938
static void
934-
heapmanaged_dealloc(HeapCTypeObject *self)
939+
heapmanaged_dealloc(PyObject *op)
935940
{
941+
HeapCTypeObject *self = (HeapCTypeObject*)op;
936942
PyTypeObject *tp = Py_TYPE(self);
937943
PyObject_ClearManagedDict((PyObject *)self);
938944
PyObject_GC_UnTrack(self);
@@ -1016,9 +1022,9 @@ static struct PyMemberDef heapctypewithweakref_members[] = {
10161022
};
10171023

10181024
static void
1019-
heapctypewithweakref_dealloc(HeapCTypeWithWeakrefObject* self)
1025+
heapctypewithweakref_dealloc(PyObject *op)
10201026
{
1021-
1027+
HeapCTypeWithWeakrefObject *self = (HeapCTypeWithWeakrefObject*)op;
10221028
PyTypeObject *tp = Py_TYPE(self);
10231029
if (self->weakreflist != NULL)
10241030
PyObject_ClearWeakRefs((PyObject *) self);
@@ -1071,16 +1077,18 @@ heapctypesetattr_init(PyObject *self, PyObject *args, PyObject *kwargs)
10711077
}
10721078

10731079
static void
1074-
heapctypesetattr_dealloc(HeapCTypeSetattrObject *self)
1080+
heapctypesetattr_dealloc(PyObject *op)
10751081
{
1082+
HeapCTypeSetattrObject *self = (HeapCTypeSetattrObject*)op;
10761083
PyTypeObject *tp = Py_TYPE(self);
10771084
PyObject_Free(self);
10781085
Py_DECREF(tp);
10791086
}
10801087

10811088
static int
1082-
heapctypesetattr_setattro(HeapCTypeSetattrObject *self, PyObject *attr, PyObject *value)
1089+
heapctypesetattr_setattro(PyObject *op, PyObject *attr, PyObject *value)
10831090
{
1091+
HeapCTypeSetattrObject *self = (HeapCTypeSetattrObject*)op;
10841092
PyObject *svalue = PyUnicode_FromString("value");
10851093
if (svalue == NULL)
10861094
return -1;
@@ -1237,8 +1245,9 @@ HeapCCollection_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)
12371245
}
12381246

12391247
static Py_ssize_t
1240-
HeapCCollection_length(PyVarObject *self)
1248+
HeapCCollection_length(PyObject *op)
12411249
{
1250+
PyVarObject *self = (PyVarObject*)op;
12421251
return Py_SIZE(self);
12431252
}
12441253

Modules/_testlimitedcapi/heaptype_relative.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ make_sized_heaptypes(PyObject *module, PyObject *args)
7777
static PyObject *
7878
var_heaptype_set_data_to_3s(
7979
PyObject *self, PyTypeObject *defining_class,
80-
PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
80+
PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
8181
{
8282
void *data_ptr = PyObject_GetTypeData(self, defining_class);
8383
if (!data_ptr) {
@@ -93,7 +93,7 @@ var_heaptype_set_data_to_3s(
9393

9494
static PyObject *
9595
var_heaptype_get_data(PyObject *self, PyTypeObject *defining_class,
96-
PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
96+
PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
9797
{
9898
void *data_ptr = PyObject_GetTypeData(self, defining_class);
9999
if (!data_ptr) {

Modules/_threadmodule.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,9 @@ thread_run(void *boot_raw)
384384
}
385385

386386
static int
387-
force_done(ThreadHandle *handle)
387+
force_done(void *arg)
388388
{
389+
ThreadHandle *handle = (ThreadHandle *)arg;
389390
assert(get_thread_handle_state(handle) == THREAD_HANDLE_STARTING);
390391
_PyEvent_Notify(&handle->thread_is_exiting);
391392
set_thread_handle_state(handle, THREAD_HANDLE_DONE);
@@ -458,7 +459,7 @@ ThreadHandle_start(ThreadHandle *self, PyObject *func, PyObject *args,
458459
return 0;
459460

460461
start_failed:
461-
_PyOnceFlag_CallOnce(&self->once, (_Py_once_fn_t *)force_done, self);
462+
_PyOnceFlag_CallOnce(&self->once, force_done, self);
462463
return -1;
463464
}
464465

0 commit comments

Comments
 (0)