comparison Modules/python.c @ 48987:f83dccf417f0

Issue #3696: Error parsing arguments on OpenBSD <= 4.4 and Cygwin. Patch by Amaury Forgeot d'Arc, reviewed by me.
author Antoine Pitrou <solipsis@pitrou.net>
date Wed, 03 Sep 2008 18:58:51 +0000
parents 22a74eaf6b22
children 1e5b2050ec6a
comparison
equal deleted inserted replaced
48986:22ab106e3186 48987:f83dccf417f0
38 return 1; 38 return 1;
39 } 39 }
40 oldloc = setlocale(LC_ALL, NULL); 40 oldloc = setlocale(LC_ALL, NULL);
41 setlocale(LC_ALL, ""); 41 setlocale(LC_ALL, "");
42 for (i = 0; i < argc; i++) { 42 for (i = 0; i < argc; i++) {
43 #ifdef HAVE_BROKEN_MBSTOWCS
44 /* Some platforms have a broken implementation of
45 * mbstowcs which does not count the characters that
46 * would result from conversion. Use an upper bound.
47 */
48 size_t argsize = strlen(argv[i]);
49 #else
43 size_t argsize = mbstowcs(NULL, argv[i], 0); 50 size_t argsize = mbstowcs(NULL, argv[i], 0);
51 #endif
52 size_t count;
44 if (argsize == (size_t)-1) { 53 if (argsize == (size_t)-1) {
45 fprintf(stderr, "Could not convert argument %d to string", i); 54 fprintf(stderr, "Could not convert argument %d to string", i);
46 return 1; 55 return 1;
47 } 56 }
48 argv_copy[i] = PyMem_Malloc((argsize+1)*sizeof(wchar_t)); 57 argv_copy[i] = PyMem_Malloc((argsize+1)*sizeof(wchar_t));
49 argv_copy2[i] = argv_copy[i]; 58 argv_copy2[i] = argv_copy[i];
50 if (!argv_copy[i]) { 59 if (!argv_copy[i]) {
51 fprintf(stderr, "out of memory"); 60 fprintf(stderr, "out of memory");
52 return 1; 61 return 1;
53 } 62 }
54 mbstowcs(argv_copy[i], argv[i], argsize+1); 63 count = mbstowcs(argv_copy[i], argv[i], argsize+1);
64 if (count == (size_t)-1) {
65 fprintf(stderr, "Could not convert argument %d to string", i);
66 return 1;
67 }
55 } 68 }
56 setlocale(LC_ALL, oldloc); 69 setlocale(LC_ALL, oldloc);
57 res = Py_Main(argc, argv_copy); 70 res = Py_Main(argc, argv_copy);
58 for (i = 0; i < argc; i++) { 71 for (i = 0; i < argc; i++) {
59 PyMem_Free(argv_copy2[i]); 72 PyMem_Free(argv_copy2[i]);