From 088d15c842d57bdfd50d942d315e8f7761331de6 Mon Sep 17 00:00:00 2001 From: Berker Peksag Date: Fri, 17 Jun 2016 13:25:01 +0300 Subject: Issue #27336: Fix compilation failures --without-threads --- Python/pylifecycle.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'Python/pylifecycle.c') diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 7187fe448a..12a5d4c8b7 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -746,9 +746,11 @@ Py_NewInterpreter(void) if (!initialized) Py_FatalError("Py_NewInterpreter: call Py_Initialize first"); +#if WITH_THREAD /* Issue #10915, #15751: The GIL API doesn't work with multiple interpreters: disable PyGILState_Check(). */ _PyGILState_check_enabled = 0; +#endif interp = PyInterpreterState_New(); if (interp == NULL) -- cgit v1.2.1 From 8a5c0e95b0a8c9109ca4395491612bf6f6856e3e Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 17 Jun 2016 12:29:00 +0200 Subject: Issue #27336: Fix compilation on Windows Replace "#if WITH_THREAD" with "#ifdef WITH_THREAD". --- Python/pylifecycle.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Python/pylifecycle.c') diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 12a5d4c8b7..72a00e671f 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -746,7 +746,7 @@ Py_NewInterpreter(void) if (!initialized) Py_FatalError("Py_NewInterpreter: call Py_Initialize first"); -#if WITH_THREAD +#ifdef WITH_THREAD /* Issue #10915, #15751: The GIL API doesn't work with multiple interpreters: disable PyGILState_Check(). */ _PyGILState_check_enabled = 0; @@ -1409,7 +1409,7 @@ exit: /* Clean up and exit */ #ifdef WITH_THREAD -#include "pythread.h" +# include "pythread.h" #endif static void (*pyexitfunc)(void) = NULL; -- cgit v1.2.1 From ca47ebf3fce4e3b9f9a29136bcfd77994e8c481e Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sun, 3 Jul 2016 21:03:53 +0300 Subject: Issue #23034: The output of a special Python build with defined COUNT_ALLOCS, SHOW_ALLOC_COUNT or SHOW_TRACK_COUNT macros is now off by default. It can be re-enabled using the "-X showalloccount" option. It now outputs to stderr instead of stdout. --- Python/pylifecycle.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Python/pylifecycle.c') diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 72a00e671f..2d2dcba016 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -626,7 +626,7 @@ Py_FinalizeEx(void) /* Debugging stuff */ #ifdef COUNT_ALLOCS - dump_counts(stdout); + dump_counts(stderr); #endif /* dump hash stats */ _PyHash_Fini(); -- cgit v1.2.1 From 47f7f2f22d067813b1406f7aa9328b53f264aa6a Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Tue, 2 Aug 2016 22:51:21 +0300 Subject: Issue #22557: Now importing already imported modules is up to 2.5 times faster. --- Python/pylifecycle.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'Python/pylifecycle.c') diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 2d2dcba016..dc855513ca 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -254,6 +254,11 @@ import_init(PyInterpreterState *interp, PyObject *sysmod) interp->importlib = importlib; Py_INCREF(interp->importlib); + interp->import_func = PyDict_GetItemString(interp->builtins, "__import__"); + if (interp->import_func == NULL) + Py_FatalError("Py_Initialize: __import__ not found"); + Py_INCREF(interp->import_func); + /* Import the _imp module */ impmod = PyInit_imp(); if (impmod == NULL) { -- cgit v1.2.1 From 96d299b2b87dd2311bcc94cbab7b1cfa2c30ccba Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sun, 14 Aug 2016 10:52:18 +0300 Subject: Issue #27574: Decreased an overhead of parsing keyword arguments in functions implemented with using Argument Clinic. --- Python/pylifecycle.c | 1 + 1 file changed, 1 insertion(+) (limited to 'Python/pylifecycle.c') diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index dc855513ca..004feae7a0 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -674,6 +674,7 @@ Py_FinalizeEx(void) PySlice_Fini(); _PyGC_Fini(); _PyRandom_Fini(); + _PyArg_Fini(); /* Cleanup Unicode implementation */ _PyUnicode_Fini(); -- cgit v1.2.1 From 06d0337c7565e35432fe744713260e2ef3e8a545 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 5 Sep 2016 18:16:01 -0700 Subject: Avoid calling functions with an empty string as format string Directly pass NULL rather than an empty string. --- Python/pylifecycle.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'Python/pylifecycle.c') diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 004feae7a0..1896888916 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -493,7 +493,7 @@ flush_std_files(void) int status = 0; if (fout != NULL && fout != Py_None && !file_is_closed(fout)) { - tmp = _PyObject_CallMethodId(fout, &PyId_flush, ""); + tmp = _PyObject_CallMethodId(fout, &PyId_flush, NULL); if (tmp == NULL) { PyErr_WriteUnraisable(fout); status = -1; @@ -503,7 +503,7 @@ flush_std_files(void) } if (ferr != NULL && ferr != Py_None && !file_is_closed(ferr)) { - tmp = _PyObject_CallMethodId(ferr, &PyId_flush, ""); + tmp = _PyObject_CallMethodId(ferr, &PyId_flush, NULL); if (tmp == NULL) { PyErr_Clear(); status = -1; @@ -1072,7 +1072,7 @@ create_stdio(PyObject* io, text = PyUnicode_FromString(name); if (text == NULL || _PyObject_SetAttrId(raw, &PyId_name, text) < 0) goto error; - res = _PyObject_CallMethodId(raw, &PyId_isatty, ""); + res = _PyObject_CallMethodId(raw, &PyId_isatty, NULL); if (res == NULL) goto error; isatty = PyObject_IsTrue(res); @@ -1343,7 +1343,7 @@ _Py_FatalError_PrintExc(int fd) Py_XDECREF(tb); /* sys.stderr may be buffered: call sys.stderr.flush() */ - res = _PyObject_CallMethodId(ferr, &PyId_flush, ""); + res = _PyObject_CallMethodId(ferr, &PyId_flush, NULL); if (res == NULL) PyErr_Clear(); else @@ -1453,7 +1453,7 @@ wait_for_thread_shutdown(void) PyErr_Clear(); return; } - result = _PyObject_CallMethodId(threading, &PyId__shutdown, ""); + result = _PyObject_CallMethodId(threading, &PyId__shutdown, NULL); if (result == NULL) { PyErr_WriteUnraisable(threading); } -- cgit v1.2.1 From 9c9a45c1f0a264d3006971b8211d948d6883a05b Mon Sep 17 00:00:00 2001 From: Steve Dower Date: Thu, 8 Sep 2016 10:35:16 -0700 Subject: Issue #27781: Change file system encoding on Windows to UTF-8 (PEP 529) --- Python/pylifecycle.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'Python/pylifecycle.c') diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 1896888916..3f3b614a47 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -90,6 +90,9 @@ int Py_NoUserSiteDirectory = 0; /* for -s and site.py */ int Py_UnbufferedStdioFlag = 0; /* Unbuffered binary std{in,out,err} */ int Py_HashRandomizationFlag = 0; /* for -R and PYTHONHASHSEED */ int Py_IsolatedFlag = 0; /* for -I, isolate from user's env */ +#ifdef MS_WINDOWS +int Py_LegacyWindowsFSEncodingFlag = 0; /* Uses mbcs instead of utf-8 */ +#endif PyThreadState *_Py_Finalizing = NULL; @@ -321,6 +324,10 @@ _Py_InitializeEx_Private(int install_sigs, int install_importlib) check its value further. */ if ((p = Py_GETENV("PYTHONHASHSEED")) && *p != '\0') Py_HashRandomizationFlag = add_flag(Py_HashRandomizationFlag, p); +#ifdef MS_WINDOWS + if ((p = Py_GETENV("PYTHONLEGACYWINDOWSFSENCODING")) && *p != '\0') + Py_LegacyWindowsFSEncodingFlag = add_flag(Py_LegacyWindowsFSEncodingFlag, p); +#endif _PyRandom_Init(); @@ -958,6 +965,18 @@ initfsencoding(PyInterpreterState *interp) { PyObject *codec; +#ifdef MS_WINDOWS + if (Py_LegacyWindowsFSEncodingFlag) + { + Py_FileSystemDefaultEncoding = "mbcs"; + Py_FileSystemDefaultEncodeErrors = "replace"; + } + else + { + Py_FileSystemDefaultEncoding = "utf-8"; + Py_FileSystemDefaultEncodeErrors = "surrogatepass"; + } +#else if (Py_FileSystemDefaultEncoding == NULL) { Py_FileSystemDefaultEncoding = get_locale_encoding(); @@ -968,6 +987,7 @@ initfsencoding(PyInterpreterState *interp) interp->fscodec_initialized = 1; return 0; } +#endif /* the encoding is mbcs, utf-8 or ascii */ codec = _PyCodec_Lookup(Py_FileSystemDefaultEncoding); -- cgit v1.2.1 From 0b262da03401df836e0d2cd8b20412aeeaec6af8 Mon Sep 17 00:00:00 2001 From: Steve Dower Date: Thu, 8 Sep 2016 11:21:54 -0700 Subject: Issue #23524: Finish removing _PyVerify_fd from sources --- Python/pylifecycle.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Python/pylifecycle.c') diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 3f3b614a47..dab5c3c1ab 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -1026,7 +1026,7 @@ static int is_valid_fd(int fd) { int fd2; - if (fd < 0 || !_PyVerify_fd(fd)) + if (fd < 0) return 0; _Py_BEGIN_SUPPRESS_IPH /* Prefer dup() over fstat(). fstat() can require input/output whereas -- cgit v1.2.1 From 73392d64a0328bce848b448206b668f695640538 Mon Sep 17 00:00:00 2001 From: Steve Dower Date: Tue, 30 Aug 2016 21:22:36 -0700 Subject: Issue #1602: Windows console doesn't input or print Unicode (PEP 528) Closes #17602: Adds a readline implementation for the Windows console --- Python/pylifecycle.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'Python/pylifecycle.c') diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index dab5c3c1ab..1a68255c93 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -31,6 +31,9 @@ #ifdef MS_WINDOWS #undef BYTE #include "windows.h" + +extern PyTypeObject PyWindowsConsoleIO_Type; +#define PyWindowsConsoleIO_Check(op) (PyObject_TypeCheck((op), &PyWindowsConsoleIO_Type)) #endif _Py_IDENTIFIER(flush); @@ -92,6 +95,7 @@ int Py_HashRandomizationFlag = 0; /* for -R and PYTHONHASHSEED */ int Py_IsolatedFlag = 0; /* for -I, isolate from user's env */ #ifdef MS_WINDOWS int Py_LegacyWindowsFSEncodingFlag = 0; /* Uses mbcs instead of utf-8 */ +int Py_LegacyWindowsStdioFlag = 0; /* Uses FileIO instead of WindowsConsoleIO */ #endif PyThreadState *_Py_Finalizing = NULL; @@ -154,6 +158,12 @@ Py_SetStandardStreamEncoding(const char *encoding, const char *errors) return -3; } } +#ifdef MS_WINDOWS + if (_Py_StandardStreamEncoding) { + /* Overriding the stream encoding implies legacy streams */ + Py_LegacyWindowsStdioFlag = 1; + } +#endif return 0; } @@ -327,6 +337,8 @@ _Py_InitializeEx_Private(int install_sigs, int install_importlib) #ifdef MS_WINDOWS if ((p = Py_GETENV("PYTHONLEGACYWINDOWSFSENCODING")) && *p != '\0') Py_LegacyWindowsFSEncodingFlag = add_flag(Py_LegacyWindowsFSEncodingFlag, p); + if ((p = Py_GETENV("PYTHONLEGACYWINDOWSSTDIO")) && *p != '\0') + Py_LegacyWindowsStdioFlag = add_flag(Py_LegacyWindowsStdioFlag, p); #endif _PyRandom_Init(); @@ -1089,6 +1101,12 @@ create_stdio(PyObject* io, Py_INCREF(raw); } +#ifdef MS_WINDOWS + /* Windows console IO is always UTF-8 encoded */ + if (PyWindowsConsoleIO_Check(raw)) + encoding = "utf-8"; +#endif + text = PyUnicode_FromString(name); if (text == NULL || _PyObject_SetAttrId(raw, &PyId_name, text) < 0) goto error; -- cgit v1.2.1 From b164476aaf77ceffac36ddbbdc7f4df90fbfebd3 Mon Sep 17 00:00:00 2001 From: Yury Selivanov Date: Thu, 8 Sep 2016 20:50:03 -0700 Subject: Issue #27985: Implement PEP 526 -- Syntax for Variable Annotations. Patch by Ivan Levkivskyi. --- Python/pylifecycle.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'Python/pylifecycle.c') diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 1a68255c93..a2399ed576 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -937,11 +937,17 @@ Py_GetPythonHome(void) static void initmain(PyInterpreterState *interp) { - PyObject *m, *d, *loader; + PyObject *m, *d, *loader, *ann_dict; m = PyImport_AddModule("__main__"); if (m == NULL) Py_FatalError("can't create __main__ module"); d = PyModule_GetDict(m); + ann_dict = PyDict_New(); + if ((ann_dict == NULL) || + (PyDict_SetItemString(d, "__annotations__", ann_dict) < 0)) { + Py_FatalError("Failed to initialize __main__.__annotations__"); + } + Py_DECREF(ann_dict); if (PyDict_GetItemString(d, "__builtins__") == NULL) { PyObject *bimod = PyImport_ImportModule("builtins"); if (bimod == NULL) { -- cgit v1.2.1 From 17668cfa5e0e6f50376cc233d9b063b908a19845 Mon Sep 17 00:00:00 2001 From: Yury Selivanov Date: Thu, 8 Sep 2016 22:01:51 -0700 Subject: Issue #28003: Implement PEP 525 -- Asynchronous Generators. --- Python/pylifecycle.c | 1 + 1 file changed, 1 insertion(+) (limited to 'Python/pylifecycle.c') diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index a2399ed576..f93afd234d 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -694,6 +694,7 @@ Py_FinalizeEx(void) _PyGC_Fini(); _PyRandom_Fini(); _PyArg_Fini(); + PyAsyncGen_Fini(); /* Cleanup Unicode implementation */ _PyUnicode_Fini(); -- cgit v1.2.1 From 2286749cb025118308ce513a1b4ba90daa6e968e Mon Sep 17 00:00:00 2001 From: ?ukasz Langa Date: Fri, 9 Sep 2016 21:47:46 -0700 Subject: Don't run garbage collection on interpreter exit if it was explicitly disabled by the user. --- Python/pylifecycle.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Python/pylifecycle.c') diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index f93afd234d..5b5cc2b55e 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -600,12 +600,12 @@ Py_FinalizeEx(void) * XXX but I'm unclear on exactly how that one happens. In any case, * XXX I haven't seen a real-life report of either of these. */ - PyGC_Collect(); + _PyGC_CollectIfEnabled(); #ifdef COUNT_ALLOCS /* With COUNT_ALLOCS, it helps to run GC multiple times: each collection might release some types from the type list, so they become garbage. */ - while (PyGC_Collect() > 0) + while (_PyGC_CollectIfEnabled() > 0) /* nothing */; #endif /* Destroy all modules */ @@ -632,7 +632,7 @@ Py_FinalizeEx(void) * XXX Python code getting called. */ #if 0 - PyGC_Collect(); + _PyGC_CollectIfEnabled(); #endif /* Disable tracemalloc after all Python objects have been destroyed, -- cgit v1.2.1 From 0af37fbc56ae6aaccab23c642142744f4e83871f Mon Sep 17 00:00:00 2001 From: Xavier de Gaye Date: Wed, 16 Nov 2016 07:24:20 +0100 Subject: Issue #26920: Fix not getting the locale's charset upon initializing the interpreter, on platforms that do not have langinfo --- Python/pylifecycle.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Python/pylifecycle.c') diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 5b5cc2b55e..71f23dd150 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -315,7 +315,7 @@ _Py_InitializeEx_Private(int install_sigs, int install_importlib) initialized = 1; _Py_Finalizing = NULL; -#if defined(HAVE_LANGINFO_H) && defined(HAVE_SETLOCALE) +#ifdef HAVE_SETLOCALE /* Set up the LC_CTYPE locale, so we can obtain the locale's charset without having to switch locales. */ -- cgit v1.2.1 From 57c0f2e61c8a5893c37e576a3a03ba5e57c1132c Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sun, 20 Nov 2016 09:13:07 +0200 Subject: Replaced outdated macros _PyUnicode_AsString and _PyUnicode_AsStringAndSize with PyUnicode_AsUTF8 and PyUnicode_AsUTF8AndSize. --- Python/pylifecycle.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Python/pylifecycle.c') diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 71f23dd150..a4f7f823bc 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -205,7 +205,7 @@ get_codec_name(const char *encoding) if (!name) goto error; - name_utf8 = _PyUnicode_AsString(name); + name_utf8 = PyUnicode_AsUTF8(name); if (name_utf8 == NULL) goto error; name_str = _PyMem_RawStrdup(name_utf8); @@ -1285,7 +1285,7 @@ initstdio(void) encoding_attr = PyObject_GetAttrString(std, "encoding"); if (encoding_attr != NULL) { const char * std_encoding; - std_encoding = _PyUnicode_AsString(encoding_attr); + std_encoding = PyUnicode_AsUTF8(encoding_attr); if (std_encoding != NULL) { PyObject *codec_info = _PyCodec_Lookup(std_encoding); Py_XDECREF(codec_info); -- cgit v1.2.1