develooper Front page | perl.perl5.porters | Postings from December 2016

Changes to hints hash via keyword are clobbered by pragmatic module

Thread Next
From:
David Mertens
Date:
December 12, 2016 14:38
Subject:
Changes to hints hash via keyword are clobbered by pragmatic module
Message ID:
CA+4ieYXKLOSAktNn4Dq9HAZtBin-fA3gn-TVUxqfm_T=CJiENg@mail.gmail.com
Hello everyone,

I am writing about peculiar behavior with the hints hash. I'll be happy to
produce a simplified test case if the answer is not obvious. I am currently
working with Perl v5.22, but I expect this is a problem on other versions.

In my distribution I utilize two means for modifying the contents of a key
in the hints hash. In the first case, I simply follow the guidance of
perlpragma and append to it. See
https://github.com/run4flat/C-Blocks/blob/8e6089bdf70e6b5337e11df1e4c06d0a254765fc/lib/C/Blocks.pm#L61.
In the second case, I have C code that triggers on a keyword. This code
retrieves the current hints hash with CopHINTHASH_get(PL_curcop) (see
https://github.com/run4flat/C-Blocks/blob/8e6089bdf70e6b5337e11df1e4c06d0a254765fc/lib/C/Blocks.xs#L927),
appends to the SV (line 1241), stores the result back in the hints hash
with cophh_store_pvs (line 1246), and calls CopHINTHASH_set (line 1247).

This usually works. If I use the keyword multiple times in a row, they all
append to the hints hash fine. If I use pragmatic modules, they append to
the hints has fine. If I use pragmatic modules followed by keywords, they
append to the hints hash fine. But, if I use keywords followed by a
pragmatic module, the appends made by the keywords are not visible.

The only way this makes sense to me is if the Perl-level $^H{"
C::Blocks/extended_symtab_tables"} is a cached copy of the hints hash. I
would have hoped that the CopHINTHASH_set would invalidate the cache, but
that does not appear to be the case. Is there a trick too working with the
hints hash from C that I've missed?

Thanks!
David

-- 
 "Debugging is twice as hard as writing the code in the first place.
  Therefore, if you write the code as cleverly as possible, you are,
  by definition, not smart enough to debug it." -- Brian Kernighan

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About