diff --git a/include/pybind11/common.h b/include/pybind11/common.h index 7122d80ce..a63b7f5bf 100644 --- a/include/pybind11/common.h +++ b/include/pybind11/common.h @@ -191,14 +191,18 @@ NAMESPACE_BEGIN(detail) inline std::string error_string(); -/// PyObject wrapper around generic types -template > struct instance { +/// Core part of the 'instance' type which POD (needed to be able to use 'offsetof') +template 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 > struct instance : instance_essentials { holder_type holder; }; diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index 25e25ca91..bbcda47f5 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -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, weakrefs); + type->ht_type.tp_weaklistoffset = offsetof(instance_essentials, weakrefs); /* Flags */ type->ht_type.tp_flags |= Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HEAPTYPE;