• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright Niall Douglas 2005.
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
5 
6 # include <boost/python/return_opaque_pointer.hpp>
7 # include <boost/python/def.hpp>
8 # include <boost/python/module.hpp>
9 # include <boost/python/return_value_policy.hpp>
10 
11 static void *test=(void *) 78;
12 
get()13 void *get()
14 {
15     return test;
16 }
17 
getnull()18 void *getnull()
19 {
20     return 0;
21 }
22 
use(void * a)23 void use(void *a)
24 {
25     if(a!=test)
26         throw std::runtime_error(std::string("failed"));
27 }
28 
useany(void * a)29 int useany(void *a)
30 {
31     return a ? 1 : 0;
32 }
33 
34 
35 namespace bpl = boost::python;
36 
BOOST_PYTHON_MODULE(voidptr_ext)37 BOOST_PYTHON_MODULE(voidptr_ext)
38 {
39     bpl::def("get", &::get, bpl::return_value_policy<bpl::return_opaque_pointer>());
40     bpl::def("getnull", &::getnull, bpl::return_value_policy<bpl::return_opaque_pointer>());
41     bpl::def("use", &::use);
42     bpl::def("useany", &::useany);
43 }
44