Guido van Rossum | 3559d1f | 2001-01-10 17:11:51 +0000 | [diff] [blame] | 1 | /* Simple program that repeatedly calls Py_Initialize(), does something, and |
| 2 | then calls Py_Finalize(). This should help finding leaks related to |
| 3 | initialization. */ |
| 4 | |
| 5 | #include "Python.h" |
| 6 | |
| 7 | main(int argc, char **argv) |
| 8 | { |
Antoine Pitrou | 7f14f0d | 2010-05-09 16:14:21 +0000 | [diff] [blame] | 9 | int count = -1; |
| 10 | char *command; |
Guido van Rossum | 3559d1f | 2001-01-10 17:11:51 +0000 | [diff] [blame] | 11 | |
Antoine Pitrou | 7f14f0d | 2010-05-09 16:14:21 +0000 | [diff] [blame] | 12 | if (argc < 2 || argc > 3) { |
| 13 | fprintf(stderr, "usage: loop <python-command> [count]\n"); |
| 14 | exit(2); |
| 15 | } |
| 16 | command = argv[1]; |
Guido van Rossum | 3559d1f | 2001-01-10 17:11:51 +0000 | [diff] [blame] | 17 | |
Antoine Pitrou | 7f14f0d | 2010-05-09 16:14:21 +0000 | [diff] [blame] | 18 | if (argc == 3) { |
| 19 | count = atoi(argv[2]); |
| 20 | } |
Barry Warsaw | 0c63fe9 | 2001-01-23 16:42:01 +0000 | [diff] [blame] | 21 | |
Georg Brandl | cea7e55 | 2010-08-01 18:56:30 +0000 | [diff] [blame] | 22 | Py_SetProgramName(L"loop"); |
Guido van Rossum | 3559d1f | 2001-01-10 17:11:51 +0000 | [diff] [blame] | 23 | |
Antoine Pitrou | 7f14f0d | 2010-05-09 16:14:21 +0000 | [diff] [blame] | 24 | /* uncomment this if you don't want to load site.py */ |
| 25 | /* Py_NoSiteFlag = 1; */ |
Barry Warsaw | 0c63fe9 | 2001-01-23 16:42:01 +0000 | [diff] [blame] | 26 | |
Antoine Pitrou | 7f14f0d | 2010-05-09 16:14:21 +0000 | [diff] [blame] | 27 | while (count == -1 || --count >= 0 ) { |
| 28 | Py_Initialize(); |
| 29 | PyRun_SimpleString(command); |
| 30 | Py_Finalize(); |
| 31 | } |
| 32 | return 0; |
Guido van Rossum | 3559d1f | 2001-01-10 17:11:51 +0000 | [diff] [blame] | 33 | } |