mirror of
				https://github.com/python/cpython.git
				synced 2025-10-30 21:21:22 +00:00 
			
		
		
		
	Handle allocation failures gracefully. Found with failmalloc.
Many (all?) of these could be backported.
This commit is contained in:
		
							parent
							
								
									1adbb50701
								
							
						
					
					
						commit
						e1fdb32ff2
					
				
					 6 changed files with 52 additions and 41 deletions
				
			
		|  | @ -116,6 +116,8 @@ _PyImport_Init(void) | |||
| 	for (scan = _PyImport_StandardFiletab; scan->suffix != NULL; ++scan) | ||||
| 		++countS; | ||||
| 	filetab = PyMem_NEW(struct filedescr, countD + countS + 1); | ||||
| 	if (filetab == NULL) | ||||
| 		Py_FatalError("Can't intiialize import file table."); | ||||
| 	memcpy(filetab, _PyImport_DynLoadFiletab, | ||||
| 	       countD * sizeof(struct filedescr)); | ||||
| 	memcpy(filetab + countD, _PyImport_StandardFiletab, | ||||
|  | @ -239,8 +241,11 @@ lock_import(void) | |||
| 	long me = PyThread_get_thread_ident(); | ||||
| 	if (me == -1) | ||||
| 		return; /* Too bad */ | ||||
| 	if (import_lock == NULL) | ||||
| 	if (import_lock == NULL) { | ||||
| 		import_lock = PyThread_allocate_lock(); | ||||
| 		if (import_lock == NULL) | ||||
| 			return;  /* Nothing much we can do. */ | ||||
| 	} | ||||
| 	if (import_lock_thread == me) { | ||||
| 		import_lock_level++; | ||||
| 		return; | ||||
|  | @ -259,7 +264,7 @@ static int | |||
| unlock_import(void) | ||||
| { | ||||
| 	long me = PyThread_get_thread_ident(); | ||||
| 	if (me == -1) | ||||
| 	if (me == -1 || import_lock == NULL) | ||||
| 		return 0; /* Too bad */ | ||||
| 	if (import_lock_thread != me) | ||||
| 		return -1; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Neal Norwitz
						Neal Norwitz