diff options
author | Eric Herman <eric@freesa.org> | 2022-11-09 08:51:32 +0000 |
---|---|---|
committer | Philippe Bruhat (BooK) <book@cpan.org> | 2022-12-16 18:18:39 +0100 |
commit | bab261c9114a5ca4aee6acea592e42b95068af70 (patch) | |
tree | b7f8aad86cd5416802569ccb083410731f80ec92 /gv.c | |
parent | 14b1818040454cd07dfbd322f99ef9a43482c2dc (diff) | |
download | perl-bab261c9114a5ca4aee6acea592e42b95068af70.tar.gz |
Added function amagic_find(sv, method, flags)
Returns the CV pointer to the overloaded method,
which will be needed by join to detect concat magic.
Co-authored-by: Philippe Bruhat (BooK) <book@cpan.org>
Diffstat (limited to 'gv.c')
-rw-r--r-- | gv.c | 42 |
1 files changed, 42 insertions, 0 deletions
@@ -3377,6 +3377,48 @@ Perl_try_amagic_un(pTHX_ int method, int flags) { } +/* +=for apidoc amagic_find + +Check C<sv> for the overloaded (active magic) operation C<method>, and +return the C<CV *> or C<NULL>. + +C<method> is one of the values found in F<overload.h>. + +C<flags> are available for future use. + +=cut +*/ +CV * +Perl_amagic_find(pTHX_ SV *sv, int method, int flags) +{ + PERL_ARGS_ASSERT_AMAGIC_FIND; + PERL_UNUSED_VAR(flags); + + assert(method >= 0 && method < NofAMmeth); + + if (!SvAMAGIC(sv)) + return NULL; + + HV *stash = SvSTASH(SvRV(sv)); + if (!Gv_AMG(stash)) + return NULL; + + MAGIC *mg = mg_find((const SV *)stash, PERL_MAGIC_overload_table); + if (!mg) + return NULL; + + CV **cvp = NULL; + if (AMT_AMAGIC((AMT *)mg->mg_ptr)) + cvp = ((AMT *)mg->mg_ptr)->table; + if (!cvp) + return NULL; + + CV *cv = cvp[method]; + return cv; +} + + /* Implement tryAMAGICbin_MG macro. Do get magic, then see if the two stack args are overloaded and if so call it. |