Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 739cf4e

Browse files
committed
Py_FrozenMain() now uses _Py_char2wchar() to decode command line arguments, as
done in main()
1 parent b5245be commit 739cf4e

1 file changed

Lines changed: 4 additions & 18 deletions

File tree

Python/frozenmain.c

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,27 +52,13 @@ Py_FrozenMain(int argc, char **argv)
5252
oldloc = setlocale(LC_ALL, NULL);
5353
setlocale(LC_ALL, "");
5454
for (i = 0; i < argc; i++) {
55-
#ifdef HAVE_BROKEN_MBSTOWCS
56-
size_t argsize = strlen(argv[i]);
57-
#else
58-
size_t argsize = mbstowcs(NULL, argv[i], 0);
59-
#endif
60-
size_t count;
61-
if (argsize == (size_t)-1) {
62-
fprintf(stderr, "Could not convert argument %d to string\n", i);
63-
return 1;
64-
}
65-
argv_copy[i] = PyMem_RawMalloc((argsize+1)*sizeof(wchar_t));
66-
argv_copy2[i] = argv_copy[i];
55+
argv_copy[i] = _Py_char2wchar(argv[i], NULL);
6756
if (!argv_copy[i]) {
68-
fprintf(stderr, "out of memory\n");
69-
return 1;
70-
}
71-
count = mbstowcs(argv_copy[i], argv[i], argsize+1);
72-
if (count == (size_t)-1) {
73-
fprintf(stderr, "Could not convert argument %d to string\n", i);
57+
fprintf(stderr, "Unable to decode the command line argument #%i\n",
58+
i + 1);
7459
return 1;
7560
}
61+
argv_copy2[i] = argv_copy[i];
7662
}
7763
setlocale(LC_ALL, oldloc);
7864

0 commit comments

Comments
 (0)