diff options
| author | Guido van Rossum <guido@python.org> | 1994-09-07 14:38:28 +0000 |
|---|---|---|
| committer | Guido van Rossum <guido@python.org> | 1994-09-07 14:38:28 +0000 |
| commit | b6d79cd57535c940832a949c24fcfdefdeed70b6 (patch) | |
| tree | 113cee2fde4725ff353dd68f16cacca1d2fc8cef /Python/pythonrun.c | |
| parent | 60529a19949403eed8e5a2cc79e19a4777656c48 (diff) | |
| download | cpython-b6d79cd57535c940832a949c24fcfdefdeed70b6.tar.gz | |
added Py_AtExit() -- register cleanup functions for C modules
Diffstat (limited to 'Python/pythonrun.c')
| -rw-r--r-- | Python/pythonrun.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c index 59fa7cad2e..8387eed027 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 |
