[Openmcl-devel] lambda-gtk question on OpenMCL

Andrew P. Lentvorski, Jr. bsder at mail.allcaps.org
Wed Jan 26 17:02:59 PST 2005


On Jan 26, 2005, at 6:16 AM, Rick Taube wrote:

>   both sbcl and cmucl return pointer args as multiple values. so in 
> the example above the NIL first return value is the value returef by 
> the function the second and third values are the pointer arg values 
> the function produces.

Sure.  But that return list is dependent upon the number of parameters 
that are actually pointers, right?  Thus:

int nasty(void *, int, int *, int, int *, int)

would return something like

10
nil
-10
40

And I would actually have to hunt down the original header file to work 
out what corresponds with what.  Sure, that's okay if it looks like 
above, but if the signature in the API docs is:

GBoolean nasty(GC, GBoolean, FontHandle, FontNumber, ClosestFontHandle, 
ClosestFontNumber);

Things get really bad.  Effectively, I have an unchecked function 
signature encoded in the logic of my program.  All manner of silent bad 
things will happen if that signature ever alters.

Additionally, if I write something like:

(widget-get-size-request widget 100 100) when I really meant
(widget-set-size-request widget 100 100), I get no complaints under the 
current system.

>  If there is a better way to handle situations like this please let me 
> know, but only if it can determined from ffigen expressions and only 
> if it works in all three lisps.

Well, I kinda hate to suggest this for lisp, but I think I'd rather see 
the calls actually alter the input arguments rather than have 
positional multiple return values with no annotation or checks.  For 
example in OpenMCL (please have someone with a lot more macro writing 
experience check this):

(defmacro my-drawable-get-size (drawable height width)
   `(rlet ((r1 :int ,height)
	  (r2 :int ,width))
	 (let ((z (#_gdk_drawable_get_size ,drawable r1 r2)))
	   (setf ,height (%get-signed-long r1))
	   (setf ,width (%get-signed-long r2))
	   z)))

Which results in something like this in OpenMCL:

? (setq h0 -1001)
-1001
? (setq w0 -455)
-455
? (my-drawable-get-size dr w0 h0)
;Compiler warnings :
;   Undeclared free variable DR, in an anonymous lambda form.
;   Undeclared free variable W0 (2 references), in an anonymous lambda 
form.
;   Undeclared free variable H0 (2 references), in an anonymous lambda 
form.
NIL
? w0
307
? h0
276
? (my-drawable-get-size dr 100 100)
 > Error in process listener(1): 100 is not a symbol.

While this results in destructive side effects, calling Gtk can always 
result in destructive side effects.  In addition, people can now create 
wrappers in lisp which can do things like copy the arguments, check for 
modification, rewrap things for multiple values, etc. without having to 
worry about position.

I assume that this kind of thing would be portable across the various 
lisps, but someone with more knowledge than I would have to check that.

> so in the case of a function that only produces values the external 
> args you pass are useless.

Actually, Gtk has the rather nasty issue that the values of args can 
alter the functionality of the function.

_gdk_drawable_get_size is allowed to take a NULL pointer and not return 
that dimension.  Consequently, gdk::drawable-get-size will likely 
segfault on the OpenMCL call to %get-signed-long.  I presume similar 
behavior on the other lisps.

This kind of thing is really crummy and it means that eventually there 
will have to be some way to handle hand coded exceptions.  However, 
this is orthogonal to the value returning questions.

-a




More information about the Openmcl-devel mailing list