diff options
author | Stefan Behnel <stefan_ml@behnel.de> | 2018-03-27 20:22:21 +0200 |
---|---|---|
committer | Stefan Behnel <stefan_ml@behnel.de> | 2018-03-27 20:22:21 +0200 |
commit | fd85d226118aac2ce315becb020d3509f7417bfc (patch) | |
tree | 821acebce84ec2e6c96b391d6696869defd16c10 /Cython/Compiler/MemoryView.py | |
parent | 16664cfaa4c9f70a57c97162289431d92ef6ffc7 (diff) | |
download | cython-fd85d226118aac2ce315becb020d3509f7417bfc.tar.gz |
Turn the copy of a read-only memory view always into a writable memory view.
Closes #2134.
Diffstat (limited to 'Cython/Compiler/MemoryView.py')
-rw-r--r-- | Cython/Compiler/MemoryView.py | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/Cython/Compiler/MemoryView.py b/Cython/Compiler/MemoryView.py index 77ef59c9d..6ac1d88e4 100644 --- a/Cython/Compiler/MemoryView.py +++ b/Cython/Compiler/MemoryView.py @@ -484,18 +484,23 @@ def copy_c_or_fortran_cname(memview): return "__pyx_memoryview_copy_slice_%s_%s" % ( memview.specialization_suffix(), c_or_f) + def get_copy_new_utility(pos, from_memview, to_memview): - if from_memview.dtype != to_memview.dtype: - return error(pos, "dtypes must be the same!") + if (from_memview.dtype != to_memview.dtype and + not (from_memview.dtype.is_const and from_memview.dtype.const_base_type == to_memview.dtype)): + error(pos, "dtypes must be the same!") + return if len(from_memview.axes) != len(to_memview.axes): - return error(pos, "number of dimensions must be same") + error(pos, "number of dimensions must be same") + return if not (to_memview.is_c_contig or to_memview.is_f_contig): - return error(pos, "to_memview must be c or f contiguous.") + error(pos, "to_memview must be c or f contiguous.") + return for (access, packing) in from_memview.axes: if access != 'direct': - return error( - pos, "cannot handle 'full' or 'ptr' access at this time.") + error(pos, "cannot handle 'full' or 'ptr' access at this time.") + return if to_memview.is_c_contig: mode = 'c' @@ -516,6 +521,7 @@ def get_copy_new_utility(pos, from_memview, to_memview): dtype_is_object=int(to_memview.dtype.is_pyobject)), requires=[copy_contents_new_utility]) + def get_axes_specs(env, axes): ''' get_axes_specs(env, axes) -> list of (access, packing) specs for each axis. |