FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-149163: Add PyInitConfig API (PEP 741) to the limited C API by anujbharambe · Pull Request #149194 · python/cpython · GitHub

Repository navigation

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .dat  (1) .h  (3) .py  (1) .rst  (3) .toml  (1) All 6 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
5 changes: 4 additions & 1 deletion Doc/c-api/init_config.rst
This file contains hidden or 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
Expand Up @@ -14,6 +14,9 @@ PyInitConfig C API

.. versionadded:: 3.14

.. versionchanged:: 3.15
Added to the :ref:`limited C API <limited-c-api>`.

Python can be initialized with :c:func:`Py_InitializeFromInitConfig`.

The :c:func:`Py_RunMain` function can be used to write a customized Python
Expand Down Expand Up @@ -70,7 +73,7 @@ Mode <devmode>` enabled; return ``-1`` on error:
Create Config
-------------

.. c:struct:: PyInitConfig
.. c:type:: PyInitConfig

Opaque structure to configure the Python initialization.

Expand Down
15 changes: 15 additions & 0 deletions Doc/data/stable_abi.dat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Doc/whatsnew/3.15.rst
This file contains hidden or 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
Expand Up @@ -2068,6 +2068,10 @@ Changed C APIs
for ``NULL`` should be updated to call :c:macro:`PyDateTime_IMPORT` instead.
(Contributed by Kumar Aditya in :gh:`141563`.)

* The :ref:`PyInitConfig API <pyinitconfig_api>` (:pep:`741`) is now part of
the :ref:`limited C API <limited-c-api>`.
(Contributed by in :gh:`149163`.)

Porting to Python 3.15
----------------------

Expand Down
2 changes: 1 addition & 1 deletion Include/Python.h
This file contains hidden or 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
Expand Up @@ -112,7 +112,7 @@ __pragma(warning(disable: 4201))
#include "sliceobject.h"
#include "cpython/cellobject.h"
#include "iterobject.h"
#include "cpython/initconfig.h"
#include "initconfig.h"
#include "pystate.h"
#include "cpython/genobject.h"
#include "descrobject.h"
Expand Down
50 changes: 4 additions & 46 deletions Include/cpython/initconfig.h
This file contains hidden or 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
@@ -1,6 +1,9 @@
#ifndef Py_PYCORECONFIG_H
#define Py_PYCORECONFIG_H
#ifndef Py_LIMITED_API
#ifndef Py_CPYTHON_INITCONFIG_H
# error "this header file must not be included directly"
#endif

#ifdef __cplusplus
extern "C" {
#endif
Expand Down Expand Up @@ -284,52 +287,7 @@ PyAPI_FUNC(int) PyConfig_Set(const char *name, PyObject *value);
PyAPI_FUNC(void) Py_GetArgcArgv(int *argc, wchar_t ***argv);


// --- PyInitConfig ---------------------------------------------------------

typedef struct PyInitConfig PyInitConfig;

PyAPI_FUNC(PyInitConfig*) PyInitConfig_Create(void);
PyAPI_FUNC(void) PyInitConfig_Free(PyInitConfig *config);

PyAPI_FUNC(int) PyInitConfig_GetError(PyInitConfig* config,
const char **err_msg);
PyAPI_FUNC(int) PyInitConfig_GetExitCode(PyInitConfig* config,
int *exitcode);

PyAPI_FUNC(int) PyInitConfig_HasOption(PyInitConfig *config,
const char *name);
PyAPI_FUNC(int) PyInitConfig_GetInt(PyInitConfig *config,
const char *name,
int64_t *value);
PyAPI_FUNC(int) PyInitConfig_GetStr(PyInitConfig *config,
const char *name,
char **value);
PyAPI_FUNC(int) PyInitConfig_GetStrList(PyInitConfig *config,
const char *name,
size_t *length,
char ***items);
PyAPI_FUNC(void) PyInitConfig_FreeStrList(size_t length, char **items);

PyAPI_FUNC(int) PyInitConfig_SetInt(PyInitConfig *config,
const char *name,
int64_t value);
PyAPI_FUNC(int) PyInitConfig_SetStr(PyInitConfig *config,
const char *name,
const char *value);
PyAPI_FUNC(int) PyInitConfig_SetStrList(PyInitConfig *config,
const char *name,
size_t length,
char * const *items);

PyAPI_FUNC(int) PyInitConfig_AddModule(PyInitConfig *config,
const char *name,
PyObject* (*initfunc)(void));

PyAPI_FUNC(int) Py_InitializeFromInitConfig(PyInitConfig *config);


#ifdef __cplusplus
}
#endif
#endif /* !Py_LIMITED_API */
#endif /* !Py_PYCORECONFIG_H */
64 changes: 64 additions & 0 deletions Include/initconfig.h
This file contains hidden or 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


// --- PyInitConfig (PEP 741) -----------------------------------------------

#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030f0000

typedef struct PyInitConfig PyInitConfig;

PyAPI_FUNC(PyInitConfig*) PyInitConfig_Create(void);
PyAPI_FUNC(void) PyInitConfig_Free(PyInitConfig *config);

PyAPI_FUNC(int) PyInitConfig_GetError(PyInitConfig* config,
const char **err_msg);
PyAPI_FUNC(int) PyInitConfig_GetExitCode(PyInitConfig* config,
int *exitcode);

PyAPI_FUNC(int) PyInitConfig_HasOption(PyInitConfig *config,
const char *name);
PyAPI_FUNC(int) PyInitConfig_GetInt(PyInitConfig *config,
const char *name,
int64_t *value);
PyAPI_FUNC(int) PyInitConfig_GetStr(PyInitConfig *config,
const char *name,
char **value);
PyAPI_FUNC(int) PyInitConfig_GetStrList(PyInitConfig *config,
const char *name,
size_t *length,
char ***items);
PyAPI_FUNC(void) PyInitConfig_FreeStrList(size_t length, char **items);

PyAPI_FUNC(int) PyInitConfig_SetInt(PyInitConfig *config,
const char *name,
int64_t value);
PyAPI_FUNC(int) PyInitConfig_SetStr(PyInitConfig *config,
const char *name,
const char *value);
PyAPI_FUNC(int) PyInitConfig_SetStrList(PyInitConfig *config,
const char *name,
size_t length,
char * const *items);

PyAPI_FUNC(int) PyInitConfig_AddModule(PyInitConfig *config,
const char *name,
PyObject* (*initfunc)(void));

PyAPI_FUNC(int) Py_InitializeFromInitConfig(PyInitConfig *config);

#endif

#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 */
14 changes: 14 additions & 0 deletions Lib/test/test_stable_abi_ctypes.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file contains hidden or 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 @@
Added the :pep:`741` :c:type:`PyInitConfig` API to the limited C API.
34 changes: 34 additions & 0 deletions Misc/stable_abi.toml
This file contains hidden or 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
Expand Up @@ -2715,3 +2715,37 @@
# Note: The `_reserved` member of this struct is for interal use only.
# (The definition of 'full-abi' was clarified when this entry was added.)
struct_abi_kind = 'full-abi'

# PEP 741: Python Configuration C API -- added to limited API.

[struct.PyInitConfig]
added = '3.15'
struct_abi_kind = 'opaque'
[function.PyInitConfig_Create]
added = '3.15'
[function.PyInitConfig_Free]
added = '3.15'
[function.PyInitConfig_GetError]
added = '3.15'
[function.PyInitConfig_GetExitCode]
added = '3.15'
[function.PyInitConfig_HasOption]
added = '3.15'
[function.PyInitConfig_GetInt]
added = '3.15'
[function.PyInitConfig_GetStr]
added = '3.15'
[function.PyInitConfig_GetStrList]
added = '3.15'
[function.PyInitConfig_FreeStrList]
added = '3.15'
[function.PyInitConfig_SetInt]
added = '3.15'
[function.PyInitConfig_SetStr]
added = '3.15'
[function.PyInitConfig_SetStrList]
added = '3.15'
[function.PyInitConfig_AddModule]
added = '3.15'
[function.Py_InitializeFromInitConfig]
added = '3.15'
14 changes: 14 additions & 0 deletions PC/python3dll.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

Back | FazBrowse Home | New Git URL