I created this issue to help people who face the same difficulty.
If you write a python / C interface with ctypes, and use callbacks: If you don't keep a reference to your callback function, it can get garbage collected (mentioned at the end of http://python.net/crew/theller/ctypes/tutorial.html#callback-functions).
You will get a segfault in ffi_closure_unix64_inner just like here:
$ gdb python
> run
Program received signal SIGSEGV, Segmentation fault.
0x0000003fc9a05cd1 in ffi_closure_unix64_inner () from /usr/lib64/libffi.so.5
$
so do
cmp_func = CMPFUNC(py_cmp_func)
qsort(ia, len(ia), sizeof(c_int), cmp_func)
instead of
qsort(ia, len(ia), sizeof(c_int), CMPFUNC(py_cmp_func))
Hope this helped you.