[Python-checkins] cpython: Py_FrozenMain() now uses _Py_char2wchar() to decode command line arguments, as

victor.stinner python-checkins at python.org
Sat Jul 27 02:39:51 CEST 2013


http://hg.python.org/cpython/rev/0001c4100823
changeset:   84860:0001c4100823
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Sat Jul 27 02:24:52 2013 +0200
summary:
  Py_FrozenMain() now uses _Py_char2wchar() to decode command line arguments, as
done in main()

files:
  Python/frozenmain.c |  22 ++++------------------
  1 files changed, 4 insertions(+), 18 deletions(-)


diff --git a/Python/frozenmain.c b/Python/frozenmain.c
--- a/Python/frozenmain.c
+++ b/Python/frozenmain.c
@@ -52,27 +52,13 @@
     oldloc = setlocale(LC_ALL, NULL);
     setlocale(LC_ALL, "");
     for (i = 0; i < argc; i++) {
-#ifdef HAVE_BROKEN_MBSTOWCS
-        size_t argsize = strlen(argv[i]);
-#else
-        size_t argsize = mbstowcs(NULL, argv[i], 0);
-#endif
-        size_t count;
-        if (argsize == (size_t)-1) {
-            fprintf(stderr, "Could not convert argument %d to string\n", i);
+        argv_copy[i] = _Py_char2wchar(argv[i], NULL);
+        if (!argv_copy[i]) {
+            fprintf(stderr, "Unable to decode the command line argument #%i\n",
+                            i + 1);
             return 1;
         }
-        argv_copy[i] = PyMem_RawMalloc((argsize+1)*sizeof(wchar_t));
         argv_copy2[i] = argv_copy[i];
-        if (!argv_copy[i]) {
-            fprintf(stderr, "out of memory\n");
-            return 1;
-        }
-        count = mbstowcs(argv_copy[i], argv[i], argsize+1);
-        if (count == (size_t)-1) {
-            fprintf(stderr, "Could not convert argument %d to string\n", i);
-            return 1;
-        }
     }
     setlocale(LC_ALL, oldloc);
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list