[C++-sig] pyplusplus question: 2d char arrays

Gary Oberbrunner garyo at genarts.com
Tue Oct 8 21:48:48 CEST 2013


Sorry if this is the wrong forum for pyplusplus questions; please feel free to tell me to post elsewhere if that's appropriate.


I have this legacy struct in foo.h that is used by some code I'd like to wrap:

struct S
{
  char name[128];
  char input_names[8][12];
};

If I run pyplusplus on it (cool tool, by the way), it generates a file called __array_1.pypp.hpp with a struct array_1_t in it. It uses that for input_names above, as here in the generated bindings.cpp:

    static pyplusplus::containers::static_sized::array_1_t< char[12], 8>
    pyplusplus_input_names_wrapper( ::S & inst ){
        return pyplusplus::containers::static_sized::array_1_t< char[12], 8>( inst.input_names );
    }

But the Windows compiler (Visual Studio 2010) won't compile that code:

cl /Fobindings-tmp.obj /c bindings-tmp.cpp /TP /MDd /DEBUG /EHsc /DPYTHON_EXT /IC:\genarts\sapphire /IC:\boost\include\boost-1_54 /IC:\python27\include
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.40219.01 for 80x86
bindings-tmp.cpp
/tmp/__array_1.pypp.hpp(122) : error C2440: '=' : cannot convert from 'const char *const ' to 'char [12]'
        There are no conversions to array types, although there are conversions to references or pointers to arrays
        /tmp/__array_1.pypp.hpp(120) : while compiling class template member function 'void pyplusplus::containers::static_sized::array_1_t<TItemType,size>::set_item(unsigned long,const char *const )'
        with
        [
            TItemType=char [12],
            size=8
        ]
        bindings-tmp.cpp(26) : see reference to class template instantiation 'pyplusplus::containers::static_sized::array_1_t<TItemType,size>' 

The code in question is in the generated __array_1.pypp.hpp, abbreviated here:

template< class TItemType, long unsigned int size >
struct array_1_t{

    typedef BOOST_DEDUCED_TYPENAME boost::call_traits<const TItemType>::param_type param_type;
    
    typedef BOOST_DEDUCED_TYPENAME boost::mpl::if_c< 
            details::is_immutable<TItemType>::value
            , TItemType
            , param_type
        >::type reference_type;
...
    void
    set_item( long unsigned int index, reference_type new_value ){
        raise_on_out_of_range( size, index );
        m_data[index] = new_value; <<<<<<<<<<<<<<<<<<<<< COMPILE ERROR HERE
    }

So that kind of makes sense.  It doesn't make sense to pass a char[12] array into set_item and expect it to populate an element of m_data.

What should I do about this?  It turns out I don't really care about exporting that particular field to python; can I tell pyplusplus to ignore it somehow?  That struct does get used lots of other places though, if that matters.


-- 
. . . . . . . . . . . . . . . . . . . . . .
Gary Oberbrunner           garyo at genarts.com
VP Engineering             Tel: 617-492-2888
GenArts, Inc.              www.genarts.com 



More information about the Cplusplus-sig mailing list