[Python-checkins] bpo-36475: Make PyThread_exit_thread with _Py_NO_RETURN (GH-13068)
Victor Stinner
webhook-mailer at python.org
Sat May 4 11:48:08 EDT 2019
https://github.com/python/cpython/commit/c664b342a47e4b4650706d07e3e40a295e3a4407
commit: c664b342a47e4b4650706d07e3e40a295e3a4407
branch: master
author: Victor Stinner <vstinner at redhat.com>
committer: GitHub <noreply at github.com>
date: 2019-05-04T11:48:05-04:00
summary:
bpo-36475: Make PyThread_exit_thread with _Py_NO_RETURN (GH-13068)
files:
M Include/pyerrors.h
M Include/pyport.h
M Include/pythread.h
M Python/ceval.c
M Python/thread_nt.h
M Python/thread_pthread.h
diff --git a/Include/pyerrors.h b/Include/pyerrors.h
index 5c6751868df4..94af3cb3420e 100644
--- a/Include/pyerrors.h
+++ b/Include/pyerrors.h
@@ -21,17 +21,6 @@ PyAPI_FUNC(void) PyErr_GetExcInfo(PyObject **, PyObject **, PyObject **);
PyAPI_FUNC(void) PyErr_SetExcInfo(PyObject *, PyObject *, PyObject *);
#endif
-#if defined(__clang__) || \
- (defined(__GNUC__) && \
- ((__GNUC__ >= 3) || \
- (__GNUC__ == 2) && (__GNUC_MINOR__ >= 5)))
-# define _Py_NO_RETURN __attribute__((__noreturn__))
-#elif defined(_MSC_VER)
-# define _Py_NO_RETURN __declspec(noreturn)
-#else
-# define _Py_NO_RETURN
-#endif
-
/* Defined in Python/pylifecycle.c */
PyAPI_FUNC(void) _Py_NO_RETURN Py_FatalError(const char *message);
diff --git a/Include/pyport.h b/Include/pyport.h
index 97fb5e59f9e5..ab88a9ac5c52 100644
--- a/Include/pyport.h
+++ b/Include/pyport.h
@@ -829,4 +829,18 @@ extern _invalid_parameter_handler _Py_silent_invalid_parameter_handler;
# define _Py_FORCE_UTF8_FS_ENCODING
#endif
+/* Mark a function which cannot return. Example:
+
+ PyAPI_FUNC(void) _Py_NO_RETURN PyThread_exit_thread(void); */
+#if defined(__clang__) || \
+ (defined(__GNUC__) && \
+ ((__GNUC__ >= 3) || \
+ (__GNUC__ == 2) && (__GNUC_MINOR__ >= 5)))
+# define _Py_NO_RETURN __attribute__((__noreturn__))
+#elif defined(_MSC_VER)
+# define _Py_NO_RETURN __declspec(noreturn)
+#else
+# define _Py_NO_RETURN
+#endif
+
#endif /* Py_PYPORT_H */
diff --git a/Include/pythread.h b/Include/pythread.h
index eb61033b2d90..bc1d92cd1ff1 100644
--- a/Include/pythread.h
+++ b/Include/pythread.h
@@ -23,7 +23,7 @@ typedef enum PyLockStatus {
PyAPI_FUNC(void) PyThread_init_thread(void);
PyAPI_FUNC(unsigned long) PyThread_start_new_thread(void (*)(void *), void *);
-PyAPI_FUNC(void) PyThread_exit_thread(void);
+PyAPI_FUNC(void) _Py_NO_RETURN PyThread_exit_thread(void);
PyAPI_FUNC(unsigned long) PyThread_get_thread_ident(void);
PyAPI_FUNC(PyThread_type_lock) PyThread_allocate_lock(void);
diff --git a/Python/ceval.c b/Python/ceval.c
index 8ae273e0820d..e616a3f53989 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -211,7 +211,6 @@ exit_thread_if_finalizing(PyThreadState *tstate)
if (_Py_IsFinalizing() && !_Py_CURRENTLY_FINALIZING(tstate)) {
drop_gil(tstate);
PyThread_exit_thread();
- Py_UNREACHABLE();
}
}
diff --git a/Python/thread_nt.h b/Python/thread_nt.h
index fdb192b7d77a..5e00c3511460 100644
--- a/Python/thread_nt.h
+++ b/Python/thread_nt.h
@@ -227,7 +227,7 @@ PyThread_get_thread_ident(void)
return GetCurrentThreadId();
}
-void
+void _Py_NO_RETURN
PyThread_exit_thread(void)
{
dprintf(("%lu: PyThread_exit_thread called\n", PyThread_get_thread_ident()));
diff --git a/Python/thread_pthread.h b/Python/thread_pthread.h
index 25f58d9446d8..1f4f36d52d55 100644
--- a/Python/thread_pthread.h
+++ b/Python/thread_pthread.h
@@ -302,7 +302,7 @@ PyThread_get_thread_ident(void)
return (unsigned long) threadid;
}
-void
+void _Py_NO_RETURN
PyThread_exit_thread(void)
{
dprintf(("PyThread_exit_thread called\n"));
More information about the Python-checkins
mailing list