instance.hpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright David Abrahams 2002.
  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. #ifndef INSTANCE_DWA200295_HPP
  6. # define INSTANCE_DWA200295_HPP
  7. # include <boost/python/detail/prefix.hpp>
  8. # include <boost/python/detail/type_traits.hpp>
  9. # include <cstddef>
  10. namespace boost { namespace python
  11. {
  12. struct instance_holder;
  13. }} // namespace boost::python
  14. namespace boost { namespace python { namespace objects {
  15. // Each extension instance will be one of these
  16. template <class Data = char>
  17. struct instance
  18. {
  19. PyObject_VAR_HEAD
  20. PyObject* dict;
  21. PyObject* weakrefs;
  22. instance_holder* objects;
  23. typedef typename boost::python::detail::type_with_alignment<
  24. boost::python::detail::alignment_of<Data>::value
  25. >::type align_t;
  26. union
  27. {
  28. align_t align;
  29. char bytes[sizeof(Data)];
  30. } storage;
  31. };
  32. template <class Data>
  33. struct additional_instance_size
  34. {
  35. typedef instance<Data> instance_data;
  36. typedef instance<char> instance_char;
  37. BOOST_STATIC_CONSTANT(std::size_t,
  38. value = sizeof(instance_data) -
  39. BOOST_PYTHON_OFFSETOF(instance_char,storage) +
  40. boost::python::detail::alignment_of<Data>::value);
  41. };
  42. }}} // namespace boost::python::object
  43. #endif // INSTANCE_DWA200295_HPP