From: Guido van Rossum Date: Wed, 7 Sep 1994 14:38:28 +0000 (+0000) Subject: added Py_AtExit() -- register cleanup functions for C modules X-Git-Tag: v1.1~109 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1662dd5a3d5301a54f15f861a5d24c179bf67bca;p=thirdparty%2FPython%2Fcpython.git added Py_AtExit() -- register cleanup functions for C modules --- diff --git a/Python/pythonrun.c b/Python/pythonrun.c index 59fa7cad2e56..8387eed027bc 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -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