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
ff27eac9
Commit
ff27eac9
authored
Oct 30, 2010
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make bytes the common type of char* and bytes literal in comparisons (ticket #582)
parent
02623216
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
85 additions
and
0 deletions
+85
-0
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+6
-0
tests/run/charptr_comparison_T582.pyx
tests/run/charptr_comparison_T582.pyx
+79
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
ff27eac9
...
...
@@ -6031,6 +6031,12 @@ class CmpNode(object):
self
.
invalid_types_error
(
operand1
,
op
,
operand2
)
new_common_type
=
error_type
if
new_common_type
.
is_string
and
(
isinstance
(
operand1
,
BytesNode
)
or
isinstance
(
operand2
,
BytesNode
)):
# special case when comparing char* to bytes literal: must
# compare string values!
new_common_type
=
bytes_type
# recursively merge types
if
common_type
is
None
or
new_common_type
.
is_error
:
common_type
=
new_common_type
...
...
tests/run/charptr_comparison_T582.pyx
View file @
ff27eac9
cimport
cython
################################################################################
## plain char*
@
cython
.
test_assert_path_exists
(
'//SingleAssignmentNode'
)
#@cython.test_fail_if_path_exists('//SingleAssignmentNode//CoerceFromPyTypeNode')
def
charptr_equals_literal
(
char
*
s
):
"""
>>> charptr_equals_literal('abc'.encode('ASCII'))
True
>>> charptr_equals_literal('aabc'.encode('ASCII'))
False
>>> charptr_equals_literal('abcx'.encode('ASCII'))
False
>>> charptr_equals_literal('bcx'.encode('ASCII'))
False
"""
cdef
bint
result
=
(
s
==
b"abc"
)
return
result
def
charptr_gt_literal
(
char
*
s
):
"""
>>> charptr_gt_literal('abc'.encode('ASCII'))
False
>>> charptr_gt_literal('aabc'.encode('ASCII'))
False
>>> charptr_gt_literal('abcx'.encode('ASCII'))
True
>>> charptr_gt_literal('bcx'.encode('ASCII'))
True
"""
cdef
bint
result
=
(
s
>
b"abc"
)
return
result
def
charptr_lt_literal
(
char
*
s
):
"""
>>> charptr_lt_literal('abc'.encode('ASCII'))
False
>>> charptr_lt_literal('aabc'.encode('ASCII'))
True
>>> charptr_lt_literal('abcx'.encode('ASCII'))
False
>>> charptr_lt_literal('bcx'.encode('ASCII'))
False
"""
cdef
bint
result
=
(
s
<
b"abc"
)
return
result
def
charptr_ge_literal
(
char
*
s
):
"""
>>> charptr_ge_literal('abc'.encode('ASCII'))
True
>>> charptr_ge_literal('aabc'.encode('ASCII'))
False
>>> charptr_ge_literal('abcx'.encode('ASCII'))
True
>>> charptr_ge_literal('bcx'.encode('ASCII'))
True
"""
cdef
bint
result
=
(
s
>=
b"abc"
)
return
result
def
charptr_le_literal
(
char
*
s
):
"""
>>> charptr_le_literal('abc'.encode('ASCII'))
True
>>> charptr_le_literal('aabc'.encode('ASCII'))
True
>>> charptr_le_literal('abcx'.encode('ASCII'))
False
>>> charptr_le_literal('bcx'.encode('ASCII'))
False
"""
cdef
bint
result
=
(
s
<=
b"abc"
)
return
result
################################################################################
## slices
@
cython
.
test_assert_path_exists
(
'//SingleAssignmentNode'
)
#FIXME: optimise me!
#@cython.test_fail_if_path_exists('//SingleAssignmentNode//CoerceFromPyTypeNode')
...
...
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