diff -r 20dc8d6430eb Include/pyport.h --- a/Include/pyport.h Mon Feb 10 19:17:46 2014 +0100 +++ b/Include/pyport.h Wed Feb 12 21:25:19 2014 -0500 @@ -856,6 +856,25 @@ #define Py_ULL(x) Py_LL(x##U) #endif +/* The Py_WCSTOK macro provides a uniform interface to the wide + * character tokenizer function. Based on the compiler / environment, + * an appropriate implementation will be chose. + * + * Microsoft does not have a three-argument wcstok, but instead provides + * an equivalent via the wcstok_s(). Borland/Embarcadero provides this + * same wcstok_s() function. MinGW does not have a three-argument + * version, thus we default to the two-argument version. If the + * compiler is not one of the three above, we'll assume that a POSIX- + * like three-argument version is available. + */ +#if defined(_MSC_VER) || defined(__BORLANDC__) +# define Py_WCSTOK(str, tok, state) wcstok_s(str, tok, state) +#elif defined(__MINGW32__) +# define Py_WCSTOK(str, tok, state) wcstok(str, tok) +#else +# define Py_WCSTOK(str, tok, state) wcstok(str, tok, state) +#endif + #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;