Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
95c699d3
Commit
95c699d3
authored
Oct 25, 2014
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
enable array assignments from pointers
parent
a0e2b420
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
85 additions
and
6 deletions
+85
-6
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+1
-4
Cython/Compiler/PyrexTypes.py
Cython/Compiler/PyrexTypes.py
+6
-2
tests/run/arrayassign.pyx
tests/run/arrayassign.pyx
+78
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
95c699d3
...
...
@@ -4070,10 +4070,7 @@ class SliceIndexNode(ExprNode):
array_length
=
rhs
.
type
.
size
self
.
generate_slice_guard_code
(
code
,
array_length
)
else
:
error
(
self
.
pos
,
"Slice assignments from pointers are not yet supported."
)
# FIXME: fix the array size according to start/stop
array_length
=
self
.
base
.
type
.
size
array_length
=
'%s - %s'
%
(
self
.
stop_code
(),
start_offset
)
def
copy_carray
(
dst
,
src
,
item_type
,
start
,
count
,
depth
):
var_name
=
Naming
.
quick_temp_cname
...
...
Cython/Compiler/PyrexTypes.py
View file @
95c699d3
...
...
@@ -2206,8 +2206,12 @@ class CArrayType(CPointerBaseType):
or
other_type
is
error_type
)
def
assignable_from_resolved_type
(
self
,
src_type
):
# Can't assign to a variable of an array type, except from Python containers
return
src_type
.
is_pyobject
# C arrays are assigned by value, either Python containers or C arrays/pointers
if
src_type
.
is_pyobject
:
return
True
if
src_type
.
is_ptr
or
src_type
.
is_array
:
return
self
.
base_type
.
assignable_from
(
src_type
.
base_type
)
return
False
def
element_ptr_type
(
self
):
return
c_ptr_type
(
self
.
base_type
)
...
...
tests/run/arrayassign.pyx
View file @
95c699d3
...
...
@@ -149,3 +149,81 @@ def test_list(list l):
cdef
int
a
[
5
]
a
[:]
=
l
return
(
a
[
0
],
a
[
1
],
a
[
2
],
a
[
3
],
a
[
4
])
def
assign_all_from_pointer
():
"""
>>> assign_all_from_pointer()
(1, 2, 3, 4, 5)
"""
cdef
int
*
v
=
[
1
,
2
,
3
,
4
,
5
]
cdef
int
[
5
]
a
a
=
v
return
(
a
[
0
],
a
[
1
],
a
[
2
],
a
[
3
],
a
[
4
])
def
assign_full_from_pointer
():
"""
>>> assign_full_from_pointer()
(1, 2, 3, 4, 5)
"""
cdef
int
*
v
=
[
1
,
2
,
3
,
4
,
5
]
cdef
int
[
5
]
a
a
[:]
=
v
return
(
a
[
0
],
a
[
1
],
a
[
2
],
a
[
3
],
a
[
4
])
def
assign_slice_end_from_pointer
():
"""
>>> assign_slice_end_from_pointer()
(1, 2, 3, 4, 123)
"""
cdef
int
*
v
=
[
1
,
2
,
3
,
4
,
5
]
cdef
int
[
5
]
a
a
[
4
]
=
123
a
[:
4
]
=
v
return
(
a
[
0
],
a
[
1
],
a
[
2
],
a
[
3
],
a
[
4
])
def
assign_slice_start_from_pointer
():
"""
>>> assign_slice_start_from_pointer()
(123, 234, 1, 2, 3)
"""
cdef
int
*
v
=
[
1
,
2
,
3
,
4
,
5
]
cdef
int
[
5
]
a
a
[
0
]
=
123
a
[
1
]
=
234
a
[
2
:]
=
v
return
(
a
[
0
],
a
[
1
],
a
[
2
],
a
[
3
],
a
[
4
])
def
assign_slice_start_end_from_pointer
():
"""
>>> assign_slice_start_end_from_pointer()
(123, 234, 1, 2, 345)
"""
cdef
int
*
v
=
[
1
,
2
,
3
,
4
,
5
]
cdef
int
[
5
]
a
a
[
0
]
=
123
a
[
1
]
=
234
a
[
4
]
=
345
a
[
2
:
4
]
=
v
return
(
a
[
0
],
a
[
1
],
a
[
2
],
a
[
3
],
a
[
4
])
'''
# FIXME: make this work:
def assign_slice_start_end_from_sliced_pointer():
"""
>>> assign_slice_start_end_from_sliced_pointer()
(123, 234, 3, 4, 345)
"""
cdef int *v = [1, 2, 3, 4, 5]
cdef int[5] a
a[0] = 123
a[1] = 234
a[4] = 345
a[2:4] = v[2:4]
return (a[0], a[1], a[2], a[3], a[4])
'''
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment