blob: 18f9b3dd668239c585484f8658b77d707939078a [file] [log] [blame]
Guido van Rossum4c04be61997-07-19 19:25:33 +00001/* Minimal main program -- everything is loaded from the library */
2
Guido van Rossumbe10c201998-08-08 20:01:22 +00003#include "Python.h"
Martin v. Löwis790465f2008-04-05 20:41:37 +00004#include <locale.h>
Guido van Rossumbe10c201998-08-08 20:01:22 +00005
Tim Peters4643bd92002-12-28 21:56:08 +00006#ifdef __FreeBSD__
7#include <floatingpoint.h>
8#endif
9
Martin v. Löwis790465f2008-04-05 20:41:37 +000010#ifdef MS_WINDOWS
11int
12wmain(int argc, wchar_t **argv)
13{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000014 return Py_Main(argc, argv);
Martin v. Löwis790465f2008-04-05 20:41:37 +000015}
16#else
Martin v. Löwis011e8422009-05-05 04:43:17 +000017
Victor Stinnerf933e1a2010-10-20 22:58:25 +000018#ifdef __APPLE__
19extern wchar_t* _Py_DecodeUTF8_surrogateescape(const char *s, Py_ssize_t size);
20#endif
21
Guido van Rossum7c141031997-08-15 02:52:08 +000022int
Fredrik Lundhfaa209d62000-07-09 20:35:15 +000023main(int argc, char **argv)
Guido van Rossum4c04be61997-07-19 19:25:33 +000024{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000025 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 Peters4643bd92002-12-28 21:56:08 +000035#ifdef __FreeBSD__
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000036 fp_except_t m;
Tim Peters4643bd92002-12-28 21:56:08 +000037
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000038 m = fpgetmask();
39 fpsetmask(m & ~FP_X_OFL);
Tim Peters4643bd92002-12-28 21:56:08 +000040#endif
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000041 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 Stinnerf933e1a2010-10-20 22:58:25 +000048#ifdef __APPLE__
49 argv_copy[i] = _Py_DecodeUTF8_surrogateescape(argv[i], strlen(argv[i]));
50#else
Victor Stinner168e1172010-10-16 23:16:16 +000051 argv_copy[i] = _Py_char2wchar(argv[i], NULL);
Victor Stinnerf933e1a2010-10-20 22:58:25 +000052#endif
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000053 if (!argv_copy[i])
54 return 1;
Victor Stinner052a04d2010-10-13 23:24:06 +000055 argv_copy2[i] = argv_copy[i];
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000056 }
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 Rossum4c04be61997-07-19 19:25:33 +000066}
Martin v. Löwis790465f2008-04-05 20:41:37 +000067#endif