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
add_string_value(PyObject * dict,const char * key,const char * str_value)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 *
_sysconfig_config_vars_impl(PyObject * module)41 _sysconfig_config_vars_impl(PyObject *module)
42 /*[clinic end generated code: output=9c41cdee63ea9487 input=391ff42f3af57d01]*/
43 {
44 PyObject *config = PyDict_New();
45 if (config == NULL) {
46 return NULL;
47 }
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 PyObject *py_gil_disabled = _PyLong_GetZero();
64 #endif
65 if (PyDict_SetItemString(config, "Py_GIL_DISABLED", py_gil_disabled) < 0) {
66 Py_DECREF(config);
67 return NULL;
68 }
69
70 return config;
71 }
72
73 PyDoc_STRVAR(sysconfig__doc__,
74 "A helper for the sysconfig module.");
75
76 static struct PyMethodDef sysconfig_methods[] = {
77 _SYSCONFIG_CONFIG_VARS_METHODDEF
78 {NULL, NULL}
79 };
80
81 static PyModuleDef_Slot sysconfig_slots[] = {
82 {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
83 {Py_mod_gil, Py_MOD_GIL_NOT_USED},
84 {0, NULL}
85 };
86
87 static PyModuleDef sysconfig_module = {
88 .m_base = PyModuleDef_HEAD_INIT,
89 .m_name = "_sysconfig",
90 .m_doc = sysconfig__doc__,
91 .m_methods = sysconfig_methods,
92 .m_slots = sysconfig_slots,
93 };
94
95 PyMODINIT_FUNC
PyInit__sysconfig(void)96 PyInit__sysconfig(void)
97 {
98 return PyModuleDef_Init(&sysconfig_module);
99 }
100