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 | |
Victor Stinner | f933e1a | 2010-10-20 22:58:25 +0000 | [diff] [blame] | 18 | #ifdef __APPLE__ |
| 19 | extern wchar_t* _Py_DecodeUTF8_surrogateescape(const char *s, Py_ssize_t size); |
| 20 | #endif |
| 21 | |
Guido van Rossum | 7c14103 | 1997-08-15 02:52:08 +0000 | [diff] [blame] | 22 | int |
Fredrik Lundh | faa209d6 | 2000-07-09 20:35:15 +0000 | [diff] [blame] | 23 | main(int argc, char **argv) |
Guido van Rossum | 4c04be6 | 1997-07-19 19:25:33 +0000 | [diff] [blame] | 24 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 25 | wchar_t **argv_copy = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*argc); |
| 26 | /* We need a second copies, as Python might modify the first one. */ |
| 27 | wchar_t **argv_copy2 = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*argc); |
| 28 | int i, res; |
| 29 | char *oldloc; |
| 30 | /* 754 requires that FP exceptions run in "no stop" mode by default, |
| 31 | * and until C vendors implement C99's ways to control FP exceptions, |
| 32 | * Python requires non-stop mode. Alas, some platforms enable FP |
| 33 | * exceptions by default. Here we disable them. |
| 34 | */ |
Tim Peters | 4643bd9 | 2002-12-28 21:56:08 +0000 | [diff] [blame] | 35 | #ifdef __FreeBSD__ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 36 | fp_except_t m; |
Tim Peters | 4643bd9 | 2002-12-28 21:56:08 +0000 | [diff] [blame] | 37 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 38 | m = fpgetmask(); |
| 39 | fpsetmask(m & ~FP_X_OFL); |
Tim Peters | 4643bd9 | 2002-12-28 21:56:08 +0000 | [diff] [blame] | 40 | #endif |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 41 | if (!argv_copy || !argv_copy2) { |
| 42 | fprintf(stderr, "out of memory\n"); |
| 43 | return 1; |
| 44 | } |
| 45 | oldloc = strdup(setlocale(LC_ALL, NULL)); |
| 46 | setlocale(LC_ALL, ""); |
| 47 | for (i = 0; i < argc; i++) { |
Victor Stinner | f933e1a | 2010-10-20 22:58:25 +0000 | [diff] [blame] | 48 | #ifdef __APPLE__ |
| 49 | argv_copy[i] = _Py_DecodeUTF8_surrogateescape(argv[i], strlen(argv[i])); |
| 50 | #else |
Victor Stinner | 168e117 | 2010-10-16 23:16:16 +0000 | [diff] [blame] | 51 | argv_copy[i] = _Py_char2wchar(argv[i], NULL); |
Victor Stinner | f933e1a | 2010-10-20 22:58:25 +0000 | [diff] [blame] | 52 | #endif |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 53 | if (!argv_copy[i]) |
| 54 | return 1; |
Victor Stinner | 052a04d | 2010-10-13 23:24:06 +0000 | [diff] [blame] | 55 | argv_copy2[i] = argv_copy[i]; |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 56 | } |
| 57 | setlocale(LC_ALL, oldloc); |
| 58 | free(oldloc); |
| 59 | res = Py_Main(argc, argv_copy); |
| 60 | for (i = 0; i < argc; i++) { |
| 61 | PyMem_Free(argv_copy2[i]); |
| 62 | } |
| 63 | PyMem_Free(argv_copy); |
| 64 | PyMem_Free(argv_copy2); |
| 65 | return res; |
Guido van Rossum | 4c04be6 | 1997-07-19 19:25:33 +0000 | [diff] [blame] | 66 | } |
Martin v. Löwis | 790465f | 2008-04-05 20:41:37 +0000 | [diff] [blame] | 67 | #endif |