summaryrefslogtreecommitdiffstats
path: root/Modules/python.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2013-07-07 14:25:15 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2013-07-07 14:25:15 (GMT)
commit1a7425f67a0d141483d89ca80ca01e3cb7f6be92 (patch)
treec5c3db81a3f0b754d3c7d2cfafd8609cba58142a /Modules/python.c
parent51fa458d0a8fa6e9f583fc5a1c4164080093e763 (diff)
downloadcpython-1a7425f67a0d141483d89ca80ca01e3cb7f6be92.zip
cpython-1a7425f67a0d141483d89ca80ca01e3cb7f6be92.tar.gz
cpython-1a7425f67a0d141483d89ca80ca01e3cb7f6be92.tar.bz2
Issue #18203: Replace malloc() with PyMem_RawMalloc() at Python initialization
* Replace malloc() with PyMem_RawMalloc() * Replace PyMem_Malloc() with PyMem_RawMalloc() where the GIL is not held. * _Py_char2wchar() now returns a buffer allocated by PyMem_RawMalloc(), instead of PyMem_Malloc()
Diffstat (limited to 'Modules/python.c')
-rw-r--r--Modules/python.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/Modules/python.c b/Modules/python.c
index 2c08b96..aaa7fcf 100644
--- a/Modules/python.c
+++ b/Modules/python.c
@@ -18,11 +18,19 @@ wmain(int argc, wchar_t **argv)
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 copies, 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_RawMalloc(sizeof(wchar_t*) * (argc+1));
+ argv_copy2 = (wchar_t **)PyMem_RawMalloc(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,7 @@ main(int argc, char **argv)
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++) {
@@ -57,10 +62,10 @@ main(int argc, char **argv)
free(oldloc);
res = Py_Main(argc, argv_copy);
for (i = 0; i < argc; i++) {
- PyMem_Free(argv_copy2[i]);
+ PyMem_RawFree(argv_copy2[i]);
}
- PyMem_Free(argv_copy);
- PyMem_Free(argv_copy2);
+ PyMem_RawFree(argv_copy);
+ PyMem_RawFree(argv_copy2);
return res;
}
#endif