summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2013-11-16 00:22:04 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2013-11-16 00:22:04 (GMT)
commit72967a4c1ad2b4d17fbaa922e7bda45472f1fe1d (patch)
treecc1d77dc8406dc65e901621f66105394e58b2e0f
parent2a1838b9dfa6f825ee272ec8bef683394e845830 (diff)
downloadcpython-72967a4c1ad2b4d17fbaa922e7bda45472f1fe1d.zip
cpython-72967a4c1ad2b4d17fbaa922e7bda45472f1fe1d.tar.gz
cpython-72967a4c1ad2b4d17fbaa922e7bda45472f1fe1d.tar.bz2
calculate_path() now fails with a fatal error when it fails to allocate memory
for module_search_path. It was already the case on _Py_char2wchar() failure.
-rw-r--r--Modules/getpath.c89
1 files changed, 40 insertions, 49 deletions
diff --git a/Modules/getpath.c b/Modules/getpath.c
index 9980243..9e79c26 100644
--- a/Modules/getpath.c
+++ b/Modules/getpath.c
@@ -134,7 +134,6 @@ static wchar_t prefix[MAXPATHLEN+1];
static wchar_t exec_prefix[MAXPATHLEN+1];
static wchar_t progpath[MAXPATHLEN+1];
static wchar_t *module_search_path = NULL;
-static int module_search_path_malloced = 0;
static void
reduce(wchar_t *dir)
@@ -740,60 +739,55 @@ calculate_path(void)
bufsz += wcslen(zip_path) + 1;
bufsz += wcslen(exec_prefix) + 1;
- buf = (wchar_t *)PyMem_Malloc(bufsz*sizeof(wchar_t));
-
+ buf = (wchar_t *)PyMem_Malloc(bufsz * sizeof(wchar_t));
if (buf == NULL) {
- /* We can't exit, so print a warning and limp along */
- fprintf(stderr, "Not enough memory for dynamic PYTHONPATH.\n");
- fprintf(stderr, "Using default static PYTHONPATH.\n");
- module_search_path = L"" PYTHONPATH;
+ Py_FatalError(
+ "Not enough memory for dynamic PYTHONPATH");
}
- else {
- /* Run-time value of $PYTHONPATH goes first */
- if (rtpypath) {
- wcscpy(buf, rtpypath);
- wcscat(buf, delimiter);
- }
- else
- buf[0] = '\0';
- /* Next is the default zip path */
- wcscat(buf, zip_path);
+ /* Run-time value of $PYTHONPATH goes first */
+ if (rtpypath) {
+ wcscpy(buf, rtpypath);
wcscat(buf, delimiter);
+ }
+ else
+ buf[0] = '\0';
- /* Next goes merge of compile-time $PYTHONPATH with
- * dynamically located prefix.
- */
- defpath = _pythonpath;
- while (1) {
- wchar_t *delim = wcschr(defpath, DELIM);
+ /* Next is the default zip path */
+ wcscat(buf, zip_path);
+ wcscat(buf, delimiter);
- if (defpath[0] != SEP) {
- wcscat(buf, prefix);
- wcscat(buf, separator);
- }
+ /* Next goes merge of compile-time $PYTHONPATH with
+ * dynamically located prefix.
+ */
+ defpath = _pythonpath;
+ while (1) {
+ wchar_t *delim = wcschr(defpath, DELIM);
- if (delim) {
- size_t len = delim - defpath + 1;
- size_t end = wcslen(buf) + len;
- wcsncat(buf, defpath, len);
- *(buf + end) = '\0';
- }
- else {
- wcscat(buf, defpath);
- break;
- }
- defpath = delim + 1;
+ if (defpath[0] != SEP) {
+ wcscat(buf, prefix);
+ wcscat(buf, separator);
}
- wcscat(buf, delimiter);
-
- /* Finally, on goes the directory for dynamic-load modules */
- wcscat(buf, exec_prefix);
- /* And publish the results */
- module_search_path = buf;
- module_search_path_malloced = 1;
+ if (delim) {
+ size_t len = delim - defpath + 1;
+ size_t end = wcslen(buf) + len;
+ wcsncat(buf, defpath, len);
+ *(buf + end) = '\0';
+ }
+ else {
+ wcscat(buf, defpath);
+ break;
+ }
+ defpath = delim + 1;
}
+ wcscat(buf, delimiter);
+
+ /* Finally, on goes the directory for dynamic-load modules */
+ wcscat(buf, exec_prefix);
+
+ /* And publish the results */
+ module_search_path = buf;
/* Reduce prefix and exec_prefix to their essence,
* e.g. /usr/local/lib/python1.5 is reduced to /usr/local.
@@ -834,10 +828,8 @@ void
Py_SetPath(const wchar_t *path)
{
if (module_search_path != NULL) {
- if (module_search_path_malloced)
- PyMem_RawFree(module_search_path);
+ PyMem_RawFree(module_search_path);
module_search_path = NULL;
- module_search_path_malloced = 0;
}
if (path != NULL) {
extern wchar_t *Py_GetProgramName(void);
@@ -845,7 +837,6 @@ Py_SetPath(const wchar_t *path)
wcsncpy(progpath, prog, MAXPATHLEN);
exec_prefix[0] = prefix[0] = L'\0';
module_search_path = PyMem_RawMalloc((wcslen(path) + 1) * sizeof(wchar_t));
- module_search_path_malloced = 1;
if (module_search_path != NULL)
wcscpy(module_search_path, path);
}