Lisp HUG Maillist Archive

Foreign pointers and with-dynamic-foreign-objects

Hello list,

I was reading the man page for with-dynamic-foreign-objects 
where it says:

   "Only standard foreign types can be bound using bindings.
   Foreign pointer types should be allocated using
   allocate-dynamic-foreign-object."

But looking through my code I see that I've ignored this and 
allocated a pointer to a pointer in the list of bindings 
rather than via allocate-dynamic-foreign-object, and it 
seems to work fine (on Windows, at least): I pass my pointer 
to a pointer to a foreign function, then dereference it and 
return the pointed-to pointer.

Is this safe, or should I modify my code to use 
allocate-dynamic-foreign-object, (now and in the future)?

Thanks,

John :^P
-- 
John Pallister
john@synchromesh.com


AW: Foreign pointers and with-dynamic-foreign-objects



> -----Ursprüngliche Nachricht-----
> Von: owner-lisp-hug@lispworks.com 
> [mailto:owner-lisp-hug@lispworks.com] Im Auftrag von John Pallister
> Gesendet: Mittwoch, 1. August 2007 12:19
> An: lisp-hug@lispworks.com
> Betreff: Foreign pointers and with-dynamic-foreign-objects
> 
> 
> 
> Hello list,
> 
> I was reading the man page for with-dynamic-foreign-objects 
> where it says:
> 
>    "Only standard foreign types can be bound using bindings.
>    Foreign pointer types should be allocated using
>    allocate-dynamic-foreign-object."
> 
> But looking through my code I see that I've ignored this and 
> allocated a pointer to a pointer in the list of bindings 
> rather than via allocate-dynamic-foreign-object, and it 
> seems to work fine (on Windows, at least): I pass my pointer 
> to a pointer to a foreign function, then dereference it and 
> return the pointed-to pointer.
> 
> Is this safe, or should I modify my code to use 
> allocate-dynamic-foreign-object, (now and in the future)?
> 
> Thanks,
> 
> John :^P
> -- 
> John Pallister
> john@synchromesh.com
> 

Hi John,

If I correctly understand you, you don't use allocate-dynamic-foreign-object. So you allocate
The pointer by 'hand' and thus you also have to deallocate it by free-foreign-object or you'd have a memory leak.

Is that correct?

Andreas


Re: AW: Foreign pointers and with-dynamic-foreign-objects

On Wednesday 01 August 2007 13:42:48 Andreas Thiele wrote:
> > -----Ursprüngliche Nachricht-----
> > Von: owner-lisp-hug@lispworks.com
> > [mailto:owner-lisp-hug@lispworks.com] Im Auftrag von John Pallister
> > Gesendet: Mittwoch, 1. August 2007 12:19
> > An: lisp-hug@lispworks.com
> > Betreff: Foreign pointers and with-dynamic-foreign-objects
> >
> >
> >
> > Hello list,
> >
> > I was reading the man page for with-dynamic-foreign-objects
> > where it says:
> >
> >    "Only standard foreign types can be bound using bindings.
> >    Foreign pointer types should be allocated using
> >    allocate-dynamic-foreign-object."
> >
> > But looking through my code I see that I've ignored this and
> > allocated a pointer to a pointer in the list of bindings
> > rather than via allocate-dynamic-foreign-object, and it
> > seems to work fine (on Windows, at least): I pass my pointer
> > to a pointer to a foreign function, then dereference it and
> > return the pointed-to pointer.
> >
> > Is this safe, or should I modify my code to use
> > allocate-dynamic-foreign-object, (now and in the future)?
> >
> > Thanks,
> >
> > John :^P
> > --
> > John Pallister
> > john@synchromesh.com
>
> Hi John,
>
> If I correctly understand you, you don't use
> allocate-dynamic-foreign-object. So you allocate The pointer by 'hand' and
> thus you also have to deallocate it by free-foreign-object or you'd have a
> memory leak.
>
> Is that correct?

No, he allocated a pointer to a pointer with with-dynamic-foreign-objects 
instead of with allocate-dynamic-foreign-object.

I don't know the answer to John's question, but I would like to know what the 
documentation for with-dynamic-foreign-objects means with "standard foreign 
types". Obviously it includes immediate types, and the example for 
with-dynamic-foreign-objects uses an aggregate type (as defined by the FLI 
User Guide and Reference Manual). So does it only exclude pointer types? The 
terminology used by the FLI guide is not always clear (to me). E.g. when I 
started with the FLI I had this question which was not answered by LispWorks 
but I concluded the answer is immediate from examples and Paul Tarvydas' 
answer (http://thread.gmane.org/gmane.lisp.lispworks.general/6707):

I am confused about whether FLI pointers types (the pointer type itself, 
not that what the pointer points to) are immediate or aggregate types. 
The Lispworks documentation specifies it as both:
immediate: 
http://www.lispworks.com/documentation/lw50/FLI/html/fli-17.htm#pgfId-888612
aggregate:
http://www.lispworks.com/documentation/lw50/FLI/html/fli-23.htm#pgfId-886654
(first sentence)

Nico




Re: Foreign pointers and with-dynamic-foreign-objects

Unable to parse email body. Email id is 6856

Updated at: 2020-12-10 08:45 UTC