mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 21:51:50 +00:00 
			
		
		
		
	added Py_AtExit() -- register cleanup functions for C modules
This commit is contained in:
		
							parent
							
								
									9776adf565
								
							
						
					
					
						commit
						1662dd5a3d
					
				
					 1 changed files with 16 additions and 0 deletions
				
			
		|  | @ -466,6 +466,19 @@ fatal(msg) | ||||||
| int threads_started = 0; /* Set by threadmodule.c and maybe others */ | int threads_started = 0; /* Set by threadmodule.c and maybe others */ | ||||||
| #endif | #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 | void | ||||||
| cleanup() | cleanup() | ||||||
| { | { | ||||||
|  | @ -489,6 +502,9 @@ cleanup() | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	flushline(); | 	flushline(); | ||||||
|  | 
 | ||||||
|  | 	while (nexitfuncs > 0) | ||||||
|  | 		(*exitfuncs[--nexitfuncs])(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #ifdef COUNT_ALLOCS | #ifdef COUNT_ALLOCS | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Guido van Rossum
						Guido van Rossum