instance.hpp 1.3 KB

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