Create a subfunction for PySys_SetArgvEx()

Create sys_update_path() static function. Do nothing if argc==0.
This commit is contained in:
Victor Stinner 2010-10-06 22:44:06 +00:00
parent 7980eaa98d
commit c08ec9fdba

View file

@ -1686,30 +1686,35 @@ _wrealpath(const wchar_t *path, wchar_t *resolved_path)
(argc > 0 && argv0 != NULL && \ (argc > 0 && argv0 != NULL && \
wcscmp(argv0, L"-c") != 0 && wcscmp(argv0, L"-m") != 0) wcscmp(argv0, L"-c") != 0 && wcscmp(argv0, L"-m") != 0)
void static void
PySys_SetArgvEx(int argc, wchar_t **argv, int updatepath) sys_update_path(int argc, wchar_t **argv)
{ {
wchar_t *argv0;
wchar_t *p = NULL;
Py_ssize_t n = 0;
PyObject *a;
PyObject *path;
#ifdef HAVE_READLINK
extern int _Py_wreadlink(const wchar_t *, wchar_t *, size_t);
wchar_t link[MAXPATHLEN+1];
wchar_t argv0copy[2*MAXPATHLEN+1];
int nr = 0;
#endif
#if defined(HAVE_REALPATH) #if defined(HAVE_REALPATH)
wchar_t fullpath[MAXPATHLEN]; wchar_t fullpath[MAXPATHLEN];
#elif defined(MS_WINDOWS) && !defined(MS_WINCE) #elif defined(MS_WINDOWS) && !defined(MS_WINCE)
wchar_t fullpath[MAX_PATH]; wchar_t fullpath[MAX_PATH];
#endif #endif
PyObject *av = makeargvobject(argc, argv);
PyObject *path = PySys_GetObject("path"); path = PySys_GetObject("path");
if (av == NULL) if (path == NULL)
Py_FatalError("no mem for sys.argv"); return;
if (PySys_SetObject("argv", av) != 0)
Py_FatalError("can't assign sys.argv"); if (argc == 0)
if (updatepath && path != NULL) { return;
wchar_t *argv0 = argv[0]; argv0 = argv[0];
wchar_t *p = NULL;
Py_ssize_t n = 0;
PyObject *a;
extern int _Py_wreadlink(const wchar_t *, wchar_t *, size_t);
#ifdef HAVE_READLINK #ifdef HAVE_READLINK
wchar_t link[MAXPATHLEN+1];
wchar_t argv0copy[2*MAXPATHLEN+1];
int nr = 0;
if (_HAVE_SCRIPT_ARGUMENT(argc, argv)) if (_HAVE_SCRIPT_ARGUMENT(argc, argv))
nr = _Py_wreadlink(argv0, link, MAXPATHLEN); nr = _Py_wreadlink(argv0, link, MAXPATHLEN);
if (nr > 0) { if (nr > 0) {
@ -1783,8 +1788,19 @@ PySys_SetArgvEx(int argc, wchar_t **argv, int updatepath)
if (PyList_Insert(path, 0, a) < 0) if (PyList_Insert(path, 0, a) < 0)
Py_FatalError("sys.path.insert(0) failed"); Py_FatalError("sys.path.insert(0) failed");
Py_DECREF(a); Py_DECREF(a);
} }
void
PySys_SetArgvEx(int argc, wchar_t **argv, int updatepath)
{
PyObject *av = makeargvobject(argc, argv);
if (av == NULL)
Py_FatalError("no mem for sys.argv");
if (PySys_SetObject("argv", av) != 0)
Py_FatalError("can't assign sys.argv");
Py_DECREF(av); Py_DECREF(av);
if (updatepath)
sys_update_path(argc, argv);
} }
void void