fix PYTHONWARNINGS handling to not modify the original env value and improve

its tests
This commit is contained in:
Philip Jenvey 2010-04-10 20:27:15 +00:00
parent b60ee469cd
commit cdd98fb463
2 changed files with 18 additions and 10 deletions

View file

@ -421,14 +421,19 @@ Py_Main(int argc, char **argv)
(p = Py_GETENV("PYTHONNOUSERSITE")) && *p != '\0')
Py_NoUserSiteDirectory = 1;
if ((p = Py_GETENV("PYTHONWARNINGS")) && *p != '\0')
{
char* warning = strtok(p, ",");
while (warning != NULL)
{
if ((p = Py_GETENV("PYTHONWARNINGS")) && *p != '\0') {
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, ","))
PySys_AddWarnOption(warning);
warning = strtok(NULL, ",");
}
free(buf);
}
if (command == NULL && module == NULL && _PyOS_optind < argc &&