develooper Front page | perl.perl5.porters | Postings from July 2001

Re: [PATCH for discussion] clamp, round #2

Thread Previous | Thread Next
Jeffrey Friedl
July 30, 2001 12:03
Re: [PATCH for discussion] clamp, round #2
Message ID:

Nick Ing-Simmons <> wrote:
|> The completeness of your patches is a joy, but IMHO:


|> while it is now using SvREADONLY it is _still_ adding 
|> the SVh_CLAMP_ACCESS flag which was what the SvREADONLY proposal 
|> was supposed to avoid.

I did so to support the ability to clamp access, which as far as I can tell
does require another bit. Being readonly and having access clamped are
really orthogonal (a fancy way to say "unrelated" :-), so I don't see a way
to implement them both with one bit.

Actually, I think it could be nice to add yet another bit that locks
readonlyness, so that once you lock it, the state can't be changed. 
(Variables like $1, etc., would be created that way). I didn't add this
aknowing your predisposition against using additional bits.

|> Re-using SVp_SCREAM (has been studied) flag seems safe enough in theory,
|> but  we need to check that someplace else isn't already (ab)using it. 

I made my first patch to Perl's internals in about 1991, but haven't done
all that much since then, so I'm relying on the exports to sanity check the
whole thing.

|> It isn't clear why you rule out readonly/clamping tied hashes.

It's simply a matter of baby steps and what I could tackle at this
still-early stage. (As of yet I don't have a clue what a tied hash looks
like to the internals.)

|> I am also a little concerned about inventing another special "address".
|> Would not NULL suffice for "place holder"?

Probably would -- I was just mimicing what I saw being done for PL_sv_undef.

|> +#define SvIMMORTAL(sv) ((sv)==&PL_sv_undef || (sv)==&PL_sv_yes || (sv)==&PL_sv_no || (sv)==&PL_sv_placehold)
|> That could add "expensive" extra test to hot-ish code.

It's easy for me to say "but it's just one compare", but I do know that
those can add up. In this case, though, you really don't save much using
NULL (I guess you save loading a constant into a register), but I'd think
NULL would make more sense as &PL_sv_undef than as a placeholder.

(FWIW, SvIMMORTAL apears only eight times -- four in op.c,
 and three in  sv.c, and once in pp_hot.c)

|> With the proposed \? prototype it should be possible to do 
|> all this with C-level magic - possibly by using a new magic type.

If I read the \? stuff right, it sounds like you could effectively overload
a function so that you could do
        readonly %hash;
        readonly $scalar;
        readonly @array;
and have it all work. That would be cool.

I still need to be educated about magic types, etc.. but it's similar to
tying, I'd be leary of the cost involved.

I realize that it's a slippery slope to just wave your hand and say "but
doing it this way has such a small extra cost that it can't possibly
matter", but that does convey my sentiments. :-) It really is extremely
light weight.....


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About