cffi を使用して Lisp 文字列を C 文字列に変換するエンコーディングとして「utf-16」を使用すると、実際に使用されるエンコーディングは「utf-16le」であることがわかりました。しかし、C 文字列を Lisp 文字列に戻す場合、実際に使用されるエンコーディングは 'utf-16be' です。私はまだ「babel」(「cffi」のエンコーディング機能を提供する) に慣れていないので、それがバグかどうかはわかりません。
(defun convtest (str to-c from-c)
(multiple-value-bind (ptr size)
(cffi:foreign-string-alloc str :encoding to-c)
(declare (ignore size))
(prog1
(cffi:foreign-string-to-lisp ptr :encoding from-c)
(cffi:foreign-string-free ptr))))
(convtest "hello" :utf-16 :utf-16) ;=> garbage string
(convtest "hello" :utf-16 :utf-16le) ;=> "hello"
(convtest "hello" :utf-16 :utf-16be) ;=> garbage string
(convtest "hello" :utf-16le :utf-16be) ;=> garbage string
(convtest "hello" :utf-16le :utf-16le) ;=> "hello"
`convtest' は Lisp 文字列を C 文字列に変換し、それから Lisp 文字列に戻します。出力されるガベージ文字列はすべて同じです。テストから、「utf-16」を「to-c」および「from-c」として同時に使用すると、変換が失敗することがわかります。