Skip to content

Emit PyPy dummy PyInit_ symbol under _WIN32 - #294

Open
M-Colley wants to merge 1 commit into
python-cffi:mainfrom
M-Colley:fix/issue-170-mingw-pypy-pyinit
Open

M-Colley wants to merge 1 commit into
python-cffi:mainfrom
M-Colley:fix/issue-170-mingw-pypy-pyinit

Conversation

@M-Colley

Copy link
Copy Markdown

Windows PyPy builds compiled with MinGW fail at link time with an undefined PyInit_ export error. Specifically, distutils and setuptools add PyInit_ to the extension export list on all Windows toolchains. Previously, src/cffi/recompiler.py guarded the dummy PyInit_ stub inside the PYPY_VERSION block with #ifdef _MSC_VER, leaving the exported symbol undefined under MinGW. Fixes #170.

This change updates src/cffi/recompiler.py to guard the dummy PyInit_ definition with #ifdef _WIN32. Consequently, both MSVC and MinGW toolchains on Windows define the required stub symbol. Additionally, testing/cffi1/test_recompiler_codegen.py adds a regression test verifying the generated PYPY_VERSION preprocessor block.

Verification ran pytest on testing/cffi1/test_recompiler_codegen.py and testing/cffi0/test_model.py, passing all 14 tests.

Fixes python-cffi#170.

Signed-off-by: Mark Colley <39366189+M-Colley@users.noreply.github.com>

@mattip mattip left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All the test does is check that the c source now has the ifdef condition, right? It does not actually check that mingw + pypy works. Did you test this in practice?

And this will never run on real code since pypy ships its own vendored cffi.

I would be more convinced to do this as a backport from pypy. So first make the change in pypy, verify it fixes the problem there (does anything work with mingw + pypy + cffi?), then backport it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PyInit_ symbol export errors on MINGW windows PyPy builds

2 participants