Message 338484 - Python tracker (original) (raw)

In term of API, we get something like:

_PyInitError err;

_PyPreConfig preconfig = _PyPreConfig_INIT;
preconfig.utf8_mode = 1;
preconfig.allocator = "malloc";

_PyInitError err = _Py_PreInitializeFromPreConfig(&preconfig);
if (_Py_INIT_FAILED(err)) {
    _Py_ExitInitError(err);
}

/* PyMem_RawMalloc and Py_DecodeLocale can now be used */

_PyCoreConfig config = _PyCoreConfig_INIT;
config.user_site_directory = 0;

err = _Py_InitializeFromConfig(&config);
if (_Py_INIT_FAILED(err)) {
    _Py_ExitInitError(err);
}

/* ... use Python ... */

Py_Finalize();

/* Note: no need to "free" preconfig nor config memory, they use constants */