Re: Evaluating types in function definitions

Kevin Rosenberg <kevin-HJRc7zDS/[email protected]> Mon, 1 Apr 2002 10:29:43 -0700 (MST)
Newsgroups gmane.lisp.uffi.devel
Message-ID <[email protected]>
> I would like to propose that parameter types and return values get 
> evaluated when defining foreign functions.

That's a interesting idea. It can likely be implemented. It is unusual
since none of the supported native FFI's evaluate these. However,
that doesn't mean that UFFI should not.

How about a simpler solution? If you don't need to do dereference 
the pointer, why not use a return value of :void-pointer?
Or, if you do need to dereference the pointer, you can use the following:
#+apple (def-foreign-type :fsspecptr (* fsspec))
#-apple (def-foreign-type :fsspecptr :cstring)

Of course, the only disadvantages of evaluating the parameters and return
type are having the extra quotes, eg, '(* :unsigned-char) rather than (*
:unsigned-char), and the fact that UFFI users have to learn something an
extra something different from their native FFI's. That said, if 
evaluating these will really make UFFI more powerful, I'll be willing to 
change things.
 
Would those simpler solutions work for you?

Kevin

> Rationale: I'm working on an API that uses different parameters 
> depending on the platform. For example, a function to open a database 
> uses a cstring (path) on Windows and a file spec record pointer on 
> the Mac. So I have my function:
> 
> (uffi:def-function ("DataBase_Create" ff-database-create)
>    ((inFileSpec :fsspecptr)
>     (inSizeOfCluster :long)
>     (inMode :unsigned-short)
>     (inNativeOS :unsigned-char))
>    :module :vcsdk
>    :returning :unsigned-long)
> 
> 
> :fsspecptr is the built record type on the Mac. For Windows I have:
> 
> #-apple
> (defconstant :fsspecptr :cstring)
> 
> 
> With the added evaluation, I can define what I need in one place 
> instead of adding conditional code to every function definition.
> 
> 
> In the MCL version I added eval to the function below:
> 
> (defun process-one-function-arg (arg)
>    (let ((name (car arg))
> 	(type (convert-from-uffi-type (eval (cadr arg)) :routine)))
>      (if (and (listp type) (listp (car type)))
> 	(append (list name) type)
>        (list name type))
>      ))
> 
> 
> And also used eval on the return value in def-function.
> 
> 
> Any problem in doing this?
> 
> Thanks,
> 
> John DeSoi, Ph.D.
> _______________________________________________
> UFFI-Devel mailing list
> [email protected]
> http://www.b9.com/mailman/listinfo/uffi-devel
>