another attempt to fix the offsetof warnings

This commit is contained in:
Wenzel Jakob 2016-01-20 01:26:42 +01:00
parent 9dcb1c3b3a
commit 88d1d04132
2 changed files with 7 additions and 6 deletions

View File

@ -191,14 +191,18 @@ NAMESPACE_BEGIN(detail)
inline std::string error_string();
/// PyObject wrapper around generic types
template <typename type, typename holder_type = std::unique_ptr<type>> struct instance {
/// Core part of the 'instance' type which POD (needed to be able to use 'offsetof')
template <typename type> struct instance_essentials {
PyObject_HEAD
type *value;
PyObject *parent;
PyObject *weakrefs;
bool owned : 1;
bool constructed : 1;
};
/// PyObject wrapper around generic types, includes a special holder type that is responsible for lifetime management
template <typename type, typename holder_type = std::unique_ptr<type>> struct instance : instance_essentials<type> {
holder_type holder;
};

View File

@ -22,9 +22,6 @@
# pragma GCC diagnostic ignored "-Wunused-but-set-parameter"
# pragma GCC diagnostic ignored "-Wunused-but-set-variable"
# pragma GCC diagnostic ignored "-Wmissing-field-initializers"
# if __GNUC__ >= 4
# pragma GCC diagnostic ignored "-Wno-invalid-offsetof"
# endif
#endif
#include "attr.h"
@ -566,7 +563,7 @@ protected:
type->ht_type.tp_dealloc = rec->dealloc;
/* Support weak references (needed for the keep_alive feature) */
type->ht_type.tp_weaklistoffset = offsetof(instance<void>, weakrefs);
type->ht_type.tp_weaklistoffset = offsetof(instance_essentials<void>, weakrefs);
/* Flags */
type->ht_type.tp_flags |= Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HEAPTYPE;