1 #include <Python.h>
2
3 /***************************************************************************
4 * Macros for determining the compiler version.
5 *
6 * These are borrowed from boost, and majorly abridged to include only
7 * the compilers we care about.
8 ***************************************************************************/
9
10 #define STRINGIZE(X) DO_STRINGIZE(X)
11 #define DO_STRINGIZE(X) #X
12
13 #if defined __clang__
14 /* Clang C++ emulates GCC, so it has to appear early. */
15 # define COMPILER "Clang version " __clang_version__
16
17 #elif defined(__INTEL_COMPILER) || defined(__ICL) || defined(__ICC) || defined(__ECC)
18 /* Intel */
19 # if defined(__INTEL_COMPILER)
20 # define INTEL_VERSION __INTEL_COMPILER
21 # elif defined(__ICL)
22 # define INTEL_VERSION __ICL
23 # elif defined(__ICC)
24 # define INTEL_VERSION __ICC
25 # elif defined(__ECC)
26 # define INTEL_VERSION __ECC
27 # endif
28 # define COMPILER "Intel C compiler version " STRINGIZE(INTEL_VERSION)
29
30 #elif defined(__GNUC__)
31 /* gcc */
32 # define COMPILER "GCC version " __VERSION__
33
34 #elif defined(__SUNPRO_CC)
35 /* Sun Workshop Compiler */
36 # define COMPILER "Sun compiler version " STRINGIZE(__SUNPRO_CC)
37
38 #elif defined(_MSC_VER)
39 /* Microsoft Visual C/C++
40 Must be last since other compilers define _MSC_VER for compatibility as well */
41 # if _MSC_VER < 1200
42 # define COMPILER_VERSION 5.0
43 # elif _MSC_VER < 1300
44 # define COMPILER_VERSION 6.0
45 # elif _MSC_VER == 1300
46 # define COMPILER_VERSION 7.0
47 # elif _MSC_VER == 1310
48 # define COMPILER_VERSION 7.1
49 # elif _MSC_VER == 1400
50 # define COMPILER_VERSION 8.0
51 # elif _MSC_VER == 1500
52 # define COMPILER_VERSION 9.0
53 # elif _MSC_VER == 1600
54 # define COMPILER_VERSION 10.0
55 # else
56 # define COMPILER_VERSION _MSC_VER
57 # endif
58 # define COMPILER "Microsoft Visual C++ version " STRINGIZE(COMPILER_VERSION)
59
60 #else
61 /* Fallback */
62 # define COMPILER "Unknown compiler"
63
64 #endif
65
66
67 /***************************************************************************
68 * Module-level
69 ***************************************************************************/
70
71 struct module_state {
72 /* The Sun compiler can't handle empty structs */
73 #if defined(__SUNPRO_C) || defined(_MSC_VER)
74 int _dummy;
75 #endif
76 };
77
78 static struct PyModuleDef moduledef = {
79 PyModuleDef_HEAD_INIT,
80 "compiler_version",
81 NULL,
82 sizeof(struct module_state),
83 NULL,
84 NULL,
85 NULL,
86 NULL,
87 NULL
88 };
89
90 #define INITERROR return NULL
91
92 PyMODINIT_FUNC
PyInit_compiler_version(void)93 PyInit_compiler_version(void)
94
95
96 {
97 PyObject* m;
98
99 m = PyModule_Create(&moduledef);
100
101 if (m == NULL)
102 INITERROR;
103
104 PyModule_AddStringConstant(m, "compiler", COMPILER);
105
106 return m;
107 }
108