From e65876f8c10471388a5c73bdfa0a966a817b5cd2d69d591d5d7e42a02d8ca8c8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ismail=20D=C3=B6nmez?= <ismail@i10z.com>
Date: Tue, 6 Mar 2012 20:46:07 +0000
Subject: [PATCH] Accepting request 108217 from home:k0da:ppc

- The perl 5.12 packages are compiled with -Duse64bitint, which
  means that IVs are 64-bits even on 32-bit architectures. When
  converting IVs, SWIG assumes that an IV is the same size as a
  long, which causes OverflowErrors with  unsigned longs when
  the value is greater than 2^31.

OBS-URL: https://build.opensuse.org/request/show/108217
OBS-URL: https://build.opensuse.org/package/show/devel:tools:building/swig?expand=0&rev=31
---
 swig-2.0.4-fix-overflow-error-64bitint.patch | 80 ++++++++++++++++++++
 swig.changes                                 |  9 +++
 swig.spec                                    |  2 +
 3 files changed, 91 insertions(+)
 create mode 100644 swig-2.0.4-fix-overflow-error-64bitint.patch

diff --git a/swig-2.0.4-fix-overflow-error-64bitint.patch b/swig-2.0.4-fix-overflow-error-64bitint.patch
new file mode 100644
index 0000000..8ad0b10
--- /dev/null
+++ b/swig-2.0.4-fix-overflow-error-64bitint.patch
@@ -0,0 +1,80 @@
+Description: Fix overflow errors with 64-bit IVs
+ The perl 5.12 packages are compiled with -Duse64bitint, which means that IVs
+ are 64-bits even on 32-bit architectures. When converting IVs, SWIG assumes
+ that an IV is the same size as a long, which causes OverflowErrors with
+ unsigned longs when the value is greater than 2^31.
+ .
+ This patch should remove those assumptions by using the "IV" type defined by
+ the perl headers, and explicitly checking the values are within the correct
+ range for the type being converted.
+Author: Chris Butler <chrisb@debian.org>
+Bug-Debian: http://bugs.debian.org/579540
+Forwarded: no
+
+--- a/Lib/perl5/perlprimtypes.swg
++++ b/Lib/perl5/perlprimtypes.swg
+@@ -56,8 +56,13 @@
+ SWIG_AsVal_dec(long)(SV *obj, long* val)
+ {
+   if (SvIOK(obj)) {
+-    if (val) *val = SvIV(obj);
+-    return SWIG_OK;
++    IV v = SvIV(obj);
++    if (v >= LONG_MIN && v <= LONG_MAX) {
++      if (val) *val = v;
++      return SWIG_OK;
++    } else {
++      return SWIG_OverflowError;
++    }
+   } else {
+     int dispatch = 0;
+     const char *nptr = SvPV_nolen(obj);
+@@ -108,11 +113,16 @@
+ SWIG_AsVal_dec(unsigned long)(SV *obj, unsigned long *val) 
+ {
+   if (SvUOK(obj)) {
+-    if (val) *val = SvUV(obj);
+-    return SWIG_OK;
++    UV v = SvUV(obj);
++    if (v >= 0 && v <= ULONG_MAX) {
++      if (val) *val = v;
++      return SWIG_OK;
++    } else {
++      return SWIG_OverflowError;
++    }
+   } else  if (SvIOK(obj)) {
+-    long v = SvIV(obj);
+-    if (v >= 0) {
++    IV v = SvIV(obj);
++    if (v >= 0 && v <= ULONG_MAX) {
+       if (val) *val = v;
+       return SWIG_OK;
+     } else {
+@@ -179,8 +189,13 @@
+ SWIG_AsVal_dec(long long)(SV *obj, long long *val)
+ {
+   if (SvIOK(obj)) {
+-    if (val) *val = SvIV(obj);
+-    return SWIG_OK;
++    IV v = SvIV(obj);
++    if (v >= LLONG_MIN && v <= LLONG_MAX) {
++      if (val) *val = v;
++      return SWIG_OK;
++    } else {
++      return SWIG_OverflowError;
++    }
+   } else {
+     int dispatch = 0;
+     const char *nptr = SvPV_nolen(obj);
+@@ -246,8 +261,8 @@
+     if (val) *val = SvUV(obj);
+     return SWIG_OK;
+   } else  if (SvIOK(obj)) {
+-    long v = SvIV(obj);
+-    if (v >= 0) {
++    IV v = SvIV(obj);
++    if (v >= 0 && v <= ULLONG_MAX) {
+       if (val) *val = v;
+       return SWIG_OK;
+     } else {
+
diff --git a/swig.changes b/swig.changes
index e877b91..e0eccd9 100644
--- a/swig.changes
+++ b/swig.changes
@@ -1,3 +1,12 @@
+-------------------------------------------------------------------
+Tue Mar  6 19:24:07 UTC 2012 - dvaleev@suse.com
+
+- The perl 5.12 packages are compiled with -Duse64bitint, which 
+  means that IVs are 64-bits even on 32-bit architectures. When 
+  converting IVs, SWIG assumes that an IV is the same size as a 
+  long, which causes OverflowErrors with  unsigned longs when 
+  the value is greater than 2^31. 
+
 -------------------------------------------------------------------
 Tue Mar  6 09:15:47 UTC 2012 - kkaempf@suse.com
 
diff --git a/swig.spec b/swig.spec
index 23fb304..09656f9 100644
--- a/swig.spec
+++ b/swig.spec
@@ -67,6 +67,7 @@ Patch3:         swig-2.0.4-disable-broken-tests.patch
 Patch4:         swig-2.0.4-disable-broken-tests_rhel4.patch
 # PATCH-FIX-UPSTREAM swig-2.0.4-guile2.patch pgajdos@suse.com -- generate guile 2 friendly code
 Patch5:         swig-2.0.4-guile2.patch
+Patch6:         swig-2.0.4-fix-overflow-error-64bitint.patch
 BuildRoot:      %{_tmppath}/%{name}-%{version}-build
 
 %description
@@ -131,6 +132,7 @@ understandig SWIG usage.
 %if 0%{?suse_version} >= 1210 
 %patch5 -p1
 %endif
+%patch6 -p1
 
 %build
 %configure --disable-ccache