Verified Commit 42e4faa3 authored by Justin Carpentier's avatar Justin Carpentier
Browse files

core: add alignment value automatically deduced

parent fdfaa736
......@@ -79,6 +79,7 @@ namespace eigenpy
static int registerNewType(PyTypeObject * py_type_ptr,
const std::type_info * type_info_ptr,
const int type_size,
const int alignment,
PyArray_GetItemFunc * getitem,
PyArray_SetItemFunc * setitem,
PyArray_NonzeroFunc * nonzero,
......
......@@ -27,6 +27,18 @@ namespace eigenpy
// static void cast(void * /*from*/, void * /*to*/, npy_intp /*n*/, void * /*fromarr*/, void * /*toarr*/) {};
};
template<typename T>
struct OffsetOf
{
struct Data
{
char c;
T v;
};
enum { value = offsetof(Data, v) };
};
template<typename T>
struct SpecialMethods<T,NPY_USERDEF>
{
......@@ -194,6 +206,7 @@ namespace eigenpy
int code = Register::registerNewType(py_type_ptr,
&typeid(Scalar),
sizeof(Scalar),
internal::OffsetOf<Scalar>::value,
getitem, setitem, nonzero,
copyswap, copyswapn,
dotfunc);
......
......@@ -36,6 +36,7 @@ namespace eigenpy
int Register::registerNewType(PyTypeObject * py_type_ptr,
const std::type_info * type_info_ptr,
const int type_size,
const int alignement,
PyArray_GetItemFunc * getitem,
PyArray_SetItemFunc * setitem,
PyArray_NonzeroFunc * nonzero,
......@@ -68,7 +69,7 @@ namespace eigenpy
descr.type_num = 0;
descr.names = 0;
descr.fields = 0;
descr.alignment = call_PyArray_DescrFromType(NPY_OBJECT)->alignment;
descr.alignment = alignement; //call_PyArray_DescrFromType(NPY_OBJECT)->alignment;
PyArray_ArrFuncs * funcs_ptr = new PyArray_ArrFuncs;
PyArray_ArrFuncs & funcs = *funcs_ptr;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment