annotate Modules/python.c @ 84708:4c1945554edb

Fix a compiler warning on FreeBSD Modules/python.c:40: warning: ISO C90 forbids mixed declarations and code
author Victor Stinner <victor.stinner@gmail.com>
date Thu, 18 Jul 2013 02:43:47 +0200
parents b583fd54c8d6
children 386ab2c12301
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 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 54427
diff changeset
14 return Py_Main(argc, argv);
46318
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 {
84490
18bb92b0c458 Issue #18203: Replace malloc() with PyMem_RawMalloc() at Python initialization
Victor Stinner <victor.stinner@gmail.com>
parents: 80706
diff changeset
21 wchar_t **argv_copy;
84530
c02656962b9c #18399: fix comment typo.
R David Murray <rdmurray@bitdance.com>
parents: 80703
diff changeset
22 /* We need a second copy, as Python might modify the first one. */
84490
18bb92b0c458 Issue #18203: Replace malloc() with PyMem_RawMalloc() at Python initialization
Victor Stinner <victor.stinner@gmail.com>
parents: 80706
diff changeset
23 wchar_t **argv_copy2;
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 54427
diff changeset
24 int i, res;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 54427
diff changeset
25 char *oldloc;
84708
4c1945554edb Fix a compiler warning on FreeBSD
Victor Stinner <victor.stinner@gmail.com>
parents: 84531
diff changeset
26 #ifdef __FreeBSD__
4c1945554edb Fix a compiler warning on FreeBSD
Victor Stinner <victor.stinner@gmail.com>
parents: 84531
diff changeset
27 fp_except_t m;
4c1945554edb Fix a compiler warning on FreeBSD
Victor Stinner <victor.stinner@gmail.com>
parents: 84531
diff changeset
28 #endif
84490
18bb92b0c458 Issue #18203: Replace malloc() with PyMem_RawMalloc() at Python initialization
Victor Stinner <victor.stinner@gmail.com>
parents: 80706
diff changeset
29
18bb92b0c458 Issue #18203: Replace malloc() with PyMem_RawMalloc() at Python initialization
Victor Stinner <victor.stinner@gmail.com>
parents: 80706
diff changeset
30 argv_copy = (wchar_t **)PyMem_RawMalloc(sizeof(wchar_t*) * (argc+1));
18bb92b0c458 Issue #18203: Replace malloc() with PyMem_RawMalloc() at Python initialization
Victor Stinner <victor.stinner@gmail.com>
parents: 80706
diff changeset
31 argv_copy2 = (wchar_t **)PyMem_RawMalloc(sizeof(wchar_t*) * (argc+1));
18bb92b0c458 Issue #18203: Replace malloc() with PyMem_RawMalloc() at Python initialization
Victor Stinner <victor.stinner@gmail.com>
parents: 80706
diff changeset
32 if (!argv_copy || !argv_copy2) {
18bb92b0c458 Issue #18203: Replace malloc() with PyMem_RawMalloc() at Python initialization
Victor Stinner <victor.stinner@gmail.com>
parents: 80706
diff changeset
33 fprintf(stderr, "out of memory\n");
18bb92b0c458 Issue #18203: Replace malloc() with PyMem_RawMalloc() at Python initialization
Victor Stinner <victor.stinner@gmail.com>
parents: 80706
diff changeset
34 return 1;
18bb92b0c458 Issue #18203: Replace malloc() with PyMem_RawMalloc() at Python initialization
Victor Stinner <victor.stinner@gmail.com>
parents: 80706
diff changeset
35 }
18bb92b0c458 Issue #18203: Replace malloc() with PyMem_RawMalloc() at Python initialization
Victor Stinner <victor.stinner@gmail.com>
parents: 80706
diff changeset
36
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 54427
diff changeset
37 /* 754 requires that FP exceptions run in "no stop" mode by default,
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 54427
diff changeset
38 * and until C vendors implement C99's ways to control FP exceptions,
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 54427
diff changeset
39 * Python requires non-stop mode. Alas, some platforms enable FP
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 54427
diff changeset
40 * exceptions by default. Here we disable them.
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 54427
diff changeset
41 */
26815
8eccfae04bb4 Apparently FreeBSD enables some HW floating-point exceptions by default.
Tim Peters <tim.peters@gmail.com>
parents: 24471
diff changeset
42 #ifdef __FreeBSD__
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 54427
diff changeset
43 m = fpgetmask();
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 54427
diff changeset
44 fpsetmask(m & ~FP_X_OFL);
26815
8eccfae04bb4 Apparently FreeBSD enables some HW floating-point exceptions by default.
Tim Peters <tim.peters@gmail.com>
parents: 24471
diff changeset
45 #endif
84490
18bb92b0c458 Issue #18203: Replace malloc() with PyMem_RawMalloc() at Python initialization
Victor Stinner <victor.stinner@gmail.com>
parents: 80706
diff changeset
46
84502
65f2c92ed079 Issue #18203: Add _PyMem_RawStrdup() and _PyMem_Strdup()
Victor Stinner <victor.stinner@gmail.com>
parents: 84490
diff changeset
47 oldloc = _PyMem_RawStrdup(setlocale(LC_ALL, NULL));
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 54427
diff changeset
48 setlocale(LC_ALL, "");
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 54427
diff changeset
49 for (i = 0; i < argc; i++) {
65412
3794c9b50824 Add an optional size argument to _Py_char2wchar()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 65277
diff changeset
50 argv_copy[i] = _Py_char2wchar(argv[i], NULL);
74000
3b17210f34d9 main() now displays an error message before exiting if a command line argument
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68257
diff changeset
51 if (!argv_copy[i]) {
84502
65f2c92ed079 Issue #18203: Add _PyMem_RawStrdup() and _PyMem_Strdup()
Victor Stinner <victor.stinner@gmail.com>
parents: 84490
diff changeset
52 PyMem_RawFree(oldloc);
74000
3b17210f34d9 main() now displays an error message before exiting if a command line argument
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68257
diff changeset
53 fprintf(stderr, "Fatal Python error: "
3b17210f34d9 main() now displays an error message before exiting if a command line argument
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68257
diff changeset
54 "unable to decode the command line argument #%i\n",
3b17210f34d9 main() now displays an error message before exiting if a command line argument
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68257
diff changeset
55 i + 1);
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 54427
diff changeset
56 return 1;
74000
3b17210f34d9 main() now displays an error message before exiting if a command line argument
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68257
diff changeset
57 }
65277
49df778889e6 Revert r85435 (and r85440): decode command line arguments from utf-8
Victor Stinner <victor.stinner@haypocalc.com>
parents: 65275
diff changeset
58 argv_copy2[i] = argv_copy[i];
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 54427
diff changeset
59 }
75944
c0900fd6e4b3 Issue #3367: NULL-terminate argv[] copies to prevent an invalid access
Stefan Krah <skrah@bytereef.org>
parents: 74000
diff changeset
60 argv_copy2[argc] = argv_copy[argc] = NULL;
c0900fd6e4b3 Issue #3367: NULL-terminate argv[] copies to prevent an invalid access
Stefan Krah <skrah@bytereef.org>
parents: 74000
diff changeset
61
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 54427
diff changeset
62 setlocale(LC_ALL, oldloc);
84502
65f2c92ed079 Issue #18203: Add _PyMem_RawStrdup() and _PyMem_Strdup()
Victor Stinner <victor.stinner@gmail.com>
parents: 84490
diff changeset
63 PyMem_RawFree(oldloc);
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 54427
diff changeset
64 res = Py_Main(argc, argv_copy);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 54427
diff changeset
65 for (i = 0; i < argc; i++) {
84490
18bb92b0c458 Issue #18203: Replace malloc() with PyMem_RawMalloc() at Python initialization
Victor Stinner <victor.stinner@gmail.com>
parents: 80706
diff changeset
66 PyMem_RawFree(argv_copy2[i]);
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 54427
diff changeset
67 }
84490
18bb92b0c458 Issue #18203: Replace malloc() with PyMem_RawMalloc() at Python initialization
Victor Stinner <victor.stinner@gmail.com>
parents: 80706
diff changeset
68 PyMem_RawFree(argv_copy);
18bb92b0c458 Issue #18203: Replace malloc() with PyMem_RawMalloc() at Python initialization
Victor Stinner <victor.stinner@gmail.com>
parents: 80706
diff changeset
69 PyMem_RawFree(argv_copy2);
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 54427
diff changeset
70 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
71 }
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 26815
diff changeset
72 #endif