Mercurial > cpython-lru_cache-weakref
annotate Modules/python.c @ 53767:ac209f132b17
Issue #5915: Implement PEP 383, Non-decodable Bytes in
System Character Interfaces.
| author | Martin v. Löwis <martin@v.loewis.de> |
|---|---|
| date | Tue, 05 May 2009 04:43:17 +0000 |
| parents | a5f0371850ff |
| children | 7c29bfbfd352 |
| 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 | 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 | 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); |
|
ac209f132b17
Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents:
51902
diff
changeset
|
41 if (count != (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
|
42 return res; |
|
ac209f132b17
Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents:
51902
diff
changeset
|
43 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
|
44 } |
|
ac209f132b17
Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents:
51902
diff
changeset
|
45 /* Conversion failed. Fall back to escaping with utf8b. */ |
|
ac209f132b17
Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents:
51902
diff
changeset
|
46 #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
|
47 /* 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
|
48 |
|
ac209f132b17
Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents:
51902
diff
changeset
|
49 /* 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
|
50 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
|
51 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
|
52 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
|
53 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
|
54 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
|
55 out = res; |
|
ac209f132b17
Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents:
51902
diff
changeset
|
56 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
|
57 while (argsize) { |
|
ac209f132b17
Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents:
51902
diff
changeset
|
58 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
|
59 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
|
60 /* 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
|
61 break; |
|
ac209f132b17
Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents:
51902
diff
changeset
|
62 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
|
63 /* 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
|
64 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
|
65 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
|
66 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
|
67 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
|
68 return NULL; |
|
ac209f132b17
Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents:
51902
diff
changeset
|
69 } |
|
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)-1) { |
|
ac209f132b17
Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents:
51902
diff
changeset
|
71 /* 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
|
72 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
|
73 *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
|
74 argsize--; |
|
ac209f132b17
Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents:
51902
diff
changeset
|
75 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
|
76 continue; |
|
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 /* 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
|
79 in += converted; |
|
ac209f132b17
Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents:
51902
diff
changeset
|
80 argsize -= converted; |
|
ac209f132b17
Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents:
51902
diff
changeset
|
81 out++; |
|
ac209f132b17
Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents:
51902
diff
changeset
|
82 } |
|
ac209f132b17
Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents:
51902
diff
changeset
|
83 #else |
|
ac209f132b17
Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents:
51902
diff
changeset
|
84 /* 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
|
85 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
|
86 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
|
87 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
|
88 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
|
89 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
|
90 out = res; |
|
ac209f132b17
Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents:
51902
diff
changeset
|
91 while(*in) |
|
ac209f132b17
Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents:
51902
diff
changeset
|
92 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
|
93 *out++ = *in++; |
|
ac209f132b17
Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents:
51902
diff
changeset
|
94 else |
|
ac209f132b17
Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents:
51902
diff
changeset
|
95 *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
|
96 *out = 0; |
|
ac209f132b17
Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents:
51902
diff
changeset
|
97 #endif |
|
ac209f132b17
Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents:
51902
diff
changeset
|
98 return res; |
|
ac209f132b17
Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents:
51902
diff
changeset
|
99 oom: |
|
ac209f132b17
Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents:
51902
diff
changeset
|
100 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
|
101 return NULL; |
|
ac209f132b17
Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents:
51902
diff
changeset
|
102 } |
|
ac209f132b17
Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents:
51902
diff
changeset
|
103 |
| 6055 | 104 int |
| 13481 | 105 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
|
106 { |
|
49554
26bc0cd0108b
restore compilation on OpenBSD #4146
Benjamin Peterson <benjamin@python.org>
parents:
49467
diff
changeset
|
107 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
|
108 /* 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
|
109 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
|
110 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
|
111 char *oldloc; |
|
26815
8eccfae04bb4
Apparently FreeBSD enables some HW floating-point exceptions by default.
Tim Peters <tim.peters@gmail.com>
parents:
24471
diff
changeset
|
112 /* 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
|
113 * 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
|
114 * 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
|
115 * 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
|
116 */ |
|
8eccfae04bb4
Apparently FreeBSD enables some HW floating-point exceptions by default.
Tim Peters <tim.peters@gmail.com>
parents:
24471
diff
changeset
|
117 #ifdef __FreeBSD__ |
|
8eccfae04bb4
Apparently FreeBSD enables some HW floating-point exceptions by default.
Tim Peters <tim.peters@gmail.com>
parents:
24471
diff
changeset
|
118 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
|
119 |
|
8eccfae04bb4
Apparently FreeBSD enables some HW floating-point exceptions by default.
Tim Peters <tim.peters@gmail.com>
parents:
24471
diff
changeset
|
120 m = fpgetmask(); |
|
8eccfae04bb4
Apparently FreeBSD enables some HW floating-point exceptions by default.
Tim Peters <tim.peters@gmail.com>
parents:
24471
diff
changeset
|
121 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
|
122 #endif |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
26815
diff
changeset
|
123 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
|
124 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
|
125 return 1; |
|
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
26815
diff
changeset
|
126 } |
|
51902
a5f0371850ff
Merged revisions 70029 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49554
diff
changeset
|
127 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
|
128 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
|
129 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
|
130 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
|
131 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
|
132 return 1; |
|
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
26815
diff
changeset
|
133 } |
|
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
26815
diff
changeset
|
134 setlocale(LC_ALL, oldloc); |
|
51902
a5f0371850ff
Merged revisions 70029 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49554
diff
changeset
|
135 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
|
136 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
|
137 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
|
138 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
|
139 } |
|
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
26815
diff
changeset
|
140 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
|
141 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
|
142 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
|
143 } |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
26815
diff
changeset
|
144 #endif |
