Coverage Report

Created: 2025-07-04 06:49

/src/cpython/Modules/_sysconfig.c
Line
Count
Source (jump to first uncovered line)
1
// _sysconfig provides data for the Python sysconfig module
2
3
#ifndef Py_BUILD_CORE_BUILTIN
4
#  define Py_BUILD_CORE_MODULE 1
5
#endif
6
7
#include "Python.h"
8
9
#include "pycore_importdl.h"   // _PyImport_DynLoadFiletab
10
#include "pycore_long.h"       // _PyLong_GetZero, _PyLong_GetOne
11
12
13
/*[clinic input]
14
module _sysconfig
15
[clinic start generated code]*/
16
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=0a7c02d3e212ac97]*/
17
18
#include "clinic/_sysconfig.c.h"
19
20
#ifdef MS_WINDOWS
21
static int
22
add_string_value(PyObject *dict, const char *key, const char *str_value)
23
{
24
    PyObject *value = PyUnicode_FromString(str_value);
25
    if (value == NULL) {
26
        return -1;
27
    }
28
    int err = PyDict_SetItemString(dict, key, value);
29
    Py_DECREF(value);
30
    return err;
31
}
32
#endif
33
34
/*[clinic input]
35
_sysconfig.config_vars
36
37
Returns a dictionary containing build variables intended to be exposed by sysconfig.
38
[clinic start generated code]*/
39
40
static PyObject *
41
_sysconfig_config_vars_impl(PyObject *module)
42
/*[clinic end generated code: output=9c41cdee63ea9487 input=391ff42f3af57d01]*/
43
0
{
44
0
    PyObject *config = PyDict_New();
45
0
    if (config == NULL) {
46
0
        return NULL;
47
0
    }
48
49
#ifdef MS_WINDOWS
50
    if (add_string_value(config, "EXT_SUFFIX", PYD_TAGGED_SUFFIX) < 0) {
51
        Py_DECREF(config);
52
        return NULL;
53
    }
54
    if (add_string_value(config, "SOABI", PYD_SOABI) < 0) {
55
        Py_DECREF(config);
56
        return NULL;
57
    }
58
#endif
59
60
#ifdef Py_GIL_DISABLED
61
    PyObject *py_gil_disabled = _PyLong_GetOne();
62
#else
63
0
    PyObject *py_gil_disabled = _PyLong_GetZero();
64
0
#endif
65
0
    if (PyDict_SetItemString(config, "Py_GIL_DISABLED", py_gil_disabled) < 0) {
66
0
        Py_DECREF(config);
67
0
        return NULL;
68
0
    }
69
70
#ifdef Py_DEBUG
71
    PyObject *py_debug = _PyLong_GetOne();
72
#else
73
0
    PyObject *py_debug = _PyLong_GetZero();
74
0
#endif
75
0
    if (PyDict_SetItemString(config, "Py_DEBUG", py_debug) < 0) {
76
0
        Py_DECREF(config);
77
0
        return NULL;
78
0
    }
79
80
0
    return config;
81
0
}
82
83
PyDoc_STRVAR(sysconfig__doc__,
84
"A helper for the sysconfig module.");
85
86
static struct PyMethodDef sysconfig_methods[] = {
87
    _SYSCONFIG_CONFIG_VARS_METHODDEF
88
    {NULL, NULL}
89
};
90
91
static PyModuleDef_Slot sysconfig_slots[] = {
92
    {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
93
    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
94
    {0, NULL}
95
};
96
97
static PyModuleDef sysconfig_module = {
98
    .m_base = PyModuleDef_HEAD_INIT,
99
    .m_name = "_sysconfig",
100
    .m_doc = sysconfig__doc__,
101
    .m_methods = sysconfig_methods,
102
    .m_slots = sysconfig_slots,
103
};
104
105
PyMODINIT_FUNC
106
PyInit__sysconfig(void)
107
0
{
108
0
    return PyModuleDef_Init(&sysconfig_module);
109
0
}