annotate Modules/python.c @ 58689:514b56efd89a 3.1

Merged revisions 77962 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/py3k ................ r77962 | r.david.murray | 2010-02-04 11:41:57 -0500 (Thu, 04 Feb 2010) | 17 lines Merged revisions 77943,77959-77960 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r77943 | r.david.murray | 2010-02-03 08:36:23 -0500 (Wed, 03 Feb 2010) | 2 lines Explicitly mention the default value for formatdate's usegmt parameter. ........ r77959 | nick.coghlan | 2010-02-04 07:43:58 -0500 (Thu, 04 Feb 2010) | 1 line Issue 6760: Clarify args handling for subprocess.Popen. Patch by Chris Rebert ........ r77960 | r.david.murray | 2010-02-04 11:33:31 -0500 (Thu, 04 Feb 2010) | 2 lines Add Chris Rebert to ACKS for issue 6760 Popen doc improvements. ........ ................
author R. David Murray <rdmurray@bitdance.com>
date Thu, 04 Feb 2010 16:44:31 +0000
parents ec5d228a83ef
children f197407bdba2 62d11785204f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5853
92bcf4cc9421 This is now the "real" main program -- it calls Py_Main(argc, argv)
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 /* Minimal main program -- everything is loaded from the library */
92bcf4cc9421 This is now the "real" main program -- it calls Py_Main(argc, argv)
Guido van Rossum <guido@python.org>
parents:
diff changeset
2
8894
764de731c806 Now include Python.h
Guido van Rossum <guido@python.org>
parents: 6055
diff changeset
3 #include "Python.h"
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 26815
diff changeset
4 #include <locale.h>
8894
764de731c806 Now include Python.h
Guido van Rossum <guido@python.org>
parents: 6055
diff changeset
5
26815
8eccfae04bb4 Apparently FreeBSD enables some HW floating-point exceptions by default.
Tim Peters <tim.peters@gmail.com>
parents: 24471
diff changeset
6 #ifdef __FreeBSD__
8eccfae04bb4 Apparently FreeBSD enables some HW floating-point exceptions by default.
Tim Peters <tim.peters@gmail.com>
parents: 24471
diff changeset
7 #include <floatingpoint.h>
8eccfae04bb4 Apparently FreeBSD enables some HW floating-point exceptions by default.
Tim Peters <tim.peters@gmail.com>
parents: 24471
diff changeset
8 #endif
8eccfae04bb4 Apparently FreeBSD enables some HW floating-point exceptions by default.
Tim Peters <tim.peters@gmail.com>
parents: 24471
diff changeset
9
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 26815
diff changeset
10 #ifdef MS_WINDOWS
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 26815
diff changeset
11 int
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 26815
diff changeset
12 wmain(int argc, wchar_t **argv)
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 26815
diff changeset
13 {
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 26815
diff changeset
14 return Py_Main(argc, argv);
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 26815
diff changeset
15 }
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 26815
diff changeset
16 #else
53767
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
17 static wchar_t*
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
18 char2wchar(char* arg)
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
19 {
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
20 wchar_t *res;
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
21 #ifdef HAVE_BROKEN_MBSTOWCS
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
22 /* Some platforms have a broken implementation of
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
23 * mbstowcs which does not count the characters that
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
24 * would result from conversion. Use an upper bound.
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
25 */
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
26 size_t argsize = strlen(arg);
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
27 #else
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
28 size_t argsize = mbstowcs(NULL, arg, 0);
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
29 #endif
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
30 size_t count;
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
31 unsigned char *in;
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
32 wchar_t *out;
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
33 #ifdef HAVE_MBRTOWC
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
34 mbstate_t mbs;
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
35 #endif
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
36 if (argsize != (size_t)-1) {
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
37 res = (wchar_t *)PyMem_Malloc((argsize+1)*sizeof(wchar_t));
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
38 if (!res)
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
39 goto oom;
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
40 count = mbstowcs(res, arg, argsize+1);
54427
ec5d228a83ef Issue #6097: Escape UTF-8 surrogates resulting from mbstocs conversion
Martin v. Löwis <martin@v.loewis.de>
parents: 53966
diff changeset
41 if (count != (size_t)-1) {
ec5d228a83ef Issue #6097: Escape UTF-8 surrogates resulting from mbstocs conversion
Martin v. Löwis <martin@v.loewis.de>
parents: 53966
diff changeset
42 wchar_t *tmp;
ec5d228a83ef Issue #6097: Escape UTF-8 surrogates resulting from mbstocs conversion
Martin v. Löwis <martin@v.loewis.de>
parents: 53966
diff changeset
43 /* Only use the result if it contains no
ec5d228a83ef Issue #6097: Escape UTF-8 surrogates resulting from mbstocs conversion
Martin v. Löwis <martin@v.loewis.de>
parents: 53966
diff changeset
44 surrogate characters. */
ec5d228a83ef Issue #6097: Escape UTF-8 surrogates resulting from mbstocs conversion
Martin v. Löwis <martin@v.loewis.de>
parents: 53966
diff changeset
45 for (tmp = res; *tmp != 0 &&
ec5d228a83ef Issue #6097: Escape UTF-8 surrogates resulting from mbstocs conversion
Martin v. Löwis <martin@v.loewis.de>
parents: 53966
diff changeset
46 (*tmp < 0xd800 || *tmp > 0xdfff); tmp++)
ec5d228a83ef Issue #6097: Escape UTF-8 surrogates resulting from mbstocs conversion
Martin v. Löwis <martin@v.loewis.de>
parents: 53966
diff changeset
47 ;
ec5d228a83ef Issue #6097: Escape UTF-8 surrogates resulting from mbstocs conversion
Martin v. Löwis <martin@v.loewis.de>
parents: 53966
diff changeset
48 if (*tmp == 0)
ec5d228a83ef Issue #6097: Escape UTF-8 surrogates resulting from mbstocs conversion
Martin v. Löwis <martin@v.loewis.de>
parents: 53966
diff changeset
49 return res;
ec5d228a83ef Issue #6097: Escape UTF-8 surrogates resulting from mbstocs conversion
Martin v. Löwis <martin@v.loewis.de>
parents: 53966
diff changeset
50 }
53767
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
51 PyMem_Free(res);
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
52 }
53966
7c29bfbfd352 Rename utf8b error handler to surrogateescape.
Martin v. Löwis <martin@v.loewis.de>
parents: 53767
diff changeset
53 /* Conversion failed. Fall back to escaping with surrogateescape. */
53767
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
54 #ifdef HAVE_MBRTOWC
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
55 /* Try conversion with mbrtwoc (C99), and escape non-decodable bytes. */
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
56
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
57 /* Overallocate; as multi-byte characters are in the argument, the
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
58 actual output could use less memory. */
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
59 argsize = strlen(arg) + 1;
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
60 res = PyMem_Malloc(argsize*sizeof(wchar_t));
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
61 if (!res) goto oom;
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
62 in = (unsigned char*)arg;
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
63 out = res;
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
64 memset(&mbs, 0, sizeof mbs);
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
65 while (argsize) {
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
66 size_t converted = mbrtowc(out, (char*)in, argsize, &mbs);
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
67 if (converted == 0)
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
68 /* Reached end of string; null char stored. */
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
69 break;
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
70 if (converted == (size_t)-2) {
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
71 /* Incomplete character. This should never happen,
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
72 since we provide everything that we have -
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
73 unless there is a bug in the C library, or I
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
74 misunderstood how mbrtowc works. */
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
75 fprintf(stderr, "unexpected mbrtowc result -2\n");
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
76 return NULL;
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
77 }
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
78 if (converted == (size_t)-1) {
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
79 /* Conversion error. Escape as UTF-8b, and start over
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
80 in the initial shift state. */
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
81 *out++ = 0xdc00 + *in++;
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
82 argsize--;
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
83 memset(&mbs, 0, sizeof mbs);
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
84 continue;
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
85 }
54427
ec5d228a83ef Issue #6097: Escape UTF-8 surrogates resulting from mbstocs conversion
Martin v. Löwis <martin@v.loewis.de>
parents: 53966
diff changeset
86 if (*out >= 0xd800 && *out <= 0xdfff) {
ec5d228a83ef Issue #6097: Escape UTF-8 surrogates resulting from mbstocs conversion
Martin v. Löwis <martin@v.loewis.de>
parents: 53966
diff changeset
87 /* Surrogate character. Escape the original
ec5d228a83ef Issue #6097: Escape UTF-8 surrogates resulting from mbstocs conversion
Martin v. Löwis <martin@v.loewis.de>
parents: 53966
diff changeset
88 byte sequence with surrogateescape. */
ec5d228a83ef Issue #6097: Escape UTF-8 surrogates resulting from mbstocs conversion
Martin v. Löwis <martin@v.loewis.de>
parents: 53966
diff changeset
89 argsize -= converted;
ec5d228a83ef Issue #6097: Escape UTF-8 surrogates resulting from mbstocs conversion
Martin v. Löwis <martin@v.loewis.de>
parents: 53966
diff changeset
90 while (converted--)
ec5d228a83ef Issue #6097: Escape UTF-8 surrogates resulting from mbstocs conversion
Martin v. Löwis <martin@v.loewis.de>
parents: 53966
diff changeset
91 *out++ = 0xdc00 + *in++;
ec5d228a83ef Issue #6097: Escape UTF-8 surrogates resulting from mbstocs conversion
Martin v. Löwis <martin@v.loewis.de>
parents: 53966
diff changeset
92 continue;
ec5d228a83ef Issue #6097: Escape UTF-8 surrogates resulting from mbstocs conversion
Martin v. Löwis <martin@v.loewis.de>
parents: 53966
diff changeset
93 }
53767
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
94 /* successfully converted some bytes */
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
95 in += converted;
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
96 argsize -= converted;
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
97 out++;
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
98 }
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
99 #else
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
100 /* Cannot use C locale for escaping; manually escape as if charset
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
101 is ASCII (i.e. escape all bytes > 128. This will still roundtrip
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
102 correctly in the locale's charset, which must be an ASCII superset. */
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
103 res = PyMem_Malloc((strlen(arg)+1)*sizeof(wchar_t));
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
104 if (!res) goto oom;
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
105 in = (unsigned char*)arg;
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
106 out = res;
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
107 while(*in)
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
108 if(*in < 128)
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
109 *out++ = *in++;
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
110 else
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
111 *out++ = 0xdc00 + *in++;
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
112 *out = 0;
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
113 #endif
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
114 return res;
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
115 oom:
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
116 fprintf(stderr, "out of memory\n");
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
117 return NULL;
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
118 }
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
119
6055
72d004971b26 Keep gcc -Wall happy
Guido van Rossum <guido@python.org>
parents: 5853
diff changeset
120 int
13481
3abecb34737f - ANSI-fication
Fredrik Lundh <fredrik@pythonware.com>
parents: 9601
diff changeset
121 main(int argc, char **argv)
5853
92bcf4cc9421 This is now the "real" main program -- it calls Py_Main(argc, argv)
Guido van Rossum <guido@python.org>
parents:
diff changeset
122 {
49554
26bc0cd0108b restore compilation on OpenBSD #4146
Benjamin Peterson <benjamin@python.org>
parents: 49467
diff changeset
123 wchar_t **argv_copy = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*argc);
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 26815
diff changeset
124 /* We need a second copies, as Python might modify the first one. */
49554
26bc0cd0108b restore compilation on OpenBSD #4146
Benjamin Peterson <benjamin@python.org>
parents: 49467
diff changeset
125 wchar_t **argv_copy2 = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*argc);
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 26815
diff changeset
126 int i, res;
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 26815
diff changeset
127 char *oldloc;
26815
8eccfae04bb4 Apparently FreeBSD enables some HW floating-point exceptions by default.
Tim Peters <tim.peters@gmail.com>
parents: 24471
diff changeset
128 /* 754 requires that FP exceptions run in "no stop" mode by default,
8eccfae04bb4 Apparently FreeBSD enables some HW floating-point exceptions by default.
Tim Peters <tim.peters@gmail.com>
parents: 24471
diff changeset
129 * and until C vendors implement C99's ways to control FP exceptions,
8eccfae04bb4 Apparently FreeBSD enables some HW floating-point exceptions by default.
Tim Peters <tim.peters@gmail.com>
parents: 24471
diff changeset
130 * Python requires non-stop mode. Alas, some platforms enable FP
8eccfae04bb4 Apparently FreeBSD enables some HW floating-point exceptions by default.
Tim Peters <tim.peters@gmail.com>
parents: 24471
diff changeset
131 * exceptions by default. Here we disable them.
8eccfae04bb4 Apparently FreeBSD enables some HW floating-point exceptions by default.
Tim Peters <tim.peters@gmail.com>
parents: 24471
diff changeset
132 */
8eccfae04bb4 Apparently FreeBSD enables some HW floating-point exceptions by default.
Tim Peters <tim.peters@gmail.com>
parents: 24471
diff changeset
133 #ifdef __FreeBSD__
8eccfae04bb4 Apparently FreeBSD enables some HW floating-point exceptions by default.
Tim Peters <tim.peters@gmail.com>
parents: 24471
diff changeset
134 fp_except_t m;
8eccfae04bb4 Apparently FreeBSD enables some HW floating-point exceptions by default.
Tim Peters <tim.peters@gmail.com>
parents: 24471
diff changeset
135
8eccfae04bb4 Apparently FreeBSD enables some HW floating-point exceptions by default.
Tim Peters <tim.peters@gmail.com>
parents: 24471
diff changeset
136 m = fpgetmask();
8eccfae04bb4 Apparently FreeBSD enables some HW floating-point exceptions by default.
Tim Peters <tim.peters@gmail.com>
parents: 24471
diff changeset
137 fpsetmask(m & ~FP_X_OFL);
8eccfae04bb4 Apparently FreeBSD enables some HW floating-point exceptions by default.
Tim Peters <tim.peters@gmail.com>
parents: 24471
diff changeset
138 #endif
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 26815
diff changeset
139 if (!argv_copy || !argv_copy2) {
49467
1e5b2050ec6a #4004: Missing newline in some startup error messages.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48987
diff changeset
140 fprintf(stderr, "out of memory\n");
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 26815
diff changeset
141 return 1;
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 26815
diff changeset
142 }
51902
a5f0371850ff Merged revisions 70029 via svnmerge from
Georg Brandl <georg@python.org>
parents: 49554
diff changeset
143 oldloc = strdup(setlocale(LC_ALL, NULL));
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 26815
diff changeset
144 setlocale(LC_ALL, "");
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 26815
diff changeset
145 for (i = 0; i < argc; i++) {
53767
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
146 argv_copy2[i] = argv_copy[i] = char2wchar(argv[i]);
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
147 if (!argv_copy[i])
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 26815
diff changeset
148 return 1;
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 26815
diff changeset
149 }
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 26815
diff changeset
150 setlocale(LC_ALL, oldloc);
51902
a5f0371850ff Merged revisions 70029 via svnmerge from
Georg Brandl <georg@python.org>
parents: 49554
diff changeset
151 free(oldloc);
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 26815
diff changeset
152 res = Py_Main(argc, argv_copy);
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 26815
diff changeset
153 for (i = 0; i < argc; i++) {
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 26815
diff changeset
154 PyMem_Free(argv_copy2[i]);
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 26815
diff changeset
155 }
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 26815
diff changeset
156 PyMem_Free(argv_copy);
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 26815
diff changeset
157 PyMem_Free(argv_copy2);
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 26815
diff changeset
158 return res;
5853
92bcf4cc9421 This is now the "real" main program -- it calls Py_Main(argc, argv)
Guido van Rossum <guido@python.org>
parents:
diff changeset
159 }
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 26815
diff changeset
160 #endif