Mercurial > cpython-lru_cache-weakref
annotate Modules/python.c @ 58664:993f703a61ba
Merged revisions 77484,77487,77561,77570,77593,77603,77608,77667,77702-77703,77739,77858,77887,77889 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77484 | skip.montanaro | 2010-01-13 19:12:34 -0600 (Wed, 13 Jan 2010) | 4 lines
Update PyEval_EvalFrame to PyEval_EvalFrameEx. This looks to have been done
partially before. Also add a comment describing how this might have to work
with different versions of the interpreter.
........
r77487 | ezio.melotti | 2010-01-14 05:34:10 -0600 (Thu, 14 Jan 2010) | 1 line
Fixed typo
........
r77561 | georg.brandl | 2010-01-17 02:42:30 -0600 (Sun, 17 Jan 2010) | 1 line
#7699: improve datetime docs: straightforward linking to strftime/strptime section, mark classmethods as such.
........
r77570 | georg.brandl | 2010-01-17 06:14:42 -0600 (Sun, 17 Jan 2010) | 1 line
Add note about usage of STRINGLIB_EMPTY.
........
r77593 | georg.brandl | 2010-01-17 17:33:53 -0600 (Sun, 17 Jan 2010) | 1 line
Fix internal reference.
........
r77603 | benjamin.peterson | 2010-01-18 17:07:56 -0600 (Mon, 18 Jan 2010) | 8 lines
data descriptors do not override the class dictionary if __get__ is not defined
Adjust documentation and add a test to verify this behavior.
See http://mail.python.org/pipermail/python-dev/2010-January/095637.html for
discussion.
........
r77608 | gregory.p.smith | 2010-01-19 02:19:03 -0600 (Tue, 19 Jan 2010) | 6 lines
Do not compile stubs for the sha2 series hashes in the openssl hashlib
module when the openssl version is too old to support them. That
leads both compiled code bloat and to unittests attempting to test
implementations that don't exist for comparison purposes on such
platforms.
........
r77667 | mark.dickinson | 2010-01-21 12:32:27 -0600 (Thu, 21 Jan 2010) | 1 line
Add two more test_strtod test values.
........
r77702 | georg.brandl | 2010-01-23 02:43:31 -0600 (Sat, 23 Jan 2010) | 1 line
#7762: fix refcount annotation of PyUnicode_Tailmatch().
........
r77703 | georg.brandl | 2010-01-23 02:47:54 -0600 (Sat, 23 Jan 2010) | 1 line
#7725: fix referencing issue.
........
r77739 | benjamin.peterson | 2010-01-24 21:52:52 -0600 (Sun, 24 Jan 2010) | 1 line
mention from_float() in error message
........
r77858 | georg.brandl | 2010-01-30 11:57:48 -0600 (Sat, 30 Jan 2010) | 1 line
#7802: fix invalid example (heh).
........
r77887 | georg.brandl | 2010-01-31 12:51:49 -0600 (Sun, 31 Jan 2010) | 5 lines
Fix-up ftplib documentation:
move exception descriptions to toplevel, not inside a class
remove attribution in "versionadded"
spell and grammar check docstring of FTP_TLS
........
r77889 | michael.foord | 2010-01-31 13:59:26 -0600 (Sun, 31 Jan 2010) | 1 line
Minor modification to unittest documentation.
........
| author | Benjamin Peterson <benjamin@python.org> |
|---|---|
| date | Wed, 03 Feb 2010 02:35:45 +0000 |
| parents | ec5d228a83ef |
| children | f197407bdba2 62d11785204f |
| 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); |
|
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 | 120 int |
| 13481 | 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 |
