comparison 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
comparison
equal deleted inserted replaced
1869:2cede61e9b1b 1870:61738ed6cc10
464 #ifdef WITH_THREAD 464 #ifdef WITH_THREAD
465 #include "thread.h" 465 #include "thread.h"
466 int threads_started = 0; /* Set by threadmodule.c and maybe others */ 466 int threads_started = 0; /* Set by threadmodule.c and maybe others */
467 #endif 467 #endif
468 468
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
469 void 482 void
470 cleanup() 483 cleanup()
471 { 484 {
472 object *exitfunc = sysget("exitfunc"); 485 object *exitfunc = sysget("exitfunc");
473 486
487 print_error(); 500 print_error();
488 } 501 }
489 } 502 }
490 503
491 flushline(); 504 flushline();
505
506 while (nexitfuncs > 0)
507 (*exitfuncs[--nexitfuncs])();
492 } 508 }
493 509
494 #ifdef COUNT_ALLOCS 510 #ifdef COUNT_ALLOCS
495 extern void dump_counts PROTO((void)); 511 extern void dump_counts PROTO((void));
496 #endif 512 #endif