Skip to content

Commit

Permalink
bpo-38304: Remove PyConfig.struct_size (pythonGH-16500)
Browse files Browse the repository at this point in the history
For now, we'll rely on the fact that the config structures aren't covered by the stable ABI.

We may revisit this in the future if we further explore the idea of offering a stable embedding API.
  • Loading branch information
vstinner authored and ncoghlan committed Sep 30, 2019
1 parent 92ca515 commit bdace21
Show file tree
Hide file tree
Showing 14 changed files with 39 additions and 273 deletions.
39 changes: 3 additions & 36 deletions Doc/c-api/init_config.rst
Expand Up @@ -194,25 +194,18 @@ PyPreConfig
* Configure the LC_CTYPE locale
* Set the UTF-8 mode
The :c:member:`struct_size` field must be explicitly initialized to
``sizeof(PyPreConfig)``.
Function to initialize a preconfiguration:
.. c:function:: PyStatus PyPreConfig_InitIsolatedConfig(PyPreConfig *preconfig)
.. c:function:: void PyPreConfig_InitIsolatedConfig(PyPreConfig *preconfig)
Initialize the preconfiguration with :ref:`Python Configuration
<init-python-config>`.
.. c:function:: PyStatus PyPreConfig_InitPythonConfig(PyPreConfig *preconfig)
.. c:function:: void PyPreConfig_InitPythonConfig(PyPreConfig *preconfig)
Initialize the preconfiguration with :ref:`Isolated Configuration
<init-isolated-conf>`.
The caller of these functions is responsible to handle exceptions (error or
exit) using :c:func:`PyStatus_Exception` and
:c:func:`Py_ExitStatusException`.
Structure fields:
.. c:member:: int allocator
Expand Down Expand Up @@ -274,13 +267,6 @@ PyPreConfig
same way the regular Python parses command line arguments: see
:ref:`Command Line Arguments <using-on-cmdline>`.
.. c:member:: size_t struct_size
Size of the structure in bytes: must be initialized to
``sizeof(PyPreConfig)``.
Field used for API and ABI compatibility.
.. c:member:: int use_environment
See :c:member:`PyConfig.use_environment`.
Expand Down Expand Up @@ -332,12 +318,7 @@ Example using the preinitialization to enable the UTF-8 Mode::
PyStatus status;
PyPreConfig preconfig;
preconfig.struct_size = sizeof(PyPreConfig);
status = PyPreConfig_InitPythonConfig(&preconfig);
if (PyStatus_Exception(status)) {
Py_ExitStatusException(status);
}
PyPreConfig_InitPythonConfig(&preconfig);
preconfig.utf8_mode = 1;
Expand All @@ -360,9 +341,6 @@ PyConfig
Structure containing most parameters to configure Python.
The :c:member:`struct_size` field must be explicitly initialized to
``sizeof(PyConfig)``.
Structure methods:
.. c:function:: PyStatus PyConfig_InitPythonConfig(PyConfig *config)
Expand Down Expand Up @@ -679,13 +657,6 @@ PyConfig
Encoding and encoding errors of :data:`sys.stdin`, :data:`sys.stdout` and
:data:`sys.stderr`.
.. c:member:: size_t struct_size
Size of the structure in bytes: must be initialized to
``sizeof(PyConfig)``.
Field used for API and ABI compatibility.
.. c:member:: int tracemalloc
If non-zero, call :func:`tracemalloc.start` at startup.
Expand Down Expand Up @@ -754,7 +725,6 @@ Example setting the program name::
{
PyStatus status;
PyConfig config;
config.struct_size = sizeof(PyConfig);
status = PyConfig_InitPythonConfig(&config);
if (PyStatus_Exception(status)) {
Expand Down Expand Up @@ -787,7 +757,6 @@ configuration, and then override some parameters::
{
PyStatus status;
PyConfig config;
config.struct_size = sizeof(PyConfig);
status = PyConfig_InitPythonConfig(&config);
if (PyStatus_Exception(status)) {
Expand Down Expand Up @@ -875,7 +844,6 @@ Example of customized Python always running in isolated mode::
{
PyStatus status;
PyConfig config;
config.struct_size = sizeof(PyConfig);
status = PyConfig_InitPythonConfig(&config);
if (PyStatus_Exception(status)) {
Expand Down Expand Up @@ -1067,7 +1035,6 @@ phases::
{
PyStatus status;
PyConfig config;
config.struct_size = sizeof(PyConfig);
status = PyConfig_InitPythonConfig(&config);
if (PyStatus_Exception(status)) {
Expand Down
12 changes: 2 additions & 10 deletions Include/cpython/initconfig.h
Expand Up @@ -45,10 +45,6 @@ PyAPI_FUNC(PyStatus) PyWideStringList_Insert(PyWideStringList *list,
/* --- PyPreConfig ----------------------------------------------- */

typedef struct {
/* Size of the structure in bytes: must be initialized to
sizeof(PyPreConfig). Field used for API and ABI compatibility. */
size_t struct_size;

int _config_init; /* _PyConfigInitEnum value */

/* Parse Py_PreInitializeFromBytesArgs() arguments?
Expand Down Expand Up @@ -124,17 +120,13 @@ typedef struct {
int allocator;
} PyPreConfig;

PyAPI_FUNC(PyStatus) PyPreConfig_InitPythonConfig(PyPreConfig *config);
PyAPI_FUNC(PyStatus) PyPreConfig_InitIsolatedConfig(PyPreConfig *config);
PyAPI_FUNC(void) PyPreConfig_InitPythonConfig(PyPreConfig *config);
PyAPI_FUNC(void) PyPreConfig_InitIsolatedConfig(PyPreConfig *config);


/* --- PyConfig ---------------------------------------------- */

typedef struct {
/* Size of the structure in bytes: must be initialized to
sizeof(PyConfig). Field used for API and ABI compatibility. */
size_t struct_size;

int _config_init; /* _PyConfigInitEnum value */

int isolated; /* Isolated mode? see PyPreConfig.isolated */
Expand Down
4 changes: 2 additions & 2 deletions Include/internal/pycore_initconfig.h
Expand Up @@ -120,8 +120,8 @@ extern PyStatus _PyPreCmdline_Read(_PyPreCmdline *cmdline,

/* --- PyPreConfig ----------------------------------------------- */

PyAPI_FUNC(PyStatus) _PyPreConfig_InitCompatConfig(PyPreConfig *preconfig);
extern PyStatus _PyPreConfig_InitFromConfig(
PyAPI_FUNC(void) _PyPreConfig_InitCompatConfig(PyPreConfig *preconfig);
extern void _PyPreConfig_InitFromConfig(
PyPreConfig *preconfig,
const PyConfig *config);
extern PyStatus _PyPreConfig_InitFromPreConfig(
Expand Down

This file was deleted.

9 changes: 2 additions & 7 deletions Modules/main.c
Expand Up @@ -53,20 +53,15 @@ pymain_init(const _PyArgv *args)
#endif

PyPreConfig preconfig;
preconfig.struct_size = sizeof(PyPreConfig);

status = PyPreConfig_InitPythonConfig(&preconfig);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
PyPreConfig_InitPythonConfig(&preconfig);

status = _Py_PreInitializeFromPyArgv(&preconfig, args);
if (_PyStatus_EXCEPTION(status)) {
return status;
}

PyConfig config;
config.struct_size = sizeof(PyConfig);

status = PyConfig_InitPythonConfig(&config);
if (_PyStatus_EXCEPTION(status)) {
goto done;
Expand Down
9 changes: 1 addition & 8 deletions PC/python_uwp.cpp
Expand Up @@ -165,12 +165,8 @@ int
wmain(int argc, wchar_t **argv)
{
PyStatus status;

PyPreConfig preconfig;
preconfig.struct_size = sizeof(PyPreConfig);

PyConfig config;
config.struct_size = sizeof(PyConfig);

const wchar_t *moduleName = NULL;
const wchar_t *p = wcsrchr(argv[0], L'\\');
Expand All @@ -189,10 +185,7 @@ wmain(int argc, wchar_t **argv)
}
}

status = PyPreConfig_InitPythonConfig(&preconfig);
if (PyStatus_Exception(status)) {
goto fail_without_config;
}
PyPreConfig_InitPythonConfig(&preconfig);
if (!moduleName) {
status = Py_PreInitializeFromArgs(&preconfig, argc, argv);
if (PyStatus_Exception(status)) {
Expand Down
1 change: 0 additions & 1 deletion Programs/_freeze_importlib.c
Expand Up @@ -78,7 +78,6 @@ main(int argc, char *argv[])

PyStatus status;
PyConfig config;
config.struct_size = sizeof(PyConfig);

status = PyConfig_InitIsolatedConfig(&config);
if (PyStatus_Exception(status)) {
Expand Down

0 comments on commit bdace21

Please sign in to comment.