voidptr.cpp 916 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. # include <boost/python/return_opaque_pointer.hpp>
  6. # include <boost/python/def.hpp>
  7. # include <boost/python/module.hpp>
  8. # include <boost/python/return_value_policy.hpp>
  9. static void *test=(void *) 78;
  10. void *get()
  11. {
  12. return test;
  13. }
  14. void *getnull()
  15. {
  16. return 0;
  17. }
  18. void use(void *a)
  19. {
  20. if(a!=test)
  21. throw std::runtime_error(std::string("failed"));
  22. }
  23. int useany(void *a)
  24. {
  25. return a ? 1 : 0;
  26. }
  27. namespace bpl = boost::python;
  28. BOOST_PYTHON_MODULE(voidptr_ext)
  29. {
  30. bpl::def("get", &::get, bpl::return_value_policy<bpl::return_opaque_pointer>());
  31. bpl::def("getnull", &::getnull, bpl::return_value_policy<bpl::return_opaque_pointer>());
  32. bpl::def("use", &::use);
  33. bpl::def("useany", &::useany);
  34. }