[C++-sig] Re: def_readonly and const array members

David Abrahams dave at boost-consulting.com
Wed Aug 6 15:51:12 CEST 2003


David Abrahams <dave at boost-consulting.com> writes:

> "Jeff Brewer" <jeff at brewer.com> writes:
>
>> I am trying to wrap structs that have character arrays and I'm having
>> problems since I moved from MSVC 7 to MSVC 7.1 (VS .NET 2003). Here is
>> the struct I'm trying to expose the theArray member of using
>> class_::def_readonly:
>>
>> struct testStruct
>> {
>> 	unsigned char theArray[16];
>> };
>>
>> I've created a to_python converter for the unsigned char [16] type but
>> I'm getting a "TypeError: No to_python (by-value) converter found for
>> C++ type: unsigned char const volatile [8]" when I try to access the
>> theArray member in Python. I've tried putting volatile in my typedef for
>> the array, but that doesn't seem to help (how C++ binds these type
>> modifiers always confuses me so maybe I put it in the wrong place).
>>
>> Thank you for the help,
>>
>> Jeff Brewer
>> jeff at purplemagma.com
>
> Jeff, the problem appears to be a bug in MSVC 7.1, namely that 
>
>    typeid(unsigned char[16]) != typeid(unsigned char const volatile[16])
>
> As it should be.  I'm looking into a workaround now.

Done and checked in.  Here's the patch to boost/python/registered.hpp:

--- registered.hpp.~1.2.~	2002-08-14 02:26:32.000000000 -0400
+++ registered.hpp	2003-08-06 09:49:09.000000000 -0400
@@ -10,6 +10,7 @@
 # include <boost/python/converter/registrations.hpp>
 # include <boost/type_traits/transform_traits.hpp>
 # include <boost/type_traits/cv_traits.hpp>
+# include <boost/detail/workaround.hpp>
 
 namespace boost { namespace python { namespace converter { 
 
@@ -34,10 +35,15 @@
 {
 };
 
-# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
-// collapses a few more types to the same static instance
+# if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) \
+    && !BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1310))
+// collapses a few more types to the same static instance.  MSVC7.1
+// fails to strip cv-qualification from array types in typeid.  For
+// some reason we can't use this collapse there or array converters
+// will not be found.
 template <class T>
-struct registered<T&> : registered<T> {};
+struct registered<T&>
+  : registered<T> {};
 # endif
 
 //

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com





More information about the Cplusplus-sig mailing list