[Ecls-list] Macro+segfault insight appreciated
Matthew Mondor
mm_lists at pulsar-zone.net
Sat May 1 19:18:33 UTC 2010
On Sat, 1 May 2010 14:44:02 -0400
Matthew Mondor <mm_lists at pulsar-zone.net> wrote:
> ;;; Here is a second variant using INTERN instead of GENSYM:
> (defmacro defsyscall ((fsymbol cfunction) (&rest cargtypes) documentation)
> (let* ((nargs (length cargtypes))
> (args (loop
> for i from 0 below nargs
> collect (intern (format nil "ARG~D" i))))
> (cargs (let ((s (with-output-to-string (s)
> (loop
> for i from 0 below nargs
> do (format s "#~D " i)))))
> (subseq s 0 (1- (length s))))))
> `(defun ,fsymbol ,args
> ,documentation
> (ffi:clines "#include <errno.h>")
> (let ((err (c-inline2 ,args
> ,cargtypes
> :int
> ,(format nil "
> {
> if (~A(~A) == 0)
> @(return) = 0;
> else
> @(return) = errno;
> }"
> cfunction
> cargs)
> :one-liner nil)))
> (if (= 0 err)
> nil
> (unix-error ,cfunction err (list , at args))))))) ; Problem using ARGS
Hmm after doing more tests, I noticed that interestingly, replacing the
unix-error call by:
(unix-error ,cfunction err (list ,@(mapcar #'identity args)))
Appears to finally work fine, although:
(unix-error ,cfunction err (list ,@(append args)))
Also doesn't (as well as various tests using APPLY and/or SYMBOL-VALUE).
I'm still interested if someone wishes to explain why :)
Thanks,
--
Matt
More information about the ecl-devel
mailing list