module_init.hpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Copyright David Abrahams 2002.
  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. #ifndef MODULE_INIT_DWA20020722_HPP
  6. # define MODULE_INIT_DWA20020722_HPP
  7. # include <boost/python/detail/prefix.hpp>
  8. # include <boost/preprocessor/cat.hpp>
  9. # include <boost/preprocessor/stringize.hpp>
  10. # ifndef BOOST_PYTHON_MODULE_INIT
  11. namespace boost { namespace python { namespace detail {
  12. # if PY_VERSION_HEX >= 0x03000000
  13. BOOST_PYTHON_DECL PyObject* init_module(PyModuleDef&, void(*)());
  14. #else
  15. BOOST_PYTHON_DECL PyObject* init_module(char const* name, void(*)());
  16. #endif
  17. }}}
  18. # if PY_VERSION_HEX >= 0x03000000
  19. # define _BOOST_PYTHON_MODULE_INIT(name) \
  20. PyObject* BOOST_PP_CAT(PyInit_, name)() \
  21. { \
  22. static PyModuleDef_Base initial_m_base = { \
  23. PyObject_HEAD_INIT(NULL) \
  24. 0, /* m_init */ \
  25. 0, /* m_index */ \
  26. 0 /* m_copy */ }; \
  27. static PyMethodDef initial_methods[] = { { 0, 0, 0, 0 } }; \
  28. \
  29. static struct PyModuleDef moduledef = { \
  30. initial_m_base, \
  31. BOOST_PP_STRINGIZE(name), \
  32. 0, /* m_doc */ \
  33. -1, /* m_size */ \
  34. initial_methods, \
  35. 0, /* m_reload */ \
  36. 0, /* m_traverse */ \
  37. 0, /* m_clear */ \
  38. 0, /* m_free */ \
  39. }; \
  40. \
  41. return boost::python::detail::init_module( \
  42. moduledef, BOOST_PP_CAT(init_module_, name) ); \
  43. } \
  44. void BOOST_PP_CAT(init_module_, name)()
  45. # else
  46. # define _BOOST_PYTHON_MODULE_INIT(name) \
  47. void BOOST_PP_CAT(init,name)() \
  48. { \
  49. boost::python::detail::init_module( \
  50. BOOST_PP_STRINGIZE(name),&BOOST_PP_CAT(init_module_,name)); \
  51. } \
  52. void BOOST_PP_CAT(init_module_,name)()
  53. # endif
  54. # define BOOST_PYTHON_MODULE_INIT(name) \
  55. void BOOST_PP_CAT(init_module_,name)(); \
  56. extern "C" BOOST_SYMBOL_EXPORT _BOOST_PYTHON_MODULE_INIT(name)
  57. # endif
  58. #endif // MODULE_INIT_DWA20020722_HPP