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 # include <pyconfig.h> 51 # if defined(_SGI_COMPILER_VERSION) && _SGI_COMPILER_VERSION >= 740 52 # undef _POSIX_C_SOURCE 53 # undef _XOPEN_SOURCE 54 # undef HAVE_STDINT_H // undo Python 2.5.1 define 55 # endif 56 57 // 58 // Python's LongObject.h helpfully #defines ULONGLONG_MAX for us, 59 // which confuses Boost's config 60 // 61 #include <limits.h> 62 #ifndef ULONG_MAX 63 # define BOOST_PYTHON_ULONG_MAX_UNDEFINED 64 #endif 65 #ifndef LONGLONG_MAX 66 # define BOOST_PYTHON_LONGLONG_MAX_UNDEFINED 67 #endif 68 #ifndef ULONGLONG_MAX 69 # define BOOST_PYTHON_ULONGLONG_MAX_UNDEFINED 70 #endif 71 72 // 73 // Get ahold of Python's version number 74 // 75 #include <patchlevel.h> 76 77 #if PY_MAJOR_VERSION<2 || PY_MAJOR_VERSION==2 && PY_MINOR_VERSION<2 78 #error Python 2.2 or higher is required for this version of Boost.Python. 79 #endif 80 81 // 82 // Some things we need in order to get Python.h to work with compilers other 83 // than MSVC on Win32 84 // 85 #if defined(_WIN32) || defined(__CYGWIN__) 86 # if defined(__GNUC__) && defined(__CYGWIN__) 87 88 # if defined(__LP64__) 89 # define SIZEOF_LONG 8 90 # else 91 # define SIZEOF_LONG 4 92 # endif 93 94 95 # if PY_MAJOR_VERSION < 2 || PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION <= 2 96 97 typedef int pid_t; 98 99 # if defined(__LP64__) 100 # define WORD_BIT 64 101 # else 102 # define WORD_BIT 32 103 # endif 104 # define hypot _hypot 105 # include <stdio.h> 106 107 # if PY_MAJOR_VERSION < 2 108 # define HAVE_CLOCK 109 # define HAVE_STRFTIME 110 # define HAVE_STRERROR 111 # endif 112 113 # define NT_THREADS 114 115 # ifndef NETSCAPE_PI 116 # define USE_SOCKET 117 # endif 118 119 # ifdef USE_DL_IMPORT 120 # define DL_IMPORT(RTYPE) __declspec(dllimport) RTYPE 121 # endif 122 123 # ifdef USE_DL_EXPORT 124 # define DL_IMPORT(RTYPE) __declspec(dllexport) RTYPE 125 # define DL_EXPORT(RTYPE) __declspec(dllexport) RTYPE 126 # endif 127 128 # define HAVE_LONG_LONG 1 129 # define LONG_LONG long long 130 # endif 131 132 # elif defined(__MWERKS__) 133 134 # ifndef _MSC_VER 135 # define PY_MSC_VER_DEFINED_FROM_WRAP_PYTHON_H 1 136 # define _MSC_VER 900 137 # endif 138 139 # undef hypot // undo the evil #define left by Python. 140 141 # elif defined(__BORLANDC__) 142 # undef HAVE_HYPOT 143 # define HAVE_HYPOT 1 144 # endif 145 146 #endif // _WIN32 147 148 #if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION == 2 && PY_MICRO_VERSION < 2 149 # include <boost/python/detail/python22_fixed.h> 150 #else 151 # include <Python.h> 152 #endif 153 154 #ifdef BOOST_PYTHON_ULONG_MAX_UNDEFINED 155 # undef ULONG_MAX 156 # undef BOOST_PYTHON_ULONG_MAX_UNDEFINED 157 #endif 158 159 #ifdef BOOST_PYTHON_LONGLONG_MAX_UNDEFINED 160 # undef LONGLONG_MAX 161 # undef BOOST_PYTHON_LONGLONG_MAX_UNDEFINED 162 #endif 163 164 #ifdef BOOST_PYTHON_ULONGLONG_MAX_UNDEFINED 165 # undef ULONGLONG_MAX 166 # undef BOOST_PYTHON_ULONGLONG_MAX_UNDEFINED 167 #endif 168 169 #ifdef PY_MSC_VER_DEFINED_FROM_WRAP_PYTHON_H 170 # undef _MSC_VER 171 #endif 172 173 #ifdef DEBUG_UNDEFINED_FROM_WRAP_PYTHON_H 174 # undef DEBUG_UNDEFINED_FROM_WRAP_PYTHON_H 175 # define _DEBUG 176 # ifdef _CRT_NOFORCE_MANIFEST_DEFINED_FROM_WRAP_PYTHON_H 177 # undef _CRT_NOFORCE_MANIFEST_DEFINED_FROM_WRAP_PYTHON_H 178 # undef _CRT_NOFORCE_MANIFEST 179 # endif 180 #endif 181 182 #if !defined(PY_MAJOR_VERSION) || PY_MAJOR_VERSION < 2 183 # define PyObject_INIT(op, typeobj) \ 184 ( (op)->ob_type = (typeobj), _Py_NewReference((PyObject *)(op)), (op) ) 185 #endif 186 187 // Define Python 3 macros for Python 2.x 188 #if PY_VERSION_HEX < 0x02060000 189 190 # define Py_TYPE(o) (((PyObject*)(o))->ob_type) 191 # define Py_REFCNT(o) (((PyObject*)(o))->ob_refcnt) 192 # define Py_SIZE(o) (((PyVarObject*)(o))->ob_size) 193 194 # define PyVarObject_HEAD_INIT(type, size) \ 195 PyObject_HEAD_INIT(type) size, 196 197 #endif 198 199 200 #ifdef __MWERKS__ 201 # pragma warn_possunwant off 202 #elif _MSC_VER 203 # pragma warning(disable:4786) 204 #endif 205 206 #if defined(HAVE_LONG_LONG) 207 # if defined(PY_LONG_LONG) 208 # define BOOST_PYTHON_LONG_LONG PY_LONG_LONG 209 # elif defined(LONG_LONG) 210 # define BOOST_PYTHON_LONG_LONG LONG_LONG 211 # else 212 # error "HAVE_LONG_LONG defined but not PY_LONG_LONG or LONG_LONG" 213 # endif 214 #endif 215