]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/python/src/module.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / python / src / module.cpp
CommitLineData
7c673cae
FG
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#include <boost/python/scope.hpp>
10#include <boost/python/object/add_to_namespace.hpp>
11
12namespace boost { namespace python { namespace detail {
13
14namespace
15{
16 PyObject* init_module_in_scope(PyObject* m, void(*init_function)())
17 {
18 if (m != 0)
19 {
20 // Create the current module scope
21 object m_obj(((borrowed_reference_t*)m));
22 scope current_module(m_obj);
23
1e59de90 24 if (handle_exception(init_function)) return NULL;
7c673cae
FG
25 }
26
27 return m;
28 }
29}
30
31BOOST_PYTHON_DECL void scope_setattr_doc(char const* name, object const& x, char const* doc)
32{
33 // Use function::add_to_namespace to achieve overloading if
34 // appropriate.
35 scope current;
36 objects::add_to_namespace(current, name, x, doc);
37}
38
39#if PY_VERSION_HEX >= 0x03000000
40
41BOOST_PYTHON_DECL PyObject* init_module(PyModuleDef& moduledef, void(*init_function)())
42{
43 return init_module_in_scope(
44 PyModule_Create(&moduledef),
45 init_function);
46}
47
48#else
49
50namespace
51{
52 PyMethodDef initial_methods[] = { { 0, 0, 0, 0 } };
53}
54
55BOOST_PYTHON_DECL PyObject* init_module(char const* name, void(*init_function)())
56{
57 return init_module_in_scope(
58 Py_InitModule(const_cast<char*>(name), initial_methods),
59 init_function);
60}
61
62#endif
63
64}}} // namespace boost::python::detail
65
66namespace boost { namespace python {
67
68namespace detail
69{
70 BOOST_PYTHON_DECL PyObject* current_scope = 0;
71}
72
73}}