summaryrefslogtreecommitdiff
path: root/PC/getpathp.c
diff options
context:
space:
mode:
authorKristján Valur Jónsson <kristjan@ccpgames.com>2010-09-27 05:32:54 +0000
committerKristján Valur Jónsson <kristjan@ccpgames.com>2010-09-27 05:32:54 +0000
commita3bf5120ac424bef95e2d7c87606124aa501a4bd (patch)
treeb8a769937eaaa3694859469da1b71ed3768eada4 /PC/getpathp.c
parent7f77f2db2e3b59453a773e315b08dd6237e7ce49 (diff)
downloadcpython-a3bf5120ac424bef95e2d7c87606124aa501a4bd.tar.gz
issue 9910
Add a Py_SetPath api to override magic path computations when starting up python.
Diffstat (limited to 'PC/getpathp.c')
-rw-r--r--PC/getpathp.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/PC/getpathp.c b/PC/getpathp.c
index 0fe04c7fa4..3a87411d0f 100644
--- a/PC/getpathp.c
+++ b/PC/getpathp.c
@@ -51,6 +51,9 @@
exe, some very strange installation setup) you get a path with
some default, but relative, paths.
+ * An embedding application can use Py_SetPath() to override all of
+ these authomatic path computations.
+
---------------------------------------------------------------- */
@@ -79,6 +82,9 @@
* The approach is an adaptation for Windows of the strategy used in
* ../Modules/getpath.c; it uses the Windows Registry as one of its
* information sources.
+ *
+ * Py_SetPath() can be used to override this mechanism. Call Py_SetPath
+ * with a semicolon separated path prior to calling Py_Initialize.
*/
#ifndef LANDMARK
@@ -654,6 +660,24 @@ calculate_path(void)
/* External interface */
+void
+Py_SetPath(const wchar_t *path)
+{
+ if (module_search_path != NULL) {
+ free(module_search_path);
+ module_search_path = NULL;
+ }
+ if (path != NULL) {
+ extern wchar_t *Py_GetProgramName(void);
+ wchar_t *prog = Py_GetProgramName();
+ wcsncpy(progpath, prog, MAXPATHLEN);
+ prefix[0] = L'\0';
+ module_search_path = malloc((wcslen(path) + 1) * sizeof(wchar_t));
+ if (module_search_path != NULL)
+ wcscpy(module_search_path, path);
+ }
+}
+
wchar_t *
Py_GetPath(void)
{