fix #4246. also fix calling convention, although it doesn't matter