Skip to content

Commit 4def1ea

Browse files
authored
Merge branch 'main' into issue-150887-importlib-docs
2 parents 01f6890 + 206788a commit 4def1ea

5 files changed

Lines changed: 28 additions & 12 deletions

File tree

Lib/test/test_capi/test_mem.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@ def check(self, code):
2424
out = assert_python_failure(
2525
'-c', code,
2626
PYTHONMALLOC=self.PYTHONMALLOC,
27-
# FreeBSD: instruct jemalloc to not fill freed() memory
28-
# with junk byte 0x5a, see JEMALLOC(3)
27+
# Instruct the system allocator to not fill freed() memory
28+
# with junk bytes:
29+
# FreeBSD: jemalloc, see JEMALLOC(3).
2930
MALLOC_CONF="junk:false",
31+
# OpenBSD: see MALLOC.CONF(5).
32+
MALLOC_OPTIONS="j",
3033
)
3134
stderr = out.err
3235
return stderr.decode('ascii', 'replace')
@@ -102,7 +105,9 @@ def check_pyobject_is_freed(self, func_name):
102105
assert_python_ok(
103106
'-c', code,
104107
PYTHONMALLOC=self.PYTHONMALLOC,
108+
# See the comment in check() above.
105109
MALLOC_CONF="junk:false",
110+
MALLOC_OPTIONS="j",
106111
)
107112

108113
def test_pyobject_null_is_freed(self):

Lib/test/test_concurrent_futures/test_init.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import contextlib
22
import logging
3+
import multiprocessing
34
import queue
45
import time
56
import unittest
@@ -147,8 +148,8 @@ def test_spawn(self):
147148
self._test(ProcessPoolSpawnFailingInitializerTest)
148149

149150
@support.skip_if_sanitizer("TSAN doesn't support threads after fork", thread=True)
150-
@unittest.skipIf(sys.platform == "cygwin",
151-
"Forkserver is not available on Cygwin")
151+
@unittest.skipUnless("forkserver" in multiprocessing.get_all_start_methods(),
152+
"forkserver start method is not available")
152153
def test_forkserver(self):
153154
self._test(ProcessPoolForkserverFailingInitializerTest)
154155

Lib/test/test_profiling/test_tracing_profiler.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Test suite for the cProfile module."""
2+
import multiprocessing
23
import sys
34
import unittest
45

@@ -220,8 +221,8 @@ def test_process_spawn_pickle(self):
220221
# gh-140729: test use Process in cProfile.
221222
self._test_process_run_pickle('spawn')
222223

223-
@unittest.skipIf(sys.platform == 'win32',
224-
"No 'forkserver' start method on Windows")
224+
@unittest.skipUnless("forkserver" in multiprocessing.get_all_start_methods(),
225+
"forkserver start method is not available")
225226
def test_process_forkserver_pickle(self):
226227
# gh-140729: test use Process in cProfile.
227228
self._test_process_run_pickle('forkserver')
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Slightly speed up deallocation of objects that are not tracked by the garbage
2+
collector, such as :class:`int`, :class:`float` and :class:`str`.

Objects/object.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3292,13 +3292,20 @@ _Py_Dealloc(PyObject *op)
32923292
PyTypeObject *type = Py_TYPE(op);
32933293
unsigned long gc_flag = type->tp_flags & Py_TPFLAGS_HAVE_GC;
32943294
destructor dealloc = type->tp_dealloc;
3295-
PyThreadState *tstate = _PyThreadState_GET();
3296-
intptr_t margin = _Py_RecursionLimit_GetMargin(tstate);
3297-
if (margin < 2 && gc_flag) {
3298-
_PyTrash_thread_deposit_object(tstate, (PyObject *)op);
3299-
return;
3295+
PyThreadState *tstate = NULL;
3296+
intptr_t margin = 0;
3297+
if (gc_flag) {
3298+
tstate = _PyThreadState_GET();
3299+
margin = _Py_RecursionLimit_GetMargin(tstate);
3300+
if (margin < 2) {
3301+
_PyTrash_thread_deposit_object(tstate, (PyObject *)op);
3302+
return;
3303+
}
33003304
}
33013305
#ifdef Py_DEBUG
3306+
if (tstate == NULL) {
3307+
tstate = _PyThreadState_GET();
3308+
}
33023309
#if !defined(Py_GIL_DISABLED) && !defined(Py_STACKREF_DEBUG)
33033310
/* This assertion doesn't hold for the free-threading build, as
33043311
* PyStackRef_CLOSE_SPECIALIZED is not implemented */
@@ -3340,7 +3347,7 @@ _Py_Dealloc(PyObject *op)
33403347
Py_XDECREF(old_exc);
33413348
Py_DECREF(type);
33423349
#endif
3343-
if (tstate->delete_later && margin >= 4 && gc_flag) {
3350+
if (gc_flag && tstate->delete_later && margin >= 4) {
33443351
_PyTrash_thread_destroy_chain(tstate);
33453352
}
33463353
}

0 commit comments

Comments
 (0)