From dfb07f359eddbf7086bc2c217fcfcacb446f5baf Mon Sep 17 00:00:00 2001 From: Thomas Geymayer Date: Sun, 1 Dec 2013 01:18:13 +0100 Subject: [PATCH] cppbind: make ghost_type static to keep same pointer on reset. Using a static naGhostType ensures that always the same address is used for the same ghost and prevents ghost_types from getting invalid (eg. on reset). --- simgear/nasal/cppbind/Ghost.hxx | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/simgear/nasal/cppbind/Ghost.hxx b/simgear/nasal/cppbind/Ghost.hxx index 681c333d..75391e79 100644 --- a/simgear/nasal/cppbind/Ghost.hxx +++ b/simgear/nasal/cppbind/Ghost.hxx @@ -67,9 +67,6 @@ namespace nasal bool isBaseOf(naGhostType* ghost_type) const { - if( ghost_type == &_ghost_type ) - return true; - for( DerivedList::const_iterator derived = _derived_classes.begin(); derived != _derived_classes.end(); ++derived ) @@ -86,7 +83,6 @@ namespace nasal typedef std::vector DerivedList; const std::string _name; - naGhostType _ghost_type; DerivedList _derived_classes; std::vector _parents; @@ -105,7 +101,7 @@ namespace nasal ( SG_NASAL, SG_INFO, - "Ghost::addDerived: " <<_ghost_type.name << " -> " << derived->_name + "Ghost::addDerived: " << _name << " -> " << derived->_name ); } @@ -549,6 +545,8 @@ namespace nasal { if( !ghost_type ) return false; + if( ghost_type == &_ghost_type ) + return true; return getSingletonPtr()->GhostMetadata::isBaseOf(ghost_type); } @@ -599,6 +597,8 @@ namespace nasal template friend class Ghost; + static naGhostType _ghost_type; + typedef naGhostType* (*type_checker_t)(const raw_type*); typedef std::vector DerivedList; DerivedList _derived_types; @@ -671,7 +671,7 @@ namespace nasal // If base is not an instance of any derived class, this class has to // be the dynamic type. - return &getSingletonPtr()->_ghost_type; + return &_ghost_type; } template @@ -684,7 +684,7 @@ namespace nasal { // For non polymorphic classes there is no possibility to get the actual // dynamic type, therefore we can only use its static type. - return &BaseGhost::getSingletonPtr()->_ghost_type; + return &BaseGhost::_ghost_type; } static Ghost* getSingletonPtr() @@ -703,7 +703,7 @@ namespace nasal c, "method called on object of wrong type: is '%s' expected '%s'", ghost_type ? ghost_type->name : "unknown", - getSingletonPtr()->_ghost_type.name + _ghost_type.name ); return *obj; @@ -894,6 +894,9 @@ namespace nasal } }; + template + naGhostType Ghost::_ghost_type; + } // namespace nasal // Needs to be outside any namespace to make ADL work -- 2.39.5