diff --git a/Cython/Compiler/Buffer.py b/Cython/Compiler/Buffer.py index 5269a6f2fcb1048a0db331a1ee6fa37af4d4694a..6c431a04da1fbcfd0501e8e16607b77244137c3a 100644 --- a/Cython/Compiler/Buffer.py +++ b/Cython/Compiler/Buffer.py @@ -543,6 +543,8 @@ def use_py2_buffer_functions(env): for e in scope.type_entries: t = e.type if t.is_extension_type: + if e.name == 'array' and not e.used: + continue release = get = None for x in t.scope.pyfunc_entries: if x.name == u"__getbuffer__": get = x.func_cname diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index 1743175d6aad277861e51d2479c3429f74ecfa09..8031887509f986294a0dc1c08510169deec11b66 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -5808,6 +5808,7 @@ class FromCImportStatNode(StatNode): if entry: if kind and not self.declaration_matches(entry, kind): entry.redeclared(pos) + entry.used = 1 else: if kind == 'struct' or kind == 'union': entry = module_scope.declare_struct_or_union(name, diff --git a/tests/run/cythonarray.pyx b/tests/run/cythonarray.pyx index 5329e732142ca81e9286e7702649f3165dbda807..1fa7f567a0f2c610b1580b4c76d8ddfc491ea024 100644 --- a/tests/run/cythonarray.pyx +++ b/tests/run/cythonarray.pyx @@ -1,4 +1,7 @@ -from cython cimport array +# from cython cimport array +# cimport cython.array as array +cimport cython as cy +# array = cython.array def contiguity(): ''' @@ -10,13 +13,13 @@ def contiguity(): 2 3 2 ''' - cdef array cvarray = array(shape=(2,3), itemsize=sizeof(int), format="i", mode='c') + cdef cy.array cvarray = cy.array(shape=(2,3), itemsize=sizeof(int), format="i", mode='c') assert cvarray.len == 2*3*sizeof(int) assert cvarray.itemsize == sizeof(int) print cvarray.strides[0], cvarray.strides[1] print cvarray.shape[0], cvarray.shape[1] print cvarray.ndim - cdef array farray = array(shape=(2,3), itemsize=sizeof(int), format="i", mode='fortran') + cdef cy.array farray = cy.array(shape=(2,3), itemsize=sizeof(int), format="i", mode='fortran') assert farray.len == 2*3*sizeof(int) assert farray.itemsize == sizeof(int) print farray.strides[0], farray.strides[1] @@ -28,19 +31,19 @@ def acquire(): >>> acquire() ''' cdef object[int, ndim=1, mode="c"] buf1d = \ - array(shape=(10,), itemsize=sizeof(int), format='i', mode='c') + cy.array(shape=(10,), itemsize=sizeof(int), format='i', mode='c') cdef object[int, ndim=2, mode="c"] buf2d = \ - array(shape=(10,10), itemsize=sizeof(int), format='i') + cy.array(shape=(10,10), itemsize=sizeof(int), format='i') cdef object[unsigned long, ndim=3, mode='fortran'] buf3d = \ - array(shape=(1,2,3), itemsize=sizeof(unsigned long), format='L', mode='fortran') + cy.array(shape=(1,2,3), itemsize=sizeof(unsigned long), format='L', mode='fortran') cdef object[long double, ndim=3, mode='fortran'] bufld = \ - array(shape=(1,2,3), itemsize=sizeof(long double), format='g', mode='fortran') + cy.array(shape=(1,2,3), itemsize=sizeof(long double), format='g', mode='fortran') def full_or_strided(): ''' >>> full_or_strided() ''' cdef object[float, ndim=2, mode='full'] fullbuf = \ - array(shape=(10,10), itemsize=sizeof(float), format='f', mode='c') + cy.array(shape=(10,10), itemsize=sizeof(float), format='f', mode='c') cdef object[long long int, ndim=3, mode='strided'] stridedbuf = \ - array(shape=(1,2,3), itemsize=sizeof(long long int), format='q', mode='fortran') + cy.array(shape=(1,2,3), itemsize=sizeof(long long int), format='q', mode='fortran')