[plt-scheme] passing pointer from one FFI call as input into another FFI call
On Jun 18, Scott Hickey wrote:
> I have a C function that allocates a linked list of structs and it
> works great until I try to pass it into another C function.
>
> (define-cstruct _st_marker ([timestamp _int] [offset _int] [value
> _int] [next _st_marker/null]))
>
> ;; int get_markers(char *filename, struct st_marker **marker_list)
>
> (define get-markers
> (get-ffi-obj "get_markers" "libvfm"
> (_fun _string [markers : (_ptr o _st_marker-pointer/
> null)]
> -> [status : _int] -> (values markers status))))
>
> I want to pass the value returned in 'markers' above to the function
> below:
>
> ;; int create_event_list_from_marker_list(struct st_marker
> *marker_list, struct st_event **event_list)
>
> (define create-event-list-from-marker-list
> (get-ffi-obj "create_event_list_from_marker_list" "libvfm"
> (_fun [markers : (_ptr i _st_marker-pointer/null)]
> [events : (_ptr o _st_event-pointer/null)]
> -> [status : _int] -> (values events status))))
>
>
> After searching for information on this, I saw on message that said
> there are problems reusing the data bound using _ptr o as input into
> another C function. Is there a different syntax I can use to
> accomplish this?
It doesn't look like there should be a problem there -- you're using
`_ptr o' which will allocate a pointer value, call the C function,
then extract the value from that, so you're using the value that was
pointed to (which in your case is also a pointer), not the temporary
pointer that was passed out.
--
((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay:
http://www.barzilay.org/ Maze is Life!