fix a segfault problem in swift