| 1 | n/a | /* Minimal main program -- everything is loaded from the library */ |
|---|
| 2 | n/a | |
|---|
| 3 | n/a | #include "Python.h" |
|---|
| 4 | n/a | #include <locale.h> |
|---|
| 5 | n/a | |
|---|
| 6 | n/a | #ifdef __FreeBSD__ |
|---|
| 7 | n/a | #include <floatingpoint.h> |
|---|
| 8 | n/a | #endif |
|---|
| 9 | n/a | |
|---|
| 10 | n/a | #ifdef MS_WINDOWS |
|---|
| 11 | n/a | int |
|---|
| 12 | n/a | wmain(int argc, wchar_t **argv) |
|---|
| 13 | n/a | { |
|---|
| 14 | n/a | return Py_Main(argc, argv); |
|---|
| 15 | n/a | } |
|---|
| 16 | n/a | #else |
|---|
| 17 | n/a | |
|---|
| 18 | n/a | int |
|---|
| 19 | n/a | main(int argc, char **argv) |
|---|
| 20 | 566 | { |
|---|
| 21 | n/a | wchar_t **argv_copy; |
|---|
| 22 | n/a | /* We need a second copy, as Python might modify the first one. */ |
|---|
| 23 | n/a | wchar_t **argv_copy2; |
|---|
| 24 | n/a | int i, res; |
|---|
| 25 | n/a | char *oldloc; |
|---|
| 26 | n/a | #ifdef __FreeBSD__ |
|---|
| 27 | n/a | fp_except_t m; |
|---|
| 28 | n/a | #endif |
|---|
| 29 | n/a | |
|---|
| 30 | 566 | argv_copy = (wchar_t **)PyMem_RawMalloc(sizeof(wchar_t*) * (argc+1)); |
|---|
| 31 | 566 | argv_copy2 = (wchar_t **)PyMem_RawMalloc(sizeof(wchar_t*) * (argc+1)); |
|---|
| 32 | 566 | if (!argv_copy || !argv_copy2) { |
|---|
| 33 | 0 | fprintf(stderr, "out of memory\n"); |
|---|
| 34 | 0 | return 1; |
|---|
| 35 | n/a | } |
|---|
| 36 | n/a | |
|---|
| 37 | n/a | /* 754 requires that FP exceptions run in "no stop" mode by default, |
|---|
| 38 | n/a | * and until C vendors implement C99's ways to control FP exceptions, |
|---|
| 39 | n/a | * Python requires non-stop mode. Alas, some platforms enable FP |
|---|
| 40 | n/a | * exceptions by default. Here we disable them. |
|---|
| 41 | n/a | */ |
|---|
| 42 | n/a | #ifdef __FreeBSD__ |
|---|
| 43 | n/a | m = fpgetmask(); |
|---|
| 44 | n/a | fpsetmask(m & ~FP_X_OFL); |
|---|
| 45 | n/a | #endif |
|---|
| 46 | n/a | |
|---|
| 47 | 566 | oldloc = _PyMem_RawStrdup(setlocale(LC_ALL, NULL)); |
|---|
| 48 | 566 | if (!oldloc) { |
|---|
| 49 | 0 | fprintf(stderr, "out of memory\n"); |
|---|
| 50 | 0 | return 1; |
|---|
| 51 | n/a | } |
|---|
| 52 | n/a | |
|---|
| 53 | 566 | setlocale(LC_ALL, ""); |
|---|
| 54 | 2930 | for (i = 0; i < argc; i++) { |
|---|
| 55 | 2364 | argv_copy[i] = _Py_char2wchar(argv[i], NULL); |
|---|
| 56 | 2364 | if (!argv_copy[i]) { |
|---|
| 57 | 0 | PyMem_RawFree(oldloc); |
|---|
| 58 | 0 | fprintf(stderr, "Fatal Python error: " |
|---|
| 59 | n/a | "unable to decode the command line argument #%i\n", |
|---|
| 60 | n/a | i + 1); |
|---|
| 61 | 0 | return 1; |
|---|
| 62 | n/a | } |
|---|
| 63 | 2364 | argv_copy2[i] = argv_copy[i]; |
|---|
| 64 | n/a | } |
|---|
| 65 | 566 | argv_copy2[argc] = argv_copy[argc] = NULL; |
|---|
| 66 | n/a | |
|---|
| 67 | 566 | setlocale(LC_ALL, oldloc); |
|---|
| 68 | 566 | PyMem_RawFree(oldloc); |
|---|
| 69 | 566 | res = Py_Main(argc, argv_copy); |
|---|
| 70 | 2165 | for (i = 0; i < argc; i++) { |
|---|
| 71 | 1728 | PyMem_RawFree(argv_copy2[i]); |
|---|
| 72 | n/a | } |
|---|
| 73 | 437 | PyMem_RawFree(argv_copy); |
|---|
| 74 | 437 | PyMem_RawFree(argv_copy2); |
|---|
| 75 | 437 | return res; |
|---|
| 76 | n/a | } |
|---|
| 77 | n/a | #endif |
|---|