Skip to content

Commit 73ffc4a

Browse files
committed
Support for free-function def() invocation (no module object)
Fix bugs relying on initialization of objects in the Python DLL [SVN r15142]
1 parent 865ef2a commit 73ffc4a

1 file changed

Lines changed: 68 additions & 0 deletions

File tree

include/boost/python/def.hpp

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Copyright David Abrahams 2002. Permission to copy, use,
2+
// modify, sell and distribute this software is granted provided this
3+
// copyright notice appears in all copies. This software is provided
4+
// "as is" without express or implied warranty, and with no claim as
5+
// to its suitability for any purpose.
6+
#ifndef DEF_DWA200292_HPP
7+
# define DEF_DWA200292_HPP
8+
9+
# include <boost/python/object_fwd.hpp>
10+
# include <boost/python/make_function.hpp>
11+
# include <boost/python/detail/def_helper.hpp>
12+
# include <boost/python/detail/defaults_def.hpp>
13+
# include <boost/python/scope.hpp>
14+
15+
namespace boost { namespace python {
16+
17+
namespace detail
18+
{
19+
void BOOST_PYTHON_DECL scope_setattr_doc(char const* name, object const& obj, char const* doc);
20+
21+
template <class Fn, class CallPolicyOrDoc>
22+
void
23+
dispatch_def(
24+
char const* name,
25+
Fn fn,
26+
CallPolicyOrDoc const& policy_or_doc,
27+
char const* doc,
28+
void const*)
29+
{
30+
typedef detail::def_helper<CallPolicyOrDoc> helper;
31+
32+
detail::scope_setattr_doc(
33+
name, boost::python::make_function(fn, helper::get_policy(policy_or_doc)),
34+
helper::get_doc(policy_or_doc, doc));
35+
}
36+
37+
template <typename StubsT, typename SigT>
38+
void
39+
dispatch_def(
40+
char const* name,
41+
SigT sig,
42+
StubsT const& stubs,
43+
char const* doc,
44+
detail::func_stubs_base const*)
45+
{
46+
// convert sig to a type_list (see detail::get_signature in signature.hpp)
47+
// before calling detail::define_with_defaults.
48+
scope current;
49+
detail::define_with_defaults(name, stubs, current, detail::get_signature(sig), doc);
50+
}
51+
}
52+
53+
template <class Fn>
54+
void def(char const* name, Fn fn)
55+
{
56+
detail::scope_setattr_doc(name, boost::python::make_function(fn), 0);
57+
}
58+
59+
template <class Arg1T, class Arg2T>
60+
void def(char const* name, Arg1T arg1, Arg2T const& arg2, char const* doc = 0)
61+
{
62+
detail::dispatch_def(name, arg1, arg2, doc, &arg2);
63+
}
64+
65+
66+
}} // namespace boost::python
67+
68+
#endif // DEF_DWA200292_HPP

0 commit comments

Comments
 (0)