Skip to content

Commit d809c33

Browse files
committed
perlapi: Consolidate cop_hints_exists* 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 c4f3541 commit d809c33

File tree

1 file changed

+26
-34
lines changed

1 file changed

+26
-34
lines changed

cop.h

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -588,54 +588,46 @@ string/length pair.
588588
cophh_fetch_sv(CopHINTHASH_get(cop), key, hash, flags)
589589

590590
/*
591-
=for apidoc Am|bool|cop_hints_exists_pvn|const COP *cop|const char *keypv|STRLEN keylen|U32 hash|U32 flags
591+
=for apidoc Am|bool|cop_hints_exists_pvn|const COP *cop|const char *key|STRLEN keylen|U32 hash|U32 flags
592+
=for apidoc_item|bool|cop_hints_exists_pv |const COP *cop|const char *key |U32 hash|U32 flags
593+
=for apidoc_item|bool|cop_hints_exists_pvs|const COP *cop| "key" |U32 flags
594+
=for apidoc_item|bool|cop_hints_exists_sv |const COP *cop| SV *key |U32 hash|U32 flags
592595
593-
Look up the hint entry in the cop C<cop> with the key specified by
594-
C<keypv> and C<keylen>. If C<flags> has the C<COPHH_KEY_UTF8> bit set,
595-
the key octets are interpreted as UTF-8, otherwise they are interpreted
596-
as Latin-1. C<hash> is a precomputed hash of the key string, or zero if
597-
it has not been precomputed. Returns true if a value exists, and false
598-
otherwise.
599-
600-
=cut
601-
*/
596+
These look up the hint entry in the cop C<cop> with the key specified by
597+
C<key> (and C<keylen> in the C<pvn> form), returning true if a value exists,
598+
and false otherwise.
602599
603-
#define cop_hints_exists_pvn(cop, keypv, keylen, hash, flags) \
604-
cophh_exists_pvn(CopHINTHASH_get(cop), keypv, keylen, hash, flags)
600+
The forms differ in how the key is specified. In all forms, the key is pointed
601+
to by C<key>.
602+
In the plain C<pv> form, the key is a C language NUL-terminated string.
603+
In the C<pvs> form, the key is a C language string literal.
604+
In the C<pvn> form, an additional parameter, C<keylen>, specifies the length of
605+
the string, which hence, may contain embedded-NUL characters.
606+
In the C<sv> form, C<*key> is an SV, and the key is the PV extracted from that.
607+
using C<L</SvPV_const>>.
605608
606-
/*
607-
=for apidoc Am|bool|cop_hints_exists_pvs|const COP *cop|"key"|U32 flags
609+
C<hash> is a precomputed hash of the key string, or zero if it has not been
610+
precomputed. This parameter is omitted from the C<pvs> form, as it is computed
611+
automatically at compile time.
608612
609-
Like L</cop_hints_exists_pvn>, but takes a literal string
610-
instead of a string/length pair, and no precomputed hash.
613+
The only flag currently used from the C<flags> parameter is C<COPHH_KEY_UTF8>.
614+
It is illegal to set this in the C<sv> form. In the C<pv*> forms, it specifies
615+
whether the key octets are interpreted as UTF-8 (if set) or as Latin-1 (if
616+
cleared). The C<sv> form uses the underlying SV to determine the UTF-8ness of
617+
the octets.
611618
612619
=cut
613620
*/
614621

622+
#define cop_hints_exists_pvn(cop, key, keylen, hash, flags) \
623+
cophh_exists_pvn(CopHINTHASH_get(cop), key, keylen, hash, flags)
624+
615625
#define cop_hints_exists_pvs(cop, key, flags) \
616626
cophh_exists_pvs(CopHINTHASH_get(cop), key, flags)
617627

618-
/*
619-
=for apidoc Am|bool|cop_hints_exists_pv|const COP *cop|const char *key|U32 hash|U32 flags
620-
621-
Like L</cop_hints_exists_pvn>, but takes a nul-terminated string instead
622-
of a string/length pair.
623-
624-
=cut
625-
*/
626-
627628
#define cop_hints_exists_pv(cop, key, hash, flags) \
628629
cophh_exists_pv(CopHINTHASH_get(cop), key, hash, flags)
629630

630-
/*
631-
=for apidoc Am|bool|cop_hints_exists_sv|const COP *cop|SV *key|U32 hash|U32 flags
632-
633-
Like L</cop_hints_exists_pvn>, but takes a Perl scalar instead of a
634-
string/length pair.
635-
636-
=cut
637-
*/
638-
639631
#define cop_hints_exists_sv(cop, key, hash, flags) \
640632
cophh_exists_sv(CopHINTHASH_get(cop), key, hash, flags)
641633

0 commit comments

Comments
 (0)