This is the mail archive of the
libffi-discuss@sourceware.org
mailing list for the libffi project.
Re: shallow copying in ffi_prep_cif
- From: Dan Witte <dwitte at mozilla dot com>
- To: Tom Dalling <tom dot dalling at gmail dot com>
- Cc: libffi-discuss at sourceware dot org
- Date: Tue, 30 Mar 2010 09:31:56 -0700 (PDT)
- Subject: Re: shallow copying in ffi_prep_cif
----- "Tom Dalling" <tom.dalling@gmail.com> wrote:
> Is this is the intended behaviour? I just assumed that ffi_prep_cif
> and ffi_prep_closure_loc would do a deep copy.
Yeah, you need to keep them both alive for the lifetime of the closure. I remember reading about this in the README, or the info page, or something -- does it not specify?
> Also, when it comes to freeing the memory, is there anything wrong
> with doing the following?
>
> free(closure->cif->arg_types);
> free(closure->cif);
> ffi_closure_free(closure);
Nope, assuming you malloc'ed closure->cif->arg_types and closure->cif. :)
Note that you would also need to free any FFI_TYPE_STRUCT ffi_types that you created.
Dan