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 
4 #ifndef _COVERAGE_UTIL_H
5 #define _COVERAGE_UTIL_H
6 
7 #include <Python.h>
8 
9 /* Compile-time debugging helpers */
10 #undef WHAT_LOG         /* Define to log the WHAT params in the trace function. */
11 #undef TRACE_LOG        /* Define to log our bookkeeping. */
12 #undef COLLECT_STATS    /* Collect counters: stats are printed when tracer is stopped. */
13 
14 /* Py 2.x and 3.x compatibility */
15 
16 #if PY_MAJOR_VERSION >= 3
17 
18 #define MyText_Type         PyUnicode_Type
19 #define MyText_AS_BYTES(o)  PyUnicode_AsASCIIString(o)
20 #define MyBytes_GET_SIZE(o) PyBytes_GET_SIZE(o)
21 #define MyBytes_AS_STRING(o) PyBytes_AS_STRING(o)
22 #define MyText_AsString(o)  PyUnicode_AsUTF8(o)
23 #define MyText_FromFormat   PyUnicode_FromFormat
24 #define MyInt_FromInt(i)    PyLong_FromLong((long)i)
25 #define MyInt_AsInt(o)      (int)PyLong_AsLong(o)
26 #define MyText_InternFromString(s) \
27                             PyUnicode_InternFromString(s)
28 
29 #define MyType_HEAD_INIT    PyVarObject_HEAD_INIT(NULL, 0)
30 
31 #else
32 
33 #define MyText_Type         PyString_Type
34 #define MyText_AS_BYTES(o)  (Py_INCREF(o), o)
35 #define MyBytes_GET_SIZE(o) PyString_GET_SIZE(o)
36 #define MyBytes_AS_STRING(o) PyString_AS_STRING(o)
37 #define MyText_AsString(o)  PyString_AsString(o)
38 #define MyText_FromFormat   PyUnicode_FromFormat
39 #define MyInt_FromInt(i)    PyInt_FromLong((long)i)
40 #define MyInt_AsInt(o)      (int)PyInt_AsLong(o)
41 #define MyText_InternFromString(s) \
42                             PyString_InternFromString(s)
43 
44 #define MyType_HEAD_INIT    PyObject_HEAD_INIT(NULL)  0,
45 
46 #endif /* Py3k */
47 
48 /* The values returned to indicate ok or error. */
49 #define RET_OK      0
50 #define RET_ERROR   -1
51 
52 #endif /* _COVERAGE_UTIL_H */
53