Skip to content

PyInit_ symbol export errors on MINGW windows PyPy builds #170

Description

@jerstlouis

As I understand it, PyInit_ is a CPython thing.

The code here:

prefix = 'PyInit_'

         if sys.platform == 'win32':
            if sys.version_info >= (3,):
                prefix = 'PyInit_'
            else:
                prefix = 'init'

seems to always generate a .def file which will cause a linker failure on trying to export the non-existing PyInit_ symbol.

I would expect a _cffi_pypyinit_ prefix for PyPy.

This makes CFFI unusable on Windows / PyPy platforms, and is quite a difficult problem to track down.

(e.g., https://github.com/ecere/pyecrt/actions/runs/14982225821/job/42088776136#step:7:3509)

CFFI extension code is generated as such:

#ifdef PYPY_VERSION
PyMODINIT_FUNC
_cffi_pypyinit_myext(const void *p[])
{
    p[0] = (const void *)0x2601;
    p[1] = &_cffi_type_context;
#if PY_MAJOR_VERSION >= 3
    return NULL;
#endif
}
#  ifdef _MSC_VER
     PyMODINIT_FUNC
#  if PY_MAJOR_VERSION >= 3
     PyInit_myext(void) { return NULL; }
#  else
     initmyext(void) { }
#  endif
#  endif
#elif PY_MAJOR_VERSION >= 3
PyMODINIT_FUNC
PyInit_myext(void)
{
  return _cffi_init("myext", 0x2601, &_cffi_type_context);
}
#else
PyMODINIT_FUNC
initmyext(void)
{
  _cffi_init("myext", 0x2601, &_cffi_type_context);
}
#endif

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions