in reply to Re^3: Internals question.
in thread Internals question.

Oh. That's perfect. I had to do in in two steps to avoid a 'Attempt to pack pointer to temporary value...' message, but that is much nicer than what I was attempting to do.

Just one further question. I could probably work it for myself, but since you seem to have specialised in all things B, how can I take that sv_ref and set it into a perl scalar?

Ie. I would like to have a standard perl scalar with the PVX pointing at the same space as an AVs ARRAY field. Actually, It would be better if the SV(PVX) shared the same value as the AV(ALLOC), but that's probably asking too much.

Can you short-circuit the learning curve for me?


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

Replies are listed 'Best First'.
Re^5: Internals question.
by diotalevi (Canon) on Jul 23, 2007 at 22:13 UTC

    It'd be easier for you to write a little bit of XS and allocate your SV, replace SvANY(your_sv) with AvARRAY(your_av). Now you've got to prevent perl from wanting to ever deallocate either object before you can undo your muckery. The array at AvARRAY(your_av) could now get freed twice and the original buffer at SvANY(your_sv) might never be freed. B is just a little bit of sugar over XS so you'd really be better off just checking that out. Visit perlapi and the various *v.h files in your distribution.

    ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

Re^5: Internals question.
by tye (Sage) on Jul 23, 2007 at 18:47 UTC

    Perl assumes that it can call free() or realloc() on PVXs with impunity. This prevents many useful "tricks".

    - tye        

      Yes. I realise that I would have to pre-allocate the array and make sure that neither the array (length), nor the scalar (at all) is mutated.

      I'd probably set them read-only using Internals::SetReadOnly() to assist in ensuring that. I realise that probably isn't foolproof. But it's just and experiment.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.