Author: mattip <[email protected]>
Branch: cpyext-ext
Changeset: r81369:55993b380e68
Date: 2015-12-17 21:54 +0200
http://bitbucket.org/pypy/pypy/changeset/55993b380e68/
Log: fix for untranslated tests, start to run -A numpy tests
diff --git a/pypy/module/cpyext/test/test_cpyext.py
b/pypy/module/cpyext/test/test_cpyext.py
--- a/pypy/module/cpyext/test/test_cpyext.py
+++ b/pypy/module/cpyext/test/test_cpyext.py
@@ -277,10 +277,10 @@
return space.wrap(pydname)
@gateway.unwrap_spec(name=str, init='str_or_None', body=str,
- load_it=bool, filename='str_or_None',
+ load_it=bool, filename='str_or_None',
PY_SSIZE_T_CLEAN=bool)
def import_module(space, name, init=None, body='', load_it=True,
- filename=None, include_dirs=[],
+ filename=None, w_include_dirs=None,
PY_SSIZE_T_CLEAN=False):
"""
init specifies the overall template of the module.
@@ -291,6 +291,10 @@
if filename is None, the module name will be used to construct the
filename.
"""
+ if w_include_dirs is None:
+ include_dirs = []
+ else:
+ include_dirs = [space.str_w(s) for s in
space.listview(w_include_dirs)]
if init is not None:
code = """
%(PY_SSIZE_T_CLEAN)s
@@ -340,11 +344,10 @@
space.sys.get('modules'),
space.wrap(name))
- @gateway.unwrap_spec(modname=str, prologue=str, include_dirs=list,
+ @gateway.unwrap_spec(modname=str, prologue=str,
more_init=str, PY_SSIZE_T_CLEAN=bool)
def import_extension(space, modname, w_functions, prologue="",
- include_dirs=[], more_init="",
PY_SSIZE_T_CLEAN=False):
- include_dirs = [space.unwrap(d) for d in include_dirs]
+ w_include_dirs=None, more_init="",
PY_SSIZE_T_CLEAN=False):
functions = space.unwrap(w_functions)
methods_table = []
codes = []
@@ -370,7 +373,7 @@
if more_init:
init += more_init
return import_module(space, name=modname, init=init, body=body,
- include_dirs=include_dirs,
+ w_include_dirs=w_include_dirs,
PY_SSIZE_T_CLEAN=PY_SSIZE_T_CLEAN)
@gateway.unwrap_spec(name=str)
diff --git a/pypy/module/cpyext/test/test_ndarrayobject.py
b/pypy/module/cpyext/test/test_ndarrayobject.py
--- a/pypy/module/cpyext/test/test_ndarrayobject.py
+++ b/pypy/module/cpyext/test/test_ndarrayobject.py
@@ -244,7 +244,7 @@
'''
npy_intp dims[2] ={2, 3};
PyObject * obj = PyArray_SimpleNew(2, dims, 1);
- PyArray_FILLWBYTE(obj, 42);
+ PyArray_FILLWBYTE((PyArrayObject*)obj, 42);
return obj;
'''
),
@@ -252,12 +252,19 @@
'''
npy_intp dims1[2] ={2, 3};
npy_intp dims2[2] ={3, 2};
+ int ok;
PyObject * obj1 = PyArray_ZEROS(2, dims1, 11, 0);
PyObject * obj2 = PyArray_ZEROS(2, dims2, 11, 0);
- PyArray_FILLWBYTE(obj2, 42);
- PyArray_CopyInto(obj2, obj1);
- Py_DECREF(obj1);
- return obj2;
+ PyArray_FILLWBYTE((PyArrayObject*)obj2, 42);
+ ok = PyArray_CopyInto((PyArrayObject*)obj2,
(PyArrayObject*)obj1);
+ Py_DECREF(obj2);
+ if (ok < 0)
+ {
+ /* Should have failed */
+ Py_DECREF(obj1);
+ return NULL;
+ }
+ return obj1;
'''
),
("test_FromAny", "METH_NOARGS",
@@ -286,7 +293,16 @@
return _PyArray_DescrFromType(typenum);
"""
),
- ], prologue='#include <numpy/arrayobject.h>')
+ ], include_dirs=self.numpy_include,
+ prologue='''
+ #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
+ #include <numpy/arrayobject.h>
+ ''',
+ more_init = '''
+ #ifndef PYPY_VER
+ import_array();
+ #endif
+ ''')
arr = mod.test_simplenew()
assert arr.shape == (2, 3)
assert arr.dtype.num == 11 #float32 dtype
@@ -302,7 +318,6 @@
dt = mod.test_DescrFromType(11)
assert dt.num == 11
-
def test_pass_ndarray_object_to_c(self):
from _numpypy.multiarray import ndarray
mod = self.import_extension('foo', [
@@ -314,7 +329,16 @@
Py_INCREF(obj);
return obj;
'''),
- ], prologue='#include <numpy/arrayobject.h>')
+ ], include_dirs=self.numpy_include,
+ prologue='''
+ #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
+ #include <numpy/arrayobject.h>
+ ''',
+ more_init = '''
+ #ifndef PYPY_VER
+ import_array();
+ #endif
+ ''')
array = ndarray((3, 4), dtype='d')
assert mod.check_array(array) is array
raises(TypeError, "mod.check_array(42)")
@@ -356,9 +380,13 @@
"a ufunc that tests a more complicated
signature",
0, "(m,m)->(m,m)");
"""),
- ], prologue='''
- #include "numpy/ndarraytypes.h"
- /*#include <numpy/ufuncobject.h> generated by numpy setup.py*/
+ ], include_dirs=self.numpy_include,
+ prologue='''
+ #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
+ #include <numpy/arrayobject.h>
+ #ifndef PYPY_VERSION
+ #include <numpy/ufuncobject.h> /*generated by numpy setup.py*/
+ #endif
typedef void (*PyUFuncGenericFunction)
(char **args,
npy_intp *dimensions,
@@ -423,6 +451,10 @@
*((float *)args[1]) = res;
};
+ ''', more_init = '''
+ #ifndef PYPY_VER
+ import_array();
+ #endif
''')
sq = arange(18, dtype="float32").reshape(2,3,3)
float_ufunc = mod.create_float_ufunc_3x3()
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit