[cffi-devel] Re: calls with variable number of arguments which are determined at run-time

Stelian Ionescu sionescu at common-lisp.net
Fri Feb 9 12:48:31 UTC 2007


On Fri, Feb 09, 2007 at 10:14:38AM +0000, Lars Rune Nøstdal wrote:
>James Bielman <jamesjb <at> gmail.com> writes:
>> 
>> What's the use case for this?  
>
>Short answer: `g_object_new'.
how many possible ways of using g_object_new do you have ?
if not too many perhaps you could so somethig like this:

(defsyscall ("fcntl" %fcntl-without-arg) :int :noexport
  (fd  :int)
  (cmd :int))

(defsyscall ("fcntl" %fcntl-with-int-arg) :int :noexport
  (fd  :int)
  (cmd :int)
  (arg :int))

(defsyscall ("fcntl" %fcntl-with-pointer-arg) :int :noexport
  (fd  :int)
  (cmd :int)
  (arg :pointer))

(define-entry-point fcntl (fd cmd &optional (arg nil argp))
  (cond ((not argp)     (%fcntl-without-arg fd cmd))
        ((integerp arg) (%fcntl-with-int-arg fd cmd arg))
        ((pointerp arg) (%fcntl-with-pointer-arg fd cmd arg))
        (t              (error "Wrong argument to fcntl: ~S" arg))))

(defsyscall is a wrapper around foreign-funcall and define-entry-point
does only a defun+export)

-- 
(sign :name "Stelian Ionescu" :aka "fe[nl]ix"
      :quote "Quidquid latine dictum sit, altum sonatur.")
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <https://mailman.common-lisp.net/pipermail/cffi-devel/attachments/20070209/55038493/attachment.sig>


More information about the cffi-devel mailing list