add better handling of ghost values to ccall/cfunction