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)
6 // The author gratefully acknowleges the support of Dragon Systems, Inc., in
7 // producing this work.
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.
15 // To use the Python debugging library, #define BOOST_DEBUG_PYTHON on the
16 // compiler command-line.
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)
24 # ifndef BOOST_DEBUG_PYTHON
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.
45 # undef _DEBUG // Don't let Python force the debug library just because we're debugging.
46 # define DEBUG_UNDEFINED_FROM_WRAP_PYTHON_H
50 # include <pyconfig.h>
51 # if defined(_SGI_COMPILER_VERSION) && _SGI_COMPILER_VERSION >= 740
52 # undef _POSIX_C_SOURCE
54 # undef HAVE_STDINT_H // undo Python 2.5.1 define
58 // Python's LongObject.h helpfully #defines ULONGLONG_MAX for us,
59 // which confuses Boost's config
63 # define BOOST_PYTHON_ULONG_MAX_UNDEFINED
66 # define BOOST_PYTHON_LONGLONG_MAX_UNDEFINED
69 # define BOOST_PYTHON_ULONGLONG_MAX_UNDEFINED
73 // Get ahold of Python's version number
75 #include <patchlevel.h>
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.
82 // Some things we need in order to get Python.h to work with compilers other
85 #if defined(_WIN32) || defined(__CYGWIN__)
86 # if defined(__GNUC__) && defined(__CYGWIN__)
88 # if defined(__LP64__)
89 # define SIZEOF_LONG 8
91 # define SIZEOF_LONG 4
95 # if PY_MAJOR_VERSION < 2 || PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION <= 2
99 # if defined(__LP64__)
104 # define hypot _hypot
107 # if PY_MAJOR_VERSION < 2
109 # define HAVE_STRFTIME
110 # define HAVE_STRERROR
119 # ifdef USE_DL_IMPORT
120 # define DL_IMPORT(RTYPE) __declspec(dllimport) RTYPE
123 # ifdef USE_DL_EXPORT
124 # define DL_IMPORT(RTYPE) __declspec(dllexport) RTYPE
125 # define DL_EXPORT(RTYPE) __declspec(dllexport) RTYPE
128 # define HAVE_LONG_LONG 1
129 # define LONG_LONG long long
132 # elif defined(__MWERKS__)
135 # define PY_MSC_VER_DEFINED_FROM_WRAP_PYTHON_H 1
136 # define _MSC_VER 900
139 # undef hypot // undo the evil #define left by Python.
141 # elif defined(__BORLANDC__)
143 # define HAVE_HYPOT 1
148 #if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION == 2 && PY_MICRO_VERSION < 2
149 # include <boost/python/detail/python22_fixed.h>
154 #ifdef BOOST_PYTHON_ULONG_MAX_UNDEFINED
156 # undef BOOST_PYTHON_ULONG_MAX_UNDEFINED
159 #ifdef BOOST_PYTHON_LONGLONG_MAX_UNDEFINED
161 # undef BOOST_PYTHON_LONGLONG_MAX_UNDEFINED
164 #ifdef BOOST_PYTHON_ULONGLONG_MAX_UNDEFINED
165 # undef ULONGLONG_MAX
166 # undef BOOST_PYTHON_ULONGLONG_MAX_UNDEFINED
169 #ifdef PY_MSC_VER_DEFINED_FROM_WRAP_PYTHON_H
173 #ifdef DEBUG_UNDEFINED_FROM_WRAP_PYTHON_H
174 # undef DEBUG_UNDEFINED_FROM_WRAP_PYTHON_H
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
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) )
187 // Define Python 3 macros for Python 2.x
188 #if PY_VERSION_HEX < 0x02060000
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)
194 # define PyVarObject_HEAD_INIT(type, size) \
195 PyObject_HEAD_INIT(type) size,
201 # pragma warn_possunwant off
203 # pragma warning(disable:4786)
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
212 # error "HAVE_LONG_LONG defined but not PY_LONG_LONG or LONG_LONG"