develooper Front page | perl.perl5.porters | Postings from June 2017

lib/ puts references in %^H

Thread Next
Paul "LeoNerd" Evans
June 14, 2017 16:44
lib/ puts references in %^H
Message ID:
I've started investigating the "false-positives" I get out of my
attempt to warn on stringifying references, and so far every one has
turned out to be a real bug in other code :) Go me.

In one case,

  lib/ lines 627-630:

  627   $^H{charnames} = \&charnames ; 
  628   $^H{charnames_ord_aliases} = {};
  629   $^H{charnames_name_aliases} = {};
  630   $^H{charnames_inverse_ords} = {};

You would think that this can't work, given as perlvar says, on the
subject of %^H:

  All the entries are stringified when accessed at runtime, so only
  simple values can be accommodated.  This means no pointers to
  objects, for example.

Except its wording here isn't quite right. What %^H does is that values
are stringified at the point when compilation is over and runtime (for
that block) starts.

I suspect what is doing here is that these values are
being used only during compilation of the containing block, and once
runtime happens they get stringified and would no longer work, only
that's OK because they won't get called upon again.

If this is the case: does anyone have any suggestions on how I might
stop it triggering a warning from my code? I feel that
is doing something slightly naughty here, that perl happens to let it
get away with. My added warning then highlights it doing that.

Additionally: maybe, regardless of my 'use warnings qw( stringify );'
work, that stringification of references stored in %^H ought to cause a
warning anyway, because otherwise that's quite subtle. Also maybe then
the warning could have clearer text; perhaps something like

  Stringifying a reference to CODE at end of compilation phase at ...

instead of how it appears now, as

  Stringifying a reference to CODE at ../lib/ line 627.

Paul "LeoNerd" Evans      |  |

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