summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2022-06-17 13:19:28 (GMT)
committerGitHub <noreply@github.com>2022-06-17 13:19:28 (GMT)
commit17357108732c731d6ed4f2bd123ee6ba1ff6891b (patch)
tree397113da596c3a246d6022324123933d613316ba /Python
parentc5b750dc0b4d4e58047c9d93c635fa26b06562f7 (diff)
downloadcpython-17357108732c731d6ed4f2bd123ee6ba1ff6891b.zip
cpython-17357108732c731d6ed4f2bd123ee6ba1ff6891b.tar.gz
cpython-17357108732c731d6ed4f2bd123ee6ba1ff6891b.tar.bz2
gh-77782: Py_FdIsInteractive() now uses PyConfig.interactive (#93916)
Diffstat (limited to 'Python')
-rw-r--r--Python/ceval.c6
-rw-r--r--Python/initconfig.c2
-rw-r--r--Python/pylifecycle.c22
-rw-r--r--Python/pystate.c1
4 files changed, 17 insertions, 14 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index ca3797c..0d6855e 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -347,9 +347,9 @@ void _Py_NO_RETURN
_Py_FatalError_TstateNULL(const char *func)
{
_Py_FatalErrorFunc(func,
- "the function must be called with the GIL held, "
- "but the GIL is released "
- "(the current Python thread state is NULL)");
+ "the function must be called with the GIL held, "
+ "after Python initialization and before Python finalization, "
+ "but the GIL is released (the current Python thread state is NULL)");
}
int
diff --git a/Python/initconfig.c b/Python/initconfig.c
index 86dcdd9..e5b8787 100644
--- a/Python/initconfig.c
+++ b/Python/initconfig.c
@@ -180,7 +180,7 @@ int Py_UTF8Mode = 0;
int Py_DebugFlag = 0; /* Needed by parser.c */
int Py_VerboseFlag = 0; /* Needed by import.c */
int Py_QuietFlag = 0; /* Needed by sysmodule.c */
-int Py_InteractiveFlag = 0; /* Needed by Py_FdIsInteractive() below */
+int Py_InteractiveFlag = 0; /* Previously, was used by Py_FdIsInteractive() */
int Py_InspectFlag = 0; /* Needed to determine whether to exit at SystemExit */
int Py_OptimizeFlag = 0; /* Needed by compile.c */
int Py_NoSiteFlag = 0; /* Suppress 'import site' */
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index 0937cce..c2c9e90 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -2938,28 +2938,30 @@ Py_Exit(int sts)
int
Py_FdIsInteractive(FILE *fp, const char *filename)
{
- if (isatty((int)fileno(fp)))
+ if (isatty(fileno(fp))) {
return 1;
- if (!Py_InteractiveFlag)
+ }
+ if (!_Py_GetConfig()->interactive) {
return 0;
- return (filename == NULL) ||
- (strcmp(filename, "<stdin>") == 0) ||
- (strcmp(filename, "???") == 0);
+ }
+ return ((filename == NULL)
+ || (strcmp(filename, "<stdin>") == 0)
+ || (strcmp(filename, "???") == 0));
}
int
_Py_FdIsInteractive(FILE *fp, PyObject *filename)
{
- if (isatty((int)fileno(fp))) {
+ if (isatty(fileno(fp))) {
return 1;
}
- if (!Py_InteractiveFlag) {
+ if (!_Py_GetConfig()->interactive) {
return 0;
}
- return (filename == NULL) ||
- (PyUnicode_CompareWithASCIIString(filename, "<stdin>") == 0) ||
- (PyUnicode_CompareWithASCIIString(filename, "???") == 0);
+ return ((filename == NULL)
+ || (PyUnicode_CompareWithASCIIString(filename, "<stdin>") == 0)
+ || (PyUnicode_CompareWithASCIIString(filename, "???") == 0));
}
diff --git a/Python/pystate.c b/Python/pystate.c
index df56c05..3cc7613 100644
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -2136,6 +2136,7 @@ _Py_GetConfig(void)
{
assert(PyGILState_Check());
PyThreadState *tstate = _PyThreadState_GET();
+ _Py_EnsureTstateNotNULL(tstate);
return _PyInterpreterState_GetConfig(tstate->interp);
}