Refactor the ndarray adaptor and expose the array flags

This uses a cleaner pattern in the C implementation, instead of computing all pointers by hand.