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

Skip to content

Commit 3559d1f

Browse files
committed
Add loop.c -- a test program for repeatedly calling Py_Initialize()
and Py_Finalize(). It seems to dump core right now...
1 parent 7339f4c commit 3559d1f

3 files changed

Lines changed: 41 additions & 1 deletion

File tree

Demo/embed/Makefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,20 @@ all: demo
3232
demo: demo.o
3333
$(CC) $(LDFLAGS) demo.o $(ALLLIBS) -o demo
3434

35+
loop: loop.o
36+
$(CC) $(LDFLAGS) loop.o $(ALLLIBS) -o loop
37+
3538
# Administrative targets
3639

3740
test: demo
3841
./demo
3942

43+
COMMAND="print 'hello world'"
44+
looptest: loop
45+
./loop $(COMMAND)
46+
4047
clean:
4148
-rm -f *.o core
4249

4350
clobber: clean
44-
-rm -f *~ @* '#'* demo
51+
-rm -f *~ @* '#'* demo loop

Demo/embed/README

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,10 @@ the source directory (../..)
1010
2) change the variables that together define the list of libraries
1111
(MODLIBS, LIBS, SYSLIBS) to link with, to match their definitions in
1212
$(blddir)/Modules/Makefile
13+
14+
An additional test program, loop.c, is used to experiment with memory
15+
leakage caused by repeated initialization and finalization of the
16+
interpreter. It can be build by saying "make loop" and tested with
17+
"make looptest". Command line usage is "./loop <python-command>",
18+
e.g. "./loop 'print 2+2'" should spit out an endless number of lines
19+
containing the number 4.

Demo/embed/loop.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
{
9+
char *command;
10+
11+
if (argc != 2) {
12+
fprintf(stderr, "usage: loop <python-command>\n");
13+
exit(2);
14+
}
15+
16+
command = argv[1];
17+
18+
Py_SetProgramName(argv[0]);
19+
20+
while (1) {
21+
Py_Initialize();
22+
PyRun_SimpleString(command);
23+
Py_Finalize();
24+
}
25+
/*NOTREACHED*/
26+
}

0 commit comments

Comments
 (0)