Mercurial > cpython-lru_cache-weakref
diff Python/pythonrun.c @ 46318:22a74eaf6b22
Change command line processing API to use wchar_t.
Fixes #2128.
| author | Martin v. Löwis <martin@v.loewis.de> |
|---|---|
| date | Sat, 05 Apr 2008 20:41:37 +0000 |
| parents | e8916c64df4c |
| children | 6196529afd73 |
line wrap: on
line diff
--- a/Python/pythonrun.c Sat Apr 05 19:47:23 2008 +0000 +++ b/Python/pythonrun.c Sat Apr 05 20:41:37 2008 +0000 @@ -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 @@ 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; }
