-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
gh-88402: Add new sysconfig variables on Windows (GH-110049) #110049
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
30814e4
gh-88402: Add new sysconfig variables on Windows
colesbury 3f2a744
Update 2023-09-28-12-32-57.gh-issue-88402.hoa3Gx.rst
colesbury 0ce92b2
Compute some sysconfig variables in _winapi
colesbury aa396e5
Move Python/importdl.h to Include/internal/pycore_importdl.h
colesbury 89f891c
Add _sysconfig module
colesbury 14d201c
Update Modules/_sysconfig.c
colesbury 34fe412
Fix "Py_NOGIL" sysconfig variable.
colesbury db30ede
Compute PYD_TAGGED_SUFFIX and PYD_SOABI in pycore_importdl.h
colesbury f0fb235
regen clinic
colesbury 0a84d76
Fix sysconfig test on POSIX systems.
colesbury File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#ifndef Py_INTERNAL_IMPORTDL_H | ||
#define Py_INTERNAL_IMPORTDL_H | ||
|
||
#include "patchlevel.h" // PY_MAJOR_VERSION | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#ifndef Py_BUILD_CORE | ||
# error "this header requires Py_BUILD_CORE define" | ||
#endif | ||
|
||
|
||
extern const char *_PyImport_DynLoadFiletab[]; | ||
|
||
extern PyObject *_PyImport_LoadDynamicModuleWithSpec(PyObject *spec, FILE *); | ||
|
||
typedef PyObject *(*PyModInitFunction)(void); | ||
|
||
/* Max length of module suffix searched for -- accommodates "module.slb" */ | ||
#define MAXSUFFIXSIZE 12 | ||
|
||
#ifdef MS_WINDOWS | ||
#include <windows.h> | ||
typedef FARPROC dl_funcptr; | ||
|
||
#ifdef _DEBUG | ||
# define PYD_DEBUG_SUFFIX "_d" | ||
#else | ||
# define PYD_DEBUG_SUFFIX "" | ||
#endif | ||
|
||
#ifdef Py_NOGIL | ||
# define PYD_THREADING_TAG "t" | ||
#else | ||
# define PYD_THREADING_TAG "" | ||
#endif | ||
|
||
#ifdef PYD_PLATFORM_TAG | ||
# define PYD_SOABI "cp" Py_STRINGIFY(PY_MAJOR_VERSION) Py_STRINGIFY(PY_MINOR_VERSION) PYD_THREADING_TAG "-" PYD_PLATFORM_TAG | ||
#else | ||
# define PYD_SOABI "cp" Py_STRINGIFY(PY_MAJOR_VERSION) Py_STRINGIFY(PY_MINOR_VERSION) PYD_THREADING_TAG | ||
#endif | ||
|
||
#define PYD_TAGGED_SUFFIX PYD_DEBUG_SUFFIX "." PYD_SOABI ".pyd" | ||
#define PYD_UNTAGGED_SUFFIX PYD_DEBUG_SUFFIX ".pyd" | ||
|
||
#else | ||
typedef void (*dl_funcptr)(void); | ||
#endif | ||
|
||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
#endif /* !Py_INTERNAL_IMPORTDL_H */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
Misc/NEWS.d/next/Library/2023-09-28-12-32-57.gh-issue-88402.hoa3Gx.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Add new variables to :py:meth:`sysconfig.get_config_vars` on Windows: | ||
``LIBRARY``, ``LDLIBRARY``, ``LIBDIR``, ``SOABI``, and ``Py_NOGIL``. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// _sysconfig provides data for the Python sysconfig module | ||
|
||
#ifndef Py_BUILD_CORE_BUILTIN | ||
# define Py_BUILD_CORE_MODULE 1 | ||
#endif | ||
|
||
#include "Python.h" | ||
|
||
#include "pycore_importdl.h" // _PyImport_DynLoadFiletab | ||
#include "pycore_long.h" // _PyLong_GetZero, _PyLong_GetOne | ||
|
||
|
||
/*[clinic input] | ||
module _sysconfig | ||
[clinic start generated code]*/ | ||
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=0a7c02d3e212ac97]*/ | ||
|
||
#include "clinic/_sysconfig.c.h" | ||
|
||
#ifdef MS_WINDOWS | ||
static int | ||
add_string_value(PyObject *dict, const char *key, const char *str_value) | ||
{ | ||
PyObject *value = PyUnicode_FromString(str_value); | ||
if (value == NULL) { | ||
return -1; | ||
} | ||
int err = PyDict_SetItemString(dict, key, value); | ||
Py_DECREF(value); | ||
return err; | ||
} | ||
#endif | ||
|
||
/*[clinic input] | ||
_sysconfig.config_vars | ||
|
||
Returns a dictionary containing build variables intended to be exposed by sysconfig. | ||
[clinic start generated code]*/ | ||
|
||
static PyObject * | ||
_sysconfig_config_vars_impl(PyObject *module) | ||
/*[clinic end generated code: output=9c41cdee63ea9487 input=391ff42f3af57d01]*/ | ||
{ | ||
PyObject *config = PyDict_New(); | ||
if (config == NULL) { | ||
return NULL; | ||
} | ||
|
||
#ifdef MS_WINDOWS | ||
if (add_string_value(config, "EXT_SUFFIX", PYD_TAGGED_SUFFIX) < 0) { | ||
Py_DECREF(config); | ||
return NULL; | ||
} | ||
if (add_string_value(config, "SOABI", PYD_SOABI) < 0) { | ||
Py_DECREF(config); | ||
return NULL; | ||
} | ||
#endif | ||
|
||
#ifdef Py_NOGIL | ||
PyObject *py_nogil = _PyLong_GetOne(); | ||
#else | ||
PyObject *py_nogil = _PyLong_GetZero(); | ||
#endif | ||
if (PyDict_SetItemString(config, "Py_NOGIL", py_nogil) < 0) { | ||
Py_DECREF(config); | ||
return NULL; | ||
} | ||
|
||
return config; | ||
} | ||
|
||
PyDoc_STRVAR(sysconfig__doc__, | ||
"A helper for the sysconfig module."); | ||
|
||
static struct PyMethodDef sysconfig_methods[] = { | ||
_SYSCONFIG_CONFIG_VARS_METHODDEF | ||
{NULL, NULL} | ||
}; | ||
|
||
static PyModuleDef_Slot sysconfig_slots[] = { | ||
{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED}, | ||
{0, NULL} | ||
}; | ||
|
||
static PyModuleDef sysconfig_module = { | ||
.m_base = PyModuleDef_HEAD_INIT, | ||
.m_name = "_sysconfig", | ||
.m_doc = sysconfig__doc__, | ||
.m_methods = sysconfig_methods, | ||
.m_slots = sysconfig_slots, | ||
}; | ||
|
||
PyMODINIT_FUNC | ||
PyInit__sysconfig(void) | ||
{ | ||
return PyModuleDef_Init(&sysconfig_module); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(note for the future)
I think we can move this to
_init_config_vars
, I am sure it will end up there soon anyway. The only thing to keep in mind is that we allow the POSIX config vars module (eg._sysconfigdata__linux_x86_64-linux-gnu
) to be overwritten (to help in cross-compilation) by setting_PYTHON_SYSCONFIGDATA_NAME
, and we should raise an error if the value given by the user is different from what we computed.To be even more cautious, I think we should probably save the original
sysconfigdata
name in the C module, as attributes likesys.implementation
, etc., are often monkey patched when cross-compiling. If needed, people working on cross-compilation should also monkey patch the_sysconfig
module explicitly, or better, just monkey patchsysconfig.get_config_vars
.You don't need to do it in this PR, I just wanted to write this down, especially to document the non-obvious issue with
_PYTHON_SYSCONFIGDATA_NAME
.I don't think relying on Makefile variables is great, for a ton of reasons, meaning the new sysconfig API (GH-103480) will very likely use
_sysconfig.config_vars
on other platforms, so I expect the_PYTHON_SYSCONFIGDATA_NAME
issue to be relevant soon.