forked from boostorg/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodule.cpp
More file actions
88 lines (70 loc) · 2.33 KB
/
module.cpp
File metadata and controls
88 lines (70 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// (C) Copyright David Abrahams 2000. Permission to copy, use, modify, sell and
// distribute this software is granted provided this copyright notice appears
// in all copies. This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
//
// The author gratefully acknowleges the support of Dragon Systems, Inc., in
// producing this work.
#include <boost/python/object/function_object.hpp>
#include <boost/python/detail/module_base.hpp>
#include <boost/python/cast.hpp>
#include <boost/python/scope.hpp>
#include <boost/python/borrowed.hpp>
#include <boost/python/object.hpp>
#include <boost/python/detail/raw_pyobject.hpp>
#include <boost/python/scope.hpp>
namespace boost { namespace python { namespace detail {
module_base::module_base(char const* name, char const* doc)
: m_module(
allow_null(python::borrowed(
scope().ptr()
)))
{
if (doc != 0)
scope().attr("__doc__") = doc;
}
module_base::~module_base()
{
}
void module_base::setattr_doc(const char* name, python::object const& x, char const* doc)
{
// Use function::add_to_namespace to achieve overloading if
// appropriate.
objects::add_to_namespace(python::object(m_module), name, x, doc);
}
void BOOST_PYTHON_DECL scope_setattr_doc(char const* name, object const& x, char const* doc)
{
// Use function::add_to_namespace to achieve overloading if
// appropriate.
scope current;
objects::add_to_namespace(current, name, x, doc);
}
void module_base::add(type_handle const& x)
{
this->setattr_doc(x->tp_name, python::object(x), 0);
}
PyMethodDef module_base::initial_methods[] = { { 0, 0, 0, 0 } };
namespace
{
PyMethodDef initial_methods[] = { { 0, 0, 0, 0 } };
}
BOOST_PYTHON_DECL void init_module(char const* name, void(*init_function)())
{
PyObject* m
= Py_InitModule(const_cast<char*>(name), initial_methods);
if (m != 0)
{
;
// Create the current module scope
scope current_module(
(object(
((borrowed_reference_t*)m)
))
);
handle_exception(init_function);
}
}
}}} // namespace boost::python::detail
namespace boost { namespace python {
BOOST_PYTHON_DECL PyObject* scope::current_scope = 0;
}}