[plt-scheme] "define-cunion" prototype for FFI

From: Brian Chin (naerbnic at ucla.edu)
Date: Sat Nov 10 05:51:46 EST 2007

Hey all,

Needing a way of representing C unions in the MzScheme FFI, I dug  
into the foreign.ss file and coded up a "define-cunion" form bearing  
many similarities to (and sharing much code with) the existing define- 
cstruct code. The syntax to define a union is identical to the struct  
version (although you are not allowed to use a structure supertype),  
and the created functions have the same interface, with the exception  
of make-TYPE, which instead of taking one argument per field (which  
would make little sense for a union), you pass it the symbol of the  
field you want to fill, and the value you want to fill that slot  
with. I've done some brief testing, and the code seems to be  
complete, except:

- The functions list->TYPE and it's brethren are still created for  
unions, even though they have next to no meaning in this framework
- You can still provide a union as a supertype for a new struct. The  
behavior in that case is untested, undefined, highly volatile, and  

I haven't participated in this mailing list enough to know what the  
right procedure for submitting these patches are, so I guess I have  
three questions:

1. Is this a useful addition to the FFI library? It preserves the  
semantics of the existing library, and with a little work should  
interact well with the other features.
2. If 1, _should_ it be added to MzScheme?
3. If 2, how do I go about submitting the appropriate patch?

- Brian Chin

(Note: I sent this initially under the wrong email address, so I got  
a reply about the first version of this email being set for approval  
by the moderator. If it ends up showing up on this list as well, I  
apologize in advance)

Posted on the users mailing list.