Hello,

I'm working on a module that need to add a new flag to a SV that is stored by it. Actually I just need to find a way to mark that SV by this module, so, will be possible to identify this SVs from the others.

*Why use a flag?

Because if I just use the number of a SV and its type, I can't guarantee that is the same SV that I have stored, since Perl can reuse that SV after clean it. If I just use the type and the number is possible that until the next access to this SV, that SV was actually destroied, than a new SV can be created with the same type and number. So, adding a flag I can guarantee that it wasn't cleanned until that, since when a SV is cleanned its flag is reseted.

I need to know if someone already done something like that, and if you, all the developers that hack Perl internals, think that this is the best way to do that, and if it is, if this is a secure thing to do.

Also I need to know if exits some reserved range for external flags defined in Perl, since I can't use a number for the flag that is in use, or any range that can be in use in the future.

*Why do that?

Is for the module Hash::NoRef, where I need to store a value/object without actually make a reference to it. I previously tried to store a reference value and decrement its REFCNT, but this will create a lot of problems, including CORE dump of the interpreter, specially if we try to access this value after the destruction of it, since is impossible to know if a reference was destroied when the REFCNT is artificialy changed, and also we can access a recycled SV. As a new approach I will store the type and number of the SV, and mark that SV to guarantee that it wasn't destroied. After this I can access the SV getting it directly from the list of SVs in use.

Thanks in advance and wish me luck! ;-P

UPDATE:
Resolved with weak references. Thanks to broquaint and bart that helped in the CB.

Graciliano M. P.
"Creativity is the expression of the liberty".


In reply to PerlHack - Adding new flag into a SV by gmpassos

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.