Hi,
I came across a strange problem that I can't explain.
if I execute a code like:
(with-alien ((RetVal (* integer)))
(unix-ioctl fd VIDIOC_G_INPUT RetVal)
(format t "Output1 is ~a~%" (deref RetVal)))
(with-alien ((RetVal1 (* integer)))
(unix-ioctl fd VIDIOC_G_INPUT RetVal1)
(format t "Output1 is ~a~%" (deref RetVal1)))))
Lisp doesn't allocate RetVal1 and the second call fails as the input
pointer is NULL. On the other hand if I do this:
(with-alien ((RetVal (* integer)) (RetVal2 (* integer)))
(unix-ioctl fd VIDIOC_G_INPUT RetVal)
(unix-ioctl fd VIDIOC_G_INPUT RetVal2)
(format t "Output1 is ~a~%" (deref RetVal)))
(with-alien ((RetVal1 (* integer)))
(format t "RetVal1 is ~a~%" RetVal1)
(unix-ioctl fd VIDIOC_G_INPUT RetVal1)
(format t "Output1 is ~a~%" (deref RetVal1)))))
There is no problem. Everything works.
Could anyone shed some light on it, please?
Thanks,
Andrew
From: Alexey Dejneka
Subject: Re: Strange behavior of "with-alien" in CMUCL
Date:
Message-ID: <m3mzzonri5.fsf@comail.ru>
Hello,
·········@yahoo.com (Andrei) writes:
> I came across a strange problem that I can't explain.
> if I execute a code like:
> (with-alien ((RetVal (* integer)))
> (unix-ioctl fd VIDIOC_G_INPUT RetVal)
> (format t "Output1 is ~a~%" (deref RetVal)))
> (with-alien ((RetVal1 (* integer)))
> (unix-ioctl fd VIDIOC_G_INPUT RetVal1)
> (format t "Output1 is ~a~%" (deref RetVal1)))))
>
> Lisp doesn't allocate RetVal1 and the second call fails as the input
> pointer is NULL.
This is strange. You make a non-initialized pointer, pass it to `ioctl',
and take the value it points to. What is the C equivalent of your
code? Did you mean
(with-alien ((RetVal integer))
(unix-ioctl fd VIDIOC_G_INPUT (addr RetVal))
(format t "Output1 is ~a~%" RetVal))
--
Regards,
Alexey Dejneka
"Alas, the spheres of truth are less transparent than those of
illusion." -- L.E.J. Brouwer
From: Andrei Stebkov
Subject: Re: Strange behavior of "with-alien" in CMUCL
Date:
Message-ID: <414c24b8@news.nnrp.ca>
Alexey Dejneka wrote:
> Hello,
>
> ·········@yahoo.com (Andrei) writes:
>
>> I came across a strange problem that I can't explain.
>> if I execute a code like:
>> (with-alien ((RetVal (* integer)))
>> (unix-ioctl fd VIDIOC_G_INPUT RetVal)
>> (format t "Output1 is ~a~%" (deref RetVal)))
>> (with-alien ((RetVal1 (* integer)))
>> (unix-ioctl fd VIDIOC_G_INPUT RetVal1)
>> (format t "Output1 is ~a~%" (deref RetVal1)))))
>>
>> Lisp doesn't allocate RetVal1 and the second call fails as the input
>> pointer is NULL.
>
> This is strange. You make a non-initialized pointer, pass it to `ioctl',
> and take the value it points to. What is the C equivalent of your
> code? Did you mean
>
> (with-alien ((RetVal integer))
> (unix-ioctl fd VIDIOC_G_INPUT (addr RetVal))
> (format t "Output1 is ~a~%" RetVal))
>
Hi, Alexey
I thought that (with-alien ((RetVal (* integer))) construct was supposed to
allocate memory for the pointer (so you can alien-free it after).
I'll try your code that looks much more up to the task than mine.
Thanks,
Andrew