From 79ba695ca59126fd31a5a18edad74508d406a072 Mon Sep 17 00:00:00 2001 From: Zakariyya Mughal Date: Thu, 27 Jan 2022 23:35:42 -0500 Subject: [PATCH] Improve check for packing quad values - 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: * , * , * - 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. --- Basic/Core/Core.pm | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Basic/Core/Core.pm b/Basic/Core/Core.pm index ca954190d..1d01f9a05 100644 --- a/Basic/Core/Core.pm +++ b/Basic/Core/Core.pm @@ -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 -# and PR . -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(); @@ -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"