summaryrefslogtreecommitdiffstats
path: root/mpi/mpi.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2017-05-19 06:40:40 -0700
committerKaz Kylheku <kaz@kylheku.com>2017-05-19 06:40:40 -0700
commit56a2b065aebd95a70d2e4d6a8500fff1d463e563 (patch)
tree2edc591cc861d9f89d92e645f0377a56bc061c3a /mpi/mpi.c
parent30061be2a8e1fae63513aa2732d16ed26283e595 (diff)
downloadtxr-56a2b065aebd95a70d2e4d6a8500fff1d463e563.tar.gz
txr-56a2b065aebd95a70d2e4d6a8500fff1d463e563.tar.bz2
txr-56a2b065aebd95a70d2e4d6a8500fff1d463e563.zip
ffi: clean up temp allocs on exception.
The problem is that the argument conversions in a FFI call can bail due to an exception, leaving the argument space partially initialized, and containing pointers to temporary buffers that have been allocated with malloc. In this change, we take care of this problem. We introduce a new virtual function called release to the FFI type hieararchy. Most types do not implement this: only types that have something to free, or aggregates which have to iterate over element types. The release virtual relies on pointers being null if nothing has been allocated. For this reason, we allocate the argument space and all temporar areas with zero filling. * ffi.c (zalloca): New macro. (struct txr_ffi_type): New member function pointer, release. (ffi_fixed_alloc): Use chk_calloc instead of chk_malloc, so that any pointers in the area are null. (ffi_varray_alloc): Use chk_calloc, which simplifies the code. (ffi_simple_release, ffi_ptr_in_release, ffi_struct_release): New static functions. (ffi_array_release_common, ffi_array_release, ffi_varray_release): New static functions. (make_ffi_type_pointer): New argument for specifying release function. (make_ffi_type_struct): Initialize release member of type structure to ffi_struct_release. (make_ffi_type_array): Initialize release member of type structure to ffi_array_release. (ffi_type_compile): Set up release function for varray, several ptr variants and buf-d. (ffi_init_types): Set up release function for string types. (ffi_call_wrap): Internals restructured. Instead of repeatedly processing type and arg lists, we now store them into arrays allocated with alloca. We allocate the argument space with zalloca instead of alloca. Allocating the arguments is separated from the put conversions into two loops, because the alloca calls must be outside of the unwind catching block. This is because the unwind control transfer will roll back the alloca allocation done since the establishment of the catch block! A new unwind block now iterates over the arguments and calls release on each one which has a release function.
Diffstat (limited to 'mpi/mpi.c')
0 files changed, 0 insertions, 0 deletions