From a1f822c22a9381f509361dddb9844877f462e6a0 Mon Sep 17 00:00:00 2001 From: Karl Williamson Date: Thu, 19 May 2022 09:28:07 -0600 Subject: perlapi: Consolidate gv_fetchmeth forms, improve doc I read the code and added details previously missing. --- gv.c | 92 +++++++++++++++++++++++++++++++++++--------------------------------- 1 file changed, 47 insertions(+), 45 deletions(-) (limited to 'gv.c') diff --git a/gv.c b/gv.c index 36b089bf59..683818a9f5 100644 --- a/gv.c +++ b/gv.c @@ -724,14 +724,56 @@ S_maybe_add_coresub(pTHX_ HV * const stash, GV *gv, } /* -=for apidoc gv_fetchmeth +=for apidoc gv_fetchmeth +=for apidoc_item gv_fetchmeth_pv +=for apidoc_item gv_fetchmeth_pvn +=for apidoc_item gv_fetchmeth_sv -Like L, but lacks a flags parameter. +These each look for a glob with name C, containing a defined subroutine, +returning the GV of that glob if found, or C if not. -=for apidoc gv_fetchmeth_sv +C is always searched (first), unless it is C. -Exactly like L, but takes the name string in the form -of an SV instead of a string/length pair. +If C is NULL, or was searched but nothing was found in it, and the +C bit is set in C, stashes accessible via C<@ISA> are searched +next. Searching is conducted according to L order|perlmroapi>. + +Finally, if no matches were found so far, and the C flag in +C is not set, C is searched. + +The argument C should be either 0 or -1. If -1, the function will +return without any side effects or caching. If 0, the function makes sure +there is a glob named C in C, creating one if necessary. +The subroutine slot in the glob will be set to any subroutine found in the +C and C search, hence caching any C result. Note that +subroutines found in C are not cached. + +The GV returned from these may be a method cache entry, which is not visible to +Perl code. So when calling C, you should not use the GV directly; +instead, you should use the method's CV, which can be obtained from the GV with +the C macro. + +The only other significant value for C is C, indicating that +C is to be treated as being encoded in UTF-8. + +Plain C lacks a C parameter, hence always searches in +C, then C, and C is never UTF-8. Otherwise it is +exactly like C. + +The other forms do have a C parameter, and differ only in how the glob +name is specified. + +In C, C is a C language NUL-terminated string. + +In C, C points to the first byte of the name, and an +additional parameter, C, specifies its length in bytes. Hence, the name +may contain embedded-NUL characters. + +In C, C<*name> is an SV, and the name is the PV extracted from +that, using L>. If the SV is marked as being in UTF-8, the extracted +PV will also be. + +=for apidoc Amnh||GV_SUPER =cut */ @@ -750,14 +792,6 @@ Perl_gv_fetchmeth_sv(pTHX_ HV *stash, SV *namesv, I32 level, U32 flags) return gv_fetchmeth_pvn(stash, namepv, namelen, level, flags); } -/* -=for apidoc gv_fetchmeth_pv - -Exactly like L, but takes a nul-terminated string -instead of a string/length pair. - -=cut -*/ GV * Perl_gv_fetchmeth_pv(pTHX_ HV *stash, const char *name, I32 level, U32 flags) @@ -766,38 +800,6 @@ Perl_gv_fetchmeth_pv(pTHX_ HV *stash, const char *name, I32 level, U32 flags) return gv_fetchmeth_internal(stash, NULL, name, strlen(name), level, flags); } -/* -=for apidoc gv_fetchmeth_pvn - -Returns the glob with the given C and a defined subroutine or -C. The glob lives in the given C, or in the stashes -accessible via C<@ISA> and C. - -The argument C should be either 0 or -1. If C, as a -side-effect creates a glob with the given C in the given C -which in the case of success contains an alias for the subroutine, and sets -up caching info for this glob. - -The only significant values for C are C, C, and -C. - -C indicates that we want to look up the method in the superclasses -of the C. - -C indicates that we do not want to look up the method in -the stash accessible by C. - -The -GV returned from C may be a method cache entry, which is not -visible to Perl code. So when calling C, you should not use -the GV directly; instead, you should use the method's CV, which can be -obtained from the GV with the C macro. - -=for apidoc Amnh||GV_SUPER - -=cut -*/ - /* NOTE: No support for tied ISA */ PERL_STATIC_INLINE GV* -- cgit v1.2.1