diff options
author | Benjamin Peterson <benjamin@python.org> | 2010-04-11 21:16:33 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2010-04-11 21:16:33 (GMT) |
commit | ad6139acc79271fd954d1f138235584a7d66c119 (patch) | |
tree | b3efbb621ab9ef45093788700cecc9cd73c9ad83 /Modules/main.c | |
parent | 75825a7a4c69e9fd609055ae2658de1660f21798 (diff) | |
download | cpython-ad6139acc79271fd954d1f138235584a7d66c119.zip cpython-ad6139acc79271fd954d1f138235584a7d66c119.tar.gz cpython-ad6139acc79271fd954d1f138235584a7d66c119.tar.bz2 |
Merged revisions 79936 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r79936 | philip.jenvey | 2010-04-10 15:27:15 -0500 (Sat, 10 Apr 2010) | 3 lines
fix PYTHONWARNINGS handling to not modify the original env value and improve
its tests
........
Diffstat (limited to 'Modules/main.c')
-rw-r--r-- | Modules/main.c | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/Modules/main.c b/Modules/main.c index 5ae82ef..88912c1 100644 --- a/Modules/main.c +++ b/Modules/main.c @@ -403,22 +403,27 @@ Py_Main(int argc, wchar_t **argv) Py_NoUserSiteDirectory = 1; if ((p = Py_GETENV("PYTHONWARNINGS")) && *p != '\0') { - char *buf; - wchar_t *warning; - size_t len; - - for (buf = strtok(p, ","); - buf != NULL; - buf = strtok(NULL, ",")) { - len = strlen(buf); - warning = (wchar_t *)malloc((len + 1) * sizeof(wchar_t)); - if (warning == NULL) + char *buf, *warning; + + buf = (char *)malloc(strlen(p) + 1); + if (buf == NULL) + Py_FatalError( + "not enough memory to copy PYTHONWARNINGS"); + strcpy(buf, p); + for (warning = strtok(buf, ","); + warning != NULL; + warning = strtok(NULL, ",")) { + wchar_t *wide_warning; + size_t len = strlen(buf); + wide_warning = (wchar_t *)malloc((len + 1) * sizeof(wchar_t)); + if (wide_warning == NULL) Py_FatalError( "not enough memory to copy PYTHONWARNINGS"); - mbstowcs(warning, buf, len); - PySys_AddWarnOption(warning); - free(warning); + mbstowcs(wide_warning, warning, len); + PySys_AddWarnOption(wide_warning); + free(wide_warning); } + free(buf); } if (command == NULL && module == NULL && _PyOS_optind < argc && |