From 86a58dabec40bfb4c112b918cabd7eb21e52183c Mon Sep 17 00:00:00 2001 From: Nick Coghlan Date: Thu, 20 Nov 2014 21:39:37 +1000 Subject: Issue #22869: Split pythonrun into two modules - interpreter startup and shutdown code moved to a new pylifecycle.c module - Py_OptimizeFlag moved into the new module with the other global flags --- Python/sysmodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Python/sysmodule.c') diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 106fc84fa9..6fb882f015 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -1681,7 +1681,7 @@ _PySys_Init(void) } #endif - /* stdin/stdout/stderr are now set by pythonrun.c */ + /* stdin/stdout/stderr are set in pylifecycle.c */ SET_SYS_FROM_STRING_BORROW("__displayhook__", PyDict_GetItemString(sysdict, "displayhook")); -- cgit v1.2.1 From a8d66b4ff6f2d4115ccd355ab1b3bc8b263bde90 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Sun, 7 Dec 2014 01:28:27 +0100 Subject: Issue #22696: Add function :func:`sys.is_finalizing` to know about interpreter shutdown. --- Python/sysmodule.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'Python/sysmodule.c') diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 6fb882f015..aa4046ff93 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -1121,6 +1121,16 @@ PyDoc_STRVAR(sys_clear_type_cache__doc__, "_clear_type_cache() -> None\n\ Clear the internal type lookup cache."); +static PyObject * +sys_is_finalizing(PyObject* self, PyObject* args) +{ + return PyBool_FromLong(_Py_Finalizing != NULL); +} + +PyDoc_STRVAR(is_finalizing_doc, +"is_finalizing()\n\ +Return True if Python is exiting."); + static PyMethodDef sys_methods[] = { /* Might as well keep this in alphabetic order */ @@ -1167,6 +1177,7 @@ static PyMethodDef sys_methods[] = { getwindowsversion_doc}, #endif /* MS_WINDOWS */ {"intern", sys_intern, METH_VARARGS, intern_doc}, + {"is_finalizing", sys_is_finalizing, METH_NOARGS, is_finalizing_doc}, #ifdef USE_MALLOPT {"mdebug", sys_mdebug, METH_VARARGS}, #endif -- cgit v1.2.1 From 4b5c8edd294f02afef7407d9fd5236789bd4bc34 Mon Sep 17 00:00:00 2001 From: Steve Dower Date: Sat, 21 Feb 2015 08:44:05 -0800 Subject: Issue #23152: Implement _Py_fstat() to support files larger than 2 GB on Windows. fstat() may fail with EOVERFLOW on files larger than 2 GB because the file size type is an signed 32-bit integer. --- Python/sysmodule.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Python/sysmodule.c') diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 0639231282..292830bc25 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -1681,8 +1681,8 @@ _PySys_Init(void) the shell already prevents that. */ #if !defined(MS_WINDOWS) { - struct stat sb; - if (fstat(fileno(stdin), &sb) == 0 && + struct _Py_stat_struct sb; + if (_Py_fstat(fileno(stdin), &sb) == 0 && S_ISDIR(sb.st_mode)) { /* There's nothing more we can do. */ /* Py_FatalError() will core dump, so just exit. */ -- cgit v1.2.1 From 547de7c7bdd902a96d8b74f35e3a24c4eeabaf2f Mon Sep 17 00:00:00 2001 From: Steve Dower Date: Mon, 2 Mar 2015 08:01:10 -0800 Subject: Issue #23451: Update pyconfig.h for Windows to require Vista headers and remove unnecessary version checks. --- Python/sysmodule.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'Python/sysmodule.c') diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 292830bc25..471389cf57 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -772,6 +772,12 @@ static PyStructSequence_Desc windows_version_desc = { via indexing, the rest are name only */ }; +/* Disable deprecation warnings about GetVersionEx as the result is + being passed straight through to the caller, who is responsible for + using it correctly. */ +#pragma warning(push) +#pragma warning(disable:4996) + static PyObject * sys_getwindowsversion(PyObject *self) { @@ -803,6 +809,8 @@ sys_getwindowsversion(PyObject *self) return version; } +#pragma warning(pop) + #endif /* MS_WINDOWS */ #ifdef HAVE_DLOPEN -- cgit v1.2.1 From 0600ebc4d9a0fbb0f16689fb2c1d6a09482594cc Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 30 Mar 2015 10:09:31 +0200 Subject: Issue #23752: _Py_fstat() is now responsible to raise the Python exception Add _Py_fstat_noraise() function when a Python exception is not welcome. --- Python/sysmodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Python/sysmodule.c') diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 471389cf57..9ec25216ed 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -1690,7 +1690,7 @@ _PySys_Init(void) #if !defined(MS_WINDOWS) { struct _Py_stat_struct sb; - if (_Py_fstat(fileno(stdin), &sb) == 0 && + if (_Py_fstat_noraise(fileno(stdin), &sb) == 0 && S_ISDIR(sb.st_mode)) { /* There's nothing more we can do. */ /* Py_FatalError() will core dump, so just exit. */ -- cgit v1.2.1 From ea639832c36905ecb07caba111f614c4bbf9bdd6 Mon Sep 17 00:00:00 2001 From: Yury Selivanov Date: Mon, 11 May 2015 22:57:16 -0400 Subject: PEP 0492 -- Coroutines with async and await syntax. Issue #24017. --- Python/sysmodule.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'Python/sysmodule.c') diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 9ec25216ed..bf9a96fb75 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -645,6 +645,49 @@ sys_setrecursionlimit(PyObject *self, PyObject *args) return Py_None; } +static PyObject * +sys_set_coroutine_wrapper(PyObject *self, PyObject *wrapper) +{ + if (wrapper != Py_None) { + if (!PyCallable_Check(wrapper)) { + PyErr_Format(PyExc_TypeError, + "callable expected, got %.50s", + Py_TYPE(wrapper)->tp_name); + return NULL; + } + + PyEval_SetCoroutineWrapper(wrapper); + } + else + PyEval_SetCoroutineWrapper(NULL); + Py_INCREF(Py_None); + Py_RETURN_NONE; +} + +PyDoc_STRVAR(set_coroutine_wrapper_doc, +"set_coroutine_wrapper(wrapper)\n\ +\n\ +Set a wrapper for coroutine objects." +); + +static PyObject * +sys_get_coroutine_wrapper(PyObject *self, PyObject *args) +{ + PyObject *wrapper = PyEval_GetCoroutineWrapper(); + if (wrapper == NULL) { + wrapper = Py_None; + } + Py_INCREF(wrapper); + return wrapper; +} + +PyDoc_STRVAR(get_coroutine_wrapper_doc, +"get_coroutine_wrapper()\n\ +\n\ +Return the wrapper for coroutine objects set by sys.set_coroutine_wrapper." +); + + static PyTypeObject Hash_InfoType; PyDoc_STRVAR(hash_info_doc, @@ -1215,6 +1258,10 @@ static PyMethodDef sys_methods[] = { {"call_tracing", sys_call_tracing, METH_VARARGS, call_tracing_doc}, {"_debugmallocstats", sys_debugmallocstats, METH_NOARGS, debugmallocstats_doc}, + {"set_coroutine_wrapper", sys_set_coroutine_wrapper, METH_O, + set_coroutine_wrapper_doc}, + {"get_coroutine_wrapper", sys_get_coroutine_wrapper, METH_NOARGS, + get_coroutine_wrapper_doc}, {NULL, NULL} /* sentinel */ }; -- cgit v1.2.1 From 77a04205150a46220b09d9ef8106d0f5667e4558 Mon Sep 17 00:00:00 2001 From: Yury Selivanov Date: Tue, 12 May 2015 11:30:14 -0400 Subject: Issue #24017: Plug ref leak. --- Python/sysmodule.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'Python/sysmodule.c') diff --git a/Python/sysmodule.c b/Python/sysmodule.c index bf9a96fb75..5f7c0ebba6 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -655,12 +655,10 @@ sys_set_coroutine_wrapper(PyObject *self, PyObject *wrapper) Py_TYPE(wrapper)->tp_name); return NULL; } - PyEval_SetCoroutineWrapper(wrapper); } else PyEval_SetCoroutineWrapper(NULL); - Py_INCREF(Py_None); Py_RETURN_NONE; } -- cgit v1.2.1 From 096d40afdee98338a16811681c687475fa52c6c0 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Tue, 12 May 2015 11:32:41 -0400 Subject: use our normal bracing style --- Python/sysmodule.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'Python/sysmodule.c') diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 5f7c0ebba6..149b76eea7 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -657,8 +657,9 @@ sys_set_coroutine_wrapper(PyObject *self, PyObject *wrapper) } PyEval_SetCoroutineWrapper(wrapper); } - else + else { PyEval_SetCoroutineWrapper(NULL); + } Py_RETURN_NONE; } -- cgit v1.2.1 From dab9b839d0e4eb315c219433c19c999729a39a95 Mon Sep 17 00:00:00 2001 From: Yury Selivanov Date: Mon, 1 Jun 2015 12:15:23 -0400 Subject: Issue 24017: Make PyEval_(Set|Get)CoroutineWrapper private --- Python/sysmodule.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Python/sysmodule.c') diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 149b76eea7..f600baf10e 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -655,10 +655,10 @@ sys_set_coroutine_wrapper(PyObject *self, PyObject *wrapper) Py_TYPE(wrapper)->tp_name); return NULL; } - PyEval_SetCoroutineWrapper(wrapper); + _PyEval_SetCoroutineWrapper(wrapper); } else { - PyEval_SetCoroutineWrapper(NULL); + _PyEval_SetCoroutineWrapper(NULL); } Py_RETURN_NONE; } @@ -672,7 +672,7 @@ Set a wrapper for coroutine objects." static PyObject * sys_get_coroutine_wrapper(PyObject *self, PyObject *args) { - PyObject *wrapper = PyEval_GetCoroutineWrapper(); + PyObject *wrapper = _PyEval_GetCoroutineWrapper(); if (wrapper == NULL) { wrapper = Py_None; } -- cgit v1.2.1