~ubuntu-branches/ubuntu/trusty/python3.4/trusty-proposed

« back to all changes in this revision

Viewing changes to Modules/python.c

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2013-11-25 09:44:27 UTC
  • Revision ID: package-import@ubuntu.com-20131125094427-lzxj8ap5w01lmo7f
Tags: upstream-3.4~b1
ImportĀ upstreamĀ versionĀ 3.4~b1

Show diffs side-by-side

added added

removed removed

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