Skip to content

Commit

Permalink
Improve check for packing quad values
Browse files Browse the repository at this point in the history
- Check if quad values can be packed by using `eval`. This is because
  the condition for whether `pack` can use quad values is a bit more
  complicated. See:

    * <https://www.nntp.perl.org/group/perl.perl5.porters/2013/10/msg208380.html>,
    * <Perl/perl5@1640b98>,
    * <Perl/perl5@c174bf3>

- Add unsigned quad value (Q) to the condition.
  • Loading branch information
zmughal committed Jan 28, 2022
1 parent fcbc68e commit 5df3554
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Basic/Core/Core.pm
Expand Up @@ -16,6 +16,8 @@ use Config;
use List::Util qw(max);
use Scalar::Util 'blessed';

our $CAN_PACK_QUAD = !! eval { my $packed = pack "Q", 0; 1 };

# If "D" is available for pack().
# See commit <https://github.com/Perl/perl5/commit/77a2054ea312b030904555167b764e4510dbcac6>
# and PR <https://github.com/Perl/perl5/pull/18517>.
Expand Down Expand Up @@ -1204,7 +1206,7 @@ sub PDL::new {
# new was passed a string argument that doesn't look like a number
# so we can process as a Matlab-style data entry format.
return PDL::Core::new_pdl_from_string($new,$value,$this,$type);
} elsif ($Config{ivsize} < 8 && $pack[$new->get_datatype] eq 'q*') {
} elsif (! $CAN_PACK_QUAD && $pack[$new->get_datatype] =~ /^[qQ]\*$/ ) {
# special case when running on a perl without 64bit int support
# we have to avoid pack("q", ...) in this case
# because it dies with error: "Invalid type 'q' in pack"
Expand Down

0 comments on commit 5df3554

Please sign in to comment.