summaryrefslogtreecommitdiffstats
path: root/txr.vim
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2022-03-17 07:13:59 -0700
committerKaz Kylheku <kaz@kylheku.com>2022-03-17 07:13:59 -0700
commit11bffd3fe034af0fbe6a9bab4c382dca5d945b9d (patch)
tree8b792e2dab00bc88a14b663d8bf6e261e9a30251 /txr.vim
parentd259634cb2d65b73ae1715a4c361c58b0dc998ae (diff)
downloadtxr-11bffd3fe034af0fbe6a9bab4c382dca5d945b9d.tar.gz
txr-11bffd3fe034af0fbe6a9bab4c382dca5d945b9d.tar.bz2
txr-11bffd3fe034af0fbe6a9bab4c382dca5d945b9d.zip
ffi: after call, process args in reverse order.
In FFI foreign function and closure calls, it behooves us to iterate over the arguments in the opposite order after the call is done. By doing that, any freeing of memory that will be done will be in the opposite order. And that is necessary if some left argument allocates a pointer that is shared with a right argument. An example of this occurs in the strtol function: long int strtol(const char *nptr, char **endptr, int base); Here, the function sets *endptr to a value derived by displacing ptr. If we call this function via FFI, then FFI will allocate memory for nptr. When the function returns, if we destroy that memory before processing *endptr then *endptr contains an invalid pointer. * ffi.c (ffi_call_wrap): In the in pass, iterate arguments in reverse. (ffi_closure_dispatch, ffi_closure_dispatch_safe): Stack-allocate an array for the argument types, so we don't have to pop the list twice, and to allow access in reverse order. In the out pass, iterate arguments in reverse.
Diffstat (limited to 'txr.vim')
0 files changed, 0 insertions, 0 deletions