Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

_compat.h 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /* Straddle Python 2 / 3 */
  2. #ifndef BTREES__COMPAT_H
  3. #define BTREES__COMPAT_H
  4. #include "Python.h"
  5. #ifdef INTERN
  6. #undef INTERN
  7. #endif
  8. #ifdef INT_FROM_LONG
  9. #undef INT_FROM_LONG
  10. #endif
  11. #ifdef INT_CHECK
  12. #undef INT_CHECK
  13. #endif
  14. #if PY_MAJOR_VERSION >= 3
  15. #define PY3K
  16. #define INTERN PyUnicode_InternFromString
  17. #define INT_FROM_LONG(x) PyLong_FromLong(x)
  18. #define INT_CHECK(x) PyLong_Check(x)
  19. #define INT_AS_LONG(x) PyLong_AS_LONG(x)
  20. #define TEXT_FROM_STRING PyUnicode_FromString
  21. #define TEXT_FORMAT PyUnicode_Format
  22. /* Note that the second comparison is skipped if the first comparison returns:
  23. 1 -> There was no error and the answer is -1
  24. -1 -> There was an error, which the caller will detect with PyError_Occurred.
  25. */
  26. #define COMPARE(lhs, rhs) \
  27. (lhs == Py_None ? (rhs == Py_None ? 0 : -1) : (rhs == Py_None ? 1 : \
  28. (PyObject_RichCompareBool((lhs), (rhs), Py_LT) != 0 ? -1 : \
  29. (PyObject_RichCompareBool((lhs), (rhs), Py_EQ) > 0 ? 0 : 1))))
  30. #else
  31. #define INTERN PyString_InternFromString
  32. #define INT_FROM_LONG(x) PyInt_FromLong(x)
  33. #define INT_CHECK(x) PyInt_Check(x)
  34. #define INT_AS_LONG(x) PyInt_AS_LONG(x)
  35. #define TEXT_FROM_STRING PyString_FromString
  36. #define TEXT_FORMAT PyString_Format
  37. #define COMPARE(lhs, rhs) \
  38. (lhs == Py_None ? (rhs == Py_None ? 0 : -1) : (rhs == Py_None ? 1 : \
  39. PyObject_Compare((lhs), (rhs))))
  40. #endif
  41. #endif /* BTREES__COMPAT_H */