Re: with-foreign-object allocation question

Martin Simmons <[email protected]> Mon, 13 Apr 2026 19:35:09 +0100
Newsgroups gmane.lisp.lispworks.general
Message-ID <[email protected]>
No, dynamic-extent Lisp objects are allocated on the Lisp control stack.

Foreign objects (including the "dynamic" ones) are always allocated outside
the Lisp heap.

-- 
Martin Simmons
LispWorks Ltd
http://www.lispworks.com/



>>>>> On Fri, 10 Apr 2026 17:56:04 +0100, Tim Bradshaw said:
> 
> Is this also the case for things declared dynamic-extent when they are stack allocated?  I mean: do they share the stack with stack-allocated foreign objects?
> 
> --tim
> 
> > On 10 Apr 2026, at 15:44, Martin Simmons <[email protected]> wrote:
> > 
> > Yes, that's correct.  Moreover, the LW with-dynamic-foreign-objects/alloca
> > stack is separate from the main control stack, so will only be overwritten by
> > other dynamic allocation nested inside this form (or later in the same thread
> > if it is used after the end of its dynamic scope).
> > 
> > --
> > Martin Simmons
> > LispWorks Ltd
> > http://www.lispworks.com/
> > 
> > 
> > 
> >>>>>> On Fri, 10 Apr 2026 12:41:08 +0100, Tim Bradshaw (as tfb at cley dot com) said:
> >> 
> >> If LW's alloca is like C's, then presumably the thing is on the stack and is probably 'legal' until something else overwrites it with probably-bad results?
> >> 
> >> --tim
> >> 
> >>>> On 10 Apr 2026, at 09:51, Madhu (as enometh at meer dot net) <[email protected]> wrote:
> >>> 
> >>> sorry for the immediate followup:
> >>> 
> >>> actuallythere is a another deeper problem because ARGS may be used
> >>> after it is freed, it really should be allocated and not freed, but
> >>> that is not the point of failure in other lisps, or on lispworks,
> >>> 
> >>> *  In  <[email protected]>
> >>> I wrote on Fri, 10 Apr 2026 14:08:38 +0530 (IST)
> >>> 
> >>>> I am trying to fix a lethal memory bug in
> >>>> https://github.com/StjepanPoljak/musicli src/jack.c: (start-jack-callbacks)
> >>>> where there is a call
> >>>> 
> >>>> (cffi:with-foreign-object (args '(:pointer (:struct jack-cb-args)))
> >>>>    ... clobber 24 bytes == (sizeof (:struct jack-cb-args))
> >>>>       allocated at ARGS ...)
> >>>> 
> >>>> which should really read
> >>>> 
> >>>> (cffi:with-foreign-object '(:struct jack-cb-args) ...)
> >>>> 
> >>>> this reliably crashes other lisps, but not lwl 64 personal.  what
> >>>> could be the reason for this resiliance? macroexpansion on the
> >>>> incorrect form shows
> >>>> 
> >>>> (fli:with-dynamic-foreign-objects nil
> >>>> (let* ((#:size6844 8)
> >>>>        (args (fli:alloca :type :byte :nelems #:size6844)))
> >>>> 
> >>>> Which shows only 8 bytes being allocated. but are allocations aligned
> >>>> at > 24byte offsets, so the memory corruption doesn't show up in
> >>>> lispworks in this case?
> >>>> 
> >>>> -- Madhu
> >>>> 
> >>>> (project author bcc'd)
> >>> 
> >>> _______________________________________________
> >>> Lisp Hug - the mailing list for LispWorks users
> >>> [email protected]
> >>> http://www.lispworks.com/support/lisp-hug.html
> >> 
> >> _______________________________________________
> >> Lisp Hug - the mailing list for LispWorks users
> >> [email protected]
> >> http://www.lispworks.com/support/lisp-hug.html
> >> 
> > 
> > _______________________________________________
> > Lisp Hug - the mailing list for LispWorks users
> > [email protected]
> > http://www.lispworks.com/support/lisp-hug.html
> 

_______________________________________________
Lisp Hug - the mailing list for LispWorks users
[email protected]
http://www.lispworks.com/support/lisp-hug.html