Skip to content

Commit c7c0c00

Browse files
committed
perlapi: Consolidate cop_hints_fetch* entries
Making these a single entry makes perlapi more concise with less repetition, and clarifies the similarities and distinctions between the variant forms. Doing this showed me that some details had been glossed over, which this commit adds. This commit also changes the formal parameter name for one macro from "keypv" to "key" so all variants use the same names.
1 parent d809c33 commit c7c0c00

File tree

1 file changed

+26
-35
lines changed

1 file changed

+26
-35
lines changed

cop.h

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -535,55 +535,46 @@ string C<p>, creating the package if necessary.
535535
#define CopHINTHASH_set(c,h) ((c)->cop_hints_hash = (h))
536536

537537
/*
538-
=for apidoc Am|SV *|cop_hints_fetch_pvn|const COP *cop|const char *keypv|STRLEN keylen|U32 hash|U32 flags
538+
=for apidoc Am|SV *|cop_hints_fetch_pvn|const COP *cop|const char *key|STRLEN keylen|U32 hash|U32 flags
539+
=for apidoc_item|SV *|cop_hints_fetch_pv |const COP *cop|const char *key |U32 hash|U32 flags
540+
=for apidoc_item|SV *|cop_hints_fetch_pvs|const COP *cop| "key" |U32 flags
541+
=for apidoc_item|SV *|cop_hints_fetch_sv |const COP *cop| SV *key |U32 hash|U32 flags
539542
540-
Look up the hint entry in the cop C<cop> with the key specified by
541-
C<keypv> and C<keylen>. If C<flags> has the C<COPHH_KEY_UTF8> bit set,
542-
the key octets are interpreted as UTF-8, otherwise they are interpreted
543-
as Latin-1. C<hash> is a precomputed hash of the key string, or zero if
544-
it has not been precomputed. Returns a mortal scalar copy of the value
545-
associated with the key, or C<&PL_sv_placeholder> if there is no value
546-
associated with the key.
547-
548-
=cut
549-
*/
543+
These look up the hint entry in the cop C<cop> with the key specified by
544+
C<key> (and C<keylen> in the C<pvn> form), returning that value as a mortal
545+
scalar copy, or C<&PL_sv_placeholder> if there is no value associated with the
546+
key.
550547
551-
#define cop_hints_fetch_pvn(cop, keypv, keylen, hash, flags) \
552-
cophh_fetch_pvn(CopHINTHASH_get(cop), keypv, keylen, hash, flags)
548+
The forms differ in how the key is specified.
549+
In the plain C<pv> form, the key is a C language NUL-terminated string.
550+
In the C<pvs> form, the key is a C language string literal.
551+
In the C<pvn> form, an additional parameter, C<keylen>, specifies the length of
552+
the string, which hence, may contain embedded-NUL characters.
553+
In the C<sv> form, C<*key> is an SV, and the key is the PV extracted from that.
554+
using C<L</SvPV_const>>.
553555
554-
/*
555-
=for apidoc Am|SV *|cop_hints_fetch_pvs|const COP *cop|"key"|U32 flags
556+
C<hash> is a precomputed hash of the key string, or zero if it has not been
557+
precomputed. This parameter is omitted from the C<pvs> form, as it is computed
558+
automatically at compile time.
556559
557-
Like L</cop_hints_fetch_pvn>, but takes a literal string
558-
instead of a string/length pair, and no precomputed hash.
560+
The only flag currently used from the C<flags> parameter is C<COPHH_KEY_UTF8>.
561+
It is illegal to set this in the C<sv> form. In the C<pv*> forms, it specifies
562+
whether the key octets are interpreted as UTF-8 (if set) or as Latin-1 (if
563+
cleared). The C<sv> form uses the underlying SV to determine the UTF-8ness of
564+
the octets.
559565
560566
=cut
561567
*/
562568

569+
#define cop_hints_fetch_pvn(cop, key, keylen, hash, flags) \
570+
cophh_fetch_pvn(CopHINTHASH_get(cop), key, keylen, hash, flags)
571+
563572
#define cop_hints_fetch_pvs(cop, key, flags) \
564573
cophh_fetch_pvs(CopHINTHASH_get(cop), key, flags)
565574

566-
/*
567-
=for apidoc Am|SV *|cop_hints_fetch_pv|const COP *cop|const char *key|U32 hash|U32 flags
568-
569-
Like L</cop_hints_fetch_pvn>, but takes a nul-terminated string instead
570-
of a string/length pair.
571-
572-
=cut
573-
*/
574-
575575
#define cop_hints_fetch_pv(cop, key, hash, flags) \
576576
cophh_fetch_pv(CopHINTHASH_get(cop), key, hash, flags)
577577

578-
/*
579-
=for apidoc Am|SV *|cop_hints_fetch_sv|const COP *cop|SV *key|U32 hash|U32 flags
580-
581-
Like L</cop_hints_fetch_pvn>, but takes a Perl scalar instead of a
582-
string/length pair.
583-
584-
=cut
585-
*/
586-
587578
#define cop_hints_fetch_sv(cop, key, hash, flags) \
588579
cophh_fetch_sv(CopHINTHASH_get(cop), key, hash, flags)
589580

0 commit comments

Comments
 (0)