From fca77093b9c144a239a4364549c17a7e747004a4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppi...@redhat.com>
Date: Fri, 24 Feb 2017 14:49:37 +0100
Subject: Fix constructing BSON::Time objects on 32-bit perl

---
 ...Do-not-produce-Math-BigFloat-by-BSON-Time.patch | 62 ++++++++++++++++++++++
 perl-BSON.spec                                     |  9 +++-
 2 files changed, 70 insertions(+), 1 deletion(-)
 create mode 100644 BSON-v1.2.2-Do-not-produce-Math-BigFloat-by-BSON-Time.patch

diff --git a/BSON-v1.2.2-Do-not-produce-Math-BigFloat-by-BSON-Time.patch 
b/BSON-v1.2.2-Do-not-produce-Math-BigFloat-by-BSON-Time.patch
new file mode 100644
index 0000000..129199a
--- /dev/null
+++ b/BSON-v1.2.2-Do-not-produce-Math-BigFloat-by-BSON-Time.patch
@@ -0,0 +1,62 @@
+From 8880ecb3084e6a4ed8cd37ea8b6701d8cd2987ef Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppi...@redhat.com>
+Date: Fri, 24 Feb 2017 14:02:28 +0100
+Subject: [PATCH] Do not produce Math::BigFloat by BSON::Time
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+Tests failed on 32-bit Perl without 64-bit intergers:
+
+During encode_one, Don't know how to encode Math::BigFloat '151109408000' as 
an Int64. at /builddir/build/BUILD/BSON-v1.2.2/blib/lib/BSON.pm line 299.
+ at t/legacy/10-bson.t line 385.
+
+That was caused by BSON::Time returning Math::BigFloat instead of
+Math::BigInt. And as consequence BSON::PP::_pack_int64() bailed out
+because it does not support Math::BigFloat.
+
+The issue was that Math::BigFloat->int() does not return Math::BigInt.
+It still returns Math::BigFloat. This patch fixes by calling
+as_number() that does so.
+
+<https://jira.mongodb.org/browse/PERL-694>
+
+Signed-off-by: Petr Písař <ppi...@redhat.com>
+---
+ lib/BSON/Time.pm | 6 +++---
+ 1 file changed, 3 insertions(+), 3 deletions(-)
+
+diff --git a/lib/BSON/Time.pm b/lib/BSON/Time.pm
+index bf10583..4f874a9 100644
+--- a/lib/BSON/Time.pm
++++ b/lib/BSON/Time.pm
+@@ -43,7 +43,7 @@ sub BUILDARGS {
+         else {
+             $args{value} = Math::BigFloat->new(time());
+             $args{value}->bmul(1000);
+-            $args{value} = int($args{value});
++            $args{value} = $args{value}->as_number('zero');
+         }
+     }
+     elsif ( $n == 1 ) {
+@@ -53,7 +53,7 @@ sub BUILDARGS {
+         if ( !$Config{use64bitint} && ref($args{value}) ne 'Math::BigInt' ) {
+             $args{value} = Math::BigFloat->new(shift);
+             $args{value}->bmul(1000);
+-            $args{value} = int($args{value});
++            $args{value} = $args{value}->as_number('zero');
+         }
+         else {
+             $args{value} = 1000 * shift;
+@@ -73,7 +73,7 @@ sub BUILDARGS {
+             if ( !$Config{use64bitint} && ref($args{value}) ne 'Math::BigInt' 
) {
+                 $args{value} = Math::BigFloat->new(shift);
+                 $args{value}->bmul(1000);
+-                $args{value} = int($args{value});
++                $args{value} = $args{value}->as_number('zero');
+             }
+             else {
+                 $args{value} = 1000 * shift;
+-- 
+2.7.4
+
diff --git a/perl-BSON.spec b/perl-BSON.spec
index 22e75c0..5d68d26 100644
--- a/perl-BSON.spec
+++ b/perl-BSON.spec
@@ -1,11 +1,14 @@
 Name:           perl-BSON
 Version:        1.2.2
-Release:        1%{?dist}
+Release:        2%{?dist}
 Summary:        BSON serialization and deserialization
 License:        ASL 2.0
 Group:          Development/Libraries
 URL:            http://search.cpan.org/dist/BSON/
 Source0:        
http://www.cpan.org/authors/id/M/MO/MONGODB/BSON-v%{version}.tar.gz
+# Fix constructing BSON::Time objects on 32-bit perl, bug #1401448,
+# <https://jira.mongodb.org/browse/PERL-694>
+Patch0:         BSON-v1.2.2-Do-not-produce-Math-BigFloat-by-BSON-Time.patch
 BuildArch:      noarch
 BuildRequires:  findutils
 BuildRequires:  make
@@ -83,6 +86,7 @@ versa in accordance with the BSON specification 
<http://bsonspec.org/>.
 
 %prep
 %setup -q -n BSON-v%{version}
+%patch0 -p1
 
 %build
 perl Makefile.PL INSTALLDIRS=vendor
@@ -104,5 +108,8 @@ make test
 %{_mandir}/man3/*
 
 %changelog
+* Fri Feb 24 2017 Petr Pisar <ppi...@redhat.com> - 1.2.2-2
+- Fix constructing BSON::Time objects on 32-bit perl (bug #1401448)
+
 * Thu Dec 01 2016 Petr Pisar <ppi...@redhat.com> 1.2.2-1
 - Specfile autogenerated by cpanspec 1.78.
-- 
cgit v1.1


        
https://src.fedoraproject.org/cgit/perl-BSON.git/commit/?h=f25&id=fca77093b9c144a239a4364549c17a7e747004a4
_______________________________________________
perl-devel mailing list -- perl-devel@lists.fedoraproject.org
To unsubscribe send an email to perl-devel-le...@lists.fedoraproject.org

Reply via email to