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
f30c3a6b
Commit
f30c3a6b
authored
May 12, 2010
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
prevent Py_UNICODE from becoming a plain integer during arithmetic operations
parent
42572ca9
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
0 deletions
+36
-0
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+5
-0
Cython/Compiler/PyrexTypes.py
Cython/Compiler/PyrexTypes.py
+3
-0
tests/run/unicode_indexing.pyx
tests/run/unicode_indexing.pyx
+28
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
f30c3a6b
...
...
@@ -5015,6 +5015,11 @@ class NumBinopNode(BinopNode):
self
.
operand1
.
result
(),
self
.
operand2
.
result
())
def
is_py_operation_types
(
self
,
type1
,
type2
):
return
(
type1
is
PyrexTypes
.
c_py_unicode_type
or
type2
is
PyrexTypes
.
c_py_unicode_type
or
BinopNode
.
is_py_operation_types
(
self
,
type1
,
type2
))
def
py_operation_function
(
self
):
return
self
.
py_functions
[
self
.
operator
]
...
...
Cython/Compiler/PyrexTypes.py
View file @
f30c3a6b
...
...
@@ -2443,6 +2443,9 @@ def spanning_type(type1, type2):
return
type1
elif
type1
is
py_object_type
or
type2
is
py_object_type
:
return
py_object_type
elif
type1
is
c_py_unicode_type
or
type2
is
c_py_unicode_type
:
# Py_UNICODE behaves more like a string than an int
return
py_object_type
span_type
=
_spanning_type
(
type1
,
type2
)
if
span_type
is
None
:
return
py_object_type
...
...
tests/run/unicode_indexing.pyx
View file @
f30c3a6b
...
...
@@ -126,3 +126,31 @@ def index_compare_string(unicode ustring, Py_ssize_t i, unicode other):
IndexError: string index out of range
"""
return
ustring
[
i
]
==
other
@
cython
.
test_assert_path_exists
(
"//CoerceToPyTypeNode"
,
"//IndexNode"
,
"//MulNode"
,
"//MulNode/CoerceToPyTypeNode"
)
@
cython
.
test_fail_if_path_exists
(
"//IndexNode//CoerceToPyTypeNode"
)
def
index_multiply
(
unicode
ustring
,
Py_ssize_t
i
,
int
mul
):
"""
>>> ustring[0] * 5
u'aaaaa'
>>> index_multiply(ustring, 0, 5)
u'aaaaa'
"""
return
ustring
[
i
]
*
mul
@
cython
.
test_assert_path_exists
(
"//CoerceToPyTypeNode"
,
"//IndexNode"
,
"//AddNode"
,
"//AddNode/CoerceToPyTypeNode"
)
@
cython
.
test_fail_if_path_exists
(
"//IndexNode//CoerceToPyTypeNode"
)
def
index_add
(
unicode
ustring
,
Py_ssize_t
i
,
Py_ssize_t
j
):
"""
>>> ustring[0] + ustring[-1]
u'a6'
>>> index_add(ustring, 0, -1)
u'a6'
"""
return
ustring
[
i
]
+
ustring
[
j
]
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