Skip to content

Commit

Permalink
Indirect string one level for libffi
Browse files Browse the repository at this point in the history
Every argument to libffi is dereferenced before being passed to the
function, including pointers. For strings to be correctly passed, an
additional level of indirection is needed. This fixes the need to use
the "address of" operator `&' in the C function for strings passed to
foreign functions that also take structures by value.
  • Loading branch information
Liam M. Healy committed Oct 27, 2013
1 parent b0f1979 commit a4c525c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/strings.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,13 @@ buffer along with ARGS." ; fix wording, sigh

(defmethod expand-to-foreign-dyn-indirect
(value var body (type foreign-string-type))
(expand-to-foreign-dyn value var body type))
(alexandria:with-gensyms (str)
(expand-to-foreign-dyn
value
str
(list
(expand-to-foreign-dyn-indirect str var body (parse-type :pointer)))
type)))

;;;# STRING+PTR

Expand Down
2 changes: 1 addition & 1 deletion tests/libfsbv.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ DLLEXPORT
struct struct_pair stringlenpair (char *string, struct struct_pair dp)
{
struct struct_pair ret;
int len = strlen(&string);
int len = strlen(string);
ret.a = len*dp.a;
ret.b = len*dp.b;
return ret;
Expand Down

0 comments on commit a4c525c

Please sign in to comment.