Mercurial > cpython-lru_cache-weakref
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 46316:4352d41affb0 | 46318:22a74eaf6b22 |
|---|---|
| 15 #include "symtable.h" | 15 #include "symtable.h" |
| 16 #include "pyarena.h" | 16 #include "pyarena.h" |
| 17 #include "ast.h" | 17 #include "ast.h" |
| 18 #include "eval.h" | 18 #include "eval.h" |
| 19 #include "marshal.h" | 19 #include "marshal.h" |
| 20 #include "osdefs.h" | |
| 20 | 21 |
| 21 #ifdef HAVE_SIGNAL_H | 22 #ifdef HAVE_SIGNAL_H |
| 22 #include <signal.h> | 23 #include <signal.h> |
| 23 #endif | 24 #endif |
| 24 | 25 |
| 28 #endif | 29 #endif |
| 29 | 30 |
| 30 #ifdef MS_WINDOWS | 31 #ifdef MS_WINDOWS |
| 31 #undef BYTE | 32 #undef BYTE |
| 32 #include "windows.h" | 33 #include "windows.h" |
| 34 #define PATH_MAX MAXPATHLEN | |
| 33 #endif | 35 #endif |
| 34 | 36 |
| 35 #ifndef Py_REF_DEBUG | 37 #ifndef Py_REF_DEBUG |
| 36 #define PRINT_TOTAL_REFS() | 38 #define PRINT_TOTAL_REFS() |
| 37 #else /* Py_REF_DEBUG */ | 39 #else /* Py_REF_DEBUG */ |
| 42 | 44 |
| 43 #ifdef __cplusplus | 45 #ifdef __cplusplus |
| 44 extern "C" { | 46 extern "C" { |
| 45 #endif | 47 #endif |
| 46 | 48 |
| 47 extern char *Py_GetPath(void); | 49 extern wchar_t *Py_GetPath(void); |
| 48 | 50 |
| 49 extern grammar _PyParser_Grammar; /* From graminit.c */ | 51 extern grammar _PyParser_Grammar; /* From graminit.c */ |
| 50 | 52 |
| 51 /* Forward */ | 53 /* Forward */ |
| 52 static void initmain(void); | 54 static void initmain(void); |
| 644 PyInterpreterState_Clear(interp); | 646 PyInterpreterState_Clear(interp); |
| 645 PyThreadState_Swap(NULL); | 647 PyThreadState_Swap(NULL); |
| 646 PyInterpreterState_Delete(interp); | 648 PyInterpreterState_Delete(interp); |
| 647 } | 649 } |
| 648 | 650 |
| 649 static char *progname = "python"; | 651 static wchar_t *progname = L"python"; |
| 650 | 652 |
| 651 void | 653 void |
| 652 Py_SetProgramName(char *pn) | 654 Py_SetProgramName(wchar_t *pn) |
| 653 { | 655 { |
| 654 if (pn && *pn) | 656 if (pn && *pn) |
| 655 progname = pn; | 657 progname = pn; |
| 656 } | 658 } |
| 657 | 659 |
| 658 char * | 660 wchar_t * |
| 659 Py_GetProgramName(void) | 661 Py_GetProgramName(void) |
| 660 { | 662 { |
| 661 return progname; | 663 return progname; |
| 662 } | 664 } |
| 663 | 665 |
| 664 static char *default_home = NULL; | 666 static wchar_t *default_home = NULL; |
| 667 static wchar_t env_home[PATH_MAX+1]; | |
| 665 | 668 |
| 666 void | 669 void |
| 667 Py_SetPythonHome(char *home) | 670 Py_SetPythonHome(wchar_t *home) |
| 668 { | 671 { |
| 669 default_home = home; | 672 default_home = home; |
| 670 } | 673 } |
| 671 | 674 |
| 672 char * | 675 wchar_t * |
| 673 Py_GetPythonHome(void) | 676 Py_GetPythonHome(void) |
| 674 { | 677 { |
| 675 char *home = default_home; | 678 wchar_t *home = default_home; |
| 676 if (home == NULL && !Py_IgnoreEnvironmentFlag) | 679 if (home == NULL && !Py_IgnoreEnvironmentFlag) { |
| 677 home = Py_GETENV("PYTHONHOME"); | 680 char* chome = Py_GETENV("PYTHONHOME"); |
| 681 if (chome) { | |
| 682 size_t r = mbstowcs(env_home, chome, PATH_MAX+1); | |
| 683 if (r != (size_t)-1 && r <= PATH_MAX) | |
| 684 home = env_home; | |
| 685 } | |
| 686 | |
| 687 } | |
| 678 return home; | 688 return home; |
| 679 } | 689 } |
| 680 | 690 |
| 681 /* Create __main__ module */ | 691 /* Create __main__ module */ |
| 682 | 692 |
