mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
bpo-31370: Remove support for threads-less builds (#3385)
* Remove Setup.config * Always define WITH_THREAD for compatibility.
This commit is contained in:
parent
1f06a680de
commit
a6a4dc816d
135 changed files with 2472 additions and 4377 deletions
|
@ -51,7 +51,7 @@ static struct {
|
|||
int use_domain;
|
||||
} tracemalloc_config = {TRACEMALLOC_NOT_INITIALIZED, 0, 1, 0};
|
||||
|
||||
#if defined(TRACE_RAW_MALLOC) && defined(WITH_THREAD)
|
||||
#if defined(TRACE_RAW_MALLOC)
|
||||
/* This lock is needed because tracemalloc_free() is called without
|
||||
the GIL held from PyMem_RawFree(). It cannot acquire the lock because it
|
||||
would introduce a deadlock in PyThreadState_DeleteCurrent(). */
|
||||
|
@ -164,7 +164,7 @@ tracemalloc_error(const char *format, ...)
|
|||
#endif
|
||||
|
||||
|
||||
#if defined(WITH_THREAD) && defined(TRACE_RAW_MALLOC)
|
||||
#if defined(TRACE_RAW_MALLOC)
|
||||
#define REENTRANT_THREADLOCAL
|
||||
|
||||
/* If your OS does not provide native thread local storage, you can implement
|
||||
|
@ -212,8 +212,7 @@ set_reentrant(int reentrant)
|
|||
|
||||
#else
|
||||
|
||||
/* WITH_THREAD not defined: Python compiled without threads,
|
||||
or TRACE_RAW_MALLOC not defined: variable protected by the GIL */
|
||||
/* TRACE_RAW_MALLOC not defined: variable protected by the GIL */
|
||||
static int tracemalloc_reentrant = 0;
|
||||
|
||||
static int
|
||||
|
@ -455,11 +454,7 @@ traceback_get_frames(traceback_t *traceback)
|
|||
PyThreadState *tstate;
|
||||
PyFrameObject *pyframe;
|
||||
|
||||
#ifdef WITH_THREAD
|
||||
tstate = PyGILState_GetThisThreadState();
|
||||
#else
|
||||
tstate = PyThreadState_Get();
|
||||
#endif
|
||||
if (tstate == NULL) {
|
||||
#ifdef TRACE_DEBUG
|
||||
tracemalloc_error("failed to get the current thread state");
|
||||
|
@ -483,9 +478,7 @@ traceback_new(void)
|
|||
traceback_t *traceback;
|
||||
_Py_hashtable_entry_t *entry;
|
||||
|
||||
#ifdef WITH_THREAD
|
||||
assert(PyGILState_Check());
|
||||
#endif
|
||||
|
||||
/* get frames */
|
||||
traceback = tracemalloc_traceback;
|
||||
|
@ -848,9 +841,7 @@ tracemalloc_realloc_gil(void *ctx, void *ptr, size_t new_size)
|
|||
static void*
|
||||
tracemalloc_raw_alloc(int use_calloc, void *ctx, size_t nelem, size_t elsize)
|
||||
{
|
||||
#ifdef WITH_THREAD
|
||||
PyGILState_STATE gil_state;
|
||||
#endif
|
||||
void *ptr;
|
||||
|
||||
if (get_reentrant()) {
|
||||
|
@ -866,13 +857,9 @@ tracemalloc_raw_alloc(int use_calloc, void *ctx, size_t nelem, size_t elsize)
|
|||
disabled. */
|
||||
set_reentrant(1);
|
||||
|
||||
#ifdef WITH_THREAD
|
||||
gil_state = PyGILState_Ensure();
|
||||
ptr = tracemalloc_alloc(use_calloc, ctx, nelem, elsize);
|
||||
PyGILState_Release(gil_state);
|
||||
#else
|
||||
ptr = tracemalloc_alloc(use_calloc, ctx, nelem, elsize);
|
||||
#endif
|
||||
|
||||
set_reentrant(0);
|
||||
return ptr;
|
||||
|
@ -896,9 +883,7 @@ tracemalloc_raw_calloc(void *ctx, size_t nelem, size_t elsize)
|
|||
static void*
|
||||
tracemalloc_raw_realloc(void *ctx, void *ptr, size_t new_size)
|
||||
{
|
||||
#ifdef WITH_THREAD
|
||||
PyGILState_STATE gil_state;
|
||||
#endif
|
||||
void *ptr2;
|
||||
|
||||
if (get_reentrant()) {
|
||||
|
@ -920,13 +905,9 @@ tracemalloc_raw_realloc(void *ctx, void *ptr, size_t new_size)
|
|||
not disabled. */
|
||||
set_reentrant(1);
|
||||
|
||||
#ifdef WITH_THREAD
|
||||
gil_state = PyGILState_Ensure();
|
||||
ptr2 = tracemalloc_realloc(ctx, ptr, new_size);
|
||||
PyGILState_Release(gil_state);
|
||||
#else
|
||||
ptr2 = tracemalloc_realloc(ctx, ptr, new_size);
|
||||
#endif
|
||||
|
||||
set_reentrant(0);
|
||||
return ptr2;
|
||||
|
@ -962,10 +943,8 @@ traceback_free_traceback(_Py_hashtable_t *ht, _Py_hashtable_entry_t *entry,
|
|||
static void
|
||||
tracemalloc_clear_traces(void)
|
||||
{
|
||||
#ifdef WITH_THREAD
|
||||
/* The GIL protects variables againt concurrent access */
|
||||
assert(PyGILState_Check());
|
||||
#endif
|
||||
|
||||
TABLES_LOCK();
|
||||
_Py_hashtable_clear(tracemalloc_traces);
|
||||
|
@ -1007,7 +986,7 @@ tracemalloc_init(void)
|
|||
}
|
||||
#endif
|
||||
|
||||
#if defined(WITH_THREAD) && defined(TRACE_RAW_MALLOC)
|
||||
#if defined(TRACE_RAW_MALLOC)
|
||||
if (tables_lock == NULL) {
|
||||
tables_lock = PyThread_allocate_lock();
|
||||
if (tables_lock == NULL) {
|
||||
|
@ -1074,7 +1053,7 @@ tracemalloc_deinit(void)
|
|||
_Py_hashtable_destroy(tracemalloc_filenames);
|
||||
_Py_hashtable_destroy(tracemalloc_traces);
|
||||
|
||||
#if defined(WITH_THREAD) && defined(TRACE_RAW_MALLOC)
|
||||
#if defined(TRACE_RAW_MALLOC)
|
||||
if (tables_lock != NULL) {
|
||||
PyThread_free_lock(tables_lock);
|
||||
tables_lock = NULL;
|
||||
|
@ -1723,9 +1702,7 @@ _PyTraceMalloc_Init(void)
|
|||
char *p;
|
||||
int nframe;
|
||||
|
||||
#ifdef WITH_THREAD
|
||||
assert(PyGILState_Check());
|
||||
#endif
|
||||
|
||||
if ((p = Py_GETENV("PYTHONTRACEMALLOC")) && *p != '\0') {
|
||||
char *endptr = p;
|
||||
|
@ -1778,9 +1755,7 @@ _PyTraceMalloc_Init(void)
|
|||
void
|
||||
_PyTraceMalloc_Fini(void)
|
||||
{
|
||||
#ifdef WITH_THREAD
|
||||
assert(PyGILState_Check());
|
||||
#endif
|
||||
tracemalloc_deinit();
|
||||
}
|
||||
|
||||
|
@ -1789,26 +1764,20 @@ PyTraceMalloc_Track(unsigned int domain, uintptr_t ptr,
|
|||
size_t size)
|
||||
{
|
||||
int res;
|
||||
#ifdef WITH_THREAD
|
||||
PyGILState_STATE gil_state;
|
||||
#endif
|
||||
|
||||
if (!tracemalloc_config.tracing) {
|
||||
/* tracemalloc is not tracing: do nothing */
|
||||
return -2;
|
||||
}
|
||||
|
||||
#ifdef WITH_THREAD
|
||||
gil_state = PyGILState_Ensure();
|
||||
#endif
|
||||
|
||||
TABLES_LOCK();
|
||||
res = tracemalloc_add_trace(domain, ptr, size);
|
||||
TABLES_UNLOCK();
|
||||
|
||||
#ifdef WITH_THREAD
|
||||
PyGILState_Release(gil_state);
|
||||
#endif
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue