diff --git a/src/cffi/recompiler.py b/src/cffi/recompiler.py index 1d2bcdd5..31f9ba8d 100644 --- a/src/cffi/recompiler.py +++ b/src/cffi/recompiler.py @@ -423,7 +423,7 @@ def write_c_source_to_f(self, f, preamble): # on Windows, distutils insists on putting init_cffi_xyz in # 'export_symbols', so instead of fighting it, just give up and # give it one - prnt('# ifdef _MSC_VER') + prnt('# ifdef _WIN32') prnt(' PyMODINIT_FUNC') prnt(f' PyInit_{base_module_name}(void) {{ return NULL; }}') prnt('# endif') diff --git a/testing/cffi1/test_recompiler_codegen.py b/testing/cffi1/test_recompiler_codegen.py new file mode 100644 index 00000000..3bd2a170 --- /dev/null +++ b/testing/cffi1/test_recompiler_codegen.py @@ -0,0 +1,24 @@ +import io + +from cffi import FFI, recompiler +from testing.cffi0.test_parsing import FakeBackend + + +def _emit_c_source(cdef_src, module_name="pkg.myext", preamble=""): + ffi = FFI(backend=FakeBackend()) + ffi.cdef(cdef_src) + recomp = recompiler.Recompiler(ffi, module_name) + recomp.collect_type_table() + recomp.collect_step_tables() + buf = io.StringIO() + recomp.write_source_to_f(buf, preamble) + return buf.getvalue() + + +def test_pypy_windows_pyinit_exported_on_mingw(): + c_src = _emit_c_source("int foo(int);", module_name="pkg.myext") + pypy_block = c_src.split("#ifdef PYPY_VERSION", 1)[1].split("#else", 1)[0] + assert "_cffi_pypyinit_myext" in pypy_block + assert "# ifdef _WIN32" in pypy_block + assert "# ifdef _MSC_VER" not in pypy_block + assert "PyInit_myext(void) { return NULL; }" in pypy_block