Need foreign string method for translate-into-foreign-memory?
Liam Healy
lnp at healy.washington.dc.us
Tue Oct 15 02:24:01 UTC 2013
On Sat, Oct 12, 2013 at 6:52 AM, Luís Oliveira
<loliveira at common-lisp.net> wrote:
> On Wed, Oct 9, 2013 at 4:35 AM, Liam Healy <lnp at healy.washington.dc.us> wrote:
>> I've pushed the rewrite; please take a look and run tests to see
>> that it's good. I've temporarily created a new branch foreign-string.
>
> This refactorization is trickier than it might seem. You cannot pass
> the string to the octet-counter without performing the
> with-checked-simple-vector adjustments beforehand. Also, this version
> doesn't take into account the null terminator when computing the right
> bound of the buffer.
>
> I'd start over and try to extract the encoder funcall and the null
> terminator loop, make sure that works, and then try to figure out
> what's the next lowest hanging fruit.
>
> Cheers,
>
> --
> Luís Oliveira
> http://kerno.org/~luis/
OK. This has already exceeded my available skills, time, and interest,
so I will leave those two functions as-is and go back to the original
task, which was to create a translate-into-foreign-memory method for
foreign-string-type. How does this look?
(defmethod translate-into-foreign-memory
((string string) (type foreign-string-type) pointer)
(check-type string string)
(with-checked-simple-vector ((string (coerce string 'babel:unicode-string))
(start 0) (end nil))
(declare (type simple-string string) (ignore start end))
(let* ((encoding (fst-encoding type))
(length
(+ (funcall (octet-counter (lookup-mapping
*foreign-string-mappings* encoding))
string 0 nil 0)
(null-terminator-len encoding))))
(lisp-string-to-foreign string pointer length))))
Thanks,
Liam
More information about the cffi-devel
mailing list