Python-checkins
Threads by month
- ----- 2025 -----
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2003 -----
- December
- November
- October
- September
- August
November 2018
- 2 participants
- 507 discussions
![](https://secure.gravatar.com/avatar/cc7737cd64a84f1b5c61a160798e97ee.jpg?s=120&d=mm&r=g)
bpo-35128: Fix spacing issues in warning.warn() messages. (GH-10268)
by Serhiy Storchaka Nov. 1, 2018
by Serhiy Storchaka Nov. 1, 2018
Nov. 1, 2018
https://github.com/python/cpython/commit/4b5e62dbb22a3593e0db266c12f805b727…
commit: 4b5e62dbb22a3593e0db266c12f805b727a42b00
branch: master
author: Pablo Aguiar <scorphus(a)gmail.com>
committer: Serhiy Storchaka <storchaka(a)gmail.com>
date: 2018-11-01T12:33:35+02:00
summary:
bpo-35128: Fix spacing issues in warning.warn() messages. (GH-10268)
files:
M Lib/bz2.py
M Lib/ftplib.py
M Lib/imaplib.py
M Lib/poplib.py
M Lib/smtplib.py
diff --git a/Lib/bz2.py b/Lib/bz2.py
index 3ab099147190..21e8ff49c67b 100644
--- a/Lib/bz2.py
+++ b/Lib/bz2.py
@@ -66,7 +66,7 @@ def __init__(self, filename, mode="r", buffering=_sentinel, compresslevel=9):
self._mode = _MODE_CLOSED
if buffering is not _sentinel:
- warnings.warn("Use of 'buffering' argument is deprecated and ignored"
+ warnings.warn("Use of 'buffering' argument is deprecated and ignored "
"since Python 3.0.",
DeprecationWarning,
stacklevel=2)
diff --git a/Lib/ftplib.py b/Lib/ftplib.py
index 05840d492360..9611282ecacb 100644
--- a/Lib/ftplib.py
+++ b/Lib/ftplib.py
@@ -732,7 +732,7 @@ def __init__(self, host='', user='', passwd='', acct='', keyfile=None,
"exclusive")
if keyfile is not None or certfile is not None:
import warnings
- warnings.warn("keyfile and certfile are deprecated, use a"
+ warnings.warn("keyfile and certfile are deprecated, use a "
"custom context instead", DeprecationWarning, 2)
self.keyfile = keyfile
self.certfile = certfile
diff --git a/Lib/imaplib.py b/Lib/imaplib.py
index e451413acf5a..dd237f7704ac 100644
--- a/Lib/imaplib.py
+++ b/Lib/imaplib.py
@@ -1277,7 +1277,7 @@ def __init__(self, host='', port=IMAP4_SSL_PORT, keyfile=None,
"exclusive")
if keyfile is not None or certfile is not None:
import warnings
- warnings.warn("keyfile and certfile are deprecated, use a"
+ warnings.warn("keyfile and certfile are deprecated, use a "
"custom ssl_context instead", DeprecationWarning, 2)
self.keyfile = keyfile
self.certfile = certfile
diff --git a/Lib/poplib.py b/Lib/poplib.py
index d8a62c034327..9796f0d2f9c5 100644
--- a/Lib/poplib.py
+++ b/Lib/poplib.py
@@ -436,7 +436,7 @@ def __init__(self, host, port=POP3_SSL_PORT, keyfile=None, certfile=None,
"exclusive")
if keyfile is not None or certfile is not None:
import warnings
- warnings.warn("keyfile and certfile are deprecated, use a"
+ warnings.warn("keyfile and certfile are deprecated, use a "
"custom context instead", DeprecationWarning, 2)
self.keyfile = keyfile
self.certfile = certfile
diff --git a/Lib/smtplib.py b/Lib/smtplib.py
index acfc3586e1c0..3c5ac75ab8ab 100755
--- a/Lib/smtplib.py
+++ b/Lib/smtplib.py
@@ -764,7 +764,7 @@ def starttls(self, keyfile=None, certfile=None, context=None):
"exclusive")
if keyfile is not None or certfile is not None:
import warnings
- warnings.warn("keyfile and certfile are deprecated, use a"
+ warnings.warn("keyfile and certfile are deprecated, use a "
"custom context instead", DeprecationWarning, 2)
if context is None:
context = ssl._create_stdlib_context(certfile=certfile,
@@ -1021,7 +1021,7 @@ def __init__(self, host='', port=0, local_hostname=None,
"exclusive")
if keyfile is not None or certfile is not None:
import warnings
- warnings.warn("keyfile and certfile are deprecated, use a"
+ warnings.warn("keyfile and certfile are deprecated, use a "
"custom context instead", DeprecationWarning, 2)
self.keyfile = keyfile
self.certfile = certfile
1
0
results for 4243df51fe43 on branch "default"
--------------------------------------------
test_collections leaked [-7, 1, 7] memory blocks, sum=1
test_functools leaked [0, 3, 1] memory blocks, sum=4
test_multiprocessing_fork leaked [-2, 2, 0] memory blocks, sum=0
test_multiprocessing_forkserver leaked [2, 0, 0] memory blocks, sum=2
test_multiprocessing_spawn leaked [-1, -1, 2] memory blocks, sum=0
Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/psf-users/antoine/refleaks/reflogdDGf3b', '--timeout', '7200']
1
0
![](https://secure.gravatar.com/avatar/cc7737cd64a84f1b5c61a160798e97ee.jpg?s=120&d=mm&r=g)
Nov. 1, 2018
https://github.com/python/cpython/commit/a1c249c40517917d2e0971d55aea8d14a4…
commit: a1c249c40517917d2e0971d55aea8d14a44b2cc8
branch: master
author: Victor Stinner <vstinner(a)redhat.com>
committer: GitHub <noreply(a)github.com>
date: 2018-11-01T03:15:58+01:00
summary:
bpo-35081: And pycore_lifecycle.h and pycore_pathconfig.h (GH-10273)
* And pycore_lifecycle.h and pycore_pathconfig.h headers to
Include/internal/
* Move Py_BUILD_CORE specific code from coreconfig.h and
pylifecycle.h to pycore_pathconfig.h and pycore_lifecycle.h
* Move _Py_wstrlist_XXX() definitions and _PyPathConfig code
from pycore_state.h to pycore_pathconfig.h
* Move "Init" and "Fini" function definitions from pylifecycle.c to
pycore_lifecycle.h.
files:
A Include/internal/pycore_lifecycle.h
A Include/internal/pycore_pathconfig.h
M Include/coreconfig.h
M Include/internal/pycore_state.h
M Include/pylifecycle.h
M Makefile.pre.in
M Modules/_testcapimodule.c
M Modules/getpath.c
M Modules/main.c
M PCbuild/pythoncore.vcxproj
M PCbuild/pythoncore.vcxproj.filters
M Programs/python.c
M Python/coreconfig.c
M Python/import.c
M Python/pathconfig.c
M Python/pylifecycle.c
M Python/sysmodule.c
diff --git a/Include/coreconfig.h b/Include/coreconfig.h
index 83c4e7ee4dbe..ff7b684a1fa5 100644
--- a/Include/coreconfig.h
+++ b/Include/coreconfig.h
@@ -361,17 +361,6 @@ PyAPI_FUNC(int) _PyCoreConfig_GetEnvDup(
#endif
-#ifdef Py_BUILD_CORE
-PyAPI_FUNC(int) _Py_SetFileSystemEncoding(
- const char *encoding,
- const char *errors);
-PyAPI_FUNC(void) _Py_ClearFileSystemEncoding(void);
-#endif
-
-#ifndef Py_LIMITED_API
-PyAPI_FUNC(PyObject*) _Py_wstrlist_as_pylist(int len, wchar_t **list);
-#endif
-
#ifdef __cplusplus
}
diff --git a/Include/internal/pycore_lifecycle.h b/Include/internal/pycore_lifecycle.h
new file mode 100644
index 000000000000..cf36440eabcf
--- /dev/null
+++ b/Include/internal/pycore_lifecycle.h
@@ -0,0 +1,50 @@
+#ifndef Py_INTERNAL_LIFECYCLE_H
+#define Py_INTERNAL_LIFECYCLE_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef Py_BUILD_CORE
+# error "Py_BUILD_CORE must be defined to include this header"
+#endif
+
+PyAPI_FUNC(int) _Py_UnixMain(int argc, char **argv);
+
+PyAPI_FUNC(int) _Py_SetFileSystemEncoding(
+ const char *encoding,
+ const char *errors);
+PyAPI_FUNC(void) _Py_ClearFileSystemEncoding(void);
+
+PyAPI_FUNC(void) _Py_ClearStandardStreamEncoding(void);
+
+PyAPI_FUNC(int) _Py_IsLocaleCoercionTarget(const char *ctype_loc);
+
+extern int _PyUnicode_Init(void);
+extern int _PyStructSequence_Init(void);
+extern int _PyLong_Init(void);
+extern _PyInitError _PyFaulthandler_Init(int enable);
+extern int _PyTraceMalloc_Init(int enable);
+
+extern void _Py_ReadyTypes(void);
+
+PyAPI_FUNC(void) _PyExc_Fini(void);
+PyAPI_FUNC(void) _PyImport_Fini(void);
+PyAPI_FUNC(void) _PyImport_Fini2(void);
+PyAPI_FUNC(void) _PyGC_Fini(void);
+PyAPI_FUNC(void) _PyType_Fini(void);
+PyAPI_FUNC(void) _Py_HashRandomization_Fini(void);
+extern void _PyUnicode_Fini(void);
+extern void PyLong_Fini(void);
+extern void _PyFaulthandler_Fini(void);
+extern void _PyHash_Fini(void);
+extern int _PyTraceMalloc_Fini(void);
+
+extern void _PyGILState_Init(PyInterpreterState *, PyThreadState *);
+extern void _PyGILState_Fini(void);
+
+PyAPI_FUNC(void) _PyGC_DumpShutdownStats(void);
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* !Py_INTERNAL_LIFECYCLE_H */
diff --git a/Include/internal/pycore_pathconfig.h b/Include/internal/pycore_pathconfig.h
new file mode 100644
index 000000000000..395df498a0dc
--- /dev/null
+++ b/Include/internal/pycore_pathconfig.h
@@ -0,0 +1,68 @@
+#ifndef Py_INTERNAL_PATHCONFIG_H
+#define Py_INTERNAL_PATHCONFIG_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+PyAPI_FUNC(void) _Py_wstrlist_clear(
+ int len,
+ wchar_t **list);
+PyAPI_FUNC(wchar_t**) _Py_wstrlist_copy(
+ int len,
+ wchar_t **list);
+PyAPI_FUNC(_PyInitError) _Py_wstrlist_append(
+ int *len,
+ wchar_t ***list,
+ const wchar_t *str);
+PyAPI_FUNC(PyObject*) _Py_wstrlist_as_pylist(
+ int len,
+ wchar_t **list);
+
+typedef struct _PyPathConfig {
+ /* Full path to the Python program */
+ wchar_t *program_full_path;
+ wchar_t *prefix;
+#ifdef MS_WINDOWS
+ wchar_t *dll_path;
+#else
+ wchar_t *exec_prefix;
+#endif
+ /* Set by Py_SetPath(), or computed by _PyPathConfig_Init() */
+ wchar_t *module_search_path;
+ /* Python program name */
+ wchar_t *program_name;
+ /* Set by Py_SetPythonHome() or PYTHONHOME environment variable */
+ wchar_t *home;
+ /* isolated and site_import are used to set Py_IsolatedFlag and
+ Py_NoSiteFlag flags on Windows in read_pth_file(). These fields
+ are ignored when their value are equal to -1 (unset). */
+ int isolated;
+ int site_import;
+} _PyPathConfig;
+
+#define _PyPathConfig_INIT \
+ {.module_search_path = NULL, \
+ .isolated = -1, \
+ .site_import = -1}
+/* Note: _PyPathConfig_INIT sets other fields to 0/NULL */
+
+PyAPI_DATA(_PyPathConfig) _Py_path_config;
+
+PyAPI_FUNC(void) _PyPathConfig_ClearGlobal(void);
+PyAPI_FUNC(_PyInitError) _PyPathConfig_SetGlobal(
+ const struct _PyPathConfig *config);
+
+PyAPI_FUNC(_PyInitError) _PyPathConfig_Calculate_impl(
+ _PyPathConfig *config,
+ const _PyCoreConfig *core_config);
+PyAPI_FUNC(PyObject*) _PyPathConfig_ComputeArgv0(int argc, wchar_t **argv);
+PyAPI_FUNC(int) _Py_FindEnvConfigValue(
+ FILE *env_file,
+ const wchar_t *key,
+ wchar_t *value,
+ size_t value_size);
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* !Py_INTERNAL_PATHCONFIG_H */
diff --git a/Include/internal/pycore_state.h b/Include/internal/pycore_state.h
index 9a084f7f4d84..6285ecf5f5dc 100644
--- a/Include/internal/pycore_state.h
+++ b/Include/internal/pycore_state.h
@@ -11,8 +11,9 @@ extern "C" {
#include "pystate.h"
#include "pythread.h"
-#include "pycore_mem.h"
#include "pycore_ceval.h"
+#include "pycore_mem.h"
+#include "pycore_pathconfig.h"
#include "pycore_warnings.h"
@@ -40,52 +41,6 @@ struct _gilstate_runtime_state {
#define _PyGILState_check_enabled _PyRuntime.gilstate.check_enabled
-typedef struct _PyPathConfig {
- /* Full path to the Python program */
- wchar_t *program_full_path;
- wchar_t *prefix;
-#ifdef MS_WINDOWS
- wchar_t *dll_path;
-#else
- wchar_t *exec_prefix;
-#endif
- /* Set by Py_SetPath(), or computed by _PyPathConfig_Init() */
- wchar_t *module_search_path;
- /* Python program name */
- wchar_t *program_name;
- /* Set by Py_SetPythonHome() or PYTHONHOME environment variable */
- wchar_t *home;
- /* isolated and site_import are used to set Py_IsolatedFlag and
- Py_NoSiteFlag flags on Windows in read_pth_file(). These fields
- are ignored when their value are equal to -1 (unset). */
- int isolated;
- int site_import;
-} _PyPathConfig;
-
-#define _PyPathConfig_INIT \
- {.module_search_path = NULL, \
- .isolated = -1, \
- .site_import = -1}
-/* Note: _PyPathConfig_INIT sets other fields to 0/NULL */
-
-PyAPI_DATA(_PyPathConfig) _Py_path_config;
-
-PyAPI_FUNC(_PyInitError) _PyPathConfig_Calculate_impl(
- _PyPathConfig *config,
- const _PyCoreConfig *core_config);
-PyAPI_FUNC(void) _PyPathConfig_ClearGlobal(void);
-
-PyAPI_FUNC(void) _Py_wstrlist_clear(
- int len,
- wchar_t **list);
-PyAPI_FUNC(wchar_t**) _Py_wstrlist_copy(
- int len,
- wchar_t **list);
-PyAPI_FUNC(_PyInitError) _Py_wstrlist_append(
- int *len,
- wchar_t ***list,
- const wchar_t *str);
-
/* interpreter state */
PyAPI_FUNC(PyInterpreterState *) _PyInterpreterState_LookUpID(PY_INT64_T);
diff --git a/Include/pylifecycle.h b/Include/pylifecycle.h
index 04e672e96e17..ca1f24f2a174 100644
--- a/Include/pylifecycle.h
+++ b/Include/pylifecycle.h
@@ -20,9 +20,6 @@ PyAPI_FUNC(wchar_t *) Py_GetPythonHome(void);
PyAPI_FUNC(int) Py_SetStandardStreamEncoding(const char *encoding,
const char *errors);
#endif
-#ifdef Py_BUILD_CORE
-PyAPI_FUNC(void) _Py_ClearStandardStreamEncoding(void);
-#endif
#ifndef Py_LIMITED_API
@@ -82,27 +79,12 @@ PyAPI_FUNC(int) Py_FdIsInteractive(FILE *, const char *);
/* Bootstrap __main__ (defined in Modules/main.c) */
PyAPI_FUNC(int) Py_Main(int argc, wchar_t **argv);
-#ifdef Py_BUILD_CORE
-PyAPI_FUNC(int) _Py_UnixMain(int argc, char **argv);
-#endif
/* In getpath.c */
PyAPI_FUNC(wchar_t *) Py_GetProgramFullPath(void);
PyAPI_FUNC(wchar_t *) Py_GetPrefix(void);
PyAPI_FUNC(wchar_t *) Py_GetExecPrefix(void);
PyAPI_FUNC(wchar_t *) Py_GetPath(void);
-#ifdef Py_BUILD_CORE
-struct _PyPathConfig;
-
-PyAPI_FUNC(_PyInitError) _PyPathConfig_SetGlobal(
- const struct _PyPathConfig *config);
-PyAPI_FUNC(PyObject*) _PyPathConfig_ComputeArgv0(int argc, wchar_t **argv);
-PyAPI_FUNC(int) _Py_FindEnvConfigValue(
- FILE *env_file,
- const wchar_t *key,
- wchar_t *value,
- size_t value_size);
-#endif
PyAPI_FUNC(void) Py_SetPath(const wchar_t *);
#ifdef MS_WINDOWS
int _Py_CheckPython3(void);
@@ -134,16 +116,6 @@ PyAPI_FUNC(_PyInitError) _Py_HashRandomization_Init(const _PyCoreConfig *);
/* Various internal finalizers */
-#ifdef Py_BUILD_CORE
-PyAPI_FUNC(void) _PyExc_Fini(void);
-PyAPI_FUNC(void) _PyImport_Fini(void);
-PyAPI_FUNC(void) _PyImport_Fini2(void);
-PyAPI_FUNC(void) _PyGC_DumpShutdownStats(void);
-PyAPI_FUNC(void) _PyGC_Fini(void);
-PyAPI_FUNC(void) _PyType_Fini(void);
-PyAPI_FUNC(void) _Py_HashRandomization_Fini(void);
-#endif /* Py_BUILD_CORE */
-
#ifndef Py_LIMITED_API
PyAPI_FUNC(void) PyMethod_Fini(void);
PyAPI_FUNC(void) PyFrame_Fini(void);
@@ -179,9 +151,6 @@ PyAPI_FUNC(void) _Py_CoerceLegacyLocale(int warn);
PyAPI_FUNC(int) _Py_LegacyLocaleDetected(void);
PyAPI_FUNC(char *) _Py_SetLocaleFromEnv(int category);
#endif
-#ifdef Py_BUILD_CORE
-PyAPI_FUNC(int) _Py_IsLocaleCoercionTarget(const char *ctype_loc);
-#endif
#ifdef __cplusplus
}
diff --git a/Makefile.pre.in b/Makefile.pre.in
index fc8b1e4e7334..15f3687be5b1 100644
--- a/Makefile.pre.in
+++ b/Makefile.pre.in
@@ -1030,7 +1030,9 @@ PYTHON_HEADERS= \
$(srcdir)/Include/internal/pycore_context.h \
$(srcdir)/Include/internal/pycore_getopt.h \
$(srcdir)/Include/internal/pycore_gil.h \
+ $(srcdir)/Include/internal/pycore_lifecycle.h \
$(srcdir)/Include/internal/pycore_mem.h \
+ $(srcdir)/Include/internal/pycore_pathconfig.h \
$(srcdir)/Include/internal/pycore_state.h \
$(srcdir)/Include/internal/pycore_warnings.h \
$(DTRACE_HEADERS)
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index 018af4a13707..e2deb2603da8 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -8,10 +8,12 @@
#define PY_SSIZE_T_CLEAN
#include "Python.h"
-#include <float.h>
-#include "structmember.h"
#include "datetime.h"
#include "marshal.h"
+#include "pycore_pathconfig.h"
+#include "pythread.h"
+#include "structmember.h"
+#include <float.h>
#include <signal.h>
#ifdef MS_WINDOWS
@@ -22,7 +24,6 @@
#include <sys/wait.h> /* For W_STOPCODE */
#endif
-#include "pythread.h"
static PyObject *TestError; /* set to exception object in init */
/* Raise TestError with test_name + ": " + msg, and return NULL. */
diff --git a/Modules/getpath.c b/Modules/getpath.c
index 53e5c2b889a6..0e210710ecf4 100644
--- a/Modules/getpath.c
+++ b/Modules/getpath.c
@@ -1,8 +1,9 @@
/* Return the initial module search path. */
#include "Python.h"
-#include "pycore_state.h"
#include "osdefs.h"
+#include "pycore_pathconfig.h"
+#include "pycore_state.h"
#include <sys/types.h>
#include <string.h>
diff --git a/Modules/main.c b/Modules/main.c
index 1918f4f9b8ff..c847d1acedb7 100644
--- a/Modules/main.c
+++ b/Modules/main.c
@@ -2,8 +2,10 @@
#include "Python.h"
#include "osdefs.h"
-#include "pycore_mem.h"
#include "pycore_getopt.h"
+#include "pycore_lifecycle.h"
+#include "pycore_mem.h"
+#include "pycore_pathconfig.h"
#include "pycore_state.h"
#include <locale.h>
diff --git a/PCbuild/pythoncore.vcxproj b/PCbuild/pythoncore.vcxproj
index 6becb8a3682c..460500cc2b1b 100644
--- a/PCbuild/pythoncore.vcxproj
+++ b/PCbuild/pythoncore.vcxproj
@@ -119,7 +119,9 @@
<ClInclude Include="..\Include\internal\pycore_getopt.h" />
<ClInclude Include="..\Include\internal\pycore_gil.h" />
<ClInclude Include="..\Include\internal\pycore_hamt.h" />
+ <ClInclude Include="..\Include\internal\pycore_lifecycle.h" />
<ClInclude Include="..\Include\internal\pycore_mem.h" />
+ <ClInclude Include="..\Include\internal\pycore_pathconfig.h" />
<ClInclude Include="..\Include\internal\pycore_state.h" />
<ClInclude Include="..\Include\internal\pycore_warnings.h" />
<ClInclude Include="..\Include\intrcheck.h" />
diff --git a/PCbuild/pythoncore.vcxproj.filters b/PCbuild/pythoncore.vcxproj.filters
index bc118c636cde..64fb77b867c4 100644
--- a/PCbuild/pythoncore.vcxproj.filters
+++ b/PCbuild/pythoncore.vcxproj.filters
@@ -156,9 +156,15 @@
<ClInclude Include="..\Include\internal\pycore_hamt.h">
<Filter>Include</Filter>
</ClInclude>
+ <ClInclude Include="..\Include\internal\pycore_lifecycle.h">
+ <Filter>Include</Filter>
+ </ClInclude>
<ClInclude Include="..\Include\internal\pycore_mem.h">
<Filter>Include</Filter>
</ClInclude>
+ <ClInclude Include="..\Include\internal\pycore_pathconfig.h">
+ <Filter>Include</Filter>
+ </ClInclude>
<ClInclude Include="..\Include\internal\pycore_state.h">
<Filter>Include</Filter>
</ClInclude>
diff --git a/Programs/python.c b/Programs/python.c
index 78e48f800c95..079bf9a2f039 100644
--- a/Programs/python.c
+++ b/Programs/python.c
@@ -1,6 +1,7 @@
/* Minimal main program -- everything is loaded from the library */
#include "Python.h"
+#include "pycore_lifecycle.h"
#ifdef MS_WINDOWS
int
diff --git a/Python/coreconfig.c b/Python/coreconfig.c
index ad14a8a457da..b21e9344cd16 100644
--- a/Python/coreconfig.c
+++ b/Python/coreconfig.c
@@ -1,5 +1,7 @@
#include "Python.h"
+#include "pycore_lifecycle.h"
#include "pycore_mem.h"
+#include "pycore_pathconfig.h"
#include "pycore_state.h"
#include <locale.h>
#ifdef HAVE_LANGINFO_H
diff --git a/Python/import.c b/Python/import.c
index 18cd29df7e93..67911ff0e41b 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -5,6 +5,7 @@
#include "Python-ast.h"
#undef Yield /* undefine macro conflicting with winbase.h */
#include "pycore_hash.h"
+#include "pycore_lifecycle.h"
#include "pycore_mem.h"
#include "pycore_state.h"
#include "errcode.h"
diff --git a/Python/pathconfig.c b/Python/pathconfig.c
index 04064159f86b..f8bcc2886a1c 100644
--- a/Python/pathconfig.c
+++ b/Python/pathconfig.c
@@ -3,6 +3,7 @@
#include "Python.h"
#include "osdefs.h"
#include "pycore_mem.h"
+#include "pycore_pathconfig.h"
#include "pycore_state.h"
#include <wchar.h>
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index 160f30ce6d6e..4c5cb5342917 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -6,7 +6,9 @@
#undef Yield /* undefine macro conflicting with winbase.h */
#include "pycore_context.h"
#include "pycore_hamt.h"
+#include "pycore_lifecycle.h"
#include "pycore_mem.h"
+#include "pycore_pathconfig.h"
#include "pycore_state.h"
#include "grammar.h"
#include "node.h"
@@ -62,20 +64,6 @@ static _PyInitError initsigs(void);
static void call_py_exitfuncs(PyInterpreterState *);
static void wait_for_thread_shutdown(void);
static void call_ll_exitfuncs(void);
-extern int _PyUnicode_Init(void);
-extern int _PyStructSequence_Init(void);
-extern void _PyUnicode_Fini(void);
-extern int _PyLong_Init(void);
-extern void PyLong_Fini(void);
-extern _PyInitError _PyFaulthandler_Init(int enable);
-extern void _PyFaulthandler_Fini(void);
-extern void _PyHash_Fini(void);
-extern int _PyTraceMalloc_Init(int enable);
-extern int _PyTraceMalloc_Fini(void);
-extern void _Py_ReadyTypes(void);
-
-extern void _PyGILState_Init(PyInterpreterState *, PyThreadState *);
-extern void _PyGILState_Fini(void);
_PyRuntimeState _PyRuntime = _PyRuntimeState_INIT;
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index 830f0a88e4fb..21647083d683 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -15,10 +15,12 @@ Data members:
*/
#include "Python.h"
-#include "pycore_mem.h"
-#include "pycore_state.h"
#include "code.h"
#include "frameobject.h"
+#include "pycore_lifecycle.h"
+#include "pycore_mem.h"
+#include "pycore_pathconfig.h"
+#include "pycore_state.h"
#include "pythread.h"
#include "osdefs.h"
1
0
![](https://secure.gravatar.com/avatar/cc7737cd64a84f1b5c61a160798e97ee.jpg?s=120&d=mm&r=g)
[2.7] bpo-32804: Include the context parameter in urlretrieve documentation (GH-10203)
by Xiang Zhang Nov. 1, 2018
by Xiang Zhang Nov. 1, 2018
Nov. 1, 2018
https://github.com/python/cpython/commit/aa39c1ab6de6d3fb0204741efdde9b7eed…
commit: aa39c1ab6de6d3fb0204741efdde9b7eed25b093
branch: 2.7
author: Lysandros Nikolaou <lisandrosnik(a)gmail.com>
committer: Xiang Zhang <angwerzx(a)126.com>
date: 2018-11-01T09:49:10+08:00
summary:
[2.7] bpo-32804: Include the context parameter in urlretrieve documentation (GH-10203)
files:
M Doc/library/urllib.rst
diff --git a/Doc/library/urllib.rst b/Doc/library/urllib.rst
index c24f4375e9d8..084d567e5e2e 100644
--- a/Doc/library/urllib.rst
+++ b/Doc/library/urllib.rst
@@ -147,14 +147,15 @@ High-level interface
:envvar:`no_proxy` environment variable.
.. versionchanged:: 2.7.9
- The *context* parameter was added. All the neccessary certificate and hostname checks are done by default.
+ The *context* parameter was added. All the neccessary certificate and hostname
+ checks are done by default.
.. deprecated:: 2.6
The :func:`urlopen` function has been removed in Python 3 in favor
of :func:`urllib2.urlopen`.
-.. function:: urlretrieve(url[, filename[, reporthook[, data]]])
+.. function:: urlretrieve(url[, filename[, reporthook[, data[, context]]]])
Copy a network object denoted by a URL to a local file, if necessary. If the URL
points to a local file, or a valid cached copy of the object exists, the object
@@ -179,6 +180,10 @@ High-level interface
:mimetype:`application/x-www-form-urlencoded` format; see the :func:`urlencode`
function below.
+ The *context* parameter may be set to a :class:`ssl.SSLContext` instance to
+ configure the SSL settings that are used if :func:`urlretrieve` makes a HTTPS
+ connection.
+
.. versionchanged:: 2.5
:func:`urlretrieve` will raise :exc:`ContentTooShortError` when it detects that
the amount of data available was less than the expected amount (which is the
@@ -196,6 +201,10 @@ High-level interface
the size of the data it has downloaded, and just returns it. In this case you
just have to assume that the download was successful.
+ .. versionchanged:: 2.7.9
+ The *context* parameter was added. All the neccessary certificate and hostname
+ checks are done by default.
+
.. data:: _urlopener
@@ -349,6 +358,10 @@ URL Opener objects
:class:`URLopener` objects will raise an :exc:`IOError` exception if the server
returns an error code.
+ .. versionchanged:: 2.7.9
+ The *context* parameter was added. All the neccessary certificate and hostname
+ checks are done by default.
+
.. method:: open(fullurl[, data])
Open *fullurl* using the appropriate protocol. This method sets up cache and
1
0
![](https://secure.gravatar.com/avatar/cc7737cd64a84f1b5c61a160798e97ee.jpg?s=120&d=mm&r=g)
Nov. 1, 2018
https://github.com/python/cpython/commit/e281f7d80ce2584a7e6a36acffb5a9cd79…
commit: e281f7d80ce2584a7e6a36acffb5a9cd796a0fe2
branch: master
author: Victor Stinner <vstinner(a)redhat.com>
committer: GitHub <noreply(a)github.com>
date: 2018-11-01T02:30:36+01:00
summary:
bpo-35081: Move accu.h to Include/internal/pycore_accu.h (GH-10271)
The accu.h header is no longer part of the Python C API: it has been
moved to the "internal" headers which are restricted to Python
itself.
Replace #include "accu.h" with #include "pycore_accu.h".
files:
A Include/internal/pycore_accu.h
D Include/accu.h
M Makefile.pre.in
M Modules/_io/stringio.c
M Modules/_json.c
M Objects/accu.c
M Objects/listobject.c
M Objects/tupleobject.c
M PCbuild/pythoncore.vcxproj
M PCbuild/pythoncore.vcxproj.filters
diff --git a/Include/accu.h b/Include/internal/pycore_accu.h
similarity index 88%
rename from Include/accu.h
rename to Include/internal/pycore_accu.h
index 3636ea6c98fd..ab1aad280346 100644
--- a/Include/accu.h
+++ b/Include/internal/pycore_accu.h
@@ -1,6 +1,9 @@
#ifndef Py_LIMITED_API
-#ifndef Py_ACCU_H
-#define Py_ACCU_H
+#ifndef Py_INTERNAL_ACCU_H
+#define Py_INTERNAL_ACCU_H
+#ifdef __cplusplus
+extern "C" {
+#endif
/*** This is a private API for use by the interpreter and the stdlib.
*** Its definition may be changed or removed at any moment.
@@ -12,10 +15,6 @@
* behaviour of using a naive repeated concatenation scheme.
*/
-#ifdef __cplusplus
-extern "C" {
-#endif
-
#undef small /* defined by some Windows headers */
typedef struct {
@@ -32,6 +31,5 @@ PyAPI_FUNC(void) _PyAccu_Destroy(_PyAccu *acc);
#ifdef __cplusplus
}
#endif
-
-#endif /* Py_ACCU_H */
-#endif /* Py_LIMITED_API */
+#endif /* !Py_INTERNAL_ACCU_H */
+#endif /* !Py_LIMITED_API */
diff --git a/Makefile.pre.in b/Makefile.pre.in
index 0336290dd841..fc8b1e4e7334 100644
--- a/Makefile.pre.in
+++ b/Makefile.pre.in
@@ -935,7 +935,6 @@ regen-typeslots:
PYTHON_HEADERS= \
$(srcdir)/Include/Python.h \
$(srcdir)/Include/abstract.h \
- $(srcdir)/Include/accu.h \
$(srcdir)/Include/asdl.h \
$(srcdir)/Include/ast.h \
$(srcdir)/Include/bltinmodule.h \
@@ -1025,6 +1024,7 @@ PYTHON_HEADERS= \
pyconfig.h \
$(PARSER_HEADERS) \
$(srcdir)/Include/Python-ast.h \
+ $(srcdir)/Include/internal/pycore_accu.h \
$(srcdir)/Include/internal/pycore_atomic.h \
$(srcdir)/Include/internal/pycore_ceval.h \
$(srcdir)/Include/internal/pycore_context.h \
diff --git a/Modules/_io/stringio.c b/Modules/_io/stringio.c
index 5a03715fbde0..793fa1ee150b 100644
--- a/Modules/_io/stringio.c
+++ b/Modules/_io/stringio.c
@@ -1,7 +1,7 @@
#define PY_SSIZE_T_CLEAN
#include "Python.h"
#include "structmember.h"
-#include "accu.h"
+#include "pycore_accu.h"
#include "_iomodule.h"
/* Implementation note: the buffer is always at least one character longer
diff --git a/Modules/_json.c b/Modules/_json.c
index ac6e017a4eaf..53e1e88fa4bf 100644
--- a/Modules/_json.c
+++ b/Modules/_json.c
@@ -7,7 +7,7 @@
#include "Python.h"
#include "structmember.h"
-#include "accu.h"
+#include "pycore_accu.h"
#ifdef __GNUC__
#define UNUSED __attribute__((__unused__))
diff --git a/Objects/accu.c b/Objects/accu.c
index 48fe02da5409..c8b5d382e388 100644
--- a/Objects/accu.c
+++ b/Objects/accu.c
@@ -1,7 +1,7 @@
/* Accumulator struct implementation */
#include "Python.h"
-#include "accu.h"
+#include "pycore_accu.h"
static PyObject *
join_list_unicode(PyObject *lst)
diff --git a/Objects/listobject.c b/Objects/listobject.c
index e38b21f2a30b..ffd91a63e323 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -2,7 +2,7 @@
#include "Python.h"
#include "pycore_state.h"
-#include "accu.h"
+#include "pycore_accu.h"
#ifdef STDC_HEADERS
#include <stddef.h>
diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c
index cce266f7a2d2..c997bc6fa2d0 100644
--- a/Objects/tupleobject.c
+++ b/Objects/tupleobject.c
@@ -3,7 +3,7 @@
#include "Python.h"
#include "pycore_state.h"
-#include "accu.h"
+#include "pycore_accu.h"
/*[clinic input]
class tuple "PyTupleObject *" "&PyTuple_Type"
diff --git a/PCbuild/pythoncore.vcxproj b/PCbuild/pythoncore.vcxproj
index ebc35a7c0049..6becb8a3682c 100644
--- a/PCbuild/pythoncore.vcxproj
+++ b/PCbuild/pythoncore.vcxproj
@@ -79,7 +79,6 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="..\Include\abstract.h" />
- <ClInclude Include="..\Include\accu.h" />
<ClInclude Include="..\Include\asdl.h" />
<ClInclude Include="..\Include\ast.h" />
<ClInclude Include="..\Include\bitset.h" />
@@ -112,6 +111,7 @@
<ClInclude Include="..\Include\graminit.h" />
<ClInclude Include="..\Include\grammar.h" />
<ClInclude Include="..\Include\import.h" />
+ <ClInclude Include="..\Include\internal\pycore_accu.h" />
<ClInclude Include="..\Include\internal\pycore_atomic.h" />
<ClInclude Include="..\Include\internal\pycore_ceval.h" />
<ClInclude Include="..\Include\internal\pycore_condvar.h" />
@@ -154,7 +154,6 @@
<ClInclude Include="..\Include\pyerrors.h" />
<ClInclude Include="..\Include\pyexpat.h" />
<ClInclude Include="..\Include\pyfpe.h" />
- <ClInclude Include="..\Include\internal\pygetopt.h" />
<ClInclude Include="..\Include\pylifecycle.h" />
<ClInclude Include="..\Include\pymath.h" />
<ClInclude Include="..\Include\pytime.h" />
diff --git a/PCbuild/pythoncore.vcxproj.filters b/PCbuild/pythoncore.vcxproj.filters
index 052c89cf806c..bc118c636cde 100644
--- a/PCbuild/pythoncore.vcxproj.filters
+++ b/PCbuild/pythoncore.vcxproj.filters
@@ -36,9 +36,6 @@
<ClInclude Include="..\Include\abstract.h">
<Filter>Include</Filter>
</ClInclude>
- <ClInclude Include="..\Include\accu.h">
- <Filter>Include</Filter>
- </ClInclude>
<ClInclude Include="..\Include\asdl.h">
<Filter>Include</Filter>
</ClInclude>
@@ -135,6 +132,9 @@
<ClInclude Include="..\Include\import.h">
<Filter>Include</Filter>
</ClInclude>
+ <ClInclude Include="..\Include\internal\pycore_accu.h">
+ <Filter>Include</Filter>
+ </ClInclude>
<ClInclude Include="..\Include\internal\pycore_atomic.h">
<Filter>Include</Filter>
</ClInclude>
1
0
![](https://secure.gravatar.com/avatar/cc7737cd64a84f1b5c61a160798e97ee.jpg?s=120&d=mm&r=g)
Nov. 1, 2018
https://github.com/python/cpython/commit/50b48572d9a90c5bb36e2bef6179548ea9…
commit: 50b48572d9a90c5bb36e2bef6179548ea927a35a
branch: master
author: Victor Stinner <vstinner(a)redhat.com>
committer: GitHub <noreply(a)github.com>
date: 2018-11-01T01:51:40+01:00
summary:
bpo-35081: Add _PyThreadState_GET() internal macro (GH-10266)
If Py_BUILD_CORE is defined, the PyThreadState_GET() macro access
_PyRuntime which comes from the internal pycore_state.h header.
Public headers must not require internal headers.
Move PyThreadState_GET() and _PyInterpreterState_GET_UNSAFE() from
Include/pystate.h to Include/internal/pycore_state.h, and rename
PyThreadState_GET() to _PyThreadState_GET() there.
The PyThreadState_GET() macro of pystate.h is now redefined when
pycore_state.h is included, to use the fast _PyThreadState_GET().
Changes:
* Add _PyThreadState_GET() macro
* Replace "PyThreadState_GET()->interp" with
_PyInterpreterState_GET_UNSAFE()
* Replace PyThreadState_GET() with _PyThreadState_GET() in internal C
files (compiled with Py_BUILD_CORE defined), but keep
PyThreadState_GET() in the public header files.
* _testcapimodule.c: replace PyThreadState_GET() with
PyThreadState_Get(); the module is not compiled with Py_BUILD_CORE
defined.
* pycore_state.h now requires Py_BUILD_CORE to be defined.
files:
M Include/internal/pycore_state.h
M Include/pystate.h
M Modules/_testcapimodule.c
M Objects/call.c
M Objects/dictobject.c
M Objects/genobject.c
M Objects/object.c
M Objects/odictobject.c
M Objects/typeobject.c
M Parser/myreadline.c
M Python/_warnings.c
M Python/ceval.c
M Python/context.c
M Python/errors.c
M Python/pylifecycle.c
M Python/pystate.c
M Python/symtable.c
M Python/sysmodule.c
M Python/thread_nt.h
M Python/thread_pthread.h
diff --git a/Include/internal/pycore_state.h b/Include/internal/pycore_state.h
index ff25d2ebf449..9a084f7f4d84 100644
--- a/Include/internal/pycore_state.h
+++ b/Include/internal/pycore_state.h
@@ -4,6 +4,10 @@
extern "C" {
#endif
+#ifndef Py_BUILD_CORE
+# error "Py_BUILD_CORE must be defined to include this header"
+#endif
+
#include "pystate.h"
#include "pythread.h"
@@ -214,6 +218,36 @@ PyAPI_FUNC(_PyInitError) _PyRuntime_Initialize(void);
(_PyRuntime.finalizing == tstate)
+/* Variable and macro for in-line access to current thread
+ and interpreter state */
+
+/* Get the current Python thread state.
+
+ Efficient macro reading directly the 'gilstate.tstate_current' atomic
+ variable. The macro is unsafe: it does not check for error and it can
+ return NULL.
+
+ The caller must hold the GIL.
+
+ See also PyThreadState_Get() and PyThreadState_GET(). */
+#define _PyThreadState_GET() \
+ ((PyThreadState*)_Py_atomic_load_relaxed(&_PyRuntime.gilstate.tstate_current))
+
+/* Redefine PyThreadState_GET() as an alias to _PyThreadState_GET() */
+#undef PyThreadState_GET
+#define PyThreadState_GET() _PyThreadState_GET()
+
+/* Get the current interpreter state.
+
+ The macro is unsafe: it does not check for error and it can return NULL.
+
+ The caller must hold the GIL.
+
+ See also _PyInterpreterState_Get()
+ and _PyGILState_GetInterpreterStateUnsafe(). */
+#define _PyInterpreterState_GET_UNSAFE() (_PyThreadState_GET()->interp)
+
+
/* Other */
PyAPI_FUNC(_PyInitError) _PyInterpreterState_Enable(_PyRuntimeState *);
diff --git a/Include/pystate.h b/Include/pystate.h
index 7fc921e9ac73..b30c3187b678 100644
--- a/Include/pystate.h
+++ b/Include/pystate.h
@@ -245,15 +245,17 @@ typedef struct _ts {
PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_New(void);
PyAPI_FUNC(void) PyInterpreterState_Clear(PyInterpreterState *);
PyAPI_FUNC(void) PyInterpreterState_Delete(PyInterpreterState *);
+
#if !defined(Py_LIMITED_API)
+/* Get the current interpreter state.
+
+ Issue a fatal error if there no current Python thread state or no current
+ interpreter. It cannot return NULL.
+
+ The caller must hold the GIL.*/
PyAPI_FUNC(PyInterpreterState *) _PyInterpreterState_Get(void);
#endif
-#ifdef Py_BUILD_CORE
- /* Macro which should only be used for performance critical code.
- Need "#include "pycore_state.h". See also _PyInterpreterState_Get()
- and _PyGILState_GetInterpreterStateUnsafe(). */
-# define _PyInterpreterState_GET_UNSAFE() (PyThreadState_GET()->interp)
-#endif
+
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03070000
/* New in 3.7 */
PyAPI_FUNC(int64_t) PyInterpreterState_GetID(PyInterpreterState *);
@@ -286,11 +288,27 @@ PyAPI_FUNC(void) PyThreadState_DeleteCurrent(void);
PyAPI_FUNC(void) _PyGILState_Reinit(void);
#endif /* !Py_LIMITED_API */
-/* Return the current thread state. The global interpreter lock must be held.
- * When the current thread state is NULL, this issues a fatal error (so that
- * the caller needn't check for NULL). */
+/* Get the current thread state.
+
+ When the current thread state is NULL, this issues a fatal error (so that
+ the caller needn't check for NULL).
+
+ The caller must hold the GIL.
+
+ See also PyThreadState_GET() and _PyThreadState_GET(). */
PyAPI_FUNC(PyThreadState *) PyThreadState_Get(void);
+/* Get the current Python thread state.
+
+ Macro using PyThreadState_Get() or _PyThreadState_GET() depending if
+ pycore_state.h is included or not (this header redefines the macro).
+
+ If PyThreadState_Get() is used, issue a fatal error if the current thread
+ state is NULL.
+
+ See also PyThreadState_Get() and _PyThreadState_GET(). */
+#define PyThreadState_GET() PyThreadState_Get()
+
#ifndef Py_LIMITED_API
/* Similar to PyThreadState_Get(), but don't issue a fatal error
* if it is NULL. */
@@ -301,18 +319,6 @@ PyAPI_FUNC(PyThreadState *) PyThreadState_Swap(PyThreadState *);
PyAPI_FUNC(PyObject *) PyThreadState_GetDict(void);
PyAPI_FUNC(int) PyThreadState_SetAsyncExc(unsigned long, PyObject *);
-
-/* Variable and macro for in-line access to current thread state */
-
-/* Assuming the current thread holds the GIL, this is the
- PyThreadState for the current thread. */
-#ifdef Py_BUILD_CORE
-# define PyThreadState_GET() \
- ((PyThreadState*)_Py_atomic_load_relaxed(&_PyRuntime.gilstate.tstate_current))
-#else
-# define PyThreadState_GET() PyThreadState_Get()
-#endif
-
typedef
enum {PyGILState_LOCKED, PyGILState_UNLOCKED}
PyGILState_STATE;
@@ -366,11 +372,11 @@ PyAPI_FUNC(PyThreadState *) PyGILState_GetThisThreadState(void);
The function returns 1 if _PyGILState_check_enabled is non-zero. */
PyAPI_FUNC(int) PyGILState_Check(void);
-/* Unsafe function to get the single PyInterpreterState used by this process'
- GILState implementation.
+/* Get the single PyInterpreterState used by this process' GILState
+ implementation.
- Return NULL before _PyGILState_Init() is called and after _PyGILState_Fini()
- is called.
+ This function doesn't check for error. Return NULL before _PyGILState_Init()
+ is called and after _PyGILState_Fini() is called.
See also _PyInterpreterState_Get() and _PyInterpreterState_GET_UNSAFE(). */
PyAPI_FUNC(PyInterpreterState *) _PyGILState_GetInterpreterStateUnsafe(void);
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index b2cda5142308..018af4a13707 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -4160,7 +4160,7 @@ test_PyTime_AsMicroseconds(PyObject *self, PyObject *args)
static PyObject*
get_recursion_depth(PyObject *self, PyObject *args)
{
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = PyThreadState_Get();
/* subtract one to ignore the frame of the get_recursion_depth() call */
return PyLong_FromLong(tstate->recursion_depth - 1);
diff --git a/Objects/call.c b/Objects/call.c
index 9061d0b1ac32..48e3aafe5fe5 100644
--- a/Objects/call.c
+++ b/Objects/call.c
@@ -258,7 +258,7 @@ function_code_fastcall(PyCodeObject *co, PyObject *const *args, Py_ssize_t nargs
PyObject *globals)
{
PyFrameObject *f;
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
PyObject **fastlocals;
Py_ssize_t i;
PyObject *result;
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index a9ae907d9f24..ea564a2b7c9f 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -1314,9 +1314,9 @@ PyDict_GetItem(PyObject *op, PyObject *key)
/* We can arrive here with a NULL tstate during initialization: try
running "python -Wi" for an example related to string interning.
Let's just hope that no exception occurs then... This must be
- PyThreadState_GET() and not PyThreadState_Get() because the latter
+ _PyThreadState_GET() and not PyThreadState_Get() because the latter
abort Python if tstate is NULL. */
- tstate = PyThreadState_GET();
+ tstate = _PyThreadState_GET();
if (tstate != NULL && tstate->curexc_type != NULL) {
/* preserve the existing exception */
PyObject *err_type, *err_value, *err_tb;
diff --git a/Objects/genobject.c b/Objects/genobject.c
index 885b3f2eca72..7c2948bb52d0 100644
--- a/Objects/genobject.c
+++ b/Objects/genobject.c
@@ -151,7 +151,7 @@ gen_dealloc(PyGenObject *gen)
static PyObject *
gen_send_ex(PyGenObject *gen, PyObject *arg, int exc, int closing)
{
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
PyFrameObject *f = gen->gi_frame;
PyObject *result;
@@ -1157,7 +1157,7 @@ PyCoro_New(PyFrameObject *f, PyObject *name, PyObject *qualname)
return NULL;
}
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
int origin_depth = tstate->coroutine_origin_tracking_depth;
if (origin_depth == 0) {
@@ -1267,7 +1267,7 @@ async_gen_init_hooks(PyAsyncGenObject *o)
o->ag_hooks_inited = 1;
- tstate = PyThreadState_GET();
+ tstate = _PyThreadState_GET();
finalizer = tstate->async_gen_finalizer;
if (finalizer) {
diff --git a/Objects/object.c b/Objects/object.c
index f7395c783ae8..d3a97f6c5bd4 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -2136,7 +2136,7 @@ _PyTrash_deposit_object(PyObject *op)
void
_PyTrash_thread_deposit_object(PyObject *op)
{
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
_PyObject_ASSERT(op, PyObject_IS_GC(op));
_PyObject_ASSERT(op, !_PyObject_GC_IS_TRACKED(op));
_PyObject_ASSERT(op, op->ob_refcnt == 0);
@@ -2174,7 +2174,7 @@ _PyTrash_destroy_chain(void)
void
_PyTrash_thread_destroy_chain(void)
{
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
/* We need to increase trash_delete_nesting here, otherwise,
_PyTrash_thread_destroy_chain will be called recursively
and then possibly crash. An example that may crash without
diff --git a/Objects/odictobject.c b/Objects/odictobject.c
index 81c996be5615..52ac7e5f88b0 100644
--- a/Objects/odictobject.c
+++ b/Objects/odictobject.c
@@ -1355,7 +1355,7 @@ static PyGetSetDef odict_getset[] = {
static void
odict_dealloc(PyODictObject *self)
{
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
PyObject_GC_UnTrack(self);
Py_TRASHCAN_SAFE_BEGIN(self)
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 9a390b3e5078..dedc4f7c8764 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -1115,7 +1115,7 @@ subtype_dealloc(PyObject *self)
{
PyTypeObject *type, *base;
destructor basedealloc;
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
int has_finalizer;
/* Extract the type; we expect it to be a heap type */
@@ -7678,7 +7678,7 @@ super_init(PyObject *self, PyObject *args, PyObject *kwds)
PyFrameObject *f;
PyCodeObject *co;
Py_ssize_t i, n;
- f = PyThreadState_GET()->frame;
+ f = _PyThreadState_GET()->frame;
if (f == NULL) {
PyErr_SetString(PyExc_RuntimeError,
"super(): no current frame");
diff --git a/Parser/myreadline.c b/Parser/myreadline.c
index d18cf1b61bac..f511319814a5 100644
--- a/Parser/myreadline.c
+++ b/Parser/myreadline.c
@@ -301,7 +301,7 @@ PyOS_Readline(FILE *sys_stdin, FILE *sys_stdout, const char *prompt)
char *rv, *res;
size_t len;
- if (_PyOS_ReadlineTState == PyThreadState_GET()) {
+ if (_PyOS_ReadlineTState == _PyThreadState_GET()) {
PyErr_SetString(PyExc_RuntimeError,
"can't re-enter readline");
return NULL;
@@ -316,7 +316,7 @@ PyOS_Readline(FILE *sys_stdin, FILE *sys_stdout, const char *prompt)
_PyOS_ReadlineLock = PyThread_allocate_lock();
}
- _PyOS_ReadlineTState = PyThreadState_GET();
+ _PyOS_ReadlineTState = _PyThreadState_GET();
Py_BEGIN_ALLOW_THREADS
PyThread_acquire_lock(_PyOS_ReadlineLock, 1);
diff --git a/Python/_warnings.c b/Python/_warnings.c
index 619ec6f26b49..9b50289bb67b 100644
--- a/Python/_warnings.c
+++ b/Python/_warnings.c
@@ -671,7 +671,7 @@ setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno,
PyObject *globals;
/* Setup globals, filename and lineno. */
- PyFrameObject *f = PyThreadState_GET()->frame;
+ PyFrameObject *f = _PyThreadState_GET()->frame;
// Stack level comparisons to Python code is off by one as there is no
// warnings-related stack level to avoid.
if (stack_level <= 0 || is_internal_frame(f)) {
diff --git a/Python/ceval.c b/Python/ceval.c
index 5599b6efa3e3..ac9db1533bf3 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -157,7 +157,7 @@ PyEval_InitThreads(void)
if (gil_created())
return;
create_gil();
- take_gil(PyThreadState_GET());
+ take_gil(_PyThreadState_GET());
_PyRuntime.ceval.pending.main_thread = PyThread_get_thread_ident();
if (!_PyRuntime.ceval.pending.lock)
_PyRuntime.ceval.pending.lock = PyThread_allocate_lock();
@@ -175,7 +175,7 @@ _PyEval_FiniThreads(void)
void
PyEval_AcquireLock(void)
{
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
if (tstate == NULL)
Py_FatalError("PyEval_AcquireLock: current thread state is NULL");
take_gil(tstate);
@@ -185,10 +185,10 @@ void
PyEval_ReleaseLock(void)
{
/* This function must succeed when the current thread state is NULL.
- We therefore avoid PyThreadState_GET() which dumps a fatal error
+ We therefore avoid PyThreadState_Get() which dumps a fatal error
in debug mode.
*/
- drop_gil(PyThreadState_GET());
+ drop_gil(_PyThreadState_GET());
}
void
@@ -222,7 +222,7 @@ PyEval_ReleaseThread(PyThreadState *tstate)
void
PyEval_ReInitThreads(void)
{
- PyThreadState *current_tstate = PyThreadState_GET();
+ PyThreadState *current_tstate = _PyThreadState_GET();
if (!gil_created())
return;
@@ -462,7 +462,7 @@ Py_SetRecursionLimit(int new_limit)
int
_Py_CheckRecursiveCall(const char *where)
{
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
int recursion_limit = _PyRuntime.ceval.recursion_limit;
#ifdef USE_STACKCHECK
@@ -543,7 +543,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
int oparg; /* Current opcode argument, if any */
PyObject **fastlocals, **freevars;
PyObject *retval = NULL; /* Return value */
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
PyCodeObject *co;
/* when tracing we set things up so that
@@ -3702,7 +3702,7 @@ _PyEval_EvalCodeWithName(PyObject *_co, PyObject *globals, PyObject *locals,
}
/* Create the frame */
- tstate = PyThreadState_GET();
+ tstate = _PyThreadState_GET();
assert(tstate != NULL);
f = _PyFrame_New_NoTrack(tstate, co, globals, locals);
if (f == NULL) {
@@ -4003,7 +4003,7 @@ do_raise(PyObject *exc, PyObject *cause)
if (exc == NULL) {
/* Reraise */
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
_PyErr_StackItem *exc_info = _PyErr_GetTopmostException(tstate);
PyObject *tb;
type = exc_info->exc_type;
@@ -4275,7 +4275,7 @@ call_trace(Py_tracefunc func, PyObject *obj,
PyObject *
_PyEval_CallTracing(PyObject *func, PyObject *args)
{
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
int save_tracing = tstate->tracing;
int save_use_tracing = tstate->use_tracing;
PyObject *result;
@@ -4329,7 +4329,7 @@ maybe_call_line_trace(Py_tracefunc func, PyObject *obj,
void
PyEval_SetProfile(Py_tracefunc func, PyObject *arg)
{
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
PyObject *temp = tstate->c_profileobj;
Py_XINCREF(arg);
tstate->c_profilefunc = NULL;
@@ -4346,7 +4346,7 @@ PyEval_SetProfile(Py_tracefunc func, PyObject *arg)
void
PyEval_SetTrace(Py_tracefunc func, PyObject *arg)
{
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
PyObject *temp = tstate->c_traceobj;
_Py_TracingPossible += (func != NULL) - (tstate->c_tracefunc != NULL);
Py_XINCREF(arg);
@@ -4366,21 +4366,21 @@ void
_PyEval_SetCoroutineOriginTrackingDepth(int new_depth)
{
assert(new_depth >= 0);
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
tstate->coroutine_origin_tracking_depth = new_depth;
}
int
_PyEval_GetCoroutineOriginTrackingDepth(void)
{
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
return tstate->coroutine_origin_tracking_depth;
}
void
_PyEval_SetCoroutineWrapper(PyObject *wrapper)
{
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
Py_XINCREF(wrapper);
Py_XSETREF(tstate->coroutine_wrapper, wrapper);
@@ -4389,14 +4389,14 @@ _PyEval_SetCoroutineWrapper(PyObject *wrapper)
PyObject *
_PyEval_GetCoroutineWrapper(void)
{
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
return tstate->coroutine_wrapper;
}
void
_PyEval_SetAsyncGenFirstiter(PyObject *firstiter)
{
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
Py_XINCREF(firstiter);
Py_XSETREF(tstate->async_gen_firstiter, firstiter);
@@ -4405,14 +4405,14 @@ _PyEval_SetAsyncGenFirstiter(PyObject *firstiter)
PyObject *
_PyEval_GetAsyncGenFirstiter(void)
{
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
return tstate->async_gen_firstiter;
}
void
_PyEval_SetAsyncGenFinalizer(PyObject *finalizer)
{
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
Py_XINCREF(finalizer);
Py_XSETREF(tstate->async_gen_finalizer, finalizer);
@@ -4421,7 +4421,7 @@ _PyEval_SetAsyncGenFinalizer(PyObject *finalizer)
PyObject *
_PyEval_GetAsyncGenFinalizer(void)
{
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
return tstate->async_gen_finalizer;
}
@@ -4465,7 +4465,7 @@ PyEval_GetGlobals(void)
PyFrameObject *
PyEval_GetFrame(void)
{
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
return _PyThreadState_GetFrame(tstate);
}
@@ -4566,11 +4566,11 @@ call_function(PyObject ***pp_stack, Py_ssize_t oparg, PyObject *kwnames)
presumed to be the most frequent callable object.
*/
if (PyCFunction_Check(func)) {
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
C_TRACE(x, _PyCFunction_FastCallKeywords(func, stack, nargs, kwnames));
}
else if (Py_TYPE(func) == &PyMethodDescr_Type) {
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
if (nargs > 0 && tstate->use_tracing) {
/* We need to create a temporary bound method as argument
for profiling.
@@ -4640,12 +4640,12 @@ do_call_core(PyObject *func, PyObject *callargs, PyObject *kwdict)
PyObject *result;
if (PyCFunction_Check(func)) {
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
C_TRACE(result, PyCFunction_Call(func, callargs, kwdict));
return result;
}
else if (Py_TYPE(func) == &PyMethodDescr_Type) {
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
Py_ssize_t nargs = PyTuple_GET_SIZE(callargs);
if (nargs > 0 && tstate->use_tracing) {
/* We need to create a temporary bound method as argument
diff --git a/Python/context.c b/Python/context.c
index b1f67b5aa75b..1fb2a5de2b1b 100644
--- a/Python/context.c
+++ b/Python/context.c
@@ -112,7 +112,7 @@ PyContext_Enter(PyObject *octx)
return -1;
}
- PyThreadState *ts = PyThreadState_GET();
+ PyThreadState *ts = _PyThreadState_GET();
assert(ts != NULL);
ctx->ctx_prev = (PyContext *)ts->context; /* borrow */
@@ -138,7 +138,7 @@ PyContext_Exit(PyObject *octx)
return -1;
}
- PyThreadState *ts = PyThreadState_GET();
+ PyThreadState *ts = _PyThreadState_GET();
assert(ts != NULL);
if (ts->context != (PyObject *)ctx) {
@@ -178,7 +178,7 @@ PyContextVar_Get(PyObject *ovar, PyObject *def, PyObject **val)
ENSURE_ContextVar(ovar, -1)
PyContextVar *var = (PyContextVar *)ovar;
- PyThreadState *ts = PyThreadState_GET();
+ PyThreadState *ts = _PyThreadState_GET();
assert(ts != NULL);
if (ts->context == NULL) {
goto not_found;
@@ -382,7 +382,7 @@ context_new_from_vars(PyHamtObject *vars)
static inline PyContext *
context_get(void)
{
- PyThreadState *ts = PyThreadState_GET();
+ PyThreadState *ts = _PyThreadState_GET();
assert(ts != NULL);
PyContext *current_ctx = (PyContext *)ts->context;
if (current_ctx == NULL) {
diff --git a/Python/errors.c b/Python/errors.c
index 14a70d9ce8e2..4c6c34c74fa6 100644
--- a/Python/errors.c
+++ b/Python/errors.c
@@ -28,7 +28,7 @@ _Py_IDENTIFIER(stderr);
void
PyErr_Restore(PyObject *type, PyObject *value, PyObject *traceback)
{
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
PyObject *oldtype, *oldvalue, *oldtraceback;
if (traceback != NULL && !PyTraceBack_Check(traceback)) {
@@ -82,7 +82,7 @@ _PyErr_CreateException(PyObject *exception, PyObject *value)
void
PyErr_SetObject(PyObject *exception, PyObject *value)
{
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
PyObject *exc_value;
PyObject *tb = NULL;
@@ -175,7 +175,7 @@ PyErr_SetString(PyObject *exception, const char *string)
PyObject* _Py_HOT_FUNCTION
PyErr_Occurred(void)
{
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
return tstate == NULL ? NULL : tstate->curexc_type;
}
@@ -334,7 +334,7 @@ PyErr_NormalizeException(PyObject **exc, PyObject **val, PyObject **tb)
void
PyErr_Fetch(PyObject **p_type, PyObject **p_value, PyObject **p_traceback)
{
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
*p_type = tstate->curexc_type;
*p_value = tstate->curexc_value;
@@ -354,7 +354,7 @@ PyErr_Clear(void)
void
PyErr_GetExcInfo(PyObject **p_type, PyObject **p_value, PyObject **p_traceback)
{
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
_PyErr_StackItem *exc_info = _PyErr_GetTopmostException(tstate);
*p_type = exc_info->exc_type;
@@ -371,7 +371,7 @@ void
PyErr_SetExcInfo(PyObject *p_type, PyObject *p_value, PyObject *p_traceback)
{
PyObject *oldtype, *oldvalue, *oldtraceback;
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
oldtype = tstate->exc_info->exc_type;
oldvalue = tstate->exc_info->exc_value;
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index d349aaf6deca..160f30ce6d6e 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -530,7 +530,7 @@ _Py_InitializeCore_impl(PyInterpreterState **interp_p,
/* bpo-34008: For backward compatibility reasons, calling Py_Main() after
Py_Initialize() ignores the new configuration. */
if (_PyRuntime.core_initialized) {
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
if (!tstate) {
return _Py_INIT_ERR("failed to read thread state");
}
@@ -1009,7 +1009,7 @@ Py_FinalizeEx(void)
wait_for_thread_shutdown();
/* Get current thread state and interpreter pointer */
- tstate = PyThreadState_GET();
+ tstate = _PyThreadState_GET();
interp = tstate->interp;
/* The interpreter is still entirely intact at this point, and the
@@ -1406,7 +1406,7 @@ Py_EndInterpreter(PyThreadState *tstate)
{
PyInterpreterState *interp = tstate->interp;
- if (tstate != PyThreadState_GET())
+ if (tstate != _PyThreadState_GET())
Py_FatalError("Py_EndInterpreter: thread is not current");
if (tstate->frame != NULL)
Py_FatalError("Py_EndInterpreter: thread still has a frame");
@@ -1928,7 +1928,7 @@ fatal_error(const char *prefix, const char *msg, int status)
and holds the GIL */
PyThreadState *tss_tstate = PyGILState_GetThisThreadState();
if (tss_tstate != NULL) {
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
if (tss_tstate != tstate) {
/* The Python thread does not hold the GIL */
tss_tstate = NULL;
diff --git a/Python/pystate.c b/Python/pystate.c
index c77902a7f9c7..c193a10c8cb2 100644
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -307,7 +307,7 @@ _PyInterpreterState_DeleteExceptMain()
PyInterpreterState *
_PyInterpreterState_Get(void)
{
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
if (tstate == NULL) {
Py_FatalError("_PyInterpreterState_Get(): no current thread state");
}
@@ -689,7 +689,7 @@ tstate_delete_common(PyThreadState *tstate)
void
PyThreadState_Delete(PyThreadState *tstate)
{
- if (tstate == PyThreadState_GET())
+ if (tstate == _PyThreadState_GET())
Py_FatalError("PyThreadState_Delete: tstate is still current");
if (_PyRuntime.gilstate.autoInterpreterState &&
PyThread_tss_get(&_PyRuntime.gilstate.autoTSSkey) == tstate)
@@ -703,7 +703,7 @@ PyThreadState_Delete(PyThreadState *tstate)
void
PyThreadState_DeleteCurrent()
{
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
if (tstate == NULL)
Py_FatalError(
"PyThreadState_DeleteCurrent: no current tstate");
@@ -758,14 +758,14 @@ _PyThreadState_DeleteExcept(PyThreadState *tstate)
PyThreadState *
_PyThreadState_UncheckedGet(void)
{
- return PyThreadState_GET();
+ return _PyThreadState_GET();
}
PyThreadState *
PyThreadState_Get(void)
{
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
if (tstate == NULL)
Py_FatalError("PyThreadState_Get: no current thread");
@@ -776,7 +776,7 @@ PyThreadState_Get(void)
PyThreadState *
PyThreadState_Swap(PyThreadState *newts)
{
- PyThreadState *oldts = PyThreadState_GET();
+ PyThreadState *oldts = _PyThreadState_GET();
_PyThreadState_SET(newts);
/* It should not be possible for more than one thread state
@@ -807,7 +807,7 @@ PyThreadState_Swap(PyThreadState *newts)
PyObject *
PyThreadState_GetDict(void)
{
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
if (tstate == NULL)
return NULL;
@@ -958,7 +958,7 @@ PyThreadState_IsCurrent(PyThreadState *tstate)
{
/* Must be the tstate for this thread */
assert(PyGILState_GetThisThreadState()==tstate);
- return tstate == PyThreadState_GET();
+ return tstate == _PyThreadState_GET();
}
/* Internal initialization/finalization functions called by
@@ -1085,7 +1085,7 @@ PyGILState_Check(void)
return 1;
}
- tstate = PyThreadState_GET();
+ tstate = _PyThreadState_GET();
if (tstate == NULL)
return 0;
diff --git a/Python/symtable.c b/Python/symtable.c
index dae6fda0e4c7..48e1515fa3bf 100644
--- a/Python/symtable.c
+++ b/Python/symtable.c
@@ -265,7 +265,7 @@ PySymtable_BuildObject(mod_ty mod, PyObject *filename, PyFutureFeatures *future)
st->st_future = future;
/* Setup recursion depth check counters */
- tstate = PyThreadState_GET();
+ tstate = _PyThreadState_GET();
if (!tstate) {
PySymtable_Free(st);
return NULL;
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index cb13e21c9405..830f0a88e4fb 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -336,7 +336,7 @@ PyDoc_STRVAR(excepthook_doc,
static PyObject *
sys_exc_info(PyObject *self, PyObject *noargs)
{
- _PyErr_StackItem *err_info = _PyErr_GetTopmostException(PyThreadState_GET());
+ _PyErr_StackItem *err_info = _PyErr_GetTopmostException(_PyThreadState_GET());
return Py_BuildValue(
"(OOO)",
err_info->exc_type != NULL ? err_info->exc_type : Py_None,
@@ -565,7 +565,7 @@ function call. See the debugger chapter in the library manual."
static PyObject *
sys_gettrace(PyObject *self, PyObject *args)
{
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
PyObject *temp = tstate->c_traceobj;
if (temp == NULL)
@@ -603,7 +603,7 @@ and return. See the profiler chapter in the library manual."
static PyObject *
sys_getprofile(PyObject *self, PyObject *args)
{
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
PyObject *temp = tstate->c_profileobj;
if (temp == NULL)
@@ -722,7 +722,7 @@ sys_setrecursionlimit(PyObject *self, PyObject *args)
the new low-water mark. Otherwise it may not be possible anymore to
reset the overflowed flag to 0. */
mark = _Py_RecursionLimitLowerWaterMark(new_limit);
- tstate = PyThreadState_GET();
+ tstate = _PyThreadState_GET();
if (tstate->recursion_depth >= mark) {
PyErr_Format(PyExc_RecursionError,
"cannot set the recursion limit to %i at "
@@ -1362,7 +1362,7 @@ purposes only."
static PyObject *
sys_getframe(PyObject *self, PyObject *args)
{
- PyFrameObject *f = PyThreadState_GET()->frame;
+ PyFrameObject *f = _PyThreadState_GET()->frame;
int depth = -1;
if (!PyArg_ParseTuple(args, "|i:_getframe", &depth))
@@ -1745,7 +1745,7 @@ static int
_PySys_ReadPreInitOptions(void)
{
/* Rerun the add commands with the actual sys module available */
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
if (tstate == NULL) {
/* Still don't have a thread state, so something is wrong! */
return -1;
@@ -1796,7 +1796,7 @@ get_warnoptions(void)
void
PySys_ResetWarnOptions(void)
{
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
if (tstate == NULL) {
_clear_preinit_entries(&_preinit_warnoptions);
return;
@@ -1835,7 +1835,7 @@ PySys_AddWarnOptionUnicode(PyObject *option)
void
PySys_AddWarnOption(const wchar_t *s)
{
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
if (tstate == NULL) {
_append_preinit_entry(&_preinit_warnoptions, s);
return;
@@ -1922,7 +1922,7 @@ _PySys_AddXOptionWithError(const wchar_t *s)
void
PySys_AddXOption(const wchar_t *s)
{
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
if (tstate == NULL) {
_append_preinit_entry(&_preinit_xoptions, s);
return;
diff --git a/Python/thread_nt.h b/Python/thread_nt.h
index 61fa8619bc17..21ef5556a6bc 100644
--- a/Python/thread_nt.h
+++ b/Python/thread_nt.h
@@ -189,7 +189,7 @@ PyThread_start_new_thread(void (*func)(void *), void *arg)
return PYTHREAD_INVALID_THREAD_ID;
obj->func = func;
obj->arg = arg;
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
size_t stacksize = tstate ? tstate->interp->pythread_stacksize : 0;
hThread = (HANDLE)_beginthreadex(0,
Py_SAFE_DOWNCAST(stacksize, Py_ssize_t, unsigned int),
@@ -334,13 +334,13 @@ _pythread_nt_set_stacksize(size_t size)
{
/* set to default */
if (size == 0) {
- PyThreadState_GET()->interp->pythread_stacksize = 0;
+ _PyInterpreterState_GET_UNSAFE()->pythread_stacksize = 0;
return 0;
}
/* valid range? */
if (size >= THREAD_MIN_STACKSIZE && size < THREAD_MAX_STACKSIZE) {
- PyThreadState_GET()->interp->pythread_stacksize = size;
+ _PyInterpreterState_GET_UNSAFE()->pythread_stacksize = size;
return 0;
}
diff --git a/Python/thread_pthread.h b/Python/thread_pthread.h
index 697140558fdc..6da8b3a44734 100644
--- a/Python/thread_pthread.h
+++ b/Python/thread_pthread.h
@@ -174,7 +174,7 @@ PyThread_start_new_thread(void (*func)(void *), void *arg)
return PYTHREAD_INVALID_THREAD_ID;
#endif
#if defined(THREAD_STACK_SIZE)
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
size_t stacksize = tstate ? tstate->interp->pythread_stacksize : 0;
tss = (stacksize != 0) ? stacksize : THREAD_STACK_SIZE;
if (tss != 0) {
@@ -591,7 +591,7 @@ _pythread_pthread_set_stacksize(size_t size)
/* set to default */
if (size == 0) {
- PyThreadState_GET()->interp->pythread_stacksize = 0;
+ _PyInterpreterState_GET_UNSAFE()->pythread_stacksize = 0;
return 0;
}
@@ -608,7 +608,7 @@ _pythread_pthread_set_stacksize(size_t size)
rc = pthread_attr_setstacksize(&attrs, size);
pthread_attr_destroy(&attrs);
if (rc == 0) {
- PyThreadState_GET()->interp->pythread_stacksize = size;
+ _PyInterpreterState_GET_UNSAFE()->pythread_stacksize = size;
return 0;
}
}
1
0
![](https://secure.gravatar.com/avatar/cc7737cd64a84f1b5c61a160798e97ee.jpg?s=120&d=mm&r=g)
bpo-26558: Fix Py_FatalError() with GIL released (GH-10267) (GH-10270)
by Victor Stinner Nov. 1, 2018
by Victor Stinner Nov. 1, 2018
Nov. 1, 2018
https://github.com/python/cpython/commit/ff56597151206a03ce421712516323430b…
commit: ff56597151206a03ce421712516323430b7749c8
branch: 3.6
author: Victor Stinner <vstinner(a)redhat.com>
committer: GitHub <noreply(a)github.com>
date: 2018-11-01T01:11:54+01:00
summary:
bpo-26558: Fix Py_FatalError() with GIL released (GH-10267) (GH-10270)
Don't call _Py_FatalError_PrintExc() nor flush_std_files() if the
current thread doesn't hold the GIL, or if the current thread
has no Python state thread.
(cherry picked from commit 3a228ab17c2a9cffd1a2f15f30d6209768de20a6)
files:
M Python/pylifecycle.c
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index ecfdfee218dc..56f04afc7701 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -1356,12 +1356,6 @@ _Py_FatalError_PrintExc(int fd)
PyObject *exception, *v, *tb;
int has_tb;
- if (PyThreadState_GET() == NULL) {
- /* The GIL is released: trying to acquire it is likely to deadlock,
- just give up. */
- return 0;
- }
-
PyErr_Fetch(&exception, &v, &tb);
if (exception == NULL) {
/* No current exception */
@@ -1425,10 +1419,32 @@ Py_FatalError(const char *msg)
fprintf(stderr, "Fatal Python error: %s\n", msg);
fflush(stderr); /* it helps in Windows debug build */
- /* Print the exception (if an exception is set) with its traceback,
- * or display the current Python stack. */
- if (!_Py_FatalError_PrintExc(fd))
+ /* Check if the current thread has a Python thread state
+ and holds the GIL */
+ PyThreadState *tss_tstate = PyGILState_GetThisThreadState();
+ if (tss_tstate != NULL) {
+ PyThreadState *tstate = PyThreadState_GET();
+ if (tss_tstate != tstate) {
+ /* The Python thread does not hold the GIL */
+ tss_tstate = NULL;
+ }
+ }
+ else {
+ /* Py_FatalError() has been called from a C thread
+ which has no Python thread state. */
+ }
+ int has_tstate_and_gil = (tss_tstate != NULL);
+
+ if (has_tstate_and_gil) {
+ /* If an exception is set, print the exception with its traceback */
+ if (!_Py_FatalError_PrintExc(fd)) {
+ /* No exception is set, or an exception is set without traceback */
+ _Py_FatalError_DumpTracebacks(fd);
+ }
+ }
+ else {
_Py_FatalError_DumpTracebacks(fd);
+ }
/* The main purpose of faulthandler is to display the traceback. We already
* did our best to display it. So faulthandler can now be disabled.
@@ -1436,7 +1452,7 @@ Py_FatalError(const char *msg)
_PyFaulthandler_Fini();
/* Check if the current Python thread hold the GIL */
- if (PyThreadState_GET() != NULL) {
+ if (has_tstate_and_gil) {
/* Flush sys.stdout and sys.stderr */
flush_std_files();
}
1
0