[cffi-devel] :pointer size on 64-bit OS's

Luke Crook luke at balooga.com
Thu May 27 00:06:38 UTC 2010


I am receiving reports of nasty intermittent crashes when lispbuilder-sdl is 
run within a 32-bit Lisp (SBCL & CCL) on a 64-bit OS (Windows 7 and OSX). A 32-
bit Lisp is used because the SDL library is 32-bit. No problems are reported 
using Lispworks/32-bit in Windows 7.

The errors reports state that the Lisp debugger is invoked on the CFFI call to 
"SDL_PollEvent" (stack trace below). This is intermittent in that it might 
happen almost immediately, or after several thousand times through the event 
loop.

SDL_PollEvent takes an SDL_Event struct as a parameter. 

SDL_Event looks like this;

(cffi:defcunion SDL-Event
	(type :unsigned-char)
	(active SDL-Active-Event)
	(key SDL-Keyboard-Event)
	(motion SDL-Mouse-Motion-Event)
	(button SDL-Mouse-Button-Event)
	(jaxis SDL-Joy-Axis-Event)
	(jball SDL-Joy-Ball-Event)
	(jhat SDL-Joy-Hat-Event)
	(jbutton SDL-Joy-Button-Event)
	(resize SDL-Resize-Event)
	(expose SDL-Expose-Event)
	(quit SDL-Quit-Event)
	(user SDL-User-Event)
	(syswm SDL-Sys-WM-Event))

A few of the SDL_Events structs include pointers...

(cffi:defcstruct SDL-User-Event
	(type :unsigned-char)
	(code :int)
	(data1 :pointer)
	(data2 :pointer))

(cffi:defcstruct SDL-Sys-WM-Event
	(type :unsigned-char)
	(msg :pointer))


If :pointer is created as a 64-bit pointer instead of 32-bit then I can foresee 
a problem as SDL_Event created by CFFI is larger than expected by SDL_PollEvent.

So my question is, on SBCL/32-bit & CCL/32-bit, what is the expected size 
of :pointer on a 64-bit OS?

Stack trace for SBCL/32-bit below;

debugger invoked on a SIMPLE-ERROR: EXCEPTION_ACCESS_VIOLATION

Type HELP for debugger help, or (SB-EXT:QUIT) to exit from SBCL.

restarts (invokable by number or by possibly-abbreviated name):
  0: [CONTINUE] Ignore runtime option --load "load.lisp".
  1: [ABORT   ] Skip rest of --eval and --load options.
  2:            Skip to toplevel READ/EVAL/PRINT loop.
  3: [QUIT    ] Quit SBCL (calling #'QUIT, killing the process).

("bogus stack frame")
0] ba

0: ("bogus stack frame")
1: ("foreign function: #x757A8112")
2: ("foreign function: #x68132D60")
3: ("foreign function: #x68106812")
4: ("foreign function: #x6810684B")
5: (LISPBUILDER-SDL-CFFI::SDL-POLL-EVENT #.(SB-SYS:INT-SAP #X02106EC0))


- Luke





More information about the cffi-devel mailing list