From 88d1d041326d16bb2c51d03e3bad86e01106c0d7 Mon Sep 17 00:00:00 2001 From: Wenzel Jakob Date: Wed, 20 Jan 2016 01:26:42 +0100 Subject: [PATCH] another attempt to fix the offsetof warnings --- include/pybind11/common.h | 8 ++++++-- include/pybind11/pybind11.h | 5 +---- 2 files changed, 7 insertions(+), 6 deletions(-) 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;