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
cb440212
Commit
cb440212
authored
Mar 24, 2018
by
scoder
Committed by
GitHub
Mar 24, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2177 from AntyMew/master
Allow `NULL` to be coerced to a pointer to a fused type
parents
8ff9c50d
f76f35ba
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
0 deletions
+35
-0
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+3
-0
tests/run/fused_types.pyx
tests/run/fused_types.pyx
+32
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
cb440212
...
...
@@ -850,6 +850,9 @@ class ExprNode(Node):
if
src_type
.
is_fused
:
error
(
self
.
pos
,
"Type is not specialized"
)
elif
src_type
.
is_null_ptr
and
dst_type
.
is_ptr
:
# NULL can be implicitly cast to any pointer type
return
self
else
:
error
(
self
.
pos
,
"Cannot coerce to a type that is not specialized"
)
...
...
tests/run/fused_types.pyx
View file @
cb440212
...
...
@@ -119,6 +119,38 @@ def test_fused_with_pointer():
print
print
fused_with_pointer
(
string_array
).
decode
(
'ascii'
)
cdef
fused_type1
*
fused_pointer_except_null
(
fused_type1
x
)
except
NULL
:
if
fused_type1
is
string_t
:
assert
(
bool
(
x
))
else
:
assert
(
x
<
10
)
return
&
x
def
test_fused_pointer_except_null
(
value
):
"""
>>> test_fused_pointer_except_null(1)
1
>>> test_fused_pointer_except_null(2.0)
2.0
>>> test_fused_pointer_except_null(b'foo')
foo
>>> test_fused_pointer_except_null(16)
Traceback (most recent call last):
AssertionError
>>> test_fused_pointer_except_null(15.1)
Traceback (most recent call last):
AssertionError
>>> test_fused_pointer_except_null(b'')
Traceback (most recent call last):
AssertionError
"""
if
isinstance
(
value
,
int
):
print
fused_pointer_except_null
(
<
cython
.
int
>
value
)[
0
]
elif
isinstance
(
value
,
float
):
print
fused_pointer_except_null
(
<
cython
.
float
>
value
)[
0
]
elif
isinstance
(
value
,
bytes
):
print
fused_pointer_except_null
(
<
string_t
>
value
)[
0
].
decode
(
'ascii'
)
include
"cythonarrayutil.pxi"
cpdef
cython
.
integral
test_fused_memoryviews
(
cython
.
integral
[:,
::
1
]
a
):
...
...
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