Skip to content

Commit

Permalink
On Perl 5.40 and above, use the various builtin:: functions to provid…
Browse files Browse the repository at this point in the history
…e those in Scalar::Util, avoiding the need for our own custom xsubs in that case
  • Loading branch information
leo authored and leonerd committed Jun 12, 2024
1 parent d562057 commit 26c5fb6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ListUtil.xs
Original file line number Diff line number Diff line change
Expand Up @@ -1717,6 +1717,7 @@ CODE:
ST(0) = boolSV((SvPOK(sv) || SvPOKp(sv)) && (SvNIOK(sv) || SvNIOKp(sv)));
XSRETURN(1);

#if !PERL_VERSION_GE(5, 40, 0)
SV *
blessed(sv)
SV *sv
Expand Down Expand Up @@ -1820,6 +1821,8 @@ CODE:
ST(0) = boolSV(SvROK(sv) && SvWEAKREF(sv));
XSRETURN(1);

#endif /* !PERL_VERSION_GE(5, 40, 0) */

int
readonly(sv)
SV *sv
Expand Down
13 changes: 13 additions & 0 deletions lib/Scalar/Util.pm
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ $VERSION =~ tr/_//d;
require List::Util; # List::Util loads the XS
List::Util->VERSION( $VERSION ); # Ensure we got the right XS version (RT#100863)

if( $] >= 5.040 ) {
# On Perl 5.40 and above, these builtins are stable, so we can use them
# instead of our own XS implementation

# Using this instead of a globref means we don't create an empty
# "builtins::" glob on older perls
no strict 'refs';
my $builtins = \%{"builtin::"};

*$_ = \&{ $builtins->{$_} } for (qw( blessed refaddr reftype weaken unweaken ));
*isweak = \&{ $builtins->{is_weak} }; # renamed
}

# populating @EXPORT_FAIL is done in the XS code
sub export_fail {
if (grep { /^isvstring$/ } @_ ) {
Expand Down

0 comments on commit 26c5fb6

Please sign in to comment.