diff -r 20dc8d6430eb Include/pyport.h --- a/Include/pyport.h Mon Feb 10 19:17:46 2014 +0100 +++ b/Include/pyport.h Tue Feb 11 12:25:09 2014 -0500 @@ -856,6 +856,25 @@ #define Py_ULL(x) Py_LL(x##U) #endif +/* There are some variations of wcstok() functionality on Windows. Open + * Watcom provides a POSIX-like wcstok() function, accepting three + * parameters. Microsoft provides an equivalent via the wcstok_s() + * function, which, incidently, is not compatible with Open Watcom's + * wcstok_s() function. If it's neither of the two, default to a simple + * two-argument version (which is all MinGW provides, incidentally). + */ +#ifdef MS_WINDOWS +#ifdef _MSC_VER +#define Py_WCSTOK(x,y,z) wcstok_s(x,y,z) +#else +#ifdef __WATCOMC__ +#define Py_WCSTOK(x,y,z) wcstok(x,y,z) +#else +#define Py_WCSTOK(x,y,z) wcstok(x,y) +#endif /* __WATCOMC__ */ +#endif /* _MSC_VER */ +#endif /* MS_WINDOWS */ + #ifdef VA_LIST_IS_ARRAY #define Py_VA_COPY(x, y) Py_MEMCPY((x), (y), sizeof(va_list)) #else diff -r 20dc8d6430eb Modules/main.c --- a/Modules/main.c Mon Feb 10 19:17:46 2014 +0100 +++ b/Modules/main.c Tue Feb 11 12:25:09 2014 -0500 @@ -511,16 +511,16 @@ #ifdef MS_WINDOWS if (!Py_IgnoreEnvironmentFlag && (wp = _wgetenv(L"PYTHONWARNINGS")) && *wp != L'\0') { - wchar_t *buf, *warning; + wchar_t *buf, *state, *warning; buf = (wchar_t *)PyMem_RawMalloc((wcslen(wp) + 1) * sizeof(wchar_t)); if (buf == NULL) Py_FatalError( "not enough memory to copy PYTHONWARNINGS"); wcscpy(buf, wp); - for (warning = wcstok(buf, L","); + for (warning = Py_WCSTOK(buf, L",", &state); warning != NULL; - warning = wcstok(NULL, L",")) { + warning = Py_WCSTOK(NULL, L",", &state)) { PySys_AddWarnOption(warning); } PyMem_RawFree(buf); diff -r 20dc8d6430eb PC/getpathp.c --- a/PC/getpathp.c Mon Feb 10 19:17:46 2014 +0100 +++ b/PC/getpathp.c Tue Feb 11 12:25:09 2014 -0500 @@ -96,7 +96,6 @@ static wchar_t dllpath[MAXPATHLEN+1]; static wchar_t *module_search_path = NULL; - static int is_sep(wchar_t ch) /* determine if "ch" is a separator character */ { @@ -451,11 +450,12 @@ tmpbuffer, MAXPATHLEN * 2); Py_DECREF(decoded); if (k >= 0) { - wchar_t * tok = wcstok(tmpbuffer, L" \t\r\n"); + wchar_t *state; + wchar_t * tok = Py_WCSTOK(tmpbuffer, L" \t\r\n", &state); if ((tok != NULL) && !wcscmp(tok, key)) { - tok = wcstok(NULL, L" \t"); + tok = Py_WCSTOK(NULL, L" \t", &state); if ((tok != NULL) && !wcscmp(tok, L"=")) { - tok = wcstok(NULL, L"\r\n"); + tok = Py_WCSTOK(NULL, L"\r\n", &state); if (tok != NULL) { wcsncpy(value, tok, MAXPATHLEN); result = 1;