]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
added Py_AtExit() -- register cleanup functions for C modules
authorGuido van Rossum <guido@python.org>
Wed, 7 Sep 1994 14:38:28 +0000 (14:38 +0000)
committerGuido van Rossum <guido@python.org>
Wed, 7 Sep 1994 14:38:28 +0000 (14:38 +0000)
Python/pythonrun.c

index 59fa7cad2e5614f0a9dedef4dd579be58af9b98d..8387eed027bc5610c48b2bd3a43c68838eada78e 100644 (file)
@@ -466,6 +466,19 @@ fatal(msg)
 int threads_started = 0; /* Set by threadmodule.c and maybe others */
 #endif
 
+#define NEXITFUNCS 32
+static void (*exitfuncs[NEXITFUNCS])();
+static int nexitfuncs = 0;
+
+int Py_AtExit(func)
+       void (*func) PROTO((void));
+{
+       if (nexitfuncs >= NEXITFUNCS)
+               return -1;
+       exitfuncs[nexitfuncs++] = func;
+       return 0;
+}
+
 void
 cleanup()
 {
@@ -489,6 +502,9 @@ cleanup()
        }
 
        flushline();
+
+       while (nexitfuncs > 0)
+               (*exitfuncs[--nexitfuncs])();
 }
 
 #ifdef COUNT_ALLOCS