I wrote a custom to-python converter for an aligned struct (It is a 128-bit aligned vector type from the http://eigen.tuxfamily.org library). I followed http://www.boost.org/doc/libs/1_39_0/libs/python/doc/v2/faq.html#custom_string), the converter looks like this:

    class AlignedType{ /*... */} __attribute__((aligned(16)));
    struct converter{
converter(){ py::converter::registry::push_back(&convertible,&construct,py::type_id<AlignedType>());
       static void* convertible(PyObject* obj_ptr){ /*...*/ }
static void construct(PyObject* obj_ptr, py::converter::rvalue_from_python_stage1_data* data){ void* storage=((py::converter::rvalue_from_python_storage<VT>*)(data))->storage.bytes; // !! this creates AlignedType instance at a possibly unaligned address !!
          new (storage) AlignedType;
          data->convertible=storage;
       }
    };

I am getting crashes due to mis-alignment of the resulting object, because it is created at a possible unaligned address. Is there a way around this? Can I allocate another chunk of memory, or enforce the alignment before it is allocated?

Best regards, Vaclav


_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig

Reply via email to