forked from python/cpython
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pythongh-107954: Add PyInitConfig C API
Add PyInitConfig functions: * PyInitConfig_Python_New() * PyInitConfig_Isolated_New() * PyInitConfig_Free(config) * PyInitConfig_SetInt(config, key, value) * PyInitConfig_SetStr(config, key, value) * PyInitConfig_SetWStr(config, key, value) * PyInitConfig_SetStrList(config, key, length, items) * PyInitConfig_SetWStrList(config, key, length, items) * PyInitConfig_GetErrorMsg(config) Add also functions using it: * Py_InitializeFromInitConfig(config) * Py_ExitWithInitConfig(config) Changes: * Add Include/initconfig.h header.
- Loading branch information
Showing
8 changed files
with
572 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#ifndef Py_INITCONFIG_H | ||
#define Py_INITCONFIG_H | ||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
typedef struct PyInitConfig PyInitConfig; | ||
|
||
// Create a new initialization configuration. | ||
// It must be freed by PyInitConfig_Free(). | ||
// Return NULL on memory allocation failure. | ||
// | ||
// PyInitConfig_Python_New() has a Python configuration by default. | ||
// PyInitConfig_Isolated_New() has an Isolated configuration by default. | ||
PyAPI_FUNC(PyInitConfig*) PyInitConfig_Python_New(void); | ||
PyAPI_FUNC(PyInitConfig*) PyInitConfig_Isolated_New(void); | ||
|
||
// Free memory of a initialization configuration. | ||
PyAPI_FUNC(void) PyInitConfig_Free(PyInitConfig *config); | ||
|
||
// Set an integer configuration option. | ||
// Return 0 on success, or return -1 on error. | ||
PyAPI_FUNC(int) PyInitConfig_SetInt( | ||
PyInitConfig *config, | ||
const char *key, | ||
int64_t value); | ||
|
||
// Set a string configuration option from a bytes string. | ||
// | ||
// The bytes string is decoded by Py_DecodeLocale(). Preinitialize Python if | ||
// needed to ensure that encodings are properly configured. | ||
// | ||
// Return 0 on success, or return -1 on error. | ||
PyAPI_FUNC(int) PyInitConfig_SetStr( | ||
PyInitConfig *config, | ||
const char *key, | ||
const char *value); | ||
|
||
// Set a string configuration option from a wide string. | ||
// Preinitialize Python if needed. | ||
// Return 0 on success, or return -1 on error. | ||
PyAPI_FUNC(int) PyInitConfig_SetWStr( | ||
PyInitConfig *config, | ||
const char *key, | ||
const wchar_t *value); | ||
|
||
// Set a string list configuration option from bytes strings. | ||
// | ||
// The bytes strings are decoded by Py_DecodeLocale(). Preinitialize Python if | ||
// needed to ensure that encodings are properly configured. | ||
// | ||
// Return 0 on success, or return -1 on error. | ||
PyAPI_FUNC(int) PyInitConfig_SetStrList( | ||
PyInitConfig *config, | ||
const char *key, | ||
size_t length, | ||
char * const *items); | ||
|
||
// Set a string list configuration option from a wide strings. | ||
// Preinitialize Python if needed. | ||
// Return 0 on success, or return -1 on error. | ||
PyAPI_FUNC(int) PyInitConfig_SetWStrList( | ||
PyInitConfig *config, | ||
const char *key, | ||
size_t length, | ||
wchar_t * const *items); | ||
|
||
// Initialize Python from the initialization configuration. | ||
// Return 0 on success. | ||
// Return -1 if Python wants to exit and on error | ||
PyAPI_FUNC(int) Py_InitializeFromInitConfig(PyInitConfig *config); | ||
|
||
// Get the current error message. | ||
// Return a UTF-8 string allocated by malloc(). It must be released by free(). | ||
// Return NULL on memory allocation failure. | ||
PyAPI_FUNC(char*) PyInitConfig_GetErrorMsg(PyInitConfig* config); | ||
|
||
// Exit Python and free memory of a initialization configuration. | ||
// The function does not return. | ||
PyAPI_FUNC(void) _Py_NO_RETURN Py_ExitWithInitConfig(PyInitConfig *config); | ||
|
||
|
||
#ifndef Py_LIMITED_API | ||
# define Py_CPYTHON_INITCONFIG_H | ||
# include "cpython/initconfig.h" | ||
# undef Py_CPYTHON_INITCONFIG_H | ||
#endif | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
#endif // !Py_INITCONFIG_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.