Re: c-string and with-foreign-string questions

Kevin Rosenberg <kevin-HJRc7zDS/[email protected]> Fri, 11 Mar 2005 07:51:50 -0700
Newsgroups gmane.lisp.uffi.devel
Message-ID <[email protected]>
Cyrus Harmon wrote:
> I have a few more questions about c-strings and foreign strings. What 
> exactly is a c-string? I assumed this was a string that one would pass 
> to a C function that takes a string, but apparently, at least for SBCL, 
> this is instead a foreign-string. Furthermore c-strings are basically 
> no-ops. Is this intended?

What exactly c-string is depends upon the implementation, so you
should consider it an opaque type. It's an optimization type which on
some platforms is a no-op and on other platforms is a foreign-sring.

On SBCL/CMUCL, cstrings themselves are normal lisp strings:

UFFI(3): (convert-to-cstring "foo")
"foo"

On Allegro, a cstring is a foreign string

UFFI(7): (convert-to-cstring "foo")
2684436496

> Also, the with-foreign-string macro seems very useful but is undefined 
> (at least it's not in the pdf file). Furthermore, there is a 
> handy-dandy with-cstrings, but not a with-foreign-strings which would 
> seem to also be useful.

with-foreign-string is exported from the UFFI package and is included
in the test suite. It should be added to the documentation. Yes,
adding a with-foreign-strings macro would be useful and would be
add symmetry to with-cstrings.

-- 
Kevin Rosenberg
kevin-HJRc7zDS/[email protected]