After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 418571 - Avoid dynamic_cast in vfunc invocations for non-derived classes
Avoid dynamic_cast in vfunc invocations for non-derived classes
Status: RESOLVED FIXED
Product: glibmm
Classification: Bindings
Component: build
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtkmm-forge
gtkmm-forge
Depends on:
Blocks:
 
 
Reported: 2007-03-15 13:44 UTC by Armin Burgmeier
Modified: 2007-03-23 17:22 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
static_cast to ObjectBase to check whether the object is derived (3.60 KB, patch)
2007-03-15 13:45 UTC, Armin Burgmeier
none Details | Review
glibmm_vfunc_staticcast.patch (7.55 KB, patch)
2007-03-15 21:36 UTC, Murray Cumming
none Details | Review

Description Armin Burgmeier 2007-03-15 13:44:17 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.
Comment 1 Armin Burgmeier 2007-03-15 13:45:19 UTC
Created attachment 84649 [details] [review]
static_cast to ObjectBase to check whether the object is derived
Comment 2 Murray Cumming 2007-03-15 13:47:35 UTC
Good catch. This seems very sensible. I'll test it locally.
Comment 3 Murray Cumming 2007-03-15 17:34:45 UTC
This does not seem to break ABI for me.
Comment 4 Armin Burgmeier 2007-03-15 20:21:32 UTC
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.
Comment 5 Murray Cumming 2007-03-15 21:36:21 UTC
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.
Comment 6 Murray Cumming 2007-03-18 17:45:33 UTC
Test tarballs with these changes are here:
http://www.openismus.com/temp/gtkmm_tests/
Comment 7 Murray Cumming 2007-03-23 17:22:37 UTC
I have committed this to glib-2-12 and trunk.