Skip to content

Commit 18a1234

Browse files
committed
amagic_call: accept a AMGf_force_scalar flag to force scalar context
and use it from the numeric comparison APIs.
1 parent 4c911a8 commit 18a1234

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

gv.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3748,8 +3748,20 @@ The operation is done only on just one operand.
37483748
37493749
The operation changes one of the operands, e.g., $x += 1
37503750
3751+
=item C<AMGf_force_scalar>
3752+
3753+
In many cases amagic_call() uses the L</GIMME_V> context of the
3754+
current OP when calling the sub handling the overload. This flag
3755+
forces amagic_call() to use scalar context.
3756+
37513757
=back
37523758
3759+
=for apidoc Amnh||AMGf_noleft
3760+
=for apidoc Amnh||AMGf_noright
3761+
=for apidoc Amnh||AMGf_unary
3762+
=for apidoc Amnh||AMGf_assign
3763+
=for apidoc Amnh||AMGf_force_scalar
3764+
37533765
=cut
37543766
*/
37553767

@@ -4142,7 +4154,8 @@ Perl_amagic_call(pTHX_ SV *left, SV *right, int method, int flags)
41424154
* with the context of individual concats being scalar,
41434155
* regardless of the overall context of the multiconcat op
41444156
*/
4145-
U8 gimme = (force_scalar || !PL_op || PL_op->op_type == OP_MULTICONCAT)
4157+
U8 gimme = (force_scalar || (flags & AMGf_force_scalar)
4158+
|| !PL_op || PL_op->op_type == OP_MULTICONCAT)
41464159
? G_SCALAR : GIMME_V;
41474160

41484161
CATCH_SET(TRUE);

pp.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -653,14 +653,15 @@ Does not use C<TARG>. See also C<L</XPUSHu>>, C<L</mPUSHu>> and C<L</PUSHu>>.
653653
(void)Perl_tmps_grow_p(aTHX_ eMiX); \
654654
} STMT_END
655655

656-
#define AMGf_noright 1
657-
#define AMGf_noleft 2
658-
#define AMGf_assign 4 /* op supports mutator variant, e.g. $x += 1 */
659-
#define AMGf_unary 8
660-
#define AMGf_numeric 0x10 /* for Perl_try_amagic_bin */
661-
662-
#define AMGf_want_list 0x40
663-
#define AMGf_numarg 0x80
656+
#define AMGf_noright 1
657+
#define AMGf_noleft 2
658+
#define AMGf_assign 4 /* op supports mutator variant, e.g. $x += 1 */
659+
#define AMGf_unary 8
660+
#define AMGf_numeric 0x0010 /* for Perl_try_amagic_bin */
661+
662+
#define AMGf_want_list 0x0040
663+
#define AMGf_numarg 0x0080
664+
#define AMGf_force_scalar 0x0100
664665

665666

666667
/* do SvGETMAGIC on the stack args before checking for overload */

sv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8723,7 +8723,7 @@ S_sv_numcmp_common(pTHX_ SV **sv1, SV **sv2, const U32 flags,
87238723

87248724
if(!(flags & SV_SKIP_OVERLOAD) &&
87258725
(SvAMAGIC(*sv1) || SvAMAGIC(*sv2))) {
8726-
if ((*result = amagic_call(*sv1, *sv2, method, 0)))
8726+
if ((*result = amagic_call(*sv1, *sv2, method, AMGf_force_scalar)))
87278727
return true;
87288728

87298729
/* normally handled by try_amagic_bin */

0 commit comments

Comments
 (0)