Skip to content

Instantly share code, notes, and snippets.

@sonots
Created October 13, 2017 15:54
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save sonots/63e55ee3f7e46b4e6e897a936ae35670 to your computer and use it in GitHub Desktop.
preprocessor in cython
# A trick to embed preprocessors in cython
cdef extern from *:
cdef void EMIT_IF_PYTHON_VERSION_HEX_LT_37 "#if PY_VERSION_HEX < 0x03070000 //" ()
cdef void EMIT_ELSE "#else //" ()
cdef void EMIT_ENDIF "#endif //" ()
EMIT_IF_PYTHON_VERSION_HEX_LT_37()
EMIT_ELSE()
EMIT_ENDIF()
@ozars
Copy link

ozars commented Jun 18, 2019

Great trick! Still working as of Cython 0.29.10.

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