Re: [racket] [FFI] _union and define-cstruct

2012-10-27 Thread Laurent
On Fri, Oct 26, 2012 at 10:26 PM, Matthew Flatt wrote: > That seems like an ok solution. > > I would be tempted to write > > (define-cstruct _XEvent ([type _int])) > > (define-cstruct (_XAnyEvent _XEvent) ([serial _ulong] >)) > (define-cstruct (_XKey

Re: [racket] [FFI] _union and define-cstruct

2012-10-26 Thread Jon Rafkind
Actually I think I know why it is like the way it is now.. To get an X11 event you pass in an XEvent* to XNextEvent which copies the event to the input pointer. Essentially void XNextEvent(XEvent * input){ switch (event_type){ case Keyboard: { XKeyboardEvent real_event; mem

Re: [racket] [FFI] _union and define-cstruct

2012-10-26 Thread Jon Rafkind
I agree with this. The code Laurent is talking about is my x11 ffi bindings. Laurent, feel free to make this change and push to the repo. I'm not sure why I didn't use the super struct thing to begin with, maybe it didn't exist when I initially wrote the bindings. https://github.com/kazzmir/x11

Re: [racket] [FFI] _union and define-cstruct

2012-10-26 Thread Matthew Flatt
That seems like an ok solution. I would be tempted to write (define-cstruct _XEvent ([type _int])) (define-cstruct (_XAnyEvent _XEvent) ([serial _ulong] )) (define-cstruct (_XKeyEvent _XEvent) ([serial _ulong] .

Re: [racket] [FFI] _union and define-cstruct

2012-10-26 Thread Laurent
Oooohh, I think I understand now: the way it was is already sufficiently general. The writer of the initial code took a different direction. Instead of defining a union type, he changes the tag of the pointer depending on what kind of type he needs in the union: (cpointer-push-tag! e XAnyEvent-tag)