Guido van Rossum | 4c04be6 | 1997-07-19 19:25:33 +0000 | [diff] [blame] | 1 | /* Minimal main program -- everything is loaded from the library */ |
| 2 | |
Guido van Rossum | be10c20 | 1998-08-08 20:01:22 +0000 | [diff] [blame] | 3 | #include "Python.h" |
Martin v. Löwis | 790465f | 2008-04-05 20:41:37 +0000 | [diff] [blame] | 4 | #include <locale.h> |
Guido van Rossum | be10c20 | 1998-08-08 20:01:22 +0000 | [diff] [blame] | 5 | |
Tim Peters | 4643bd9 | 2002-12-28 21:56:08 +0000 | [diff] [blame] | 6 | #ifdef __FreeBSD__ |
| 7 | #include <floatingpoint.h> |
| 8 | #endif |
| 9 | |
Martin v. Löwis | 790465f | 2008-04-05 20:41:37 +0000 | [diff] [blame] | 10 | #ifdef MS_WINDOWS |
| 11 | int |
| 12 | wmain(int argc, wchar_t **argv) |
| 13 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 14 | return Py_Main(argc, argv); |
Martin v. Löwis | 790465f | 2008-04-05 20:41:37 +0000 | [diff] [blame] | 15 | } |
| 16 | #else |
Martin v. Löwis | 011e842 | 2009-05-05 04:43:17 +0000 | [diff] [blame] | 17 | |
Guido van Rossum | 7c14103 | 1997-08-15 02:52:08 +0000 | [diff] [blame] | 18 | int |
Fredrik Lundh | faa209d6 | 2000-07-09 20:35:15 +0000 | [diff] [blame] | 19 | main(int argc, char **argv) |
Guido van Rossum | 4c04be6 | 1997-07-19 19:25:33 +0000 | [diff] [blame] | 20 | { |
Victor Stinner | 1a7425f | 2013-07-07 16:25:15 +0200 | [diff] [blame] | 21 | wchar_t **argv_copy; |
R David Murray | 296b73c | 2013-07-10 10:57:39 -0400 | [diff] [blame] | 22 | /* We need a second copy, as Python might modify the first one. */ |
Victor Stinner | 1a7425f | 2013-07-07 16:25:15 +0200 | [diff] [blame] | 23 | wchar_t **argv_copy2; |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 24 | int i, res; |
| 25 | char *oldloc; |
Victor Stinner | 1a7425f | 2013-07-07 16:25:15 +0200 | [diff] [blame] | 26 | |
| 27 | argv_copy = (wchar_t **)PyMem_RawMalloc(sizeof(wchar_t*) * (argc+1)); |
| 28 | argv_copy2 = (wchar_t **)PyMem_RawMalloc(sizeof(wchar_t*) * (argc+1)); |
| 29 | if (!argv_copy || !argv_copy2) { |
| 30 | fprintf(stderr, "out of memory\n"); |
| 31 | return 1; |
| 32 | } |
| 33 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 34 | /* 754 requires that FP exceptions run in "no stop" mode by default, |
| 35 | * and until C vendors implement C99's ways to control FP exceptions, |
| 36 | * Python requires non-stop mode. Alas, some platforms enable FP |
| 37 | * exceptions by default. Here we disable them. |
| 38 | */ |
Tim Peters | 4643bd9 | 2002-12-28 21:56:08 +0000 | [diff] [blame] | 39 | #ifdef __FreeBSD__ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 40 | fp_except_t m; |
Tim Peters | 4643bd9 | 2002-12-28 21:56:08 +0000 | [diff] [blame] | 41 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 42 | m = fpgetmask(); |
| 43 | fpsetmask(m & ~FP_X_OFL); |
Tim Peters | 4643bd9 | 2002-12-28 21:56:08 +0000 | [diff] [blame] | 44 | #endif |
Victor Stinner | 1a7425f | 2013-07-07 16:25:15 +0200 | [diff] [blame] | 45 | |
Victor Stinner | 49fc8ec | 2013-07-07 23:30:24 +0200 | [diff] [blame] | 46 | oldloc = _PyMem_RawStrdup(setlocale(LC_ALL, NULL)); |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 47 | setlocale(LC_ALL, ""); |
| 48 | for (i = 0; i < argc; i++) { |
Victor Stinner | 168e117 | 2010-10-16 23:16:16 +0000 | [diff] [blame] | 49 | argv_copy[i] = _Py_char2wchar(argv[i], NULL); |
Victor Stinner | 94ba691 | 2011-12-16 23:48:31 +0100 | [diff] [blame] | 50 | if (!argv_copy[i]) { |
Victor Stinner | 49fc8ec | 2013-07-07 23:30:24 +0200 | [diff] [blame] | 51 | PyMem_RawFree(oldloc); |
Victor Stinner | 94ba691 | 2011-12-16 23:48:31 +0100 | [diff] [blame] | 52 | fprintf(stderr, "Fatal Python error: " |
| 53 | "unable to decode the command line argument #%i\n", |
| 54 | i + 1); |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 55 | return 1; |
Victor Stinner | 94ba691 | 2011-12-16 23:48:31 +0100 | [diff] [blame] | 56 | } |
Victor Stinner | 052a04d | 2010-10-13 23:24:06 +0000 | [diff] [blame] | 57 | argv_copy2[i] = argv_copy[i]; |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 58 | } |
Stefan Krah | 0f6ce8d | 2012-03-26 15:05:22 +0200 | [diff] [blame] | 59 | argv_copy2[argc] = argv_copy[argc] = NULL; |
| 60 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 61 | setlocale(LC_ALL, oldloc); |
Victor Stinner | 49fc8ec | 2013-07-07 23:30:24 +0200 | [diff] [blame] | 62 | PyMem_RawFree(oldloc); |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 63 | res = Py_Main(argc, argv_copy); |
| 64 | for (i = 0; i < argc; i++) { |
Victor Stinner | 1a7425f | 2013-07-07 16:25:15 +0200 | [diff] [blame] | 65 | PyMem_RawFree(argv_copy2[i]); |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 66 | } |
Victor Stinner | 1a7425f | 2013-07-07 16:25:15 +0200 | [diff] [blame] | 67 | PyMem_RawFree(argv_copy); |
| 68 | PyMem_RawFree(argv_copy2); |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 69 | return res; |
Guido van Rossum | 4c04be6 | 1997-07-19 19:25:33 +0000 | [diff] [blame] | 70 | } |
Martin v. Löwis | 790465f | 2008-04-05 20:41:37 +0000 | [diff] [blame] | 71 | #endif |