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 | { |
| 14 | return Py_Main(argc, argv); |
| 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 | { |
Benjamin Peterson | 08a8f5f | 2008-10-19 14:15:00 +0000 | [diff] [blame] | 21 | wchar_t **argv_copy = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*argc); |
Martin v. Löwis | 790465f | 2008-04-05 20:41:37 +0000 | [diff] [blame] | 22 | /* We need a second copies, as Python might modify the first one. */ |
Benjamin Peterson | 08a8f5f | 2008-10-19 14:15:00 +0000 | [diff] [blame] | 23 | wchar_t **argv_copy2 = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*argc); |
Martin v. Löwis | 790465f | 2008-04-05 20:41:37 +0000 | [diff] [blame] | 24 | int i, res; |
| 25 | char *oldloc; |
Tim Peters | 4643bd9 | 2002-12-28 21:56:08 +0000 | [diff] [blame] | 26 | /* 754 requires that FP exceptions run in "no stop" mode by default, |
| 27 | * and until C vendors implement C99's ways to control FP exceptions, |
| 28 | * Python requires non-stop mode. Alas, some platforms enable FP |
| 29 | * exceptions by default. Here we disable them. |
| 30 | */ |
| 31 | #ifdef __FreeBSD__ |
| 32 | fp_except_t m; |
| 33 | |
| 34 | m = fpgetmask(); |
| 35 | fpsetmask(m & ~FP_X_OFL); |
| 36 | #endif |
Martin v. Löwis | 790465f | 2008-04-05 20:41:37 +0000 | [diff] [blame] | 37 | if (!argv_copy || !argv_copy2) { |
Amaury Forgeot d'Arc | d0ca955 | 2008-10-07 21:06:18 +0000 | [diff] [blame] | 38 | fprintf(stderr, "out of memory\n"); |
Martin v. Löwis | 790465f | 2008-04-05 20:41:37 +0000 | [diff] [blame] | 39 | return 1; |
| 40 | } |
Georg Brandl | 26338d1 | 2009-02-27 17:52:38 +0000 | [diff] [blame] | 41 | oldloc = strdup(setlocale(LC_ALL, NULL)); |
Martin v. Löwis | 790465f | 2008-04-05 20:41:37 +0000 | [diff] [blame] | 42 | setlocale(LC_ALL, ""); |
| 43 | for (i = 0; i < argc; i++) { |
Philip Jenvey | e53de3d | 2010-04-14 03:01:39 +0000 | [diff] [blame] | 44 | argv_copy2[i] = argv_copy[i] = _Py_char2wchar(argv[i]); |
Martin v. Löwis | 011e842 | 2009-05-05 04:43:17 +0000 | [diff] [blame] | 45 | if (!argv_copy[i]) |
Martin v. Löwis | 790465f | 2008-04-05 20:41:37 +0000 | [diff] [blame] | 46 | return 1; |
Martin v. Löwis | 790465f | 2008-04-05 20:41:37 +0000 | [diff] [blame] | 47 | } |
| 48 | setlocale(LC_ALL, oldloc); |
Georg Brandl | 26338d1 | 2009-02-27 17:52:38 +0000 | [diff] [blame] | 49 | free(oldloc); |
Martin v. Löwis | 790465f | 2008-04-05 20:41:37 +0000 | [diff] [blame] | 50 | res = Py_Main(argc, argv_copy); |
| 51 | for (i = 0; i < argc; i++) { |
| 52 | PyMem_Free(argv_copy2[i]); |
| 53 | } |
| 54 | PyMem_Free(argv_copy); |
| 55 | PyMem_Free(argv_copy2); |
| 56 | return res; |
Guido van Rossum | 4c04be6 | 1997-07-19 19:25:33 +0000 | [diff] [blame] | 57 | } |
Martin v. Löwis | 790465f | 2008-04-05 20:41:37 +0000 | [diff] [blame] | 58 | #endif |