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 <boost/type_traits/alignment_traits.hpp>
  9. # include <cstddef>
  10. namespace boost { namespace python
  11. {
  12. struct BOOST_PYTHON_DECL_FORWARD 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 type_with_alignment<
  24. ::boost::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(
  38. std::size_t, value = sizeof(instance_data)
  39. - BOOST_PYTHON_OFFSETOF(instance_char,storage));
  40. };
  41. }}} // namespace boost::python::object
  42. #endif // INSTANCE_DWA200295_HPP