[Python-checkins] cpython (3.3): Issue #15893: frozenmain.c now handles PyMem_Malloc() failure
victor.stinner
python-checkins at python.org
Sat Jul 27 01:06:02 CEST 2013
http://hg.python.org/cpython/rev/ab8121466785
changeset: 84857:ab8121466785
branch: 3.3
parent: 84855:65121aa79ab3
user: Victor Stinner <victor.stinner at gmail.com>
date: Sat Jul 27 01:04:56 2013 +0200
summary:
Issue #15893: frozenmain.c now handles PyMem_Malloc() failure
files:
Modules/python.c | 16 ++++++++++------
Python/frozenmain.c | 11 +++++++++--
2 files changed, 19 insertions(+), 8 deletions(-)
diff --git a/Modules/python.c b/Modules/python.c
--- a/Modules/python.c
+++ b/Modules/python.c
@@ -18,11 +18,19 @@
int
main(int argc, char **argv)
{
- wchar_t **argv_copy = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*(argc+1));
+ wchar_t **argv_copy;
/* We need a second copy, as Python might modify the first one. */
- wchar_t **argv_copy2 = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*(argc+1));
+ wchar_t **argv_copy2;
int i, res;
char *oldloc;
+
+ argv_copy = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*(argc+1));
+ argv_copy2 = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*(argc+1));
+ if (!argv_copy || !argv_copy2) {
+ fprintf(stderr, "out of memory\n");
+ return 1;
+ }
+
/* 754 requires that FP exceptions run in "no stop" mode by default,
* and until C vendors implement C99's ways to control FP exceptions,
* Python requires non-stop mode. Alas, some platforms enable FP
@@ -34,10 +42,6 @@
m = fpgetmask();
fpsetmask(m & ~FP_X_OFL);
#endif
- if (!argv_copy || !argv_copy2) {
- fprintf(stderr, "out of memory\n");
- return 1;
- }
oldloc = strdup(setlocale(LC_ALL, NULL));
setlocale(LC_ALL, "");
for (i = 0; i < argc; i++) {
diff --git a/Python/frozenmain.c b/Python/frozenmain.c
--- a/Python/frozenmain.c
+++ b/Python/frozenmain.c
@@ -20,9 +20,16 @@
int inspect = 0;
int unbuffered = 0;
char *oldloc;
- wchar_t **argv_copy = PyMem_Malloc(sizeof(wchar_t*)*argc);
+ wchar_t **argv_copy;
/* We need a second copies, as Python might modify the first one. */
- wchar_t **argv_copy2 = PyMem_Malloc(sizeof(wchar_t*)*argc);
+ wchar_t **argv_copy2;
+
+ argv_copy = PyMem_Malloc(sizeof(wchar_t*)*argc);
+ argv_copy2 = PyMem_Malloc(sizeof(wchar_t*)*argc);
+ if (!argv_copy || !argv_copy2) {
+ fprintf(stderr, "out of memory\n");
+ return 1;
+ }
Py_FrozenFlag = 1; /* Suppress errors from getpath.c */
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list