From 2cbe87566840481cd7b01595486322bb95f9d559 Mon Sep 17 00:00:00 2001 From: Marius Gerbershagen Date: Tue, 6 Aug 2019 20:14:10 +0200 Subject: [PATCH] dffi: fix bug in converting to :cstring's We used the next argument instead of the current one. Bug identified and fixed by Christoph Buck. Fixes #523. --- src/c/ffi.d | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/c/ffi.d b/src/c/ffi.d index fd8548411..2c4f04614 100644 --- a/src/c/ffi.d +++ b/src/c/ffi.d @@ -870,13 +870,15 @@ prepare_cif(cl_env_ptr the_env, ffi_cif *cif, cl_object return_type, the_env->ffi_types[++n] = ecl_type_to_libffi_type(arg_type); if (CONSP(args)) { cl_object object = ECL_CONS_CAR(args); - args = ECL_CONS_CDR(args); if (type == ECL_FFI_CSTRING) { - object = ecl_null_terminated_base_string(CAR(args)); + object = ecl_null_terminated_base_string(object); + /* Push the newly allocated object onto the stack so that it + * is reachable by the garbage collector */ if (ECL_CONS_CAR(args) != object) { ECL_STACK_PUSH(the_env, object); } } + args = ECL_CONS_CDR(args); ecl_foreign_data_set_elt(the_env->ffi_values + n, type, object); } }