Implement a capi calling convention; fixes #2979