Subject: | min/max do not handle magic correctly on their arguments |
See https://rt.perl.org/Ticket/Display.html?id=126440 for the original report.
min/max do handle AMAGIC (overload magic) correctly on their arguments, but do not handle GMAGIC.
The macro definition:
# define slu_sv_value(sv) (SvIOK(sv)) ? (SvIOK_UV(sv)) ? (NV)(SvUVX(sv)) : (NV)(SvIVX(sv)) : (SvNV(sv))
checks the flags on sv without having called any get magic on the SV, so the flags are meaningless.
This wasn't an issue before perl commit 4bac9ae47b5ad7845a24e26b0e95609805de688a since before that the IOK flag wouldn't be set before or after get magic was called and the macro would call SvNV() which does the get magic.
Changing the above macro to:
# define slu_sv_value(sv) (SvGETMAGIC(sv), SvIOK(sv)) ? (SvIOK_UV(sv)) ? (NV)(SvUVX(sv)) : (NV)(SvIVX(sv)) : (SvNV(sv))
allows the case in the rt.perl.org ticket to behave as expected, but will result in some extra magic calls, probably fixable by using SvNV_nomg, but I haven't performed any extensive testing of it.
Tony