10000 gh-81057: Move faulthandler Globals to _PyRuntimeState by ericsnowcurrently · Pull Request #100152 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-81057: Move faulthandler Globals to _PyRuntimeState #100152

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move thread to _PyRuntimeState.
  • Loading branch information
ericsnowcurrently committed Dec 12, 2022
commit b280eeebfad8acfa00ee70a1448dfa45c517ac54
18 changes: 17 additions & 1 deletion Include/internal/pycore_faulthandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ extern "C" {


struct _faulthandler_runtime_state {
int _not_used;
struct {
int enabled;
PyObject *file;
Expand All @@ -21,6 +20,23 @@ struct _faulthandler_runtime_state {
void *exc_handler;
#endif
} fatal_error;

struct {
PyObject *file;
int fd;
PY_TIMEOUT_T timeout_us; /* timeout in microseconds */
int repeat;
PyInterpreterState *interp;
int exit;
char *header;
size_t header_len;
/* The main thread always holds this lock. It is only released when
faulthandler_thread() is interrupted before this thread exits, or at
Python exit. */
PyThread_type_lock cancel_event;
/* released by child thread when joined */
PyThread_type_lock running;
} thread;
};

#define _faulthandler_runtime_state_INIT \
Expand Down
24 changes: 4 additions & 20 deletions Modules/faulthandler.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,23 +73,7 @@ typedef struct {
} fault_handler_t;

#define fatal_error _PyRuntime.faulthandler.fatal_error

static struct {
PyObject *file;
int fd;
PY_TIMEOUT_T timeout_us; /* timeout in microseconds */
int repeat;
PyInterpreterState *interp;
int exit;
char *header;
size_t header_len;
/* The main thread always holds this lock. It is only released when
faulthandler_thread() is interrupted before this thread exits, or at
Python exit. */
PyThread_type_lock cancel_event;
/* released by child thread when joined */
PyThread_type_lock running;
} thread;
#define thread _PyRuntime.faulthandler.thread

#ifdef FAULTHANDLER_USER
typedef struct {
Expand Down Expand Up @@ -1085,7 +1069,7 @@ faulthandler_fatal_error_thread(void *plock)
static PyObject *
faulthandler_fatal_error_c_thread(PyObject *self, PyObject *args)
{
long thread;
long tid;
PyThread_type_lock lock;

faulthandler_suppress_crash_report();
Expand All @@ -1096,8 +1080,8 @@ faulthandler_fatal_error_c_thread(PyObject *self, PyObject *args)

PyThread_acquire_lock(lock, WAIT_LOCK);

thread = PyThread_start_new_thread(faulthandler_fatal_error_thread, lock);
if (thread == -1) {
tid = PyThread_start_new_thread(faulthandler_fatal_error_thread, lock);
if (tid == -1) {
PyThread_free_lock(lock);
PyErr_SetString(PyExc_RuntimeError, "unable to start the thread");
return NULL;
Expand Down
1 change: 0 additions & 1 deletion Tools/c-analyzer/cpython/globals-to-fix.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,6 @@ Modules/itertoolsmodule.c - ziplongest_type -
##-----------------------
## state

Modules/faulthandler.c - thread -
Modules/faulthandler.c - user_signals -
Modules/faulthandler.c - stack -
Modules/faulthandler.c - old_stack -
Expand Down
0