@@ -2765,14 +2765,25 @@ Perl_sv_2nv_flags(pTHX_ SV *const sv, const I32 flags)
27652765/*
27662766=for apidoc sv_2num_flags
27672767=for apidoc_item sv_2num
2768- X<SV_SKIP_OVERLOAD>
27692768
27702769Return an SV with the numeric value of the source SV, doing any necessary
27712770reference or overload conversion. The caller is expected to have handled
27722771get-magic already.
27732772
2774- For sv_2num_flags() you can set C<SV_SKIP_OVERLOAD> in flags to avoid
2775- any numeric context overloading.
2773+ For sv_2num_flags() you can set the following flags:
2774+
2775+ =over
2776+
2777+ =item *
2778+
2779+ C<SV_SKIP_OVERLOAD> - avoid any numeric context overloading.
2780+
2781+ =item *
2782+
2783+ C<SV_FORCE_OVERLOAD> - use numeric context overloading even if
2784+ disabled in hints by C<no overloading;>.
2785+
2786+ =back
27762787
27772788=cut
27782789*/
@@ -2782,15 +2793,18 @@ Perl_sv_2num_flags(pTHX_ SV *const sv, int flags)
27822793{
27832794 PERL_ARGS_ASSERT_SV_2NUM_FLAGS;
27842795
2785- assert((flags & ~SV_SKIP_OVERLOAD) == 0);
2796+ assert((flags & ~( SV_SKIP_OVERLOAD|SV_FORCE_OVERLOAD) ) == 0);
27862797
27872798 if (!SvROK(sv))
27882799 return sv;
27892800 if (SvAMAGIC(sv) && !(flags & SV_SKIP_OVERLOAD)) {
2790- SV * const tmpsv = AMG_CALLunary(sv, numer_amg);
2801+ STATIC_ASSERT_STMT(AMGf_force_overload == SV_FORCE_OVERLOAD);
2802+ SV * const tmpsv =
2803+ AMG_CALLunary_flags(sv, numer_amg,
2804+ (flags & SV_FORCE_OVERLOAD));
27912805 TAINT_IF(tmpsv && SvTAINTED(tmpsv));
27922806 if (tmpsv && (!SvROK(tmpsv) || (SvRV(tmpsv) != SvRV(sv))))
2793- return sv_2num (tmpsv);
2807+ return sv_2num_flags (tmpsv, flags );
27942808 }
27952809 return sv_2mortal(newSVuv(PTR2UV(SvRV(sv))));
27962810}
@@ -8735,8 +8749,12 @@ S_sv_numcmp_common(pTHX_ SV **sv1, SV **sv2, const U32 flags,
87358749 *sv2 = &PL_sv_undef;
87368750
87378751 if (SvAMAGIC(*sv1) || SvAMAGIC(*sv2)) {
8738- if (!(flags & SV_SKIP_OVERLOAD)) {
8739- if ((*result = amagic_call(*sv1, *sv2, method, AMGf_force_scalar)))
8752+ STATIC_ASSERT_STMT(AMGf_force_overload == SV_FORCE_OVERLOAD);
8753+ if (!(flags & SV_SKIP_OVERLOAD)
8754+ || (flags & SV_FORCE_OVERLOAD)) {
8755+ int amg_flags = AMGf_force_scalar
8756+ | (flags & AMGf_force_overload);
8757+ if ((*result = amagic_call(*sv1, *sv2, method, amg_flags)))
87408758 return true;
87418759 }
87428760
@@ -8817,7 +8835,8 @@ different to C< !sv_numne(sv1, sv2) >.
88178835
88188836The non-C<_flags> suffix versions of these functions always perform
88198837get magic and handle the appropriate type of overloading. See
8820- L<overload> for details.
8838+ L<overload> for details. Be aware that like the builtin operators,
8839+ C<no overloading;> will disable overloading.
88218840
88228841These each return a boolean indicating if the numbers in the two SV
88238842arguments satisfy the given relationship, coercing them to numbers if
@@ -8836,11 +8855,22 @@ otherwise 'get' magic is ignored.
88368855
88378856=item C<SV_SKIP_OVERLOAD>
88388857
8839- Skip any operator overloading implemented for this type and operator.
8858+ Skip any operator or numeric overloading implemented for this type and
8859+ operator. Be aware that for overloaded values this will compare the
8860+ addresses of the references, as for the usual numeric comparison of
8861+ non-overloaded references.
8862+
8863+ =item C<SV_FORCE_OVERLOAD>
8864+
8865+ Force overloading on even in the context of C<no overloading;>.
88408866
88418867=back
88428868
8869+ If neither overload flag is set overloading is honored unless C<no
8870+ overloading;> has disabled it.
8871+
88438872=for apidoc Amnh||SV_SKIP_OVERLOAD
8873+ =for apidoc Amnh||SV_FORCE_OVERLOAD
88448874
88458875=cut
88468876*/
@@ -8954,15 +8984,36 @@ because one of them is C<NaN>, though overloads can extend that.
89548984
89558985=back
89568986
8957- C<sv_numcmp> always performs 'get' magic. C<sv_numcmp_flags> performs
8958- 'get' magic on if C<flags> has the C<SV_GMAGIC> bit set.
8987+ C<sv_numcmp> always performs 'get' magic.
8988+
8989+ <sv_numcmp_flags> accepts these flags:
89598990
8960- C<sv_numcmp> always checks for, and if present, handles C<< <=> >>
8961- overloading. If not present, regular numerical comparison will be
8962- used instead.
8963- C<sv_numcmp_flags> normally does the same, but if the
8964- C<SV_SKIP_OVERLOAD> bit is set in C<flags> any C<< <=> >> overloading
8965- is ignored and a regular numerical comparison is done instead.
8991+ =over
8992+
8993+ =item *
8994+
8995+ C<SV_GMAGIC> - Perform 'get' magic on both C<sv1> amd C<sv2> if this
8996+ flag is set, otherwise 'get' magic is ignored.
8997+
8998+ =item *
8999+
9000+ C<SV_SKIP_OVERLOAD> - If this is set any C<< <=> >> or numeric
9001+ overloading implemented for this type is ignored. Be aware that for
9002+ overloaded values this will compare the addresses of the references,
9003+ as for the usual numeric comparison of non-overloaded references.
9004+
9005+ =item *
9006+
9007+ C<SV_FORCE_OVERLOAD> - Force overloading on even in the context of
9008+ C<no overloading;>.
9009+
9010+ =back
9011+
9012+ If neither overload flag is set overloading is honored unless C<no
9013+ overloading;> has disabled it.
9014+
9015+ =for apidoc Amnh||SV_SKIP_OVERLOAD
9016+ =for apidoc Amnh||SV_FORCE_OVERLOAD
89669017
89679018=cut
89689019*/
0 commit comments