1. Python CFFI
  2. Untitled project
  3. cffi
  4. Issues
Issue #153 resolved

Generate same C code for CPython 2 and 3

Lisandro Dalcin
created an issue

Currently, the C code generated after ffi.verify() is the same for both CPytho 2 and 3 except for the extension module init function. Would you accept a patch to generate the same C code for both major CPython version?

Comments (6)

  1. Lisandro Dalcin reporter

    The main rationale is related to using a setup.py for distributing extension modules. Right now, if you run "python setup.py build" and then you run it again (or run "python setup.py install", possibly as root), cffi regenerates the C sources and this re-triggers the execution of the C compiler. I would like to fix this behaviour in the near future, and I believe a necessary step is to generate CPy2/3 compatible C source code.

    Other option would be to add a implementation+major_version tag to the generated C source files, e.g. "sourcefilename-cpy2.c" or "sourcefilename-pypy.c".

    While working on a patch for this issue, I've realized that _cffi_setup() does not return an error code, this should be improved and handled in the init function. I'll open another issue for it and upload a patch, then we can go back to this one to take a final decision on it.

  2. Armin Rigo

    Ok. Thanks for the pull request, including the fixes to some details! Merged. Indeed, if having a single C source simplifies the life of upcoming fixes, then it was easy to provide anyway.

  3. Log in to comment