Can someone with a little more core knowledge please comment on this?

I'm also curious as to whether this test case will eventually result in an
OOB error due to foreign reliance on GC-controlled memory.

-Dan


On Sun, Feb 10, 2013 at 11:04 PM, Andrei Barbu <and...@0xab.com> wrote:

> Attached is a trivial patch that does the strdup.
>
>
> Andrei
>
>
> On Sat, Feb 9, 2013 at 6:07 PM, Andrei Barbu <and...@0xab.com> wrote:
> > Hi,
> >
> >
> > I've been using the bind egg and encountered some strange behaviour.
> > I have:
> >
> > struct a {
> >   char *b;
> > };
> >
> > Bind generates:
> >
> > (begin
> >   (define a-b
> >     (foreign-lambda* c-string (((c-pointer (struct "a")) s))
> "return(s->b);"))
> >   (define make-a
> >     (foreign-lambda*
> >       (c-pointer (struct "a"))
> >       ((c-string b))
> >       "struct a *tmp_ = (struct a *)C_malloc(sizeof(struct
> > a));\ntmp_->b = b;\n\nC_return(tmp_);")))
> >
> >
> > It seems to me that make-a is guaranteed to eventually lead to an out
> > of bounds memory access because of:
> >  tmp_->b = b
> > b is a c-string and will be GCed as soon a the foreign-lambda* returns.
> > This is further exacerbated when using -mutable-fields making it
> > impossible to set any char* member.
> > Shouldn't the bind egg be doing an strdup here? Is there a way to get
> > it do so? Or am I missing something?
> >
> >
> > Thanks!
> > Andrei
>
> _______________________________________________
> Chicken-users mailing list
> Chicken-users@nongnu.org
> https://lists.nongnu.org/mailman/listinfo/chicken-users
>
>
_______________________________________________
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users

Reply via email to