Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Reliability of SvREADONLY

by zshzn (Hermit)
on Dec 14, 2006 at 03:56 UTC ( [id://589737]=note: print w/replies, xml ) Need Help??


in reply to Reliability of SvREADONLY

I am not quite sure why it is said above that type coercion is going to cause a problem here. Let me provide a little example.
use ExtUtils::testlib; use Flag; #all local, sorry my $c = 'test'; Flag::sv_set_flag($c, 'READONLY'); #$c++; #$c = 'not a test'; $c = 5;
Any of those examples produce a "Modification of a read-only value" error. Naturally. And as long as that works, that we cannot directly modify the value, we're set. Certain types of behavior can modify the underlying data structure, but not to the point of changing the eventual data.
use Devel::Peek; use ExtUtils::testlib; use Flag; my $c = 15; Flag::sv_set_flag($c, 'READONLY'); print Dump $c; print "$c"; print Dump $c;
Naturally the interpolation causes the IV to become an PVIV. But our PV value will be "15"\0. So in any circumstance our behavior is normal. Yes the structure has changed, but from a user standpoint our data is readonly.

Is there a specific need to protect the data from perl internals that could possibly be ignoring the readonly state of a variable? If not, then type coercion isn't a problem at all.

Replies are listed 'Best First'.
Re^2: Reliability of SvREADONLY
by ikegami (Patriarch) on Dec 14, 2006 at 04:14 UTC

    Naturally the interpolation causes the IV to become an PVIV.

    That causes a write to the memory page, causing it to become unshared, ...

    I am not quite sure why it is said above that type coercion is going to cause a problem here.

    ...thus type coercion causes a problem.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://589737]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2024-03-28 09:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found