Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Include/pyport.h
Original file line number Diff line number Diff line change
Expand Up @@ -809,4 +809,19 @@ extern _invalid_parameter_handler _Py_silent_invalid_parameter_handler;
#define WITH_THREAD
#endif

/* The _Py_WCSTOK macro provides a uniform interface to the wide
* character tokenizer function. Based on the environment,
* an appropriate implementation will be chosen.
*
* Microsoft does not have a three-argument wcstok, but instead provides
* an equivalent via the wcstok_s(). Borland/Embarcadero and MinGW provide this
* same wcstok_s() function. If MS_WINDOWS is not defined,
* we'll assume that a POSIX-like three-argument version is available.
*/
#if defined(MS_WINDOWS)
# define _Py_WCSTOK(str, tok, state) wcstok_s(str, tok, state)
#else
# define _Py_WCSTOK(str, tok, state) wcstok(str, tok, state)
#endif

#endif /* Py_PYPORT_H */
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
define a platform dependent _Py_WCSTOK in Include/pyport.h
11 changes: 2 additions & 9 deletions Modules/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,6 @@ extern "C" {
? _Py_INIT_USER_ERR("cannot decode " NAME) \
: _Py_INIT_NO_MEMORY())


#ifdef MS_WINDOWS
#define WCSTOK wcstok_s
#else
#define WCSTOK wcstok
#endif

/* For Py_GetArgcArgv(); set by main() */
static wchar_t **orig_argv = NULL;
static int orig_argc = 0;
Expand Down Expand Up @@ -893,9 +886,9 @@ cmdline_init_env_warnoptions(_PyMain *pymain, const _PyCoreConfig *config,


wchar_t *warning, *context = NULL;
for (warning = WCSTOK(env, L",", &context);
for (warning = _Py_WCSTOK(env, L",", &context);
warning != NULL;
warning = WCSTOK(NULL, L",", &context))
warning = _Py_WCSTOK(NULL, L",", &context))
{
_PyInitError err = _Py_wstrlist_append(&cmdline->nenv_warnoption,
&cmdline->env_warnoptions,
Expand Down
6 changes: 3 additions & 3 deletions Python/pathconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -693,11 +693,11 @@ _Py_FindEnvConfigValue(FILE *env_file, const wchar_t *key,
wchar_t *tmpbuffer = _Py_DecodeUTF8_surrogateescape(buffer, n);
if (tmpbuffer) {
wchar_t * state;
wchar_t * tok = wcstok(tmpbuffer, L" \t\r\n", &state);
wchar_t * tok = _Py_WCSTOK(tmpbuffer, L" \t\r\n", &state);
if ((tok != NULL) && !wcscmp(tok, key)) {
tok = wcstok(NULL, L" \t", &state);
tok = _Py_WCSTOK(NULL, L" \t", &state);
if ((tok != NULL) && !wcscmp(tok, L"=")) {
tok = wcstok(NULL, L"\r\n", &state);
tok = _Py_WCSTOK(NULL, L"\r\n", &state);
if (tok != NULL) {
wcsncpy(value, tok, MAXPATHLEN);
result = 1;
Expand Down