develooper Front page | perl.perl5.porters | Postings from September 2011

RFC: Eliminate fake globs (glob copies)

Thread Next
Father Chrysostomos
September 11, 2011 18:15
RFC: Eliminate fake globs (glob copies)
Message ID:
I would like to propose that $thing = *foo stringify the glob, instead of assigning a glob copy (fake/coercible glob).

There are dozens of bugs involving fake globs.  Most of them I’ve fixed, but in fixing them it occurred to me that there is just far too much code in the core to deal with them.  And each piece of code treats them differently.  Here is an example:

$ perl -le' $foo = *bar; ++$foo'
Modification of a read-only value attempted at -e line 1.

But it’s not read-only, as I can assign to $foo.

There’s also a scalar vs glob ambiguity, in that a tied scalar can return a glob, and, voila! now it is a glob.  Consequently, ref(\$tied) will return a value that doesn’t necessarily represent what $tied will give you.

I could go on and on with more examples, but I think/hope you get the idea.

I do not think a deprecation cycle could work, as I am not proposing that ‘$foo = *bar’ be an error.

To avoid breaking existing code, we need to flag stringified globs as such, so that *$stringified_glob will still work under strict refs.  Any modification of the string will turn the flag off.

Globs assigned to undefined symbol table elements have never been guaranteed to work, but we can still make them work by using the flag to upgrade them to real globs.  (In fact, we could actually make it work in a way that is less buggy than what currently happens, in that a glob ends up in a stash element whose name does not agree with the glob, resulting in ISA caches not being updated properly.)

I believe the only code that will break will be that which deletes packages while holding copies of globs inside the package and expecting them to work still, or code that assigns globs over other globs while expecting copies of those clobbered globs to be unaffected.

I think it highly unlikely that any code will break, as globs were stringified from 5.10 to 5.12 when returned from tied arrays and hashes, and nobody noticed.  There was even a core test to make sure that a glob was returned, but it passed anyway as it used the ‘glob’ as a filehandle.

I plan to write a patch for this and see if Slaven Rezić would be willing to smoke all of CPAN with it.

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