rework patches for 3.3 to more directly reflect upstream's commits

* Sun Aug  5 2012 David Malcolm <dmalcolm@redhat.com> - 1:1.6.2-5
- rework patches for 3.3 to more directly reflect upstream's commits
- re-enable test suite on python 3
- forcibly regenerate Cython .c source to avoid import issues on Python 3.3
This commit is contained in:
David Malcolm 2012-08-05 19:39:40 -04:00
parent e158175a23
commit c8ca126fdd
6 changed files with 266 additions and 36 deletions

View File

@ -0,0 +1,69 @@
diff -up numpy-1.6.2/numpy/core/tests/test_multiarray.py.test_multiarray numpy-1.6.2/numpy/core/tests/test_multiarray.py
--- numpy-1.6.2/numpy/core/tests/test_multiarray.py.test_multiarray 2012-05-19 09:51:54.000000000 -0400
+++ numpy-1.6.2/numpy/core/tests/test_multiarray.py 2012-08-05 09:36:17.138719006 -0400
@@ -13,6 +13,15 @@ from numpy.compat import asbytes, getexc
from test_print import in_foreign_locale
+if sys.version_info[:2] > (3, 2):
+ # In Python 3.3 the representation of empty shape, strides and suboffsets
+ # is an empty tuple instead of None.
+ # http://docs.python.org/dev/whatsnew/3.3.html#api-changes
+ EMPTY = ()
+else:
+ EMPTY = None
+
+
class TestFlags(TestCase):
def setUp(self):
self.a = arange(10)
@@ -2162,7 +2171,7 @@ if sys.version_info >= (2, 6):
assert_equal(y.shape, (5,))
assert_equal(y.ndim, 1)
assert_equal(y.strides, (4,))
- assert_equal(y.suboffsets, None)
+ assert_equal(y.suboffsets, EMPTY)
assert_equal(y.itemsize, 4)
def test_export_simple_nd(self):
@@ -2172,7 +2181,7 @@ if sys.version_info >= (2, 6):
assert_equal(y.shape, (2, 2))
assert_equal(y.ndim, 2)
assert_equal(y.strides, (16, 8))
- assert_equal(y.suboffsets, None)
+ assert_equal(y.suboffsets, EMPTY)
assert_equal(y.itemsize, 8)
def test_export_discontiguous(self):
@@ -2182,7 +2191,7 @@ if sys.version_info >= (2, 6):
assert_equal(y.shape, (3, 3))
assert_equal(y.ndim, 2)
assert_equal(y.strides, (36, 4))
- assert_equal(y.suboffsets, None)
+ assert_equal(y.suboffsets, EMPTY)
assert_equal(y.itemsize, 4)
def test_export_record(self):
@@ -2214,7 +2223,7 @@ if sys.version_info >= (2, 6):
y = memoryview(x)
assert_equal(y.shape, (1,))
assert_equal(y.ndim, 1)
- assert_equal(y.suboffsets, None)
+ assert_equal(y.suboffsets, EMPTY)
sz = sum([dtype(b).itemsize for a, b in dt])
if dtype('l').itemsize == 4:
@@ -2228,10 +2237,10 @@ if sys.version_info >= (2, 6):
x = np.array(([[1,2],[3,4]],), dtype=[('a', ('i', (2,2)))])
y = memoryview(x)
assert_equal(y.format, 'T{(2,2)i:a:}')
- assert_equal(y.shape, None)
+ assert_equal(y.shape, EMPTY)
assert_equal(y.ndim, 0)
- assert_equal(y.strides, None)
- assert_equal(y.suboffsets, None)
+ assert_equal(y.strides, EMPTY)
+ assert_equal(y.suboffsets, EMPTY)
assert_equal(y.itemsize, 16)
def test_export_endian(self):

View File

@ -1,24 +1,30 @@
--- numpy/core/src/multiarray/scalarapi.c.orig 2012-05-19 15:51:54.000000000 +0200
+++ numpy/core/src/multiarray/scalarapi.c 2012-08-05 14:57:02.068276634 +0200
@@ -652,6 +652,35 @@
diff -up numpy-1.6.2/numpy/core/src/multiarray/scalarapi.c.fix_PyUnicodeObject numpy-1.6.2/numpy/core/src/multiarray/scalarapi.c
--- numpy-1.6.2/numpy/core/src/multiarray/scalarapi.c.fix_PyUnicodeObject 2012-05-19 09:51:54.000000000 -0400
+++ numpy-1.6.2/numpy/core/src/multiarray/scalarapi.c 2012-08-05 16:07:29.956719007 -0400
@@ -652,6 +652,40 @@ PyArray_Scalar(void *data, PyArray_Descr
itemsize = (((itemsize - 1) >> 2) + 1) << 2;
}
}
+#if PY_VERSION_HEX >= 0x03030000
+ if (type_num == NPY_UNICODE) {
+ PyObject *u, *args;
+ int byteorder;
+
+#if NPY_BYTE_ORDER == NPY_LITTLE_ENDIAN
+ byteorder = -1;
+#elif NPY_BYTE_ORDER == NPY_BIG_ENDIAN
+ byteorder = +1;
+#else
+ #error Endianness undefined ?
+#endif
+ if (swap) byteorder *= -1;
+
+ u = PyUnicode_DecodeUTF32(data, itemsize, NULL, &byteorder);
+ char *buffer;
+ if (swap) {
+ buffer = malloc(itemsize);
+ if (buffer == NULL) {
+ PyErr_NoMemory();
+ return NULL;
+ }
+ memcpy(buffer, data, itemsize);
+ byte_swap_vector(buffer, itemsize >> 2, 4);
+ } else {
+ buffer = data;
+ }
+ u = PyUnicode_FromKindAndData(PyUnicode_4BYTE_KIND, buffer,
+ itemsize >> 2);
+ if (swap) {
+ free(buffer);
+ }
+ if (u == NULL) {
+ return NULL;
+ }
@ -36,7 +42,7 @@
if (type->tp_itemsize != 0) {
/* String type */
obj = type->tp_alloc(type, itemsize);
@@ -688,6 +717,7 @@
@@ -688,6 +722,7 @@ PyArray_Scalar(void *data, PyArray_Descr
memcpy(destptr, data, itemsize);
return obj;
}
@ -44,19 +50,18 @@
else if (type_num == PyArray_UNICODE) {
/* tp_alloc inherited from Python PyBaseObject_Type */
PyUnicodeObject *uni = (PyUnicodeObject*)obj;
@@ -759,6 +789,7 @@
@@ -759,6 +794,7 @@ PyArray_Scalar(void *data, PyArray_Descr
#endif
return obj;
}
+#endif /* PY_VERSION_HEX < 0x03030000 */
+#endif // PY_VERSION_HEX < 0x03030000
else {
PyVoidScalarObject *vobj = (PyVoidScalarObject *)obj;
vobj->base = NULL;
diff --git numpy/core/src/multiarray/scalartypes.c.src numpy/core/src/multiarray/scalartypes.c.src
index e547071..12745d7 100644
--- numpy/core/src/multiarray/scalartypes.c.src
+++ numpy/core/src/multiarray/scalartypes.c.src
@@ -2592,7 +2592,11 @@ finish:
diff -up numpy-1.6.2/numpy/core/src/multiarray/scalartypes.c.src.fix_PyUnicodeObject numpy-1.6.2/numpy/core/src/multiarray/scalartypes.c.src
--- numpy-1.6.2/numpy/core/src/multiarray/scalartypes.c.src.fix_PyUnicodeObject 2012-05-19 09:51:54.000000000 -0400
+++ numpy-1.6.2/numpy/core/src/multiarray/scalartypes.c.src 2012-08-05 16:05:40.868718999 -0400
@@ -2323,7 +2323,11 @@ finish:
*((npy_@name@ *)dest) = *((npy_@name@ *)src);
#elif @default@ == 1 /* unicode and strings */
if (itemsize == 0) { /* unicode */

View File

@ -0,0 +1,37 @@
commit 09d2c51fa1d09b17060a8545b925f4dded9dedb1
Author: Ondrej Certik <ondrej.certik@gmail.com>
Date: Fri Aug 3 09:36:46 2012 -0700
Follow the C guidelines
diff --git a/numpy/core/src/multiarray/scalarapi.c b/numpy/core/src/multiarray/scalarapi.c
index 0afdc17..97a5e4b 100644
--- a/numpy/core/src/multiarray/scalarapi.c
+++ b/numpy/core/src/multiarray/scalarapi.c
@@ -645,6 +645,7 @@ PyArray_Scalar(void *data, PyArray_Descr *descr, PyObject *base)
if (type_num == NPY_UNICODE) {
PyObject *u, *args;
char *buffer;
+
if (swap) {
buffer = malloc(itemsize);
if (buffer == NULL) {
@@ -653,7 +654,8 @@ PyArray_Scalar(void *data, PyArray_Descr *descr, PyObject *base)
}
memcpy(buffer, data, itemsize);
byte_swap_vector(buffer, itemsize >> 2, 4);
- } else {
+ }
+ else {
buffer = data;
}
u = PyUnicode_FromKindAndData(PyUnicode_4BYTE_KIND, buffer,
@@ -778,7 +780,7 @@ PyArray_Scalar(void *data, PyArray_Descr *descr, PyObject *base)
#endif
return obj;
}
-#endif // PY_VERSION_HEX < 0x03030000
+#endif /* PY_VERSION_HEX < 0x03030000 */
else {
PyVoidScalarObject *vobj = (PyVoidScalarObject *)obj;
vobj->base = NULL;

View File

@ -0,0 +1,28 @@
commit 4234b6b13e3ee9da6fc1c24e9e8c442d77587837
Author: Ondrej Certik <ondrej.certik@gmail.com>
Date: Fri Aug 3 07:27:42 2012 -0700
FIX: Make sure the tests produce valid unicode
The tests are testing byte order for unicode, so we can only use such unicode
data, so that both versions (swapped and unswapped) are valid unicode.
diff --git a/numpy/core/tests/test_unicode.py b/numpy/core/tests/test_unicode.py
index d47ac54..7b27076 100644
--- a/numpy/core/tests/test_unicode.py
+++ b/numpy/core/tests/test_unicode.py
@@ -26,10 +26,12 @@ else:
return len(arr.data)
return len(buffer(arr))
+# In both cases below we need to make sure that the byte swapped value (as
+# UCS4) is still a valid unicode:
# Value that can be represented in UCS2 interpreters
-ucs2_value = u'\uFFFF'
+ucs2_value = u'\u0900'
# Value that cannot be represented in UCS2 interpreters (but can in UCS4)
-ucs4_value = u'\U0010FFFF'
+ucs4_value = u'\U00100900'
############################################################

View File

@ -0,0 +1,50 @@
commit f2ac38f09ff258339ef44572a3abba02019e1f55
Author: Ondrej Certik <ondrej.certik@gmail.com>
Date: Fri Aug 3 10:39:25 2012 -0700
Use PyUnicode_DecodeUTF32()
This function handles the swapping automatically and it returns a unicode
object in one of: UCS1, UCS2 or UCS4 internal Python format.
diff --git a/numpy/core/src/multiarray/scalarapi.c b/numpy/core/src/multiarray/scalarapi.c
index 97a5e4b..d9bc492 100644
--- a/numpy/core/src/multiarray/scalarapi.c
+++ b/numpy/core/src/multiarray/scalarapi.c
@@ -644,25 +644,18 @@ PyArray_Scalar(void *data, PyArray_Descr *descr, PyObject *base)
#if PY_VERSION_HEX >= 0x03030000
if (type_num == NPY_UNICODE) {
PyObject *u, *args;
- char *buffer;
+ int byteorder;
- if (swap) {
- buffer = malloc(itemsize);
- if (buffer == NULL) {
- PyErr_NoMemory();
- return NULL;
- }
- memcpy(buffer, data, itemsize);
- byte_swap_vector(buffer, itemsize >> 2, 4);
- }
- else {
- buffer = data;
- }
- u = PyUnicode_FromKindAndData(PyUnicode_4BYTE_KIND, buffer,
- itemsize >> 2);
- if (swap) {
- free(buffer);
- }
+#if NPY_BYTE_ORDER == NPY_LITTLE_ENDIAN
+ byteorder = -1;
+#elif NPY_BYTE_ORDER == NPY_BIG_ENDIAN
+ byteorder = +1;
+#else
+ #error Endianness undefined ?
+#endif
+ if (swap) byteorder *= -1;
+
+ u = PyUnicode_DecodeUTF32(data, itemsize, NULL, &byteorder);
if (u == NULL) {
return NULL;
}

View File

@ -9,7 +9,7 @@
Name: numpy
Version: 1.6.2
Release: 4%{?dist}
Release: 5%{?dist}
Epoch: 1
Summary: A fast multidimensional array facility for Python
@ -17,14 +17,32 @@ Group: Development/Languages
License: BSD
URL: http://numeric.scipy.org/
Source0: http://downloads.sourceforge.net/numpy/%{name}-%{version}%{?relc}.tar.gz
# backport unicode fixes from upstream git repo
# based on:
# commit 4676f33f9c77b04e9c599e642de7ab465f48ea8f
# Merge: fd15162 f2ac38f
# Author: Travis E. Oliphant <teoliphant@gmail.com>
# Date: Fri Aug 3 22:46:21 2012 -0700
# and commit a9d58ab42da8d2ed9071044848a54c5e066b557a
Patch0: numpy-1.6.2-unicode-python3.3.patch
# Fix tests for empty shape, strides and suboffsets on Python 3.3
# Backported from 02f3d1f73ca5957d3b5a3e575293e4d970de4267 upstream, see
# https://github.com/numpy/numpy/pull/367
Patch1: 001-fix-test_multiarray.patch
# Patches to fix PyUnicodeObject handling under 3.3, taken from upstream
# See
# https://github.com/numpy/numpy/pull/372
#
# "FIX: Fixes the PyUnicodeObject problem in py-3.3"
# based on upstream commit a9d58ab42da8d2ed9071044848a54c5e066b557a:
Patch2: 002-fix_PyUnicodeObject.patch
#
# "FIX: Make sure the tests produce valid unicode"
# copy of upstream commit 4234b6b13e3ee9da6fc1c24e9e8c442d77587837:
Patch3: 4234b6b13e3ee9da6fc1c24e9e8c442d77587837.patch
#
# "Follow the C guidelines"
# copy of upstream commit 09d2c51fa1d09b17060a8545b925f4dded9dedb1:
Patch4: 09d2c51fa1d09b17060a8545b925f4dded9dedb1.patch
#
# "Use PyUnicode_DecodeUTF32()"
# copy of upstream commit f2ac38f09ff258339ef44572a3abba02019e1f55:
Patch5: f2ac38f09ff258339ef44572a3abba02019e1f55.patch
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildRequires: python2-devel lapack-devel python-setuptools gcc-gfortran atlas-devel python-nose
@ -32,8 +50,9 @@ Requires: python-nose
%if 0%{?with_python3}
BuildRequires: python3-devel
BuildRequires: python3-setuptools
#BuildRequires: python3-nose
BuildRequires: python3-nose
%endif
BuildRequires: Cython
%description
NumPy is a general-purpose array-processing package designed to
@ -90,7 +109,24 @@ This package includes a version of f2py that works properly with NumPy.
%prep
%setup -q -n %{name}-%{version}%{?relc}
%patch0 -p0
%patch1 -p1
%patch2 -p1
%patch3 -p1
%patch4 -p1
%patch5 -p1
# Regenerate Cython c sources
# This is needed with numpy-1.6.2.tar.gz with python 3.3 to avoid an exception
# with an import call in the generated .c file in the tarball that uses the
# old default of -1:
# File "mtrand.pyx", line 126, in init mtrand (numpy/random/mtrand/mtrand.c:20679)
# ValueError: level must be >= 0
# due to the changes in import in 3.3
# Regenerating with a newer Cython fixes it:
pushd numpy/random/mtrand/
rm -v mtrand.c
cython mtrand.pyx
popd
%if 0%{?with_python3}
rm -rf %{py3dir}
@ -182,9 +218,9 @@ popd &> /dev/null
%if 0%{?with_python3}
pushd doc &> /dev/null
# there is no python3-nose yet
#PYTHONPATH="%{buildroot}%{python3_sitearch}" %{__python3} -c "import pkg_resources, numpy ; numpy.test()" \
PYTHONPATH="%{buildroot}%{python3_sitearch}" %{__python3} -c "import pkg_resources, numpy ; numpy.test()" \
%ifarch s390 s390x
#|| :
|| :
%endif
# don't remove this comment
popd &> /dev/null
@ -256,6 +292,11 @@ rm -rf %{buildroot}
%changelog
* Sun Aug 5 2012 David Malcolm <dmalcolm@redhat.com> - 1:1.6.2-5
- rework patches for 3.3 to more directly reflect upstream's commits
- re-enable test suite on python 3
- forcibly regenerate Cython .c source to avoid import issues on Python 3.3
* Sun Aug 5 2012 Thomas Spura <tomspur@fedoraproject.org> - 1:1.6.2-4
- rebuild for https://fedoraproject.org/wiki/Features/Python_3.3
- needs unicode patch