Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cffi/recompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
24 changes: 24 additions & 0 deletions testing/cffi1/test_recompiler_codegen.py
Original file line number Diff line number Diff line change
@@ -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