util.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /* Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0 */
  2. /* For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt */
  3. #ifndef _COVERAGE_UTIL_H
  4. #define _COVERAGE_UTIL_H
  5. #include <Python.h>
  6. /* Compile-time debugging helpers */
  7. #undef WHAT_LOG /* Define to log the WHAT params in the trace function. */
  8. #undef TRACE_LOG /* Define to log our bookkeeping. */
  9. #undef COLLECT_STATS /* Collect counters: stats are printed when tracer is stopped. */
  10. /* Py 2.x and 3.x compatibility */
  11. #if PY_MAJOR_VERSION >= 3
  12. #define MyText_Type PyUnicode_Type
  13. #define MyText_AS_BYTES(o) PyUnicode_AsASCIIString(o)
  14. #define MyBytes_GET_SIZE(o) PyBytes_GET_SIZE(o)
  15. #define MyBytes_AS_STRING(o) PyBytes_AS_STRING(o)
  16. #define MyText_AsString(o) PyUnicode_AsUTF8(o)
  17. #define MyText_FromFormat PyUnicode_FromFormat
  18. #define MyInt_FromInt(i) PyLong_FromLong((long)i)
  19. #define MyInt_AsInt(o) (int)PyLong_AsLong(o)
  20. #define MyText_InternFromString(s) PyUnicode_InternFromString(s)
  21. #define MyType_HEAD_INIT PyVarObject_HEAD_INIT(NULL, 0)
  22. #else
  23. #define MyText_Type PyString_Type
  24. #define MyText_AS_BYTES(o) (Py_INCREF(o), o)
  25. #define MyBytes_GET_SIZE(o) PyString_GET_SIZE(o)
  26. #define MyBytes_AS_STRING(o) PyString_AS_STRING(o)
  27. #define MyText_AsString(o) PyString_AsString(o)
  28. #define MyText_FromFormat PyUnicode_FromFormat
  29. #define MyInt_FromInt(i) PyInt_FromLong((long)i)
  30. #define MyInt_AsInt(o) (int)PyInt_AsLong(o)
  31. #define MyText_InternFromString(s) PyString_InternFromString(s)
  32. #define MyType_HEAD_INIT PyObject_HEAD_INIT(NULL) 0,
  33. #endif /* Py3k */
  34. /* The values returned to indicate ok or error. */
  35. #define RET_OK 0
  36. #define RET_ERROR -1
  37. /* Nicer booleans */
  38. typedef int BOOL;
  39. #define FALSE 0
  40. #define TRUE 1
  41. #endif /* _COVERAGE_UTIL_H */