Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2ebf8ce

Browse files
committed
Merged revisions 81881-81882 via svnmerge from
svn+ssh://[email protected]/python/trunk ........ r81881 | andrew.kuchling | 2010-06-10 19:16:08 -0500 (Thu, 10 Jun 2010) | 1 line #5753: update demo.c to use PySys_SetArgvEx(), and add a comment ........ r81882 | andrew.kuchling | 2010-06-10 19:23:01 -0500 (Thu, 10 Jun 2010) | 1 line #5753: Suggest PySys_SetArgvEx() instead of PySys_SetArgv() ........
1 parent 3e5cd1d commit 2ebf8ce

2 files changed

Lines changed: 16 additions & 7 deletions

File tree

Demo/embed/demo.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,19 @@ main(int argc, char **argv)
2020
Py_Initialize();
2121

2222
/* Define sys.argv. It is up to the application if you
23-
want this; you can also let it undefined (since the Python
23+
want this; you can also leave it undefined (since the Python
2424
code is generally not a main program it has no business
25-
touching sys.argv...) */
26-
PySys_SetArgv(2, args);
25+
touching sys.argv...)
26+
27+
If the third argument is true, sys.path is modified to include
28+
either the directory containing the script named by argv[0], or
29+
the current working directory. This can be risky; if you run
30+
an application embedding Python in a directory controlled by
31+
someone else, attackers could put a Trojan-horse module in the
32+
directory (say, a file named os.py) that your application would
33+
then import and run.
34+
*/
35+
PySys_SetArgvEx(argc, argv, 0);
2736

2837
/* Do some application specific code */
2938
printf("Hello, brave new world\n\n");

Doc/c-api/intro.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -519,12 +519,12 @@ the table of loaded modules, and creates the fundamental modules
519519
:mod:`builtins`, :mod:`__main__`, :mod:`sys`, and :mod:`exceptions`. It also
520520
initializes the module search path (``sys.path``).
521521

522-
.. index:: single: PySys_SetArgv()
522+
.. index:: single: PySys_SetArgvEx()
523523

524524
:cfunc:`Py_Initialize` does not set the "script argument list" (``sys.argv``).
525-
If this variable is needed by Python code that will be executed later, it must
526-
be set explicitly with a call to ``PySys_SetArgv(argc, argv)`` subsequent to
527-
the call to :cfunc:`Py_Initialize`.
525+
If this variable is needed by Python code that will be executed later, it must
526+
be set explicitly with a call to ``PySys_SetArgvEx(argc, argv, updatepath)``
527+
after the call to :cfunc:`Py_Initialize`.
528528

529529
On most systems (in particular, on Unix and Windows, although the details are
530530
slightly different), :cfunc:`Py_Initialize` calculates the module search path

0 commit comments

Comments
 (0)