$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
From: Dan Fike (dan.fike_at_[hidden])
Date: 2008-04-22 14:07:26
Using Boost.Python, is it possible to expose a C++ memory-aligned data type 
to Python?
For example, I want to expose this data type.
class __declspec(align(16)) foo {
public:
    foo() {};
    bool isAligned() {
        if ((int)this % 16 == 0) {
            return true;
        } else {
            return false;
        }
    }
private:
    int a, b, c, d;
};
I've written the following code to expose this class to Python:
BOOST_PYTHON_MODULE(myModule) {
    boost::python::class_<foo>("foo", boost::python::init<>())
        .def("isAligned", &bar.isAligned)
    ;
}
When compiling this code (MSVC 8.0, VS2005, Win32), I get the following 
error (entire error listed at the bottom):
d:\...\boost\python\converter\as_to_python_function.hpp(21) : error C2719: 
'unnamed-parameter': formal parameter with __declspec(align('16')) won't be 
aligned
Note that I used to get a STATIC_ASSERTION_FAILURE in the 
type_with_alignment class definition when compiling with Boost 1.34. I found 
adding a 16-byte aligned struct type to the BOOST_TT_ALIGNMENT_BASE_TYPES 
list in type_with_alignment.hpp made the ASSERT go away, but introduced the 
above error. In an attempt to fix it, I downloaded Boost revision 43984 from 
early April, 2008, which included a patch that I thought would help me. See 
http://svn.boost.org/trac/boost/changeset/43984. While the 
type_with_alignment.hpp included in that revision did correct the 
STATIC_ASSERTION_FAILURE, I am still hitting the above error.
Now, if I try to build the same code in x64 instead of Win32 (again, from 
revision 43984), I do not encounter the error. Not only does it compile, but 
I have verified that any objects 16-byte aligned objects I instanciate in 
Python are actually aligned correctly.
Unsurprisingly, however, the x64 build produces the same error when I try to 
expose a 32-byte aligned data type. On the other hand, the Win32 build still 
complains if I try it with an 8-byte aligned data type.
I'm hoping there is a piece of Boost.Python code missing from the class 
exposition that I don't know about. I've scoured the documentation and 
internet (and code) for such a thing, but I may have overlooked it. Any 
advice?
-Dan Fike
Here is the entire error, as printed by VS2005...
d:\...\boost\python\converter\as_to_python_function.hpp(21) : error C2719: 
'unnamed-parameter': formal parameter with __declspec(align('16')) won't be 
aligned
        d:\...\boost\python\to_python_converter.hpp(88) : see reference to 
class template instantiation 
'boost::python::converter::as_to_python_function' being compiled
        with
        [
            T=foo,
            ToPython=boost::python::objects::class_cref_wrapper>>
        ]
        d:\...\boost\python\to_python_converter.hpp(82) : while compiling 
class template member function 
'boost::python::to_python_converter::to_python_converter(void)'
        with
        [
            T=foo,
            Conversion=boost::python::objects::class_cref_wrapper>>,
            has_get_pytype=true
        ]
        d:\...\boost\python\object\class_wrapper.hpp(26) : see reference to 
class template instantiation 'boost::python::to_python_converter' being 
compiled
        with
        [
            T=foo,
            Conversion=boost::python::objects::class_cref_wrapper>>,
            has_get_pytype=true
        ]
        d:\...\boost\python\object\class_metadata.hpp(272) : see reference 
to class template instantiation 'boost::python::objects::class_cref_wrapper' 
being compiled
        with
        [
            Src=foo,
            MakeInstance=boost::python::objects::make_instance>
        ]
        d:\...\boost\python\object\class_metadata.hpp(229) : see reference 
to function template instantiation 'void 
boost::python::objects::class_metadata::maybe_register_class_to_python(T2 
*,boost::mpl::false_)' being compiled
        with
        [
            T=foo,
            X1=boost::python::detail::not_specified,
            X2=boost::python::detail::not_specified,
            X3=boost::python::detail::not_specified,
            T2=foo
        ]
        d:\...\boost\python\object\class_metadata.hpp(219) : see reference 
to function template instantiation 'void 
boost::python::objects::class_metadata::register_aux2>(T2 *,Callback)' being 
compiled
        with
        [
            T=foo,
            X1=boost::python::detail::not_specified,
            X2=boost::python::detail::not_specified,
            X3=boost::python::detail::not_specified,
            T2=foo,
            Callback=boost::integral_constant
        ]
        d:\...\boost\python\object\class_metadata.hpp(217) : while compiling 
class template member function 'void 
boost::python::objects::class_metadata::register_aux(void *)'
        with
        [
            T=foo,
            X1=boost::python::detail::not_specified,
            X2=boost::python::detail::not_specified,
            X3=boost::python::detail::not_specified
        ]
        d:\...\boost\python\class.hpp(174) : see reference to class template 
instantiation 'boost::python::objects::class_metadata' being compiled
        with
        [
            T=foo,
            X1=boost::python::detail::not_specified,
            X2=boost::python::detail::not_specified,
            X3=boost::python::detail::not_specified
        ]
        d:\...\boost\python\class.hpp(205) : see reference to class template 
instantiation 'boost::python::class_::id_vector' being compiled
        with
        [
            W=foo
        ]
        d:\...\MyProject\my_project_python_modules.h(77) : see reference to 
function template instantiation 'boost::python::class_::class_>(const char 
*,const boost::python::init_base &)' being compiled
        with
        [
            W=foo,
            DerivedT=boost::python::init<>
        ]