Cyrus Harmon | 1 Mar 08:36 2005

struct/array question

dear uffi-dev,

Is there a way to use UFFI to get access to data in a struct such as 
the following:

typedef struct array_struct {
   unsigned char stuff[80];
   unsigned int other_stuff[80];
} array_struct;

I can't figure out how to do the UFFI declaration of the struct to be 
able to access stuff and other_stuff.

Thanks,

Cyrus
Cyrus Harmon | 10 Mar 22:21 2005

sbcl and uffi functions that return :pointer-void

dear uffi-devel,

I know there's been some discussion of how to avoid runtime allocation 
on SBCL for UFFI memory access, but I'm trying to declare an UFFI 
function that returns a :pointer-void and I get a warning about runtime 
allocation. Declaring the return type as :int makes the warning go 
away, but this is, of course, not the right answer. Is there a way to 
do this without the runtime allocation?

Thanks,

Cyrus
Cyrus Harmon | 10 Mar 23:20 2005

c-string and with-foreign-string questions

Dear uffi-devel,

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?

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.

Thanks,

Cyrus
Julian Squires | 11 Mar 00:41 2005

Re: sbcl and uffi functions that return :pointer-void

Hi Cyrus, uffi-devel.

On Thu, Mar 10, 2005 at 01:21:13PM -0800, Cyrus Harmon wrote:
> I know there's been some discussion of how to avoid runtime allocation 
> on SBCL for UFFI memory access, but I'm trying to declare an UFFI 
> function that returns a :pointer-void and I get a warning about runtime 
> allocation. Declaring the return type as :int makes the warning go 
> away, but this is, of course, not the right answer. Is there a way to 
> do this without the runtime allocation?

Not easily with UFFI currently.  If you look at my correspondence with
kmr on this list a few months ago, I think I cover all the bases of
what's happening.  I'm using a workaround in a game that I intended to
release a while ago, but which I haven't finished, and I'm currently on
a vacation from programming.

If you're interested in working on a solution (other than my
workaround), I'd like to hear about it.  I was toying with a few ways of
getting UFFI to deal with the problem cases nicely, but it might require
some overhaul to do the Right thing.

Sorry I can't be of more help just right now.  Hopefully I'll be getting
back to hacking on lisp stuff in a week or two.

--

-- 
Julian Squires
Kevin Rosenberg | 11 Mar 15:43 2005
Picon

Re: sbcl and uffi functions that return :pointer-void

Cyrus Harmon wrote:
> I know there's been some discussion of how to avoid runtime allocation 
> on SBCL for UFFI memory access, but I'm trying to declare an UFFI 
> function that returns a :pointer-void and I get a warning about runtime 
> allocation. Declaring the return type as :int makes the warning go 
> away, but this is, of course, not the right answer. Is there a way to 
> do this without the runtime allocation?

Not every runtime allocation warning causes SBCL/CMUCL to have
horrible performance. I've not tested with a function returning
:pointer-void, but typically that wouldn't cause a problem. The
runtime problem with SBCL/CMUCL is when you'd want to cast that
pointer to another type. 

What are you planning on doing with the return value? Just passing
back to a foreign function, or casting and dereferencing? If it's the
first, have you tested if there really is a performance problem [it'll
be easy to see if it is]. In the latter case, SBCL/CMUCL have serious
trouble with this and you and I have exchanged email before how to try
to work around that.

--

-- 
Kevin Rosenberg
kevin@...
Kevin Rosenberg | 11 Mar 15:51 2005
Picon

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

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.
(Continue reading)


Gmane