> I've some XS code that creates a self-tied AV thusly:
> 
>         av = newAV();
>         ...
>         rv = newRV_noinc((SV *)av);
>         sv_bless(rv, gv_stashpv("MyPackage", TRUE));
>         sv_magic((SV *)av, Nullsv, 'P', Nullch, 0);
>         RETVAL = rv;
> 
> I basically copied the logic from pp_tie.  However, when the FETCH
> method (written in perl) is called, it goes into a recursive frenzy
> repeatedly calling itself on the AV.  This kind of makes sense - after
> all because it is a self-tie the tied from and tied to AVs are one and
> the same.  However this recursion doesn't happen if you do a self-tie
> purely in perl, so I must be missing a necessary step somewhere.  Can
> someone give me a clue?

I think I might have an insight into what is going on.  At the point
marked '...' I am doing an av_extend followed by a series of av_stores,
so when I then come to bless & tie the array it already has stuff in
it.  From looking at the av *after* the call to sv_magic it seems to
have recursively copied bits of the array inside itself so that each AV
entry is in fact another AV with 'p' magic instead of an SV with 'p'
magic.  Whatever, it looks hosed.

Am I correct in thinking that an AV must be empty if it is to be
self-tied, and that any data elements must be added after the bless/tie
with the appropriate calls to av_store & mg_set?

Thanks,

Alan Burlison

Reply via email to