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.

- Also check for pack("D", ...) directly. This simplifies the check and
  removes the need for checking against the Perl version.
  • Loading branch information
zmughal committed Jan 28, 2022
1 parent fcbc68e commit 79ba695
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions Basic/Core/Core.pm
Expand Up @@ -16,12 +16,11 @@ use Config;
use List::Util qw(max);
use Scalar::Util 'blessed';

# If quad (q/Q) is available for pack().
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>.
our $CAN_PACK_D =
( $^V < v5.33.7 && $Config{d_longdbl} && $Config{uselongdouble} )
|| ( $^V >= v5.33.7 && $Config{d_longdbl} );
our $CAN_PACK_D = !! eval { my $packed = pack "D", 0; 1 };

our @EXPORT = qw( piddle pdl null barf ); # Only stuff always exported!
my @convertfuncs = map $_->convertfunc, PDL::Types::types();
Expand Down Expand Up @@ -1204,7 +1203,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] =~ /^q\*$/i ) {
# 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 79ba695

Please sign in to comment.