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
d3982ce7
Commit
d3982ce7
authored
Feb 25, 2010
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
safety fix
parent
067af347
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
4 deletions
+25
-4
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+7
-4
tests/run/charptr_len.pyx
tests/run/charptr_len.pyx
+18
-0
No files found.
Cython/Compiler/Optimize.py
View file @
d3982ce7
...
...
@@ -1205,10 +1205,6 @@ class OptimizeBuiltinCalls(Visitor.EnvTransform):
])
def
_handle_simple_function_len
(
self
,
node
,
pos_args
):
# note: this only works because we already replaced len() by
# PyObject_Length() which returns a Py_ssize_t instead of a
# Python object, so we can return a plain size_t instead
# without caring about Python object conversion etc.
if
len
(
pos_args
)
!=
1
:
self
.
_error_wrong_arg_count
(
'len'
,
node
,
pos_args
,
1
)
return
node
...
...
@@ -1217,6 +1213,13 @@ class OptimizeBuiltinCalls(Visitor.EnvTransform):
arg
=
arg
.
arg
if
not
arg
.
type
.
is_string
:
return
node
if
not
node
.
type
.
is_numeric
:
# this optimisation only works when we already replaced
# len() by PyObject_Length() which returns a Py_ssize_t
# instead of a Python object, so we can return a plain
# size_t instead without caring about Python object
# conversion etc.
return
node
node
=
ExprNodes
.
PythonCapiCallNode
(
node
.
pos
,
"strlen"
,
self
.
Pyx_strlen_func_type
,
args
=
[
arg
],
...
...
tests/run/charptr_len.pyx
View file @
d3982ce7
...
...
@@ -3,6 +3,10 @@ __doc__ = """
7
>>> lentest_char_c()
7
>>> lentest_char_c_short()
7
>>> lentest_char_c_float()
7.0
>>> lentest_uchar()
7
...
...
@@ -36,6 +40,20 @@ def lentest_char_c():
cdef
Py_ssize_t
l
=
len
(
s
)
return
l
@
cython
.
test_assert_path_exists
(
"//PythonCapiCallNode"
,
)
def
lentest_char_c_short
():
cdef
short
l
=
len
(
s
)
return
l
@
cython
.
test_assert_path_exists
(
"//PythonCapiCallNode"
,
)
def
lentest_char_c_float
():
cdef
float
l
=
len
(
s
)
return
l
@
cython
.
test_assert_path_exists
(
"//PythonCapiCallNode"
,
...
...
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