summaryrefslogtreecommitdiffstats
path: root/Python/pythonrun.c
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2008-04-05 20:41:37 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2008-04-05 20:41:37 (GMT)
commit790465fd90e8a72590386465f518db9e67ab843f (patch)
tree62e3e47f6f97120dfdfc94a87dc1a06414d95a13 /Python/pythonrun.c
parentb9279bc88f867d9d3b6606502a678b137329b54d (diff)
downloadcpython-790465fd90e8a72590386465f518db9e67ab843f.zip
cpython-790465fd90e8a72590386465f518db9e67ab843f.tar.gz
cpython-790465fd90e8a72590386465f518db9e67ab843f.tar.bz2
Change command line processing API to use wchar_t.
Fixes #2128.
Diffstat (limited to 'Python/pythonrun.c')
-rw-r--r--Python/pythonrun.c30
1 files changed, 20 insertions, 10 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index 3207fb8..124eaf0 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -17,6 +17,7 @@
#include "ast.h"
#include "eval.h"
#include "marshal.h"
+#include "osdefs.h"
#ifdef HAVE_SIGNAL_H
#include <signal.h>
@@ -30,6 +31,7 @@
#ifdef MS_WINDOWS
#undef BYTE
#include "windows.h"
+#define PATH_MAX MAXPATHLEN
#endif
#ifndef Py_REF_DEBUG
@@ -44,7 +46,7 @@
extern "C" {
#endif
-extern char *Py_GetPath(void);
+extern wchar_t *Py_GetPath(void);
extern grammar _PyParser_Grammar; /* From graminit.c */
@@ -646,35 +648,43 @@ Py_EndInterpreter(PyThreadState *tstate)
PyInterpreterState_Delete(interp);
}
-static char *progname = "python";
+static wchar_t *progname = L"python";
void
-Py_SetProgramName(char *pn)
+Py_SetProgramName(wchar_t *pn)
{
if (pn && *pn)
progname = pn;
}
-char *
+wchar_t *
Py_GetProgramName(void)
{
return progname;
}
-static char *default_home = NULL;
+static wchar_t *default_home = NULL;
+static wchar_t env_home[PATH_MAX+1];
void
-Py_SetPythonHome(char *home)
+Py_SetPythonHome(wchar_t *home)
{
default_home = home;
}
-char *
+wchar_t *
Py_GetPythonHome(void)
{
- char *home = default_home;
- if (home == NULL && !Py_IgnoreEnvironmentFlag)
- home = Py_GETENV("PYTHONHOME");
+ wchar_t *home = default_home;
+ if (home == NULL && !Py_IgnoreEnvironmentFlag) {
+ char* chome = Py_GETENV("PYTHONHOME");
+ if (chome) {
+ size_t r = mbstowcs(env_home, chome, PATH_MAX+1);
+ if (r != (size_t)-1 && r <= PATH_MAX)
+ home = env_home;
+ }
+
+ }
return home;
}