[Openmcl-devel] EXTERNAL-CALL type checking with constants

Gary Byers gb at clozure.com
Sat Feb 20 12:31:11 PST 2010


You could change C so that things like

extern int
foo(unsigned int);

int
main()
{
   return (foo(-1));  /* we're passing a signed constant to a function
                         declared to take an unsigned argument.  Won't
                         someone think of the children ? */
}

weren't quietly accepted, or you could change CCL's FFI to disallow
things that are common (sometimes idiomatic) in C.  (If I recall correctly,
CCL's FFI used be more anal retentive about this, but that made it difficult
to translate C code that depended on this casual treatment of the sign of
constants.)

64-bit CCL allows things like:

(external-call "something" :int #x10000000 ...)

and that's a bit more questionable (we're losing information: signed or not,
we can't fit a 33-bit constant into 32 bits.)  C would warn about that loss
of information and I think that CCL should warn or error or both; I don't
think that this sort of thing is idiomatic C in the same sense that sign-
sloppiness is.

Being casual about the sign of constants (e.g., behaving like C does) has
pretty strong practical justification, and quietly treating a signed 32-bit
integer constant as if it was an unsigned 32-bit constant seems more reasonable
(if less consistent) than whining about it would be.



On Sat, 20 Feb 2010, Alexander Repenning wrote:

> Some parameter types of external functions appear not be checked (at all or
> the same) when invoked using parameters that are constant, e.g.
> 
> OpenGL function definition of GLPUSHNAME. Notice <GL>UINT which is an
> unsigned int
> 
> (DEFUN GLPUSHNAME (GLUINT-0) 
> (CCL:EXTERNAL-CALL "glPushName" :<GL>UINT GLUINT-0 :VOID))
> 
> calling like this:
> 
> (let ((View (view-named *w* "world")))  ;;; need to have an glcontext to
> avoid crashing
>   (with-glcontext View
>     (glPushName (- (random 2) 2))))
> 
> can result in an error, e.g., Error: value -1 is not of the expected type
> (UNSIGNED-BYTE 32). Good!
> 
> but 
> 
> (let ((View (view-named *w* "world")))
>   (with-glcontext View
>     (glPushName -1)))
> 
> will not create an error or warning at all. I assume this could be some
> compiler inlining "optimization"? What could be done?
> 
> thanks,  Alex
> 
> 
> 
> 
> Prof. Alexander Repenning
> 
> 
> University of Colorado
> 
> Computer Science Department
> 
> Boulder, CO 80309-430
> 
> 
> vCard: http://www.cs.colorado.edu/~ralex/AlexanderRepenning.vcf
> 
> 
> 
> 
>


More information about the Openmcl-devel mailing list