Skip to content

Commit

Permalink
Python: fix limited API logic under mingw
Browse files Browse the repository at this point in the history
The Python Limited API support that was added in 1.2 had
special handling of Windows, but the condition to check for
Windows was not correct: it checked for MSVC and not for
the target's OS. This causes mingw installations to not have
the special handling applied.

This commit fixes this to check explicitly for Windows.
  • Loading branch information
amcn committed Jun 11, 2024
1 parent f66a527 commit fea7f94
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions mesonbuild/modules/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,9 @@ def extension_module_method(self, args: T.Tuple[str, T.List[BuildTargetSource]],
new_cpp_args.append(limited_api_definition)
kwargs['cpp_args'] = new_cpp_args

# When compiled under MSVC, Python's PC/pyconfig.h forcibly inserts pythonMAJOR.MINOR.lib
# into the linker path when not running in debug mode via a series #pragma comment(lib, "")
# directives. We manually override these here as this interferes with the intended
# use of the 'limited_api' kwarg
# On Windows, the limited API DLL is python3.dll, not python3X.dll.
for_machine = kwargs['native']
compilers = self.interpreter.environment.coredata.compilers[for_machine]
if any(compiler.get_id() == 'msvc' for compiler in compilers.values()):
if self.interpreter.environment.machines[for_machine].is_windows():
pydep_copy = copy.copy(pydep)
pydep_copy.find_libpy_windows(self.env, limited_api=True)
if not pydep_copy.found():
Expand All @@ -199,6 +195,12 @@ def extension_module_method(self, args: T.Tuple[str, T.List[BuildTargetSource]],
new_deps.remove(pydep)
new_deps.append(pydep_copy)

# When compiled under MSVC, Python's PC/pyconfig.h forcibly inserts pythonMAJOR.MINOR.lib
# into the linker path when not running in debug mode via a series #pragma comment(lib, "")
# directives. We manually override these here as this interferes with the intended
# use of the 'limited_api' kwarg
compilers = self.interpreter.environment.coredata.compilers[for_machine]
if any(compiler.get_id() == 'msvc' for compiler in compilers.values()):
pyver = pydep.version.replace('.', '')
python_windows_debug_link_exception = f'/NODEFAULTLIB:python{pyver}_d.lib'
python_windows_release_link_exception = f'/NODEFAULTLIB:python{pyver}.lib'
Expand Down

0 comments on commit fea7f94

Please sign in to comment.