@@ -22,6 +22,7 @@ Initialization, Finalization, and Threads
2222 module: sys
2323 triple: module; search; path
2424 single: PySys_SetArgv()
25+ single: PySys_SetArgvEx()
2526 single: Py_Finalize()
2627
2728 Initialize the Python interpreter. In an application embedding Python, this
@@ -31,7 +32,7 @@ Initialization, Finalization, and Threads
3132 the table of loaded modules (``sys.modules ``), and creates the fundamental
3233 modules :mod: `__builtin__ `, :mod: `__main__ ` and :mod: `sys `. It also initializes
3334 the module search path (``sys.path ``). It does not set ``sys.argv ``; use
34- :cfunc: `PySys_SetArgv ` for that. This is a no-op when called for a second time
35+ :cfunc: `PySys_SetArgvEx ` for that. This is a no-op when called for a second time
3536 (without calling :cfunc: `Py_Finalize ` first). There is no return value; it is a
3637 fatal error if the initialization fails.
3738
@@ -338,7 +339,7 @@ Initialization, Finalization, and Threads
338339 ``sys.version ``.
339340
340341
341- .. cfunction :: void PySys_SetArgv (int argc, char **argv)
342+ .. cfunction :: void PySys_SetArgvEx (int argc, char **argv, int updatepath )
342343
343344 .. index ::
344345 single: main()
@@ -353,14 +354,41 @@ Initialization, Finalization, and Threads
353354 string. If this function fails to initialize :data: `sys.argv `, a fatal
354355 condition is signalled using :cfunc: `Py_FatalError `.
355356
356- This function also prepends the executed script's path to :data: `sys.path `.
357- If no script is executed (in the case of calling ``python -c `` or just the
358- interactive interpreter), the empty string is used instead.
357+ If *updatepath * is zero, this is all the function does. If *updatepath *
358+ is non-zero, the function also modifies :data: `sys.path ` according to the
359+ following algorithm:
360+
361+ - If the name of an existing script is passed in ``argv[0] ``, the absolute
362+ path of the directory where the script is located is prepended to
363+ :data: `sys.path `.
364+ - Otherwise (that is, if *argc * is 0 or ``argv[0] `` doesn't point
365+ to an existing file name), an empty string is prepended to
366+ :data: `sys.path `, which is the same as prepending the current working
367+ directory (``"." ``).
368+
369+ .. note ::
370+ It is recommended that applications embedding the Python interpreter
371+ for purposes other than executing a single script pass 0 as *updatepath *,
372+ and update :data: `sys.path ` themselves if desired.
373+ See `CVE-2008-5983 <http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2008-5983 >`_.
374+
375+ On versions before 2.6.6, you can achieve the same effect by manually
376+ popping the first :data: `sys.path ` element after having called
377+ :cfunc: `PySys_SetArgv `, for example using::
378+
379+ PyRun_SimpleString("import sys; sys.path.pop(0)\n");
380+
381+ .. versionadded :: 2.6.6
359382
360383 .. XXX impl. doesn't seem consistent in allowing 0/NULL for the params;
361384 check w/ Guido.
362385
363386
387+ .. cfunction :: void PySys_SetArgv(int argc, char **argv)
388+
389+ This function works like :cfunc: `PySys_SetArgv ` with *updatepath * set to 1.
390+
391+
364392.. cfunction :: void Py_SetPythonHome(char *home)
365393
366394 Set the default "home" directory, that is, the location of the standard
0 commit comments