annotate Modules/python.c @ 51902:a5f0371850ff 3.0

Merged revisions 70029 via svnmerge from svn+ssh://svn.python.org/python/branches/py3k ........ r70029 | georg.brandl | 2009-02-27 18:52:38 +0100 (Fr, 27 Feb 2009) | 1 line another instance of #804543: use strdup() when saving the result of setlocale() because it could be overwritten by subsequent setlocale()s. ........
author Georg Brandl <georg@python.org>
date Fri, 27 Feb 2009 17:54:11 +0000
parents 26bc0cd0108b
children ac209f132b17
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
6055
72d004971b26 Keep gcc -Wall happy
Guido van Rossum <guido@python.org>
parents: 5853
diff changeset
17 int
13481
3abecb34737f - ANSI-fication
Fredrik Lundh <fredrik@pythonware.com>
parents: 9601
diff changeset
18 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
19 {
49554
26bc0cd0108b restore compilation on OpenBSD #4146
Benjamin Peterson <benjamin@python.org>
parents: 49467
diff changeset
20 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
21 /* 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
22 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
23 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
24 char *oldloc;
26815
8eccfae04bb4 Apparently FreeBSD enables some HW floating-point exceptions by default.
Tim Peters <tim.peters@gmail.com>
parents: 24471
diff changeset
25 /* 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
26 * 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
27 * 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
28 * 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
29 */
8eccfae04bb4 Apparently FreeBSD enables some HW floating-point exceptions by default.
Tim Peters <tim.peters@gmail.com>
parents: 24471
diff changeset
30 #ifdef __FreeBSD__
8eccfae04bb4 Apparently FreeBSD enables some HW floating-point exceptions by default.
Tim Peters <tim.peters@gmail.com>
parents: 24471
diff changeset
31 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
32
8eccfae04bb4 Apparently FreeBSD enables some HW floating-point exceptions by default.
Tim Peters <tim.peters@gmail.com>
parents: 24471
diff changeset
33 m = fpgetmask();
8eccfae04bb4 Apparently FreeBSD enables some HW floating-point exceptions by default.
Tim Peters <tim.peters@gmail.com>
parents: 24471
diff changeset
34 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
35 #endif
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 26815
diff changeset
36 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
37 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
38 return 1;
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 26815
diff changeset
39 }
51902
a5f0371850ff Merged revisions 70029 via svnmerge from
Georg Brandl <georg@python.org>
parents: 49554
diff changeset
40 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
41 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
42 for (i = 0; i < argc; i++) {
48987
f83dccf417f0 Issue #3696: Error parsing arguments on OpenBSD <= 4.4 and Cygwin.
Antoine Pitrou <solipsis@pitrou.net>
parents: 46318
diff changeset
43 #ifdef HAVE_BROKEN_MBSTOWCS
f83dccf417f0 Issue #3696: Error parsing arguments on OpenBSD <= 4.4 and Cygwin.
Antoine Pitrou <solipsis@pitrou.net>
parents: 46318
diff changeset
44 /* Some platforms have a broken implementation of
f83dccf417f0 Issue #3696: Error parsing arguments on OpenBSD <= 4.4 and Cygwin.
Antoine Pitrou <solipsis@pitrou.net>
parents: 46318
diff changeset
45 * mbstowcs which does not count the characters that
f83dccf417f0 Issue #3696: Error parsing arguments on OpenBSD <= 4.4 and Cygwin.
Antoine Pitrou <solipsis@pitrou.net>
parents: 46318
diff changeset
46 * would result from conversion. Use an upper bound.
f83dccf417f0 Issue #3696: Error parsing arguments on OpenBSD <= 4.4 and Cygwin.
Antoine Pitrou <solipsis@pitrou.net>
parents: 46318
diff changeset
47 */
f83dccf417f0 Issue #3696: Error parsing arguments on OpenBSD <= 4.4 and Cygwin.
Antoine Pitrou <solipsis@pitrou.net>
parents: 46318
diff changeset
48 size_t argsize = strlen(argv[i]);
f83dccf417f0 Issue #3696: Error parsing arguments on OpenBSD <= 4.4 and Cygwin.
Antoine Pitrou <solipsis@pitrou.net>
parents: 46318
diff changeset
49 #else
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 26815
diff changeset
50 size_t argsize = mbstowcs(NULL, argv[i], 0);
48987
f83dccf417f0 Issue #3696: Error parsing arguments on OpenBSD <= 4.4 and Cygwin.
Antoine Pitrou <solipsis@pitrou.net>
parents: 46318
diff changeset
51 #endif
f83dccf417f0 Issue #3696: Error parsing arguments on OpenBSD <= 4.4 and Cygwin.
Antoine Pitrou <solipsis@pitrou.net>
parents: 46318
diff changeset
52 size_t count;
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 26815
diff changeset
53 if (argsize == (size_t)-1) {
49467
1e5b2050ec6a #4004: Missing newline in some startup error messages.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48987
diff changeset
54 fprintf(stderr, "Could not convert argument %d to string\n", i);
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 26815
diff changeset
55 return 1;
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 26815
diff changeset
56 }
49554
26bc0cd0108b restore compilation on OpenBSD #4146
Benjamin Peterson <benjamin@python.org>
parents: 49467
diff changeset
57 argv_copy[i] = (wchar_t *)PyMem_Malloc((argsize+1)*sizeof(wchar_t));
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 26815
diff changeset
58 argv_copy2[i] = argv_copy[i];
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 26815
diff changeset
59 if (!argv_copy[i]) {
49467
1e5b2050ec6a #4004: Missing newline in some startup error messages.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48987
diff changeset
60 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
61 return 1;
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 26815
diff changeset
62 }
48987
f83dccf417f0 Issue #3696: Error parsing arguments on OpenBSD <= 4.4 and Cygwin.
Antoine Pitrou <solipsis@pitrou.net>
parents: 46318
diff changeset
63 count = mbstowcs(argv_copy[i], argv[i], argsize+1);
f83dccf417f0 Issue #3696: Error parsing arguments on OpenBSD <= 4.4 and Cygwin.
Antoine Pitrou <solipsis@pitrou.net>
parents: 46318
diff changeset
64 if (count == (size_t)-1) {
49467
1e5b2050ec6a #4004: Missing newline in some startup error messages.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48987
diff changeset
65 fprintf(stderr, "Could not convert argument %d to string\n", i);
48987
f83dccf417f0 Issue #3696: Error parsing arguments on OpenBSD <= 4.4 and Cygwin.
Antoine Pitrou <solipsis@pitrou.net>
parents: 46318
diff changeset
66 return 1;
f83dccf417f0 Issue #3696: Error parsing arguments on OpenBSD <= 4.4 and Cygwin.
Antoine Pitrou <solipsis@pitrou.net>
parents: 46318
diff changeset
67 }
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 26815
diff changeset
68 }
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 26815
diff changeset
69 setlocale(LC_ALL, oldloc);
51902
a5f0371850ff Merged revisions 70029 via svnmerge from
Georg Brandl <georg@python.org>
parents: 49554
diff changeset
70 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
71 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
72 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
73 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
74 }
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 26815
diff changeset
75 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
76 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
77 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
78 }
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 26815
diff changeset
79 #endif