Skip to content

Commit 2fba67c

Browse files
committed
Fix weird merge artifact.
1 parent 32a4937 commit 2fba67c

File tree

1 file changed

+0
-318
lines changed

1 file changed

+0
-318
lines changed

Doc/c-api/init_config.rst

Lines changed: 0 additions & 318 deletions
Original file line numberDiff line numberDiff line change
@@ -2266,324 +2266,6 @@ The ``__PYVENV_LAUNCHER__`` environment variable is used to set
22662266
set to the ``pyvenv.cfg`` directory. This was previously done by :mod:`site`,
22672267
therefore affected by :option:`-S`.
22682268
2269-
.. _pyinitconfig_api:
2270-
2271-
PyInitConfig C API
2272-
==================
2273-
2274-
C API to configure the Python initialization (:pep:`741`).
2275-
2276-
.. versionadded:: 3.14
2277-
2278-
Create Config
2279-
-------------
2280-
2281-
.. c:struct:: PyInitConfig
2282-
2283-
Opaque structure to configure the Python initialization.
2284-
2285-
2286-
.. c:function:: PyInitConfig* PyInitConfig_Create(void)
2287-
2288-
Create a new initialization configuration using :ref:`Isolated Configuration
2289-
<init-isolated-conf>` default values.
2290-
2291-
It must be freed by :c:func:`PyInitConfig_Free`.
2292-
2293-
Return ``NULL`` on memory allocation failure.
2294-
2295-
2296-
.. c:function:: void PyInitConfig_Free(PyInitConfig *config)
2297-
2298-
Free memory of the initialization configuration *config*.
2299-
2300-
If *config* is ``NULL``, no operation is performed.
2301-
2302-
2303-
Error Handling
2304-
--------------
2305-
2306-
.. c:function:: int PyInitConfig_GetError(PyInitConfig* config, const char **err_msg)
2307-
2308-
Get the *config* error message.
2309-
2310-
* Set *\*err_msg* and return ``1`` if an error is set.
2311-
* Set *\*err_msg* to ``NULL`` and return ``0`` otherwise.
2312-
2313-
An error message is an UTF-8 encoded string.
2314-
2315-
If *config* has an exit code, format the exit code as an error
2316-
message.
2317-
2318-
The error message remains valid until another ``PyInitConfig``
2319-
function is called with *config*. The caller doesn't have to free the
2320-
error message.
2321-
2322-
2323-
.. c:function:: int PyInitConfig_GetExitCode(PyInitConfig* config, int *exitcode)
2324-
2325-
Get the *config* exit code.
2326-
2327-
* Set *\*exitcode* and return ``1`` if *config* has an exit code set.
2328-
* Return ``0`` if *config* has no exit code set.
2329-
2330-
Only the ``Py_InitializeFromInitConfig()`` function can set an exit
2331-
code if the ``parse_argv`` option is non-zero.
2332-
2333-
An exit code can be set when parsing the command line failed (exit
2334-
code ``2``) or when a command line option asks to display the command
2335-
line help (exit code ``0``).
2336-
2337-
2338-
Get Options
2339-
-----------
2340-
2341-
The configuration option *name* parameter must be a non-NULL
2342-
null-terminated UTF-8 encoded string.
2343-
2344-
.. c:function:: int PyInitConfig_HasOption(PyInitConfig *config, const char *name)
2345-
2346-
Test if the configuration has an option called *name*.
2347-
2348-
Return ``1`` if the option exists, or return ``0`` otherwise.
2349-
2350-
2351-
.. c:function:: int PyInitConfig_GetInt(PyInitConfig *config, const char *name, int64_t *value)
2352-
2353-
Get an integer configuration option.
2354-
2355-
* Set *\*value*, and return ``0`` on success.
2356-
* Set an error in *config* and return ``-1`` on error.
2357-
2358-
2359-
.. c:function:: int PyInitConfig_GetStr(PyInitConfig *config, const char *name, char **value)
2360-
2361-
Get a string configuration option as a null-terminated UTF-8
2362-
encoded string.
2363-
2364-
* Set *\*value*, and return ``0`` on success.
2365-
* Set an error in *config* and return ``-1`` on error.
2366-
2367-
*\*value* can be set to ``NULL`` if the option is an optional string and the
2368-
option is unset.
2369-
2370-
On success, the string must be released with ``free(value)`` if it's not
2371-
``NULL``.
2372-
2373-
2374-
.. c:function:: int PyInitConfig_GetStrList(PyInitConfig *config, const char *name, size_t *length, char ***items)
2375-
2376-
Get a string list configuration option as an array of
2377-
null-terminated UTF-8 encoded strings.
2378-
2379-
* Set *\*length* and *\*value*, and return ``0`` on success.
2380-
* Set an error in *config* and return ``-1`` on error.
2381-
2382-
On success, the string list must be released with
2383-
``PyInitConfig_FreeStrList(length, items)``.
2384-
2385-
2386-
.. c:function:: void PyInitConfig_FreeStrList(size_t length, char **items)
2387-
2388-
Free memory of a string list created by
2389-
``PyInitConfig_GetStrList()``.
2390-
2391-
2392-
Set Options
2393-
-----------
2394-
2395-
The configuration option *name* parameter must be a non-NULL null-terminated
2396-
UTF-8 encoded string.
2397-
2398-
Some configuration options have side effects on other options. This logic is
2399-
only implemented when ``Py_InitializeFromInitConfig()`` is called, not by the
2400-
"Set" functions below. For example, setting ``dev_mode`` to ``1`` does not set
2401-
``faulthandler`` to ``1``.
2402-
2403-
.. c:function:: int PyInitConfig_SetInt(PyInitConfig *config, const char *name, int64_t value)
2404-
2405-
Set an integer configuration option.
2406-
2407-
* Return ``0`` on success.
2408-
* Set an error in *config* and return ``-1`` on error.
2409-
2410-
2411-
.. c:function:: int PyInitConfig_SetStr(PyInitConfig *config, const char *name, const char *value)
2412-
2413-
Set a string configuration option from a null-terminated UTF-8
2414-
encoded string. The string is copied.
2415-
2416-
* Return ``0`` on success.
2417-
* Set an error in *config* and return ``-1`` on error.
2418-
2419-
2420-
.. c:function:: int PyInitConfig_SetStrList(PyInitConfig *config, const char *name, size_t length, char * const *items)
2421-
2422-
Set a string list configuration option from an array of
2423-
null-terminated UTF-8 encoded strings. The string list is copied.
2424-
2425-
* Return ``0`` on success.
2426-
* Set an error in *config* and return ``-1`` on error.
2427-
2428-
2429-
Module
2430-
------
2431-
2432-
.. c:function:: int PyInitConfig_AddModule(PyInitConfig *config, const char *name, PyObject* (*initfunc)(void))
2433-
2434-
Add a built-in extension module to the table of built-in modules.
2435-
2436-
The new module can be imported by the name *name*, and uses the function
2437-
*initfunc* as the initialization function called on the first attempted
2438-
import.
2439-
2440-
* Return ``0`` on success.
2441-
* Set an error in *config* and return ``-1`` on error.
2442-
2443-
If Python is initialized multiple times, ``PyInitConfig_AddModule()`` must
2444-
be called at each Python initialization.
2445-
2446-
Similar to the :c:func:`PyImport_AppendInittab` function.
2447-
2448-
2449-
Initialize Python
2450-
-----------------
2451-
2452-
.. c:function:: int Py_InitializeFromInitConfig(PyInitConfig *config)
2453-
2454-
Initialize Python from the initialization configuration.
2455-
2456-
* Return ``0`` on success.
2457-
* Set an error in *config* and return ``-1`` on error.
2458-
* Set an exit code in *config* and return ``-1`` if Python wants to
2459-
exit.
2460-
2461-
See ``PyInitConfig_GetExitcode()`` for the exit code case.
2462-
2463-
2464-
Example
2465-
-------
2466-
2467-
Example initializing Python, set configuration options of various types,
2468-
return ``-1`` on error:
2469-
2470-
.. code-block:: c
2471-
2472-
int init_python(void)
2473-
{
2474-
PyInitConfig *config = PyInitConfig_Create();
2475-
if (config == NULL) {
2476-
printf("PYTHON INIT ERROR: memory allocation failed\n");
2477-
return -1;
2478-
}
2479-
2480-
// Set an integer (dev mode)
2481-
if (PyInitConfig_SetInt(config, "dev_mode", 1) < 0) {
2482-
goto error;
2483-
}
2484-
2485-
// Set a list of UTF-8 strings (argv)
2486-
char *argv[] = {"my_program", "-c", "pass"};
2487-
if (PyInitConfig_SetStrList(config, "argv",
2488-
Py_ARRAY_LENGTH(argv), argv) < 0) {
2489-
goto error;
2490-
}
2491-
2492-
// Set a UTF-8 string (program name)
2493-
if (PyInitConfig_SetStr(config, "program_name", L"my_program") < 0) {
2494-
goto error;
2495-
}
2496-
2497-
// Initialize Python with the configuration
2498-
if (Py_InitializeFromInitConfig(config) < 0) {
2499-
goto error;
2500-
}
2501-
PyInitConfig_Free(config);
2502-
return 0;
2503-
2504-
error:
2505-
{
2506-
// Display the error message
2507-
// This uncommon braces style is used, because you cannot make
2508-
// goto targets point to variable declarations.
2509-
const char *err_msg;
2510-
(void)PyInitConfig_GetError(config, &err_msg);
2511-
printf("PYTHON INIT ERROR: %s\n", err_msg);
2512-
PyInitConfig_Free(config);
2513-
2514-
return -1;
2515-
}
2516-
}
2517-
2518-
2519-
Runtime Python configuration API
2520-
================================
2521-
2522-
The configuration option *name* parameter must be a non-NULL null-terminated
2523-
UTF-8 encoded string.
2524-
2525-
Some options are read from the :mod:`sys` attributes. For example, the option
2526-
``"argv"`` is read from :data:`sys.argv`.
2527-
2528-
2529-
.. c:function:: PyObject* PyConfig_Get(const char *name)
2530-
2531-
Get the current runtime value of a configuration option as a Python object.
2532-
2533-
* Return a new reference on success.
2534-
* Set an exception and return ``NULL`` on error.
2535-
2536-
The object type depends on the configuration option. It can be:
2537-
2538-
* ``bool``
2539-
* ``int``
2540-
* ``str``
2541-
* ``list[str]``
2542-
* ``dict[str, str]``
2543-
2544-
The caller must have an :term:`attached thread state`. The function cannot
2545-
be called before Python initialization nor after Python finalization.
2546-
2547-
.. versionadded:: 3.14
2548-
2549-
2550-
.. c:function:: int PyConfig_GetInt(const char *name, int *value)
2551-
2552-
Similar to :c:func:`PyConfig_Get`, but get the value as a C int.
2553-
2554-
* Return ``0`` on success.
2555-
* Set an exception and return ``-1`` on error.
2556-
2557-
.. versionadded:: 3.14
2558-
2559-
2560-
.. c:function:: PyObject* PyConfig_Names(void)
2561-
2562-
Get all configuration option names as a ``frozenset``.
2563-
2564-
* Return a new reference on success.
2565-
* Set an exception and return ``NULL`` on error.
2566-
2567-
The caller must have an :term:`attached thread state`. The function cannot
2568-
be called before Python initialization nor after Python finalization.
2569-
2570-
.. versionadded:: 3.14
2571-
2572-
2573-
.. c:function:: int PyConfig_Set(const char *name, PyObject *value)
2574-
2575-
Set the current runtime value of a configuration option.
2576-
2577-
* Raise a :exc:`ValueError` if there is no option *name*.
2578-
* Raise a :exc:`ValueError` if *value* is an invalid value.
2579-
* Raise a :exc:`ValueError` if the option is read-only (cannot be set).
2580-
* Raise a :exc:`TypeError` if *value* has not the proper type.
2581-
2582-
The caller must have an :term:`attached thread state`. The function cannot
2583-
be called before Python initialization nor after Python finalization.
2584-
2585-
.. versionadded:: 3.14
2586-
25872269
25882270
Py_GetArgcArgv()
25892271
================

0 commit comments

Comments
 (0)