GNOME Bugzilla – Bug 418571
Avoid dynamic_cast in vfunc invocations for non-derived classes
Last modified: 2007-03-23 17:22:37 UTC
The attached patch uses static_cast in vfuncs and signal handlers to cast the wrapper object to ObjectBase*. This is enough to check whether the object is from a derived type or not. A slow dynamic_cast has only to be performed if it is derived, and the C++ vfunc needs to be called. This requires ObjectBase::is_derived_ to be public, because it is called on a ObjectBase* rather than the actual type. It also seems to break ABI.
Created attachment 84649 [details] [review] static_cast to ObjectBase to check whether the object is derived
Good catch. This seems very sensible. I'll test it locally.
This does not seem to break ABI for me.
I tested this again, and it also seems to work for me now. I don't know what caused the problem then. Sorry for the inconvenience.
Created attachment 84677 [details] [review] glibmm_vfunc_staticcast.patch Revised the patch, to remove the g_assert()s, because the result of the dynamic_cast<> can be NULL during destruction. Well, I'm fairly sure that's possible and OK. I also added a ChangeLog entry.
Test tarballs with these changes are here: http://www.openismus.com/temp/gtkmm_tests/
I have committed this to glib-2-12 and trunk.