Re: [Chicken-users] Basic FFI Principle in Chicken

2013-09-07 Thread Kristian Lein-Mathisen
Hey Chris,

I though I'd mention the srfi-4 unit and it's u32vector. This may come in
handy for your particular struct. While make-blobs are great for allocating
managed memory for arbitrary structs, you can sometimes use make-s32vector,
for example, where the struct is basically an array like yours.

Note that this may not be a good idea if your struct members are just using
int because you wouldn't know if it's a s32vector or a s64vector. Also,
your foreign-type would go from (pointer (struct color)) to a
u32vectorwhich means you may have to cast it to a (struct
color*) in C. However, it does make extracting the individual
color-components much easier than having to work with raw blobs.

Because size of an int can generally be either 32 or 64-bit depending on
your architecture, the srfi-4 vectors are possible better suited for floats
and doubles where the sizes are all set. It's worth knowing about them
though.

Cheers,
K.


On Fri, Sep 6, 2013 at 12:23 PM, Chris Mueller ruunsm...@gmail.com wrote:

 On 06.09.2013 09:07, Peter Bex wrote:

 On Fri, Sep 06, 2013 at 08:52:08AM +0200, Chris Mueller wrote:

 Hope its not too basic for you. :)


 Never, user questions are what this mailing list is for!  I hope my
 answers make a little sense.


 Definitely! This is very helpful. I will immediately check and use this.

 Now it also makes sense for me what's one of the intensions behind blobs
 in the documentation/wiki. Never thought it can be used for
 memory allocation in C interfaces :)

 Thanks

 Chris


 __**_
 Chicken-users mailing list
 Chicken-users@nongnu.org
 https://lists.nongnu.org/**mailman/listinfo/chicken-usershttps://lists.nongnu.org/mailman/listinfo/chicken-users

___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] Basic FFI Principle in Chicken

2013-09-07 Thread Peter Bex
On Sat, Sep 07, 2013 at 12:48:27PM +0200, Kristian Lein-Mathisen wrote:
 Note that this may not be a good idea if your struct members are just using
 int because you wouldn't know if it's a s32vector or a s64vector. Also,
 your foreign-type would go from (pointer (struct color)) to a
 u32vectorwhich means you may have to cast it to a (struct
 color*) in C. However, it does make extracting the individual
 color-components much easier than having to work with raw blobs.
 
 Because size of an int can generally be either 32 or 64-bit depending on
 your architecture, the srfi-4 vectors are possible better suited for floats
 and doubles where the sizes are all set. It's worth knowing about them
 though.

Good call!  There's also the bitstring egg which makes destructuring
blobs into component values pretty easy as well.

Cheers,
Peter
-- 
http://www.more-magic.net

___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] Basic FFI Principle in Chicken

2013-09-07 Thread John Cowan
Kristian Lein-Mathisen scripsit:

 Because size of an int can generally be either 32 or 64-bit depending
 on your architecture, the srfi-4 vectors are possible better suited
 for floats and doubles where the sizes are all set. It's worth knowing
 about them though.

Actually, there are essentially no architectures on which int is
anything but 32 bits: unless you have an ancient Cray running Unicos
(modern ones run Linux), a (now-defunct) HAL Systems port of Solaris,
or an IBM PC/AT, you don't have to worry about that.  What does vary is
long, which is 32 bits on 32-bit systems and Win64, and 64 bits on
non-Windows 64-bit systems.

-- 
John Cowanhttp://ccil.org/~cowanco...@ccil.org
SAXParserFactory [is] a hideous, evil monstrosity of a class that should
be hung, shot, beheaded, drawn and quartered, burned at the stake,
buried in unconsecrated ground, dug up, cremated, and the ashes tossed
in the Tiber while the complete cast of Wicked sings Ding dong, the
witch is dead.  --Elliotte Rusty Harold on xml-dev

___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users