/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 | | @permit_long_summary |
36 | | _sysconfig.config_vars |
37 | | |
38 | | Returns a dictionary containing build variables intended to be exposed by sysconfig. |
39 | | [clinic start generated code]*/ |
40 | | |
41 | | static PyObject * |
42 | | _sysconfig_config_vars_impl(PyObject *module) |
43 | | /*[clinic end generated code: output=9c41cdee63ea9487 input=fdda9cab12ca19fe]*/ |
44 | 0 | { |
45 | 0 | PyObject *config = PyDict_New(); |
46 | 0 | if (config == NULL) { |
47 | 0 | return NULL; |
48 | 0 | } |
49 | | |
50 | | #ifdef MS_WINDOWS |
51 | | if (add_string_value(config, "EXT_SUFFIX", PYD_TAGGED_SUFFIX) < 0) { |
52 | | Py_DECREF(config); |
53 | | return NULL; |
54 | | } |
55 | | if (add_string_value(config, "SOABI", PYD_SOABI) < 0) { |
56 | | Py_DECREF(config); |
57 | | return NULL; |
58 | | } |
59 | | #endif |
60 | | |
61 | | #ifdef Py_GIL_DISABLED |
62 | | PyObject *py_gil_disabled = _PyLong_GetOne(); |
63 | | #else |
64 | 0 | PyObject *py_gil_disabled = _PyLong_GetZero(); |
65 | 0 | #endif |
66 | 0 | if (PyDict_SetItemString(config, "Py_GIL_DISABLED", py_gil_disabled) < 0) { |
67 | 0 | Py_DECREF(config); |
68 | 0 | return NULL; |
69 | 0 | } |
70 | | |
71 | | #ifdef Py_DEBUG |
72 | | PyObject *py_debug = _PyLong_GetOne(); |
73 | | #else |
74 | 0 | PyObject *py_debug = _PyLong_GetZero(); |
75 | 0 | #endif |
76 | 0 | if (PyDict_SetItemString(config, "Py_DEBUG", py_debug) < 0) { |
77 | 0 | Py_DECREF(config); |
78 | 0 | return NULL; |
79 | 0 | } |
80 | | |
81 | 0 | return config; |
82 | 0 | } |
83 | | |
84 | | PyDoc_STRVAR(sysconfig__doc__, |
85 | | "A helper for the sysconfig module."); |
86 | | |
87 | | static struct PyMethodDef sysconfig_methods[] = { |
88 | | _SYSCONFIG_CONFIG_VARS_METHODDEF |
89 | | {NULL, NULL} |
90 | | }; |
91 | | |
92 | | static PyModuleDef_Slot sysconfig_slots[] = { |
93 | | {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED}, |
94 | | {Py_mod_gil, Py_MOD_GIL_NOT_USED}, |
95 | | {0, NULL} |
96 | | }; |
97 | | |
98 | | static PyModuleDef sysconfig_module = { |
99 | | .m_base = PyModuleDef_HEAD_INIT, |
100 | | .m_name = "_sysconfig", |
101 | | .m_doc = sysconfig__doc__, |
102 | | .m_methods = sysconfig_methods, |
103 | | .m_slots = sysconfig_slots, |
104 | | }; |
105 | | |
106 | | PyMODINIT_FUNC |
107 | | PyInit__sysconfig(void) |
108 | 0 | { |
109 | 0 | return PyModuleDef_Init(&sysconfig_module); |
110 | 0 | } |