annotate Modules/python.c @ 60688:fe6b6c189bb4

Move _Py_char2wchar from python.c to main.c. This fixes issue #8441: python.c is not included in the framework while main.c is and without this patch you get a link error when building Python.framework on OSX.
author Ronald Oussoren <ronaldoussoren@mac.com>
date Sun, 18 Apr 2010 14:46:12 +0000
parents c532afb0fa89
children cab14be0ada1
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
6055
72d004971b26 Keep gcc -Wall happy
Guido van Rossum <guido@python.org>
parents: 5853
diff changeset
18 int
13481
3abecb34737f - ANSI-fication
Fredrik Lundh <fredrik@pythonware.com>
parents: 9601
diff changeset
19 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
20 {
49554
26bc0cd0108b restore compilation on OpenBSD #4146
Benjamin Peterson <benjamin@python.org>
parents: 49467
diff changeset
21 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
22 /* 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
23 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
24 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
25 char *oldloc;
26815
8eccfae04bb4 Apparently FreeBSD enables some HW floating-point exceptions by default.
Tim Peters <tim.peters@gmail.com>
parents: 24471
diff changeset
26 /* 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
27 * 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
28 * 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
29 * 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
30 */
8eccfae04bb4 Apparently FreeBSD enables some HW floating-point exceptions by default.
Tim Peters <tim.peters@gmail.com>
parents: 24471
diff changeset
31 #ifdef __FreeBSD__
8eccfae04bb4 Apparently FreeBSD enables some HW floating-point exceptions by default.
Tim Peters <tim.peters@gmail.com>
parents: 24471
diff changeset
32 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
33
8eccfae04bb4 Apparently FreeBSD enables some HW floating-point exceptions by default.
Tim Peters <tim.peters@gmail.com>
parents: 24471
diff changeset
34 m = fpgetmask();
8eccfae04bb4 Apparently FreeBSD enables some HW floating-point exceptions by default.
Tim Peters <tim.peters@gmail.com>
parents: 24471
diff changeset
35 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
36 #endif
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 26815
diff changeset
37 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
38 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
39 return 1;
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 26815
diff changeset
40 }
51902
a5f0371850ff Merged revisions 70029 via svnmerge from
Georg Brandl <georg@python.org>
parents: 49554
diff changeset
41 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
42 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
43 for (i = 0; i < argc; i++) {
60593
62d11785204f #7301: decode $PYTHONWARNINGS in the same way as argv, test non-ascii values
Philip Jenvey <pjenvey@underboss.org>
parents: 54427
diff changeset
44 argv_copy2[i] = argv_copy[i] = _Py_char2wchar(argv[i]);
53767
ac209f132b17 Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents: 51902
diff changeset
45 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
46 return 1;
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 26815
diff changeset
47 }
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 26815
diff changeset
48 setlocale(LC_ALL, oldloc);
51902
a5f0371850ff Merged revisions 70029 via svnmerge from
Georg Brandl <georg@python.org>
parents: 49554
diff changeset
49 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
50 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
51 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
52 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
53 }
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 26815
diff changeset
54 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
55 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
56 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
57 }
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 26815
diff changeset
58 #endif