Mercurial > cpython-lru_cache-weakref
diff Python/pythonrun.c @ 1870:61738ed6cc10 legacy-trunk
added Py_AtExit() -- register cleanup functions for C modules
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Wed, 07 Sep 1994 14:38:28 +0000 |
| parents | 1f4a86dbcd79 |
| children | ac6a9f90f6fd |
line wrap: on
line diff
--- a/Python/pythonrun.c Wed Sep 07 14:36:45 1994 +0000 +++ b/Python/pythonrun.c Wed Sep 07 14:38:28 1994 +0000 @@ -466,6 +466,19 @@ 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 @@ } flushline(); + + while (nexitfuncs > 0) + (*exitfuncs[--nexitfuncs])(); } #ifdef COUNT_ALLOCS
