1 // (C) Copyright David Abrahams 2000. 2 // Distributed under the Boost Software License, Version 1.0. (See 3 // accompanying file LICENSE_1_0.txt or copy at 4 // http://www.boost.org/LICENSE_1_0.txt) 5 // 6 // The author gratefully acknowleges the support of Dragon Systems, Inc., in 7 // producing this work. 8 9 // This file serves as a wrapper around <Python.h> which allows it to be 10 // compiled with GCC 2.95.2 under Win32 and which disables the default MSVC 11 // behavior so that a program may be compiled in debug mode without requiring a 12 // special debugging build of the Python library. 13 14 15 // To use the Python debugging library, #define BOOST_DEBUG_PYTHON on the 16 // compiler command-line. 17 18 // Revision History: 19 // 05 Mar 01 Suppress warnings under Cygwin with Python 2.0 (Dave Abrahams) 20 // 04 Mar 01 Rolled in some changes from the Dragon fork (Dave Abrahams) 21 // 01 Mar 01 define PyObject_INIT() for Python 1.x (Dave Abrahams) 22 23 #ifdef _DEBUG 24 # ifndef BOOST_DEBUG_PYTHON 25 # ifdef _MSC_VER 26 // VC8.0 will complain if system headers are #included both with 27 // and without _DEBUG defined, so we have to #include all the 28 // system headers used by pyconfig.h right here. 29 # include <stddef.h> 30 # include <stdarg.h> 31 # include <stdio.h> 32 # include <stdlib.h> 33 # include <assert.h> 34 # include <errno.h> 35 # include <ctype.h> 36 # include <wchar.h> 37 # include <basetsd.h> 38 # include <io.h> 39 # include <limits.h> 40 # include <float.h> 41 # include <string.h> 42 # include <math.h> 43 # include <time.h> 44 # endif 45 # undef _DEBUG // Don't let Python force the debug library just because we're debugging. 46 # define DEBUG_UNDEFINED_FROM_WRAP_PYTHON_H 47 # endif 48 #endif 49 50 // pyconfig.h defines a macro with hypot name, what breaks libstdc++ math headers 51 // that Python.h tries to include afterwards. 52 #if defined(__MINGW32__) 53 # include <cmath> 54 # include <math.h> 55 #endif 56 57 # include <pyconfig.h> 58 # if defined(_SGI_COMPILER_VERSION) && _SGI_COMPILER_VERSION >= 740 59 # undef _POSIX_C_SOURCE 60 # undef _XOPEN_SOURCE 61 # undef HAVE_STDINT_H // undo Python 2.5.1 define 62 # endif 63 64 // 65 // Python's LongObject.h helpfully #defines ULONGLONG_MAX for us, 66 // which confuses Boost's config 67 // 68 #include <limits.h> 69 #ifndef ULONG_MAX 70 # define BOOST_PYTHON_ULONG_MAX_UNDEFINED 71 #endif 72 #ifndef LONGLONG_MAX 73 # define BOOST_PYTHON_LONGLONG_MAX_UNDEFINED 74 #endif 75 #ifndef ULONGLONG_MAX 76 # define BOOST_PYTHON_ULONGLONG_MAX_UNDEFINED 77 #endif 78 79 // 80 // Get ahold of Python's version number 81 // 82 #include <patchlevel.h> 83 84 #if PY_MAJOR_VERSION<2 || PY_MAJOR_VERSION==2 && PY_MINOR_VERSION<2 85 #error Python 2.2 or higher is required for this version of Boost.Python. 86 #endif 87 88 // 89 // Some things we need in order to get Python.h to work with compilers other 90 // than MSVC on Win32 91 // 92 #if defined(_WIN32) || defined(__CYGWIN__) 93 94 # if defined(__GNUC__) && defined(__CYGWIN__) 95 96 # if defined(__LP64__) 97 # define SIZEOF_LONG 8 98 # else 99 # define SIZEOF_LONG 4 100 # endif 101 102 103 # if PY_MAJOR_VERSION < 2 || PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION <= 2 104 105 typedef int pid_t; 106 107 # if defined(__LP64__) 108 # define WORD_BIT 64 109 # else 110 # define WORD_BIT 32 111 # endif 112 # define hypot _hypot 113 # include <stdio.h> 114 115 # if PY_MAJOR_VERSION < 2 116 # define HAVE_CLOCK 117 # define HAVE_STRFTIME 118 # define HAVE_STRERROR 119 # endif 120 121 # define NT_THREADS 122 123 # ifndef NETSCAPE_PI 124 # define USE_SOCKET 125 # endif 126 127 # ifdef USE_DL_IMPORT 128 # define DL_IMPORT(RTYPE) __declspec(dllimport) RTYPE 129 # endif 130 131 # ifdef USE_DL_EXPORT 132 # define DL_IMPORT(RTYPE) __declspec(dllexport) RTYPE 133 # define DL_EXPORT(RTYPE) __declspec(dllexport) RTYPE 134 # endif 135 136 # define HAVE_LONG_LONG 1 137 # define LONG_LONG long long 138 # endif 139 140 # elif defined(__MWERKS__) 141 142 # ifndef _MSC_VER 143 # define PY_MSC_VER_DEFINED_FROM_WRAP_PYTHON_H 1 144 # define _MSC_VER 900 145 # endif 146 147 # undef hypot // undo the evil #define left by Python. 148 149 # elif defined(__BORLANDC__) 150 # undef HAVE_HYPOT 151 # define HAVE_HYPOT 1 152 # endif 153 154 #endif // _WIN32 155 156 #if defined(__GNUC__) 157 # if defined(__has_warning) 158 # define BOOST_PYTHON_GCC_HAS_WREGISTER __has_warning("-Wregister") 159 # else 160 # define BOOST_PYTHON_GCC_HAS_WREGISTER __GNUC__ >= 7 161 # endif 162 #else 163 # define BOOST_PYTHON_GCC_HAS_WREGISTER 0 164 #endif 165 166 // Python.h header uses `register` keyword until Python 3.4 167 #if BOOST_PYTHON_GCC_HAS_WREGISTER 168 # pragma GCC diagnostic push 169 # pragma GCC diagnostic ignored "-Wregister" 170 #elif defined(_MSC_VER) 171 # pragma warning(push) 172 # pragma warning(disable : 5033) // 'register' is no longer a supported storage class 173 #endif 174 175 #if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION == 2 && PY_MICRO_VERSION < 2 176 # include <boost/python/detail/python22_fixed.h> 177 #else 178 # include <Python.h> 179 #endif 180 181 #if BOOST_PYTHON_GCC_HAS_WREGISTER 182 # pragma GCC diagnostic pop 183 #elif defined(_MSC_VER) 184 # pragma warning(pop) 185 #endif 186 #undef BOOST_PYTHON_GCC_HAS_WREGISTER 187 188 #ifdef BOOST_PYTHON_ULONG_MAX_UNDEFINED 189 # undef ULONG_MAX 190 # undef BOOST_PYTHON_ULONG_MAX_UNDEFINED 191 #endif 192 193 #ifdef BOOST_PYTHON_LONGLONG_MAX_UNDEFINED 194 # undef LONGLONG_MAX 195 # undef BOOST_PYTHON_LONGLONG_MAX_UNDEFINED 196 #endif 197 198 #ifdef BOOST_PYTHON_ULONGLONG_MAX_UNDEFINED 199 # undef ULONGLONG_MAX 200 # undef BOOST_PYTHON_ULONGLONG_MAX_UNDEFINED 201 #endif 202 203 #ifdef PY_MSC_VER_DEFINED_FROM_WRAP_PYTHON_H 204 # undef _MSC_VER 205 #endif 206 207 #ifdef DEBUG_UNDEFINED_FROM_WRAP_PYTHON_H 208 # undef DEBUG_UNDEFINED_FROM_WRAP_PYTHON_H 209 # define _DEBUG 210 # ifdef _CRT_NOFORCE_MANIFEST_DEFINED_FROM_WRAP_PYTHON_H 211 # undef _CRT_NOFORCE_MANIFEST_DEFINED_FROM_WRAP_PYTHON_H 212 # undef _CRT_NOFORCE_MANIFEST 213 # endif 214 #endif 215 216 #if !defined(PY_MAJOR_VERSION) || PY_MAJOR_VERSION < 2 217 # define PyObject_INIT(op, typeobj) \ 218 ( (op)->ob_type = (typeobj), _Py_NewReference((PyObject *)(op)), (op) ) 219 #endif 220 221 // Define Python 3 macros for Python 2.x 222 #if PY_VERSION_HEX < 0x02060000 223 224 # define Py_TYPE(o) (((PyObject*)(o))->ob_type) 225 # define Py_REFCNT(o) (((PyObject*)(o))->ob_refcnt) 226 # define Py_SIZE(o) (((PyVarObject*)(o))->ob_size) 227 228 # define PyVarObject_HEAD_INIT(type, size) \ 229 PyObject_HEAD_INIT(type) size, 230 231 #endif 232 233 234 #ifdef __MWERKS__ 235 # pragma warn_possunwant off 236 #elif _MSC_VER 237 # pragma warning(disable:4786) 238 #endif 239 240 #if defined(HAVE_LONG_LONG) 241 # if defined(PY_LONG_LONG) 242 # define BOOST_PYTHON_LONG_LONG PY_LONG_LONG 243 # elif defined(LONG_LONG) 244 # define BOOST_PYTHON_LONG_LONG LONG_LONG 245 # else 246 # error "HAVE_LONG_LONG defined but not PY_LONG_LONG or LONG_LONG" 247 # endif 248 #endif 249