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 #include <boost/python/scope.hpp>
10 #include <boost/python/object/add_to_namespace.hpp>
12 namespace boost
{ namespace python
{ namespace detail
{
16 PyObject
* init_module_in_scope(PyObject
* m
, void(*init_function
)())
20 // Create the current module scope
21 object
m_obj(((borrowed_reference_t
*)m
));
22 scope
current_module(m_obj
);
24 handle_exception(init_function
);
31 BOOST_PYTHON_DECL
void scope_setattr_doc(char const* name
, object
const& x
, char const* doc
)
33 // Use function::add_to_namespace to achieve overloading if
36 objects::add_to_namespace(current
, name
, x
, doc
);
39 #if PY_VERSION_HEX >= 0x03000000
41 BOOST_PYTHON_DECL PyObject
* init_module(PyModuleDef
& moduledef
, void(*init_function
)())
43 return init_module_in_scope(
44 PyModule_Create(&moduledef
),
52 PyMethodDef initial_methods
[] = { { 0, 0, 0, 0 } };
55 BOOST_PYTHON_DECL PyObject
* init_module(char const* name
, void(*init_function
)())
57 return init_module_in_scope(
58 Py_InitModule(const_cast<char*>(name
), initial_methods
),
64 }}} // namespace boost::python::detail
66 namespace boost
{ namespace python
{
70 BOOST_PYTHON_DECL PyObject
* current_scope
= 0;