[cffi-devel] Re: [Sbcl-devel] encoding of alien c-string once again

James Bielman jamesjb at jamesjb.com
Thu Apr 27 20:27:54 UTC 2006


Juho Snellman <jsnell at iki.fi> writes:

>   * I'm not sure that the interface is quite right. It seems probable
>     that at one point or another somebody will need to use multiple
>     external formats at once (ebcdic for pathnames and latin-1 for a
>     database connection, or something). So we might need to be able to
>     parametrize the external format to be used when defining the
>     types. As a silly example:
>
>     (define-alien-routine strdup (c-string :external-format :latin-1)
>        (str (c-string :external-format :utf-8)))

I agree; this is what the half-finished patch I have adding support
for string encodings to CFFI looks like as well:

(defcfun "strdup" (:string :encoding :latin-1)
  (str (:string :encoding :utf-8)))

>     James, Luis, would something like this be useful for CFFI? Would
>     the proposed interface work for you? Any opinions on the c-string
>     issue mentioned above?

CFFI wants to operate at a lower level than this.  The sort of
interface that would be really useful for us would be versions of
STRING-TO-OCTETS and OCTETS-TO-STRING that operate on SAPs instead of
octet vectors.  IIRC, there are unexported functions in SBCL for doing
this for the various encodings, but nothing exported.

James



More information about the cffi-devel mailing list