◐ Shell
clean mode source ↗

gh-140550: Remove PyInit function from test_cext by encukou · Pull Request #141511 · python/cpython

@encukou

@encukou encukou commented

Nov 13, 2025

edited by bedevere-app Bot

Loading

vstinner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@bedevere-bot

@vstinner

FreeBSD failures are unrelated and should be fixed by #141551.

@vstinner

buildbot/AMD64 Windows PGO NoGIL PR
buildbot/AMD64 Windows11 Non-Debug PR

test_cext fails with:

  "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\bin\HostX86\x64\link.exe" /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO /LIBPATH:C:\Users\Administrator\buildarea\pull_request.itamaro-win64-srv-22-aws.nogil.pgo\build\PCbuild\AMD64 /LIBPATH:C:\Users\Administrator\buildarea\pull_request.itamaro-win64-srv-22-aws.nogil.pgo\build\build\test_python_3776æ\tempcwd\env\libs /LIBPATH:C:\Users\Administrator\buildarea\pull_request.itamaro-win64-srv-22-aws.nogil.pgo\build\libs /LIBPATH:C:\Users\Administrator\buildarea\pull_request.itamaro-win64-srv-22-aws.nogil.pgo\build /LIBPATH:C:\Users\Administrator\buildarea\pull_request.itamaro-win64-srv-22-aws.nogil.pgo\build\build\test_python_3776æ\tempcwd\env\PCbuild\amd64 "/LIBPATH:C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\lib\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.26100.0\ucrt\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\\lib\10.0.26100.0\\um\x64" /EXPORT:PyInit__test_cext build\temp.win-amd64-cpython-315t\Release\extension.obj /OUT:build\lib.win-amd64-cpython-315t\_test_cext.cp315t-win_amd64.pyd /IMPLIB:build\temp.win-amd64-cpython-315t\Release\_test_cext.cp315t-win_amd64.lib
  LINK : error LNK2001: unresolved external symbol PyInit__test_cext
  build\temp.win-amd64-cpython-315t\Release\_test_cext.cp315t-win_amd64.lib : fatal error LNK1120: 1 unresolved externals
  error: command 'C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.44.35207\\bin\\HostX86\\x64\\link.exe' failed with exit code 1120
  error: subprocess-exited-with-error

It looks like a legit error.

The (long) build command contains /EXPORT:PyInit__test_cext.

@encukou

This one will need coordination with setuptools. Glad we found it early :)

Setuptools is adding an /EXPORT specification to the LINK command for the PyInit_* function.
This fails if there is no such function.

According to MSVC docs:

There are four methods for exporting a definition, listed in recommended order of use:

  1. __declspec(dllexport) in the source code
  2. An EXPORTS statement in a .def file
  3. An /EXPORT specification in a LINK command
  4. A comment directive in the source code, of the form #pragma comment(linker, "/export: definition ").

We should be using method (1). Once we do, setuptools can stop doing (3), perhaps conditionally.

@encukou

@github-actions

This PR is stale because it has been open for 30 days with no activity.