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

Re: Changes to hints hash via keyword are clobbered by pragmaticmodule

Thread Previous | Thread Next
From:
Zefram
Date:
December 12, 2016 15:36
Subject:
Re: Changes to hints hash via keyword are clobbered by pragmaticmodule
Message ID:
20161212153602.GB6507@fysh.org
David Mertens wrote:
>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).

Don't do that.  The hints should always be set through %^H.  Writes to %^H
are automatically reflected in the CopHINTHASH copy.  The reverse does
not occur, and, because the CopHINTHASH form is a lossy representation
of %^H, it could not be made to work that way.  You should never write
to CopHINTHASH directly.  The CopHINTHASH stuff is only for reading,
and really only when the hints need to be read at runtime.  For reading
at compile time you should prefer to read from %^H.

See Array::Base on CPAN for a simple example of reading and writing %^H
at compile time from C code.

-zefram

Thread Previous | 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