On Sat, Oct 12, 2013 at 6:52 AM, Luís Oliveira loliveira@common-lisp.net wrote:
On Wed, Oct 9, 2013 at 4:35 AM, Liam Healy lnp@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