summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorKristján Valur Jónsson <kristjan@ccpgames.com>2010-09-27 05:32:54 (GMT)
committerKristján Valur Jónsson <kristjan@ccpgames.com>2010-09-27 05:32:54 (GMT)
commit3b69db27d70f05584b76ece61bb882c26ecfcc68 (patch)
treec02d068991fa7d393ec6a33ab4307d401a90c1f7 /Modules
parent42ef4b1f4c8f07357f7c4e9cb8470f57365b0ffa (diff)
downloadcpython-3b69db27d70f05584b76ece61bb882c26ecfcc68.zip
cpython-3b69db27d70f05584b76ece61bb882c26ecfcc68.tar.gz
cpython-3b69db27d70f05584b76ece61bb882c26ecfcc68.tar.bz2
issue 9910
Add a Py_SetPath api to override magic path computations when starting up python.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/getpath.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/Modules/getpath.c b/Modules/getpath.c
index c55b3d7..6f2e537 100644
--- a/Modules/getpath.c
+++ b/Modules/getpath.c
@@ -90,6 +90,9 @@
* known use of sys.prefix and sys.exec_prefix is for the ILU installation
* process to find the installed Python tree.
*
+ * An embedding application can use Py_SetPath() to override all of
+ * these authomatic path computations.
+ *
* NOTE: Windows MSVC builds use PC/getpathp.c instead!
*/
@@ -771,6 +774,23 @@ 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);
+ exec_prefix[0] = 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)