Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1662dd5

Browse files
committed
added Py_AtExit() -- register cleanup functions for C modules
1 parent 9776adf commit 1662dd5

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

Python/pythonrun.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,19 @@ fatal(msg)
466466
int threads_started = 0; /* Set by threadmodule.c and maybe others */
467467
#endif
468468

469+
#define NEXITFUNCS 32
470+
static void (*exitfuncs[NEXITFUNCS])();
471+
static int nexitfuncs = 0;
472+
473+
int Py_AtExit(func)
474+
void (*func) PROTO((void));
475+
{
476+
if (nexitfuncs >= NEXITFUNCS)
477+
return -1;
478+
exitfuncs[nexitfuncs++] = func;
479+
return 0;
480+
}
481+
469482
void
470483
cleanup()
471484
{
@@ -489,6 +502,9 @@ cleanup()
489502
}
490503

491504
flushline();
505+
506+
while (nexitfuncs > 0)
507+
(*exitfuncs[--nexitfuncs])();
492508
}
493509

494510
#ifdef COUNT_ALLOCS

0 commit comments

Comments
 (0)