Defer _PyRuntime_Initialize to Py_InitializeFromConfig. #121628
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When I was working on my own copy of
Py_Initialize()for my own embedded interpreter that:sys.path(set to the base name of the exe since I store the python stlib in a zip file in it's win32 resource section)import site(set to 0)The way I did this was with a direct copy and paste of the code in
Py_InitializeExand changed a only what I needed to implement my ownPy_Initializethat suited my own needs. I hated how I needed to definePy_BUILD_CORE_MODULEand include#include <internal/pycore_runtime.h>And then checked and saw that everything but the if check inPy_InitializeExis inside ofPy_InitializeFromConfigand that the if check could be replaced easily withPy_IsInitialized. Because of that I submitted this change to remove the needless code duplication here sincePy_InitializeFromConfigis used anyways. It also might increase performance very slightly as a result as well for free.Because this is a trivial change to an implementation detail and does not affect functionality at all, I feel like this might not need an issue first. Very glad I took the time to look at this code and seen that it could be simplified somewhat.