From 843e7e3013f4bd43277f9bb1a1935d1c63837647 Mon Sep 17 00:00:00 2001 From: Karl Williamson Date: Fri, 21 Jun 2024 13:29:30 -0600 Subject: [PATCH] perlapi: Combine all forms of gv_stash() --- gv.c | 61 ++++++++++++++++++++++++--------------------------------- handy.h | 10 ++++------ 2 files changed, 30 insertions(+), 41 deletions(-) diff --git a/gv.c b/gv.c index 6accdc0b0354..d5bdeb327e25 100644 --- a/gv.c +++ b/gv.c @@ -1548,30 +1548,28 @@ S_require_tie_mod(pTHX_ GV *gv, const char varname, const char * name, S_require_tie_mod(aTHX_ gv, varname, STR_WITH_LEN(name), flags) /* -=for apidoc gv_stashpv +=for apidoc gv_stashpv +=for apidoc_item gv_stashpvn +=for apidoc_item gv_stashpvs +=for apidoc_item gv_stashsv -Returns a pointer to the stash for a specified package. Uses C to -determine the length of C, then calls C. +Note C is strongly preferred for performance reasons. -=cut -*/ +These each return a pointer to the stash for a specified package. -HV* -Perl_gv_stashpv(pTHX_ const char *name, I32 create) -{ - PERL_ARGS_ASSERT_GV_STASHPV; - return gv_stashpvn(name, strlen(name), create); -} +In C, the package is specified by C. -/* -=for apidoc gv_stashpvn +In C, the package is specified by the literal C string enclosed in +double quotes. + +In the other forms, C specifies the package. In C, +C gives the length of the name in bytes, so it may include embedded +NUL characters. In C, C ends at the first NUL character. -Returns a pointer to the stash for a specified package. The C -parameter indicates the length of the C, in bytes. C is passed -to C, so if set to C then the package will be -created if it does not already exist. If the package does not exist and -C is 0 (or any other setting that does not create packages) then C -is returned. +C is passed to C, so if set to C then the +package will be created if it does not already exist. If the package does not +exist and C is 0 (or any other setting that does not create packages) +then C is returned. Flags may be one of: @@ -1585,9 +1583,6 @@ Flags may be one of: The most important of which are probably C and C. -Note, use of C instead of C where possible is strongly -recommended for performance reasons. - =for apidoc Amnh||GV_ADD =for apidoc Amnh||GV_NOADD_NOINIT =for apidoc Amnh||GV_NOINIT @@ -1598,11 +1593,19 @@ recommended for performance reasons. =cut */ +HV* +Perl_gv_stashpv(pTHX_ const char *name, I32 create) +{ + PERL_ARGS_ASSERT_GV_STASHPV; + return gv_stashpvn(name, strlen(name), create); +} + /* gv_stashpvn_internal Perform the internal bits of gv_stashsvpvn_cached. You could think of this -as being one half of the logic. Not to be called except from gv_stashsvpvn_cached(). +as being one half of the logic. Not to be called except from +gv_stashsvpvn_cached(). */ @@ -1718,18 +1721,6 @@ Perl_gv_stashpvn(pTHX_ const char *name, U32 namelen, I32 flags) return gv_stashsvpvn_cached(NULL, name, namelen, flags); } -/* -=for apidoc gv_stashsv - -Returns a pointer to the stash for a specified package. See -C>. - -Note this interface is strongly preferred over C for performance -reasons. - -=cut -*/ - HV* Perl_gv_stashsv(pTHX_ SV *sv, I32 flags) { diff --git a/handy.h b/handy.h index 21531c07ecaf..41764ac6bf3e 100644 --- a/handy.h +++ b/handy.h @@ -407,12 +407,6 @@ string/length pair. Like C, but takes a literal string instead of a string/length pair. -=for apidoc_section $GV - -=for apidoc Am|HV*|gv_stashpvs|"name"|I32 create -Like C, but takes a literal string instead of a -string/length pair. - =for apidoc_section $HV =for apidoc Am|SV**|hv_fetchs|HV* tb|"key"|I32 lval @@ -467,6 +461,10 @@ Perl_xxx(aTHX_ ...) form for any API calls where it's used. #define savepvs(str) Perl_savepvn(aTHX_ STR_WITH_LEN(str)) #define savesharedpvs(str) Perl_savesharedpvn(aTHX_ STR_WITH_LEN(str)) +/* +=for apidoc_defn Am|HV*|gv_stashpvs|"name"|I32 create +=cut +*/ #define gv_stashpvs(str, create) \ Perl_gv_stashpvn(aTHX_ STR_WITH_LEN(str), create)