[Boost-bugs] [ boost-Bugs-1577259 ] boost::any - typeid comparison across shared boundaries

Bugs item #1577259, was opened at 2006-10-14 18:37 Message generated for change (Tracker Item Submitted) made by Item Submitter You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=107586&aid=1577259&group_id=7586 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Open Resolution: None Priority: 5 Submitted By: Kulik (kulik) Assigned to: Nobody/Anonymous (nobody) Summary: boost::any - typeid comparison across shared boundaries Initial Comment: typeid comparison (using == operator) fails under certain platforms and certain conditions. For me it fails for template classes at least (std::vector for example) when I use it across shared boundaries. Therefore boost::any doesn't work in these cases and throws bad_any_cast exception even when it returns it holds the same type I am about to cast it to (I am using gcc-4.1). boost::python has already solved this by comparing string representations of types under problematic platforms. This works well in all cases but can be a bit slower. In boost/python/type_id.hpp: // for this compiler at least, cross-shared-library type_info // comparisons don't work, so use typeid(x).name() instead. It's not // yet clear what the best default strategy is. # if (defined(__GNUC__) && __GNUC__ >= 3) \ || defined(_AIX) \ || ( defined(__sgi) && defined(__host_mips)) \ || (defined(linux) && defined(__INTEL_COMPILER) && defined(__ICC)) # define BOOST_PYTHON_TYPE_ID_NAME # endif I would say the same thing should be applied to boost::any In boost/any.hpp: template<typename ValueType> ValueType * any_cast(any * operand) { return operand && operand->type() == typeid(ValueType) ? &static_cast<any::holder<ValueType> *>(operand->content)->held : 0; } should be replaced with: template<typename ValueType> ValueType * any_cast(any * operand) { # if (defined(__GNUC__) && __GNUC__ >= 3) \ || defined(_AIX) \ || ( defined(__sgi) && defined(__host_mips)) \ || (defined(linux) && defined(__INTEL_COMPILER) && defined(__ICC)) return operand && !strcmp( operand->type().name(), typeid(ValueType).name() ? &static_cast<any::holder<ValueType> *>(operand->content)->held : 0; # else return operand && operand->type() == typeid(ValueType) ? &static_cast<any::holder<ValueType> *>(operand->content)->held : 0; # endif } btw: I am aware that this may cause performance drops and it would be great if there was a switch for that or something for people that aren't using boost::any across shared boundaries. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=107586&aid=1577259&group_id=7586 ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ Boost-bugs mailing list Boost-bugs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/boost-bugs
participants (1)
-
SourceForge.net