]> granicus.if.org Git - python/commitdiff
Add loop.c -- a test program for repeatedly calling Py_Initialize()
authorGuido van Rossum <guido@python.org>
Wed, 10 Jan 2001 17:11:51 +0000 (17:11 +0000)
committerGuido van Rossum <guido@python.org>
Wed, 10 Jan 2001 17:11:51 +0000 (17:11 +0000)
and Py_Finalize().  It seems to dump core right now...

Demo/embed/Makefile
Demo/embed/README
Demo/embed/loop.c [new file with mode: 0644]

index fb2b1edc2a878b5fad3cb6ba7f6aebc27a4821ce..ee0196b10303164f363c46d6e7a116b93089ec29 100644 (file)
@@ -32,13 +32,20 @@ all:                demo
 demo:          demo.o
                $(CC) $(LDFLAGS) demo.o $(ALLLIBS) -o demo
 
+loop:          loop.o
+               $(CC) $(LDFLAGS) loop.o $(ALLLIBS) -o loop
+
 # Administrative targets
 
 test:          demo
                ./demo
 
+COMMAND="print 'hello world'"
+looptest:      loop
+               ./loop $(COMMAND)
+
 clean:
                -rm -f *.o core
 
 clobber:       clean
-               -rm -f *~ @* '#'* demo
+               -rm -f *~ @* '#'* demo loop
index 8858c713e44bc34e6493216579e542ad86008f88..a0f7af84397aa99be9c9b7de4ed462b80d3e783f 100644 (file)
@@ -10,3 +10,10 @@ the source directory (../..)
 2) change the variables that together define the list of libraries
 (MODLIBS, LIBS, SYSLIBS) to link with, to match their definitions in
 $(blddir)/Modules/Makefile
+
+An additional test program, loop.c, is used to experiment with memory
+leakage caused by repeated initialization and finalization of the
+interpreter.  It can be build by saying "make loop" and tested with
+"make looptest".  Command line usage is "./loop <python-command>",
+e.g. "./loop 'print 2+2'" should spit out an endless number of lines
+containing the number 4.
diff --git a/Demo/embed/loop.c b/Demo/embed/loop.c
new file mode 100644 (file)
index 0000000..ca89cb7
--- /dev/null
@@ -0,0 +1,26 @@
+/* Simple program that repeatedly calls Py_Initialize(), does something, and
+   then calls Py_Finalize().  This should help finding leaks related to
+   initialization. */
+
+#include "Python.h"
+
+main(int argc, char **argv)
+{
+       char *command;
+
+       if (argc != 2) {
+               fprintf(stderr, "usage: loop <python-command>\n");
+               exit(2);
+       }
+
+       command = argv[1];
+
+       Py_SetProgramName(argv[0]);
+
+       while (1) {
+               Py_Initialize();
+               PyRun_SimpleString(command);
+               Py_Finalize();
+       }
+       /*NOTREACHED*/
+}