From 10bb1d6feae6334f8b8639ed450aee57eb2b0d47 Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 9 Nov 2016 22:02:42 +0100 Subject: [PATCH] make FeaturePythonPyT more flexible --- src/App/FeaturePythonPyImp.h | 4 ++-- src/App/FeaturePythonPyImp.inl | 24 +++++++++++++----------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/App/FeaturePythonPyImp.h b/src/App/FeaturePythonPyImp.h index e56d4fa3f..058866477 100644 --- a/src/App/FeaturePythonPyImp.h +++ b/src/App/FeaturePythonPyImp.h @@ -26,7 +26,7 @@ #include #include #include -#include +#include namespace App { @@ -41,7 +41,7 @@ public: static PyTypeObject Type; public: - FeaturePythonPyT(PropertyContainer *pcObject, PyTypeObject *T = &Type); + FeaturePythonPyT(Base::BaseClass *pcObject, PyTypeObject *T = &Type); virtual ~FeaturePythonPyT(); /** @name callbacks and implementers for the python object methods */ diff --git a/src/App/FeaturePythonPyImp.inl b/src/App/FeaturePythonPyImp.inl index 922f1c079..ba5694f4f 100644 --- a/src/App/FeaturePythonPyImp.inl +++ b/src/App/FeaturePythonPyImp.inl @@ -81,7 +81,7 @@ PyTypeObject FeaturePythonPyT::Type = { }; template -FeaturePythonPyT::FeaturePythonPyT(PropertyContainer *pcObject, PyTypeObject *T) +FeaturePythonPyT::FeaturePythonPyT(Base::BaseClass *pcObject, PyTypeObject *T) : FeaturePyT(reinterpret_cast(pcObject), T) { } @@ -156,16 +156,18 @@ PyObject *FeaturePythonPyT::_getattr(char *attr) return 0; } - PyObject* dict = PyDict_Copy(tp->tp_dict); - std::map Map; - FeaturePyT::getPropertyContainerPtr()->getPropertyMap(Map); - for (std::map::iterator it = Map.begin(); it != Map.end(); ++it) - PyDict_SetItem(dict, PyString_FromString(it->first.c_str()), PyString_FromString("")); - for (std::map::const_iterator it = dyn_methods.begin(); it != dyn_methods.end(); ++it) - PyDict_SetItem(dict, PyString_FromString(it->first.c_str()), PyString_FromString("")); - if (PyErr_Occurred()) { - Py_DECREF(dict); - dict = 0; + PyObject* dict = FeaturePyT::_getattr(attr); + if (dict && PyDict_CheckExact(dict)) { + PyObject* dict_old = dict; + dict = PyDict_Copy(dict_old); + Py_DECREF(dict_old); // delete old dict + + for (std::map::const_iterator it = dyn_methods.begin(); it != dyn_methods.end(); ++it) + PyDict_SetItem(dict, PyString_FromString(it->first.c_str()), PyString_FromString("")); + if (PyErr_Occurred()) { + Py_DECREF(dict); + dict = 0; + } } return dict; }