Need foreign string method for translate-into-foreign-memory?
Luís Oliveira
loliveira at common-lisp.net
Sun Oct 6 07:42:17 UTC 2013
On Sun, Oct 6, 2013 at 12:36 AM, Liam Healy <lnp at healy.washington.dc.us> wrote:
>> Having the foreign-string-alloc call lisp-string-to-foreign would
>> cause the string length to be calculated twice. But it indeed seems
>> like they could both share a helper function at least.
>
> Are you sure?
>
> ;;; LMH new function
> (defun length-of-string-as-foreign (string encoding start end null-terminated-p)
> (+ (funcall (octet-counter (lookup-mapping *foreign-string-mappings*
> encoding))
[...]
> ;;; LMH new version
> (defun foreign-string-alloc (string &key (encoding *default-foreign-encoding*)
> (null-terminated-p t) (start 0) end)
[...]
> (lisp-string-to-foreign
> string ptr length :start start :end end :encoding encoding)
[...]
> The only duplication of effort is mapping and null-len, which seem
> like pretty lightweight operations.
This version of foreign-string-alloc calls the octet-counter function
twice. Once via length-of-string-as-foreign then again via
lisp-string-to-foreign.
Cheers,
--
Luís Oliveira
http://kerno.org/~luis/
More information about the cffi-devel
mailing list