py3.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. Python3 definition file to consistently map the code to Python 2 or
  3. Python 3.
  4. PyInt and PyLong were merged into PyLong in Python 3, so all PyInt functions
  5. are mapped to PyLong.
  6. PyString, on the other hand, was split into PyBytes and PyUnicode. We map
  7. both back onto PyString, so use PyBytes or PyUnicode where appropriate. The
  8. only exception to this is _imagingft.c, where PyUnicode is left alone.
  9. */
  10. #if PY_VERSION_HEX >= 0x03000000
  11. #define PY_ARG_BYTES_LENGTH "y#"
  12. /* Map PyInt -> PyLong */
  13. #define PyInt_AsLong PyLong_AsLong
  14. #define PyInt_Check PyLong_Check
  15. #define PyInt_FromLong PyLong_FromLong
  16. #define PyInt_AS_LONG PyLong_AS_LONG
  17. #define PyInt_FromSsize_t PyLong_FromSsize_t
  18. #define PyInt_AsSsize_t PyLong_AsSsize_t
  19. #else /* PY_VERSION_HEX < 0x03000000 */
  20. #define PY_ARG_BYTES_LENGTH "s#"
  21. #if !defined(KEEP_PY_UNICODE)
  22. /* Map PyUnicode -> PyString */
  23. #undef PyUnicode_AsString
  24. #undef PyUnicode_AS_STRING
  25. #undef PyUnicode_Check
  26. #undef PyUnicode_FromStringAndSize
  27. #undef PyUnicode_FromString
  28. #undef PyUnicode_FromFormat
  29. #undef PyUnicode_DecodeFSDefault
  30. #define PyUnicode_AsString PyString_AsString
  31. #define PyUnicode_AS_STRING PyString_AS_STRING
  32. #define PyUnicode_Check PyString_Check
  33. #define PyUnicode_FromStringAndSize PyString_FromStringAndSize
  34. #define PyUnicode_FromString PyString_FromString
  35. #define PyUnicode_FromFormat PyString_FromFormat
  36. #define PyUnicode_DecodeFSDefault PyString_FromString
  37. #endif
  38. /* Map PyBytes -> PyString */
  39. #define PyBytesObject PyStringObject
  40. #define PyBytes_AsString PyString_AsString
  41. #define PyBytes_AS_STRING PyString_AS_STRING
  42. #define PyBytes_Check PyString_Check
  43. #define PyBytes_AsStringAndSize PyString_AsStringAndSize
  44. #define PyBytes_FromStringAndSize PyString_FromStringAndSize
  45. #define PyBytes_FromString PyString_FromString
  46. #define _PyBytes_Resize _PyString_Resize
  47. #endif /* PY_VERSION_HEX < 0x03000000 */