Hi,
I wrote a major update of my PEP 741 “Python Configuration C API (second version)” to address most, if not all, requests in the previous discussion.
=> Read the updated PEP 741 <=
See the Commit of the PEP 741 update.
Changes (incomplete list):
-
PyInitConfig_SetStr()
andPyInitConfig_SetStrList()
now expect UTF-8 encoded string, instead of strings encoded to the locale encoding. -
Add
PyInitConfig_SetStrLocale()
andPyInitConfig_SetStrLocaleList()
functions which expect null-terminated strings encoded to the locale encoding. -
Calling
PyInitConfig_SetStrLocale()
andPyInitConfig_SetStrLocaleList()
now requires first to preinitialize Python. -
Setting a preconfiguration option, such as
"allocator"
, after Python preconfiguration now fails with an error. -
Add functions to get PyInitConfig options:
PyInitConfig_GetInt()
PyInitConfig_GetStr()
PyInitConfig_GetWStr()
PyInitConfig_GetStrList()
PyInitConfig_GetWStrList()
PyInitConfig_FreeStrList()
PyInitConfig_FreeWStrList()
-
Remove
PyInitConfig_GetExitCode()
andPyInitConfig_Exception()
functions: simplify error handling. -
Document that
PyConfig_Get()
cannot be called before Python initialization, nor after Python finalization. -
PyConfig_Get()
: Document which values are read from the sys module. -
Remove support for custom configuration options. I’m no longer convinced that third-party project need/want pass their custom options. Apparently, Python is the main and only consumer of Python configuration options. I prefer to make the API as small as possible for now.
-
Add
PyConfig_Keys()
function: get all configuration option names as a tuple. I plan to sort them for convenience. -
Deprecating and removing configuration options is out of the scope of the PEP and should be discussed on a case by case basis.
-
Give multiple examples of applications, libraries and utilities embedding Python.
-
Quote developers asking for a stable ABI.
I was asked to fully remove the Python preinitialization. Well, I almost did it: only PyInitConfig_SetStrLocale()
and PyInitConfig_SetStrLocaleList()
need it. If you use other APIs using UTF-8, you should no longer have to bother with the preinitialization. Well, if you only speak ASCII or UTF-8, you’re good!
PyInitConfig_SetStrLocale()
is the only correct way to pass a string encoded to the locale encoding. For example, to pass main()
char **argv
arguments to set the configuration option "argv"
.