Fix three PyChecker-detected gotchas.
[python/dscho.git] / Mac / Demo / embed / demo.c
bloba23c249b05065b37e7c5ea3e21ed02d4090bd8e9
1 /* Example of embedding Python in another program */
3 #include "Python.h"
4 #ifdef macintosh
5 #include "macglue.h"
6 #include <SIOUX.h>
7 #endif /* macintosh */
9 static char *argv0;
11 main(argc, argv)
12 int argc;
13 char **argv;
15 #ifdef macintosh
16 /* So the user can set argc/argv to something interesting */
17 argc = ccommand(&argv);
18 #endif
19 /* Save a copy of argv0 */
20 argv0 = argv[0];
22 /* Initialize the Python interpreter. Required. */
23 #ifdef macintosh
24 PyMac_Initialize();
25 #else
26 Py_Initialize();
27 #endif
29 /* Define sys.argv. It is up to the application if you
30 want this; you can also let it undefined (since the Python
31 code is generally not a main program it has no business
32 touching sys.argv...) */
33 PySys_SetArgv(argc, argv);
35 /* Do some application specific code */
36 printf("Hello, brave new world\n\n");
38 /* Execute some Python statements (in module __main__) */
39 PyRun_SimpleString("import sys\n");
40 PyRun_SimpleString("print sys.builtin_module_names\n");
41 PyRun_SimpleString("print sys.argv\n");
43 /* Note that you can call any public function of the Python
44 interpreter here, e.g. call_object(). */
46 /* Some more application specific code */
47 printf("\nGoodbye, cruel world\n");
48 #ifdef macintosh
49 printf("Type return or so-\n");
50 getchar();
51 #endif
52 /* Exit, cleaning up the interpreter */
53 Py_Exit(0);
54 /*NOTREACHED*/
57 /* This function is called by the interpreter to get its own name */
58 char *
59 getprogramname()
61 return argv0;