Mercurial > cpython-lru_cache-weakref
comparison Python/frozenmain.c @ 61467:f197407bdba2 3.1
Recorded merge of revisions 81032 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
................
r81032 | antoine.pitrou | 2010-05-09 17:52:27 +0200 (dim., 09 mai 2010) | 9 lines
Recorded merge of revisions 81029 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r81029 | antoine.pitrou | 2010-05-09 16:46:46 +0200 (dim., 09 mai 2010) | 3 lines
Untabify C files. Will watch buildbots.
........
................
| author | Antoine Pitrou <solipsis@pitrou.net> |
|---|---|
| date | Sun, 09 May 2010 16:14:21 +0000 |
| parents | 1e5b2050ec6a |
| children | ab8121466785 |
comparison
equal
deleted
inserted
replaced
| 61459:f8c19c5f5dd2 | 61467:f197407bdba2 |
|---|---|
| 13 /* Main program */ | 13 /* Main program */ |
| 14 | 14 |
| 15 int | 15 int |
| 16 Py_FrozenMain(int argc, char **argv) | 16 Py_FrozenMain(int argc, char **argv) |
| 17 { | 17 { |
| 18 char *p; | 18 char *p; |
| 19 int i, n, sts; | 19 int i, n, sts; |
| 20 int inspect = 0; | 20 int inspect = 0; |
| 21 int unbuffered = 0; | 21 int unbuffered = 0; |
| 22 char *oldloc; | 22 char *oldloc; |
| 23 wchar_t **argv_copy = PyMem_Malloc(sizeof(wchar_t*)*argc); | 23 wchar_t **argv_copy = PyMem_Malloc(sizeof(wchar_t*)*argc); |
| 24 /* We need a second copies, as Python might modify the first one. */ | 24 /* We need a second copies, as Python might modify the first one. */ |
| 25 wchar_t **argv_copy2 = PyMem_Malloc(sizeof(wchar_t*)*argc); | 25 wchar_t **argv_copy2 = PyMem_Malloc(sizeof(wchar_t*)*argc); |
| 26 | 26 |
| 27 Py_FrozenFlag = 1; /* Suppress errors from getpath.c */ | 27 Py_FrozenFlag = 1; /* Suppress errors from getpath.c */ |
| 28 | 28 |
| 29 if ((p = Py_GETENV("PYTHONINSPECT")) && *p != '\0') | 29 if ((p = Py_GETENV("PYTHONINSPECT")) && *p != '\0') |
| 30 inspect = 1; | 30 inspect = 1; |
| 31 if ((p = Py_GETENV("PYTHONUNBUFFERED")) && *p != '\0') | 31 if ((p = Py_GETENV("PYTHONUNBUFFERED")) && *p != '\0') |
| 32 unbuffered = 1; | 32 unbuffered = 1; |
| 33 | 33 |
| 34 if (unbuffered) { | 34 if (unbuffered) { |
| 35 setbuf(stdin, (char *)NULL); | 35 setbuf(stdin, (char *)NULL); |
| 36 setbuf(stdout, (char *)NULL); | 36 setbuf(stdout, (char *)NULL); |
| 37 setbuf(stderr, (char *)NULL); | 37 setbuf(stderr, (char *)NULL); |
| 38 } | 38 } |
| 39 | 39 |
| 40 if (!argv_copy) { | 40 if (!argv_copy) { |
| 41 fprintf(stderr, "out of memory\n"); | 41 fprintf(stderr, "out of memory\n"); |
| 42 return 1; | 42 return 1; |
| 43 } | 43 } |
| 44 | 44 |
| 45 oldloc = setlocale(LC_ALL, NULL); | 45 oldloc = setlocale(LC_ALL, NULL); |
| 46 setlocale(LC_ALL, ""); | 46 setlocale(LC_ALL, ""); |
| 47 for (i = 0; i < argc; i++) { | 47 for (i = 0; i < argc; i++) { |
| 48 #ifdef HAVE_BROKEN_MBSTOWCS | 48 #ifdef HAVE_BROKEN_MBSTOWCS |
| 49 size_t argsize = strlen(argv[i]); | 49 size_t argsize = strlen(argv[i]); |
| 50 #else | 50 #else |
| 51 size_t argsize = mbstowcs(NULL, argv[i], 0); | 51 size_t argsize = mbstowcs(NULL, argv[i], 0); |
| 52 #endif | 52 #endif |
| 53 size_t count; | 53 size_t count; |
| 54 if (argsize == (size_t)-1) { | 54 if (argsize == (size_t)-1) { |
| 55 fprintf(stderr, "Could not convert argument %d to string\n", i); | 55 fprintf(stderr, "Could not convert argument %d to string\n", i); |
| 56 return 1; | 56 return 1; |
| 57 } | 57 } |
| 58 argv_copy[i] = PyMem_Malloc((argsize+1)*sizeof(wchar_t)); | 58 argv_copy[i] = PyMem_Malloc((argsize+1)*sizeof(wchar_t)); |
| 59 argv_copy2[i] = argv_copy[i]; | 59 argv_copy2[i] = argv_copy[i]; |
| 60 if (!argv_copy[i]) { | 60 if (!argv_copy[i]) { |
| 61 fprintf(stderr, "out of memory\n"); | 61 fprintf(stderr, "out of memory\n"); |
| 62 return 1; | 62 return 1; |
| 63 } | 63 } |
| 64 count = mbstowcs(argv_copy[i], argv[i], argsize+1); | 64 count = mbstowcs(argv_copy[i], argv[i], argsize+1); |
| 65 if (count == (size_t)-1) { | 65 if (count == (size_t)-1) { |
| 66 fprintf(stderr, "Could not convert argument %d to string\n", i); | 66 fprintf(stderr, "Could not convert argument %d to string\n", i); |
| 67 return 1; | 67 return 1; |
| 68 } | 68 } |
| 69 } | 69 } |
| 70 setlocale(LC_ALL, oldloc); | 70 setlocale(LC_ALL, oldloc); |
| 71 | 71 |
| 72 #ifdef MS_WINDOWS | 72 #ifdef MS_WINDOWS |
| 73 PyInitFrozenExtensions(); | 73 PyInitFrozenExtensions(); |
| 74 #endif /* MS_WINDOWS */ | 74 #endif /* MS_WINDOWS */ |
| 75 Py_SetProgramName(argv_copy[0]); | 75 Py_SetProgramName(argv_copy[0]); |
| 76 Py_Initialize(); | 76 Py_Initialize(); |
| 77 #ifdef MS_WINDOWS | 77 #ifdef MS_WINDOWS |
| 78 PyWinFreeze_ExeInit(); | 78 PyWinFreeze_ExeInit(); |
| 79 #endif | 79 #endif |
| 80 | 80 |
| 81 if (Py_VerboseFlag) | 81 if (Py_VerboseFlag) |
| 82 fprintf(stderr, "Python %s\n%s\n", | 82 fprintf(stderr, "Python %s\n%s\n", |
| 83 Py_GetVersion(), Py_GetCopyright()); | 83 Py_GetVersion(), Py_GetCopyright()); |
| 84 | 84 |
| 85 PySys_SetArgv(argc, argv_copy); | 85 PySys_SetArgv(argc, argv_copy); |
| 86 | 86 |
| 87 n = PyImport_ImportFrozenModule("__main__"); | 87 n = PyImport_ImportFrozenModule("__main__"); |
| 88 if (n == 0) | 88 if (n == 0) |
| 89 Py_FatalError("__main__ not frozen"); | 89 Py_FatalError("__main__ not frozen"); |
| 90 if (n < 0) { | 90 if (n < 0) { |
| 91 PyErr_Print(); | 91 PyErr_Print(); |
| 92 sts = 1; | 92 sts = 1; |
| 93 } | 93 } |
| 94 else | 94 else |
| 95 sts = 0; | 95 sts = 0; |
| 96 | 96 |
| 97 if (inspect && isatty((int)fileno(stdin))) | 97 if (inspect && isatty((int)fileno(stdin))) |
| 98 sts = PyRun_AnyFile(stdin, "<stdin>") != 0; | 98 sts = PyRun_AnyFile(stdin, "<stdin>") != 0; |
| 99 | 99 |
| 100 #ifdef MS_WINDOWS | 100 #ifdef MS_WINDOWS |
| 101 PyWinFreeze_ExeTerm(); | 101 PyWinFreeze_ExeTerm(); |
| 102 #endif | 102 #endif |
| 103 Py_Finalize(); | 103 Py_Finalize(); |
| 104 for (i = 0; i < argc; i++) { | 104 for (i = 0; i < argc; i++) { |
| 105 PyMem_Free(argv_copy2[i]); | 105 PyMem_Free(argv_copy2[i]); |
| 106 } | 106 } |
| 107 PyMem_Free(argv_copy); | 107 PyMem_Free(argv_copy); |
| 108 PyMem_Free(argv_copy2); | 108 PyMem_Free(argv_copy2); |
| 109 return sts; | 109 return sts; |
| 110 } | 110 } |
