/src/cpython/Modules/_sysconfig.c
Line | Count | Source |
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 | | #ifdef MS_WINDOWS |
85 | | /*[clinic input] |
86 | | _sysconfig.get_platform |
87 | | |
88 | | Return a string that identifies the current platform. |
89 | | [clinic start generated code]*/ |
90 | | |
91 | | static PyObject * |
92 | | _sysconfig_get_platform_impl(PyObject *module) |
93 | | /*[clinic end generated code: output=4ecbbe2b77633f3e input=c0b43abda44f9a01]*/ |
94 | | { |
95 | | #ifdef MS_WIN64 |
96 | | # if defined(_M_X64) || defined(_M_AMD64) |
97 | | # define SYSCONFIG_PLATFORM "win-amd64" |
98 | | # elif defined(_M_ARM64) |
99 | | # define SYSCONFIG_PLATFORM "win-arm64" |
100 | | # endif |
101 | | #endif |
102 | | |
103 | | #if defined(MS_WIN32) && !defined(MS_WIN64) |
104 | | # if defined(_M_IX86) |
105 | | # define SYSCONFIG_PLATFORM "win32" |
106 | | # elif defined(_M_ARM) |
107 | | # define SYSCONFIG_PLATFORM "win-arm32" |
108 | | # endif |
109 | | #endif |
110 | | |
111 | | #ifdef SYSCONFIG_PLATFORM |
112 | | return PyUnicode_FromString(SYSCONFIG_PLATFORM); |
113 | | #else |
114 | | Py_RETURN_NONE; |
115 | | #endif |
116 | | } |
117 | | #endif // MS_WINDOWS |
118 | | |
119 | | |
120 | | PyDoc_STRVAR(sysconfig__doc__, |
121 | | "A helper for the sysconfig module."); |
122 | | |
123 | | static struct PyMethodDef sysconfig_methods[] = { |
124 | | _SYSCONFIG_CONFIG_VARS_METHODDEF |
125 | | _SYSCONFIG_GET_PLATFORM_METHODDEF |
126 | | {NULL, NULL} |
127 | | }; |
128 | | |
129 | | static PyModuleDef_Slot sysconfig_slots[] = { |
130 | | {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED}, |
131 | | {Py_mod_gil, Py_MOD_GIL_NOT_USED}, |
132 | | {0, NULL} |
133 | | }; |
134 | | |
135 | | static PyModuleDef sysconfig_module = { |
136 | | .m_base = PyModuleDef_HEAD_INIT, |
137 | | .m_name = "_sysconfig", |
138 | | .m_doc = sysconfig__doc__, |
139 | | .m_methods = sysconfig_methods, |
140 | | .m_slots = sysconfig_slots, |
141 | | }; |
142 | | |
143 | | PyMODINIT_FUNC |
144 | | PyInit__sysconfig(void) |
145 | 0 | { |
146 | 0 | return PyModuleDef_Init(&sysconfig_module); |
147 | 0 | } |