mirror of
				https://github.com/python/cpython.git
				synced 2025-11-04 03:44:55 +00:00 
			
		
		
		
	bpo-38070: Add _PyRuntimeState.preinitializing (GH-16245)
Add _PyRuntimeState.preinitializing field: set to 1 while Py_PreInitialize() is running. _PyRuntimeState: rename also pre_initialized field to preinitialized.
This commit is contained in:
		
							parent
							
								
									b39afb7876
								
							
						
					
					
						commit
						d3b904144e
					
				
					 2 changed files with 16 additions and 6 deletions
				
			
		| 
						 | 
					@ -190,8 +190,11 @@ struct _gilstate_runtime_state {
 | 
				
			||||||
/* Full Python runtime state */
 | 
					/* Full Python runtime state */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
typedef struct pyruntimestate {
 | 
					typedef struct pyruntimestate {
 | 
				
			||||||
    /* Is Python pre-initialized? Set to 1 by Py_PreInitialize() */
 | 
					    /* Is running Py_PreInitialize()? */
 | 
				
			||||||
    int pre_initialized;
 | 
					    int preinitializing;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* Is Python preinitialized? Set to 1 by Py_PreInitialize() */
 | 
				
			||||||
 | 
					    int preinitialized;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Is Python core initialized? Set to 1 by _Py_InitializeCore() */
 | 
					    /* Is Python core initialized? Set to 1 by _Py_InitializeCore() */
 | 
				
			||||||
    int core_initialized;
 | 
					    int core_initialized;
 | 
				
			||||||
| 
						 | 
					@ -199,6 +202,8 @@ typedef struct pyruntimestate {
 | 
				
			||||||
    /* Is Python fully initialized? Set to 1 by Py_Initialize() */
 | 
					    /* Is Python fully initialized? Set to 1 by Py_Initialize() */
 | 
				
			||||||
    int initialized;
 | 
					    int initialized;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* Set by Py_FinalizeEx(). Only reset to NULL if Py_Initialize()
 | 
				
			||||||
 | 
					       is called again. */
 | 
				
			||||||
    PyThreadState *finalizing;
 | 
					    PyThreadState *finalizing;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    struct pyinterpreters {
 | 
					    struct pyinterpreters {
 | 
				
			||||||
| 
						 | 
					@ -241,7 +246,7 @@ typedef struct pyruntimestate {
 | 
				
			||||||
} _PyRuntimeState;
 | 
					} _PyRuntimeState;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define _PyRuntimeState_INIT \
 | 
					#define _PyRuntimeState_INIT \
 | 
				
			||||||
    {.pre_initialized = 0, .core_initialized = 0, .initialized = 0}
 | 
					    {.preinitialized = 0, .core_initialized = 0, .initialized = 0}
 | 
				
			||||||
/* Note: _PyRuntimeState_INIT sets other fields to 0/NULL */
 | 
					/* Note: _PyRuntimeState_INIT sets other fields to 0/NULL */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
PyAPI_DATA(_PyRuntimeState) _PyRuntime;
 | 
					PyAPI_DATA(_PyRuntimeState) _PyRuntime;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -725,11 +725,15 @@ _Py_PreInitializeFromPyArgv(const PyPreConfig *src_config, const _PyArgv *args)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    _PyRuntimeState *runtime = &_PyRuntime;
 | 
					    _PyRuntimeState *runtime = &_PyRuntime;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (runtime->pre_initialized) {
 | 
					    if (runtime->preinitialized) {
 | 
				
			||||||
        /* If it's already configured: ignored the new configuration */
 | 
					        /* If it's already configured: ignored the new configuration */
 | 
				
			||||||
        return _PyStatus_OK();
 | 
					        return _PyStatus_OK();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* Note: preinitialized remains 1 on error, it is only set to 0
 | 
				
			||||||
 | 
					       at exit on success. */
 | 
				
			||||||
 | 
					    runtime->preinitializing = 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    PyPreConfig config;
 | 
					    PyPreConfig config;
 | 
				
			||||||
    _PyPreConfig_InitFromPreConfig(&config, src_config);
 | 
					    _PyPreConfig_InitFromPreConfig(&config, src_config);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -743,7 +747,8 @@ _Py_PreInitializeFromPyArgv(const PyPreConfig *src_config, const _PyArgv *args)
 | 
				
			||||||
        return status;
 | 
					        return status;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    runtime->pre_initialized = 1;
 | 
					    runtime->preinitializing = 0;
 | 
				
			||||||
 | 
					    runtime->preinitialized = 1;
 | 
				
			||||||
    return _PyStatus_OK();
 | 
					    return _PyStatus_OK();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -783,7 +788,7 @@ _Py_PreInitializeFromConfig(const PyConfig *config,
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    _PyRuntimeState *runtime = &_PyRuntime;
 | 
					    _PyRuntimeState *runtime = &_PyRuntime;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (runtime->pre_initialized) {
 | 
					    if (runtime->preinitialized) {
 | 
				
			||||||
        /* Already initialized: do nothing */
 | 
					        /* Already initialized: do nothing */
 | 
				
			||||||
        return _PyStatus_OK();
 | 
					        return _PyStatus_OK();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue