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_SetString(config, key, value) * PyInitConfig_SetList(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
6 changed files
with
432 additions
and
36 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,64 @@ | ||
#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. | ||
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. | ||
// Return 0 on success, or return -1 on error. | ||
PyAPI_FUNC(int) PyInitConfig_SetString( | ||
PyInitConfig *config, | ||
const char *key, | ||
const wchar_t *value); | ||
|
||
// Set a string configuration option. | ||
// Return 0 on success, or return -1 on error. | ||
PyAPI_FUNC(int) PyInitConfig_SetList( | ||
PyInitConfig *config, | ||
const char *key, | ||
size_t length, | ||
wchar_t **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
Oops, something went wrong.