move ffi stuff from header to impl
(cherry picked from commit c9baec7)